diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal')
611 files changed, 0 insertions, 87150 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java deleted file mode 100644 index fb420786e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; - -public abstract class AbstractJpaAnnotationDefintionProvider - implements JpaAnnotationDefinitionProvider -{ - private AnnotationDefinition[] typeAnnotationDefinitions; - - private AnnotationDefinition[] typeMappingAnnotationDefinitions; - - private AnnotationDefinition[] attributeAnnotationDefinitions; - - - protected AbstractJpaAnnotationDefintionProvider() { - super(); - } - - - // ********** type annotation definitions ********** - - public synchronized Iterator<AnnotationDefinition> typeAnnotationDefinitions() { - if (this.typeAnnotationDefinitions == null) { - this.typeAnnotationDefinitions = this.buildTypeAnnotationDefinitions(); - } - return new ArrayIterator<AnnotationDefinition>(this.typeAnnotationDefinitions); - } - - protected AnnotationDefinition[] buildTypeAnnotationDefinitions() { - ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>(); - this.addTypeAnnotationDefinitionsTo(definitions); - return definitions.toArray(new AnnotationDefinition[definitions.size()]); - } - - /** - * Subclasses must override this to specify type annotation definitions. - */ - protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - // no op - } - - public synchronized Iterator<AnnotationDefinition> typeMappingAnnotationDefinitions() { - if (this.typeMappingAnnotationDefinitions == null) { - this.typeMappingAnnotationDefinitions = this.buildTypeMappingAnnotationDefinitions(); - } - return new ArrayIterator<AnnotationDefinition>(this.typeMappingAnnotationDefinitions); - } - - protected AnnotationDefinition[] buildTypeMappingAnnotationDefinitions() { - ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>(); - this.addTypeMappingAnnotationDefinitionsTo(definitions); - return definitions.toArray(new AnnotationDefinition[definitions.size()]); - } - - /** - * Subclasses must override this to specify type mapping annotation definitions. - */ - protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - // no op - } - - - // ********** attribute annotation definitions ********** - - public synchronized Iterator<AnnotationDefinition> attributeAnnotationDefinitions() { - if (this.attributeAnnotationDefinitions == null) { - this.attributeAnnotationDefinitions = this.buildAttributeAnnotationDefinitions(); - } - return new ArrayListIterator<AnnotationDefinition>(this.attributeAnnotationDefinitions); - } - - protected AnnotationDefinition[] buildAttributeAnnotationDefinitions() { - ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>(); - this.addAttributeAnnotationDefinitionsTo(definitions); - return definitions.toArray(new AnnotationDefinition[definitions.size()]); - } - - /** - * Subclasses must override this to specify attribute annotation definitions. - */ - protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - // no op - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFactory.java deleted file mode 100644 index 1cf8e79f8e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFactory.java +++ /dev/null @@ -1,437 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaDataSource; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModel; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JarFile; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaCascade; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaConverter; -import org.eclipse.jpt.core.context.java.JavaDiscriminatorColumn; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaEnumeratedConverter; -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaLobConverter; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -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.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaQueryContainer; -import org.eclipse.jpt.core.context.java.JavaQueryHint; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -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.context.java.JavaTemporalConverter; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.JarFileRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -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.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.internal.jpa1.GenericJpaDataSource; -import org.eclipse.jpt.core.internal.jpa1.GenericJpaFile; -import org.eclipse.jpt.core.internal.jpa1.GenericJpaProject; -import org.eclipse.jpt.core.internal.jpa1.context.GenericRootContextNode; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJarFile; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaAssociationOverride; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaAttributeOverride; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaAttributeOverrideContainer; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaBasicMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaCascade; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaColumn; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaDiscriminatorColumn; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaEmbeddable; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaEmbeddedIdMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaEmbeddedMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaEntity; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaEnumeratedConverter; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaGeneratedValue; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaGeneratorContainer; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaIdMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaJoinColumn; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaJoinTable; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaLobConverter; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaManyToManyMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaManyToOneMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaMappedSuperclass; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNamedNativeQuery; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNamedQuery; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullConverter; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaOneToManyMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaOneToOneMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaPersistentAttribute; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaPersistentType; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaQueryContainer; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaQueryHint; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaSecondaryTable; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaSequenceGenerator; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaTable; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaTableGenerator; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaTemporalConverter; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaTransientMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaUniqueConstraint; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaVersionMapping; -import org.eclipse.jpt.core.internal.jpa1.context.java.NullJavaAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.jpa1.context.java.VirtualAssociationOverride1_0Annotation; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericJarFileRef; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericMappingFileRef; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericPersistence; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericPersistenceUnit; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericPersistenceUnitProperty; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericPersistenceXml; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.ImpliedMappingFileRef; -import org.eclipse.jpt.core.internal.jpa2.NullPersistentTypeStaticMetamodelSynchronizer; -import org.eclipse.jpt.core.internal.jpa2.NullStaticMetamodelSynchronizer; -import org.eclipse.jpt.core.internal.jpa2.context.java.NullJavaDerivedId2_0; -import org.eclipse.jpt.core.jpa2.JpaFactory2_0; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.jpa2.PersistentTypeStaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.StaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; - -/** - * Central class that allows extenders to easily replace implementations of - * various Dali interfaces. - */ -public abstract class AbstractJpaFactory - implements JpaFactory2_0 -{ - protected AbstractJpaFactory() { - super(); - } - - - // ********** Core Model ********** - - public JpaProject buildJpaProject(JpaProject.Config config) throws CoreException { - return new GenericJpaProject(config); - } - - public StaticMetamodelSynchronizer buildStaticMetamodelSynchronizer(JpaProject2_0 jpaProject) { - return new NullStaticMetamodelSynchronizer(jpaProject); - } - - public PersistentTypeStaticMetamodelSynchronizer buildPersistentTypeStaticMetamodelSynchronizer(StaticMetamodelSynchronizer staticMetamodelSynchronizer, PersistentType persistentType) { - return new NullPersistentTypeStaticMetamodelSynchronizer(); - } - - public JpaDataSource buildJpaDataSource(JpaProject jpaProject, String connectionProfileName) { - return new GenericJpaDataSource(jpaProject, connectionProfileName); - } - - public JpaFile buildJpaFile(JpaProject jpaProject, IFile file, IContentType contentType, JpaResourceModel resourceModel) { - return new GenericJpaFile(jpaProject, file, contentType, resourceModel); - } - - - // ********** Context Nodes ********** - - public JpaRootContextNode buildRootContextNode(JpaProject parent) { - return new GenericRootContextNode(parent); - } - - - // ********** Persistence Context Model ********** - - public PersistenceXml buildPersistenceXml(JpaRootContextNode parent, JpaXmlResource resource) { - return new GenericPersistenceXml(parent, resource); - } - - public Persistence buildPersistence(PersistenceXml parent, XmlPersistence xmlPersistence) { - return new GenericPersistence(parent, xmlPersistence); - } - - public PersistenceUnit buildPersistenceUnit(Persistence parent, XmlPersistenceUnit xmlPersistenceUnit) { - return new GenericPersistenceUnit(parent, xmlPersistenceUnit); - } - - public JarFileRef buildJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { - return new GenericJarFileRef(parent, xmlJarFileRef); - } - - public MappingFileRef buildMappingFileRef(PersistenceUnit parent, XmlMappingFileRef xmlMappingFileRef) { - return new GenericMappingFileRef(parent, xmlMappingFileRef); - } - - public MappingFileRef buildImpliedMappingFileRef(PersistenceUnit parent) { - return new ImpliedMappingFileRef(parent, JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH ); - } - - public ClassRef buildClassRef(PersistenceUnit parent, XmlJavaClassRef classRef) { - return new GenericClassRef(parent, classRef); - } - - public ClassRef buildClassRef(PersistenceUnit parent, String className) { - return new GenericClassRef(parent, className); - } - - public PersistenceUnit.Property buildProperty(PersistenceUnit parent, XmlProperty xmlProperty) { - return new GenericPersistenceUnitProperty(parent, xmlProperty); - } - - - // ********** Java Context Model ********** - - public JavaPersistentType buildJavaPersistentType(PersistentType.Owner owner, JavaResourcePersistentType jrpt) { - return new GenericJavaPersistentType(owner, jrpt); - } - - public JavaPersistentAttribute buildJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa) { - return new GenericJavaPersistentAttribute(parent, jrpa); - } - - public JavaTypeMapping buildJavaNullTypeMapping(JavaPersistentType parent) { - return new JavaNullTypeMapping(parent); - } - - public JavaEntity buildJavaEntity(JavaPersistentType parent) { - return new GenericJavaEntity(parent); - } - - public JavaMappedSuperclass buildJavaMappedSuperclass(JavaPersistentType parent) { - return new GenericJavaMappedSuperclass(parent); - } - - public JavaEmbeddable buildJavaEmbeddable(JavaPersistentType parent) { - return new GenericJavaEmbeddable(parent); - } - - public JavaTable buildJavaTable(JavaEntity parent) { - return new GenericJavaTable(parent); - } - - public JavaCascade buildJavaCascade(JavaRelationshipMapping parent) { - return new GenericJavaCascade(parent); - } - - public JavaColumn buildJavaColumn(JavaJpaContextNode parent, JavaColumn.Owner owner) { - return new GenericJavaColumn(parent, owner); - } - - public JavaDiscriminatorColumn buildJavaDiscriminatorColumn(JavaEntity parent, JavaDiscriminatorColumn.Owner owner) { - return new GenericJavaDiscriminatorColumn(parent, owner); - } - - public JavaJoinColumn buildJavaJoinColumn(JavaJpaContextNode parent, JavaJoinColumn.Owner owner) { - return new GenericJavaJoinColumn(parent, owner); - } - - public JavaJoinTable buildJavaJoinTable(JavaJoinTableJoiningStrategy parent) { - return new GenericJavaJoinTable(parent); - } - - public JavaSecondaryTable buildJavaSecondaryTable(JavaEntity parent) { - return new GenericJavaSecondaryTable(parent); - } - - public JavaBasicMapping buildJavaBasicMapping(JavaPersistentAttribute parent) { - return new GenericJavaBasicMapping(parent); - } - - public JavaEmbeddedIdMapping buildJavaEmbeddedIdMapping(JavaPersistentAttribute parent) { - return new GenericJavaEmbeddedIdMapping(parent); - } - - public JavaEmbeddedMapping buildJavaEmbeddedMapping(JavaPersistentAttribute parent) { - return new GenericJavaEmbeddedMapping(parent); - } - - public JavaIdMapping buildJavaIdMapping(JavaPersistentAttribute parent) { - return new GenericJavaIdMapping(parent); - } - - public JavaManyToManyMapping buildJavaManyToManyMapping(JavaPersistentAttribute parent) { - return new GenericJavaManyToManyMapping(parent); - } - - public JavaManyToOneMapping buildJavaManyToOneMapping(JavaPersistentAttribute parent) { - return new GenericJavaManyToOneMapping(parent); - } - - public JavaOneToManyMapping buildJavaOneToManyMapping(JavaPersistentAttribute parent) { - return new GenericJavaOneToManyMapping(parent); - } - - public JavaOneToOneMapping buildJavaOneToOneMapping(JavaPersistentAttribute parent) { - return new GenericJavaOneToOneMapping(parent); - } - - public JavaTransientMapping buildJavaTransientMapping(JavaPersistentAttribute parent) { - return new GenericJavaTransientMapping(parent); - } - - public JavaVersionMapping buildJavaVersionMapping(JavaPersistentAttribute parent) { - return new GenericJavaVersionMapping(parent); - } - - public JavaAttributeMapping buildJavaNullAttributeMapping(JavaPersistentAttribute parent) { - return new GenericJavaNullAttributeMapping(parent); - } - - public JavaGeneratorContainer buildJavaGeneratorContainer(JavaJpaContextNode parent) { - return new GenericJavaGeneratorContainer(parent); - } - - public JavaSequenceGenerator buildJavaSequenceGenerator(JavaJpaContextNode parent) { - return new GenericJavaSequenceGenerator(parent); - } - - public JavaTableGenerator buildJavaTableGenerator(JavaJpaContextNode parent) { - return new GenericJavaTableGenerator(parent); - } - - public JavaGeneratedValue buildJavaGeneratedValue(JavaIdMapping parent) { - return new GenericJavaGeneratedValue(parent); - } - - public JavaPrimaryKeyJoinColumn buildJavaPrimaryKeyJoinColumn(JavaJpaContextNode parent, JavaBaseJoinColumn.Owner owner) { - return new GenericJavaPrimaryKeyJoinColumn(parent, owner); - } - - public JavaAttributeOverrideContainer buildJavaAttributeOverrideContainer(JavaJpaContextNode parent, JavaAttributeOverrideContainer.Owner owner) { - return new GenericJavaAttributeOverrideContainer(parent, owner); - } - - public JavaAssociationOverrideContainer buildJavaAssociationOverrideContainer(JavaEntity parent, AssociationOverrideContainer.Owner owner) { - return new GenericJavaAssociationOverrideContainer(parent, owner); - } - - public JavaAssociationOverrideContainer buildJavaAssociationOverrideContainer(JavaEmbeddedMapping2_0 parent, AssociationOverrideContainer.Owner owner) { - return new NullJavaAssociationOverrideContainer(parent, owner); - } - - public JavaAttributeOverride buildJavaAttributeOverride(JavaJpaContextNode parent, AttributeOverride.Owner owner) { - return new GenericJavaAttributeOverride(parent, owner); - } - - public JavaAssociationOverride buildJavaAssociationOverride(JavaJpaContextNode parent, AssociationOverride.Owner owner) { - return new GenericJavaAssociationOverride(parent, owner); - } - - public JavaAssociationOverrideRelationshipReference buildJavaAssociationOverrideRelationshipReference(JavaAssociationOverride parent) { - return new GenericJavaAssociationOverrideRelationshipReference(parent); - } - - public AssociationOverrideAnnotation buildJavaVirtualAssociationOverrideAnnotation(JavaResourcePersistentMember jrpm, String name, JoiningStrategy joiningStrategy) { - return new VirtualAssociationOverride1_0Annotation(jrpm, name, joiningStrategy); - } - - public JavaQueryContainer buildJavaQueryContainer(JavaJpaContextNode parent) { - return new GenericJavaQueryContainer(parent); - } - - public JavaNamedQuery buildJavaNamedQuery(JavaJpaContextNode parent) { - return new GenericJavaNamedQuery(parent); - } - - public JavaNamedNativeQuery buildJavaNamedNativeQuery(JavaJpaContextNode parent) { - return new GenericJavaNamedNativeQuery(parent); - } - - public JavaQueryHint buildJavaQueryHint(JavaQuery parent) { - return new GenericJavaQueryHint(parent); - } - - public JavaUniqueConstraint buildJavaUniqueConstraint(JavaJpaContextNode parent, UniqueConstraint.Owner owner) { - return new GenericJavaUniqueConstraint(parent, owner); - } - - public JavaEnumeratedConverter buildJavaEnumeratedConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa) { - return new GenericJavaEnumeratedConverter(parent, jrpa); - } - - public JavaTemporalConverter buildJavaTemporalConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa) { - return new GenericJavaTemporalConverter(parent, jrpa); - } - - public JavaLobConverter buildJavaLobConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa) { - return new GenericJavaLobConverter(parent, jrpa); - } - - public JavaConverter buildJavaNullConverter(JavaAttributeMapping parent) { - return new GenericJavaNullConverter(parent); - } - - public JavaDerivedId2_0 buildJavaDerivedId(JavaSingleRelationshipMapping2_0 parent) { - return new NullJavaDerivedId2_0(parent); - } - - - // ********** JAR Context Model ********** - - public JarFile buildJarFile(JarFileRef parent, JavaResourcePackageFragmentRoot jarResourcePackageFragmentRoot) { - return new GenericJarFile(parent, jarResourcePackageFragmentRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaNode.java deleted file mode 100644 index f04be55841..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaNode.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jpt.core.JpaDataSource; -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaPlatformVariation; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.CallbackChangeSupport; -import org.eclipse.jpt.utility.internal.model.ChangeSupport; - -/** - * Some common Dali behavior:<ul> - * <li>containment hierarchy - * <li>Eclipse adaptable - * <li>update triggers - * </ul> - */ -public abstract class AbstractJpaNode - extends AbstractModel - implements JpaNode -{ - private final JpaNode parent; - - - // ********** constructor/initialization ********** - - protected AbstractJpaNode(JpaNode parent) { - super(); - this.checkParent(parent); - this.parent = parent; - } - - protected void checkParent(JpaNode p) { - if (p == null) { - if (this.requiresParent()) { - throw new IllegalArgumentException("'parent' cannot be null"); //$NON-NLS-1$ - } - } else { - if (this.forbidsParent()) { - throw new IllegalArgumentException("'parent' must be null"); //$NON-NLS-1$ - } - } - } - - protected boolean requiresParent() { - return true; - } - - protected boolean forbidsParent() { - return ! this.requiresParent(); // assume 'parent' is not optional - } - - @Override - protected ChangeSupport buildChangeSupport() { - return new CallbackChangeSupport(this, this.buildChangeSupportListener()); - } - - protected CallbackChangeSupport.Listener buildChangeSupportListener() { - return new CallbackChangeSupport.Listener() { - public void aspectChanged(String aspectName) { - AbstractJpaNode.this.aspectChanged(aspectName); - } - }; - } - - - // ********** IAdaptable implementation ********** - - @SuppressWarnings("unchecked") - public Object getAdapter(Class adapter) { - return Platform.getAdapterManager().getAdapter(this, adapter); - } - - - // ********** JpaNode implementation ********** - - public JpaNode getParent() { - return this.parent; - } - - public IResource getResource() { - return this.parent.getResource(); - } - - public JpaProject getJpaProject() { - return this.parent.getJpaProject(); - } - - - // ********** convenience methods ********** - - protected JpaPlatform getJpaPlatform() { - return this.getJpaProject().getJpaPlatform(); - } - - protected JpaPlatform.Version getJpaPlatformVersion() { - return this.getJpaPlatform().getJpaVersion(); - } - - protected JpaFactory getJpaFactory() { - return this.getJpaPlatform().getJpaFactory(); - } - - protected JpaPlatformVariation getJpaPlatformVariation() { - return this.getJpaPlatform().getJpaVariation(); - } - - protected JpaFile getJpaFile(IFile file) { - return this.getJpaProject().getJpaFile(file); - } - - protected JpaDataSource getDataSource() { - return this.getJpaProject().getDataSource(); - } - - protected Database getDatabase() { - return this.getDataSource().getDatabase(); - } - - protected boolean connectionProfileIsActive() { - return this.getDataSource().connectionProfileIsActive(); - } - - /** - * Pre-condition: specified catalog <em>identifier</em> is not null. - * NB: Do not use the catalog <em>name</em>. - */ - protected Catalog getDbCatalog(String catalog) { - Database database = this.getDatabase(); - return (database == null) ? null : database.getCatalogForIdentifier(catalog); - } - - - // ********** CallbackChangeSupport.Listener support ********** - - protected void aspectChanged(String aspectName) { - if (this.aspectTriggersUpdate(aspectName)) { - // System.out.println(Thread.currentThread() + " \"update\" change: " + this + ": " + aspectName); - this.getJpaProject().update(); - } - } - - private boolean aspectTriggersUpdate(String aspectName) { - return ! this.aspectDoesNotTriggerUpdate(aspectName); - } - - private boolean aspectDoesNotTriggerUpdate(String aspectName) { - return this.nonUpdateAspectNames().contains(aspectName); - } - - protected final Set<String> nonUpdateAspectNames() { - synchronized (nonUpdateAspectNameSets) { - HashSet<String> nonUpdateAspectNames = nonUpdateAspectNameSets.get(this.getClass()); - if (nonUpdateAspectNames == null) { - nonUpdateAspectNames = new HashSet<String>(); - this.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - nonUpdateAspectNameSets.put(this.getClass(), nonUpdateAspectNames); - } - return nonUpdateAspectNames; - } - } - - private static final HashMap<Class<? extends AbstractJpaNode>, HashSet<String>> nonUpdateAspectNameSets = new HashMap<Class<? extends AbstractJpaNode>, HashSet<String>>(); - - protected void addNonUpdateAspectNamesTo(@SuppressWarnings("unused") Set<String> nonUpdateAspectNames) { - // when you override this method, don't forget to include: - // super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaPlatformProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaPlatformProvider.java deleted file mode 100644 index e0b87d1b0b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaPlatformProvider.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaPlatformProvider; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.context.MappingFileDefinition; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.context.java.NullDefaultJavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.NullJavaTypeMappingDefinition; -import org.eclipse.jpt.core.context.java.NullSpecifiedJavaAttributeMappingDefinition; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; - -/** - * All the state in the JPA platform should be "static" (i.e. unchanging once - * it is initialized). - */ -public abstract class AbstractJpaPlatformProvider - implements JpaPlatformProvider -{ - private JpaResourceModelProvider[] resourceModelProviders; - - private JavaTypeMappingDefinition[] javaTypeMappingDefinitions; - - private JavaAttributeMappingDefinition[] specifiedJavaAttributeMappingDefinitions; - - private JavaAttributeMappingDefinition[] defaultJavaAttributeMappingDefinitions; - - private MappingFileDefinition[] mappingFileDefinitions; - - - /** - * zero-argument constructor - */ - protected AbstractJpaPlatformProvider() { - super(); - } - - - // ********** resource models ********** - - public ListIterator<JpaResourceModelProvider> resourceModelProviders() { - return new ArrayListIterator<JpaResourceModelProvider>(getResourceModelProviders()); - } - - protected synchronized JpaResourceModelProvider[] getResourceModelProviders() { - if (this.resourceModelProviders == null) { - this.resourceModelProviders = this.buildResourceModelProviders(); - } - return this.resourceModelProviders; - } - - protected abstract JpaResourceModelProvider[] buildResourceModelProviders(); - - - // ********** Java type mappings ********** - - public ListIterator<JavaTypeMappingDefinition> javaTypeMappingDefinitions() { - return new ArrayListIterator<JavaTypeMappingDefinition>(getJavaTypeMappingDefinitions()); - } - - protected synchronized JavaTypeMappingDefinition[] getJavaTypeMappingDefinitions() { - if (this.javaTypeMappingDefinitions == null) { - this.javaTypeMappingDefinitions = this.buildJavaTypeMappingDefinitions(); - } - return this.javaTypeMappingDefinitions; - } - - /** - * Return an array of mapping definitions to use for analyzing the mapping of a type given all - * annotations on it. The order is important, as once a mapping definition tests positive for an - * attribute, all following mapping definitions are ignored. - * Extenders may either overwrite this method or {@link #buildNonNullJavaTypeMappingDefinitions()}. - * Doing the former places the additional requirement on the extender to provide a "null" - * mapping definition (@see {@link NullJavaTypeMappingDefinition}.) - */ - protected JavaTypeMappingDefinition[] buildJavaTypeMappingDefinitions() { - return ArrayTools.add( - buildNonNullJavaTypeMappingDefinitions(), - NullJavaTypeMappingDefinition.instance()); - } - - /** - * No-op implementation of this method. - * @see #buildJavaTypeMappingDefinitions() - */ - protected JavaTypeMappingDefinition[] buildNonNullJavaTypeMappingDefinitions() { - return new JavaTypeMappingDefinition[0]; - } - - - // ********** Java attribute mappings ********** - - public ListIterator<JavaAttributeMappingDefinition> defaultJavaAttributeMappingDefinitions() { - return new ArrayListIterator<JavaAttributeMappingDefinition>(getDefaultJavaAttributeMappingDefinitions()); - } - - protected synchronized JavaAttributeMappingDefinition[] getDefaultJavaAttributeMappingDefinitions() { - if (this.defaultJavaAttributeMappingDefinitions == null) { - this.defaultJavaAttributeMappingDefinitions = this.buildDefaultJavaAttributeMappingDefinitions(); - } - return this.defaultJavaAttributeMappingDefinitions; - } - - /** - * Return an array of mapping definitions to use for analyzing the default mapping of an attribute - * in the absence of any annotations. The order is important, as once a mapping definition tests - * positively for a given attribute, all following mapping definitions are ignored. - * Extenders may either overwrite this method or - * {@link #buildNonNullDefaultJavaAttributeMappingDefinitions()}. - * Doing the former places the additional requirement on the extender to provide a "null" - * mapping definition (@see {@link NullDefaultJavaAttributeMappingDefinition}.) - */ - protected JavaAttributeMappingDefinition[] buildDefaultJavaAttributeMappingDefinitions() { - return ArrayTools.add( - buildNonNullDefaultJavaAttributeMappingDefinitions(), - NullDefaultJavaAttributeMappingDefinition.instance()); - } - - /** - * No-op implementation of this method. - * @see #buildDefaultJavaAttributeMappingDefinitions() - */ - protected JavaAttributeMappingDefinition[] buildNonNullDefaultJavaAttributeMappingDefinitions() { - return new JavaAttributeMappingDefinition[0]; - } - - public ListIterator<JavaAttributeMappingDefinition> specifiedJavaAttributeMappingDefinitions() { - return new ArrayListIterator<JavaAttributeMappingDefinition>( - getSpecifiedJavaAttributeMappingDefinitions()); - } - - protected synchronized JavaAttributeMappingDefinition[] getSpecifiedJavaAttributeMappingDefinitions() { - if (this.specifiedJavaAttributeMappingDefinitions == null) { - this.specifiedJavaAttributeMappingDefinitions = this.buildSpecifiedJavaAttributeMappingDefinitions(); - } - return this.specifiedJavaAttributeMappingDefinitions; - } - - /** - * Return an array of mapping definitions to use for analyzing the specified mapping of an attribute - * given all annotations on it. The order is important, as once a mapping definition tests - * positively for a given attribute, all following mapping definitions are ignored. - * Extenders may either overwrite this method or - * {@link #buildNonNullSpecifiedJavaAttributeMappingDefinitions()}. - * Doing the former places the additional requirement on the extender to provide a "null" - * mapping definition (@see {@link NullSpecifiedJavaAttributeMappingDefinition}.) - */ - protected JavaAttributeMappingDefinition[] buildSpecifiedJavaAttributeMappingDefinitions() { - return ArrayTools.add( - buildNonNullSpecifiedJavaAttributeMappingDefinitions(), - NullSpecifiedJavaAttributeMappingDefinition.instance()); - } - - /** - * No-op implementation of this method. - * @see #buildSpecifiedJavaAttributeMappingDefinitions() - */ - protected JavaAttributeMappingDefinition[] buildNonNullSpecifiedJavaAttributeMappingDefinitions() { - return new JavaAttributeMappingDefinition[0]; - } - - - // ********** Mapping Files ********** - - public ListIterator<MappingFileDefinition> mappingFileDefinitions() { - return new ArrayListIterator<MappingFileDefinition>(getMappingFileDefinitions()); - } - - protected synchronized MappingFileDefinition[] getMappingFileDefinitions() { - if (this.mappingFileDefinitions == null) { - this.mappingFileDefinitions = this.buildMappingFileDefinitions(); - } - return this.mappingFileDefinitions; - } - - protected abstract MappingFileDefinition[] buildMappingFileDefinitions(); -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java deleted file mode 100644 index 0cea4731a6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java +++ /dev/null @@ -1,1410 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.Vector; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JpaDataSource; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModel; -import org.eclipse.jpt.core.JpaResourceModelListener; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryPersistentTypeCache; -import org.eclipse.jpt.core.internal.resource.java.source.SourceCompilationUnit; -import org.eclipse.jpt.core.internal.utility.PlatformTools; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.JpaFactory2_0; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.jpa2.StaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.context.JpaRootContextNode2_0; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentTypeCache; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.jpt.utility.internal.BitTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.ThreadLocalCommandExecutor; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; -import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * JPA project. Holds all the JPA stuff. - * - * The JPA platform provides the hooks for vendor-specific stuff. - * - * The JPA files are the "resource" model (i.e. objects that correspond directly - * to Eclipse resources; e.g. Java source code files, XML files, JAR files). - * - * The root context node is the "context"model (i.e. objects that attempt to - * model the JPA spec, using the "resource" model as an adapter to the Eclipse - * resources). - * - * The data source is an adapter to the DTP meta-data model. - */ -public abstract class AbstractJpaProject - extends AbstractJpaNode - implements JpaProject2_0 -{ - /** - * The Eclipse project corresponding to the JPA project. - */ - protected final IProject project; - - /** - * The vendor-specific JPA platform that builds the JPA project - * and all its contents. - */ - protected final JpaPlatform jpaPlatform; - - /** - * The JPA files associated with the JPA project: - * persistence.xml - * orm.xml - * java - */ - protected final Vector<JpaFile> jpaFiles = new Vector<JpaFile>(); - - /** - * The "external" Java resource compilation units (source). Populated upon demand. - */ - protected final Vector<JavaResourceCompilationUnit> externalJavaResourceCompilationUnits = new Vector<JavaResourceCompilationUnit>(); - - /** - * The "external" Java resource persistent types (binary). Populated upon demand. - */ - protected final JavaResourcePersistentTypeCache externalJavaResourcePersistentTypeCache; - - /** - * Resource models notify this listener when they change. A project update - * should occur any time a resource model changes. - */ - protected final JpaResourceModelListener resourceModelListener; - - /** - * The root of the model representing the collated resources associated with - * the JPA project. - */ - protected final JpaRootContextNode rootContextNode; - - /** - * A pluggable updater that can be used to "update" the JPA project either - * synchronously or asynchronously (or not at all). A synchronous updater - * is the default, allowing a newly-constructed JPA project to be "updated" - * upon return from the constructor. For performance reasons, a UI should - * immediately change this to an asynchronous updater. A synchronous - * updater can be used when the project is being manipulated by a "batch" - * (or non-UI) client (e.g. when testing the "update" behavior). A null - * updater can used during tests that do not care whether "updates" occur. - * Clients will need to explicitly configure the updater if they require - * something other than a synchronous updater. - */ - protected Updater updater; - - /** - * The data source that wraps the DTP model. - */ - protected final JpaDataSource dataSource; - - /** - * A catalog name used to override the connection's default catalog. - */ - protected String userOverrideDefaultCatalog; - - /** - * A schema name used to override the connection's default schema. - */ - protected String userOverrideDefaultSchema; - - /** - * Flag indicating whether the project should "discover" annotated - * classes automatically, as opposed to requiring the classes to be - * listed in persistence.xml. - */ - protected boolean discoversAnnotatedClasses; - - /** - * Support for modifying documents shared with the UI. - */ - protected final ThreadLocalCommandExecutor modifySharedDocumentCommandExecutor; - - - //********* 2.0 static metamodel ************** - protected final StaticMetamodelSynchronizer staticMetamodelSynchronizer; - protected final Job staticMetamodelSynchronizationJob; - protected boolean generatesStaticMetamodel = false; - - // ********** constructor/initialization ********** - - protected AbstractJpaProject(JpaProject.Config config) throws CoreException { - super(null); // JPA project is the root of the containment tree - if ((config.getProject() == null) || (config.getJpaPlatform() == null)) { - throw new NullPointerException(); - } - this.project = config.getProject(); - this.jpaPlatform = config.getJpaPlatform(); - this.dataSource = this.getJpaFactory().buildJpaDataSource(this, config.getConnectionProfileName()); - this.userOverrideDefaultCatalog = config.getUserOverrideDefaultCatalog(); - this.userOverrideDefaultSchema = config.getUserOverrideDefaultSchema(); - this.discoversAnnotatedClasses = config.discoverAnnotatedClasses(); - - this.modifySharedDocumentCommandExecutor = this.buildModifySharedDocumentCommandExecutor(); - - this.resourceModelListener = this.buildResourceModelListener(); - // build the JPA files corresponding to the Eclipse project's files - this.project.accept(this.buildInitialResourceProxyVisitor(), IResource.NONE); - - this.externalJavaResourcePersistentTypeCache = this.buildExternalJavaResourcePersistentTypeCache(); - - this.rootContextNode = this.buildRootContextNode(); - - this.staticMetamodelSynchronizer = this.buildStaticMetamodelSynchronizer(); - this.staticMetamodelSynchronizationJob = this.buildStaticMetamodelSynchronizationJob(); - - // "update" the project before returning - this.setUpdater_(new SynchronousJpaProjectUpdater(this)); - - // start listening to this cache once the context model has been built - // and all the external types are faulted in - this.externalJavaResourcePersistentTypeCache.addResourceModelListener(this.resourceModelListener); - } - - @Override - protected boolean requiresParent() { - return false; - } - - @Override - public IResource getResource() { - return this.project; - } - - protected ThreadLocalCommandExecutor buildModifySharedDocumentCommandExecutor() { - return new ThreadLocalCommandExecutor(); - } - - protected JpaResourceModelListener buildResourceModelListener() { - return new DefaultResourceModelListener(); - } - - protected IResourceProxyVisitor buildInitialResourceProxyVisitor() { - return new InitialResourceProxyVisitor(); - } - - protected JavaResourcePersistentTypeCache buildExternalJavaResourcePersistentTypeCache() { - return new BinaryPersistentTypeCache(this.jpaPlatform.getAnnotationProvider()); - } - - protected JpaRootContextNode buildRootContextNode() { - return this.getJpaFactory().buildRootContextNode(this); - } - - protected StaticMetamodelSynchronizer buildStaticMetamodelSynchronizer() { - return ((JpaFactory2_0) this.getJpaFactory()).buildStaticMetamodelSynchronizer(this); - } - - protected Job buildStaticMetamodelSynchronizationJob() { - String jobName = NLS.bind(JptCoreMessages.SYNCHRONIZE_STATIC_METAMODEL_JOB_NAME, this.getName()); - Job job = new Job(jobName) { - @Override - protected IStatus run(IProgressMonitor monitor) { - AbstractJpaProject.this.synchronizeStaticMetamodel_(); - return Status.OK_STATUS; - } - }; - job.setRule(this.project); - return job; - } - - // ***** inner class - protected class InitialResourceProxyVisitor implements IResourceProxyVisitor { - protected InitialResourceProxyVisitor() { - super(); - } - // add a JPA file for every [appropriate] file encountered by the visitor - public boolean visit(IResourceProxy resource) throws CoreException { - switch (resource.getType()) { - case IResource.ROOT : // shouldn't happen - return true; // visit children - case IResource.PROJECT : - return true; // visit children - case IResource.FOLDER : - return true; // visit children - case IResource.FILE : - AbstractJpaProject.this.addJpaFile_((IFile) resource.requestResource()); - return false; // no children - default : - return false; // no children - } - } - } - - - // ********** miscellaneous ********** - - /** - * Ignore changes to this collection. Adds can be ignored since they are triggered - * by requests that will, themselves, trigger updates (typically during the - * update of an object that calls a setter with the newly-created resource - * type). Deletes will be accompanied by manual updates. - */ - @Override - protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) { - super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - nonUpdateAspectNames.add(EXTERNAL_JAVA_RESOURCE_COMPILATION_UNITS_COLLECTION); - } - - - // ********** general queries ********** - - @Override - public JpaProject getJpaProject() { - return this; - } - - public String getName() { - return this.project.getName(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - public IProject getProject() { - return this.project; - } - - public IJavaProject getJavaProject() { - return JavaCore.create(this.project); - } - - @Override - public JpaPlatform getJpaPlatform() { - return this.jpaPlatform; - } - - @SuppressWarnings("unchecked") - protected Iterable<JavaResourceCompilationUnit> getCombinedJavaResourceCompilationUnits() { - return new CompositeIterable<JavaResourceCompilationUnit>( - this.getInternalJavaResourceCompilationUnits(), - this.getExternalJavaResourceCompilationUnits() - ); - } - - - // ********** database ********** - - @Override - public JpaDataSource getDataSource() { - return this.dataSource; - } - - public ConnectionProfile getConnectionProfile() { - return this.dataSource.getConnectionProfile(); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDefaultDbCatalog() { - String catalog = this.getDefaultCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - public String getDefaultCatalog() { - String catalog = this.getUserOverrideDefaultCatalog(); - return (catalog != null) ? catalog : this.getDatabaseDefaultCatalog(); - } - - protected String getDatabaseDefaultCatalog() { - Database db = this.getDatabase(); - return (db == null ) ? null : db.getDefaultCatalogIdentifier(); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDefaultDbSchemaContainer() { - String catalog = this.getDefaultCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - public Schema getDefaultDbSchema() { - SchemaContainer sc = this.getDefaultDbSchemaContainer(); - return (sc == null) ? null : sc.getSchemaForIdentifier(this.getDefaultSchema()); - } - - public String getDefaultSchema() { - String schema = this.getUserOverrideDefaultSchema(); - if (schema != null) { - return schema; - } - - String catalog = this.getDefaultCatalog(); - if (catalog == null) { - // if there is no default catalog (either user-override or database-determined), - // the database probably does not support catalogs; - // return the database's default schema - return this.getDatabaseDefaultSchema(); - } - - Catalog dbCatalog = this.getDbCatalog(catalog); - if (dbCatalog != null) { - return dbCatalog.getDefaultSchemaIdentifier(); - } - - // if we could not find a catalog on the database that matches the default - // catalog name, return the database's default schema(?) - hmmm - return this.getDatabaseDefaultSchema(); - } - - protected String getDatabaseDefaultSchema() { - Database db = this.getDatabase(); - return (db == null ) ? null : db.getDefaultSchemaIdentifier(); - } - - - // ********** user override default catalog ********** - - public String getUserOverrideDefaultCatalog() { - return this.userOverrideDefaultCatalog; - } - - public void setUserOverrideDefaultCatalog(String catalog) { - String old = this.userOverrideDefaultCatalog; - this.userOverrideDefaultCatalog = catalog; - JptCorePlugin.setUserOverrideDefaultCatalog(this.project, catalog); - this.firePropertyChanged(USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - - // ********** user override default schema ********** - - public String getUserOverrideDefaultSchema() { - return this.userOverrideDefaultSchema; - } - - public void setUserOverrideDefaultSchema(String schema) { - String old = this.userOverrideDefaultSchema; - this.userOverrideDefaultSchema = schema; - JptCorePlugin.setUserOverrideDefaultSchema(this.project, schema); - this.firePropertyChanged(USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - - // ********** discover annotated classes ********** - - public boolean discoversAnnotatedClasses() { - return this.discoversAnnotatedClasses; - } - - public void setDiscoversAnnotatedClasses(boolean discoversAnnotatedClasses) { - boolean old = this.discoversAnnotatedClasses; - this.discoversAnnotatedClasses = discoversAnnotatedClasses; - JptCorePlugin.setDiscoverAnnotatedClasses(this.project, discoversAnnotatedClasses); - this.firePropertyChanged(DISCOVERS_ANNOTATED_CLASSES_PROPERTY, old, discoversAnnotatedClasses); - } - - - // ********** JPA files ********** - - public Iterator<JpaFile> jpaFiles() { - return this.getJpaFiles().iterator(); - } - - protected Iterable<JpaFile> getJpaFiles() { - return new LiveCloneIterable<JpaFile>(this.jpaFiles); // read-only - } - - public int jpaFilesSize() { - return this.jpaFiles.size(); - } - - protected Iterable<JpaFile> getJpaFiles(final IContentType contentType) { - return new FilteringIterable<JpaFile, JpaFile>(this.getJpaFiles()) { - @Override - protected boolean accept(JpaFile jpaFile) { - return jpaFile.getContentType().isKindOf(contentType); - } - }; - } - - @Override - public JpaFile getJpaFile(IFile file) { - for (JpaFile jpaFile : this.getJpaFiles()) { - if (jpaFile.getFile().equals(file)) { - return jpaFile; - } - } - return null; - } - - /** - * Add a JPA file for the specified file, if appropriate. - * Return true if a JPA File was created and added, false otherwise - */ - protected boolean addJpaFile(IFile file) { - JpaFile jpaFile = this.addJpaFile_(file); - if (jpaFile != null) { - this.fireItemAdded(JPA_FILES_COLLECTION, jpaFile); - return true; - } - return false; - } - - /** - * Add a JPA file for the specified file, if appropriate, without firing - * an event; useful during construction. - * Return the new JPA file, null if it was not created. - */ - protected JpaFile addJpaFile_(IFile file) { - if ( ! this.getJavaProject().isOnClasspath(file)) { - return null; // the file must be on the Java classpath - } - - JpaFile jpaFile = this.getJpaPlatform().buildJpaFile(this, file); - if (jpaFile == null) { - return null; - } - jpaFile.getResourceModel().addResourceModelListener(this.resourceModelListener); - this.jpaFiles.add(jpaFile); - return jpaFile; - } - - /** - * Remove the JPA file corresponding to the specified IFile, if it exists. - * Return true if a JPA File was removed, false otherwise - */ - protected boolean removeJpaFile(IFile file) { - JpaFile jpaFile = this.getJpaFile(file); - if (jpaFile != null) { // a JpaFile is not added for every IFile - this.removeJpaFile(jpaFile); - return true; - } - return false; - } - - /** - * Stop listening to the JPA file and remove it. - */ - protected void removeJpaFile(JpaFile jpaFile) { - jpaFile.getResourceModel().removeResourceModelListener(this.resourceModelListener); - if ( ! this.removeItemFromCollection(jpaFile, this.jpaFiles, JPA_FILES_COLLECTION)) { - throw new IllegalArgumentException(jpaFile.toString()); - } - } - - - // ********** external Java resource persistent types (source or binary) ********** - - protected JavaResourcePersistentType buildPersistableExternalJavaResourcePersistentType(String typeName) { - IType jdtType = this.findType(typeName); - return (jdtType == null) ? null : this.buildPersistableExternalJavaResourcePersistentType(jdtType); - } - - protected IType findType(String typeName) { - try { - return this.getJavaProject().findType(typeName); - } catch (JavaModelException ex) { - return null; // ignore exception? - } - } - - protected JavaResourcePersistentType buildPersistableExternalJavaResourcePersistentType(IType jdtType) { - JavaResourcePersistentType jrpt = this.buildExternalJavaResourcePersistentType(jdtType); - return ((jrpt != null) && jrpt.isPersistable()) ? jrpt : null; - } - - protected JavaResourcePersistentType buildExternalJavaResourcePersistentType(IType jdtType) { - return jdtType.isBinary() ? - this.buildBinaryExternalJavaResourcePersistentType(jdtType) : - this.buildSourceExternalJavaResourcePersistentType(jdtType); - } - - protected JavaResourcePersistentType buildBinaryExternalJavaResourcePersistentType(IType jdtType) { - return this.externalJavaResourcePersistentTypeCache.addPersistentType(jdtType); - } - - protected JavaResourcePersistentType buildSourceExternalJavaResourcePersistentType(IType jdtType) { - JavaResourceCompilationUnit jrcu = this.getExternalJavaResourceCompilationUnit(jdtType.getCompilationUnit()); - String jdtTypeName = jdtType.getFullyQualifiedName('.'); // JDT member type names use '$' - for (Iterator<JavaResourcePersistentType> stream = jrcu.persistentTypes(); stream.hasNext(); ) { - JavaResourcePersistentType jrpt = stream.next(); - if (jrpt.getQualifiedName().equals(jdtTypeName)) { - return jrpt; - } - } - // we can get here if the project JRE is removed; - // see SourceCompilationUnit#getPrimaryType(CompilationUnit) - // bug 225332 - return null; - } - - - // ********** external Java resource persistent types (binary) ********** - - public JavaResourcePersistentTypeCache getExternalJavaResourcePersistentTypeCache() { - return this.externalJavaResourcePersistentTypeCache; - } - - - // ********** external Java resource compilation units (source) ********** - - public Iterator<JavaResourceCompilationUnit> externalJavaResourceCompilationUnits() { - return this.getExternalJavaResourceCompilationUnits().iterator(); - } - - protected Iterable<JavaResourceCompilationUnit> getExternalJavaResourceCompilationUnits() { - return new LiveCloneIterable<JavaResourceCompilationUnit>(this.externalJavaResourceCompilationUnits); // read-only - } - - public int externalJavaResourceCompilationUnitsSize() { - return this.externalJavaResourceCompilationUnits.size(); - } - - /** - * Return the resource model compilation unit corresponding to the specified - * JDT compilation unit. If it does not exist, build it. - */ - protected JavaResourceCompilationUnit getExternalJavaResourceCompilationUnit(ICompilationUnit jdtCompilationUnit) { - for (JavaResourceCompilationUnit jrcu : this.getExternalJavaResourceCompilationUnits()) { - if (jrcu.getCompilationUnit().equals(jdtCompilationUnit)) { - // we will get here if the JRCU could not build its persistent type... - return jrcu; - } - } - return this.addExternalJavaResourceCompilationUnit(jdtCompilationUnit); - } - - /** - * Add an external Java resource compilation unit. - */ - protected JavaResourceCompilationUnit addExternalJavaResourceCompilationUnit(ICompilationUnit jdtCompilationUnit) { - JavaResourceCompilationUnit jrcu = this.buildJavaResourceCompilationUnit(jdtCompilationUnit); - this.addItemToCollection(jrcu, this.externalJavaResourceCompilationUnits, EXTERNAL_JAVA_RESOURCE_COMPILATION_UNITS_COLLECTION); - jrcu.addResourceModelListener(this.resourceModelListener); - return jrcu; - } - - protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit jdtCompilationUnit) { - return new SourceCompilationUnit( - jdtCompilationUnit, - this.jpaPlatform.getAnnotationProvider(), - this.jpaPlatform.getAnnotationEditFormatter(), - this.modifySharedDocumentCommandExecutor - ); - } - - protected boolean removeExternalJavaResourceCompilationUnit(IFile file) { - for (JavaResourceCompilationUnit jrcu : this.getExternalJavaResourceCompilationUnits()) { - if (jrcu.getFile().equals(file)) { - this.removeExternalJavaResourceCompilationUnit(jrcu); - return true; - } - } - return false; - } - - protected void removeExternalJavaResourceCompilationUnit(JavaResourceCompilationUnit jrcu) { - jrcu.removeResourceModelListener(this.resourceModelListener); - this.removeItemFromCollection(jrcu, this.externalJavaResourceCompilationUnits, EXTERNAL_JAVA_RESOURCE_COMPILATION_UNITS_COLLECTION); - } - - - // ********** context model ********** - - public JpaRootContextNode getRootContextNode() { - return this.rootContextNode; - } - - - // ********** utility ********** - - public IFile convertToPlatformFile(String fileName) { - return JptCorePlugin.getPlatformFile(this.project, fileName); - } - - - // ********** XML files ********** - - public JpaXmlResource getPersistenceXmlResource() { - return (JpaXmlResource) this.getResourceModel( - JptCorePlugin.DEFAULT_PERSISTENCE_XML_FILE_PATH, - JptCorePlugin.PERSISTENCE_FILE_CONTENT_TYPE - ); - } - - public JpaXmlResource getDefaultOrmXmlResource() { - return this.getMappingFileXmlResource(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - } - - public JpaXmlResource getMappingFileXmlResource(String fileName) { - return (JpaXmlResource) this.getResourceModel(fileName, JptCorePlugin.MAPPING_FILE_CONTENT_TYPE); - } - - /** - * If the specified file exists, is significant to the JPA project, and its - * content is a "kind of" the specified content type, return the JPA - * resource model corresponding to the file; otherwise, return null. - */ - protected JpaResourceModel getResourceModel(String fileName, IContentType contentType) { - IFile file = this.convertToPlatformFile(fileName); - return file.exists() ? this.getResourceModel(file, contentType) : null; - } - - /** - * If the specified file is significant to the JPA project and its content - * is a "kind of" the specified content type, return the JPA resource model - * corresponding to the file; otherwise, return null. - */ - protected JpaResourceModel getResourceModel(IFile file, IContentType contentType) { - JpaFile jpaFile = this.getJpaFile(file); - return (jpaFile == null) ? null : jpaFile.getResourceModel(contentType); - } - - - // ********** annotated Java source classes ********** - - public Iterator<String> annotatedJavaSourceClassNames() { - return getAnnotatedJavaSourceClassNames().iterator(); - } - - protected Iterable<String> getAnnotatedJavaSourceClassNames() { - return new TransformationIterable<JavaResourcePersistentType, String>( - getInternalAnnotatedSourceJavaResourcePersistentTypes()) { - @Override - protected String transform(JavaResourcePersistentType jrpType) { - return jrpType.getQualifiedName(); - } - }; - } - - /** - * return only those valid annotated Java resource persistent types that are part of the - * JPA project, ignoring those in JARs referenced in persistence.xml - * @see org.eclipse.jpt.core.internal.utility.jdt.JPTTools#typeIsPersistable(org.eclipse.jpt.core.internal.utility.jdt.JPTTools.TypeAdapter) - */ - protected Iterable<JavaResourcePersistentType> getInternalAnnotatedSourceJavaResourcePersistentTypes() { - return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType>( - getInternalSourceJavaResourcePersistentTypes()) { - @Override - protected boolean accept(JavaResourcePersistentType jrpType) { - return jrpType.isPersistable() && jrpType.isAnnotated(); // i.e. the type is valid and has a valid type annotation - } - }; - } - - public Iterator<String> mappedJavaSourceClassNames() { - return this.getMappedJavaSourceClassNames().iterator(); - } - - protected Iterable<String> getMappedJavaSourceClassNames() { - return new TransformationIterable<JavaResourcePersistentType, String>( - getInternalMappedSourceJavaResourcePersistentTypes()) { - @Override - protected String transform(JavaResourcePersistentType jrpType) { - return jrpType.getQualifiedName(); - } - }; - } - - /** - * return only those valid "mapped" (i.e. annotated with @Entity, @Embeddable, etc.) Java - * resource persistent types that are part of the JPA project, ignoring those in JARs - * referenced in persistence.xml - */ - protected Iterable<JavaResourcePersistentType> getInternalMappedSourceJavaResourcePersistentTypes() { - return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType>( - getInternalAnnotatedSourceJavaResourcePersistentTypes()) { - @Override - protected boolean accept(JavaResourcePersistentType jrpType) { - return jrpType.isMapped(); // i.e. the type is already persistable and annotated - } - }; - } - - /** - * return only those Java resource persistent types that are - * part of the JPA project, ignoring those in JARs referenced in persistence.xml - */ - protected Iterable<JavaResourcePersistentType> getInternalSourceJavaResourcePersistentTypes() { - return new CompositeIterable<JavaResourcePersistentType>(this.getInternalSourceJavaResourcePersistentTypeSets()); - } - - /** - * return only those Java resource persistent types that are - * part of the JPA project, ignoring those in JARs referenced in persistence.xml - */ - protected Iterable<Iterable<JavaResourcePersistentType>> getInternalSourceJavaResourcePersistentTypeSets() { - return new TransformationIterable<JavaResourceCompilationUnit, Iterable<JavaResourcePersistentType>>(this.getInternalJavaResourceCompilationUnits()) { - @Override - protected Iterable<JavaResourcePersistentType> transform(final JavaResourceCompilationUnit compilationUnit) { - return new Iterable<JavaResourcePersistentType>() { - public Iterator<JavaResourcePersistentType> iterator() { - return compilationUnit.persistentTypes(); // *all* the types in the compilation unit - } - }; - } - }; - } - - protected Iterable<JavaResourceCompilationUnit> getInternalJavaResourceCompilationUnits() { - return new TransformationIterable<JpaFile, JavaResourceCompilationUnit>(this.getJavaSourceJpaFiles()) { - @Override - protected JavaResourceCompilationUnit transform(JpaFile jpaFile) { - return (JavaResourceCompilationUnit) jpaFile.getResourceModel(); - } - }; - } - - /** - * return JPA files with Java source "content" - */ - protected Iterable<JpaFile> getJavaSourceJpaFiles() { - return this.getJpaFiles(JptCorePlugin.JAVA_SOURCE_CONTENT_TYPE); - } - - - // ********** Java resource persistent type look-up ********** - - public JavaResourcePersistentType getJavaResourcePersistentType(String typeName) { - for (JavaResourcePersistentType jrpType : this.getPersistableJavaResourcePersistentTypes()) { - if (jrpType.getQualifiedName().equals(typeName)) { - return jrpType; - } - } - // if we don't have a type already, try to build new one from the project classpath - return this.buildPersistableExternalJavaResourcePersistentType(typeName); - } - - /** - * return *all* the "persistable" Java resource persistent types, including those in JARs referenced in - * persistence.xml - * @see org.eclipse.jpt.core.internal.utility.jdt.JPTTools#typeIsPersistable(org.eclipse.jpt.core.internal.utility.jdt.JPTTools.TypeAdapter) - */ - protected Iterable<JavaResourcePersistentType> getPersistableJavaResourcePersistentTypes() { - return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType>(this.getJavaResourcePersistentTypes()) { - @Override - protected boolean accept(JavaResourcePersistentType jrpType) { - return jrpType.isPersistable(); - } - }; - } - - /** - * return *all* the Java resource persistent types, including those in JARs referenced in - * persistence.xml - */ - protected Iterable<JavaResourcePersistentType> getJavaResourcePersistentTypes() { - return new CompositeIterable<JavaResourcePersistentType>(this.getJavaResourcePersistentTypeSets()); - } - - /** - * return *all* the Java resource persistent types, including those in JARs referenced in - * persistence.xml - */ - protected Iterable<Iterable<JavaResourcePersistentType>> getJavaResourcePersistentTypeSets() { - return new TransformationIterable<JavaResourceNode.Root, Iterable<JavaResourcePersistentType>>(this.getJavaResourceNodeRoots()) { - @Override - protected Iterable<JavaResourcePersistentType> transform(final JavaResourceNode.Root root) { - return new Iterable<JavaResourcePersistentType>() { - public Iterator<JavaResourcePersistentType> iterator() { - return root.persistentTypes(); // *all* the types held by the root - } - }; - } - }; - } - - @SuppressWarnings("unchecked") - protected Iterable<JavaResourceNode.Root> getJavaResourceNodeRoots() { - return new CompositeIterable<JavaResourceNode.Root>( - this.getInternalJavaResourceCompilationUnits(), - this.getInternalJavaResourcePackageFragmentRoots(), - this.getExternalJavaResourceCompilationUnits(), - Collections.singleton(this.externalJavaResourcePersistentTypeCache) - ); - } - - - // ********** JARs ********** - - // TODO - public JavaResourcePackageFragmentRoot getJavaResourcePackageFragmentRoot(String jarFileName) { -// return this.getJarResourcePackageFragmentRoot(this.convertToPlatformFile(jarFileName)); - return this.getJavaResourcePackageFragmentRoot(this.getProject().getFile(jarFileName)); - } - - protected JavaResourcePackageFragmentRoot getJavaResourcePackageFragmentRoot(IFile jarFile) { - for (JavaResourcePackageFragmentRoot pfr : this.getInternalJavaResourcePackageFragmentRoots()) { - if (pfr.getFile().equals(jarFile)) { - return pfr; - } - } - return null; - } - - protected Iterable<JavaResourcePackageFragmentRoot> getInternalJavaResourcePackageFragmentRoots() { - return new TransformationIterable<JpaFile, JavaResourcePackageFragmentRoot>(this.getJarJpaFiles()) { - @Override - protected JavaResourcePackageFragmentRoot transform(JpaFile jpaFile) { - return (JavaResourcePackageFragmentRoot) jpaFile.getResourceModel(); - } - }; - } - - /** - * return JPA files with JAR "content" - */ - protected Iterable<JpaFile> getJarJpaFiles() { - return this.getJpaFiles(JptCorePlugin.JAR_CONTENT_TYPE); - } - - // ********** Static Metamodel ********** - - /** - * Will only synchronize the static metamodel for 2.0 compatible projects - */ - public void synchronizeStaticMetamodel() { - if (this.generatesStaticMetamodel) { - if (getJpaPlatformVersion().is2_0Compatible()) { - if (this.staticMetamodelSynchronizationJob != null) { - this.staticMetamodelSynchronizationJob.schedule(); - } - } - } - } - - protected void synchronizeStaticMetamodel_() { - ((JpaRootContextNode2_0) this.getRootContextNode()).synchronizeStaticMetamodel(); - } - - public void synchronizeStaticMetamodel(PersistentType persistentType) { - this.staticMetamodelSynchronizer.synchronize(persistentType); - } - - // TODO - public IPackageFragmentRoot getStaticMetaModelSourceFolder() { - return this.getJavaProject().getPackageFragmentRoot(this.getProject().getFolder("src")); - } - - // ********** Java events ********** - - // TODO handle changes to external projects - public void javaElementChanged(ElementChangedEvent event) { - this.synchWithJavaDelta(event.getDelta()); - } - - /** - * We recurse back here when processing 'affectedChildren'. - */ - protected void synchWithJavaDelta(IJavaElementDelta delta) { - switch (delta.getElement().getElementType()) { - case IJavaElement.JAVA_MODEL : - this.javaModelChanged(delta); - break; - case IJavaElement.JAVA_PROJECT : - this.javaProjectChanged(delta); - break; - case IJavaElement.PACKAGE_FRAGMENT_ROOT : - this.javaPackageFragmentRootChanged(delta); - break; - case IJavaElement.PACKAGE_FRAGMENT : - this.javaPackageFragmentChanged(delta); - break; - case IJavaElement.COMPILATION_UNIT : - this.javaCompilationUnitChanged(delta); - break; - default : - break; // ignore the elements inside a compilation unit - } - } - - protected void synchWithJavaDeltaChildren(IJavaElementDelta delta) { - for (IJavaElementDelta child : delta.getAffectedChildren()) { - this.synchWithJavaDelta(child); // recurse - } - } - - // ***** model - protected void javaModelChanged(IJavaElementDelta delta) { - // process the java model's projects - this.synchWithJavaDeltaChildren(delta); - } - - // ***** project - protected void javaProjectChanged(IJavaElementDelta delta) { - // process the java project's package fragment roots - this.synchWithJavaDeltaChildren(delta); - - if (this.classpathHasChanged(delta)) { - if (delta.getElement().equals(this.getJavaProject())) { - this.update(this.getInternalJavaResourceCompilationUnits()); - } else { - // TODO see if changed project is on our classpath? - this.update(this.getExternalJavaResourceCompilationUnits()); - } - } - } - - protected boolean classpathHasChanged(IJavaElementDelta delta) { - return BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED); - } - - protected void update(Iterable<JavaResourceCompilationUnit> javaResourceCompilationUnits) { - for (JavaResourceCompilationUnit javaResourceCompilationUnit : javaResourceCompilationUnits) { - javaResourceCompilationUnit.update(); - } - } - - // ***** package fragment root - protected void javaPackageFragmentRootChanged(IJavaElementDelta delta) { - // process the java package fragment root's package fragments - this.synchWithJavaDeltaChildren(delta); - - if (this.classpathEntryHasBeenAdded(delta)) { - // TODO - } else if (this.classpathEntryHasBeenRemoved(delta)) { // should be mutually-exclusive w/added (?) - // TODO - } - } - - protected boolean classpathEntryHasBeenAdded(IJavaElementDelta delta) { - return BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_ADDED_TO_CLASSPATH); - } - - protected boolean classpathEntryHasBeenRemoved(IJavaElementDelta delta) { - return BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_REMOVED_FROM_CLASSPATH); - } - - // ***** package fragment - protected void javaPackageFragmentChanged(IJavaElementDelta delta) { - // process the java package fragment's compilation units - this.synchWithJavaDeltaChildren(delta); - } - - // ***** compilation unit - protected void javaCompilationUnitChanged(IJavaElementDelta delta) { - if (this.javaCompilationUnitDeltaIsRelevant(delta)) { - ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement(); - for (JavaResourceCompilationUnit jrcu : this.getCombinedJavaResourceCompilationUnits()) { - if (jrcu.getCompilationUnit().equals(compilationUnit)) { - jrcu.update(); - // TODO ? this.resolveJavaTypes(); // might have new member types now... - break; // there *shouldn't* be any more... - } - } - } - // ignore the java compilation unit's children - } - - protected boolean javaCompilationUnitDeltaIsRelevant(IJavaElementDelta delta) { - // ignore changes to/from primary working copy - no content has changed; - // and make sure there are no other flags set that indicate *both* a - // change to/from primary working copy *and* content has changed - if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) { - return false; - } - - // ignore java notification for ADDED or REMOVED; - // these are handled via resource notification - return delta.getKind() == IJavaElementDelta.CHANGED; - } - - - // ********** validation ********** - - public Iterator<IMessage> validationMessages(IReporter reporter) { - List<IMessage> messages = new ArrayList<IMessage>(); - this.validate(messages, reporter); - return messages.iterator(); - } - - protected void validate(List<IMessage> messages, IReporter reporter) { - if (reporter.isCancelled()) { - throw new ValidationCancelledException(); - } - this.validateConnection(messages); - this.rootContextNode.validate(messages, reporter); - } - - protected void validateConnection(List<IMessage> messages) { - String cpName = this.dataSource.getConnectionProfileName(); - if (StringTools.stringIsEmpty(cpName)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PROJECT_NO_CONNECTION, - this - ) - ); - return; - } - ConnectionProfile cp = this.dataSource.getConnectionProfile(); - if (cp == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PROJECT_INVALID_CONNECTION, - new String[] {cpName}, - this - ) - ); - return; - } - if (cp.isInactive()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PROJECT_INACTIVE_CONNECTION, - new String[] {cpName}, - this - ) - ); - } - } - - - // ********** dispose ********** - - public void dispose() { - this.updater.stop(); - this.dataSource.dispose(); - } - - - // ********** resource model listener ********** - - protected class DefaultResourceModelListener implements JpaResourceModelListener { - protected DefaultResourceModelListener() { - super(); - } - public void resourceModelChanged() { - AbstractJpaProject.this.update(); - } - } - - - // ********** resource events ********** - - // TODO need to do the same thing for external projects and compilation units - public void projectChanged(IResourceDelta delta) throws CoreException { - if (delta.getResource().equals(this.getProject())) { - this.internalProjectChanged(delta); - } else { - this.externalProjectChanged(delta); - } - } - - protected void internalProjectChanged(IResourceDelta delta) throws CoreException { - ResourceDeltaVisitor resourceDeltaVisitor = this.buildInternalResourceDeltaVisitor(); - delta.accept(resourceDeltaVisitor); - // at this point, if we have added and/or removed JpaFiles, an "update" will have been triggered; - // any changes to the resource model during the "resolve" will trigger further "updates"; - // there should be no need to "resolve" external Java types (they can't have references to - // the internal Java types) - if (resourceDeltaVisitor.encounteredSignificantChange()) { - this.resolveInternalJavaTypes(); - } - } - - protected ResourceDeltaVisitor buildInternalResourceDeltaVisitor() { - return new ResourceDeltaVisitor() { - @Override - public boolean fileChangeIsSignificant(IFile file, int deltaKind) { - return AbstractJpaProject.this.synchronizeJpaFiles(file, deltaKind); - } - }; - } - - /** - * Internal resource delta visitor callback. - * Return true if a JpaFile was either added or removed. - */ - protected boolean synchronizeJpaFiles(IFile file, int deltaKind) { - switch (deltaKind) { - case IResourceDelta.ADDED : - return this.addJpaFile(file); - case IResourceDelta.REMOVED : - return this.removeJpaFile(file); - case IResourceDelta.CHANGED : - return this.checkForChangedFileContent(file); - case IResourceDelta.ADDED_PHANTOM : - break; // ignore - case IResourceDelta.REMOVED_PHANTOM : - break; // ignore - default : - break; // only worried about added/removed/changed files - } - - return false; - } - - protected boolean checkForChangedFileContent(IFile file) { - JpaFile jpaFile = this.getJpaFile(file); - if (jpaFile == null) { - // the file might have changed its content to something that we are interested in - return this.addJpaFile(file); - } - - if (jpaFile.getContentType().equals(PlatformTools.getContentType(file))) { - // content has not changed - ignore - return false; - } - - // the content type changed, we need to build a new JPA file - // (e.g. the schema of an orm.xml file changed from JPA to EclipseLink) - this.removeJpaFile(jpaFile); - this.addJpaFile(file); - return true; // at the least, we have removed a JPA file - } - - protected void resolveInternalJavaTypes() { - for (JavaResourceCompilationUnit jrcu : this.getInternalJavaResourceCompilationUnits()) { - jrcu.resolveTypes(); - } - } - - protected void externalProjectChanged(IResourceDelta delta) throws CoreException { - if (this.getJavaProject().isOnClasspath(delta.getResource())) { - ResourceDeltaVisitor resourceDeltaVisitor = this.buildExternalResourceDeltaVisitor(); - delta.accept(resourceDeltaVisitor); - // force an "update" here since adding and/or removing an external Java type - // will only trigger an "update" if the "resolve" causes something in the resource model to change - if (resourceDeltaVisitor.encounteredSignificantChange()) { - this.update(); - this.resolveExternalJavaTypes(); - this.resolveInternalJavaTypes(); - } - } - } - - protected ResourceDeltaVisitor buildExternalResourceDeltaVisitor() { - return new ResourceDeltaVisitor() { - @Override - public boolean fileChangeIsSignificant(IFile file, int deltaKind) { - return AbstractJpaProject.this.synchronizeExternalFiles(file, deltaKind); - } - }; - } - - /** - * external resource delta visitor callback - * Return true if an "external" Java resource compilation unit - * was added or removed. - */ - protected boolean synchronizeExternalFiles(IFile file, int deltaKind) { - switch (deltaKind) { - case IResourceDelta.ADDED : - return this.externalFileAdded(file); - case IResourceDelta.REMOVED : - return this.externalFileRemoved(file); - case IResourceDelta.CHANGED : - break; // ignore - case IResourceDelta.ADDED_PHANTOM : - break; // ignore - case IResourceDelta.REMOVED_PHANTOM : - break; // ignore - default : - break; // only worried about added/removed/changed files - } - - return false; - } - - protected boolean externalFileAdded(IFile file) { - IContentType contentType = PlatformTools.getContentType(file); - if (contentType == null) { - return false; - } - if (contentType.equals(JptCorePlugin.JAVA_SOURCE_CONTENT_TYPE)) { - return true; - } - if (contentType.equals(JptCorePlugin.JAR_CONTENT_TYPE)) { - return true; - } - return false; - } - - protected boolean externalFileRemoved(IFile file) { - IContentType contentType = PlatformTools.getContentType(file); - if (contentType == null) { - return false; - } - if (contentType.equals(JptCorePlugin.JAVA_SOURCE_CONTENT_TYPE)) { - return this.removeExternalJavaResourceCompilationUnit(file); - } - if (contentType.equals(JptCorePlugin.JAR_CONTENT_TYPE)) { - return this.externalJavaResourcePersistentTypeCache.removePersistentTypes(file); - } - return false; - } - - protected void resolveExternalJavaTypes() { - for (JavaResourceCompilationUnit jrcu : this.getExternalJavaResourceCompilationUnits()) { - jrcu.resolveTypes(); - } - } - - // ***** resource delta visitors - /** - * add or remove a JPA file for every [appropriate] file encountered by the visitor - */ - protected abstract class ResourceDeltaVisitor implements IResourceDeltaVisitor { - protected boolean encounteredSignificantChange = false; - - protected ResourceDeltaVisitor() { - super(); - } - - public boolean visit(IResourceDelta delta) throws CoreException { - IResource res = delta.getResource(); - switch (res.getType()) { - case IResource.ROOT : - return true; // visit children - case IResource.PROJECT : - return true; // visit children - case IResource.FOLDER : - return true; // visit children - case IResource.FILE : - this.fileChanged((IFile) res, delta.getKind()); - return false; // no children - default : - return false; // no children (probably shouldn't get here...) - } - } - - protected void fileChanged(IFile file, int deltaKind) { - if (this.fileChangeIsSignificant(file, deltaKind)) { - this.encounteredSignificantChange = true; - } - } - - protected abstract boolean fileChangeIsSignificant(IFile file, int deltaKind); - - /** - * Return whether the visitor encountered some sort of "significant" - * change while traversing the IResourceDelta - * (e.g. a JPA file was added or removed). - */ - protected boolean encounteredSignificantChange() { - return this.encounteredSignificantChange; - } - - } - - - // ********** support for modifying documents shared with the UI ********** - - public void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor) { - this.modifySharedDocumentCommandExecutor.set(commandExecutor); - } - - public CommandExecutor getModifySharedDocumentCommandExecutor() { - return this.modifySharedDocumentCommandExecutor; - } - - - // ********** project "update" ********** - - public Updater getUpdater() { - return this.updater; - } - - public void setUpdater(Updater updater) { - if (updater == null) { - throw new NullPointerException(); - } - this.updater.stop(); - this.setUpdater_(updater); - } - - protected void setUpdater_(Updater updater) { - this.updater = updater; - this.updater.start(); - } - - /** - * Delegate to the updater so clients can configure how updates occur. - */ - public void update() { - this.updater.update(); - } - - /** - * Called by the updater. - */ - public IStatus update(IProgressMonitor monitor) { - this.update_(monitor); - return Status.OK_STATUS; - } - - protected void update_(IProgressMonitor monitor) { - this.rootContextNode.update(monitor); - this.rootContextNode.postUpdate(); - } - - /** - * Also called by the updater. - */ - public void updateQuiesced() { - this.synchronizeStaticMetamodel(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractOrmXmlContextNodeFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractOrmXmlContextNodeFactory.java deleted file mode 100644 index 3d40e64be0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractOrmXmlContextNodeFactory.java +++ /dev/null @@ -1,425 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmCascade; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryContainer; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.internal.context.orm.NullOrmAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlAssociationOverride; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlBasic; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlEmbedded; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlEmbeddedId; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlId; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlManyToMany; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlManyToOne; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlNullAttributeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlOneToMany; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlOneToOne; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlTransient; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlVersion; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericEntityMappings; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAssociationOverride; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAttributeOverride; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAttributeOverrideContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmBasicMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmCascade; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmDiscriminatorColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEmbeddable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEmbeddedIdMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEmbeddedMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEntity; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEnumeratedConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmGeneratedValue; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmGeneratorContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmIdMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmJoinColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmJoinTable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmLobConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmManyToManyMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmManyToOneMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmMappedSuperclass; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNamedNativeQuery; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNamedQuery; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNullAttributeMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNullConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmOneToManyMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmOneToOneMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmPersistentAttribute; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmPersistentType; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmQueryContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmQueryHint; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmSecondaryTable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmSequenceGenerator; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTableGenerator; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTemporalConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTransientMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmUniqueConstraint; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmVersionMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmXml; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericPersistenceUnitDefaults; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericPersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.jpa2.context.orm.NullOrmDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlDerivedId; -import org.eclipse.jpt.core.resource.orm.AbstractXmlRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverrideContainer; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverrideContainer; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlConvertibleMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlGeneratorContainer; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlQueryContainer; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; - -public abstract class AbstractOrmXmlContextNodeFactory implements OrmXml2_0ContextNodeFactory -{ - public OrmXml buildMappingFile(MappingFileRef parent, JpaXmlResource resource) { - return new GenericOrmXml(parent, resource); - } - - public EntityMappings buildEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { - return new GenericEntityMappings(parent, xmlEntityMappings); - } - - public PersistenceUnitMetadata buildPersistenceUnitMetadata(EntityMappings parent, XmlEntityMappings xmlEntityMappings) { - return new GenericPersistenceUnitMetadata(parent, xmlEntityMappings); - } - - public OrmPersistenceUnitDefaults buildPersistenceUnitDefaults(PersistenceUnitMetadata parent, XmlEntityMappings xmlEntityMappings) { - return new GenericPersistenceUnitDefaults(parent, xmlEntityMappings); - } - - public OrmPersistentType buildOrmPersistentType(EntityMappings parent, XmlTypeMapping resourceMapping) { - return new GenericOrmPersistentType(parent, resourceMapping); - } - - public OrmEntity buildOrmEntity(OrmPersistentType parent, XmlEntity resourceMapping) { - return new GenericOrmEntity(parent, resourceMapping); - } - - public OrmMappedSuperclass buildOrmMappedSuperclass(OrmPersistentType parent, XmlMappedSuperclass resourceMapping) { - return new GenericOrmMappedSuperclass(parent, resourceMapping); - } - - public OrmEmbeddable buildOrmEmbeddable(OrmPersistentType parent, XmlEmbeddable resourceMapping) { - return new GenericOrmEmbeddable(parent, resourceMapping); - } - - public OrmPersistentAttribute buildOrmPersistentAttribute(OrmPersistentType parent, OrmPersistentAttribute.Owner owner, XmlAttributeMapping resourceMapping) { - return new GenericOrmPersistentAttribute(parent, owner, resourceMapping); - } - - public OrmTable buildOrmTable(OrmEntity parent) { - return new GenericOrmTable(parent); - } - - public OrmSecondaryTable buildOrmSecondaryTable(OrmEntity parent, XmlSecondaryTable xmlSecondaryTable) { - return new GenericOrmSecondaryTable(parent, xmlSecondaryTable); - } - - public OrmPrimaryKeyJoinColumn buildOrmPrimaryKeyJoinColumn(XmlContextNode parent, OrmBaseJoinColumn.Owner owner, XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - return new GenericOrmPrimaryKeyJoinColumn(parent, owner, resourcePkJoinColumn); - } - - public OrmJoinTable buildOrmJoinTable(OrmJoinTableJoiningStrategy parent, XmlJoinTable resourceJoinTable) { - return new GenericOrmJoinTable(parent, resourceJoinTable); - } - - public OrmJoinColumn buildOrmJoinColumn(XmlContextNode parent, OrmJoinColumn.Owner owner, XmlJoinColumn resourceJoinColumn) { - return new GenericOrmJoinColumn(parent, owner, resourceJoinColumn); - } - - public OrmAttributeOverrideContainer buildOrmAttributeOverrideContainer(XmlContextNode parent, OrmAttributeOverrideContainer.Owner owner, XmlAttributeOverrideContainer resourceAttributeOverrideContainer) { - return new GenericOrmAttributeOverrideContainer(parent, owner, resourceAttributeOverrideContainer); - } - - public OrmAssociationOverrideContainer buildOrmAssociationOverrideContainer(OrmEntity parent, OrmAssociationOverrideContainer.Owner owner, XmlAssociationOverrideContainer resourceAssociationOverrideContainer) { - return new GenericOrmAssociationOverrideContainer(parent, owner, resourceAssociationOverrideContainer); - } - - public OrmAssociationOverrideContainer buildOrmAssociationOverrideContainer(OrmEmbeddedMapping2_0 parent, OrmAssociationOverrideContainer.Owner owner, XmlAssociationOverrideContainer resourceAssociationOverrideContainer) { - return new NullOrmAssociationOverrideContainer(parent, owner); - } - - public OrmAttributeOverride buildOrmAttributeOverride(XmlContextNode parent, AttributeOverride.Owner owner, XmlAttributeOverride xmlAttributeOverride) { - return new GenericOrmAttributeOverride(parent, owner, xmlAttributeOverride); - } - - public OrmAssociationOverride buildOrmAssociationOverride(XmlContextNode parent, AssociationOverride.Owner owner, XmlAssociationOverride xmlAssociationOverride) { - return new GenericOrmAssociationOverride(parent, owner, xmlAssociationOverride); - } - - public OrmAssociationOverrideRelationshipReference buildOrmAssociationOverrideRelationshipReference(OrmAssociationOverride parent, XmlAssociationOverride associationOverride) { - return new GenericOrmAssociationOverrideRelationshipReference(parent, associationOverride); - } - - public OrmDiscriminatorColumn buildOrmDiscriminatorColumn(OrmEntity parent, OrmDiscriminatorColumn.Owner owner) { - return new GenericOrmDiscriminatorColumn(parent, owner); - } - - public OrmCascade buildOrmCascade(OrmRelationshipMapping parent, AbstractXmlRelationshipMapping resourceMapping) { - return new GenericOrmCascade(parent, resourceMapping); - } - - public OrmColumn buildOrmColumn(XmlContextNode parent, OrmColumn.Owner owner) { - return new GenericOrmColumn(parent, owner); - } - - public OrmGeneratedValue buildOrmGeneratedValue(XmlContextNode parent, XmlGeneratedValue resourceGeneratedValue) { - return new GenericOrmGeneratedValue(parent, resourceGeneratedValue); - } - - public OrmGeneratorContainer buildOrmGeneratorContainer(XmlContextNode parent, XmlGeneratorContainer resourceGeneratorContainer) { - return new GenericOrmGeneratorContainer(parent, resourceGeneratorContainer); - } - - public OrmSequenceGenerator buildOrmSequenceGenerator(XmlContextNode parent, XmlSequenceGenerator resourceSequenceGenerator) { - return new GenericOrmSequenceGenerator(parent, resourceSequenceGenerator); - } - - public OrmTableGenerator buildOrmTableGenerator(XmlContextNode parent, XmlTableGenerator resourceTableGenerator) { - return new GenericOrmTableGenerator(parent, resourceTableGenerator); - } - - public OrmQueryContainer buildOrmQueryContainer(XmlContextNode parent, XmlQueryContainer resourceQueryContainer) { - return new GenericOrmQueryContainer(parent, resourceQueryContainer); - } - - public OrmNamedNativeQuery buildOrmNamedNativeQuery(XmlContextNode parent, XmlNamedNativeQuery resourceNamedNativeQuery) { - return new GenericOrmNamedNativeQuery(parent, resourceNamedNativeQuery); - } - - public OrmNamedQuery buildOrmNamedQuery(XmlContextNode parent, XmlNamedQuery resourceNamedQuery) { - return new GenericOrmNamedQuery(parent, resourceNamedQuery); - } - - public OrmQueryHint buildOrmQueryHint(OrmQuery parent, XmlQueryHint resourceQueryHint) { - return new GenericOrmQueryHint(parent, resourceQueryHint); - } - - public OrmBasicMapping buildOrmBasicMapping(OrmPersistentAttribute parent, XmlBasic resourceMapping) { - return new GenericOrmBasicMapping(parent, resourceMapping); - } - - public OrmEmbeddedMapping buildOrmEmbeddedMapping(OrmPersistentAttribute parent, XmlEmbedded resourceMapping) { - return new GenericOrmEmbeddedMapping(parent, resourceMapping); - } - - public OrmEmbeddedIdMapping buildOrmEmbeddedIdMapping(OrmPersistentAttribute parent, XmlEmbeddedId resourceMapping) { - return new GenericOrmEmbeddedIdMapping(parent, resourceMapping); - } - - public OrmIdMapping buildOrmIdMapping(OrmPersistentAttribute parent, XmlId resourceMapping) { - return new GenericOrmIdMapping(parent, resourceMapping); - } - - public OrmManyToManyMapping buildOrmManyToManyMapping(OrmPersistentAttribute parent, XmlManyToMany resourceMapping) { - return new GenericOrmManyToManyMapping(parent, resourceMapping); - } - - public OrmManyToOneMapping buildOrmManyToOneMapping(OrmPersistentAttribute parent, XmlManyToOne resourceMapping) { - return new GenericOrmManyToOneMapping(parent, resourceMapping); - } - - public OrmOneToManyMapping buildOrmOneToManyMapping(OrmPersistentAttribute parent, XmlOneToMany resourceMapping) { - return new GenericOrmOneToManyMapping(parent, resourceMapping); - } - - public OrmOneToOneMapping buildOrmOneToOneMapping(OrmPersistentAttribute parent, XmlOneToOne resourceMapping) { - return new GenericOrmOneToOneMapping(parent, resourceMapping); - } - - public OrmTransientMapping buildOrmTransientMapping(OrmPersistentAttribute parent, XmlTransient resourceMapping) { - return new GenericOrmTransientMapping(parent, resourceMapping); - } - - public OrmVersionMapping buildOrmVersionMapping(OrmPersistentAttribute parent, XmlVersion resourceMapping) { - return new GenericOrmVersionMapping(parent, resourceMapping); - } - - public OrmAttributeMapping buildOrmNullAttributeMapping(OrmPersistentAttribute parent, XmlNullAttributeMapping resourceMapping) { - return new GenericOrmNullAttributeMapping(parent, resourceMapping); - } - - public OrmUniqueConstraint buildOrmUniqueConstraint(XmlContextNode parent, UniqueConstraint.Owner owner, XmlUniqueConstraint resourceUniqueConstraint) { - return new GenericOrmUniqueConstraint(parent, owner, resourceUniqueConstraint); - } - - public OrmConverter buildOrmEnumeratedConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - return new GenericOrmEnumeratedConverter(parent, resourceMapping); - } - - public OrmConverter buildOrmLobConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - return new GenericOrmLobConverter(parent, resourceMapping); - } - - public OrmConverter buildOrmTemporalConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - return new GenericOrmTemporalConverter(parent, resourceMapping); - } - - public OrmConverter buildOrmNullConverter(OrmAttributeMapping parent) { - return new GenericOrmNullConverter(parent); - } - - public OrmDerivedId2_0 buildOrmDerivedId(OrmSingleRelationshipMapping2_0 parent, XmlDerivedId resource) { - return new NullOrmDerivedId2_0(parent); - } - - - // ********** ORM Virtual Resource Model ********** - - public XmlAssociationOverride buildVirtualXmlAssociationOverride(String name, OrmTypeMapping parent, JoiningStrategy joiningStrategy) { - return new VirtualXmlAssociationOverride(name, parent, joiningStrategy); - } - - public XmlBasic buildVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { - return new VirtualXmlBasic(ormTypeMapping, javaBasicMapping); - } - - public XmlEmbeddedId buildVirtualXmlEmbeddedId(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - return new VirtualXmlEmbeddedId(ormTypeMapping, javaEmbeddedIdMapping); - } - - public XmlEmbedded buildVirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { - return new VirtualXmlEmbedded(ormTypeMapping, javaEmbeddedMapping); - } - - public XmlId buildVirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { - return new VirtualXmlId(ormTypeMapping, javaIdMapping); - } - - public XmlManyToMany buildVirtualXmlManyToMany(OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { - return new VirtualXmlManyToMany(ormTypeMapping, javaManyToManyMapping); - } - - public XmlManyToOne buildVirtualXmlManyToOne(OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { - return new VirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping); - } - - public XmlOneToMany buildVirtualXmlOneToMany(OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { - return new VirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping); - } - - public XmlOneToOne buildVirtualXmlOneToOne(OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { - return new VirtualXmlOneToOne(ormTypeMapping, javaOneToOneMapping); - } - - public XmlTransient buildVirtualXmlTransient(OrmTypeMapping ormTypeMapping, JavaTransientMapping javaTransientMapping) { - return new VirtualXmlTransient(ormTypeMapping, javaTransientMapping); - } - - public XmlVersion buildVirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { - return new VirtualXmlVersion(ormTypeMapping, javaVersionMapping); - } - - public XmlNullAttributeMapping buildVirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - return new VirtualXmlNullAttributeMapping(ormTypeMapping, javaAttributeMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractSynchronizerJpaProjectUpdater.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractSynchronizerJpaProjectUpdater.java deleted file mode 100644 index 2c90da7041..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractSynchronizerJpaProjectUpdater.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.synchronizers.CallbackSynchronizer; - -/** - * Adapt the "synchronizer" interface to the JPA project "updater" interface. - * <p> - * Subclasses must build the appropriate synchronizer. - */ -public abstract class AbstractSynchronizerJpaProjectUpdater - implements JpaProject.Updater -{ - protected final JpaProject jpaProject; - protected final CallbackSynchronizer synchronizer; - - - protected AbstractSynchronizerJpaProjectUpdater(JpaProject jpaProject) { - super(); - this.jpaProject = jpaProject; - this.synchronizer = this.buildSynchronizer(); - this.synchronizer.addListener(this.buildCallbackSynchronizerListener()); - } - - protected abstract CallbackSynchronizer buildSynchronizer(); - - protected CallbackSynchronizer.Listener buildCallbackSynchronizerListener() { - return new CallbackSynchronizer.Listener() { - public void synchronizationQuiesced(CallbackSynchronizer s) { - AbstractSynchronizerJpaProjectUpdater.this.jpaProject.updateQuiesced(); - } - }; - } - - - // ********** JpaProject.Updater implementation ********** - - public void start() { - this.synchronizer.start(); - } - - // recursion: we come back here if IJpaProject#update() is called again, during the "update" - public void update() { - this.synchronizer.synchronize(); - } - - public void stop() { - this.synchronizer.stop(); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.synchronizer); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java deleted file mode 100644 index afbf4519f0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.internal.utility.CallbackJobSynchronizer; -import org.eclipse.jpt.core.internal.utility.JobCommand; -import org.eclipse.jpt.utility.internal.synchronizers.CallbackSynchronizer; -import org.eclipse.osgi.util.NLS; - -/** - * Adapt the "synchronizer" interface to the JPA project "updater" interface. - * <p> - * This updater will "update" the JPA project in an Eclipse job that executes - * in a separate thread allowing calls to {@link JpaProject.Updater#update()} - * to return immediately. - */ -public class AsynchronousJpaProjectUpdater - extends AbstractSynchronizerJpaProjectUpdater -{ - public AsynchronousJpaProjectUpdater(JpaProject jpaProject) { - super(jpaProject); - } - - @Override - protected CallbackSynchronizer buildSynchronizer() { - return new CallbackJobSynchronizer( - this.buildJobName(), - this.buildJobCommand(), - this.buildJobSchedulingRule() - ); - } - - protected String buildJobName() { - return NLS.bind(JptCoreMessages.UPDATE_JOB_NAME, this.jpaProject.getName()); - } - - protected JobCommand buildJobCommand() { - return new JobCommand() { - public IStatus execute(IProgressMonitor monitor) { - return AsynchronousJpaProjectUpdater.this.jpaProject.update(monitor); - } - }; - } - - protected ISchedulingRule buildJobSchedulingRule() { - return this.jpaProject.getProject(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericEntityGeneratorDatabaseAnnotationNameBuilder.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericEntityGeneratorDatabaseAnnotationNameBuilder.java deleted file mode 100644 index 6e622115a7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericEntityGeneratorDatabaseAnnotationNameBuilder.java +++ /dev/null @@ -1,55 +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; - -import org.eclipse.jpt.core.EntityGeneratorDatabaseAnnotationNameBuilder; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Table; - -/** - * Singleton that delegates to the db object passed in. - */ -public final class GenericEntityGeneratorDatabaseAnnotationNameBuilder - implements EntityGeneratorDatabaseAnnotationNameBuilder -{ - public static final EntityGeneratorDatabaseAnnotationNameBuilder INSTANCE - = new GenericEntityGeneratorDatabaseAnnotationNameBuilder(); - - public static EntityGeneratorDatabaseAnnotationNameBuilder instance() { - return INSTANCE; - } - - // ensure single instance - private GenericEntityGeneratorDatabaseAnnotationNameBuilder() { - super(); - } - - public String buildTableAnnotationName(String entityName, Table table) { - return table.getIdentifier(entityName); - } - - public String buildColumnAnnotationName(String attributeName, Column column) { - return column.getIdentifier(attributeName); - } - - public String buildJoinColumnAnnotationName(String attributeName, ForeignKey foreignKey) { - return foreignKey.getJoinColumnAnnotationIdentifier(attributeName); - } - - public String buildJoinColumnAnnotationName(Column column) { - return column.getIdentifier(); - } - - public String buildJoinTableAnnotationName(Table table) { - return table.getIdentifier(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationDefinitionProvider.java deleted file mode 100644 index 72d17468fb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationDefinitionProvider.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.List; -import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.internal.resource.java.AssociationOverrideAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AssociationOverridesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AttributeOverrideAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AttributeOverridesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.BasicAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.DiscriminatorColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.DiscriminatorValueAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddedAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddedIdAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EntityAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EnumeratedAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.GeneratedValueAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.IdAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.IdClassAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.InheritanceAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinColumnsAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinTableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.LobAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ManyToManyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ManyToOneAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.MapKeyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.MappedSuperclassAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedNativeQueriesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedNativeQueryAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedQueriesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedQueryAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OneToManyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OneToOneAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OrderByAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.PrimaryKeyJoinColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.PrimaryKeyJoinColumnsAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SecondaryTableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SecondaryTablesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SequenceGeneratorAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TableGeneratorAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TemporalAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TransientAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.VersionAnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; - -public class GenericJpaAnnotationDefinitionProvider - extends AbstractJpaAnnotationDefintionProvider -{ - // singleton - private static final JpaAnnotationDefinitionProvider INSTANCE = - new GenericJpaAnnotationDefinitionProvider(); - - - /** - * Return the singleton - */ - public static JpaAnnotationDefinitionProvider instance() { - return INSTANCE; - } - - - /** - * Ensure singleton usage - */ - protected GenericJpaAnnotationDefinitionProvider() { - super(); - } - - - @Override - protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(AssociationOverrideAnnotationDefinition.instance()); - definitions.add(AssociationOverridesAnnotationDefinition.instance()); - definitions.add(AttributeOverrideAnnotationDefinition.instance()); - definitions.add(AttributeOverridesAnnotationDefinition.instance()); - definitions.add(DiscriminatorColumnAnnotationDefinition.instance()); - definitions.add(DiscriminatorValueAnnotationDefinition.instance()); - definitions.add(EmbeddableAnnotationDefinition.instance()); - definitions.add(EntityAnnotationDefinition.instance()); - definitions.add(IdClassAnnotationDefinition.instance()); - definitions.add(InheritanceAnnotationDefinition.instance()); - definitions.add(MappedSuperclassAnnotationDefinition.instance()); - definitions.add(NamedQueryAnnotationDefinition.instance()); - definitions.add(NamedQueriesAnnotationDefinition.instance()); - definitions.add(NamedNativeQueryAnnotationDefinition.instance()); - definitions.add(NamedNativeQueriesAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnsAnnotationDefinition.instance()); - definitions.add(SecondaryTableAnnotationDefinition.instance()); - definitions.add(SecondaryTablesAnnotationDefinition.instance()); - definitions.add(SequenceGeneratorAnnotationDefinition.instance()); - definitions.add(TableAnnotationDefinition.instance()); - definitions.add(TableGeneratorAnnotationDefinition.instance()); - } - - @Override - protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(EmbeddableAnnotationDefinition.instance()); - definitions.add(EntityAnnotationDefinition.instance()); - definitions.add(MappedSuperclassAnnotationDefinition.instance()); - } - - @Override - protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(AssociationOverrideAnnotationDefinition.instance()); - definitions.add(AssociationOverridesAnnotationDefinition.instance()); - definitions.add(AttributeOverrideAnnotationDefinition.instance()); - definitions.add(AttributeOverridesAnnotationDefinition.instance()); - definitions.add(BasicAnnotationDefinition.instance()); - definitions.add(ColumnAnnotationDefinition.instance()); - definitions.add(EmbeddedAnnotationDefinition.instance()); - definitions.add(EmbeddedIdAnnotationDefinition.instance()); - definitions.add(EnumeratedAnnotationDefinition.instance()); - definitions.add(GeneratedValueAnnotationDefinition.instance()); - definitions.add(IdAnnotationDefinition.instance()); - definitions.add(JoinColumnAnnotationDefinition.instance()); - definitions.add(JoinColumnsAnnotationDefinition.instance()); - definitions.add(JoinTableAnnotationDefinition.instance()); - definitions.add(LobAnnotationDefinition.instance()); - definitions.add(ManyToManyAnnotationDefinition.instance()); - definitions.add(ManyToOneAnnotationDefinition.instance()); - definitions.add(MapKeyAnnotationDefinition.instance()); - definitions.add(OneToManyAnnotationDefinition.instance()); - definitions.add(OneToOneAnnotationDefinition.instance()); - definitions.add(OrderByAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnsAnnotationDefinition.instance()); - definitions.add(SequenceGeneratorAnnotationDefinition.instance()); - definitions.add(TableGeneratorAnnotationDefinition.instance()); - definitions.add(TemporalAnnotationDefinition.instance()); - definitions.add(TransientAnnotationDefinition.instance()); - definitions.add(VersionAnnotationDefinition.instance()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java deleted file mode 100644 index 640b4bffbe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Delegate to annotation definition providers. - * The platform factory will build an instance of this annotation provider, - * passing in the appropriate array of annotation definition providers necessary - * to build the annotations for the platform (vendor and/or version). - */ -public class GenericJpaAnnotationProvider - implements JpaAnnotationProvider -{ - private final JpaAnnotationDefinitionProvider[] annotationDefinitionProviders; - - public GenericJpaAnnotationProvider(JpaAnnotationDefinitionProvider... annotationDefinitionProviders) { - super(); - this.annotationDefinitionProviders = annotationDefinitionProviders; - } - - - // ********** static methods ********** - - protected static Iterator<String> annotationNames( - Iterator<AnnotationDefinition> annotationDefinitions) { - return new TransformationIterator<AnnotationDefinition, String>(annotationDefinitions) { - @Override - protected String transform(AnnotationDefinition annotationDefinition) { - return annotationDefinition.getAnnotationName(); - } - }; - } - - protected static AnnotationDefinition getAnnotationDefinition( - String annotationName, Iterator<AnnotationDefinition> annotationDefinitions) { - while (annotationDefinitions.hasNext()) { - AnnotationDefinition annotationDefinition = annotationDefinitions.next(); - if (annotationDefinition.getAnnotationName().equals(annotationName)) { - return annotationDefinition; - } - } - return null; - } - - - // ********** annotation definition providers ********** - - protected ListIterator<JpaAnnotationDefinitionProvider> annotationDefinitionProviders() { - return new ArrayListIterator<JpaAnnotationDefinitionProvider>(this.annotationDefinitionProviders); - } - - - // ********** type annotations ********** - - @SuppressWarnings("unchecked") - public Iterator<String> typeAnnotationNames() { - return new CompositeIterator<String>( - annotationNames(typeAnnotationDefinitions())); - } - - protected Iterator<AnnotationDefinition> typeAnnotationDefinitions() { - return new CompositeIterator<AnnotationDefinition> ( - new TransformationIterator<JpaAnnotationDefinitionProvider, Iterator<AnnotationDefinition>>( - this.annotationDefinitionProviders()) { - @Override - protected Iterator<AnnotationDefinition> transform( - JpaAnnotationDefinitionProvider annotationDefinitionProvider) { - return annotationDefinitionProvider.typeAnnotationDefinitions(); - } - }); - } - - public Iterator<String> typeMappingAnnotationNames() { - return new CompositeIterator<String>( - annotationNames(typeMappingAnnotationDefinitions())); - } - - protected Iterator<AnnotationDefinition> typeMappingAnnotationDefinitions() { - return new CompositeIterator<AnnotationDefinition> ( - new TransformationIterator<JpaAnnotationDefinitionProvider, Iterator<AnnotationDefinition>>( - this.annotationDefinitionProviders()) { - @Override - protected Iterator<AnnotationDefinition> transform( - JpaAnnotationDefinitionProvider annotationDefinitionProvider) { - return annotationDefinitionProvider.typeMappingAnnotationDefinitions(); - } - }); - } - - public Annotation buildTypeAnnotation( - JavaResourcePersistentType parent, Type type, String annotationName) { - return this.getTypeAnnotationDefinition(annotationName).buildAnnotation(parent, type); - } - - public Annotation buildTypeAnnotation( - JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - return this.getTypeAnnotationDefinition(jdtAnnotation.getElementName()). - buildAnnotation(parent, jdtAnnotation); - } - - protected AnnotationDefinition getTypeAnnotationDefinition(String annotationName) { - AnnotationDefinition annotationDefinition = - getAnnotationDefinition(annotationName, this.typeAnnotationDefinitions()); - if (annotationDefinition == null) { - throw new IllegalArgumentException("unsupported type annotation: " + annotationName); //$NON-NLS-1$ - } - return annotationDefinition; - } - - public Annotation buildNullTypeAnnotation( - JavaResourcePersistentType parent, String annotationName) { - return this.getTypeAnnotationDefinition(annotationName).buildNullAnnotation(parent); - } - - - // ********** attribute annotations ********** - - @SuppressWarnings("unchecked") - public Iterator<String> attributeAnnotationNames() { - return new CompositeIterator<String>( - annotationNames(attributeAnnotationDefinitions())); - } - - protected Iterator<AnnotationDefinition> attributeAnnotationDefinitions() { - return new CompositeIterator<AnnotationDefinition> ( - new TransformationIterator<JpaAnnotationDefinitionProvider, Iterator<AnnotationDefinition>>( - this.annotationDefinitionProviders()) { - @Override - protected Iterator<AnnotationDefinition> transform( - JpaAnnotationDefinitionProvider annotationDefinitionProvider) { - return annotationDefinitionProvider.attributeAnnotationDefinitions(); - } - }); - } - - public Annotation buildAttributeAnnotation( - JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName) { - return this.getAttributeAnnotationDefinition(annotationName).buildAnnotation(parent, attribute); - } - - public Annotation buildAttributeAnnotation( - JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - return this.getAttributeAnnotationDefinition(jdtAnnotation.getElementName()). - buildAnnotation(parent, jdtAnnotation); - } - - public Annotation buildNullAttributeAnnotation( - JavaResourcePersistentAttribute parent, String annotationName) { - return this.getAttributeAnnotationDefinition(annotationName).buildNullAnnotation(parent); - } - - protected AnnotationDefinition getAttributeAnnotationDefinition(String annotationName) { - AnnotationDefinition annotationDefinition = - getAnnotationDefinition(annotationName, this.attributeAnnotationDefinitions()); - if (annotationDefinition == null) { - throw new IllegalArgumentException("unsupported attribute annotation: " + annotationName); //$NON-NLS-1$ - } - return annotationDefinition; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java deleted file mode 100644 index 4d72046c0d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java +++ /dev/null @@ -1,520 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.ArrayList; -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaModel; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.JpaProject.Config; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.resource.orm.OrmXmlResourceProvider; -import org.eclipse.jpt.core.internal.resource.persistence.PersistenceXmlResourceProvider; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent; - -/** - * The JPA model is synchronized so all changes to the list of JPA projects - * are thread-safe. - * - * The JPA model holds on to a list of JPA project configs and only instantiates - * their associated JPA projects when necessary. Other than performance, - * this should be transparent to clients. - */ -public class GenericJpaModel - extends AbstractModel - implements JpaModel -{ - - /** maintain a list of all the current JPA projects */ - private final ArrayList<JpaProjectHolder> jpaProjectHolders = new ArrayList<JpaProjectHolder>(); - - - // ********** constructor ********** - - /** - * Construct a JPA model and populate it with JPA projects for all the - * current Eclipse projects with JPA facets. - * The JPA model can only be instantiated by the JPA model manager. - */ - GenericJpaModel() throws CoreException { - super(); - ResourcesPlugin.getWorkspace().getRoot().accept(new ResourceProxyVisitor(), IResource.NONE); - } - - - // ********** IJpaModel implementation ********** - - /** - * This will trigger the instantiation of the JPA project associated with the - * specified Eclipse project. - */ - public synchronized JpaProject getJpaProject(IProject project) throws CoreException { - return this.getJpaProjectHolder(project).jpaProject(); - } - - /** - * We can answer this question without instantiating the - * associated JPA project. - */ - public synchronized boolean containsJpaProject(IProject project) { - return this.getJpaProjectHolder(project).holdsJpaProjectFor(project); - } - - /** - * This will trigger the instantiation of all the JPA projects. - */ - public synchronized Iterator<JpaProject> jpaProjects() throws CoreException { - // force the CoreException to occur here (instead of later, in Iterator#next()) - ArrayList<JpaProject> jpaProjects = new ArrayList<JpaProject>(this.jpaProjectHolders.size()); - for (JpaProjectHolder holder : this.jpaProjectHolders) { - jpaProjects.add(holder.jpaProject()); - } - return jpaProjects.iterator(); - } - - /** - * We can answer this question without instantiating any JPA projects. - */ - public synchronized int jpaProjectsSize() { - return this.jpaProjectHolders.size(); - } - - /** - * This will trigger the instantiation of the JPA project associated with the - * specified file. - */ - public synchronized JpaFile getJpaFile(IFile file) throws CoreException { - JpaProject jpaProject = this.getJpaProject(file.getProject()); - return (jpaProject == null) ? null : jpaProject.getJpaFile(file); - } - - - // ********** internal methods ********** - - /** - * never return null - */ - private JpaProjectHolder getJpaProjectHolder(IProject project) { - for (JpaProjectHolder holder : this.jpaProjectHolders) { - if (holder.holdsJpaProjectFor(project)) { - return holder; - } - } - return NullJpaProjectHolder.instance(); - } - - private JpaProject.Config buildJpaProjectConfig(IProject project) { - SimpleJpaProjectConfig config = new SimpleJpaProjectConfig(); - config.setProject(project); - config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); - config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); - config.setUserOverrideDefaultCatalog(JptCorePlugin.getUserOverrideDefaultCatalog(project)); - config.setUserOverrideDefaultSchema(JptCorePlugin.getUserOverrideDefaultSchema(project)); - config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project)); - return config; - } - - /* private */ void addJpaProject(IProject project) { - this.addJpaProject(this.buildJpaProjectConfig(project)); - } - - /** - * Add a JPA project to the JPA model for the specified Eclipse project. - * JPA projects can only be added by the JPA model manager. - * The JPA project will only be instantiated later, on demand. - */ - private void addJpaProject(JpaProject.Config config) { - dumpStackTrace(); // figure out exactly when JPA projects are added - this.jpaProjectHolders.add(this.getJpaProjectHolder(config.getProject()).buildJpaProjectHolder(this, config)); - } - - /** - * Remove the JPA project corresponding to the specified Eclipse project - * from the JPA model. Return whether the removal actually happened. - * JPA projects can only be removed by the JPA model manager. - */ - private void removeJpaProject(IProject project) { - dumpStackTrace(); // figure out exactly when JPA projects are removed - this.getJpaProjectHolder(project).remove(); - } - - - // ********** Resource events ********** - - /** - * A project is being deleted. Remove its corresponding - * JPA project if appropriate. - */ - synchronized void projectPreDelete(IProject project) { - this.removeJpaProject(project); - } - - /** - * Forward the specified resource delta to all our JPA projects; - * they will each determine whether the event is significant. - */ - synchronized void projectChanged(IResourceDelta delta) throws CoreException { - for (JpaProjectHolder holder : this.jpaProjectHolders) { - holder.projectChanged(delta); - } - } - - - // ********** Resource and/or Facet events ********** - - /** - * Check whether the JPA facet has been added or removed. - */ - synchronized void checkForTransition(IProject project) { - boolean jpaFacet = JptCorePlugin.projectHasJpaFacet(project); - boolean jpaProject = this.containsJpaProject(project); - - if (jpaFacet) { - if ( ! jpaProject) { // JPA facet added - this.addJpaProject(project); - } - } else { - if (jpaProject) { // JPA facet removed - this.removeJpaProject(project); - } - } - } - - - // ********** Facet events ********** - - synchronized void jpaFacetedProjectPostInstall(IProjectFacetActionEvent event) { - IProject project = event.getProject().getProject(); - IDataModel dataModel = (IDataModel) event.getActionConfig(); - - boolean buildOrmXml = dataModel.getBooleanProperty(JpaFacetDataModelProperties.CREATE_ORM_XML); - this.createProjectXml(project, buildOrmXml); - - // assume(?) this is the first event to indicate we need to add the JPA project to the JPA model - this.addJpaProject(project); - } - - private void createProjectXml(IProject project, boolean buildOrmXml) { - this.createPersistenceXml(project); - - if (buildOrmXml) { - this.createOrmXml(project); - } - - } - - private void createPersistenceXml(IProject project) { - PersistenceXmlResourceProvider resourceProvider = - PersistenceXmlResourceProvider.getDefaultXmlResourceProvider(project); - try { - resourceProvider.createFileAndResource(); - } - catch (CoreException e) { - JptCorePlugin.log(e); - } - } - - private void createOrmXml(IProject project) { - OrmXmlResourceProvider resourceProvider = - OrmXmlResourceProvider.getDefaultXmlResourceProvider(project); - try { - resourceProvider.createFileAndResource(); - } - catch (CoreException e) { - JptCorePlugin.log(e); - } - } - - // TODO remove classpath items? persistence.xml? orm.xml? - synchronized void jpaFacetedProjectPreUninstall(IProjectFacetActionEvent event) { - // assume(?) this is the first event to indicate we need to remove the JPA project to the JPA model - this.removeJpaProject(event.getProject().getProject()); - } - - - // ********** Java events ********** - - /** - * Forward the Java element changed event to all the JPA projects - * because the event could affect multiple projects. - */ - synchronized void javaElementChanged(ElementChangedEvent event) { - for (JpaProjectHolder jpaProjectHolder : this.jpaProjectHolders) { - jpaProjectHolder.javaElementChanged(event); - } - } - - - // ********** miscellaneous ********** - - /** - * The JPA settings associated with the specified Eclipse project - * have changed in such a way as to require the associated - * JPA project to be completely rebuilt - * (e.g. when the user changes a project's JPA platform). - */ - synchronized void rebuildJpaProject(IProject project) { - this.removeJpaProject(project); - this.addJpaProject(project); - } - - /** - * Dispose the JPA model by disposing and removing all its JPA projects. - * The JPA model can only be disposed by the JPA model manager. - */ - synchronized void dispose() { - // clone the list to prevent concurrent modification exceptions - JpaProjectHolder[] holders = this.jpaProjectHolders.toArray(new JpaProjectHolder[this.jpaProjectHolders.size()]); - for (JpaProjectHolder holder : holders) { - holder.remove(); - } - } - - @Override - public void toString(StringBuilder sb) { - sb.append("JPA projects size: " + this.jpaProjectsSize()); //$NON-NLS-1$ - } - - - // ********** holder callbacks ********** - - /** - * called by the JPA project holder when the JPA project is actually - * instantiated - */ - /* private */ void jpaProjectBuilt(JpaProject jpaProject) { - this.fireItemAdded(JPA_PROJECTS_COLLECTION, jpaProject); - } - - /** - * called by the JPA project holder if the JPA project has been - * instantiated and we need to remove it - */ - /* private */ void jpaProjectRemoved(JpaProject jpaProject) { - this.fireItemRemoved(JPA_PROJECTS_COLLECTION, jpaProject); - } - - /** - * called by the JPA project holder - */ - /* private */ void removeJpaProjectHolder(JpaProjectHolder jpaProjectHolder) { - this.jpaProjectHolders.remove(jpaProjectHolder); - } - - - // ********** JPA project holders ********** - - private interface JpaProjectHolder { - - boolean holdsJpaProjectFor(IProject project); - - JpaProject jpaProject() throws CoreException; - - void projectChanged(IResourceDelta delta) throws CoreException; - - void javaElementChanged(ElementChangedEvent event); - - JpaProjectHolder buildJpaProjectHolder(GenericJpaModel jpaModel, JpaProject.Config config); - - void remove(); - - } - - private static class NullJpaProjectHolder implements JpaProjectHolder { - private static final JpaProjectHolder INSTANCE = new NullJpaProjectHolder(); - - static JpaProjectHolder instance() { - return INSTANCE; - } - - // ensure single instance - private NullJpaProjectHolder() { - super(); - } - - public boolean holdsJpaProjectFor(IProject project) { - return false; - } - - public JpaProject jpaProject() throws CoreException { - return null; - } - - public void projectChanged(IResourceDelta delta) throws CoreException { - // do nothing - } - - public void javaElementChanged(ElementChangedEvent event) { - // do nothing - } - - public JpaProjectHolder buildJpaProjectHolder(GenericJpaModel jpaModel, Config config) { - return new DefaultJpaProjectHolder(jpaModel, config); - } - - public void remove() { - // do nothing - } - - @Override - public String toString() { - return ClassTools.shortClassNameForObject(this); - } - } - - /** - * Pair a JPA project config with its lazily-initialized JPA project. - */ - private static class DefaultJpaProjectHolder implements JpaProjectHolder { - private final GenericJpaModel jpaModel; - private final JpaProject.Config config; - private JpaProject jpaProject; - - DefaultJpaProjectHolder(GenericJpaModel jpaModel, JpaProject.Config config) { - super(); - this.jpaModel = jpaModel; - this.config = config; - } - - public boolean holdsJpaProjectFor(IProject project) { - return this.config.getProject().equals(project); - } - - public JpaProject jpaProject() throws CoreException { - if (this.jpaProject == null) { - this.jpaProject = this.buildJpaProject(); - // notify listeners of the JPA model - this.jpaModel.jpaProjectBuilt(this.jpaProject); - } - return this.jpaProject; - } - - private JpaProject buildJpaProject() throws CoreException { - JpaPlatform jpaPlatform = this.config.getJpaPlatform(); - if (jpaPlatform == null) { - return null; - } - JpaProject result = jpaPlatform.getJpaFactory().buildJpaProject(this.config); - result.setUpdater(new AsynchronousJpaProjectUpdater(result)); - return result; - } - - public void projectChanged(IResourceDelta delta) throws CoreException { - if (this.jpaProject != null) { - this.jpaProject.projectChanged(delta); - } - } - - public void javaElementChanged(ElementChangedEvent event) { - if (this.jpaProject != null) { - this.jpaProject.javaElementChanged(event); - } - } - - public JpaProjectHolder buildJpaProjectHolder(GenericJpaModel jm, Config c) { - throw new IllegalArgumentException(c.getProject().getName()); - } - - public void remove() { - this.jpaModel.removeJpaProjectHolder(this); - if (this.jpaProject != null) { - this.jpaModel.jpaProjectRemoved(this.jpaProject); - this.jpaProject.dispose(); - } - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.config.getProject().getName()); - } - - } - - - // ********** resource proxy visitor ********** - - /** - * Visit the workspace resource tree, adding a JPA project to the - * JPA model for each open Eclipse project that has a JPA facet. - */ - private class ResourceProxyVisitor implements IResourceProxyVisitor { - - ResourceProxyVisitor() { - super(); - } - - public boolean visit(IResourceProxy resourceProxy) throws CoreException { - switch (resourceProxy.getType()) { - case IResource.ROOT : - return true; // all projects are in the "root" - case IResource.PROJECT : - this.checkProject(resourceProxy); - return false; // no nested projects - default : - return false; - } - } - - private void checkProject(IResourceProxy resourceProxy) { - if (resourceProxy.isAccessible()) { // the project exists and is open - IProject project = (IProject) resourceProxy.requestResource(); - if (JptCorePlugin.projectHasJpaFacet(project)) { - GenericJpaModel.this.addJpaProject(project); - } - } - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - } - - - // ********** DEBUG ********** - - // @see JpaModelTests#testDEBUG() - private static final boolean DEBUG = false; - - private static void dumpStackTrace() { - if (DEBUG) { - // lock System.out so the stack elements are printed out contiguously - synchronized (System.out) { - StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); - // skip the first 3 elements - those are this method and 2 methods in Thread - for (int i = 3; i < stackTrace.length; i++) { - StackTraceElement element = stackTrace[i]; - if (element.getMethodName().equals("invoke0")) { //$NON-NLS-1$ - break; // skip all elements outside of the JUnit test - } - System.out.println("\t" + element); //$NON-NLS-1$ - } - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatform.java deleted file mode 100644 index 3171e1d041..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatform.java +++ /dev/null @@ -1,244 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.ListIterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.EntityGeneratorDatabaseAnnotationNameBuilder; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaPlatformProvider; -import org.eclipse.jpt.core.JpaPlatformVariation; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModel; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.context.MappingFileDefinition; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.internal.utility.PlatformTools; -import org.eclipse.jpt.core.internal.utility.jdt.DefaultAnnotationEditFormatter; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.DatabaseFinder; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Tools; - -/** - * All the state in the JPA platform should be "static" (i.e. unchanging once - * it is initialized). - */ -public class GenericJpaPlatform - implements JpaPlatform -{ - private final String id; - - private final Version jpaVersion; - - private final JpaFactory jpaFactory; - - private final JpaAnnotationProvider annotationProvider; - - private final JpaPlatformProvider platformProvider; - - private final JpaPlatformVariation jpaVariation; - - - public GenericJpaPlatform(String id, Version jpaVersion, JpaFactory jpaFactory, JpaAnnotationProvider jpaAnnotationProvider, JpaPlatformProvider platformProvider, JpaPlatformVariation jpaVariation) { - super(); - this.id = id; - this.jpaVersion = jpaVersion; - this.jpaFactory = jpaFactory; - this.annotationProvider = jpaAnnotationProvider; - this.jpaVariation = jpaVariation; - this.platformProvider = platformProvider; - } - - - public String getId() { - return this.id; - } - - public Version getJpaVersion() { - return this.jpaVersion; - } - - // ********** factory ********** - - public JpaFactory getJpaFactory() { - return this.jpaFactory; - } - - - // ********** platform providers ********** - - protected JpaPlatformProvider getPlatformProvider() { - return this.platformProvider; - } - - - // ********** JPA file/resource models ********** - - public JpaFile buildJpaFile(JpaProject jpaProject, IFile file) { - IContentType contentType = PlatformTools.getContentType(file); - return (contentType == null) ? null : this.buildJpaFile(jpaProject, file, contentType); - } - - protected JpaFile buildJpaFile(JpaProject jpaProject, IFile file, IContentType contentType) { - JpaResourceModel resourceModel = this.buildResourceModel(jpaProject, file, contentType); - return (resourceModel == null) ? null : this.jpaFactory.buildJpaFile(jpaProject, file, contentType, resourceModel); - } - - protected JpaResourceModel buildResourceModel(JpaProject jpaProject, IFile file, IContentType contentType) { - JpaResourceModelProvider provider = this.getResourceModelProvider(contentType); - return (provider == null) ? null : provider.buildResourceModel(jpaProject, file); - } - - /** - * Return null if we don't have a provider for the specified content type - * (since we don't have control over the possible content types). - */ - protected JpaResourceModelProvider getResourceModelProvider(IContentType contentType) { - for (JpaResourceModelProvider provider : CollectionTools.iterable(resourceModelProviders())) { - if (contentType.equals(provider.getContentType())) { - return provider; - } - } - return null; - } - - protected ListIterator<JpaResourceModelProvider> resourceModelProviders() { - return this.platformProvider.resourceModelProviders(); - } - - - // ********** Java annotations ********** - - public JpaAnnotationProvider getAnnotationProvider() { - return this.annotationProvider; - } - - public AnnotationEditFormatter getAnnotationEditFormatter() { - return DefaultAnnotationEditFormatter.instance(); - } - - - // ********** Java type mappings ********** - - public JavaTypeMappingDefinition getJavaTypeMappingDefinition(JavaPersistentType type) { - for (JavaTypeMappingDefinition definition : - CollectionTools.iterable(javaTypeMappingDefinitions())) { - if (definition.test(type)) { - return definition; - } - } - throw new IllegalStateException("There must be a mapping definition for all types"); //$NON-NLS-1$ - } - - public JavaTypeMappingDefinition getJavaTypeMappingDefinition(String mappingKey) { - for (JavaTypeMappingDefinition definition : - CollectionTools.iterable(javaTypeMappingDefinitions())) { - if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) { - return definition; - } - } - throw new IllegalArgumentException("Illegal type mapping key: " + mappingKey); //$NON-NLS-1$ - } - - protected ListIterator<JavaTypeMappingDefinition> javaTypeMappingDefinitions() { - return this.platformProvider.javaTypeMappingDefinitions(); - } - - - // ********** Java attribute mappings ********** - - public JavaAttributeMappingDefinition getDefaultJavaAttributeMappingDefinition( - JavaPersistentAttribute attribute) { - for (JavaAttributeMappingDefinition definition : - CollectionTools.iterable(defaultJavaAttributeMappingDefinitions())) { - if (definition.testDefault(attribute)) { - return definition; - } - } - throw new IllegalStateException("There must be a mapping definition for all attributes"); //$NON-NLS-1$ - } - - protected ListIterator<JavaAttributeMappingDefinition> defaultJavaAttributeMappingDefinitions() { - return this.platformProvider.defaultJavaAttributeMappingDefinitions(); - } - - public JavaAttributeMappingDefinition getSpecifiedJavaAttributeMappingDefinition( - JavaPersistentAttribute attribute) { - for (JavaAttributeMappingDefinition definition : - CollectionTools.iterable(specifiedJavaAttributeMappingDefinitions())) { - if (definition.testSpecified(attribute)) { - return definition; - } - } - throw new IllegalStateException("There must be a mapping definition for all attributes"); //$NON-NLS-1$ - } - - protected ListIterator<JavaAttributeMappingDefinition> specifiedJavaAttributeMappingDefinitions() { - return this.platformProvider.specifiedJavaAttributeMappingDefinitions(); - } - - public JavaAttributeMappingDefinition getSpecifiedJavaAttributeMappingDefinition(String mappingKey) { - for (JavaAttributeMappingDefinition definition : - CollectionTools.iterable(specifiedJavaAttributeMappingDefinitions())) { - if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) { - return definition; - } - } - throw new IllegalArgumentException("Illegal attribute mapping key: " + mappingKey); //$NON-NLS-1$ - } - - - // ********** Mapping Files ********** - - public MappingFileDefinition getMappingFileDefinition(IContentType contentType) { - for (MappingFileDefinition mappingFileDef : CollectionTools.iterable(mappingFileDefinitions())) { - if (mappingFileDef.getContentType().isKindOf(contentType)) { - return mappingFileDef; - } - } - throw new IllegalArgumentException("Illegal mapping file content type: " + contentType); //$NON-NLS-1$ - } - - protected ListIterator<MappingFileDefinition> mappingFileDefinitions() { - return this.platformProvider.mappingFileDefinitions(); - } - - - // ********** database ********** - - public ConnectionProfileFactory getConnectionProfileFactory() { - return JptDbPlugin.instance().getConnectionProfileFactory(); - } - - public EntityGeneratorDatabaseAnnotationNameBuilder getEntityGeneratorDatabaseAnnotationNameBuilder() { - return GenericEntityGeneratorDatabaseAnnotationNameBuilder.instance(); - } - - public DatabaseFinder getDatabaseFinder() { - return DatabaseFinder.Default.instance(); - } - - - // ********** validation ********** - - public JpaPlatformVariation getJpaVariation() { - return this.jpaVariation; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformFactory.java deleted file mode 100644 index e5fcbb87f1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaPlatformFactory; -import org.eclipse.jpt.core.JpaPlatformVariation; -import org.eclipse.jpt.core.internal.jpa1.GenericJpaFactory; - -/** - * All the state in the JPA platform should be "static" (i.e. unchanging once - * it is initialized). - */ -public class GenericJpaPlatformFactory - implements JpaPlatformFactory -{ - /** - * zero-argument constructor - */ - public GenericJpaPlatformFactory() { - super(); - } - - public JpaPlatform buildJpaPlatform(String id) { - return new GenericJpaPlatform( - id, - this.buildJpaVersion(), - new GenericJpaFactory(), - new GenericJpaAnnotationProvider(GenericJpaAnnotationDefinitionProvider.instance()), - GenericJpaPlatformProvider.instance(), - this.buildJpaPlatformVariation()); - } - - - private JpaPlatform.Version buildJpaVersion() { - return new JpaPlatform.Version() { - public boolean is2_0Compatible() { - return false; - } - - public int getJpaVersion() { - return 1; - } - }; - } - - protected JpaPlatformVariation buildJpaPlatformVariation() { - return new JpaPlatformVariation() { - public Supported getTablePerConcreteClassInheritanceIsSupported() { - return Supported.MAYBE; - } - public boolean isJoinTableOverridable() { - return false; - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformProvider.java deleted file mode 100644 index 09a325e81a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaPlatformProvider.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.jpt.core.JpaPlatformProvider; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.context.MappingFileDefinition; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaBasicMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddableDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEntityDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaManyToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaManyToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaMappedSuperclassDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaOneToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaOneToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaTransientMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaVersionMappingDefinition; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmXmlDefinition; - -/** - * All the state in the JPA platform should be "static" (i.e. unchanging once - * it is initialized). - */ -public class GenericJpaPlatformProvider - extends AbstractJpaPlatformProvider -{ - public static final String ID = "generic"; //$NON-NLS-1$ - - // singleton - private static final JpaPlatformProvider INSTANCE = - new GenericJpaPlatformProvider(); - - - /** - * Return the singleton. - */ - public static JpaPlatformProvider instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private GenericJpaPlatformProvider() { - super(); - } - - - // ********** resource models ********** - - @Override - protected JpaResourceModelProvider[] buildResourceModelProviders() { - // order should not be important here - return new JpaResourceModelProvider[] { - JavaResourceModelProvider.instance(), - JarResourceModelProvider.instance(), - PersistenceResourceModelProvider.instance(), - OrmResourceModelProvider.instance()}; - } - - - // ********** Java type mappings ********** - - @Override - protected JavaTypeMappingDefinition[] buildNonNullJavaTypeMappingDefinitions() { - // order determined by analyzing order that reference implementation (toplink) uses - return new JavaTypeMappingDefinition[] { - JavaEntityDefinition.instance(), - JavaEmbeddableDefinition.instance(), - JavaMappedSuperclassDefinition.instance()}; - } - - - // ********** Java attribute mappings ********** - - @Override - protected JavaAttributeMappingDefinition[] buildNonNullDefaultJavaAttributeMappingDefinitions() { - // order determined by analyzing order that reference implementation (toplink) uses - return new JavaAttributeMappingDefinition[] { - JavaEmbeddedMappingDefinition.instance(), - JavaBasicMappingDefinition.instance()}; - } - - @Override - protected JavaAttributeMappingDefinition[] buildNonNullSpecifiedJavaAttributeMappingDefinitions() { - // order determined by analyzing order that reference implementation (toplink) uses - return new JavaAttributeMappingDefinition[] { - JavaTransientMappingDefinition.instance(), - JavaIdMappingDefinition.instance(), - JavaVersionMappingDefinition.instance(), - JavaBasicMappingDefinition.instance(), - JavaEmbeddedMappingDefinition.instance(), - JavaEmbeddedIdMappingDefinition.instance(), - JavaManyToManyMappingDefinition.instance(), - JavaManyToOneMappingDefinition.instance(), - JavaOneToManyMappingDefinition.instance(), - JavaOneToOneMappingDefinition.instance()}; - } - - - // ********** Mapping Files ********** - - @Override - protected MappingFileDefinition[] buildMappingFileDefinitions() { - return new MappingFileDefinition[] { - GenericOrmXmlDefinition.instance()}; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JarResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JarResourceModelProvider.java deleted file mode 100644 index 1347db8270..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JarResourceModelProvider.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModel; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryPackageFragmentRoot; - -/** - * JAR files - */ -public class JarResourceModelProvider - implements JpaResourceModelProvider -{ - // singleton - private static final JpaResourceModelProvider INSTANCE = new JarResourceModelProvider(); - - /** - * Return the singleton. - */ - public static JpaResourceModelProvider instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private JarResourceModelProvider() { - super(); - } - - public IContentType getContentType() { - return JptCorePlugin.JAR_CONTENT_TYPE; - } - - /** - * NB: Despite the check in GenericJpaProject.addJpaFile_(IFile), - * we can get here and - * the PFR will be null if the JAR is underneath a directory on the - * classpath but the JAR itself is not on the classpath. - * Returning null should be OK. - */ - public JpaResourceModel buildResourceModel(JpaProject jpaProject, IFile file) { - IPackageFragmentRoot pfr = JavaCore.createJarPackageFragmentRootFrom(file); - return (pfr ==null) ? null : new BinaryPackageFragmentRoot(pfr, jpaProject.getJpaPlatform().getAnnotationProvider()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java deleted file mode 100644 index 5d87c03086..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.resource.java.source.SourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; - -/** - * Java source code - */ -public class JavaResourceModelProvider - implements JpaResourceModelProvider -{ - // singleton - private static final JpaResourceModelProvider INSTANCE = new JavaResourceModelProvider(); - - /** - * Return the singleton. - */ - public static JpaResourceModelProvider instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private JavaResourceModelProvider() { - super(); - } - - public IContentType getContentType() { - return JptCorePlugin.JAVA_SOURCE_CONTENT_TYPE; - } - - public JavaResourceCompilationUnit buildResourceModel(JpaProject jpaProject, IFile file) { - return new SourceCompilationUnit( - JavaCore.createCompilationUnitFrom(file), - jpaProject.getJpaPlatform().getAnnotationProvider(), - jpaProject.getJpaPlatform().getAnnotationEditFormatter(), - jpaProject.getModifySharedDocumentCommandExecutor() - ); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java deleted file mode 100644 index b4ec22bef0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java +++ /dev/null @@ -1,590 +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; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.IOpenable; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaModel; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.utility.internal.BitTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; -import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent; -import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener; -import org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent; - -/** - * "Internal" global stuff. - * Provide access via a singleton. - * Hold and manage the JPA model (which holds all the JPA projects) - * and the various global listeners. We attempt to determine whether events - * are relevant before forwarding them to the JPA model. - * - * Various things that cause us to add or remove a JPA project: - * - Startup of the Dali plug-in will trigger all the JPA projects to be added - * - * - Project created and facet installed - * facet POST_INSTALL - * - Project facet uninstalled - * facet PRE_UNINSTALL - * - * - Project opened - * facet PROJECT_MODIFIED - * - Project closed - * facet PROJECT_MODIFIED - * - * - Pre-existing project imported from directory or archive (created and opened) - * resource POST_CHANGE -> PROJECT -> ADDED -> OPEN - * - Project deleted - * resource PRE_DELETE - * - * - Project facet installed by editing the facets settings file directly - * facet PROJECT_MODIFIED - * - Project facet uninstalled by editing the facets settings file directly - * facet PROJECT_MODIFIED - */ -public class JpaModelManager { - - /** - * The JPA model - null until the plug-in is started. - */ - private GenericJpaModel jpaModel; - - /** - * Listen for changes to projects and files. - */ - private final IResourceChangeListener resourceChangeListener; - - /** - * Listen for the JPA facet being added or removed from a project. - */ - private final IFacetedProjectListener facetedProjectListener; - - /** - * Listen for Java changes and forward them to the JPA model, - * which will forward them to the JPA projects. - */ - private final IElementChangedListener javaElementChangeListener; - private boolean javaElementChangeListenerIsActive; - - - // ********** singleton ********** - - private static final JpaModelManager INSTANCE = new JpaModelManager(); - - /** - * Return the singleton JPA model manager. - */ - public static JpaModelManager instance() { - return INSTANCE; - } - - - // ********** constructor ********** - - /** - * Private - ensure single instance. - */ - private JpaModelManager() { - super(); - this.resourceChangeListener = new ResourceChangeListener(); - this.facetedProjectListener = new FacetedProjectListener(); - this.javaElementChangeListener = new JavaElementChangeListener(); - this.javaElementChangeListenerIsActive = true; - } - - - // ********** plug-in controlled life-cycle ********** - - /** - * internal - called by JptCorePlugin - */ - public synchronized void start() throws Exception { - debug("*** START JPA model manager ***"); //$NON-NLS-1$ - try { - this.jpaModel = new GenericJpaModel(); - ResourcesPlugin.getWorkspace().addResourceChangeListener( - this.resourceChangeListener, - IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.POST_BUILD); - FacetedProjectFramework.addListener(this.facetedProjectListener, IFacetedProjectEvent.Type.values()); - JavaCore.addElementChangedListener(this.javaElementChangeListener); - } catch (RuntimeException ex) { - this.log(ex); - this.stop(); - } - } - - /** - * internal - called by JptCorePlugin - */ - public synchronized void stop() throws Exception { - debug("*** STOP JPA model manager ***"); //$NON-NLS-1$ - JavaCore.removeElementChangedListener(this.javaElementChangeListener); - FacetedProjectFramework.removeListener(this.facetedProjectListener); - ResourcesPlugin.getWorkspace().removeResourceChangeListener(this.resourceChangeListener); - this.jpaModel.dispose(); - this.jpaModel = null; - } - - - // ********** API ********** - - /** - * Return the workspace-wide JPA model. - */ - public JpaModel getJpaModel() { - return this.jpaModel; - } - - /** - * Return the JPA project corresponding to the specified Eclipse project, - * or null if unable to associate the specified project with a - * JPA project. - */ - public JpaProject getJpaProject(IProject project) throws CoreException { - return this.jpaModel.getJpaProject(project); - } - - /** - * Return the JPA file corresponding to the specified Eclipse file, - * or null if unable to associate the specified file with a JPA file. - */ - public JpaFile getJpaFile(IFile file) throws CoreException { - return this.jpaModel.getJpaFile(file); - } - - /** - * The JPA settings associated with the specified Eclipse project - * have changed in such a way as to require the associated - * JPA project to be completely rebuilt - * (e.g. when the user changes a project's JPA platform). - */ - public void rebuildJpaProject(IProject project) { - this.jpaModel.rebuildJpaProject(project); - } - - /** - * Return whether the model manager's Java change listener is active. - */ - public boolean javaElementChangeListenerIsActive() { - return this.javaElementChangeListenerIsActive; - } - - /** - * Set whether the model manager's Java change listener is active. - */ - public void setJavaElementChangeListenerIsActive(boolean javaElementChangeListenerIsActive) { - this.javaElementChangeListenerIsActive = javaElementChangeListenerIsActive; - } - - /** - * Log the specified status. - */ - public void log(IStatus status) { - JptCorePlugin.log(status); - } - - /** - * Log the specified message. - */ - public void log(String msg) { - JptCorePlugin.log(msg); - } - - /** - * Log the specified exception or error. - */ - public void log(Throwable throwable) { - JptCorePlugin.log(throwable); - } - - - // ********** resource changed ********** - - /** - * Check for: - * - project close/delete - * - file add/remove - * - project open/rename - */ - /* private */ void resourceChanged(IResourceChangeEvent event) { - // build events can have the workspace or project as source - if (event.getType() == IResourceChangeEvent.POST_BUILD) { - this.resourcePostBuild(event); - return; - } - - if (! (event.getSource() instanceof IWorkspace)) { - return; // this probably shouldn't happen... - } - - switch (event.getType()) { - case IResourceChangeEvent.PRE_DELETE : // project-only event - this.resourcePreDelete(event); - break; - case IResourceChangeEvent.POST_CHANGE : - this.resourcePostChange(event); - break; - default : - break; - } - } - - /** - * A project is being deleted. Remove its corresponding - * JPA project if appropriate. - */ - private void resourcePreDelete(IResourceChangeEvent event) { - IProject project = (IProject) event.getResource(); - debug("Resource (Project) PRE_DELETE: ", project); //$NON-NLS-1$ - this.jpaModel.projectPreDelete(project); - } - - /** - * A resource has changed somehow. - * Check for files being added or removed. - * (The JPA project only handles added and removed files here - * Changed files are handlded via the Java Element Changed event.) - * Also check for opened projects. - */ - private void resourcePostChange(IResourceChangeEvent event) { - debug("Resource POST_CHANGE"); //$NON-NLS-1$ - this.resourceChanged(event.getDelta()); - } - - private void resourceChanged(IResourceDelta delta) { - IResource resource = delta.getResource(); - switch (resource.getType()) { - case IResource.ROOT : - this.resourceChangedChildren(delta); - break; - case IResource.PROJECT : - this.projectChanged((IProject) resource, delta); - break; - case IResource.FILE : - case IResource.FOLDER : - default : - break; - } - } - - private void resourceChangedChildren(IResourceDelta delta) { - for (IResourceDelta child : delta.getAffectedChildren()) { - this.resourceChanged(child); // recurse - } - } - - private void projectChanged(IProject project, IResourceDelta delta) { - this.projectChanged_(delta); - this.checkForOpenedProject(project, delta); - } - - - /** - * Checked exceptions bite. - */ - private void projectChanged_(IResourceDelta delta) { - try { - this.jpaModel.projectChanged(delta); - } catch (CoreException ex) { - this.log(ex); // problem traversing the project's resources - not much we can do - } - } - - /** - * Crawl the specified delta, looking for projects being opened. - * Projects being deleted are handled in IResourceChangeEvent.PRE_DELETE. - * Projects being closed are handled in IFacetedProjectEvent.Type.PROJECT_MODIFIED. - */ - private void checkForOpenedProject(IProject project, IResourceDelta delta) { - switch (delta.getKind()) { - case IResourceDelta.ADDED : // all but project import and rename handled with the facet POST_INSTALL event - this.checkDeltaFlagsForOpenedProject(project, delta); - this.checkDeltaFlagsForRenamedProject(project, delta); - break; - case IResourceDelta.REMOVED : // already handled with the PRE_DELETE event - break; - case IResourceDelta.CHANGED : - this.checkDeltaFlagsForOpenedProject(project, delta); - break; - case IResourceDelta.ADDED_PHANTOM : // ignore - break; - case IResourceDelta.REMOVED_PHANTOM : // ignore - break; - default : - break; - } - } - - /** - * We don't get any events from the Facets Framework when a pre-existing - * project is imported, so we need to check for the newly imported project here. - * - * This event also occurs when a project is simply opened. Project opening - * also triggers a Facet PROJECT_MODIFIED event and that is where we add - * the JPA project, not here - */ - private void checkDeltaFlagsForOpenedProject(IProject project, IResourceDelta delta) { - if (BitTools.flagIsSet(delta.getFlags(), IResourceDelta.OPEN) && project.isOpen()) { - debug("\tProject CHANGED - OPEN: ", project.getName()); //$NON-NLS-1$ - this.jpaModel.checkForTransition(project); - } - } - - /** - * We don't get any events from the Facets Framework when a project is renamed, - * so we need to check for the renamed projects here. - */ - private void checkDeltaFlagsForRenamedProject(IProject project, IResourceDelta delta) { - if (BitTools.flagIsSet(delta.getFlags(), IResourceDelta.MOVED_FROM) && project.isOpen()) { - debug("\tProject ADDED - MOVED_FROM: ", delta.getMovedFromPath()); //$NON-NLS-1$ - this.jpaModel.checkForTransition(project); - } - } - - /** - * A post build event has occurred. - * Check for whether the build was a "clean" build and trigger project update. - */ - private void resourcePostBuild(IResourceChangeEvent event) { - debug("Resource POST_BUILD"); //$NON-NLS-1$ - if (event.getBuildKind() == IncrementalProjectBuilder.CLEAN_BUILD) { - this.resourcePostClean(event.getDelta()); - } - } - - private void resourcePostClean(IResourceDelta delta) { - IResource resource = delta.getResource(); - switch (resource.getType()) { - case IResource.ROOT : - this.resourcePostCleanChildren(delta); - break; - case IResource.PROJECT : - this.projectPostClean((IProject) resource); - break; - case IResource.FILE : - case IResource.FOLDER : - default : - break; - } - } - - private void resourcePostCleanChildren(IResourceDelta delta) { - for (IResourceDelta child : delta.getAffectedChildren()) { - this.resourcePostClean(child); // recurse - } - } - - private void projectPostClean(IProject project) { - JpaProject jpaProject = null; - try { - jpaProject = getJpaProject(project); - } - catch (CoreException ce) { - // nothing to do, we won't be able to update anyway - } - if (jpaProject != null) { - rebuildJpaProject(project); - } - } - - - // ********** faceted project changed ********** - - /** - * Check for: - * - install of JPA facet - * - un-install of JPA facet - * - any other appearance or disappearance of the JPA facet - */ - /* private */ void facetedProjectChanged(IFacetedProjectEvent event) { - switch (event.getType()) { - case POST_INSTALL : - this.facetedProjectPostInstall((IProjectFacetActionEvent) event); - break; - case PRE_UNINSTALL : - this.facetedProjectPreUninstall((IProjectFacetActionEvent) event); - break; - case PROJECT_MODIFIED : - this.facetedProjectModified(event.getProject().getProject()); - break; - default : - break; - } - } - - private void facetedProjectPostInstall(IProjectFacetActionEvent event) { - debug("Facet POST_INSTALL: ", event.getProjectFacet()); //$NON-NLS-1$ - if (event.getProjectFacet().getId().equals(JptCorePlugin.FACET_ID)) { - this.jpaModel.jpaFacetedProjectPostInstall(event); - } - } - - private void facetedProjectPreUninstall(IProjectFacetActionEvent event) { - debug("Facet PRE_UNINSTALL: ", event.getProjectFacet()); //$NON-NLS-1$ - if (event.getProjectFacet().getId().equals(JptCorePlugin.FACET_ID)) { - this.jpaModel.jpaFacetedProjectPreUninstall(event); - } - } - - /** - * This event is triggered for any change to a faceted project. - * We use the event to watch for the following: - * - an open project is closed - * - a closed project is opened - * - one of a project's (facet) metadata files is edited directly - */ - private void facetedProjectModified(IProject project) { - debug("Facet PROJECT_MODIFIED: ", project.getName()); //$NON-NLS-1$ - this.jpaModel.checkForTransition(project); - } - - - // ********** Java element changed ********** - - /** - * Forward the event to the JPA model. - */ - /* private */ void javaElementChanged(ElementChangedEvent event) { - if ( ! this.javaElementChangeListenerIsActive) { - return; // ignore Java events - } - if (this.eventIndicatesProjectAddedButNotOpen(event)) { - return; - } - this.jpaModel.javaElementChanged(event); - } - - //209275 - This particular event only causes problems in a clean workspace the first time a JPA project - //is created through the JPA wizard. The second time a JPA project is created, this event occurs, but - //it occurs as the wizard is closing so it does not cause a deadlock. - private boolean eventIndicatesProjectAddedButNotOpen(ElementChangedEvent event) { - IJavaElementDelta delta = event.getDelta(); - if (delta.getKind() == IJavaElementDelta.CHANGED) { - if (delta.getElement().getElementType() == IJavaElement.JAVA_MODEL) { - IJavaElementDelta[] children = delta.getAffectedChildren(); - if (children.length == 1) { - IJavaElementDelta childDelta = children[0]; - if (childDelta.getKind() == IJavaElementDelta.ADDED) { - IJavaElement childElement = childDelta.getElement(); - if (childElement.getElementType() == IJavaElement.JAVA_PROJECT) { - if (childDelta.getAffectedChildren().length == 0) { - if (!((IOpenable) childElement).isOpen()) { - return true; - } - } - } - } - } - } - } - return false; - } - - - // ********** resource change listener ********** - - /** - * Forward the Resource change event back to the JPA model manager. - */ - private class ResourceChangeListener implements IResourceChangeListener { - ResourceChangeListener() { - super(); - } - public void resourceChanged(IResourceChangeEvent event) { - JpaModelManager.this.resourceChanged(event); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - // ********** faceted project listener ********** - - /** - * Forward the Faceted project change event back to the JPA model manager. - */ - private class FacetedProjectListener implements IFacetedProjectListener { - FacetedProjectListener() { - super(); - } - public void handleEvent(IFacetedProjectEvent event) { - JpaModelManager.this.facetedProjectChanged(event); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - // ********** Java element change listener ********** - - /** - * Forward the Java element change event back to the JPA model manager. - */ - private class JavaElementChangeListener implements IElementChangedListener { - JavaElementChangeListener() { - super(); - } - public void elementChanged(ElementChangedEvent event) { - JpaModelManager.this.javaElementChanged(event); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - // ********** debug ********** - - // @see JpaModelTests#testDEBUG() - private static final boolean DEBUG = false; - - /** - * trigger #toString() call and string concatenation only if DEBUG is true - */ - private static void debug(String message, Object object) { - if (DEBUG) { - debug_(message + object); - } - } - - private static void debug(String message) { - if (DEBUG) { - debug_(message); - } - } - - private static void debug_(String message) { - System.out.println(Thread.currentThread().getName() + ": " + message); //$NON-NLS-1$ - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java deleted file mode 100644 index 440161cddb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformRegistry.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaPlatformFactory; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator; -import org.eclipse.osgi.util.NLS; - -/** - * Singleton registry for storing all the registered JPA platform configuration - * elements and instantiating JPA platforms from them. - */ -public class JpaPlatformRegistry { - - private final HashMap<String, IConfigurationElement> jpaPlatformConfigurationElements; - - - // singleton - private static final JpaPlatformRegistry INSTANCE = new JpaPlatformRegistry(); - - /** - * Return the singleton. - */ - public static JpaPlatformRegistry instance() { - return INSTANCE; - } - - private static final String EXTENSION_ID = "jpaPlatforms"; //$NON-NLS-1$ - private static final String PLATFORM_ELEMENT_NAME = "jpaPlatform"; //$NON-NLS-1$ - private static final String ID_ATTRIBUTE_NAME = "id"; //$NON-NLS-1$ - private static final String LABEL_ATTRIBUTE_NAME = "label"; //$NON-NLS-1$ - private static final String FACTORY_CLASS_ATTRIBUTE_NAME = "factoryClass"; //$NON-NLS-1$ - private static final String DEFAULT_ATTRIBUTE_NAME = "default"; //$NON-NLS-1$ - - - // ********** constructor/initialization ********** - - /** - * ensure single instance - */ - private JpaPlatformRegistry() { - super(); - this.jpaPlatformConfigurationElements = this.buildJpaPlatformConfigurationElements(); - } - - - private HashMap<String, IConfigurationElement> buildJpaPlatformConfigurationElements() { - HashMap<String, IConfigurationElement> configElements = new HashMap<String, IConfigurationElement>(); - for (IConfigurationElement configElement : this.getConfigElements()) { - this.addConfigElementTo(configElement, configElements); - } - return configElements; - } - - /** - * Return the configuration elements from the Eclipse platform extension - * registry. - */ - private Iterable<IConfigurationElement> getConfigElements() { - return new CompositeIterable<IConfigurationElement>( - new TransformationIterable<IExtension, Iterable<IConfigurationElement>>(this.getExtensions()) { - @Override - protected Iterable<IConfigurationElement> transform(IExtension extension) { - return CollectionTools.iterable(extension.getConfigurationElements()); - } - } - ); - } - - private Iterable<IExtension> getExtensions() { - return CollectionTools.iterable(this.getExtensionPoint().getExtensions()); - } - - private IExtensionPoint getExtensionPoint() { - return Platform.getExtensionRegistry().getExtensionPoint(JptCorePlugin.PLUGIN_ID, EXTENSION_ID); - } - - private void addConfigElementTo(IConfigurationElement configElement, HashMap<String, IConfigurationElement> configElements) { - if ( ! configElement.getName().equals(PLATFORM_ELEMENT_NAME)) { - return; - } - if ( ! this.configElementIsValid(configElement)) { - return; - } - - String id = configElement.getAttribute(ID_ATTRIBUTE_NAME); - IConfigurationElement prev = configElements.put(id, configElement); - if (prev != null) { - configElements.put(id, prev); // replace previous(?) - this.logDuplicatePlatform(prev, configElement, id); - } - } - - /** - * check *all* attributes before returning - */ - private boolean configElementIsValid(IConfigurationElement configElement) { - boolean valid = true; - if (configElement.getAttribute(ID_ATTRIBUTE_NAME) == null) { - this.logMissingAttribute(configElement, ID_ATTRIBUTE_NAME); - valid = false; - } - if (configElement.getAttribute(LABEL_ATTRIBUTE_NAME) == null) { - this.logMissingAttribute(configElement, LABEL_ATTRIBUTE_NAME); - valid = false; - } - if (configElement.getAttribute(FACTORY_CLASS_ATTRIBUTE_NAME) == null) { - this.logMissingAttribute(configElement, FACTORY_CLASS_ATTRIBUTE_NAME); - valid = false; - } - return valid; - } - - - // ********** public methods ********** - - /** - * Return the IDs for the registered JPA platforms. - * This does not activate any of the JPA platforms' plug-ins. - */ - public Iterator<String> jpaPlatformIds() { - return new ReadOnlyIterator<String>(this.jpaPlatformConfigurationElements.keySet()); - } - - /** - * Return whether the platform id is registered - */ - public boolean containsPlatform(String platformId) { - return this.jpaPlatformConfigurationElements.containsKey(platformId); - } - - /** - * Return the label for the JPA platform with the specified ID. - * This does not activate the JPA platform's plug-in. - */ - public String getJpaPlatformLabel(String id) { - return this.jpaPlatformConfigurationElements.get(id).getAttribute(LABEL_ATTRIBUTE_NAME); - } - - /** - * Return the ID for a JPA platform registered as a default platform. - * Returns null if there are no such registered platforms. - * Returns the first platform ID if there are multiple such registered platforms. - */ - public String getDefaultJpaPlatformId() { - for (Map.Entry<String, IConfigurationElement> entry: this.jpaPlatformConfigurationElements.entrySet()) { - String defaultFlag = entry.getValue().getAttribute(DEFAULT_ATTRIBUTE_NAME); - if ((defaultFlag != null) && defaultFlag.equals("true")) { //$NON-NLS-1$ - return entry.getKey(); - } - } - return null; - } - - /** - * Return a new JPA platform for the specified ID. - * NB: This should only be called when instantiating a JPA platform - * when building a new JPA project. - * Unlike other registry methods, invoking this method may activate - * the plug-in. - */ - public JpaPlatform getJpaPlatform(IProject project) { - String id = JptCorePlugin.getJpaPlatformId(project); - IConfigurationElement configElement = this.jpaPlatformConfigurationElements.get(id); - if (configElement == null) { - JptCorePlugin.log(NLS.bind(JptCoreMessages.PLATFORM_ID_DOES_NOT_EXIST, id, project.getName())); - return null; - } - JpaPlatformFactory platformFactory; - try { - platformFactory = (JpaPlatformFactory) configElement.createExecutableExtension(FACTORY_CLASS_ATTRIBUTE_NAME); - } catch (CoreException ex) { - this.logFailedInstantiation(configElement, ex); - throw new IllegalArgumentException(id); - } - return platformFactory.buildJpaPlatform(id); - } - - - // ********** errors ********** - - private void logMissingAttribute(IConfigurationElement configElement, String attributeName) { - this.log(JptCoreMessages.REGISTRY_MISSING_ATTRIBUTE, - configElement.getName(), - configElement.getContributor().getName(), - attributeName - ); - } - - private void logDuplicatePlatform(IConfigurationElement prevConfigElement, IConfigurationElement newConfigElement, String id) { - this.log(JptCoreMessages.REGISTRY_DUPLICATE, - prevConfigElement.getContributor().getName(), - newConfigElement.getContributor().getName(), - ID_ATTRIBUTE_NAME, - PLATFORM_ELEMENT_NAME, - id - ); - } - - private void logFailedInstantiation(IConfigurationElement configElement, CoreException ex) { - this.log(JptCoreMessages.REGISTRY_FAILED_INSTANTIATION, - configElement.getAttribute(FACTORY_CLASS_ATTRIBUTE_NAME), - configElement.getName(), - configElement.getContributor().getName() - ); - JptCorePlugin.log(ex); - } - - private void log(String msg, Object... bindings) { - JptCorePlugin.log(NLS.bind(msg, bindings)); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformTester.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformTester.java deleted file mode 100644 index 4a6c98edfb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaPlatformTester.java +++ /dev/null @@ -1,40 +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; - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jpt.core.JptCorePlugin; - -public class JpaPlatformTester extends PropertyTester { - - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (! property.equals("jpaPlatform")) { //$NON-NLS-1$ - return false; - } - - String platformId = null; - - if (receiver instanceof IResource) { - platformId = platformId(((IResource) receiver).getProject()); - } - else if (receiver instanceof IJavaElement) { - platformId = platformId(((IJavaElement) receiver).getResource().getProject()); - } - - - return platformId == null ? false : platformId.equals(expectedValue); - } - - private String platformId(IProject project) { - return (project == null) ? null : JptCorePlugin.getJpaPlatformId(project); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaTester.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaTester.java deleted file mode 100644 index cb32a9531c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaTester.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2008 BEA Systems, Inc and others. - * All rights reserved. This program and the accompanying materials - * are made available under the 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: - * Konstantin Komissarchik - initial implementation and ongoing maintenance - * Oracle - copied and modified from org.eclipse.wst.common.project.facet.core.internal.FacetedProjectPropertyTester - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; - -public class JpaTester extends PropertyTester { - - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (!property.equals("projectFacet")) { //$NON-NLS-1$ - return false; - } - if (receiver instanceof IJavaElement) { - IProject project = ((IJavaElement) receiver).getResource().getProject(); - if (project != null) { - - String val = (String) expectedValue; - int colon = val.indexOf( ':' ); - String facetID; - String facetVer; - if( colon == -1 || colon == val.length() - 1 ) { - facetID = val; - facetVer = null; - } else { - facetID = val.substring( 0, colon ); - facetVer = val.substring( colon + 1 ); - } - try { - return FacetedProjectFramework.hasProjectFacet( project, facetID, facetVer ); - } catch (CoreException e) { - JptCorePlugin.log(e.getStatus()); - return false; - } - } - } - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java deleted file mode 100644 index 5faa3e32ad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.osgi.util.NLS; - -/** - * Localized messages used by Dali core. - */ -public class JptCoreMessages { - - public static String NONE; - public static String VALIDATE_JOB; - public static String VALIDATE_PROJECT_NOT_SPECIFIED; - public static String VALIDATE_SOURCE_FOLDER_NOT_SPECIFIED; - public static String VALIDATE_SOURCE_FOLDER_ILLEGAL; - public static String VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST; - public static String VALIDATE_SOURCE_FOLDER_NOT_IN_PROJECT; - public static String VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER; - public static String VALIDATE_FILE_PATH_NOT_SPECIFIED; - public static String VALIDATE_ORM_FILE_ALREADY_EXISTS; - public static String VALIDATE_PERSISTENCE_UNIT_DOES_NOT_SPECIFIED; - public static String VALIDATE_PERSISTENCE_UNIT_NOT_IN_PROJECT; - public static String VALIDATE_PLATFORM_NOT_SPECIFIED; - public static String VALIDATE_CONNECTION_NOT_SPECIFIED; - public static String VALIDATE_CONNECTION_INVALID; - public static String VALIDATE_CONNECTION_NOT_CONNECTED; - public static String VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED; - public static String VALIDATE_CONNECTION_DOESNT_CONTAIN_CATALOG; - public static String VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED; - public static String VALIDATE_CONNECTION_DOESNT_CONTAIN_SCHEMA; - public static String VALIDATE_RUNTIME_NOT_SPECIFIED; - public static String VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30; - public static String VALIDATE_LIBRARY_NOT_SPECIFIED; - public static String SYNCHRONIZE_CLASSES_JOB; - public static String SYNCHRONIZING_CLASSES_TASK; - public static String INVALID_PERSISTENCE_XML_CONTENT; - public static String ERROR_SYNCHRONIZING_CLASSES_COULD_NOT_VALIDATE; - public static String ERROR_WRITING_FILE; - public static String REGISTRY_MISSING_ATTRIBUTE; - public static String REGISTRY_DUPLICATE; - public static String REGISTRY_FAILED_INSTANTIATION; - public static String UPDATE_JOB_NAME; - public static String SYNCHRONIZE_STATIC_METAMODEL_JOB_NAME; - public static String PLATFORM_ID_DOES_NOT_EXIST; - - private static final String BUNDLE_NAME = "jpa_core"; //$NON-NLS-1$ - private static final Class<?> BUNDLE_CLASS = JptCoreMessages.class; - static { - NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS); - } - - private JptCoreMessages() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/OrmResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/OrmResourceModelProvider.java deleted file mode 100644 index 4fdff725c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/OrmResourceModelProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.resource.orm.OrmXmlResourceProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; - -/** - * orm.xml - */ -public class OrmResourceModelProvider - implements JpaResourceModelProvider -{ - // singleton - private static final JpaResourceModelProvider INSTANCE = new OrmResourceModelProvider(); - - /** - * Return the singleton. - */ - public static JpaResourceModelProvider instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private OrmResourceModelProvider() { - super(); - } - - public IContentType getContentType() { - return JptCorePlugin.ORM_XML_CONTENT_TYPE; - } - - public JpaXmlResource buildResourceModel(JpaProject jpaProject, IFile file) { - return OrmXmlResourceProvider.getXmlResourceProvider(file).getXmlResource(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/PersistenceResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/PersistenceResourceModelProvider.java deleted file mode 100644 index 1e12878e0c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/PersistenceResourceModelProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.resource.persistence.PersistenceXmlResourceProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; - -/** - * persistence.xml - */ -public class PersistenceResourceModelProvider - implements JpaResourceModelProvider -{ - // singleton - private static final JpaResourceModelProvider INSTANCE = new PersistenceResourceModelProvider(); - - /** - * Return the singleton. - */ - public static JpaResourceModelProvider instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private PersistenceResourceModelProvider() { - super(); - } - - public IContentType getContentType() { - return JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE; - } - - public JpaXmlResource buildResourceModel(JpaProject jpaProject, IFile file) { - return PersistenceXmlResourceProvider.getXmlResourceProvider(file).getXmlResource(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ProjectAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ProjectAdapterFactory.java deleted file mode 100644 index fa80271fb8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ProjectAdapterFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; - -/** - * [Double-duty] factory to build adapters for either standard projects or - * Java projects: - * - JPA project - * - * See org.eclipse.jpt.core plugin.xml. - */ -public class ProjectAdapterFactory - implements IAdapterFactory -{ - private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaProject.class }; - - public Class<?>[] getAdapterList() { - return ADAPTER_LIST; - } - - public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) { - if (adaptableObject instanceof IProject) { - return this.getAdapter((IProject) adaptableObject, adapterType); - } - if (adaptableObject instanceof IJavaProject) { - return this.getAdapter((IJavaProject) adaptableObject, adapterType); - } - return null; - } - - private Object getAdapter(IProject project, Class <?>adapterType) { - if (adapterType == JpaProject.class) { - return this.getJpaProject(project); - } - return null; - } - - private Object getAdapter(IJavaProject javaProject, Class <?>adapterType) { - if (adapterType == JpaProject.class) { - return this.getJpaProject(javaProject.getProject()); - } - return null; - } - - private JpaProject getJpaProject(IProject project) { - return JptCorePlugin.getJpaProject(project); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ResourceAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ResourceAdapterFactory.java deleted file mode 100644 index 45fa245e63..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/ResourceAdapterFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jpt.core.IResourcePart; - -/** - * Factory to build adapters for Eclipse resources: - * - resource part - * - * See org.eclipse.jpt.core plugin.xml. - */ -public class ResourceAdapterFactory - implements IAdapterFactory -{ - private static final Class<?>[] ADAPTER_LIST = new Class[] { IResourcePart.class }; - - public Class<?>[] getAdapterList() { - return ADAPTER_LIST; - } - - public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) { - if (adaptableObject instanceof IResource) { - return this.getAdapter((IResource) adaptableObject, adapterType); - } - return null; - } - - private Object getAdapter(final IResource resource, Class <?>adapterType) { - if (adapterType == IResourcePart.class) { - return new IResourcePart() { - public IResource getResource() { - return resource; - } - }; - } - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java deleted file mode 100644 index 0852bea195..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Straightforward implementation of the JPA project config. - */ -public class SimpleJpaProjectConfig implements JpaProject.Config { - protected IProject project; - protected JpaPlatform jpaPlatform; - protected String connectionProfileName; - protected String userOverrideDefaultCatalog; - protected String userOverrideDefaultSchema; - protected boolean discoverAnnotatedClasses; - - public SimpleJpaProjectConfig() { - super(); - } - - public IProject getProject() { - return this.project; - } - - public void setProject(IProject project) { - this.project = project; - } - - public JpaPlatform getJpaPlatform() { - return this.jpaPlatform; - } - - public void setJpaPlatform(JpaPlatform jpaPlatform) { - this.jpaPlatform = jpaPlatform; - } - - public String getConnectionProfileName() { - return this.connectionProfileName; - } - - public void setConnectionProfileName(String connectionProfileName) { - this.connectionProfileName = connectionProfileName; - } - - public String getUserOverrideDefaultSchema() { - return this.userOverrideDefaultSchema; - } - - public void setUserOverrideDefaultSchema(String userOverrideDefaultSchema) { - this.userOverrideDefaultSchema = userOverrideDefaultSchema; - } - - public String getUserOverrideDefaultCatalog() { - return this.userOverrideDefaultCatalog; - } - - public void setUserOverrideDefaultCatalog(String userOverrideDefaultCatalog) { - this.userOverrideDefaultCatalog = userOverrideDefaultCatalog; - } - - public boolean discoverAnnotatedClasses() { - return this.discoverAnnotatedClasses; - } - - public void setDiscoverAnnotatedClasses(boolean discoverAnnotatedClasses) { - this.discoverAnnotatedClasses = discoverAnnotatedClasses; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.project.getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.java deleted file mode 100644 index 9412f1f8eb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.utility.Command; -import org.eclipse.jpt.utility.internal.synchronizers.CallbackSynchronizer; -import org.eclipse.jpt.utility.internal.synchronizers.CallbackSynchronousSynchronizer; - -/** - * Adapt the "synchronizer" interface to the JPA project "updater" interface. - * <p> - * This updater will "update" the JPA project immediately and not return until - * the "update" and all resulting "updates" are complete. This implementation - * should be used sparingly and for as short a time as possible, as it increases - * the probability of deadlocks. A deadlock can occur when a JPA project is - * updated from multiple threads and various resources are locked in varying - * orders. - */ -public class SynchronousJpaProjectUpdater - extends AbstractSynchronizerJpaProjectUpdater -{ - public SynchronousJpaProjectUpdater(JpaProject jpaProject) { - super(jpaProject); - } - - @Override - protected CallbackSynchronizer buildSynchronizer() { - return new CallbackSynchronousSynchronizer(this.buildCommand()); - } - - protected Command buildCommand() { - return new Command() { - public void execute() { - SynchronousJpaProjectUpdater.this.jpaProject.update(new NullProgressMonitor()); - } - }; - } - -} 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 ae3741fe1a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractJpaContextNode.java +++ /dev/null @@ -1,102 +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.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.MappingFileRoot; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.AbstractJpaNode; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; - -public abstract class AbstractJpaContextNode - extends AbstractJpaNode - implements JpaContextNode -{ - - // ********** constructor ********** - - protected AbstractJpaContextNode(JpaNode parent) { - super(parent); - } - - - // ********** JpaNode implentation ********** - - /** - * covariant override - */ - @Override - public JpaContextNode getParent() { - return (JpaContextNode) super.getParent(); - } - - - // ********** JpaContextNode implementation ********** - - public IContentType getContentType() { - return getParent().getContentType(); - } - - /** - * Overridden in GenericPersistence and GenericPersistenceXml to throw - * UnsupportedOperationException. - * Overridden in GenericRootContextNode to return null. - * Overridden in GenericPersistenceUnit to return itself. - */ - public PersistenceUnit getPersistenceUnit() { - return this.getParent().getPersistenceUnit(); - } - - public MappingFileRoot getMappingFileRoot() { - return this.getParent().getMappingFileRoot(); - } - - public Schema getContextDefaultDbSchema() { - SchemaContainer dbSchemaContainer = this.getContextDefaultDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getContextDefaultSchema()); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getContextDefaultDbSchemaContainer() { - String catalog = this.getContextDefaultCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - protected String getContextDefaultSchema() { - MappingFileRoot mfr = this.getMappingFileRoot(); - return (mfr != null) ? mfr.getSchema() : this.getPersistenceUnit().getDefaultSchema(); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getContextDefaultDbCatalog() { - String catalog = this.getContextDefaultCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - protected String getContextDefaultCatalog() { - MappingFileRoot mfr = this.getMappingFileRoot(); - return (mfr != null) ? mfr.getCatalog() : this.getPersistenceUnit().getDefaultCatalog(); - } - - public void postUpdate() { - // do nothing - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractXmlContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractXmlContextNode.java deleted file mode 100644 index 66eec94d9e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractXmlContextNode.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context; - -import java.util.List; - -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractXmlContextNode - extends AbstractJpaContextNode - implements XmlContextNode -{ - - // ********** constructor ********** - - protected AbstractXmlContextNode(JpaContextNode parent) { - super(parent); - } - - - // ********** validation ********** - - /** - * All subclass implementations {@link #validate(List<IMessage>)} - * should be preceded by a "super" call to this method - */ - public void validate(List<IMessage> messages, IReporter reporter) { - if (reporter.isCancelled()) { - throw new ValidationCancelledException(); - } - } - -} 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 02c320a42a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.ColumnMapping; -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.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.RelationshipReference; -import org.eclipse.jpt.db.Table; - -/** - * Gather some of the behavior common to the Java and XML models. :-( - */ -public class MappingTools { - - /** - * 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] - * - * NB: The *names* are concatenated, *not* the *identifiers*. - * E.g. the join table for "Foo" and "baR" (where the "delimited" identifier - * is required) is - * "Foo_baR" - * not - * "Foo"_"baR" - * As a result, we cannot honestly calculate the default name without a - * database connection. - */ - public static String buildJoinTableDefaultName(RelationshipReference relationshipReference) { - if (relationshipReference.getJpaProject().getDataSource().connectionProfileIsActive()) { - return buildDbJoinTableDefaultName(relationshipReference); - } - // continue with a "best effort": - String owningTableName = relationshipReference.getTypeMapping().getPrimaryTableName(); - if (owningTableName == null) { - return null; - } - RelationshipMapping relationshipMapping = relationshipReference.getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - Entity targetEntity = relationshipMapping.getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - String targetTableName = targetEntity.getPrimaryTableName(); - if (targetTableName == null) { - return null; - } - return owningTableName + '_' + targetTableName; - } - - /** - * Use the database to build a more accurate default name. - */ - protected static String buildDbJoinTableDefaultName(RelationshipReference relationshipReference) { - Table owningTable = relationshipReference.getTypeMapping().getPrimaryDbTable(); - if (owningTable == null) { - return null; - } - RelationshipMapping relationshipMapping = relationshipReference.getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - Entity targetEntity = relationshipMapping.getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - Table targetTable = targetEntity.getPrimaryDbTable(); - if (targetTable == null) { - return null; - } - String name = owningTable.getName() + '_' + targetTable.getName(); - return owningTable.getDatabase().convertNameToIdentifier(name); - } - - /** - * 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] - * - * @see #buildJoinTableDefaultName(RelationshipMapping) - */ - public static String buildJoinColumnDefaultName(JoinColumn joinColumn) { - JoinColumn.Owner owner = joinColumn.getOwner(); - RelationshipMapping relationshipMapping = owner.getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (owner.joinColumnsSize() != 1) { - return null; - } - String prefix = owner.getAttributeName(); - if (prefix == null) { - Entity targetEntity = owner.getTargetEntity(); - if (targetEntity == null) { - return null; - } - prefix = targetEntity.getName(); - } - // not sure which of these is correct... - // (the spec implies that the referenced column is always the - // primary key column of the target entity) - // Column targetColumn = joinColumn.getTargetPrimaryKeyDbColumn(); - String targetColumnName = joinColumn.getReferencedColumnName(); - if (targetColumnName == null) { - return null; - } - String name = prefix + '_' + targetColumnName; - // not sure which of these is correct... - // converting the name to an identifier will result in the identifier - // being delimited nearly every time (at least on non-Sybase/MS - // databases); but that probably is not the intent of the spec... - // return targetColumn.getDatabase().convertNameToIdentifier(name); - return name; - } - - /** - * If appropriate, return the name of the single primary key column of the - * target entity. - */ - public static String buildJoinColumnDefaultReferencedColumnName(JoinColumn.Owner joinColumnOwner) { - RelationshipMapping relationshipMapping = joinColumnOwner.getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (joinColumnOwner.joinColumnsSize() != 1) { - return null; - } - Entity targetEntity = joinColumnOwner.getTargetEntity(); - if (targetEntity == null) { - return null; - } - return targetEntity.getPrimaryKeyColumnName(); - } - - public static ColumnMapping getColumnMapping(String attributeName, PersistentType persistentType) { - if (attributeName == null || persistentType == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = persistentType.allAttributes(); stream.hasNext(); ) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof ColumnMapping) { - return (ColumnMapping) persAttribute.getMapping(); - } - // keep looking or return null??? - } - } - return null; - } - - public static RelationshipMapping getRelationshipMapping(String attributeName, PersistentType persistentType) { - if (attributeName == null || persistentType == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = persistentType.allAttributes(); stream.hasNext(); ) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof RelationshipMapping) { - return (RelationshipMapping) persAttribute.getMapping(); - } - // keep looking or return null??? - } - } - return null; - } - - public static void convertJoinTableDefaultToSpecifiedJoinColumn(JoinTable joinTable) { - JoinColumn defaultJoinColumn = joinTable.getDefaultJoinColumn(); - if (defaultJoinColumn != null) { - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - JoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - } - - public static void convertJoinTableDefaultToSpecifiedInverseJoinColumn(JoinTable joinTable) { - JoinColumn defaultInverseJoinColumn = joinTable.getDefaultInverseJoinColumn(); - if (defaultInverseJoinColumn != null) { - String columnName = defaultInverseJoinColumn.getDefaultName(); - String referencedColumnName = defaultInverseJoinColumn.getDefaultReferencedColumnName(); - JoinColumn joinColumn = joinTable.addSpecifiedInverseJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - } - -} 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/AbstractJavaAssociationOverrideRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAssociationOverrideRelationshipReference.java deleted file mode 100644 index ee0f982f26..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAssociationOverrideRelationshipReference.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JoiningStrategy; -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.JavaAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnInAssociationOverrideJoiningStrategy; -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.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractJavaAssociationOverrideRelationshipReference extends AbstractJavaJpaContextNode - implements JavaAssociationOverrideRelationshipReference -{ - - // cache the strategy for property change notification - protected JoiningStrategy cachedPredominantJoiningStrategy; - - protected final JavaJoinColumnInAssociationOverrideJoiningStrategy joinColumnJoiningStrategy; - - protected AbstractJavaAssociationOverrideRelationshipReference(JavaAssociationOverride parent) { - super(parent); - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - } - - protected JavaJoinColumnInAssociationOverrideJoiningStrategy buildJoinColumnJoiningStrategy() { - return new GenericJavaJoinColumnInAssociationOverrideJoiningStrategy(this); - } - - @Override - public JavaAssociationOverride getParent() { - return (JavaAssociationOverride) super.getParent(); - } - - public JavaAssociationOverride getAssociationOverride() { - return getParent(); - } - - public boolean isOverridableAssociation() { - return false; - } - - public TypeMapping getTypeMapping() { - return getAssociationOverride().getOwner().getTypeMapping(); - } - - public Entity getEntity() { - TypeMapping typeMapping = getTypeMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - // **************** RelationshipMapping implementation ******************************* - - public boolean isParentVirtual() { - return getAssociationOverride().isVirtual(); - } - - // **************** predominant joining strategy *************************** - - public JoiningStrategy getPredominantJoiningStrategy() { - return this.cachedPredominantJoiningStrategy; - } - - protected void setPredominantJoiningStrategy(JoiningStrategy newJoiningStrategy) { - JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; - this.cachedPredominantJoiningStrategy = newJoiningStrategy; - firePropertyChanged(PREDOMINANT_JOINING_STRATEGY_PROPERTY, oldJoiningStrategy, newJoiningStrategy); - } - - public void initialize(AssociationOverrideAnnotation associationOverride) { - initializeJoiningStrategies(associationOverride); - this.cachedPredominantJoiningStrategy = calculatePredominantJoiningStrategy(); - } - - protected void initializeJoiningStrategies(AssociationOverrideAnnotation associationOverride) { - this.joinColumnJoiningStrategy.initialize(associationOverride); - } - - public void update(AssociationOverrideAnnotation associationOverride) { - updateJoiningStrategies(associationOverride); - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); - } - - protected void updateJoiningStrategies(AssociationOverrideAnnotation associationOverride) { - this.joinColumnJoiningStrategy.update(associationOverride); - } - - protected abstract JoiningStrategy calculatePredominantJoiningStrategy(); - - @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.joinColumnJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.connectionProfileIsActive()) { - this.validateJoinColumns(messages, astRoot); - } - } - - protected void validateJoinColumns(List<IMessage> messages, CompilationUnit astRoot) { - for (Iterator<JavaJoinColumn> stream = this.getJoinColumnJoiningStrategy().joinColumns(); stream.hasNext(); ) { - this.validateJoinColumn(stream.next(), messages, astRoot); - } - } - - protected void validateJoinColumn(JavaJoinColumn joinColumn, List<IMessage> messages, CompilationUnit astRoot) { - String tableName = joinColumn.getTable(); - if (this.getAssociationOverride().getOwner().getTypeMapping().tableNameIsInvalid(tableName)) { - if (this.getAssociationOverride().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {this.getAssociationOverride().getName(), tableName, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot) - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot) - ) - ); - } - return; - } - - if ( ! joinColumn.isResolved()) { - if (this.getAssociationOverride().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {this.getAssociationOverride().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 ( ! joinColumn.isReferencedColumnResolved()) { - if (this.getAssociationOverride().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {this.getAssociationOverride().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 TextRange getValidationTextRange(CompilationUnit astRoot) { - return getAssociationOverride().getValidationTextRange(astRoot); - } - - // **************** join columns ******************************************* - - - public JavaJoinColumnInAssociationOverrideJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.addStrategy(); - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return false; - } - - public RelationshipMapping getRelationshipMapping() { - return getAssociationOverride().getOwner().getRelationshipMapping(getAssociationOverride().getName()); - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return getRelationshipMapping().isOwnedBy(mapping); - } - - public boolean isRelationshipOwner() { - return getRelationshipMapping().isRelationshipOwner(); - } - -} 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 a495af54de..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.RelationshipMapping; -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.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * Java attribute mapping - */ -public abstract class AbstractJavaAttributeMapping<T extends Annotation> - extends AbstractJavaJpaContextNode - implements JavaAttributeMapping -{ - protected final JavaResourcePersistentAttribute resourcePersistentAttribute; - - protected T mappingAnnotation; - - private String[] supportingAnnotationNames; - - - protected AbstractJavaAttributeMapping(JavaPersistentAttribute parent) { - super(parent); - this.resourcePersistentAttribute = parent.getResourcePersistentAttribute(); - } - - @Override - public JavaPersistentAttribute getParent() { - return (JavaPersistentAttribute) super.getParent(); - } - - public JavaPersistentAttribute getPersistentAttribute() { - return this.getParent(); - } - - protected JavaResourcePersistentAttribute getResourcePersistentAttribute() { - return this.resourcePersistentAttribute; - } - - public T getMappingAnnotation() { - return this.mappingAnnotation; - } - - /** - * the persistent attribute can tell whether there is a "specified" mapping - * or a "default" one - */ - public boolean isDefault() { - return this.getPersistentAttribute().mappingIsDefault(this); - } - - public boolean shouldValidateAgainstDatabase() { - return this.getTypeMapping().shouldValidateAgainstDatabase(); - } - - public TypeMapping getTypeMapping() { - return this.getPersistentAttribute().getTypeMapping(); - } - - public String getName() { - return this.getPersistentAttribute().getName(); - } - - public Table getDbTable(String tableName) { - return this.getTypeMapping().getDbTable(tableName); - } - - public String getPrimaryKeyColumnName() { - return null; - } - - public boolean isOverridableAttributeMapping() { - return false; - } - - public boolean isOverridableAssociationMapping() { - return false; - } - - public boolean isIdMapping() { - return false; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return false; - } - - // ********** supporting annotation names ********** - - public Iterator<String> supportingAnnotationNames() { - return new ArrayListIterator<String>(getSupportingAnnotationNames()); - } - - protected synchronized String[] getSupportingAnnotationNames() { - if (this.supportingAnnotationNames == null) { - this.supportingAnnotationNames = this.buildSupportingAnnotationNames(); - } - return this.supportingAnnotationNames; - } - - protected String[] buildSupportingAnnotationNames() { - return new String[0]; - } - - - @SuppressWarnings("unchecked") - public void initialize(Annotation annotation) { - this.mappingAnnotation = (T) annotation; - this.initialize(); - } - - protected void initialize() { - // do nothing by default - } - - @SuppressWarnings("unchecked") - public void update(Annotation annotation) { - this.mappingAnnotation = (T) annotation; - this.update(); - } - - protected void update() { - // do nothing by default - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.validateMappingType(messages, astRoot); - } - - protected void validateMappingType(List<IMessage> messages, CompilationUnit astRoot) { - if ( ! this.getTypeMapping().attributeMappingKeyAllowed(this.getKey())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_MAPPING, - new String[] {this.getName()}, - this, - this.getValidationTextRange(astRoot) - ) - ); - } - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getMappingAnnotationTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - protected TextRange getMappingAnnotationTextRange(CompilationUnit astRoot) { - return (this.mappingAnnotation == null) ? null : this.mappingAnnotation.getTextRange(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMappingDefinition.java deleted file mode 100644 index 46bbad8953..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMappingDefinition.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; - -public abstract class AbstractJavaAttributeMappingDefinition - implements JavaAttributeMappingDefinition -{ - protected AbstractJavaAttributeMappingDefinition() { - super(); - } - - - /** - * Default implementation. Override if the mapping definition applies in the annotationless case. - */ - public boolean testDefault(JavaPersistentAttribute persistentAttribute) { - return false; - } - - /** - * Default implementation. Override if the mapping definition needs to do more analysis. - */ - public boolean testSpecified(JavaPersistentAttribute persistentAttribute) { - return persistentAttribute.getResourcePersistentAttribute().getAnnotation(getAnnotationName()) - != null; - } -} 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 fd55f476d5..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, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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 initialize(T column) { - super.initialize(column); - this.defaultTable = this.buildDefaultTable(); - this.specifiedTable = this.getResourceTable(column); - this.specifiedUnique = this.getResourceUnique(column); - this.specifiedNullable = this.getResourceNullable(column); - this.specifiedInsertable = this.getResourceInsertable(column); - this.specifiedUpdatable = this.getResourceUpdatable(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; - getResourceColumn().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 isUnique() { - return (this.getSpecifiedUnique() == null) ? this.isDefaultUnique() : this.getSpecifiedUnique().booleanValue(); - } - - public boolean isDefaultUnique() { - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getSpecifiedUnique() { - return this.specifiedUnique; - } - - public void setSpecifiedUnique(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - this.getResourceColumn().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 isNullable() { - return (this.getSpecifiedNullable() == null) ? this.isDefaultNullable() : this.getSpecifiedNullable().booleanValue(); - } - - public boolean isDefaultNullable() { - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getSpecifiedNullable() { - return this.specifiedNullable; - } - - public void setSpecifiedNullable(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - this.getResourceColumn().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 isInsertable() { - return (this.getSpecifiedInsertable() == null) ? this.isDefaultInsertable() : this.getSpecifiedInsertable().booleanValue(); - } - - public boolean isDefaultInsertable() { - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getSpecifiedInsertable() { - return this.specifiedInsertable; - } - - public void setSpecifiedInsertable(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - this.getResourceColumn().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 isUpdatable() { - return (this.getSpecifiedUpdatable() == null) ? this.isDefaultUpdatable() : this.getSpecifiedUpdatable().booleanValue(); - } - - public boolean isDefaultUpdatable() { - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getSpecifiedUpdatable() { - return this.specifiedUpdatable; - } - - public void setSpecifiedUpdatable(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - this.getResourceColumn().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.getResourceColumn().getTableTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - return getResourceColumn().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> javaCandidateTableNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(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.javaCandidateTableNames(filter); - } - return null; - } - - @Override - protected void update(T column) { - super.update(column); - this.setDefaultTable(this.buildDefaultTable()); - this.setSpecifiedTable_(this.getResourceTable(column)); - this.setSpecifiedUnique_(this.getResourceUnique(column)); - this.setSpecifiedNullable_(this.getResourceNullable(column)); - this.setSpecifiedInsertable_(this.getResourceInsertable(column)); - this.setSpecifiedUpdatable_(this.getResourceUpdatable(column)); - } - - protected String buildDefaultTable() { - return this.getOwner().getDefaultTableName(); - } - - protected String getResourceTable(BaseColumnAnnotation column) { - return column.getTable(); - } - - protected Boolean getResourceUnique(BaseColumnAnnotation column) { - return column.getUnique(); - } - - protected Boolean getResourceNullable(BaseColumnAnnotation column) { - return column.getNullable(); - } - - protected Boolean getResourceInsertable(BaseColumnAnnotation column) { - return column.getInsertable(); - } - - protected Boolean getResourceUpdatable(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 19bcc91ecc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.ArrayTools; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractJavaBaseEmbeddedMapping<T extends Annotation> - extends AbstractJavaAttributeMapping<T> - implements JavaBaseEmbeddedMapping -{ - protected final JavaAttributeOverrideContainer attributeOverrideContainer; - - private Embeddable embeddable; - - protected AbstractJavaBaseEmbeddedMapping(JavaPersistentAttribute parent) { - super(parent); - this.attributeOverrideContainer = this.getJpaFactory().buildJavaAttributeOverrideContainer(this, this); - } - - public JavaAttributeOverrideContainer getAttributeOverrideContainer() { - return this.attributeOverrideContainer; - } - - public PersistentType getOverridablePersistentType() { - Embeddable embeddable = getEmbeddable(); - return embeddable == null ? null : embeddable.getPersistentType(); - } - - //****************** JavaAttributeMapping implementation ******************* - - @Override - protected String[] buildSupportingAnnotationNames() { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.ATTRIBUTE_OVERRIDE, - JPA.ATTRIBUTE_OVERRIDES); - } - - public Embeddable getEmbeddable() { - return this.embeddable; - } - - - @Override - protected void initialize() { - super.initialize(); - this.attributeOverrideContainer.initialize(this.resourcePersistentAttribute); - this.embeddable = this.getPersistentAttribute().getEmbeddable(); - } - - @Override - protected void update() { - super.update(); - this.embeddable = this.getPersistentAttribute().getEmbeddable(); - this.attributeOverrideContainer.update(this.resourcePersistentAttribute); - } - - public Iterator<String> allOverridableAttributeNames() { - return new TransformationIterator<ColumnMapping, String>(this.allOverridableAttributes()) { - @Override - protected String transform(ColumnMapping attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<ColumnMapping> allOverridableAttributes() { - if (this.getEmbeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<AttributeMapping, ColumnMapping>(this.getEmbeddable().attributeMappings()) { - @Override - protected boolean accept(AttributeMapping o) { - return o.isOverridableAttributeMapping(); - } - }; - } - - @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 = getAttributeOverrideContainer().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - //******** Validation ****************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - getAttributeOverrideContainer().validate(messages, reporter, astRoot); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBasicMapping.java deleted file mode 100644 index 49f55a8e28..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBasicMapping.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.Converter; -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.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaConverter; -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.LobAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractJavaBasicMapping extends AbstractJavaAttributeMapping<BasicAnnotation> implements JavaBasicMapping -{ - protected FetchType specifiedFetch; - - protected Boolean specifiedOptional; - - protected final JavaColumn column; - - protected final JavaConverter defaultConverter; - - protected JavaConverter specifiedConverter; - - - protected AbstractJavaBasicMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildJavaColumn(this, this); - this.defaultConverter = getJpaFactory().buildJavaNullConverter(this); - } - - @Override - protected void initialize() { - super.initialize(); - this.column.initialize(this.getResourceColumn()); - this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); - this.specifiedFetch = this.getResourceFetch(); - this.specifiedOptional = this.getResourceOptional(); - } - - public ColumnAnnotation getResourceColumn() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** AttributeMapping implementation *************** - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - //************** JavaAttributeMapping implementation *************** - public String getAnnotationName() { - return BasicAnnotation.ANNOTATION_NAME; - } - - @Override - protected String[] buildSupportingAnnotationNames() { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.COLUMN, - JPA.LOB, - JPA.TEMPORAL, - JPA.ENUMERATED); - } - - public String getDefaultColumnName() { - return getName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - //************** BasicMapping 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.mappingAnnotation.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 isOptional() { - return (this.getSpecifiedOptional() == null) ? this.isDefaultOptional() : this.getSpecifiedOptional().booleanValue(); - } - - public boolean isDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - this.mappingAnnotation.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 JavaConverter getConverter() { - return getSpecifiedConverter() == null ? getDefaultConverter() : getSpecifiedConverter(); - } - - public JavaConverter getDefaultConverter() { - return this.defaultConverter; - } - - public JavaConverter getSpecifiedConverter() { - return this.specifiedConverter; - } - - protected String getSpecifedConverterType() { - if (this.specifiedConverter == null) { - return Converter.NO_CONVERTER; - } - return this.specifiedConverter.getType(); - } - - public void setSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(getSpecifedConverterType(), converterType)) { - return; - } - JavaConverter oldConverter = this.specifiedConverter; - JavaConverter newConverter = buildSpecifiedConverter(converterType); - this.specifiedConverter = null; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.specifiedConverter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setSpecifiedConverter(JavaConverter newConverter) { - JavaConverter oldConverter = this.specifiedConverter; - this.specifiedConverter = newConverter; - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - @Override - protected void update() { - super.update(); - this.column.update(this.getResourceColumn()); - if (this.valuesAreEqual(getResourceConverterType(), getSpecifedConverterType())) { - getSpecifiedConverter().update(this.resourcePersistentAttribute); - } - else { - JavaConverter javaConverter = buildSpecifiedConverter(getResourceConverterType()); - setSpecifiedConverter(javaConverter); - } - this.setSpecifiedFetch_(this.getResourceFetch()); - this.setSpecifiedOptional_(this.getResourceOptional()); - } - - protected FetchType getResourceFetch() { - return FetchType.fromJavaResourceModel(this.mappingAnnotation.getFetch()); - } - - protected Boolean getResourceOptional() { - return this.mappingAnnotation.getOptional(); - } - - protected JavaConverter buildSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.ENUMERATED_CONVERTER)) { - return getJpaFactory().buildJavaEnumeratedConverter(this, this.resourcePersistentAttribute); - } - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getJpaFactory().buildJavaTemporalConverter(this, this.resourcePersistentAttribute); - } - if (this.valuesAreEqual(converterType, Converter.LOB_CONVERTER)) { - return getJpaFactory().buildJavaLobConverter(this, this.resourcePersistentAttribute); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourcePersistentAttribute.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME) != null) { - return Converter.ENUMERATED_CONVERTER; - } - else if (this.resourcePersistentAttribute.getAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { - return Converter.TEMPORAL_CONVERTER; - } - else if (this.resourcePersistentAttribute.getAnnotation(LobAnnotation.ANNOTATION_NAME) != null) { - return Converter.LOB_CONVERTER; - } - - return null; - } - - @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 validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.shouldValidateAgainstDatabase()) { - this.validateColumn(messages, astRoot); - } - if (this.specifiedConverter != null) { - this.specifiedConverter.validate(messages, reporter, astRoot); - } - } - - protected void validateColumn(List<IMessage> messages, CompilationUnit astRoot) { - if (this.getTypeMapping().tableNameIsInvalid(this.column.getTable())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {this.column.getTable(), this.column.getName()}, - this.column, - this.column.getTableTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange(astRoot) - ) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEmbeddable.java deleted file mode 100644 index 272d0f0cd3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEmbeddable.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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 abstract class AbstractJavaEmbeddable - extends AbstractJavaTypeMapping - implements JavaEmbeddable -{ - protected AbstractJavaEmbeddable(JavaPersistentType parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddableAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> supportingAnnotationNames() { - return EmptyIterator.instance(); - } - - public boolean isMapped() { - return true; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java deleted file mode 100644 index bdabdd792b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java +++ /dev/null @@ -1,1566 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JpaPlatformVariation.Supported; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseJoinColumn; -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.InheritanceType; -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.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.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaColumnMapping; -import org.eclipse.jpt.core.context.java.JavaDiscriminatorColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaQueryContainer; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.internal.resource.java.NullPrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -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.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -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.ArrayTools; -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.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractJavaEntity - extends AbstractJavaTypeMapping - implements JavaEntity -{ - protected String specifiedName; - - protected String defaultName; - - protected final JavaTable table; - - protected boolean specifiedTableIsAllowed; - - protected boolean tableIsUndefined; - - protected final List<JavaSecondaryTable> specifiedSecondaryTables; - - protected final List<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected JavaPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - protected InheritanceType specifiedInheritanceStrategy; - - protected InheritanceType defaultInheritanceStrategy; - - protected String defaultDiscriminatorValue; - - protected String specifiedDiscriminatorValue; - - protected boolean specifiedDiscriminatorValueIsAllowed; - - protected boolean discriminatorValueIsUndefined; - - protected final JavaDiscriminatorColumn discriminatorColumn; - - protected boolean specifiedDiscriminatorColumnIsAllowed; - - protected boolean discriminatorColumnIsUndefined; - - protected final JavaAttributeOverrideContainer attributeOverrideContainer; - - protected final JavaAssociationOverrideContainer associationOverrideContainer; - - protected final JavaQueryContainer queryContainer; - - protected final JavaGeneratorContainer generatorContainer; - - protected String idClass; - - protected Entity rootEntity; - - protected AbstractJavaEntity(JavaPersistentType parent) { - super(parent); - this.table = this.getJpaFactory().buildJavaTable(this); - this.discriminatorColumn = buildJavaDiscriminatorColumn(); - this.specifiedSecondaryTables = new ArrayList<JavaSecondaryTable>(); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - this.attributeOverrideContainer = this.getJpaFactory().buildJavaAttributeOverrideContainer(this, this); - this.associationOverrideContainer = this.getJpaFactory().buildJavaAssociationOverrideContainer(this, this); - this.queryContainer = this.getJpaFactory().buildJavaQueryContainer(this); - this.generatorContainer = this.getJpaFactory().buildJavaGeneratorContainer(this); - } - - protected JavaBaseJoinColumn.Owner buildPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected JavaDiscriminatorColumn buildJavaDiscriminatorColumn() { - return this.getJpaFactory().buildJavaDiscriminatorColumn(this, buildDiscriminatorColumnOwner()); - } - - protected JavaDiscriminatorColumn.Owner buildDiscriminatorColumnOwner() { - return new JavaDiscriminatorColumn.Owner(){ - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractJavaEntity.this.getDbTable(tableName); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return AbstractJavaEntity.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return AbstractJavaEntity.this; - } - - public String getDefaultColumnName() { - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getName() - : - discriminatorColumnIsUndefined()? - null - : - DiscriminatorColumn.DEFAULT_NAME; - } - - public int getDefaultLength() { - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getLength() - : - discriminatorColumnIsUndefined()? - 0//TODO think i want to return null here - : - DiscriminatorColumn.DEFAULT_LENGTH; - } - - public DiscriminatorType getDefaultDiscriminatorType() { - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getDiscriminatorType() - : - discriminatorColumnIsUndefined()? - null - : - DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE; - } - }; - } - - @Override - public void initialize(JavaResourcePersistentType resourcePersistentType) { - super.initialize(resourcePersistentType); - - this.specifiedName = this.getResourceName(); - this.defaultName = this.getResourceDefaultName(); - this.rootEntity = calculateRootEntity(); - this.defaultInheritanceStrategy = this.buildDefaultInheritanceStrategy(); - this.specifiedInheritanceStrategy = this.getResourceInheritanceStrategy(getResourceInheritance()); - this.specifiedDiscriminatorValueIsAllowed = this.buildSpecifiedDiscriminatorValueIsAllowed(); - this.discriminatorValueIsUndefined = this.buildDiscriminatorValueIsUndefined(); - this.specifiedDiscriminatorValue = this.getResourceDiscriminatorValue().getValue(); - this.defaultDiscriminatorValue = this.buildDefaultDiscriminatorValue(); - this.specifiedDiscriminatorColumnIsAllowed = this.buildSpecifiedDiscriminatorColumnIsAllowed(); - this.discriminatorColumnIsUndefined = this.buildDiscriminatorColumnIsUndefined(); - this.discriminatorColumn.initialize(resourcePersistentType); - this.specifiedTableIsAllowed = this.buildSpecifiedTableIsAllowed(); - this.tableIsUndefined = this.buildTableIsUndefined(); - this.table.initialize(resourcePersistentType); - this.initializeSecondaryTables(); - this.generatorContainer.initialize(resourcePersistentType); - this.queryContainer.initialize(resourcePersistentType); - this.initializePrimaryKeyJoinColumns(); - this.initializeDefaultPrimaryKeyJoinColumn(); - this.attributeOverrideContainer.initialize(resourcePersistentType); - this.associationOverrideContainer.initialize(resourcePersistentType); - this.initializeIdClass(); - } - - protected void initializeSecondaryTables() { - for (Iterator<NestableAnnotation> stream = - this.javaResourcePersistentType.annotations( - SecondaryTableAnnotation.ANNOTATION_NAME, - SecondaryTablesAnnotation.ANNOTATION_NAME); - stream.hasNext(); ) { - this.specifiedSecondaryTables.add( - buildSecondaryTable((SecondaryTableAnnotation) stream.next())); - } - } - - protected void initializePrimaryKeyJoinColumns() { - for (Iterator<NestableAnnotation> stream = - this.javaResourcePersistentType.annotations( - PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - stream.hasNext(); ) { - this.specifiedPrimaryKeyJoinColumns.add( - buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) stream.next())); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumnAnnotation(this.javaResourcePersistentType)); - } - - //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 getResourceInheritance() { - return (InheritanceAnnotation) this.javaResourcePersistentType. - getNonNullAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - } - - protected DiscriminatorValueAnnotation getResourceDiscriminatorValue() { - return (DiscriminatorValueAnnotation) this.javaResourcePersistentType. - getNonNullAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - } - - protected void initializeIdClass() { - IdClassAnnotation resourceIdClass = getResourceIdClass(); - if (resourceIdClass != null) { - this.idClass = resourceIdClass.getValue(); - } - } - - @Override - protected EntityAnnotation getResourceMappingAnnotation() { - return (EntityAnnotation) super.getResourceMappingAnnotation(); - } - - - //****************** AttributeOverrideContainer.Owner implementation ******************* - - public TypeMapping getTypeMapping() { - return this; - } - - public PersistentType getOverridablePersistentType() { - return getPersistentType().getSuperPersistentType(); - } - - - //****************** TypeMapping implementation ******************* - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public boolean isMapped() { - return true; - } - - @Override - public String getPrimaryTableName() { - return this.getTable().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return getTable().getDbTable(); - } - - private static final org.eclipse.jpt.db.Table[] EMPTY_DB_TABLE_ARRAY = new org.eclipse.jpt.db.Table[0]; - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - // the JPA platform searches database objects for us - return this.getDataSource().selectDatabaseObjectForIdentifier( - ArrayTools.array(this.associatedDbTablesIncludingInherited(), EMPTY_DB_TABLE_ARRAY), - tableName - ); - } - - protected Iterator<org.eclipse.jpt.db.Table> associatedDbTablesIncludingInherited() { - return new FilteringIterator<org.eclipse.jpt.db.Table, org.eclipse.jpt.db.Table>(this.associatedDbTablesIncludingInherited_()) { - @Override - protected boolean accept(org.eclipse.jpt.db.Table t) { - return t != null; - } - }; - } - - protected Iterator<org.eclipse.jpt.db.Table> associatedDbTablesIncludingInherited_() { - return new TransformationIterator<Table, org.eclipse.jpt.db.Table>(this.associatedTablesIncludingInherited()) { - @Override - protected org.eclipse.jpt.db.Table transform(Table t) { - return t.getDbTable(); - } - }; - } - - @Override - public Schema getDbSchema() { - return getTable().getDbSchema(); - } - - - //****************** IJavaTypeMapping implemenation ******************* - - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> supportingAnnotationNames() { - 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); - } - - //****************** Entity implementation ******************* - - 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.getResourceMappingAnnotation().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/*private-protected*/ void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(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.initialize(secondaryTableResource); - fireItemAdded(SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); - return secondaryTable; - } - - public JavaSecondaryTable addSpecifiedSecondaryTable() { - return this.addSpecifiedSecondaryTable(this.specifiedSecondaryTables.size()); - } - - protected void addSpecifiedSecondaryTable(int index, JavaSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.specifiedSecondaryTables, SPECIFIED_SECONDARY_TABLES_LIST); - } - - protected void addSpecifiedSecondaryTable(JavaSecondaryTable secondaryTable) { - this.addSpecifiedSecondaryTable(this.specifiedSecondaryTables.size(), secondaryTable); - } - - 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(SPECIFIED_SECONDARY_TABLES_LIST, index, removedSecondaryTable); - } - - protected void removeSpecifiedSecondaryTable_(JavaSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.specifiedSecondaryTables, SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void moveSpecifiedSecondaryTable(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedSecondaryTables, targetIndex, sourceIndex); - this.javaResourcePersistentType.moveAnnotation( - targetIndex, sourceIndex, SecondaryTablesAnnotation.ANNOTATION_NAME); - fireItemMoved(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; - getResourceInheritance().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; - getResourceDiscriminatorValue().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 specifiedDiscriminatorValueIsAllowed() { - return this.specifiedDiscriminatorValueIsAllowed; - } - - protected void setSpecifiedDiscriminatorValueIsAllowed(boolean specifiedDiscriminatorValueIsAllowed) { - boolean old = this.specifiedDiscriminatorValueIsAllowed; - this.specifiedDiscriminatorValueIsAllowed = specifiedDiscriminatorValueIsAllowed; - firePropertyChanged(Entity.SPECIFIED_DISCRIMINATOR_VALUE_IS_ALLOWED_PROPERTY, old, specifiedDiscriminatorValueIsAllowed); - } - - public boolean discriminatorValueIsUndefined() { - return this.discriminatorValueIsUndefined; - } - - protected void setDiscriminatorValueIsUndefined(boolean discriminatorValueIsUndefined) { - boolean old = this.discriminatorValueIsUndefined; - this.discriminatorValueIsUndefined = discriminatorValueIsUndefined; - firePropertyChanged(DISCRIMINATOR_VALUE_IS_UNDEFINED_PROPERTY, old, discriminatorValueIsUndefined); - } - - public boolean specifiedDiscriminatorColumnIsAllowed() { - return this.specifiedDiscriminatorColumnIsAllowed; - } - - protected void setSpecifiedDiscriminatorColumnIsAllowed(boolean specifiedDiscriminatorColumnIsAllowed) { - boolean old = this.specifiedDiscriminatorColumnIsAllowed; - this.specifiedDiscriminatorColumnIsAllowed = specifiedDiscriminatorColumnIsAllowed; - firePropertyChanged(SPECIFIED_DISCRIMINATOR_COLUMN_IS_ALLOWED_PROPERTY, old, specifiedDiscriminatorColumnIsAllowed); - } - - public boolean discriminatorColumnIsUndefined() { - return this.discriminatorColumnIsUndefined; - } - - protected void setDiscriminatorColumnIsUndefined(boolean discriminatorColumnIsUndefined) { - boolean old = this.discriminatorColumnIsUndefined; - this.discriminatorColumnIsUndefined = discriminatorColumnIsUndefined; - firePropertyChanged(DISCRIMINATOR_COLUMN_IS_UNDEFINED_PROPERTY, old, discriminatorColumnIsUndefined); - } - - public boolean specifiedTableIsAllowed() { - return this.specifiedTableIsAllowed; - } - - protected void setSpecifiedTableIsAllowed(boolean specifiedTableIsAllowed) { - boolean old = this.specifiedTableIsAllowed; - this.specifiedTableIsAllowed = specifiedTableIsAllowed; - firePropertyChanged(SPECIFIED_TABLE_IS_ALLOWED_PROPERTY, old, specifiedTableIsAllowed); - } - - public boolean tableIsUndefined() { - return this.tableIsUndefined; - } - - protected void setTableIsUndefined(boolean tableIsUndefined) { - boolean old = this.tableIsUndefined; - this.tableIsUndefined = tableIsUndefined; - firePropertyChanged(TABLE_IS_UNDEFINED_PROPERTY, old, tableIsUndefined); - } - - public JavaGeneratorContainer getGeneratorContainer() { - return this.generatorContainer; - } - - 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(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, buildPrimaryKeyJoinColumnOwner()); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = - (PrimaryKeyJoinColumnAnnotation) this.javaResourcePersistentType. - addAnnotation( - index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - primaryKeyJoinColumn.initialize(pkJoinColumnResource); - this.fireItemAdded(SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return primaryKeyJoinColumn; - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.addSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.size(), primaryKeyJoinColumn); - } - - 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 NullPrimaryKeyJoinColumnAnnotation(this.javaResourcePersistentType)); - } - this.javaResourcePersistentType.removeAnnotation( - index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - fireItemRemoved(SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (this.defaultPrimaryKeyJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(DEFAULT_PRIMARY_KEY_JOIN_COLUMN, null, this.defaultPrimaryKeyJoinColumn); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - this.javaResourcePersistentType.moveAnnotation( - targetIndex, sourceIndex, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - moveItemInList(targetIndex, sourceIndex, this.specifiedPrimaryKeyJoinColumns, SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public JavaAttributeOverrideContainer getAttributeOverrideContainer() { - return this.attributeOverrideContainer; - } - - public JavaAssociationOverrideContainer getAssociationOverrideContainer() { - return this.associationOverrideContainer; - } - - public JavaQueryContainer getQueryContainer() { - return this.queryContainer; - } - - public char getIdClassEnclosingTypeSeparator() { - return '.'; - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (this.valuesAreDifferent(newIdClass, oldIdClass)) { - if (newIdClass != null) { - if (getResourceIdClass() == null) { - addResourceIdClass(); - } - getResourceIdClass().setValue(newIdClass); - } - else { - removeResourceIdClass(); - } - } - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected IdClassAnnotation getResourceIdClass() { - return (IdClassAnnotation) this.javaResourcePersistentType. - getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void addResourceIdClass() { - this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void removeResourceIdClass() { - this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - public Entity getParentEntity() { - for (Iterator<PersistentType> stream = getPersistentType().ancestors(); stream.hasNext();) { - TypeMapping typeMapping = stream.next().getMapping(); - if (typeMapping instanceof Entity) { - return (Entity) typeMapping; - } - } - return this; - } - - /** - * Return the ultimate top of the inheritance hierarchy - * This method should never return null. The root - * is defined as the persistent type in the inheritance hierarchy - * that has no parent. The root should be an entity - * - * Non-entities in the hierarchy should be ignored, ie skip - * over them in the search for the root. - */ - protected Entity getRootEntity() { - return this.rootEntity; - } - - /** - * Table name defaults to the entity name. - * If the entity is part of a single table inheritance hierarchy, table - * name defaults to the root entity's table name. - * If the entity is abstract and part of a table per class - * inheritance hierarchy, the table name defaults to null, no table applies - */ - public String getDefaultTableName() { - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getName() - : - this.isAbstractTablePerClass() ? - null - : - this.getName(); - } - - public String getDefaultSchema() { - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getSchema() - : - this.isAbstractTablePerClass() ? - null - : - this.getContextDefaultSchema(); - } - - public String getDefaultCatalog() { - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getCatalog() - : - this.isAbstractTablePerClass() ? - null - : - this.getContextDefaultCatalog(); - } - - /** - * Return whether the entity is a descendant of the root entity - * of a "single table" inheritance hierarchy. - */ - protected boolean isSingleTableDescendant() { - return (this.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) - && this.isDescendant(); - } - - /** - * Return whether the entity is a descendant in (as opposed to the root of) - * an inheritance hierarchy. - */ - protected boolean isDescendant() { - return ! this.isRoot(); - } - - /** - * Return whether the entity is the top of an inheritance hierarchy. - */ - protected boolean isRoot() { - return this == this.getRootEntity(); - } - - /** - * Return whether the entity is the top of an inheritance hierarchy - * and has no descendants and no specified inheritance strategy has been defined. - */ - protected boolean isRootNoDescendantsNoStrategyDefined() { - return isRoot() && !getPersistenceUnit().isRootWithSubEntities(this.getName()) && getSpecifiedInheritanceStrategy() == null; - } - - /** - * Return whether the entity is abstract and is a part of a - * "table per class" inheritance hierarchy. - */ - protected boolean isAbstractTablePerClass() { - return isAbstract() && isTablePerClass(); - } - - /** - * Return whether the entity is a part of a "table per class" - * inheritance hierarchy. - */ - protected boolean isTablePerClass() { - return (this.getInheritanceStrategy() == InheritanceType.TABLE_PER_CLASS); - } - - /** - * Return whether the entity is a part of a "table per class" - * inheritance hierarchy. - */ - protected boolean isTablePerClassDescendant() { - return isTablePerClass() && isDescendant(); - } - - /** - * Return whether the type is abstract. - */ - protected boolean isAbstract() { - return this.javaResourcePersistentType.isAbstract(); - } - - 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 = this.attributeOverrideContainer.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; - } - - public boolean tableNameIsInvalid(String tableName) { - return ! CollectionTools.contains(this.associatedTableNamesIncludingInherited(), tableName); - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return super.shouldValidateAgainstDatabase() && ! isAbstractTablePerClass(); - } - - @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(); - } - }; - } - - /** - * Return an iterator of Entities, each which inherits from the one before, - * and terminates at the root entity (or at the point of cyclicity). - */ - protected Iterator<TypeMapping> ancestors() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().ancestors()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - @Override - public Iterator<JavaColumnMapping> overridableAttributes() { - if (!isTablePerClass()) { - return EmptyIterator.instance(); - } - return new FilteringIterator<JavaAttributeMapping, JavaColumnMapping>(this.attributeMappings()) { - @Override - protected boolean accept(JavaAttributeMapping o) { - return o.isOverridableAttributeMapping(); - } - }; - } - - @Override - public Iterator<JavaRelationshipMapping> overridableAssociations() { - if (!isTablePerClass()) { - return EmptyIterator.instance(); - } - return new FilteringIterator<JavaAttributeMapping, JavaRelationshipMapping>(this.attributeMappings()) { - @Override - protected boolean accept(JavaAttributeMapping o) { - return o.isOverridableAssociationMapping(); - } - }; - } - - @Override - public Iterator<ColumnMapping> allOverridableAttributes() { - return new CompositeIterator<ColumnMapping>(new TransformationIterator<TypeMapping, Iterator<ColumnMapping>>(this.ancestors()) { - @Override - protected Iterator<ColumnMapping> transform(TypeMapping mapping) { - return mapping.overridableAttributes(); - } - }); - } - - @Override - public Iterator<RelationshipMapping> allOverridableAssociations() { - return new CompositeIterator<RelationshipMapping>(new TransformationIterator<TypeMapping, Iterator<RelationshipMapping>>(this.ancestors()) { - @Override - protected Iterator<RelationshipMapping> transform(TypeMapping mapping) { - return mapping.overridableAssociations(); - } - }); - } - - @Override - public void update(JavaResourcePersistentType resourcePersistentType) { - super.update(resourcePersistentType); - - this.setSpecifiedName_(this.getResourceName()); - this.setDefaultName(this.getResourceDefaultName()); - - this.updateRootEntity(); - this.updateInheritance(this.getResourceInheritance()); - this.updateDiscriminatorColumn(); - this.updateDiscriminatorValue(this.getResourceDiscriminatorValue()); - this.setSpecifiedTableIsAllowed(this.buildSpecifiedTableIsAllowed()); - this.setTableIsUndefined(this.buildTableIsUndefined()); - this.updateTable(); - this.updateSecondaryTables(); - this.generatorContainer.update(resourcePersistentType); - this.queryContainer.update(resourcePersistentType); - this.updateSpecifiedPrimaryKeyJoinColumns(); - this.updateDefaultPrimaryKeyJoinColumn(); - this.attributeOverrideContainer.update(resourcePersistentType); - this.associationOverrideContainer.update(resourcePersistentType); - this.updateIdClass(); - } - - @Override - public void postUpdate() { - super.postUpdate(); - this.postUpdateDiscriminatorColumn(); - this.postUpdateDiscriminatorValue(); - this.associationOverrideContainer.postUpdate(); - } - - protected String getResourceName() { - return this.getResourceMappingAnnotation().getName(); - } - - protected String getResourceDefaultName() { - return this.javaResourcePersistentType.getName(); - } - - protected void updateTable() { - getTable().update(this.javaResourcePersistentType); - } - - protected void updateInheritance(InheritanceAnnotation inheritanceResource) { - this.setSpecifiedInheritanceStrategy_(this.getResourceInheritanceStrategy(inheritanceResource)); - this.setDefaultInheritanceStrategy(this.buildDefaultInheritanceStrategy()); - } - - protected InheritanceType getResourceInheritanceStrategy(InheritanceAnnotation inheritanceResource) { - return InheritanceType.fromJavaResourceModel(inheritanceResource.getStrategy()); - } - - protected InheritanceType buildDefaultInheritanceStrategy() { - return this.isRoot() ? InheritanceType.SINGLE_TABLE : this.getRootEntity().getInheritanceStrategy(); - } - - protected void updateRootEntity() { - //I am making an assumption here that we don't need property change notification for rootEntity, this might be wrong - this.rootEntity = calculateRootEntity(); - if (this.rootEntity != this) { - this.rootEntity.addSubEntity(this); - } - } - - protected Entity calculateRootEntity() { - Entity root = this; - for (Iterator<PersistentType> stream = getPersistentType().inheritanceHierarchy(); stream.hasNext();) { - PersistentType persistentType = stream.next(); - if (persistentType.getMapping() instanceof Entity) { - root = (Entity) persistentType.getMapping(); - } - } - return root; - } - - public void addSubEntity(Entity subEntity) { - getPersistenceUnit().addRootWithSubEntities(getName()); - } - - protected void updateDiscriminatorColumn() { - this.setSpecifiedDiscriminatorColumnIsAllowed(this.buildSpecifiedDiscriminatorColumnIsAllowed()); - getDiscriminatorColumn().update(this.javaResourcePersistentType); - } - - protected void postUpdateDiscriminatorColumn() { - this.setDiscriminatorColumnIsUndefined(this.buildDiscriminatorColumnIsUndefined()); - this.getDiscriminatorColumn().postUpdate(); - } - - protected void updateDiscriminatorValue(DiscriminatorValueAnnotation discriminatorValueResource) { - this.setSpecifiedDiscriminatorValueIsAllowed(this.buildSpecifiedDiscriminatorValueIsAllowed()); - this.setSpecifiedDiscriminatorValue_(discriminatorValueResource.getValue()); - } - - protected void postUpdateDiscriminatorValue() { - this.setDiscriminatorValueIsUndefined(this.buildDiscriminatorValueIsUndefined()); - this.setDefaultDiscriminatorValue(this.buildDefaultDiscriminatorValue()); - } - - /** - * From the Spec: - * If the DiscriminatorValue annotation is not specified, a - * provider-specific function to generate a value representing - * the entity type is used for the value of the discriminator - * column. If the DiscriminatorType is STRING, the discriminator - * value default is the entity name. - * - * TODO extension point for provider-specific function? - */ - protected String buildDefaultDiscriminatorValue() { - if (discriminatorValueIsUndefined()) { - return null; - } - if (this.getDiscriminatorType() != DiscriminatorType.STRING) { - return null; - } - return this.getName(); - } - - protected DiscriminatorType getDiscriminatorType() { - return this.getDiscriminatorColumn().getDiscriminatorType(); - } - - protected boolean buildSpecifiedDiscriminatorValueIsAllowed() { - return !isTablePerClass() && !isAbstract(); - } - - protected boolean buildDiscriminatorValueIsUndefined() { - return isTablePerClass() || isAbstract() || isRootNoDescendantsNoStrategyDefined(); - } - - protected boolean buildSpecifiedDiscriminatorColumnIsAllowed() { - return !isTablePerClass() && isRoot(); - } - - protected boolean buildDiscriminatorColumnIsUndefined() { - return isTablePerClass() || isRootNoDescendantsNoStrategyDefined(); - } - - protected boolean buildSpecifiedTableIsAllowed() { - return !isAbstractTablePerClass() && !isSingleTableDescendant(); - } - - protected boolean buildTableIsUndefined() { - return isAbstractTablePerClass(); - } - - protected void updateSecondaryTables() { - ListIterator<JavaSecondaryTable> secondaryTables = specifiedSecondaryTables(); - Iterator<NestableAnnotation> resourceSecondaryTables = - this.javaResourcePersistentType.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(buildSecondaryTable((SecondaryTableAnnotation) resourceSecondaryTables.next())); - } - } - - protected JavaSecondaryTable buildSecondaryTable(SecondaryTableAnnotation secondaryTableResource) { - JavaSecondaryTable secondaryTable = getJpaFactory().buildJavaSecondaryTable(this); - secondaryTable.initialize(secondaryTableResource); - return secondaryTable; - } - - protected void updateSpecifiedPrimaryKeyJoinColumns() { - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - Iterator<NestableAnnotation> resourcePrimaryKeyJoinColumns = - this.javaResourcePersistentType.annotations( - PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - while (primaryKeyJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update((PrimaryKeyJoinColumnAnnotation) resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) resourcePrimaryKeyJoinColumns.next())); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, buildPrimaryKeyJoinColumnOwner()); - primaryKeyJoinColumn.initialize(primaryKeyJoinColumnResource); - return primaryKeyJoinColumn; - } - - protected void updateDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumnAnnotation(this.javaResourcePersistentType))); - } - else { - this.defaultPrimaryKeyJoinColumn.update(new NullPrimaryKeyJoinColumnAnnotation(this.javaResourcePersistentType)); - } - } - - protected void updateIdClass( ) { - IdClassAnnotation annotation = getResourceIdClass(); - if (annotation != null) { - setIdClass_(annotation.getValue()); - } - else { - setIdClass_(null); - } - } - - - //******************** 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; - } - } - result = this.getAttributeOverrideContainer().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getAssociationOverrideContainer().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getDiscriminatorColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getGeneratorContainer().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - - //********** Validation ******************************************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - - this.validateTable(messages, reporter, astRoot); - this.validateId(messages, astRoot); - this.validateInheritance(messages, reporter, astRoot); - this.getGeneratorContainer().validate(messages, reporter, astRoot); - this.getQueryContainer().validate(messages, reporter, astRoot); - this.getAttributeOverrideContainer().validate(messages, reporter, astRoot); - this.getAssociationOverrideContainer().validate(messages, reporter, astRoot); - - for (Iterator<JavaSecondaryTable> stream = this.specifiedSecondaryTables(); stream.hasNext();) { - stream.next().validate(messages, reporter, astRoot); - } - } - - protected void validateTable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - if (isAbstractTablePerClass()) { - if (this.table.isResourceSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE, - new String[] {this.getName()}, - this, - this.getTable().getValidationTextRange(astRoot) - ) - ); - } - return; - } - if (isSingleTableDescendant()) { - if (this.table.isResourceSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE, - new String[] {this.getName()}, - this, - this.getTable().getValidationTextRange(astRoot) - ) - ); - } - return; - } - this.table.validate(messages, reporter, astRoot); - } - - protected void validateId(List<IMessage> messages, CompilationUnit astRoot) { - if (this.entityHasNoId()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NO_ID, - new String[] {this.getName()}, - this, - this.getValidationTextRange(astRoot) - ) - ); - } - } - - protected void validateInheritance(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - validateInheritanceStrategy(messages, astRoot); - validateDiscriminatorColumn(messages, reporter, astRoot); - validateDiscriminatorValue(messages, astRoot); - } - - protected void validateDiscriminatorColumn(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - if (specifiedDiscriminatorColumnIsAllowed() && !discriminatorColumnIsUndefined()) { - getDiscriminatorColumn().validate(messages, reporter, astRoot); - } - else if (getDiscriminatorColumn().isResourceSpecified()) { - if (!isRoot()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorColumnTextRange(astRoot) - ) - ); - } - else if (isTablePerClass()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorColumnTextRange(astRoot) - ) - ); - } - } - } - - protected void validateDiscriminatorValue(List<IMessage> messages, CompilationUnit astRoot) { - if (discriminatorValueIsUndefined() && getSpecifiedDiscriminatorValue() != null) { - if (isAbstract()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorValueTextRange(astRoot) - ) - ); - } - else if (isTablePerClass()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorValueTextRange(astRoot) - ) - ); - } - } - } - - protected void validateInheritanceStrategy(List<IMessage> messages, CompilationUnit astRoot) { - Supported tablePerConcreteClassInheritanceIsSupported = getJpaPlatformVariation().getTablePerConcreteClassInheritanceIsSupported(); - if (tablePerConcreteClassInheritanceIsSupported == Supported.YES) { - return; - } - if ((getInheritanceStrategy() == InheritanceType.TABLE_PER_CLASS) && isRoot()) { - if (tablePerConcreteClassInheritanceIsSupported == Supported.NO) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM, - new String[] {this.getName()}, - this, - this.getInheritanceStrategyTextRange(astRoot) - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM, - new String[] {this.getName()}, - this, - this.getInheritanceStrategyTextRange(astRoot) - ) - ); - } - } - } - - protected TextRange getDiscriminatorValueTextRange(CompilationUnit astRoot) { - return getResourceDiscriminatorValue().getTextRange(astRoot); - } - - protected TextRange getDiscriminatorColumnTextRange(CompilationUnit astRoot) { - return getDiscriminatorColumn().getValidationTextRange(astRoot); - } - - protected TextRange getInheritanceStrategyTextRange(CompilationUnit astRoot) { - return getResourceInheritance().getStrategyTextRange(astRoot); - } - - protected boolean entityHasNoId() { - return ! this.entityHasId(); - } - - protected boolean entityHasId() { - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext(); ) { - if (stream.next().isIdAttribute()) { - return true; - } - } - return false; - } - - - // ********** pk join column owner ********** - - class PrimaryKeyJoinColumnOwner implements JavaBaseJoinColumn.Owner - { - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return AbstractJavaEntity.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return AbstractJavaEntity.this; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractJavaEntity.this.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getReferencedColumnDbTable() { - Entity parentEntity = AbstractJavaEntity.this.getParentEntity(); - return (parentEntity == null) ? null : parentEntity.getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return AbstractJavaEntity.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractJavaEntity.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return AbstractJavaEntity.this.getParentEntity().getPrimaryKeyColumnName(); - } - } - -} 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 1b7acb4051..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaGenerator.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * - */ -public abstract class AbstractJavaGenerator - extends AbstractJavaJpaContextNode - implements JavaGenerator -{ - protected String name; - - protected Integer specifiedInitialValue; - - protected Integer specifiedAllocationSize; - - protected GeneratorAnnotation resourceGenerator; - - - protected AbstractJavaGenerator(JavaJpaContextNode parent) { - super(parent); - } - - protected GeneratorAnnotation getResourceGenerator() { - return this.resourceGenerator; - } - - - // ********** name ********** - - public String getName() { - return this.name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - this.resourceGenerator.setName(name); - this.firePropertyChanged(Generator.NAME_PROPERTY, old, name); - } - - protected void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(Generator.NAME_PROPERTY, old, name); - } - - - // ********** initial value ********** - - public int getInitialValue() { - return (this.specifiedInitialValue != null) ? this.specifiedInitialValue.intValue() : this.getDefaultInitialValue(); - } - - public Integer getSpecifiedInitialValue() { - return this.specifiedInitialValue; - } - - public void setSpecifiedInitialValue(Integer specifiedInitialValue) { - Integer old = this.specifiedInitialValue; - this.specifiedInitialValue = specifiedInitialValue; - this.resourceGenerator.setInitialValue(specifiedInitialValue); - this.firePropertyChanged(Generator.SPECIFIED_INITIAL_VALUE_PROPERTY, old, specifiedInitialValue); - } - - protected void setSpecifiedInitialValue_(Integer specifiedInitialValue) { - Integer old = this.specifiedInitialValue; - this.specifiedInitialValue = specifiedInitialValue; - this.firePropertyChanged(Generator.SPECIFIED_INITIAL_VALUE_PROPERTY, old, specifiedInitialValue); - } - - - // ********** allocation size ********** - - public int getAllocationSize() { - return (this.specifiedAllocationSize != null) ? this.specifiedAllocationSize.intValue() : this.getDefaultAllocationSize(); - } - - public Integer getSpecifiedAllocationSize() { - return this.specifiedAllocationSize; - } - - public void setSpecifiedAllocationSize(Integer specifiedAllocationSize) { - Integer old = this.specifiedAllocationSize; - this.specifiedAllocationSize = specifiedAllocationSize; - this.resourceGenerator.setAllocationSize(specifiedAllocationSize); - this.firePropertyChanged(Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY, old, specifiedAllocationSize); - } - - protected void setSpecifiedAllocationSize_(Integer specifiedAllocationSize) { - Integer old = this.specifiedAllocationSize; - this.specifiedAllocationSize = specifiedAllocationSize; - this.firePropertyChanged(Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY, old, specifiedAllocationSize); - } - - public int getDefaultAllocationSize() { - return Generator.DEFAULT_ALLOCATION_SIZE; - } - - - // ********** text ranges ********** - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - public TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.resourceGenerator.getTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.resourceGenerator.getNameTextRange(astRoot); - } - - - // ********** resource => context ********** - - protected void initialize(GeneratorAnnotation generatorAnnotation) { - this.resourceGenerator = generatorAnnotation; - this.name = generatorAnnotation.getName(); - this.specifiedInitialValue = generatorAnnotation.getInitialValue(); - this.specifiedAllocationSize = generatorAnnotation.getAllocationSize(); - } - - protected void update(GeneratorAnnotation generatorAnnotation) { - this.resourceGenerator = generatorAnnotation; - this.setName_(generatorAnnotation.getName()); - this.setSpecifiedInitialValue_(generatorAnnotation.getInitialValue()); - this.setSpecifiedAllocationSize_(generatorAnnotation.getAllocationSize()); - getPersistenceUnit().addGenerator(this); - } - - - // ********** database stuff ********** - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - protected abstract String getSchema(); - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - protected abstract String getCatalog(); - - - // ********** misc ********** - - public boolean isVirtual() { - return false; - } - - public boolean overrides(Generator generator) { - // java is at the base of the tree - return false; - } - - public boolean duplicates(Generator other) { - return (this != other) - && ! StringTools.stringIsEmpty(this.name) - && this.name.equals(other.getName()) - && ! this.overrides(other) - && ! other.overrides(this); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java deleted file mode 100644 index 3b62f85ab4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java +++ /dev/null @@ -1,384 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.Converter; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaConverter; -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -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.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.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.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractJavaIdMapping - extends AbstractJavaAttributeMapping<IdAnnotation> - implements JavaIdMapping -{ - protected final JavaColumn column; - - protected JavaGeneratedValue generatedValue; - - protected final JavaGeneratorContainer generatorContainer; - - protected final JavaConverter defaultConverter; - - protected JavaConverter specifiedConverter; - - - protected AbstractJavaIdMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = this.getJpaFactory().buildJavaColumn(this, this); - this.defaultConverter = this.getJpaFactory().buildJavaNullConverter(this); - this.generatorContainer = this.buildGeneratorContainer(); - } - - @Override - protected void initialize() { - super.initialize(); - this.column.initialize(this.getResourceColumn()); - this.generatorContainer.initialize(this.resourcePersistentAttribute); - this.initializeGeneratedValue(); - this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); - } - - protected void initializeGeneratedValue() { - GeneratedValueAnnotation resourceGeneratedValue = this.getResourceGeneratedValue(); - if (resourceGeneratedValue != null) { - this.generatedValue = this.buildGeneratedValue(resourceGeneratedValue); - } - } - - public ColumnAnnotation getResourceColumn() { - return (ColumnAnnotation) this.getResourcePersistentAttribute(). - getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - private JavaGeneratorContainer buildGeneratorContainer() { - return this.getJpaFactory().buildJavaGeneratorContainer(this); - } - - //************** JavaAttributeMapping implementation *************** - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return IdAnnotation.ANNOTATION_NAME; - } - - @Override - protected String[] buildSupportingAnnotationNames() { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.COLUMN, - JPA.GENERATED_VALUE, - JPA.TEMPORAL, - JPA.TABLE_GENERATOR, - JPA.SEQUENCE_GENERATOR); - } - - public String getDefaultColumnName() { - return getName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - //************** IdMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - public JavaGeneratedValue addGeneratedValue() { - if (getGeneratedValue() != null) { - throw new IllegalStateException("gemeratedValue already exists"); //$NON-NLS-1$ - } - this.generatedValue = getJpaFactory().buildJavaGeneratedValue(this); - GeneratedValueAnnotation generatedValueResource = - (GeneratedValueAnnotation) getResourcePersistentAttribute(). - addAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - this.generatedValue.initialize(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"); //$NON-NLS-1$ - } - 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 JavaGeneratorContainer getGeneratorContainer() { - return this.generatorContainer; - } - - - public JavaConverter getConverter() { - return getSpecifiedConverter() == null ? getDefaultConverter() : getSpecifiedConverter(); - } - - public JavaConverter getDefaultConverter() { - return this.defaultConverter; - } - - public JavaConverter getSpecifiedConverter() { - return this.specifiedConverter; - } - - protected String getSpecifedConverterType() { - if (this.specifiedConverter == null) { - return Converter.NO_CONVERTER; - } - return this.specifiedConverter.getType(); - } - - public void setSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(getSpecifedConverterType(), converterType)) { - return; - } - JavaConverter oldConverter = this.specifiedConverter; - JavaConverter newConverter = buildSpecifiedConverter(converterType); - this.specifiedConverter = null; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.specifiedConverter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setSpecifiedConverter(JavaConverter newConverter) { - JavaConverter oldConverter = this.specifiedConverter; - this.specifiedConverter = newConverter; - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - @Override - protected void update() { - super.update(); - this.column.update(this.getResourceColumn()); - this.generatorContainer.update(this.resourcePersistentAttribute); - this.updateGeneratedValue(); - if (this.valuesAreEqual(getResourceConverterType(), getSpecifedConverterType())) { - getSpecifiedConverter().update(this.resourcePersistentAttribute); - } - else { - JavaConverter javaConverter = buildSpecifiedConverter(getResourceConverterType()); - setSpecifiedConverter(javaConverter); - } - } - - protected void updateGeneratedValue() { - GeneratedValueAnnotation resourceGeneratedValue = getResourceGeneratedValue(); - if (resourceGeneratedValue == null) { - if (getGeneratedValue() != null) { - setGeneratedValue(null); - } - } - else { - if (getGeneratedValue() == null) { - setGeneratedValue(buildGeneratedValue(resourceGeneratedValue)); - } - else { - getGeneratedValue().update(resourceGeneratedValue); - } - } - } - - protected JavaGeneratedValue buildGeneratedValue(GeneratedValueAnnotation resourceGeneratedValue) { - JavaGeneratedValue gv = getJpaFactory().buildJavaGeneratedValue(this); - gv.initialize(resourceGeneratedValue); - return gv; - } - - protected TableGeneratorAnnotation getResourceTableGenerator() { - return (TableGeneratorAnnotation) this.resourcePersistentAttribute. - getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - } - - protected SequenceGeneratorAnnotation getResourceSequenceGenerator() { - return (SequenceGeneratorAnnotation) this.resourcePersistentAttribute. - getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - } - - protected GeneratedValueAnnotation getResourceGeneratedValue() { - return (GeneratedValueAnnotation) this.resourcePersistentAttribute. - getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - } - - protected JavaConverter buildSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getJpaFactory().buildJavaTemporalConverter(this, this.resourcePersistentAttribute); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourcePersistentAttribute.getAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { - return Converter.TEMPORAL_CONVERTER; - } - - return null; - } - - // ********** code assist ********** - - @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; - } - if (this.generatorTouches(pos, astRoot)) { - result = this.persistenceGeneratorNames(filter); - if (result != null) { - return result; - } - } - result = this.getGeneratorContainer().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - // ********** code assist: generator - - protected boolean generatorTouches(int pos, CompilationUnit astRoot) { - if (getResourceGeneratedValue() != null) { - return this.getResourceGeneratedValue().generatorTouches(pos, astRoot); - } - return false; - } - - protected Iterator<String> persistenceGeneratorNames() { - if(this.getPersistenceUnit().generatorsSize() == 0) { - return EmptyIterator.<String> instance(); - } - return CollectionTools.iterator(this.getPersistenceUnit().uniqueGeneratorNames()); - } - - private Iterator<String> generatorNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.persistenceGeneratorNames(), filter); - } - - protected Iterator<String> persistenceGeneratorNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.generatorNames(filter)); - } - - // ************************************************************************* - - @Override - public String getPrimaryKeyColumnName() { - return this.getColumn().getName(); - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public boolean isIdMapping() { - return true; - } - - //*********** Validation ************ - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - - if (this.shouldValidateAgainstDatabase()) { - this.validateColumn(messages, astRoot); - } - if (this.generatedValue != null) { - this.generatedValue.validate(messages, reporter, astRoot); - } - getGeneratorContainer().validate(messages, reporter, astRoot); - if (this.specifiedConverter != null) { - this.specifiedConverter.validate(messages, reporter, astRoot); - } - } - - protected void validateColumn(List<IMessage> messages, CompilationUnit astRoot) { - if (this.getTypeMapping().tableNameIsInvalid(this.column.getTable())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {this.column.getTable(), this.column.getName()}, - this.column, - this.column.getTableTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange(astRoot) - ) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMappingDefinition.java deleted file mode 100644 index 06fce4be77..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMappingDefinition.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.IdAnnotation; - -public abstract class AbstractJavaIdMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - protected AbstractJavaIdMappingDefinition() { - 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/AbstractJavaJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinColumnJoiningStrategy.java deleted file mode 100644 index 748c6fd41c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,380 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractJavaJoinColumnJoiningStrategy - extends AbstractJavaJpaContextNode - implements JavaJoinColumnJoiningStrategy -{ - protected JavaJoinColumn defaultJoinColumn; - - protected final Vector<JavaJoinColumn> specifiedJoinColumns = new Vector<JavaJoinColumn>(); - protected final JavaJoinColumn.Owner joinColumnOwner; - - - protected AbstractJavaJoinColumnJoiningStrategy(JoinColumnEnabledRelationshipReference parent) { - super(parent); - this.joinColumnOwner = this.buildJoinColumnOwner(); - } - - protected abstract JavaJoinColumn.Owner buildJoinColumnOwner(); - - public void initializeFrom(JoinColumnJoiningStrategy oldStrategy) { - for (JoinColumn joinColumn : CollectionTools.iterable(oldStrategy.joinColumns())) { - JoinColumn newJoinColumn = this.addSpecifiedJoinColumn(this.specifiedJoinColumnsSize()); - newJoinColumn.setSpecifiedName(joinColumn.getName()); - newJoinColumn.setSpecifiedReferencedColumnName(joinColumn.getReferencedColumnName()); - } - } - - @Override - public JoinColumnEnabledRelationshipReference getParent() { - return (JoinColumnEnabledRelationshipReference) super.getParent(); - } - - public JoinColumnEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public RelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public void addStrategy() { - if (specifiedJoinColumnsSize() == 0) { - addSpecifiedJoinColumn(0); - } - } - - public void removeStrategy() { - for (JoinColumn each : CollectionTools.iterable(specifiedJoinColumns())) { - removeSpecifiedJoinColumn(each); - } - } - - - // **************** join columns ******************************************* - - public ListIterator<JavaJoinColumn> joinColumns() { - return this.hasSpecifiedJoinColumns() ? - this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.hasSpecifiedJoinColumns() ? - this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - - // **************** default join column ************************************ - - public JavaJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(JavaJoinColumn column) { - JavaJoinColumn old = this.defaultJoinColumn; - this.defaultJoinColumn = column; - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, old, column); - } - - 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; - } - - - // **************** specified join columns ********************************* - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean hasSpecifiedJoinColumns() { - return ! this.specifiedJoinColumns.isEmpty(); - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - // Clear out the default now so it doesn't get removed during an update and - // cause change notifications to be sent to the UI in the wrong order. - JavaJoinColumn oldDefault = this.defaultJoinColumn; - this.defaultJoinColumn = null; - - JavaJoinColumn joinColumn = this.getJpaFactory().buildJavaJoinColumn(this, this.joinColumnOwner); - this.specifiedJoinColumns.add(index, joinColumn); - JoinColumnAnnotation joinColumnAnnotation = this.addAnnotation(index); - joinColumn.initialize(joinColumnAnnotation); - this.fireItemAdded(SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, oldDefault, null); - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedJoinColumn(JavaJoinColumn joinColumn) { - addSpecifiedJoinColumn(this.specifiedJoinColumns.size(), joinColumn); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (this.specifiedJoinColumns.isEmpty()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = buildJoinColumn(buildNullJoinColumnAnnotation()); - } - removeAnnotation(index); - fireItemRemoved(SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - moveAnnotation(targetIndex, sourceIndex); - fireItemMoved(SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected abstract JoinColumnAnnotation addAnnotation(int index); - - protected abstract void removeAnnotation(int index); - - protected abstract void moveAnnotation(int targetIndex, int sourceIndex); - - protected abstract Iterator<JoinColumnAnnotation> joinColumnAnnotations(); - - protected abstract JoinColumnAnnotation buildNullJoinColumnAnnotation(); - - - // **************** resource => context ************************************ - - public void initialize() { - initializeSpecifiedJoinColumns(); - initializeDefaultJoinColumn(); - } - - protected void initializeSpecifiedJoinColumns() { - Iterator<JoinColumnAnnotation> annotations = joinColumnAnnotations(); - while (annotations.hasNext()) { - this.specifiedJoinColumns.add(buildJoinColumn(annotations.next())); - } - } - - public void initializeDefaultJoinColumn() { - if (mayHaveDefaultJoinColumn()) { - this.defaultJoinColumn = - buildJoinColumn(buildNullJoinColumnAnnotation()); - } - } - - public void update() { - updateSpecifiedJoinColumns(); - updateDefaultJoinColumn(); - } - - protected void updateSpecifiedJoinColumns() { - ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - Iterator<JoinColumnAnnotation> resourceJoinColumns = joinColumnAnnotations(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(buildJoinColumn(resourceJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn() { - if (mayHaveDefaultJoinColumn()) { - JoinColumnAnnotation nullAnnotation = buildNullJoinColumnAnnotation(); - if (this.defaultJoinColumn == null) { - setDefaultJoinColumn(this.buildJoinColumn(nullAnnotation)); - } - this.defaultJoinColumn.update(nullAnnotation); - } - else { - if (this.defaultJoinColumn != null) { - setDefaultJoinColumn(null); - } - } - } - - protected boolean mayHaveDefaultJoinColumn() { - return getRelationshipReference().mayHaveDefaultJoinColumn() - && ! hasSpecifiedJoinColumns(); - } - - protected JavaJoinColumn buildJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, this.joinColumnOwner); - joinColumn.initialize(joinColumnResource); - return joinColumn; - } - - - // **************** Java completion proposals ****************************** - - @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 validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (getRelationshipMapping().shouldValidateAgainstDatabase()) { - for (Iterator<JavaJoinColumn> stream = this.joinColumns(); stream.hasNext(); ) { - validateJoinColumn(stream.next(), messages, astRoot); - } - } - } - - protected void validateJoinColumn(JavaJoinColumn joinColumn, List<IMessage> messages, CompilationUnit astRoot) { - if (getRelationshipMapping().getTypeMapping().tableNameIsInvalid(joinColumn.getTable())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {joinColumn.getTable(), joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot) - ) - ); - return; - } - validateJoinColumnName(joinColumn, messages, astRoot); - validationJoinColumnReferencedColumnName(joinColumn, messages, astRoot); - } - - protected void validateJoinColumnName(JavaJoinColumn joinColumn, List<IMessage> messages, CompilationUnit astRoot) { - if ( ! joinColumn.isResolved() && joinColumn.getDbTable() != null) { - if (joinColumn.getName() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange(astRoot) - ) - ); - } - else if (joinColumn.getOwner().joinColumnsSize() > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - joinColumn, - joinColumn.getNameTextRange(astRoot) - ) - ); - } - //If the name is null and there is only one join-column, one of these validation messages will apply - // 1. target entity does not have a primary key - // 2. target entity is not specified - // 3. target entity is not an entity - } - } - - protected void validationJoinColumnReferencedColumnName(JavaJoinColumn joinColumn, List<IMessage> messages, CompilationUnit astRoot) { - if ( ! joinColumn.isReferencedColumnResolved() && joinColumn.getReferencedColumnDbTable() != null) { - if (joinColumn.getReferencedColumnName() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange(astRoot) - ) - ); - } - else if (joinColumn.getOwner().joinColumnsSize() > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - joinColumn, - joinColumn.getReferencedColumnNameTextRange(astRoot) - ) - ); - } - //If the referenced column name is null and there is only one join-column, one of these validation messages will apply - // 1. target entity does not have a primary key - // 2. target entity is not specified - // 3. target entity is not an entity - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinTableJoiningStrategy.java deleted file mode 100644 index fe4a4076de..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinTableJoiningStrategy.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.JoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.JoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaJoinTableJoiningStrategy; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractJavaJoinTableJoiningStrategy - extends AbstractJavaJpaContextNode - implements JavaJoinTableJoiningStrategy -{ - protected JavaJoinTable joinTable; - - - protected AbstractJavaJoinTableJoiningStrategy(JoinTableEnabledRelationshipReference parent) { - super(parent); - } - - - @Override - public JoinTableEnabledRelationshipReference getParent() { - return (JoinTableEnabledRelationshipReference) super.getParent(); - } - - public JoinTableEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public RelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public String getJoinTableDefaultName() { - return MappingTools.buildJoinTableDefaultName(this.getRelationshipReference()); - } - - public void addStrategy() { - if (this.joinTable == null) { - this.joinTable = getJpaFactory().buildJavaJoinTable(this); - addAnnotation(); - this.firePropertyChanged(JOIN_TABLE_PROPERTY, null, this.joinTable); - } - } - - public void removeStrategy() { - if (this.joinTable != null) { - JavaJoinTable oldJoinTable = this.joinTable; - this.joinTable = null; - removeAnnotation(); - this.firePropertyChanged(JOIN_TABLE_PROPERTY, oldJoinTable, null); - } - } - - public void initializeFrom(JoinTableJoiningStrategy oldStrategy) { - JoinTable oldJoinTable = (oldStrategy.getJoinTable()); - if (oldJoinTable != null) { - this.addStrategy(); - this.getJoinTable().setSpecifiedCatalog(oldJoinTable.getSpecifiedCatalog()); - this.getJoinTable().setSpecifiedSchema(oldJoinTable.getSpecifiedSchema()); - this.getJoinTable().setSpecifiedName(oldJoinTable.getSpecifiedName()); - } - } - - - // **************** join table ********************************************* - - public JavaJoinTable getJoinTable() { - return this.joinTable; - } - - protected void setJoinTable_(JavaJoinTable newJoinTable) { - JavaJoinTable oldJoinTable = this.joinTable; - this.joinTable = newJoinTable; - this.firePropertyChanged(JOIN_TABLE_PROPERTY, oldJoinTable, newJoinTable); - } - - protected abstract JoinTableAnnotation addAnnotation(); - - protected abstract void removeAnnotation(); - - - // **************** resource => context ************************************ - - public void initialize() { - JoinTableAnnotation annotation = getAnnotation(); - if (annotation.isSpecified() || getRelationshipReference().mayHaveDefaultJoinTable()) { - this.joinTable = getJpaFactory().buildJavaJoinTable(this); - this.joinTable.initialize(annotation); - } - } - - public void update() { - JoinTableAnnotation annotation = getAnnotation(); - if (annotation.isSpecified() || getRelationshipReference().mayHaveDefaultJoinTable()) { - if (this.joinTable == null) { - setJoinTable_(getJpaFactory().buildJavaJoinTable(this)); - } - this.joinTable.update(annotation); - } - else { - if (this.joinTable != null) { - // no annotation, so no clean up - setJoinTable_(null); - } - } - } - - // **************** Java completion proposals ****************************** - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result == null && this.joinTable != null) { - result = this.joinTable.javaCompletionProposals(pos, filter, astRoot); - } - return result; - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.joinTable != null && getRelationshipMapping().shouldValidateAgainstDatabase()) { - this.joinTable.validate(messages, reporter, astRoot); - } - } - -} 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 f79055d5ce..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJpaContextNode.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -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.jst.j2ee.model.internal.validation.ValidationCancelledException; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractJavaJpaContextNode - extends AbstractJpaContextNode - implements JavaJpaContextNode -{ - // ********** constructor ********** - - protected AbstractJavaJpaContextNode(JpaContextNode parent) { - super(parent); - } - - @Override - public IContentType getContentType() { - return JptCorePlugin.JAVA_SOURCE_CONTENT_TYPE; - } - - 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). - */ - @SuppressWarnings("unused") - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - return null; - } - - // ********** validation ********** - - /** - * All subclass implementations {@link #validate(List, CompilationUnit))} - * should be preceded by a "super" call to this method - */ - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - if (reporter.isCancelled()) { - throw new ValidationCancelledException(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaManyToManyMapping.java deleted file mode 100644 index 5909def13c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaManyToManyMapping.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 org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaRelationshipReference; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; - - -public abstract class AbstractJavaManyToManyMapping - extends AbstractJavaMultiRelationshipMapping<ManyToManyAnnotation> - implements JavaManyToManyMapping -{ - protected AbstractJavaManyToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - - @Override - protected JavaRelationshipReference buildRelationshipReference() { - return new GenericJavaManyToManyRelationshipReference(this); - } - - public String getAnnotationName() { - return ManyToManyAnnotation.ANNOTATION_NAME; - } - - @Override - public ManyToManyAnnotation getMappingAnnotation() { - return super.getMappingAnnotation(); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public JavaManyToManyRelationshipReference getRelationshipReference() { - return (JavaManyToManyRelationshipReference) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaManyToOneMapping.java deleted file mode 100644 index 43cedb917d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaManyToOneMapping.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaManyToOneRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; - - -public abstract class AbstractJavaManyToOneMapping - extends AbstractJavaSingleRelationshipMapping<ManyToOneAnnotation> - implements JavaManyToOneMapping2_0 -{ - protected AbstractJavaManyToOneMapping(JavaPersistentAttribute parent) { - super(parent); - } - - - @Override - protected JavaManyToOneRelationshipReference buildRelationshipReference() { - return new GenericJavaManyToOneRelationshipReference(this); - } - - public String getAnnotationName() { - return ManyToOneAnnotation.ANNOTATION_NAME; - } - - @Override - public ManyToOneAnnotation getMappingAnnotation() { - return super.getMappingAnnotation(); - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public JavaManyToOneRelationshipReference getRelationshipReference() { - return (JavaManyToOneRelationshipReference) super.getRelationshipReference(); - } - - @Override - protected Boolean getResourceOptional() { - return this.mappingAnnotation.getOptional(); - } - - @Override - protected void setResourceOptional(Boolean newOptional) { - this.mappingAnnotation.setOptional(newOptional); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java deleted file mode 100644 index 2410790473..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaColumnMapping; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -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; - -public abstract class AbstractJavaMappedSuperclass extends AbstractJavaTypeMapping - implements JavaMappedSuperclass -{ - - protected String idClass; - - protected AbstractJavaMappedSuperclass(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> supportingAnnotationNames() { - 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 char getIdClassEnclosingTypeSeparator() { - return '.'; - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (this.valuesAreDifferent(newIdClass, oldIdClass)) { - if (newIdClass != null) { - if (getResourceIdClass() == null) { - addResourceIdClass(); - } - getResourceIdClass().setValue(newIdClass); - } - else { - removeResourceIdClass(); - } - } - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected IdClassAnnotation getResourceIdClass() { - return (IdClassAnnotation) this.javaResourcePersistentType. - getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void addResourceIdClass() { - this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void removeResourceIdClass() { - this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - @Override - public Iterator<JavaColumnMapping> overridableAttributes() { - return new FilteringIterator<JavaAttributeMapping, JavaColumnMapping>(this.attributeMappings()) { - @Override - protected boolean accept(JavaAttributeMapping o) { - return o.isOverridableAttributeMapping(); - } - }; - } - - @Override - public Iterator<JavaRelationshipMapping> overridableAssociations() { - return new FilteringIterator<JavaAttributeMapping, JavaRelationshipMapping>(this.attributeMappings()) { - @Override - protected boolean accept(JavaAttributeMapping o) { - return o.isOverridableAssociationMapping(); - } - }; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return false; - } - - @Override - public void initialize(JavaResourcePersistentType persistentTypeResource) { - super.initialize(persistentTypeResource); - this.idClass = this.getResourceIdClassName(this.getResourceIdClass()); - } - - @Override - public void update(JavaResourcePersistentType persistentTypeResource) { - super.update(persistentTypeResource); - this.setIdClass_(this.getResourceIdClassName(this.getResourceIdClass())); - } - - protected String getResourceIdClassName(IdClassAnnotation resourceIdClass) { - return resourceIdClass == null ? null : resourceIdClass.getValue(); - } -} 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 618f4f9de1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.java.JavaMultiRelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -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.utility.Filter; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -/** - * Java multi-relationship (m:m, 1:m) mapping - */ -public abstract class AbstractJavaMultiRelationshipMapping<T extends RelationshipMappingAnnotation> - extends AbstractJavaRelationshipMapping<T> - implements JavaMultiRelationshipMapping -{ - protected String orderBy; - - protected boolean noOrdering = false; - - protected boolean pkOrdering = false; - - protected boolean customOrdering = false; - - protected String mapKey; - - - protected AbstractJavaMultiRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - } - - @Override - protected void initialize() { - super.initialize(); - this.initializeOrderBy(); - this.initializeMapKey(); - } - - @Override - protected void update() { - super.update(); - this.updateOrderBy(); - this.updateMapKey(); - } - - // ********** AbstractJavaAttributeMapping implementation ********** - - @Override - protected String[] buildSupportingAnnotationNames() { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.JOIN_TABLE, - JPA.MAP_KEY, - JPA.ORDER_BY - ); - } - - // ********** AbstractJavaRelationshipMapping implementation ********** - - @Override - protected String buildDefaultTargetEntity() { - return this.getPersistentAttribute().getMultiReferenceEntityTypeName(); - } - - - // ********** order by ********** - - public String getOrderBy() { - return this.orderBy; - } - - public void setOrderBy(String orderBy) { - String old = this.orderBy; - this.orderBy = orderBy; - OrderByAnnotation orderByAnnotation = this.getOrderByAnnotation(); - if (orderBy == null) { - if (orderByAnnotation != null) { - this.removeOrderByAnnotation(); - } - } else { - if (orderByAnnotation == null) { - orderByAnnotation = this.addOrderByAnnotation(); - } - orderByAnnotation.setValue(orderBy); - } - this.firePropertyChanged(ORDER_BY_PROPERTY, old, orderBy); - } - - protected void setOrderBy_(String orderBy) { - String old = this.orderBy; - this.orderBy = orderBy; - this.firePropertyChanged(ORDER_BY_PROPERTY, old, orderBy); - } - - protected void initializeOrderBy() { - OrderByAnnotation orderByAnnotation = this.getOrderByAnnotation(); - if (orderByAnnotation == null) { - this.noOrdering = true; - } else { - this.orderBy = orderByAnnotation.getValue(); - if (orderByAnnotation.getValue() == null) { - this.pkOrdering = true; - } else { - this.customOrdering = true; - } - } - } - - protected void updateOrderBy() { - OrderByAnnotation orderByAnnotation = this.getOrderByAnnotation(); - if (orderByAnnotation == null) { - this.setOrderBy_(null); - this.setNoOrdering_(true); - this.setPkOrdering_(false); - this.setCustomOrdering_(false); - } else { - String ob = orderByAnnotation.getValue(); - this.setOrderBy_(ob); - if (ob == null) { - this.setPkOrdering_(true); - this.setCustomOrdering_(false); - this.setNoOrdering_(false); - } - else { - this.setCustomOrdering_(true); - this.setPkOrdering_(false); - this.setNoOrdering_(false); - } - } - } - - protected OrderByAnnotation getOrderByAnnotation() { - return (OrderByAnnotation) this.resourcePersistentAttribute.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - protected OrderByAnnotation addOrderByAnnotation() { - return (OrderByAnnotation) this.resourcePersistentAttribute.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - protected void removeOrderByAnnotation() { - this.resourcePersistentAttribute.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - - // ********** no ordering ********** - - public boolean isNoOrdering() { - return this.noOrdering; - } - - public void setNoOrdering(boolean noOrdering) { - boolean old = this.noOrdering; - this.noOrdering = noOrdering; - if (noOrdering) { - if (this.getOrderByAnnotation() != null) { - this.removeOrderByAnnotation(); - } - } else { - // the 'noOrdering' flag is cleared as a - // side-effect of setting the other flags, - // via a call to #setNoOrdering_(boolean) - } - this.firePropertyChanged(NO_ORDERING_PROPERTY, old, noOrdering); - } - - protected void setNoOrdering_(boolean noOrdering) { - boolean old = this.noOrdering; - this.noOrdering = noOrdering; - this.firePropertyChanged(NO_ORDERING_PROPERTY, old, noOrdering); - } - - - // ********** pk ordering ********** - - public boolean isPkOrdering() { - return this.pkOrdering; - } - - public void setPkOrdering(boolean pkOrdering) { - boolean old = this.pkOrdering; - this.pkOrdering = pkOrdering; - OrderByAnnotation orderByAnnotation = this.getOrderByAnnotation(); - if (pkOrdering) { - if (orderByAnnotation == null) { - this.addOrderByAnnotation(); - } else { - orderByAnnotation.setValue(null); - } - } else { - // the 'pkOrdering' flag is cleared as a - // side-effect of setting the other flags, - // via a call to #setPkOrdering_(boolean) - } - this.firePropertyChanged(PK_ORDERING_PROPERTY, old, pkOrdering); - } - - protected void setPkOrdering_(boolean pkOrdering) { - boolean old = this.pkOrdering; - this.pkOrdering = pkOrdering; - this.firePropertyChanged(PK_ORDERING_PROPERTY, old, pkOrdering); - } - - - // ********** custom ordering ********** - - public boolean isCustomOrdering() { - return this.customOrdering; - } - - public void setCustomOrdering(boolean customOrdering) { - boolean old = this.customOrdering; - this.customOrdering = customOrdering; - if (customOrdering) { - this.setOrderBy(""); //$NON-NLS-1$ - } else { - // the 'customOrdering' flag is cleared as a - // side-effect of setting the other flags, - // via a call to #setCustomOrdering_(boolean) - } - this.firePropertyChanged(CUSTOM_ORDERING_PROPERTY, old, customOrdering); - } - - protected void setCustomOrdering_(boolean customOrdering) { - boolean old = this.customOrdering; - this.customOrdering = customOrdering; - this.firePropertyChanged(CUSTOM_ORDERING_PROPERTY, old, customOrdering); - } - - - // ********** Fetchable implementation ********** - - public FetchType getDefaultFetch() { - return DEFAULT_FETCH_TYPE; - } - - - // ********** map key ********** - - public String getMapKey() { - return this.mapKey; - } - - public void setMapKey(String mapKey) { - String old = this.mapKey; - this.mapKey = mapKey; - MapKeyAnnotation mapKeyAnnotation = this.getMapKeyAnnotation(); - if (mapKey == null) { - if (mapKeyAnnotation != null) { - this.removeMapKeyAnnotation(); - } - } else { - if (mapKeyAnnotation == null) { - mapKeyAnnotation = this.addMapKeyAnnotation(); - } - mapKeyAnnotation.setName(mapKey); - } - this.firePropertyChanged(MAP_KEY_PROPERTY, old, mapKey); - } - - protected void setMapKey_(String mapKey) { - String old = this.mapKey; - this.mapKey = mapKey; - this.firePropertyChanged(MAP_KEY_PROPERTY, old, mapKey); - } - - protected void initializeMapKey() { - MapKeyAnnotation mapKeyAnnotation = this.getMapKeyAnnotation(); - if (mapKeyAnnotation != null) { - this.mapKey = mapKeyAnnotation.getName(); - } - } - - protected void updateMapKey() { - MapKeyAnnotation mapKeyAnnotation = this.getMapKeyAnnotation(); - this.setMapKey_((mapKeyAnnotation == null) ? null : mapKeyAnnotation.getName()); - } - - protected MapKeyAnnotation getMapKeyAnnotation() { - return (MapKeyAnnotation) this.resourcePersistentAttribute.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - - protected MapKeyAnnotation addMapKeyAnnotation() { - return (MapKeyAnnotation) this.resourcePersistentAttribute.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - - protected void removeMapKeyAnnotation() { - this.resourcePersistentAttribute.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - - protected boolean mapKeyNameTouches(int pos, CompilationUnit astRoot) { - MapKeyAnnotation mapKeyAnnotation = this.getMapKeyAnnotation(); - return (mapKeyAnnotation != null) && mapKeyAnnotation.nameTouches(pos, astRoot); - } - - - // ********** Java completion proposals ********** - - @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.mapKeyNameTouches(pos, astRoot)) { - return this.javaCandidateMapKeyNames(filter); - } - return null; - } - - protected Iterator<String> javaCandidateMapKeyNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateMapKeyNames(filter)); - } - - protected Iterator<String> candidateMapKeyNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateMapKeyNames(), filter); - } - - public Iterator<String> candidateMapKeyNames() { - return this.allTargetEntityAttributeNames(); - } - -} 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 123dd5f57f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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 initialize(T column) { - this.specifiedName = column.getName(); - this.defaultName = this.buildDefaultName(); - this.columnDefinition = column.getColumnDefinition(); - } - - - protected abstract T getResourceColumn(); - - - //************** INamedColumn implementation ***************** - 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; - getResourceColumn().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; - getResourceColumn().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.getResourceColumn().getNameTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.getResourceColumn().nameTouches(pos, astRoot); - } - - public Column getDbColumn() { - Table table = this.getDbTable(); - return (table == null) ? null : table.getColumnForIdentifier(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.javaCandidateNames(filter); - } - return null; - } - - private Iterator<String> javaCandidateNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateNames(filter)); - } - - private Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - private Iterator<String> candidateNames() { - Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.sortedColumnIdentifiers() : EmptyIterator.<String> instance(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ******************* update from java resource model ******************** - - protected void update(T column) { - this.setSpecifiedName_(column.getName()); - this.setDefaultName(this.buildDefaultName()); - this.setColumnDefinition_(column.getColumnDefinition()); - } - - /** - * Return the default column name. - */ - protected String buildDefaultName() { - return this.getOwner().getDefaultColumnName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyMapping.java deleted file mode 100644 index f3f5326e2c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyMapping.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyRelationshipReference; -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.utility.internal.ArrayTools; - - -public abstract class AbstractJavaOneToManyMapping - extends AbstractJavaMultiRelationshipMapping<OneToManyAnnotation> - implements JavaOneToManyMapping -{ - - protected AbstractJavaOneToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - - - public String getAnnotationName() { - return OneToManyAnnotation.ANNOTATION_NAME; - } - - @Override - protected String[] buildSupportingAnnotationNames() { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS); - } - - @Override - public OneToManyAnnotation getMappingAnnotation() { - return super.getMappingAnnotation(); - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public JavaOneToManyRelationshipReference getRelationshipReference() { - return (JavaOneToManyRelationshipReference) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyRelationshipReference.java deleted file mode 100644 index a886b844d1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToManyRelationshipReference.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyRelationshipReference; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractJavaOneToManyRelationshipReference - extends AbstractJavaRelationshipReference - implements JavaOneToManyRelationshipReference -{ - protected final JavaMappedByJoiningStrategy mappedByJoiningStrategy; - - protected final JavaJoinTableJoiningStrategy joinTableJoiningStrategy; - - - protected AbstractJavaOneToManyRelationshipReference(JavaOneToManyMapping parent) { - super(parent); - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - } - - protected JavaMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericJavaMappedByJoiningStrategy(this); - } - - protected JavaJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new GenericJavaJoinTableJoiningStrategy(this); - } - - @Override - public JavaOneToManyMapping getRelationshipMapping() { - return (JavaOneToManyMapping) getParent(); - } - - public OneToManyAnnotation getMappingAnnotation() { - return getRelationshipMapping().getMappingAnnotation(); - } - - public boolean isRelationshipOwner() { - return this.getMappedByJoiningStrategy().getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result == null) { - result = this.mappedByJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - } - if (result == null) { - result = this.joinTableJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - } - return result; - } - - - // **************** mapped by ********************************************** - - public JavaMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - } - - public boolean usesMappedByJoiningStrategy() { - return this.getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join table ********************************************* - - public JavaJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public void setJoinTableJoiningStrategy() { - // join table is default, so no need to add annotation - this.mappedByJoiningStrategy.removeStrategy(); - } - - public void unsetJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null; - } - - - // **************** resource => context ************************************ - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy.initialize(); - this.joinTableJoiningStrategy.initialize(); - } - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - this.joinTableJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.mappedByJoiningStrategy.validate(messages, reporter, astRoot); - this.joinTableJoiningStrategy.validate(messages, reporter, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToOneMapping.java deleted file mode 100644 index e9bdfba73a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOneToOneMapping.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaOneToOneRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.utility.internal.ArrayTools; - - -public abstract class AbstractJavaOneToOneMapping - extends AbstractJavaSingleRelationshipMapping<OneToOneAnnotation> - implements JavaOneToOneMapping2_0 -{ - protected AbstractJavaOneToOneMapping(JavaPersistentAttribute parent) { - super(parent); - } - - - @Override - protected JavaRelationshipReference buildRelationshipReference() { - return new GenericJavaOneToOneRelationshipReference(this); - } - - public String getAnnotationName() { - return OneToOneAnnotation.ANNOTATION_NAME; - } - - @Override - public OneToOneAnnotation getMappingAnnotation() { - return super.getMappingAnnotation(); - } - - @Override - protected String[] buildSupportingAnnotationNames() { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.PRIMARY_KEY_JOIN_COLUMN, - JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public JavaOneToOneRelationshipReference getRelationshipReference() { - return (JavaOneToOneRelationshipReference) super.getRelationshipReference(); - } - - @Override - protected Boolean getResourceOptional() { - return this.mappingAnnotation.getOptional(); - } - - @Override - protected void setResourceOptional(Boolean newOptional) { - this.mappingAnnotation.setOptional(newOptional); - } -} 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 ca07b093dc..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 overrideAnnotation; - - public AbstractJavaOverride(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - protected void initialize(OverrideAnnotation overrideAnnotation) { - this.overrideAnnotation = overrideAnnotation; - this.name = this.getResourceName(overrideAnnotation); - } - - protected OverrideAnnotation getOverrideAnnotation() { - return this.overrideAnnotation; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.overrideAnnotation.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.overrideAnnotation = overrideResource; - this.setName_(this.getResourceName(overrideResource)); - } - - protected String getResourceName(OverrideAnnotation overrideAnnotation) { - return overrideAnnotation.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> javaCandidateNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(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.javaCandidateNames(filter); - } - return null; - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.overrideAnnotation.nameTouches(pos, astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.overrideAnnotation.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/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java deleted file mode 100644 index b6f9893a4d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java +++ /dev/null @@ -1,791 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.internal.jpa2.context.SimpleStaticMetamodelField; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.StaticMetamodelField; -import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -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.ArrayTools; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * common state/behavior between Generic and EclipseLink persistent attributes - */ -public abstract class AbstractJavaPersistentAttribute - extends AbstractJavaJpaContextNode - implements JavaPersistentAttribute2_0 -{ - protected String name; - - protected JavaAttributeMapping defaultMapping; - - protected JavaAttributeMapping specifiedMapping; - - protected AccessType defaultAccess; - - protected JavaResourcePersistentAttribute resourcePersistentAttribute; - - - protected AbstractJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute resourcePersistentAttribute) { - super(parent); - this.resourcePersistentAttribute = resourcePersistentAttribute; - this.name = buildName(); - this.defaultMapping = buildDefaultMapping(); - this.specifiedMapping = buildSpecifiedMapping(); - this.defaultAccess = buildDefaultAccess(); - } - - public void update() { - this.setName(this.buildName()); - this.updateDefaultMapping(); - this.updateSpecifiedMapping(); - this.setDefaultAccess(this.buildDefaultAccess()); - } - - @Override - public void postUpdate() { - super.postUpdate(); - getMapping().postUpdate(); - } - - - // ********** JpaStructureNode implementation ********** - - public String getId() { - return JavaStructureNodes.PERSISTENT_ATTRIBUTE_ID; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public TextRange getSelectionTextRange() { - return this.getSelectionTextRange(this.buildASTRoot()); - } - - protected TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.resourcePersistentAttribute.getNameTextRange(astRoot); - } - - protected CompilationUnit buildASTRoot() { - return this.resourcePersistentAttribute.getJavaResourceCompilationUnit().buildASTRoot(); - } - - public void dispose() { - //nothing to dispose - } - - - // ********** AccessHolder implementation ********** - - public AccessType getAccess() { - AccessType access = this.getSpecifiedAccess(); - return (access != null) ? access : this.getDefaultAccess(); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType defaultAccess) { - AccessType old = this.defaultAccess; - this.defaultAccess = defaultAccess; - this.firePropertyChanged(DEFAULT_ACCESS_PROPERTY, old, defaultAccess); - } - - protected AccessType buildDefaultAccess() { - return this.resourcePersistentAttribute.isField() ? AccessType.FIELD : AccessType.PROPERTY; - } - - - // ********** [Java]PersistentAttribute implementation ********** - - public JavaResourcePersistentAttribute getResourcePersistentAttribute() { - return this.resourcePersistentAttribute; - } - - public PersistentType getPersistentType() { - return this.getParent(); - } - - public TypeMapping getTypeMapping() { - return this.getPersistentType().getMapping(); - } - - public String getPrimaryKeyColumnName() { - return this.getMapping().getPrimaryKeyColumnName(); - } - - public boolean isIdAttribute() { - return this.getMapping().isIdMapping(); - } - - public boolean isVirtual() { - return false; - } - - 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); - } - - protected TextRange getFullTextRange(CompilationUnit astRoot) { - return this.resourcePersistentAttribute.getTextRange(astRoot); - } - - public Embeddable getEmbeddable() { - String typeName = this.resourcePersistentAttribute.getTypeName(); - return (typeName == null) ? null : this.getPersistenceUnit().getEmbeddable(typeName); - } - - public boolean isField() { - return this.resourcePersistentAttribute.isField(); - } - - public boolean isProperty() { - return this.resourcePersistentAttribute.isProperty(); - } - - public boolean isPublic() { - return Modifier.isPublic(this.resourcePersistentAttribute.getModifiers()); - } - - public boolean isFinal() { - return Modifier.isFinal(this.resourcePersistentAttribute.getModifiers()); - } - - // ***** Basic defaults - /** - * From the JPA spec, when the basic mapping applies: - * If the type of the attribute (field or property) is one of the following - * it must be mapped as @Basic: - * byte[] - * java.lang.Byte[] - * char[] - * java.lang.Character[] - * primitive types (except 'void') - * primitive wrappers (except 'java.lang.Void') - * java.lang.String - * java.math.BigInteger - * java.math.BigDecimal - * java.util.Date - * java.util.Calendar - * java.sql.Date - * java.sql.Time - * java.sql.Timestamp - * enums - * any other type that implements java.io.Serializable - */ - public boolean typeIsBasic() { - // 'typeName' may include array brackets but not generic type arguments - String typeName = this.resourcePersistentAttribute.getTypeName(); - if (typeName == null) { - return false; - } - - int arrayDepth = ClassTools.arrayDepthForTypeDeclaration(typeName); - if (arrayDepth > 1) { - return false; // multi-dimensional arrays are not supported - } - - if (arrayDepth == 1) { - String elementTypeName = ClassTools.elementTypeNameForTypeDeclaration(typeName, 1); - return this.elementTypeIsValidForBasicArray(elementTypeName); - } - - // arrayDepth == 0 - if (ClassTools.classNamedIsVariablePrimitive(typeName)) { - return true; // any primitive but 'void' - } - if (ClassTools.classNamedIsVariablePrimitiveWrapperClass(typeName)) { - return true; // any primitive wrapper but 'java.lang.Void' - } - if (this.typeIsOtherValidBasicType(typeName)) { - return true; - } - if (this.resourcePersistentAttribute.typeIsEnum()) { - return true; - } - if (this.resourcePersistentAttribute.typeIsSubTypeOf(SERIALIZABLE_TYPE_NAME)) { - return true; - } - return false; - } - - /** - * Return whether the specified type is a valid element type for - * a one-dimensional array that can default to a Basic mapping: - * byte - * char - * java.lang.Byte - * java.lang.Character - */ - protected boolean elementTypeIsValidForBasicArray(String elementTypeName) { - return ArrayTools.contains(VALID_BASIC_ARRAY_ELEMENT_TYPE_NAMES, elementTypeName); - } - - protected static final String[] VALID_BASIC_ARRAY_ELEMENT_TYPE_NAMES = { - byte.class.getName(), - char.class.getName(), - java.lang.Byte.class.getName(), - java.lang.Character.class.getName() - }; - - /** - * Return whether the specified type is among the various "other" types - * that can default to a Basic mapping. - */ - protected boolean typeIsOtherValidBasicType(String typeName) { - return ArrayTools.contains(OTHER_VALID_BASIC_TYPE_NAMES, typeName); - } - - protected static final String[] OTHER_VALID_BASIC_TYPE_NAMES = { - java.lang.String.class.getName(), - java.math.BigInteger.class.getName(), - java.math.BigDecimal.class.getName(), - java.util.Date.class.getName(), - java.util.Calendar.class.getName(), - java.sql.Date.class.getName(), - java.sql.Time.class.getName(), - java.sql.Timestamp.class.getName(), - }; - - protected static final String SERIALIZABLE_TYPE_NAME = java.io.Serializable.class.getName(); - - // ***** reference entities - /** - * 'typeName' may include array brackets ("[]") - * but not generic type arguments (e.g. "<java.lang.String>") - */ - public String getSingleReferenceEntityTypeName() { - String typeName = this.resourcePersistentAttribute.getTypeName(); - if (typeName == null) { - return null; - } - if (ClassTools.arrayDepthForTypeDeclaration(typeName) != 0) { - return null; // arrays cannot be entities - } - if (this.typeIsContainer(typeName)) { - return null; // "containers" cannot be entities - } - return typeName; - } - - public String getMultiReferenceEntityTypeName() { - // 'typeName' may include array brackets but not generic type arguments - String typeName = this.resourcePersistentAttribute.getTypeName(); - return (typeName == null) ? null : - this.getJpaContainer(typeName).getMultiReferenceEntityTypeName(this.resourcePersistentAttribute); - } - - /** - * return whether the specified type is one of the container - * types allowed by the JPA spec - */ - protected boolean typeIsContainer(String typeName) { - return this.getJpaContainer(typeName).isContainer(); - } - - // ***** name - public String getName() { - return this.name; - } - - protected void setName(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - protected String buildName() { - return this.resourcePersistentAttribute.getName(); - } - - // ***** mapping - public JavaAttributeMapping getMapping() { - return (this.specifiedMapping != null) ? this.specifiedMapping : this.defaultMapping; - } - - public String getMappingKey() { - return this.getMapping().getKey(); - } - - - // ***** default mapping - public JavaAttributeMapping getDefaultMapping() { - return this.defaultMapping; - } - - /** - * clients do not set the "default" mapping - */ - protected void setDefaultMapping(JavaAttributeMapping defaultMapping) { - JavaAttributeMapping old = this.defaultMapping; - this.defaultMapping = defaultMapping; - this.firePropertyChanged(DEFAULT_MAPPING_PROPERTY, old, defaultMapping); - } - - protected JavaAttributeMapping buildDefaultMapping() { - JavaAttributeMappingDefinition mappingDefinition = - getJpaPlatform().getDefaultJavaAttributeMappingDefinition(this); - return buildDefaultMapping(mappingDefinition); - } - - protected JavaAttributeMapping buildDefaultMapping(JavaAttributeMappingDefinition mappingDefinition) { - Annotation annotation = this.resourcePersistentAttribute. - buildNullAnnotation(mappingDefinition.getAnnotationName()); - JavaAttributeMapping mapping = mappingDefinition.buildMapping(this, getJpaFactory()); - mapping.initialize(annotation); - return mapping; - } - - /** - * return null if there is no "default" mapping for the attribute - */ - public String getDefaultMappingKey() { - return this.defaultMapping.getKey(); - } - - /** - * the mapping might be "default", but it still might be a "null" mapping... - */ - public boolean mappingIsDefault(JavaAttributeMapping mapping) { - return this.defaultMapping == mapping; - } - - protected void updateDefaultMapping() { - // There will always be a mapping definition, even if it is a "null" mapping provider ... - JavaAttributeMappingDefinition mappingDefinition = - getJpaPlatform().getDefaultJavaAttributeMappingDefinition(this); - String mappingKey = mappingDefinition.getKey(); - if (this.valuesAreEqual(this.defaultMapping.getKey(), mappingKey)) { - this.defaultMapping.update(this.resourcePersistentAttribute. - buildNullAnnotation(mappingDefinition.getAnnotationName())); - } - else { - setDefaultMapping(buildDefaultMapping(mappingDefinition)); - } - } - - // ***** specified mapping - public JavaAttributeMapping getSpecifiedMapping() { - return this.specifiedMapping; - } - - /** - * clients do not set the "specified" mapping; - * @see #setSpecifiedMappingKey(String) - */ - protected void setSpecifiedMapping(JavaAttributeMapping specifiedMapping) { - JavaAttributeMapping old = this.specifiedMapping; - this.specifiedMapping = specifiedMapping; - this.firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, old, specifiedMapping); - } - - protected JavaAttributeMapping buildSpecifiedMapping() { - JavaAttributeMappingDefinition mappingDefinition = - getJpaPlatform().getSpecifiedJavaAttributeMappingDefinition(this); - return buildSpecifiedMapping(mappingDefinition); - } - - protected JavaAttributeMapping buildSpecifiedMapping(JavaAttributeMappingDefinition mappingDefinition) { - Annotation annotation = this.resourcePersistentAttribute. - getAnnotation(mappingDefinition.getAnnotationName()); - JavaAttributeMapping mapping = mappingDefinition.buildMapping(this, getJpaFactory()); - // specified mappings may be null - if (mapping != null) { - mapping.initialize(annotation); - } - return mapping; - } - - /** - * return the key of the currently specified mapping or null - * if there is no specified mapping for the attribute - */ - protected 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 key) { - if (key == this.getSpecifiedMappingKey()) { - return; - } - JavaAttributeMapping oldMapping = this.specifiedMapping; - JavaAttributeMapping newMapping = this.buildMappingFromMappingKey(key); - - this.specifiedMapping = newMapping; - - String newAnnotation; - String[] newSupportingAnnotationNames; - if (newMapping != null) { - newAnnotation = newMapping.getAnnotationName(); - newSupportingAnnotationNames = - ArrayTools.array(newMapping.supportingAnnotationNames(), new String[0]); - } - else { - newAnnotation = null; - newSupportingAnnotationNames = - ArrayTools.array(this.defaultMapping.supportingAnnotationNames(), new String[0]); - } - this.resourcePersistentAttribute.setPrimaryAnnotation( - newAnnotation, newSupportingAnnotationNames); - this.firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, newMapping); - } - - /** - * return the annotation name of the currently specified mapping or null - * if there is no specified mapping for the attribute - */ - protected String getSpecifiedMappingAnnotationName() { - return (this.specifiedMapping == null) ? null : this.specifiedMapping.getAnnotationName(); - } - - protected JavaAttributeMapping buildMappingFromMappingKey(String key) { - JavaAttributeMappingDefinition mappingDefinition = getJpaPlatform().getSpecifiedJavaAttributeMappingDefinition(key); - JavaAttributeMapping mapping = mappingDefinition.buildMapping(this, getJpaFactory()); - //no mapping.initialize(JavaResourcePersistentAttribute) call here - //we do not yet have a mapping annotation so we can't call initialize - return mapping; - } - - protected Iterator<String> supportingAnnotationNames() { - JavaAttributeMapping mapping = this.getMapping(); - return (mapping != null) ? mapping.supportingAnnotationNames() : EmptyIterator.<String>instance(); - } - - protected void updateSpecifiedMapping() { - // There will always be a mapping definition, even if it is a "null" mapping provider ... - JavaAttributeMappingDefinition mappingDefinition = - getJpaPlatform().getSpecifiedJavaAttributeMappingDefinition(this); - String mappingKey = mappingDefinition.getKey(); - if (this.specifiedMapping != null - && this.specifiedMapping.getKey().equals(mappingKey)) { - this.specifiedMapping.update(this.resourcePersistentAttribute. - getAnnotation(mappingDefinition.getAnnotationName())); - } - else { - setSpecifiedMapping(buildSpecifiedMapping(mappingDefinition)); - } - } - - - // ********** misc overrides ********** - - @Override - public PersistentType getParent() { - return (PersistentType) super.getParent(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.name); - } - - - // ********** validation ********** - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - - this.validateModifiers(messages, astRoot); - - if (this.specifiedMapping != null) { - this.specifiedMapping.validate(messages, reporter, astRoot); - } - else if (this.defaultMapping != null) { - this.defaultMapping.validate(messages, reporter, astRoot); - } - } - - - protected void validateModifiers(List<IMessage> messages, CompilationUnit astRoot) { - if (this.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - - if (this.isField()) { - if (this.isFinal()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, astRoot)); - } - if (this.isPublic()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, astRoot)); - } - } - } - - protected IMessage buildAttributeMessage(String msgID, CompilationUnit astRoot) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - msgID, - new String[] {getName()}, - this, - this.getValidationTextRange(astRoot) - ); - } - - - // ********** Java completion proposals ********** - - @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); - } - - - // ********** static metamodel ********** - - public StaticMetamodelField getStaticMetamodelField() { - return new SimpleStaticMetamodelField( - this.getStaticMetamodelFieldModifiers(), - this.getStaticMetamodelFieldTypeName(), - this.getStaticMetamodelFieldTypeArgumentNames(), - this.getStaticMetamodelFieldName() - ); - } - - protected Iterable<String> getStaticMetamodelFieldModifiers() { - return STANDARD_STATIC_METAMODEL_FIELD_MODIFIERS; - } - - protected String getStaticMetamodelFieldTypeName() { - String typeName = this.resourcePersistentAttribute.getTypeName(); - if (typeName == null) { - return JPA2_0.SINGULAR_ATTRIBUTE; - } - return this.getJpaContainer(typeName).getStaticMetamodelFieldTypeName(); - } - - protected Iterable<String> getStaticMetamodelFieldTypeArgumentNames() { - ArrayList<String> typeArgumentNames = new ArrayList<String>(3); - typeArgumentNames.add(this.getPersistentType().getName()); - this.addStaticMetamodelFieldTypeArgumentNamesTo(typeArgumentNames); - return typeArgumentNames; - } - - protected void addStaticMetamodelFieldTypeArgumentNamesTo(ArrayList<String> typeArgumentNames){ - String typeName = this.resourcePersistentAttribute.getTypeName(); - if (typeName == null) { - typeArgumentNames.add(OBJECT_CLASS_NAME); // ??? - return; - } - if (ClassTools.classNamedIsPrimitive(typeName)) { - typeArgumentNames.add(ClassTools.wrapperClassName(typeName)); // ??? - return; - } - JpaContainer jpaContainer = this.getJpaContainer(typeName); - if (jpaContainer.isContainer()) { - jpaContainer.addStaticMetamodelFieldTypeArgumentNamesTo(typeArgumentNames, this.resourcePersistentAttribute); - return; - } - typeArgumentNames.add(typeName); - } - - protected static final String OBJECT_CLASS_NAME = java.lang.Object.class.getName(); - - protected String getStaticMetamodelFieldName() { - return this.getName(); - } - - - // ********** JPA containers ********** - - /** - * Return the JPA container corresponding to the specified type; - * return a "null" JPA container if the specified type is not one of the - * container types allowed by the JPA spec. - */ - protected JpaContainer getJpaContainer(String typeName) { - for (JpaContainer jpaContainer : JPA_CONTAINERS) { - if (jpaContainer.getTypeName().equals(typeName)) { - return jpaContainer; - } - } - return JpaContainer.Null.instance(); - } - - protected static final Iterable<JpaContainer> JPA_CONTAINERS = - new ArrayIterable<JpaContainer>(new JpaContainer[] { - new CollectionJpaContainer(java.util.Collection.class, JPA2_0.COLLECTION_ATTRIBUTE), - new CollectionJpaContainer(java.util.Set.class, JPA2_0.SET_ATTRIBUTE), - new CollectionJpaContainer(java.util.List.class, JPA2_0.LIST_ATTRIBUTE), - new MapJpaContainer(java.util.Map.class, JPA2_0.MAP_ATTRIBUTE) - }); - - /** - * JPA container interface (and null implementation) - */ - protected interface JpaContainer { - String getTypeName(); - boolean isContainer(); - String getMultiReferenceEntityTypeName(JavaResourcePersistentAttribute resourcePersistentAttribute); - String getStaticMetamodelFieldTypeName(); - void addStaticMetamodelFieldTypeArgumentNamesTo(List<String> typeArgumentNames, JavaResourcePersistentAttribute resourcePersistentAttribute); - - final class Null implements JpaContainer { - public static final JpaContainer INSTANCE = new Null(); - public static JpaContainer instance() { - return INSTANCE; - } - // ensure single instance - private Null() { - super(); - } - public String getTypeName() { - return null; - } - public boolean isContainer() { - return false; - } - public String getMultiReferenceEntityTypeName(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return null; - } - public String getStaticMetamodelFieldTypeName() { - return JPA2_0.SINGULAR_ATTRIBUTE; - } - public void addStaticMetamodelFieldTypeArgumentNamesTo(List<String> typeArgumentNames, JavaResourcePersistentAttribute resourcePersistentAttribute) { - throw new UnsupportedOperationException(); - } - @Override - public String toString() { - return "JpaContainer.Null"; //$NON-NLS-1$ - } - } - - } - - /** - * Abstract JPA container - */ - protected abstract static class AbstractJpaContainer implements JpaContainer { - protected final String typeName; - protected final String staticMetamodelFieldTypeName; - - protected AbstractJpaContainer(Class<?> containerClass, String staticMetamodelTypeDeclarationTypeName) { - this(containerClass.getName(), staticMetamodelTypeDeclarationTypeName); - } - - protected AbstractJpaContainer(String typeName, String staticMetamodelFieldTypeName) { - super(); - if ((typeName == null) || (staticMetamodelFieldTypeName == null)) { - throw new NullPointerException(); - } - this.typeName = typeName; - this.staticMetamodelFieldTypeName = staticMetamodelFieldTypeName; - } - - public String getTypeName() { - return this.typeName; - } - - public boolean isContainer() { - return true; - } - - public String getStaticMetamodelFieldTypeName() { - return this.staticMetamodelFieldTypeName; - } - - public void addStaticMetamodelFieldTypeArgumentNamesTo(List<String> typeArgumentNames, JavaResourcePersistentAttribute resourcePersistentAttribute) { - String elementType = this.getMultiReferenceEntityTypeName(resourcePersistentAttribute); - typeArgumentNames.add((elementType != null) ? elementType : OBJECT_CLASS_NAME); - } - - } - - /** - * Collection JPA container - */ - protected static class CollectionJpaContainer extends AbstractJpaContainer { - protected CollectionJpaContainer(Class<?> collectionClass, String staticMetamodelTypeDeclarationTypeName) { - super(collectionClass, staticMetamodelTypeDeclarationTypeName); - } - - public String getMultiReferenceEntityTypeName(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (resourcePersistentAttribute.typeTypeArgumentNamesSize() == 1) ? - resourcePersistentAttribute.getTypeTypeArgumentName(0) : - null; - } - - } - - /** - * Map JPA container - */ - protected static class MapJpaContainer extends AbstractJpaContainer { - protected MapJpaContainer(Class<?> mapClass, String staticMetamodelTypeDeclarationTypeName) { - super(mapClass, staticMetamodelTypeDeclarationTypeName); - } - - public String getMultiReferenceEntityTypeName(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (resourcePersistentAttribute.typeTypeArgumentNamesSize() == 2) ? - resourcePersistentAttribute.getTypeTypeArgumentName(1) : - null; - } - - private String getMultiKeyTypeName(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (resourcePersistentAttribute.typeTypeArgumentNamesSize() == 2) ? - resourcePersistentAttribute.getTypeTypeArgumentName(0) : - null; - } - - @Override - public void addStaticMetamodelFieldTypeArgumentNamesTo(List<String> typeArgumentNames, JavaResourcePersistentAttribute resourcePersistentAttribute) { - String keyType = this.getMultiKeyTypeName(resourcePersistentAttribute); - typeArgumentNames.add((keyType != null) ? keyType : OBJECT_CLASS_NAME); - super.addStaticMetamodelFieldTypeArgumentNamesTo(typeArgumentNames, resourcePersistentAttribute); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java deleted file mode 100644 index 33a456c45c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java +++ /dev/null @@ -1,650 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.core.resources.IFile; -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.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.internal.resource.java.source.SourceNode; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentType2_0; -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.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -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.jst.j2ee.model.internal.validation.ValidationCancelledException; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractJavaPersistentType - extends AbstractJavaJpaContextNode - implements JavaPersistentType2_0 -{ - protected JavaResourcePersistentType resourcePersistentType; - - protected PersistentType superPersistentType; - - protected String name; - - protected AccessType defaultAccess; - - protected AccessType specifiedAccess; - - protected JavaTypeMapping mapping; - - protected final Vector<JavaPersistentAttribute> attributes = - new Vector<JavaPersistentAttribute>(); - - - protected AbstractJavaPersistentType(PersistentType.Owner parent, JavaResourcePersistentType jrpt) { - super(parent); - this.initialize(jrpt); - } - - - @Override - public IResource getResource() { - return this.resourcePersistentType.getFile(); - } - - - //****************** JpaStructureNode implementation ******************* - - public String getId() { - return JavaStructureNodes.PERSISTENT_TYPE_ID; - } - - - //****************** PersistentType implementation ******************* - - public JavaResourcePersistentType getResourcePersistentType() { - return this.resourcePersistentType; - } - - @Override - public PersistentType.Owner getParent() { - return (PersistentType.Owner) super.getParent(); - } - - - // **************** name ************************************************** - - public String getName() { - return this.name; - } - - public String getShortName(){ - return getName().substring(getName().lastIndexOf('.') + 1); - } - - protected void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - protected String buildName() { - return this.resourcePersistentType.getQualifiedName(); - } - - - // **************** access ************************************************ - - public AccessType getAccess() { - return (this.specifiedAccess != null) ? this.specifiedAccess : this.defaultAccess; - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newDefaultAccess) { - AccessType oldAccess = this.defaultAccess; - this.defaultAccess = newDefaultAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldAccess, newDefaultAccess); - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - /** - * Check the access "specified" by the java resource model. - * Check java annotations first. - * If still null check xml mapping specified access - * If still null then set to superPersistentType 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 buildDefaultAccess() { - AccessType accessType = AccessType.fromJavaResourceModel(this.resourcePersistentType.getAccess()); - if (accessType != null) { - return accessType; - } - accessType = this.getOwnerOverrideAccess(); - if (accessType != null) { - return accessType; - } - - if (this.superPersistentType != null) { - accessType = this.superPersistentType.getDefaultAccess(); - if (accessType != null) { - return accessType; - } - } - - accessType = this.getOwnerDefaultAccess(); - if (accessType != null) { - return accessType; - } - - // last ditch attempt to allow the user to annotate *something* - return AccessType.FIELD; - } - - /** - * Build an access type based on annotations from the resource model. - * (This is platform dependent) - */ - protected abstract AccessType buildSpecifiedAccess(); - - - // **************** mapping *********************************************** - - public JavaTypeMapping getMapping() { - return this.mapping; - } - - public String getMappingKey() { - return getMapping().getKey(); - } - - public void setMappingKey(String key) { - if (this.valuesAreEqual(key, this.getMapping().getKey())) { - return; - } - JavaTypeMapping oldMapping = getMapping(); - JavaTypeMapping newMapping = buildMappingFromMappingKey(key); - - this.mapping = newMapping; - this.resourcePersistentType.setPrimaryAnnotation( - newMapping.getAnnotationName(), - ArrayTools.array(newMapping.supportingAnnotationNames(), new String[0])); - firePropertyChanged(MAPPING_PROPERTY, oldMapping, newMapping); - } - - protected void setMapping(JavaTypeMapping newMapping) { - JavaTypeMapping oldMapping = this.mapping; - this.mapping = newMapping; - firePropertyChanged(MAPPING_PROPERTY, oldMapping, newMapping); - } - - protected JavaTypeMapping buildMapping() { - JavaTypeMappingDefinition mappingDefinition = - getJpaPlatform().getJavaTypeMappingDefinition(this); - return buildMapping(mappingDefinition); - } - - protected JavaTypeMapping buildMapping(JavaTypeMappingDefinition mappingDefinition) { - JavaTypeMapping jtMapping = mappingDefinition.buildMapping(this, getJpaFactory()); - // mapping may be null - if (jtMapping != null) { - jtMapping.initialize(this.resourcePersistentType); - } - return jtMapping; - } - - protected JavaTypeMapping buildMappingFromMappingKey(String key) { - JavaTypeMappingDefinition mappingDefinition = - getJpaPlatform().getJavaTypeMappingDefinition(key); - JavaTypeMapping jtMapping = mappingDefinition.buildMapping(this, getJpaFactory()); - //no mapping.initialize(JavaResourcePersistentType) call here - //we do not yet have a mapping annotation so we can't call initialize - return jtMapping; - } - - - public boolean isMapped() { - return getMapping().isMapped(); - } - - public AccessType getOwnerOverrideAccess() { - return this.getParent().getOverridePersistentTypeAccess(); - } - - public AccessType getOwnerDefaultAccess() { - return this.getParent().getDefaultPersistentTypeAccess(); - } - - 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 (this.superPersistentType == null) ? null : this.superPersistentType.resolveAttribute(attributeName); - } - - public ListIterator<JavaPersistentAttribute> attributes() { - return new CloneListIterator<JavaPersistentAttribute>(this.attributes); - } - - protected Iterable<JavaPersistentAttribute> getAttributes() { - return new LiveCloneIterable<JavaPersistentAttribute>(this.attributes); - } - - public int attributesSize() { - return this.attributes.size(); - } - - private void addAttribute(int index, JavaPersistentAttribute attribute) { - addItemToList(index, attribute, this.attributes, ATTRIBUTES_LIST); - } - - private void removeAttribute(JavaPersistentAttribute attribute) { - removeItemFromList(attribute, this.attributes, ATTRIBUTES_LIST); - } - - private void moveAttribute(int index, JavaPersistentAttribute attribute) { - moveItemInList(index, this.attributes.indexOf(attribute), this.attributes, 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 (JavaPersistentAttribute attribute : this.getAttributes()) { - values = attribute.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 (JavaPersistentAttribute persistentAttribute : this.getAttributes()) { - if (persistentAttribute.contains(offset, astRoot)) { - return persistentAttribute; - } - } - return this; - } - return null; - } - - protected CompilationUnit buildASTRoot() { - return this.resourcePersistentType.getJavaResourceCompilationUnit().buildASTRoot(); - } - - 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() { - return this.inheritanceHierarchyOf(this); - } - - public Iterator<PersistentType> ancestors() { - return this.inheritanceHierarchyOf(this.superPersistentType); - } - - protected Iterator<PersistentType> inheritanceHierarchyOf(PersistentType start) { - // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(start) { - @Override - protected PersistentType nextLink(PersistentType persistentType) { - return persistentType.getSuperPersistentType(); - } - }; - } - - public PersistentType getSuperPersistentType() { - return this.superPersistentType; - } - - protected void setSuperPersistentType(PersistentType superPersistentType) { - PersistentType old = this.superPersistentType; - this.superPersistentType = superPersistentType; - this.firePropertyChanged(SUPER_PERSISTENT_TYPE_PROPERTY, old, superPersistentType); - } - - public boolean hasAnyAnnotatedAttributes() { - return this.resourcePersistentType.hasAnyAnnotatedAttributes(); - } - - // **************** 2.0 static metamodel ***************************** - - public void synchronizeStaticMetamodel() { - ((JpaProject2_0) this.getJpaProject()).synchronizeStaticMetamodel(this); - } - - // **************** initialization / updating ***************************** - - protected void initialize(JavaResourcePersistentType jrpt) { - this.resourcePersistentType = jrpt; - this.superPersistentType = this.buildSuperPersistentType(); - this.name = this.buildName(); - this.defaultAccess = buildDefaultAccess(); - this.specifiedAccess = buildSpecifiedAccess(); - this.mapping = buildMapping(); - this.initializeAttributes(); - } - - protected void initializeAttributes() { - for (Iterator<JavaResourcePersistentAttribute> stream = this.resourceAttributes(); stream.hasNext(); ) { - this.attributes.add(this.createAttribute(stream.next())); - } - } - - protected Iterator<JavaResourcePersistentAttribute> resourceAttributes() { - return (this.getAccess() == AccessType.PROPERTY) ? - this.resourcePersistentType.persistableProperties() : - this.resourcePersistentType.persistableFields(); - } - - public void update(JavaResourcePersistentType jrpt) { - this.resourcePersistentType = jrpt; - this.update(); - } - - public void update() { - JpaFile jpaFile = this.getJpaFile(); - if (jpaFile != null) { - // the JPA file can be null if the resource type is "external" - jpaFile.addRootStructureNode(this.resourcePersistentType.getQualifiedName(), this); - } - this.setSuperPersistentType(this.buildSuperPersistentType()); - this.setName(this.buildName()); - this.updateAccess(); - this.updateMapping(); - this.updateAttributes(); - } - - protected JpaFile getJpaFile() { - return this.getJpaFile(this.resourcePersistentType.getFile()); - } - - protected void updateAccess() { - this.setDefaultAccess(this.buildDefaultAccess()); - - } - - protected void updateMapping() { - // There will always be a mapping definition, even if it is a "null" mapping definition ... - JavaTypeMappingDefinition mappingDefinition = - getJpaPlatform().getJavaTypeMappingDefinition(this); - String mappingKey = mappingDefinition.getKey(); - if (this.mapping != null - && valuesAreEqual(this.mapping.getKey(), mappingKey)) { - this.mapping.update(this.resourcePersistentType); - } - else { - setMapping(buildMapping(mappingDefinition)); - } - } - - protected void updateAttributes() { - HashBag<JavaPersistentAttribute> contextAttributesToRemove = CollectionTools.bag(this.attributes(), this.attributesSize()); - ArrayList<JavaPersistentAttribute> contextAttributesToUpdate = new ArrayList<JavaPersistentAttribute>(this.attributesSize()); - int resourceIndex = 0; - - for (Iterator<JavaResourcePersistentAttribute> resourceAttributes = this.resourceAttributes(); resourceAttributes.hasNext(); ) { - JavaResourcePersistentAttribute resourceAttribute = resourceAttributes.next(); - boolean match = false; - for (Iterator<JavaPersistentAttribute> contextAttributes = contextAttributesToRemove.iterator(); contextAttributes.hasNext(); ) { - JavaPersistentAttribute contextAttribute = contextAttributes.next(); - if (contextAttribute.getResourcePersistentAttribute() == resourceAttribute) { - this.moveAttribute(resourceIndex, contextAttribute); - contextAttributes.remove(); - contextAttributesToUpdate.add(contextAttribute); - match = true; - break; - } - } - if ( ! match) { - this.addAttribute(resourceIndex, this.createAttribute(resourceAttribute)); - } - resourceIndex++; - } - for (JavaPersistentAttribute contextAttribute : contextAttributesToRemove) { - this.removeAttribute(contextAttribute); - } - // handle adding and removing attributes first, update the - // remaining attributes last; this reduces the churn during "update" - for (JavaPersistentAttribute contextAttribute : contextAttributesToUpdate) { - contextAttribute.update(); - } - } - - protected JavaPersistentAttribute createAttribute(JavaResourcePersistentAttribute jrpa) { - return getJpaFactory().buildJavaPersistentAttribute(this, jrpa); - } - - protected PersistentType buildSuperPersistentType() { - HashSet<JavaResourcePersistentType> visited = new HashSet<JavaResourcePersistentType>(); - visited.add(this.resourcePersistentType); - PersistentType spt = this.getSuperPersistentType(this.resourcePersistentType.getSuperclassQualifiedName(), visited); - if (spt == null) { - return null; - } - if (CollectionTools.contains(spt.inheritanceHierarchy(), this)) { - return null; // short-circuit in this case, we have circular inheritance - } - return spt.isMapped() ? spt : spt.getSuperPersistentType(); - } - - /** - * The JPA spec allows non-persistent types in a persistent type's - * inheritance hierarchy. We check for a persistent type with the - * specified name in the persistence unit. If it is not found we use - * resource persistent type and look for *its* super type. - * - * The 'visited' collection is used to detect a cycle in the *resource* type - * inheritance hierarchy and prevent the resulting stack overflow. - * Any cycles in the *context* type inheritance hierarchy are handled in - * #buildSuperPersistentType(). - */ - protected PersistentType getSuperPersistentType(String typeName, Collection<JavaResourcePersistentType> visited) { - if (typeName == null) { - return null; - } - JavaResourcePersistentType resourceType = this.getJpaProject().getJavaResourcePersistentType(typeName); - if ((resourceType == null) || visited.contains(resourceType)) { - return null; - } - visited.add(resourceType); - PersistentType spt = this.getPersistentType(typeName); - return (spt != null) ? spt : this.getSuperPersistentType(resourceType.getSuperclassQualifiedName(), visited); // recurse - } - - protected PersistentType getPersistentType(String fullyQualifiedTypeName) { - return getPersistenceUnit().getPersistentType(fullyQualifiedTypeName); - } - - @Override - public void postUpdate() { - super.postUpdate(); - getMapping().postUpdate(); - for (PersistentAttribute attribute : CollectionTools.iterable(attributes())) { - attribute.postUpdate(); - } - } - - // ********** validation ********** - - public void validate(List<IMessage> messages, IReporter reporter) { - if (reporter.isCancelled()) { - throw new ValidationCancelledException(); - } - // TODO temporary hack since we don't know yet where to put - // any messages for types in another project (e.g. referenced by - // persistence.xml) - IFile file = this.resourcePersistentType.getFile(); - // 'file' will be null if the type is "external" and binary; - // the file will be in a different project if the type is "external" and source; - // the type will be binary if it is in a JAR in the current project - if ((file != null) && file.getProject().equals(this.getJpaProject().getProject()) && - (this.resourcePersistentType instanceof SourceNode)) { - // build the AST root here to pass down - this.validate(messages, reporter, this.buildASTRoot()); - } - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.validateMapping(messages, reporter, astRoot); - this.validateAttributes(messages, reporter, astRoot); - } - - protected void validateMapping(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - try { - this.mapping.validate(messages, reporter, astRoot); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - - protected void validateAttributes(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - for (JavaPersistentAttribute attribute : this.getAttributes()) { - this.validateAttribute(attribute, reporter, messages, astRoot); - } - } - - protected void validateAttribute(JavaPersistentAttribute attribute, IReporter reporter, List<IMessage> messages, CompilationUnit astRoot) { - try { - attribute.validate(messages, reporter, astRoot); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - - - // ********** misc ********** - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.name); - } - - public void dispose() { - JpaFile jpaFile = this.getJpaFile(); - if (jpaFile != null) { - // the JPA file can be null if the .java file was deleted - // or the resource type is "external" - jpaFile.removeRootStructureNode(this.resourcePersistentType.getQualifiedName()); - } - } - -} 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 0d4a41289d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaQuery.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.BaseNamedQueryAnnotation; -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.StringTools; -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 BaseNamedQueryAnnotation resourceQuery; - - protected AbstractJavaQuery(JavaJpaContextNode parent) { - super(parent); - this.hints = new ArrayList<JavaQueryHint>(); - } - - protected BaseNamedQueryAnnotation getResourceQuery() { - return this.resourceQuery; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.resourceQuery.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.resourceQuery.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.getResourceQuery().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); - } - - protected void addHint(JavaQueryHint hint) { - addHint(this.hints.size(), hint); - } - - public void removeHint(QueryHint queryHint) { - removeHint(this.hints.indexOf(queryHint)); - } - - public void removeHint(int index) { - JavaQueryHint removedHint = this.hints.remove(index); - this.getResourceQuery().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.getResourceQuery().moveHint(targetIndex, sourceIndex); - fireItemMoved(Query.HINTS_LIST, targetIndex, sourceIndex); - } - - protected void initialize(BaseNamedQueryAnnotation queryAnnotation) { - this.resourceQuery = queryAnnotation; - this.name = queryAnnotation.getName(); - this.query = queryAnnotation.getQuery(); - this.initializeQueryHints(); - } - - protected void update(BaseNamedQueryAnnotation queryAnnotation) { - this.resourceQuery = queryAnnotation; - this.setName_(queryAnnotation.getName()); - this.setQuery_(queryAnnotation.getQuery()); - this.updateQueryHints(); - getPersistenceUnit().addQuery(this); - } - - protected void initializeQueryHints() { - ListIterator<QueryHintAnnotation> resourceHints = this.resourceQuery.hints(); - - while(resourceHints.hasNext()) { - this.hints.add(createQueryHint(resourceHints.next())); - } - } - - protected void updateQueryHints() { - ListIterator<JavaQueryHint> contextHints = hints(); - ListIterator<QueryHintAnnotation> resourceHints = this.resourceQuery.hints(); - - while (contextHints.hasNext()) { - JavaQueryHint hint = contextHints.next(); - if (resourceHints.hasNext()) { - hint.update(resourceHints.next()); - } - else { - removeHint_(hint); - } - } - - while (resourceHints.hasNext()) { - addHint(createQueryHint(resourceHints.next())); - } - } - - protected JavaQueryHint createQueryHint(QueryHintAnnotation resourceQueryHint) { - JavaQueryHint queryHint = getJpaFactory().buildJavaQueryHint(this); - queryHint.initialize(resourceQueryHint); - return queryHint; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.resourceQuery.getTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.resourceQuery.getNameTextRange(astRoot); - } - - public boolean overrides(Query other) { - // java is at the base of the tree - return false; - } - - public boolean duplicates(Query other) { - return (this != other) - && ! StringTools.stringIsEmpty(this.name) - && this.name.equals(other.getName()) - && ! this.overrides(other) - && ! other.overrides(this); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/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 163000aff1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipMapping.java +++ /dev/null @@ -1,258 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaCascade; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaRelationshipReference; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -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.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * Java relationship mapping - */ -public abstract class AbstractJavaRelationshipMapping<T extends RelationshipMappingAnnotation> - extends AbstractJavaAttributeMapping<T> - implements JavaRelationshipMapping -{ - protected String specifiedTargetEntity; - protected String defaultTargetEntity; - protected Entity resolvedTargetEntity; - - protected final JavaRelationshipReference relationshipReference; - - protected final JavaCascade cascade; - - protected FetchType specifiedFetch; - - - protected AbstractJavaRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.relationshipReference = this.buildRelationshipReference(); - this.cascade = this.getJpaFactory().buildJavaCascade(this); - } - - @Override - protected void initialize() { - super.initialize(); - this.defaultTargetEntity = this.buildDefaultTargetEntity(); - this.relationshipReference.initialize(); - this.specifiedFetch = this.getResourceFetch(); - this.cascade.initialize(this.mappingAnnotation); - this.specifiedTargetEntity = this.getResourceTargetEntity(); - this.resolvedTargetEntity = this.buildResolvedTargetEntity(); - } - - @Override - protected void update() { - super.update(); - this.setDefaultTargetEntity(this.buildDefaultTargetEntity()); - this.relationshipReference.update(); - this.setSpecifiedFetch_(this.getResourceFetch()); - this.cascade.update(this.mappingAnnotation); - this.setSpecifiedTargetEntity_(this.getResourceTargetEntity()); - this.setResolvedTargetEntity(this.buildResolvedTargetEntity()); - } - - - // ********** target entity ********** - - public String getTargetEntity() { - return (this.specifiedTargetEntity != null) ? this.specifiedTargetEntity : this.defaultTargetEntity; - } - - public String getSpecifiedTargetEntity() { - return this.specifiedTargetEntity; - } - - public void setSpecifiedTargetEntity(String targetEntity) { - String old = this.specifiedTargetEntity; - this.specifiedTargetEntity = targetEntity; - this.mappingAnnotation.setTargetEntity(targetEntity); - this.firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - protected void setSpecifiedTargetEntity_(String targetEntity) { - String old = this.specifiedTargetEntity; - this.specifiedTargetEntity = targetEntity; - this.firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - protected String getResourceTargetEntity() { - return this.mappingAnnotation.getTargetEntity(); - } - - public String getDefaultTargetEntity() { - return this.defaultTargetEntity; - } - - protected void setDefaultTargetEntity(String targetEntity) { - String old = this.defaultTargetEntity; - this.defaultTargetEntity = targetEntity; - this.firePropertyChanged(DEFAULT_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - protected abstract String buildDefaultTargetEntity(); - - public Entity getResolvedTargetEntity() { - return this.resolvedTargetEntity; - } - - protected void setResolvedTargetEntity(Entity entity) { - Entity old = this.resolvedTargetEntity; - this.resolvedTargetEntity = entity; - this.firePropertyChanged(RESOLVED_TARGET_ENTITY_PROPERTY, old, entity); - } - - protected Entity buildResolvedTargetEntity() { - String targetEntityClassName = (this.specifiedTargetEntity == null) ? - this.defaultTargetEntity : - this.mappingAnnotation.getFullyQualifiedTargetEntityClassName(); - return (targetEntityClassName == null) ? null : this.getPersistenceUnit().getEntity(targetEntityClassName); - } - - public Iterator<String> allTargetEntityAttributeNames() { - return (this.resolvedTargetEntity != null) ? - this.resolvedTargetEntity.getPersistentType().allAttributeNames() : - EmptyIterator.<String> instance(); - } - - public char getTargetEntityEnclosingTypeSeparator() { - return '.'; - } - - - // ********** relationship reference ********** - - public JavaRelationshipReference getRelationshipReference() { - return this.relationshipReference; - } - - protected abstract JavaRelationshipReference buildRelationshipReference(); - - public boolean isRelationshipOwner() { - return this.relationshipReference.isRelationshipOwner(); - } - - @Override - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.relationshipReference.isOwnedBy(mapping); - } - - @Override - public boolean isOverridableAssociationMapping() { - return this.relationshipReference.isOverridableAssociation(); - } - - - // ********** cascade ********** - - public JavaCascade getCascade() { - return this.cascade; - } - - - // ********** fetch ********** - - public FetchType getFetch() { - return (this.specifiedFetch != null) ? this.specifiedFetch : this.getDefaultFetch(); - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType fetch) { - FetchType old = this.specifiedFetch; - this.specifiedFetch = fetch; - this.mappingAnnotation.setFetch(FetchType.toJavaResourceModel(fetch)); - this.firePropertyChanged(SPECIFIED_FETCH_PROPERTY, old, fetch); - } - - protected void setSpecifiedFetch_(FetchType fetch) { - FetchType old = this.specifiedFetch; - this.specifiedFetch = fetch; - this.firePropertyChanged(SPECIFIED_FETCH_PROPERTY, old, fetch); - } - - protected FetchType getResourceFetch() { - return FetchType.fromJavaResourceModel(this.mappingAnnotation.getFetch()); - } - - - // ********** Java completion proposals ********** - - @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.relationshipReference.javaCompletionProposals(pos, filter, astRoot); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.validateTargetEntity(messages, astRoot); - this.relationshipReference.validate(messages, reporter, astRoot); - } - - protected void validateTargetEntity(List<IMessage> messages, CompilationUnit astRoot) { - if (this.getTargetEntity() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TARGET_ENTITY_NOT_DEFINED, - new String[] {this.getName()}, - this, - this.getValidationTextRange(astRoot) - ) - ); - } - else if (this.resolvedTargetEntity == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TARGET_ENTITY_IS_NOT_AN_ENTITY, - new String[] {this.getTargetEntity(), this.getName()}, - this, - this.getTargetEntityTextRange(astRoot) - ) - ); - } - } - - protected TextRange getTargetEntityTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.mappingAnnotation.getTargetEntityTextRange(astRoot), astRoot); - } - - protected TextRange getTextRange(TextRange textRange, CompilationUnit astRoot) { - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipReference.java deleted file mode 100644 index 41c77fceaf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipReference.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaRelationshipReference; -import org.eclipse.jpt.core.utility.TextRange; - -public abstract class AbstractJavaRelationshipReference - extends AbstractJavaJpaContextNode - implements JavaRelationshipReference -{ - // cache the strategy for property change notification - protected JoiningStrategy cachedPredominantJoiningStrategy; - - - public AbstractJavaRelationshipReference(JavaRelationshipMapping parent) { - super(parent); - } - - - public JavaRelationshipMapping getRelationshipMapping() { - return (JavaRelationshipMapping) getParent(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public Entity getEntity() { - TypeMapping typeMapping = getTypeMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - public boolean isOverridableAssociation() { - return getPredominantJoiningStrategy().isOverridableAssociation(); - } - - public boolean isParentVirtual() { - return getRelationshipMapping().getPersistentAttribute().isVirtual(); - } - - // **************** predominant joining strategy *************************** - - public JoiningStrategy getPredominantJoiningStrategy() { - return this.cachedPredominantJoiningStrategy; - } - - protected void setPredominantJoiningStrategy(JoiningStrategy newJoiningStrategy) { - JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; - this.cachedPredominantJoiningStrategy = newJoiningStrategy; - firePropertyChanged(PREDOMINANT_JOINING_STRATEGY_PROPERTY, oldJoiningStrategy, newJoiningStrategy); - } - - - // **************** resource -> context ************************************ - - public void initialize() { - initializeJoiningStrategies(); - this.cachedPredominantJoiningStrategy = calculatePredominantJoiningStrategy(); - } - - protected abstract void initializeJoiningStrategies(); - - public void update() { - updateJoiningStrategies(); - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); - } - - protected abstract void updateJoiningStrategies(); - - protected abstract JoiningStrategy calculatePredominantJoiningStrategy(); - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return getRelationshipMapping().getValidationTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java deleted file mode 100644 index 3d59451b5c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSequenceGenerator.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -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; -import org.eclipse.jpt.db.Schema; -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 AbstractJavaSequenceGenerator extends AbstractJavaGenerator - implements JavaSequenceGenerator -{ - protected String specifiedSequenceName; - - - protected AbstractJavaSequenceGenerator(JavaJpaContextNode parent) { - super(parent); - } - - - // ********** sequence name ********** - - public String getSequenceName() { - return (this.specifiedSequenceName != null) ? this.specifiedSequenceName : this.getDefaultSequenceName(); - } - - public String getSpecifiedSequenceName() { - return this.specifiedSequenceName; - } - - public void setSpecifiedSequenceName(String specifiedSequenceName) { - String old = this.specifiedSequenceName; - this.specifiedSequenceName = specifiedSequenceName; - this.getResourceGenerator().setSequenceName(specifiedSequenceName); - this.firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, old, specifiedSequenceName); - } - - protected void setSpecifiedSequenceName_(String specifiedSequenceName) { - String old = this.specifiedSequenceName; - this.specifiedSequenceName = specifiedSequenceName; - this.firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, old, specifiedSequenceName); - } - - public String getDefaultSequenceName() { - return null; - } - - - // ********** resource => context ********** - - public void initialize(SequenceGeneratorAnnotation resourceSequenceGenerator) { - super.initialize(resourceSequenceGenerator); - this.specifiedSequenceName = resourceSequenceGenerator.getSequenceName(); - } - - public void update(SequenceGeneratorAnnotation resourceSequenceGenerator) { - super.update(resourceSequenceGenerator); - this.setSpecifiedSequenceName_(resourceSequenceGenerator.getSequenceName()); - } - - - // ********** Java completion proposals ********** - - /** - * called if the database is connected: - * sequenceName - */ - @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.sequenceNameTouches(pos, astRoot)) { - return this.javaCandidateSequences(filter); - } - return null; - } - - protected boolean sequenceNameTouches(int pos, CompilationUnit astRoot) { - return this.getResourceGenerator().sequenceNameTouches(pos, astRoot); - } - - protected Iterator<String> javaCandidateSequences(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateSequences(filter)); - } - - protected Iterator<String> candidateSequences(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateSequences(), filter); - } - - protected Iterator<String> candidateSequences() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema != null) ? dbSchema.sortedSequenceIdentifiers() : EmptyIterator.<String> instance(); - } - - - // ********** misc ********** - - public int getDefaultInitialValue() { - return SequenceGenerator.DEFAULT_INITIAL_VALUE; - } - - @Override - protected SequenceGeneratorAnnotation getResourceGenerator() { - return (SequenceGeneratorAnnotation) super.getResourceGenerator(); - } - -} 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 c5d956fa01..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.jpa2.JpaFactory2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * Java single relationship (1:1, m:1) mapping - */ -public abstract class AbstractJavaSingleRelationshipMapping<T extends RelationshipMappingAnnotation> - extends AbstractJavaRelationshipMapping<T> - implements JavaSingleRelationshipMapping2_0 -{ - protected Boolean specifiedOptional; - - protected final JavaDerivedId2_0 derivedId; - - protected AbstractJavaSingleRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.derivedId = buildDerivedId(); - } - - @Override - protected void initialize() { - super.initialize(); - this.specifiedOptional = this.getResourceOptional(); - this.derivedId.initialize(); - } - - @Override - protected void update() { - super.update(); - this.setSpecifiedOptional_(this.getResourceOptional()); - this.derivedId.update(); - } - - @Override - protected String[] buildSupportingAnnotationNames() { - String[] annotationNames = ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS, - JPA.JOIN_TABLE); - - if (getJpaPlatformVersion().is2_0Compatible()) { - annotationNames = ArrayTools.add(annotationNames, JPA.ID); - } - return annotationNames; - } - - // ********** optional ********** - - public boolean isOptional() { - return (this.specifiedOptional != null) ? this.specifiedOptional.booleanValue() : this.isDefaultOptional(); - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean optional) { - Boolean old = this.specifiedOptional; - this.specifiedOptional = optional; - this.setResourceOptional(optional); - this.firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, old, optional); - } - - protected void setSpecifiedOptional_(Boolean optional) { - Boolean old = this.specifiedOptional; - this.specifiedOptional = optional; - this.firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, old, optional); - } - - public boolean isDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - protected abstract Boolean getResourceOptional(); - - protected abstract void setResourceOptional(Boolean newOptional); - - - // ********** 2.0 derived id ********** - - protected JavaDerivedId2_0 buildDerivedId() { - return ((JpaFactory2_0) getJpaFactory()).buildJavaDerivedId(this); - } - - public JavaDerivedId2_0 getDerivedId() { - return this.derivedId; - } - - @Override - public boolean isIdMapping() { - return this.derivedId.getValue(); - } - - // ********** AbstractJavaRelationshipMapping implementation ********** - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - @Override - protected String buildDefaultTargetEntity() { - return this.getPersistentAttribute().getSingleReferenceEntityTypeName(); - } - - - // ********** Fetchable implementation ********** - - public FetchType getDefaultFetch() { - return DEFAULT_FETCH_TYPE; - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.derivedId.validate(messages, reporter, astRoot); - } - -} 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 ee99590247..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java +++ /dev/null @@ -1,501 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; - -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.BaseTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -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; - -/** - * Java table - */ -public abstract class AbstractJavaTable - extends AbstractJavaJpaContextNode - implements Table, UniqueConstraint.Owner -{ - protected String specifiedName; - protected String defaultName; - - protected String specifiedSchema; - protected String defaultSchema; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected final Vector<JavaUniqueConstraint> uniqueConstraints = new Vector<JavaUniqueConstraint>(); - - - // ********** constructor ********** - - protected AbstractJavaTable(JavaJpaContextNode parent) { - super(parent); - } - - - // ********** abstract methods ********** - - /** - * Return the Java table annotation. Do not return null if the Java - * annotation does not exist; return a null table annotation instead. - */ - protected abstract BaseTableAnnotation getAnnotation(); - - /** - * Return the name of the Java annotation. - */ - protected abstract String getAnnotationName(); - - protected abstract String buildDefaultName(); - - protected abstract String buildDefaultSchema(); - - protected abstract String buildDefaultCatalog(); - - - // ********** name ********** - - public String getName() { - return (this.specifiedName != null) ? this.specifiedName : this.defaultName; - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String name) { - String old = this.specifiedName; - this.specifiedName = name; - this.getAnnotation().setName(name); - this.firePropertyChanged(SPECIFIED_NAME_PROPERTY, old, name); - } - - /** - * 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 name) { - String old = this.specifiedName; - this.specifiedName = name; - this.firePropertyChanged(SPECIFIED_NAME_PROPERTY, old, name); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String name) { - String old = this.defaultName; - this.defaultName = name; - this.firePropertyChanged(DEFAULT_NAME_PROPERTY, old, name); - } - - - // ********** schema ********** - - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.getAnnotation().setSchema(schema); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - /** - * 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(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - - // ********** catalog ********** - - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.getAnnotation().setCatalog(catalog); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - /** - * 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 catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - this.firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - - // ********** unique constraints ********** - - public @SuppressWarnings("unchecked") 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.getAnnotation().addUniqueConstraint(index); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - fireItemAdded(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.getAnnotation().removeUniqueConstraint(index); - fireItemRemoved(UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getAnnotation().moveUniqueConstraint(targetIndex, sourceIndex); - fireItemMoved(UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void addUniqueConstraint(int index, JavaUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - protected void addUniqueConstraint(JavaUniqueConstraint uniqueConstraint) { - this.addUniqueConstraint(this.uniqueConstraints.size(), uniqueConstraint); - } - - protected void removeUniqueConstraint_(JavaUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - protected void initializeUniqueConstraints(BaseTableAnnotation baseTableAnnotation) { - for (Iterator<UniqueConstraintAnnotation> stream = baseTableAnnotation.uniqueConstraints(); stream.hasNext(); ) { - this.uniqueConstraints.add(buildUniqueConstraint(stream.next())); - } - } - - protected void updateUniqueConstraints(BaseTableAnnotation baseTableAnnotation) { - ListIterator<UniqueConstraintAnnotation> constraintAnnotations = baseTableAnnotation.uniqueConstraints(); - ListIterator<JavaUniqueConstraint> constraints = this.uniqueConstraints(); - while (constraints.hasNext()) { - JavaUniqueConstraint uniqueConstraint = constraints.next(); - if (constraintAnnotations.hasNext()) { - uniqueConstraint.update(constraintAnnotations.next()); - } else { - this.removeUniqueConstraint_(uniqueConstraint); - } - } - - while (constraintAnnotations.hasNext()) { - this.addUniqueConstraint(this.buildUniqueConstraint(constraintAnnotations.next())); - } - } - - protected JavaUniqueConstraint buildUniqueConstraint(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - JavaUniqueConstraint uniqueConstraint = this.getJpaFactory().buildJavaUniqueConstraint(this, this); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - return uniqueConstraint; - } - - - // ********** convenience methods ********** - - protected TextRange getTextRange(TextRange textRange, CompilationUnit astRoot) { - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - protected TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.getAnnotation().getNameTextRange(astRoot), astRoot); - } - - protected boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.getAnnotation().nameTouches(pos, astRoot); - } - - protected TextRange getSchemaTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.getAnnotation().getSchemaTextRange(astRoot), astRoot); - } - - protected boolean schemaTouches(int pos, CompilationUnit astRoot) { - return this.getAnnotation().schemaTouches(pos, astRoot); - } - - protected TextRange getCatalogTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.getAnnotation().getCatalogTextRange(astRoot), astRoot); - } - - protected boolean catalogTouches(int pos, CompilationUnit astRoot) { - return this.getAnnotation().catalogTouches(pos, astRoot); - } - - - // ********** resource => context ********** - - protected void initialize(BaseTableAnnotation baseTableAnnotation) { - this.defaultName = this.buildDefaultName(); - this.specifiedName = baseTableAnnotation.getName(); - - this.defaultSchema = this.buildDefaultSchema(); - this.specifiedSchema = baseTableAnnotation.getSchema(); - - this.defaultCatalog = this.buildDefaultCatalog(); - this.specifiedCatalog = baseTableAnnotation.getCatalog(); - - this.initializeUniqueConstraints(baseTableAnnotation); - } - - protected void update(BaseTableAnnotation baseTableAnnotation) { - this.setDefaultName(this.buildDefaultName()); - this.setSpecifiedName_(baseTableAnnotation.getName()); - - this.setDefaultSchema(this.buildDefaultSchema()); - this.setSpecifiedSchema_(baseTableAnnotation.getSchema()); - - this.setDefaultCatalog(this.buildDefaultCatalog()); - this.setSpecifiedCatalog_(baseTableAnnotation.getCatalog()); - - this.updateUniqueConstraints(baseTableAnnotation); - } - - - // ********** database ********** - - public org.eclipse.jpt.db.Table getDbTable() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema == null) ? null : dbSchema.getTableForIdentifier(this.getName()); - } - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - public boolean isResolved() { - return this.getDbTable() != null; - } - - public boolean hasResolvedSchema() { - return this.getDbSchema() != null; - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public boolean hasResolvedCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) || (this.getDbCatalog(catalog) != null); - } - - - // ********** UniqueConstraint.Owner implementation ********** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.sortedColumnIdentifiers() : EmptyIterator.<String>instance(); - } - - - // ********** validation ********** - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.getAnnotation().getTextRange(astRoot), astRoot); - } - - - // ********** Java completion proposals ********** - - @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.javaCandidateNames(filter); - } - if (this.schemaTouches(pos, astRoot)) { - return this.javaCandidateSchemata(filter); - } - if (this.catalogTouches(pos, astRoot)) { - return this.javaCandidateCatalogs(filter); - } - return null; - } - - protected Iterator<String> javaCandidateNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateNames(filter)); - } - - protected Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - protected Iterator<String> candidateNames() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema != null) ? dbSchema.sortedTableIdentifiers() : EmptyIterator.<String> instance(); - } - - protected Iterator<String> javaCandidateSchemata(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateSchemata(filter)); - } - - protected Iterator<String> candidateSchemata(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateSchemata(), filter); - } - - protected Iterator<String> candidateSchemata() { - return this.getDbSchemaContainer().sortedSchemaIdentifiers(); - } - - protected Iterator<String> javaCandidateCatalogs(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateCatalogs(filter)); - } - - protected Iterator<String> candidateCatalogs(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateCatalogs(), filter); - } - - protected Iterator<String> candidateCatalogs() { - Database db = this.getDatabase(); - return (db != null) ? db.sortedCatalogIdentifiers() : EmptyIterator.<String> instance(); - } - - - // ********** misc ********** - - /** - * covariant override - */ - @Override - public JavaJpaContextNode getParent() { - return (JavaJpaContextNode) super.getParent(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.getQualifiedName()); - } - - protected String getQualifiedName() { - return NameTools.buildQualifiedDatabaseObjectName(this.getCatalog(), this.getSchema(), this.getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/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 2f33b1fbbd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaColumnMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.resource.java.Annotation; -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; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationListIterator; - - -public abstract class AbstractJavaTypeMapping extends AbstractJavaJpaContextNode - implements JavaTypeMapping -{ - protected JavaResourcePersistentType javaResourcePersistentType; - - - protected AbstractJavaTypeMapping(JavaPersistentType parent) { - super(parent); - } - - @Override - public JavaPersistentType getParent() { - return (JavaPersistentType) super.getParent(); - } - - protected Annotation getResourceMappingAnnotation() { - return this.javaResourcePersistentType.getAnnotation(getAnnotationName()); - } - - //***************** TypeMapping impl *************************************** - - public JavaPersistentType getPersistentType() { - return getParent(); - } - - public String getPrimaryTableName() { - 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 ListIterator<JavaAttributeMapping> attributeMappings() { - return new TransformationListIterator<JavaPersistentAttribute, JavaAttributeMapping>(getPersistentType().attributes()) { - @Override - protected JavaAttributeMapping transform(JavaPersistentAttribute next) { - return next.getMapping(); - } - }; - } - - public Iterator<JavaColumnMapping> overridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<ColumnMapping> allOverridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAttributeNames() { - return this.namesOf(this.overridableAttributes()); - } - - public Iterator<String> allOverridableAttributeNames() { - return this.namesOf(this.allOverridableAttributes()); - } - - public Iterator<JavaRelationshipMapping> overridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAssociationNames() { - return this.namesOf(this.overridableAssociations()); - } - - public Iterator<RelationshipMapping> allOverridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAssociationNames() { - return this.namesOf(this.allOverridableAssociations()); - } - - protected Iterator<String> namesOf(Iterator<? extends AttributeMapping> attributeMappings) { - return new TransformationIterator<AttributeMapping, String>(attributeMappings) { - @Override - protected String transform(AttributeMapping attributeMapping) { - return attributeMapping.getName(); - } - }; - } - - - //******************** updating ********************* - public void initialize(JavaResourcePersistentType jrpt) { - this.javaResourcePersistentType = jrpt; - } - - public void update(JavaResourcePersistentType jrpt) { - this.javaResourcePersistentType = jrpt; - } - - //******************** validation ********************* - - public boolean shouldValidateAgainstDatabase() { - return getPersistenceUnit().shouldValidateAgainstDatabase(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getResourceMappingAnnotation().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getPersistentType().getValidationTextRange(astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getPersistentType().getName()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMappingDefinition.java deleted file mode 100644 index 65e6850206..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMappingDefinition.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.utility.internal.StringTools; - -public abstract class AbstractJavaTypeMappingDefinition - implements JavaTypeMappingDefinition -{ - protected AbstractJavaTypeMappingDefinition() { - super(); - } - - - /** - * Default implementation. Override if the mapping definition needs to do more analysis. - */ - public boolean test(JavaPersistentType persistentType) { - return persistentType.getResourcePersistentType().getAnnotation(getAnnotationName()) - != null; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getAnnotationName()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaVersionMapping.java deleted file mode 100644 index 6ce21c7315..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaVersionMapping.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.Converter; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaConverter; -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.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractJavaVersionMapping - extends AbstractJavaAttributeMapping<VersionAnnotation> - implements JavaVersionMapping -{ - protected final JavaColumn column; - - protected final JavaConverter defaultConverter; - - protected JavaConverter specifiedConverter; - - protected AbstractJavaVersionMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildJavaColumn(this, this); - this.defaultConverter = getJpaFactory().buildJavaNullConverter(this); - } - - @Override - protected void initialize( ) { - super.initialize(); - this.column.initialize(this.getResourceColumn()); - this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); - } - - public ColumnAnnotation getResourceColumn() { - return (ColumnAnnotation) getResourcePersistentAttribute(). - getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** JavaAttributeMapping implementation *************** - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return VersionAnnotation.ANNOTATION_NAME; - } - - - @Override - protected String[] buildSupportingAnnotationNames() { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.COLUMN, - JPA.TEMPORAL); - } - - //************** NamedColumn.Owner implementation *************** - - public String getDefaultColumnName() { - return getName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - //************** VersionMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - public JavaConverter getConverter() { - return getSpecifiedConverter() == null ? getDefaultConverter() : getSpecifiedConverter(); - } - - public JavaConverter getDefaultConverter() { - return this.defaultConverter; - } - - public JavaConverter getSpecifiedConverter() { - return this.specifiedConverter; - } - - protected String getSpecifedConverterType() { - if (this.specifiedConverter == null) { - return Converter.NO_CONVERTER; - } - return this.specifiedConverter.getType(); - } - - public void setSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(getSpecifedConverterType(), converterType)) { - return; - } - JavaConverter oldConverter = this.specifiedConverter; - JavaConverter newConverter = buildSpecifiedConverter(converterType); - this.specifiedConverter = null; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.specifiedConverter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setSpecifiedConverter(JavaConverter newConverter) { - JavaConverter oldConverter = this.specifiedConverter; - this.specifiedConverter = newConverter; - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - - @Override - protected void update() { - super.update(); - this.column.update(this.getResourceColumn()); - if (this.valuesAreEqual(getResourceConverterType(), getSpecifedConverterType())) { - getSpecifiedConverter().update(this.resourcePersistentAttribute); - } - else { - JavaConverter javaConverter = buildSpecifiedConverter(getResourceConverterType()); - setSpecifiedConverter(javaConverter); - } - } - - protected JavaConverter buildSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getJpaFactory().buildJavaTemporalConverter(this, this.resourcePersistentAttribute); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourcePersistentAttribute.getAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { - return Converter.TEMPORAL_CONVERTER; - } - return 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; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - //*********** Validation ****************************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.shouldValidateAgainstDatabase()) { - this.validateColumn(messages, astRoot); - } - if (this.specifiedConverter != null) { - this.specifiedConverter.validate(messages, reporter, astRoot); - } - } - - protected void validateColumn(List<IMessage> messages, CompilationUnit astRoot) { - String tableName = this.column.getTable(); - if (this.getTypeMapping().tableNameIsInvalid(tableName)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange(astRoot) - ) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.java deleted file mode 100644 index cca5eff2f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -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.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnInAssociationOverrideJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaJoinColumn.Owner; -import org.eclipse.jpt.core.internal.resource.java.NullJoinColumnAnnotation; -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; - -public class GenericJavaJoinColumnInAssociationOverrideJoiningStrategy - extends AbstractJavaJoinColumnJoiningStrategy - implements JavaJoinColumnInAssociationOverrideJoiningStrategy -{ - protected transient AssociationOverrideAnnotation associationOverrideAnnotation; - - public GenericJavaJoinColumnInAssociationOverrideJoiningStrategy(JavaAssociationOverrideRelationshipReference parent) { - super(parent); - } - - @Override - protected Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - public TypeMapping getTypeMapping() { - return getAssociationOverride().getOwner().getTypeMapping(); - } - - public boolean isOverridableAssociation() { - return false; - } - - protected JavaAssociationOverride getAssociationOverride() { - return this.getRelationshipReference().getAssociationOverride(); - } - - @Override - public JavaAssociationOverrideRelationshipReference getRelationshipReference() { - return (JavaAssociationOverrideRelationshipReference) super.getRelationshipReference(); - } - - @Override - protected ListIterator<JoinColumnAnnotation> joinColumnAnnotations() { - return this.associationOverrideAnnotation.joinColumns(); - } - - @Override - protected JoinColumnAnnotation buildNullJoinColumnAnnotation() { - return new NullJoinColumnAnnotation(this.associationOverrideAnnotation); - } - - @Override - protected JoinColumnAnnotation addAnnotation(int index) { - return this.associationOverrideAnnotation.addJoinColumn(index); - } - - @Override - protected void removeAnnotation(int index) { - this.associationOverrideAnnotation.removeJoinColumn(index); - } - - @Override - protected void moveAnnotation(int targetIndex, int sourceIndex) { - this.associationOverrideAnnotation.moveJoinColumn(targetIndex, sourceIndex); - } - - public void initialize(AssociationOverrideAnnotation associationOverride) { - this.associationOverrideAnnotation = associationOverride; - super.initialize(); - } - - public void update(AssociationOverrideAnnotation associationOverride) { - this.associationOverrideAnnotation = associationOverride; - super.update(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getRelationshipReference().getValidationTextRange(astRoot); - } - -// ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements JavaJoinColumn.Owner - { - - protected JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public Entity getTargetEntity() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipReference().getAssociationOverride().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipReference().getAssociationOverride().getOwner().getRelationshipMapping(GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipReference().getAssociationOverride().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) { - return GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipReference().getAssociationOverride().getOwner().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return false; - } - - public int joinColumnsSize() { - return GenericJavaJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipReference().getJoinColumnJoiningStrategy().joinColumnsSize(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java deleted file mode 100644 index 8ca8fb555c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.Entity; -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.JavaJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.internal.resource.java.NullJoinColumnAnnotation; -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.NestableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -public class GenericJavaJoinColumnJoiningStrategy - extends AbstractJavaJoinColumnJoiningStrategy -{ - - public GenericJavaJoinColumnJoiningStrategy(JavaJoinColumnEnabledRelationshipReference parent) { - super(parent); - } - - @Override - protected JavaJoinColumn.Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public boolean isOverridableAssociation() { - return true; - } - - @Override - public JavaJoinColumnEnabledRelationshipReference getRelationshipReference() { - return (JavaJoinColumnEnabledRelationshipReference) super.getRelationshipReference(); - } - - @Override - public JavaRelationshipMapping getRelationshipMapping() { - return getRelationshipReference().getRelationshipMapping(); - } - - protected JavaResourcePersistentAttribute getResourcePersistentAttribute() { - return getRelationshipMapping().getPersistentAttribute().getResourcePersistentAttribute(); - } - - @Override - protected Iterator<JoinColumnAnnotation> joinColumnAnnotations() { - return new TransformationIterator<NestableAnnotation, JoinColumnAnnotation>( - this.getResourcePersistentAttribute().annotations( - JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)) { - @Override - protected JoinColumnAnnotation transform(NestableAnnotation next) { - return (JoinColumnAnnotation) next; - } - }; - } - - @Override - protected JoinColumnAnnotation buildNullJoinColumnAnnotation() { - return new NullJoinColumnAnnotation(this.getResourcePersistentAttribute()); - } - - @Override - protected JoinColumnAnnotation addAnnotation(int index) { - return (JoinColumnAnnotation) this.getResourcePersistentAttribute(). - addAnnotation( - index, - JoinColumnAnnotation.ANNOTATION_NAME, - JoinColumnsAnnotation.ANNOTATION_NAME); - } - - @Override - protected void removeAnnotation(int index) { - this.getResourcePersistentAttribute(). - removeAnnotation( - index, - JoinColumnAnnotation.ANNOTATION_NAME, - JoinColumnsAnnotation.ANNOTATION_NAME); - } - - @Override - protected void moveAnnotation(int targetIndex, int sourceIndex) { - this.getResourcePersistentAttribute(). - moveAnnotation( - targetIndex, - sourceIndex, - JoinColumnsAnnotation.ANNOTATION_NAME); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getRelationshipReference().getValidationTextRange(astRoot); - } - protected class JoinColumnOwner - implements JavaJoinColumn.Owner -{ - protected JoinColumnOwner() { - super(); - } - - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public Entity getTargetEntity() { - return getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return getRelationshipMapping().getPersistentAttribute().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericJavaJoinColumnJoiningStrategy.this.getRelationshipMapping(); - } - - 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 getRelationshipMapping().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaJoinColumnJoiningStrategy.this.defaultJoinColumn == joinColumn; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaJoinColumnJoiningStrategy.this.getValidationTextRange(astRoot); - } - - public int joinColumnsSize() { - return GenericJavaJoinColumnJoiningStrategy.this.joinColumnsSize(); - } -} -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTableJoiningStrategy.java deleted file mode 100644 index 8cbca2c542..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTableJoiningStrategy.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.java.JavaJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaJoinTableJoiningStrategy - extends AbstractJavaJoinTableJoiningStrategy -{ - protected JavaResourcePersistentAttribute resourcePersistentAttribute; - - - public GenericJavaJoinTableJoiningStrategy(JavaJoinTableEnabledRelationshipReference parent) { - super(parent); - } - - public boolean isOverridableAssociation() { - return getJpaPlatformVariation().isJoinTableOverridable(); - } - - @Override - public JavaJoinTableEnabledRelationshipReference getParent() { - return (JavaJoinTableEnabledRelationshipReference) super.getParent(); - } - - @Override - public JavaJoinTableEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - @Override - public JavaRelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - - // **************** join table ********************************************* - - @Override - protected JoinTableAnnotation addAnnotation() { - return (JoinTableAnnotation) this.resourcePersistentAttribute. - addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - @Override - protected void removeAnnotation() { - this.resourcePersistentAttribute. - removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - - // **************** resource => context ************************************ - - @Override - public void initialize() { - this.resourcePersistentAttribute = - getRelationshipReference().getRelationshipMapping(). - getPersistentAttribute().getResourcePersistentAttribute(); - super.initialize(); - } - - @Override - public void update() { - this.resourcePersistentAttribute = - getRelationshipReference().getRelationshipMapping(). - getPersistentAttribute().getResourcePersistentAttribute(); - super.update(); - } - - public JoinTableAnnotation getAnnotation() { - return (JoinTableAnnotation) this.resourcePersistentAttribute. - getNonNullAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getRelationshipReference().getValidationTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyRelationshipReference.java deleted file mode 100644 index 5808c4beb4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyRelationshipReference.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaMappedByJoiningStrategy; -import org.eclipse.jpt.core.resource.java.OwnableRelationshipMappingAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaManyToManyRelationshipReference - extends AbstractJavaRelationshipReference - implements JavaManyToManyRelationshipReference -{ - protected final JavaMappedByJoiningStrategy mappedByJoiningStrategy; - - protected final JavaJoinTableJoiningStrategy joinTableJoiningStrategy; - - - public GenericJavaManyToManyRelationshipReference(JavaManyToManyMapping parent) { - super(parent); - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - } - - - protected JavaMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericJavaMappedByJoiningStrategy(this); - } - - protected JavaJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new GenericJavaJoinTableJoiningStrategy(this); - } - - @Override - public JavaManyToManyMapping getRelationshipMapping() { - return (JavaManyToManyMapping) getParent(); - } - - public OwnableRelationshipMappingAnnotation getMappingAnnotation() { - return getRelationshipMapping().getMappingAnnotation(); - } - - public boolean isRelationshipOwner() { - return this.getMappedByJoiningStrategy().getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - else { - return this.joinTableJoiningStrategy; - } - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result == null) { - result = this.mappedByJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - } - if (result == null) { - result = this.joinTableJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - } - return result; - } - - - // **************** mapped by ********************************************** - - public JavaMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - } - - public boolean usesMappedByJoiningStrategy() { - return getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join table joining strategy *************************** - - public JavaJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public void setJoinTableJoiningStrategy() { - // join table is default option, so no need to add to resource - this.mappedByJoiningStrategy.removeStrategy(); - } - - public void unsetJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return getMappedByJoiningStrategy().getMappedByAttribute() == null; - } - - - // **************** resource => context ************************************ - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy.initialize(); - this.joinTableJoiningStrategy.initialize(); - } - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - this.joinTableJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.mappedByJoiningStrategy.validate(messages, reporter, astRoot); - this.joinTableJoiningStrategy.validate(messages, reporter, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneRelationshipReference.java deleted file mode 100644 index bfa5d4fa87..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneRelationshipReference.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneRelationshipReference; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaManyToOneRelationshipReference - extends AbstractJavaRelationshipReference - implements JavaManyToOneRelationshipReference -{ - protected final JavaJoinColumnJoiningStrategy joinColumnJoiningStrategy; - - - public GenericJavaManyToOneRelationshipReference(JavaManyToOneMapping parent) { - super(parent); - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - } - - - protected JavaJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { - return new GenericJavaJoinColumnJoiningStrategy(this); - } - - @Override - public JavaManyToOneMapping getRelationshipMapping() { - return (JavaManyToOneMapping) getParent(); - } - - public boolean isRelationshipOwner() { - return true; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return false; - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - // the only joining strategy - return this.joinColumnJoiningStrategy; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result == null) { - result = this.joinColumnJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - } - return result; - } - - - // **************** join columns ******************************************* - - public JavaJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - // join columns are default (and only, so far) strategy, so no need - // to add to resource model - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return true; - } - - - // **************** resource => context ************************************ - - @Override - protected void initializeJoiningStrategies() { - // initialize join column strategy last, as the existence of a default - // join column is dependent on the other mechanisms (join table) not - // being specified - this.joinColumnJoiningStrategy.initialize(); - } - - @Override - protected void updateJoiningStrategies() { - // update join column strategy last, as the existence of a default join - // column is dependent on the other mechanisms (join table) not being - // specified - this.joinColumnJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.joinColumnJoiningStrategy.validate(messages, reporter, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java deleted file mode 100644 index ab287b795e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedByJoiningStrategy.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaOwnableRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.OwnableRelationshipMappingAnnotation; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaMappedByJoiningStrategy - extends AbstractJavaJpaContextNode - implements JavaMappedByJoiningStrategy -{ - protected OwnableRelationshipMappingAnnotation mappingAnnotation; - - protected String mappedByAttribute; - - - public GenericJavaMappedByJoiningStrategy(JavaOwnableRelationshipReference parent) { - super(parent); - } - - - @Override - public JavaOwnableRelationshipReference getParent() { - return (JavaOwnableRelationshipReference) super.getParent(); - } - - public JavaOwnableRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public JavaRelationshipMapping getRelationshipMapping() { - return getParent().getRelationshipMapping(); - } - - public boolean isOverridableAssociation() { - return false; - } - - public boolean relationshipIsOwnedBy(RelationshipMapping otherMapping) { - String thisEntity = - (getRelationshipReference().getEntity()) == null ? - null : getRelationshipReference().getEntity().getName(); - String targetEntity = - (getRelationshipMapping().getResolvedTargetEntity() == null) ? - null : getRelationshipMapping().getResolvedTargetEntity().getName(); - return StringTools.stringsAreEqual( - thisEntity, - targetEntity) - && StringTools.stringsAreEqual( - getMappedByAttribute(), - otherMapping.getName()); - } - - public String getMappedByAttribute() { - return this.mappedByAttribute; - } - - public void setMappedByAttribute(String newMappedByAttribute) { - String oldMappedByAttribute = this.mappedByAttribute; - this.mappedByAttribute = newMappedByAttribute; - this.mappingAnnotation.setMappedBy(newMappedByAttribute); - firePropertyChanged(MAPPED_BY_ATTRIBUTE_PROPERTY, oldMappedByAttribute, newMappedByAttribute); - } - - protected void setMappedByAttribute_(String newMappedByAttribute) { - String oldMappedByAttribute = this.mappedByAttribute; - this.mappedByAttribute = newMappedByAttribute; - firePropertyChanged(MAPPED_BY_ATTRIBUTE_PROPERTY, oldMappedByAttribute, newMappedByAttribute); - } - - public void addStrategy() { - if (this.mappedByAttribute == null) { - setMappedByAttribute(""); - } - } - - public void removeStrategy() { - if (this.mappedByAttribute != null) { - setMappedByAttribute(null); - } - } - - public void initialize() { - this.mappingAnnotation = this.getRelationshipReference().getMappingAnnotation(); - this.mappedByAttribute = this.mappingAnnotation.getMappedBy(); - } - - public void update() { - this.mappingAnnotation = this.getRelationshipReference().getMappingAnnotation(); - setMappedByAttribute_(this.mappingAnnotation.getMappedBy()); - } - - @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.mappingAnnotation.mappedByTouches(pos, astRoot)) { - result = javaCandidateMappedByAttributeNames(filter); - } - return result; - } - - public Iterator<String> candidateMappedByAttributeNames() { - return getRelationshipMapping().allTargetEntityAttributeNames(); - } - - public Iterator<String> candidateMappedByAttributeNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateMappedByAttributeNames(), filter); - } - - protected Iterator<String> javaCandidateMappedByAttributeNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateMappedByAttributeNames(filter)); - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - - if (getMappedByAttribute() == null) { - return; - } - - Entity targetEntity = this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return; // null target entity is validated elsewhere - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(this.mappedByAttribute); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {this.mappedByAttribute}, - this, - this.getValidationTextRange(astRoot) - ) - ); - return; - } - - AttributeMapping mappedByMapping = attribute.getMapping(); - if ( ! this.getRelationshipReference().mayBeMappedBy(mappedByMapping)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {this.mappedByAttribute}, - this, - this.getValidationTextRange(astRoot) - ) - ); - return; - } - - // if mappedByMapping is not a relationship owner, then it should have - // been flagged in above rule (mappedByIsValid) - if (! ((RelationshipMapping) mappedByMapping).isRelationshipOwner()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, - this.getValidationTextRange(astRoot) - ) - ); - } - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.mappingAnnotation.getMappedByTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneRelationshipReference.java deleted file mode 100644 index 8df83efda7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneRelationshipReference.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaOneToOneRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.resource.java.OwnableRelationshipMappingAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaOneToOneRelationshipReference - extends AbstractJavaRelationshipReference - implements JavaOneToOneRelationshipReference -{ - protected final JavaMappedByJoiningStrategy mappedByJoiningStrategy; - - protected final JavaJoinColumnJoiningStrategy joinColumnJoiningStrategy; - - protected final JavaPrimaryKeyJoinColumnJoiningStrategy primaryKeyJoinColumnJoiningStrategy; - - - public GenericJavaOneToOneRelationshipReference(JavaOneToOneMapping parent) { - super(parent); - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - this.primaryKeyJoinColumnJoiningStrategy = buildPrimaryKeyJoinColumnJoiningStrategy(); - } - - - protected JavaMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericJavaMappedByJoiningStrategy(this); - } - - protected JavaJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { - return new GenericJavaJoinColumnJoiningStrategy(this); - } - - protected JavaPrimaryKeyJoinColumnJoiningStrategy buildPrimaryKeyJoinColumnJoiningStrategy() { - return new GenericJavaPrimaryKeyJoinColumnJoiningStrategy(this); - } - - @Override - public JavaOneToOneMapping getRelationshipMapping() { - return (JavaOneToOneMapping) getParent(); - } - - public OwnableRelationshipMappingAnnotation getMappingAnnotation() { - return getRelationshipMapping().getMappingAnnotation(); - } - - public boolean isRelationshipOwner() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - else if (this.primaryKeyJoinColumnJoiningStrategy.primaryKeyJoinColumnsSize() > 0) { - return this.primaryKeyJoinColumnJoiningStrategy; - } - else { - return this.joinColumnJoiningStrategy; - } - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result == null) { - result = this.mappedByJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - } - if (result == null) { - result = this.joinColumnJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - } - return result; - } - - - // **************** mapped by ********************************************** - - public JavaMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public boolean usesMappedByJoiningStrategy() { - return getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join columns ******************************************* - - public JavaJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - // join columns are default, so no need to add annotations - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return this.getMappedByJoiningStrategy().getMappedByAttribute() == null - && this.getPrimaryKeyJoinColumnJoiningStrategy().primaryKeyJoinColumnsSize() == 0; - } - - - // **************** primary key join columns ******************************* - - public JavaPrimaryKeyJoinColumnJoiningStrategy getPrimaryKeyJoinColumnJoiningStrategy() { - return this.primaryKeyJoinColumnJoiningStrategy; - } - - public boolean usesPrimaryKeyJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.primaryKeyJoinColumnJoiningStrategy; - } - - public void setPrimaryKeyJoinColumnJoiningStrategy() { - this.primaryKeyJoinColumnJoiningStrategy.addStrategy(); - this.mappedByJoiningStrategy.removeStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public void unsetPrimaryKeyJoinColumnJoiningStrategy() { - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultPrimaryKeyJoinColumn() { - return false; - } - - - // **************** resource => context ************************************ - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy.initialize(); - this.primaryKeyJoinColumnJoiningStrategy.initialize(); - - // initialize join columns last, as the existence of a default join - // column is dependent on the other mechanisms (mappedBy, join table) - // not being specified - this.joinColumnJoiningStrategy.initialize(); - } - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - this.primaryKeyJoinColumnJoiningStrategy.update(); - - // update join columns last, as the existence of a default join - // column is dependent on the other mechanisms (mappedBy, join table) - // not being specified - this.joinColumnJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.mappedByJoiningStrategy.validate(messages, reporter, astRoot); - this.primaryKeyJoinColumnJoiningStrategy.validate(messages, reporter, astRoot); - this.joinColumnJoiningStrategy.validate(messages, reporter, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnJoiningStrategy.java deleted file mode 100644 index cb7fa70263..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; -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.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -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; - -public class GenericJavaPrimaryKeyJoinColumnJoiningStrategy - extends AbstractJavaJpaContextNode - implements JavaPrimaryKeyJoinColumnJoiningStrategy -{ - protected JavaResourcePersistentAttribute resourcePersistentAttribute; - - protected final Vector<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = new Vector<JavaPrimaryKeyJoinColumn>(); - protected final JavaJoinColumn.Owner joinColumnOwner; - - - public GenericJavaPrimaryKeyJoinColumnJoiningStrategy( - JavaPrimaryKeyJoinColumnEnabledRelationshipReference parent) { - super(parent); - this.joinColumnOwner = this.buildJoinColumnOwner(); - } - - protected JavaJoinColumn.Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - @Override - public JavaPrimaryKeyJoinColumnEnabledRelationshipReference getParent() { - return (JavaPrimaryKeyJoinColumnEnabledRelationshipReference) super.getParent(); - } - - public JavaPrimaryKeyJoinColumnEnabledRelationshipReference getRelationshipReference() { - return getParent(); - } - - public JavaRelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public boolean isOverridableAssociation() { - return false; - } - - // **************** primary key join columns ******************************* - - public ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return new CloneListIterator<JavaPrimaryKeyJoinColumn>(this.primaryKeyJoinColumns); - } - - public int primaryKeyJoinColumnsSize() { - return this.primaryKeyJoinColumns.size(); - } - - public boolean hasPrimaryKeyJoinColumns() { - return ! this.primaryKeyJoinColumns.isEmpty(); - } - - public JavaPrimaryKeyJoinColumn addPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn pkJoinColumn = - getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, this.joinColumnOwner); - this.primaryKeyJoinColumns.add(index, pkJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnAnnotation = addAnnotation(index); - pkJoinColumn.initialize(pkJoinColumnAnnotation); - fireItemAdded(PRIMARY_KEY_JOIN_COLUMNS_LIST, index, pkJoinColumn); - return pkJoinColumn; - } - - protected void addPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.primaryKeyJoinColumns, PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn joinColumn) { - addPrimaryKeyJoinColumn(this.primaryKeyJoinColumns.size(), joinColumn); - } - - public void removePrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - removePrimaryKeyJoinColumn(this.primaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removePrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn pkJoinColumn = this.primaryKeyJoinColumns.remove(index); - removeAnnotation(index); - fireItemRemoved(PRIMARY_KEY_JOIN_COLUMNS_LIST, index, pkJoinColumn); - } - - protected void removePrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.primaryKeyJoinColumns, PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void movePrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.primaryKeyJoinColumns, targetIndex, sourceIndex); - moveAnnotation(targetIndex, sourceIndex); - fireItemMoved(PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected PrimaryKeyJoinColumnAnnotation addAnnotation(int index) { - return (PrimaryKeyJoinColumnAnnotation) this.resourcePersistentAttribute. - addAnnotation( - index, - PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - } - - protected void removeAnnotation(int index) { - this.resourcePersistentAttribute. - removeAnnotation( - index, - PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - } - - protected void moveAnnotation(int targetIndex, int sourceIndex) { - this.resourcePersistentAttribute. - moveAnnotation( - targetIndex, - sourceIndex, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - } - - public void addStrategy() { - if (primaryKeyJoinColumnsSize() == 0) { - addPrimaryKeyJoinColumn(0); - } - } - - public void removeStrategy() { - for (PrimaryKeyJoinColumn each : CollectionTools.iterable(primaryKeyJoinColumns())) { - removePrimaryKeyJoinColumn(each); - } - } - - - // **************** resource -> context ************************************ - - public void initialize() { - this.resourcePersistentAttribute = - getRelationshipReference().getRelationshipMapping(). - getPersistentAttribute().getResourcePersistentAttribute(); - initializePrimaryKeyJoinColumns(); - } - - protected void initializePrimaryKeyJoinColumns() { - Iterator<NestableAnnotation> annotations = - this.resourcePersistentAttribute.annotations( - PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - while (annotations.hasNext()) { - this.primaryKeyJoinColumns.add( - buildPrimaryKeyJoinColumn( - (PrimaryKeyJoinColumnAnnotation) annotations.next())); - } - } - - public void update() { - this.resourcePersistentAttribute = - getRelationshipReference().getRelationshipMapping(). - getPersistentAttribute().getResourcePersistentAttribute(); - updatePrimaryKeyJoinColumns(); - } - - protected void updatePrimaryKeyJoinColumns() { - ListIterator<JavaPrimaryKeyJoinColumn> joinColumns = primaryKeyJoinColumns(); - Iterator<NestableAnnotation> annotations = - this.resourcePersistentAttribute.annotations( - PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, - PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - while (joinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn joinColumn = joinColumns.next(); - if (annotations.hasNext()) { - joinColumn.update( - (PrimaryKeyJoinColumnAnnotation) annotations.next()); - } - else { - removePrimaryKeyJoinColumn_(joinColumn); - } - } - - while (annotations.hasNext()) { - addPrimaryKeyJoinColumn( - buildPrimaryKeyJoinColumn( - (PrimaryKeyJoinColumnAnnotation) annotations.next())); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn( - PrimaryKeyJoinColumnAnnotation annotation) { - JavaPrimaryKeyJoinColumn joinColumn = - getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, this.joinColumnOwner); - joinColumn.initialize(annotation); - return joinColumn; - } - - - // **************** Java completion proposals ****************************** - - @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; - } - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getRelationshipReference().getValidationTextRange(astRoot); - } - - - // ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements JavaJoinColumn.Owner - { - protected JoinColumnOwner() { - super(); - } - - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public Entity getTargetEntity() { - return getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return getRelationshipMapping().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericJavaPrimaryKeyJoinColumnJoiningStrategy.this.getRelationshipMapping(); - } - - 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 getRelationshipMapping().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return false; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaPrimaryKeyJoinColumnJoiningStrategy.this.getValidationTextRange(astRoot); - } - - public int joinColumnsSize() { - return GenericJavaPrimaryKeyJoinColumnJoiningStrategy.this.primaryKeyJoinColumnsSize(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingDefinition.java deleted file mode 100644 index a530ad632a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingDefinition.java +++ /dev/null @@ -1,59 +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.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; - -public class JavaBasicMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaBasicMappingDefinition INSTANCE = - new JavaBasicMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaBasicMappingDefinition() { - 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); - } - - @Override - public boolean testDefault(JavaPersistentAttribute persistentAttribute) { - return persistentAttribute.typeIsBasic(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableDefinition.java deleted file mode 100644 index 2a94eab3b8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableDefinition.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; - -public class JavaEmbeddableDefinition - extends AbstractJavaTypeMappingDefinition -{ - // singleton - private static final JavaEmbeddableDefinition INSTANCE = - new JavaEmbeddableDefinition(); - - - /** - * Return the singleton - */ - public static JavaTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaEmbeddableDefinition() { - 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/JavaEmbeddedIdMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingDefinition.java deleted file mode 100644 index fe78cadb6a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingDefinition.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; - -public class JavaEmbeddedIdMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaEmbeddedIdMappingDefinition INSTANCE = - new JavaEmbeddedIdMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singletong usage - */ - private JavaEmbeddedIdMappingDefinition() { - 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); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingDefinition.java deleted file mode 100644 index 5910a5327e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingDefinition.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; - -public class JavaEmbeddedMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaEmbeddedMappingDefinition INSTANCE = - new JavaEmbeddedMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaEmbeddedMappingDefinition() { - 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); - } - - @Override - public boolean testDefault(JavaPersistentAttribute persistentAttribute) { - return persistentAttribute.getEmbeddable() != null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityDefinition.java deleted file mode 100644 index 58df102ce8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityDefinition.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; - -public class JavaEntityDefinition - extends AbstractJavaTypeMappingDefinition -{ - // singleton - private static final JavaEntityDefinition INSTANCE = - new JavaEntityDefinition(); - - - /** - * Return the singleton - */ - public static JavaTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaEntityDefinition() { - 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/JavaIdMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingDefinition.java deleted file mode 100644 index 27f6bbe4eb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingDefinition.java +++ /dev/null @@ -1,36 +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.context.java.JavaAttributeMappingDefinition; - -public class JavaIdMappingDefinition - extends AbstractJavaIdMappingDefinition -{ - // singleton - private static final JavaIdMappingDefinition INSTANCE = - new JavaIdMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaIdMappingDefinition() { - super(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingDefinition.java deleted file mode 100644 index aec9281f56..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingDefinition.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.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; - -public class JavaManyToManyMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaManyToManyMappingDefinition INSTANCE = - new JavaManyToManyMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaManyToManyMappingDefinition() { - 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/JavaManyToOneMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingDefinition.java deleted file mode 100644 index 905cf786e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingDefinition.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.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; - -public class JavaManyToOneMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaManyToOneMappingDefinition INSTANCE = - new JavaManyToOneMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaManyToOneMappingDefinition() { - 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/JavaMappedSuperclassDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassDefinition.java deleted file mode 100644 index d14c61cb57..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassDefinition.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; - -public class JavaMappedSuperclassDefinition - extends AbstractJavaTypeMappingDefinition -{ - // singleton - private static final JavaMappedSuperclassDefinition INSTANCE = - new JavaMappedSuperclassDefinition(); - - - /** - * Return the singleton - */ - public static JavaTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaMappedSuperclassDefinition() { - 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/JavaNullTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java deleted file mode 100644 index fefecbf43f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -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> supportingAnnotationNames() { - return EmptyIterator.instance(); - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return false; - } - - /** - * We added this message here because the most likely solution is to add - * an annotation to the .java file. - * This message used to be found on the <class> tag in persistence.xml. - * The other possible way to fix the error is to remove it from persistence.xml. - * This can be accomplished with the Synchronize Classes action. - * We could also add a quick fix for this error. - */ - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - 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/JavaOneToManyMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingDefinition.java deleted file mode 100644 index 63a93ae3c1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingDefinition.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.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; - -public class JavaOneToManyMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaOneToManyMappingDefinition INSTANCE = - new JavaOneToManyMappingDefinition(); - - - /** - * Return the singleton - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaOneToManyMappingDefinition() { - 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/JavaOneToOneMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingDefinition.java deleted file mode 100644 index b90bdc2787..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingDefinition.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.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; - -public class JavaOneToOneMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaOneToOneMappingDefinition INSTANCE = - new JavaOneToOneMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaOneToOneMappingDefinition() { - 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/JavaTransientMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingDefinition.java deleted file mode 100644 index 18a68cc456..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingDefinition.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.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; - -public class JavaTransientMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaTransientMappingDefinition INSTANCE = - new JavaTransientMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaTransientMappingDefinition() { - 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/JavaVersionMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingDefinition.java deleted file mode 100644 index 6442ac664d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingDefinition.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.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; - -public class JavaVersionMappingDefinition - extends AbstractJavaAttributeMappingDefinition -{ - // singleton - private static final JavaVersionMappingDefinition INSTANCE = - new JavaVersionMappingDefinition(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaVersionMappingDefinition() { - 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/VirtualAssociationOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideAnnotation.java deleted file mode 100644 index 827b7b1980..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideAnnotation.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * javax.persistence.AssociationOverride - */ -public abstract class VirtualAssociationOverrideAnnotation - extends VirtualOverrideAnnotation - implements AssociationOverrideAnnotation -{ - protected JoiningStrategy joiningStrategy; - - private final Vector<JoinColumnAnnotation> joinColumns; - - protected VirtualAssociationOverrideAnnotation(JavaResourcePersistentMember parent, String name, JoiningStrategy joiningStrategy) { - super(parent, name); - this.joiningStrategy = joiningStrategy; - this.joinColumns = this.buildJoinColumns(); - } - - protected Vector<JoinColumnAnnotation> buildJoinColumns() { - if (this.joiningStrategy instanceof JoinColumnJoiningStrategy) { - Vector<JoinColumnAnnotation> result = new Vector<JoinColumnAnnotation>(((JoinColumnJoiningStrategy) this.joiningStrategy).joinColumnsSize()); - for (JoinColumn joinColumn : CollectionTools.iterable(((JoinColumnJoiningStrategy) this.joiningStrategy).joinColumns())) { - result.add(new VirtualAssociationOverrideJoinColumnAnnotation(this, joinColumn)); - } - return result; - } - return new Vector<JoinColumnAnnotation>(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected AssociationOverrideAnnotation addAnnotation() { - return (AssociationOverrideAnnotation) super.addAnnotation(); - } - - // ***** join columns - public ListIterator<JoinColumnAnnotation> joinColumns() { - return this.joinColumns.listIterator(); - } - - public JoinColumnAnnotation joinColumnAt(int index) { - return this.joinColumns.elementAt(index); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - public JoinColumnAnnotation addJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public void removeJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - //Rebuilt every time so no need to implement update() - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideJoinColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideJoinColumnAnnotation.java deleted file mode 100644 index b782216bfb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideJoinColumnAnnotation.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.internal.resource.java.NullBaseColumnAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Column - */ -public final class VirtualAssociationOverrideJoinColumnAnnotation extends NullBaseColumnAnnotation - implements JoinColumnAnnotation -{ - private JoinColumn joinColumn; - - public VirtualAssociationOverrideJoinColumnAnnotation(Annotation parent, JoinColumn joinColumn) { - super(parent); - this.joinColumn = joinColumn; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected JoinColumnAnnotation addAnnotation() { - throw new UnsupportedOperationException(); - } - - @Override - public String getName() { - return this.joinColumn.getSpecifiedName(); - } - - @Override - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - public String getReferencedColumnName() { - return this.joinColumn.getSpecifiedReferencedColumnName(); - } - - public void setReferencedColumnName(String referencedColumnName) { - throw new UnsupportedOperationException(); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return false; - } - - @Override - public String getColumnDefinition() { - return this.joinColumn.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String columnDefinition) { - throw new UnsupportedOperationException(); - } - - @Override - public String getTable() { - return this.joinColumn.getSpecifiedTable(); - } - - @Override - public void setTable(String table) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean getInsertable() { - return this.joinColumn.getSpecifiedInsertable(); - } - - @Override - public void setInsertable(Boolean insertable) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean getUpdatable() { - return this.joinColumn.getSpecifiedUpdatable(); - } - - @Override - public void setUpdatable(Boolean updatable) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean getNullable() { - return this.joinColumn.getSpecifiedNullable(); - } - - @Override - public void setNullable(Boolean nullable) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean getUnique() { - return this.joinColumn.getSpecifiedUnique(); - } - - @Override - public void setUnique(Boolean unique) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideAnnotation.java deleted file mode 100644 index 25e71fa18e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideAnnotation.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; - -/** - * javax.persistence.AssociationOverride - */ -public class VirtualAttributeOverrideAnnotation - extends VirtualOverrideAnnotation - implements AttributeOverrideAnnotation -{ - private final VirtualAttributeOverrideColumnAnnotation column; - - - public VirtualAttributeOverrideAnnotation(JavaResourcePersistentMember parent, String name, Column column) { - super(parent, name); - this.column = new VirtualAttributeOverrideColumnAnnotation(this, column); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected AttributeOverrideAnnotation addAnnotation() { - return (AttributeOverrideAnnotation) super.addAnnotation(); - } - - // ****** column - public ColumnAnnotation getColumn() { - return this.column; - } - - public ColumnAnnotation getNonNullColumn() { - return this.getColumn(); - } - - public ColumnAnnotation addColumn() { - throw new UnsupportedOperationException(); - } - - public void removeColumn() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumnAnnotation.java deleted file mode 100644 index 89ebcab07c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumnAnnotation.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.internal.resource.java.NullAttributeOverrideColumnAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; - -/** - * javax.persistence.Column - */ -public class VirtualAttributeOverrideColumnAnnotation - extends NullAttributeOverrideColumnAnnotation -{ - private Column column; - - public VirtualAttributeOverrideColumnAnnotation(AttributeOverrideAnnotation parent, Column column) { - super(parent); - this.column = column; - } - - @Override - public String getName() { - return this.column.getSpecifiedName(); - } - - @Override - public String getColumnDefinition() { - return this.column.getColumnDefinition(); - } - - @Override - public String getTable() { - return this.column.getSpecifiedTable(); - } - - @Override - public Boolean getInsertable() { - return this.column.getSpecifiedInsertable(); - } - - @Override - public Boolean getUpdatable() { - return this.column.getSpecifiedUpdatable(); - } - - @Override - public Boolean getNullable() { - return this.column.getSpecifiedNullable(); - } - - @Override - public Boolean getUnique() { - return this.column.getSpecifiedUnique(); - } - - @Override - public Integer getLength() { - return this.column.getSpecifiedLength(); - } - - @Override - public Integer getScale() { - return this.column.getSpecifiedScale(); - } - - @Override - public Integer getPrecision() { - return this.column.getSpecifiedPrecision(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualOverrideAnnotation.java deleted file mode 100644 index 01f16152ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualOverrideAnnotation.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.NullAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.OverrideAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * Common behavior for virtual versions of - * javax.persistence.AttributeOverride - * and - * javax.persistence.AssociationOverride - */ -public abstract class VirtualOverrideAnnotation - extends NullAnnotation - implements OverrideAnnotation -{ - private final String name; - - public VirtualOverrideAnnotation(JavaResourcePersistentMember parent, String name) { - super(parent); - this.name = name; - } - - @Override - protected OverrideAnnotation addAnnotation() { - return (OverrideAnnotation) super.addAnnotation(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (name != null) { - this.addAnnotation().setName(name); - } - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return false; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java deleted file mode 100644 index dcc281d5c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java +++ /dev/null @@ -1,787 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.MappingFileRoot; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryContainer; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractEntityMappings - extends AbstractOrmXmlContextNode - implements EntityMappings -{ - protected final XmlEntityMappings xmlEntityMappings; - - protected String description; - - protected String package_; - - protected AccessType specifiedAccess; - protected AccessType defaultAccess; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - protected /*final*/ PersistenceUnitMetadata persistenceUnitMetadata; - - protected final List<OrmPersistentType> persistentTypes; - - protected final List<OrmSequenceGenerator> sequenceGenerators; - - protected final List<OrmTableGenerator> tableGenerators; - - protected final OrmQueryContainer queryContainer; - - - protected AbstractEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.xmlEntityMappings = xmlEntityMappings; - this.persistentTypes = new ArrayList<OrmPersistentType>(); - this.sequenceGenerators = new ArrayList<OrmSequenceGenerator>(); - this.tableGenerators = new ArrayList<OrmTableGenerator>(); - this.queryContainer = getXmlContextNodeFactory().buildOrmQueryContainer(this, xmlEntityMappings); - - this.persistenceUnitMetadata = buildPersistenceUnitMetadata(); - this.description = this.xmlEntityMappings.getDescription(); - this.package_ = this.xmlEntityMappings.getPackage(); - - this.defaultAccess = this.getPersistenceUnit().getDefaultAccess(); - this.specifiedAccess = this.getResourceAccess(); - - this.defaultCatalog = this.getPersistenceUnit().getDefaultCatalog(); - this.specifiedCatalog = this.xmlEntityMappings.getCatalog(); - - this.defaultSchema = this.getPersistenceUnit().getDefaultSchema(); - this.specifiedSchema = this.xmlEntityMappings.getSchema(); - - this.initializePersistentTypes(); - this.initializeTableGenerators(); - this.initializeSequenceGenerators(); - } - - protected PersistenceUnitMetadata buildPersistenceUnitMetadata() { - return getXmlContextNodeFactory().buildPersistenceUnitMetadata(this, this.xmlEntityMappings); - } - - protected OrmPersistentType buildPersistentType(XmlTypeMapping resourceMapping) { - return getXmlContextNodeFactory().buildOrmPersistentType(this, resourceMapping); - } - - // **************** JpaNode impl ******************************************* - - @Override - public OrmXml getParent() { - return (OrmXml) super.getParent(); - } - - protected OrmXml getOrmXml() { - return this.getParent(); - } - - - // **************** JpaContextNode impl ************************************ - - @Override - public MappingFileRoot getMappingFileRoot() { - return this; - } - - - // **************** JpaStructureNode impl ********************************** - - public String getId() { - return OrmStructureNodes.ENTITY_MAPPINGS_ID; - } - - - // ********** PersistentType.Owner implementation ********** - - public AccessType getOverridePersistentTypeAccess() { - return this.isXmlMappingMetadataComplete() ? this.getSpecifiedAccess() : null; - } - - public AccessType getDefaultPersistentTypeAccess() { - return getAccess(); - } - - public String getDefaultPersistentTypePackage() { - return getPackage(); - } - - protected boolean isXmlMappingMetadataComplete() { - return this.getPersistenceUnitMetadata().isXmlMappingMetadataComplete(); - } - - public boolean isDefaultPersistentTypeMetadataComplete() { - return this.isXmlMappingMetadataComplete(); - } - - - // **************** EntityMappings impl ************************************ - - public XmlEntityMappings getXmlEntityMappings() { - return this.xmlEntityMappings; - } - - public void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping) { - AccessType savedAccess = ormPersistentType.getSpecifiedAccess(); - ormPersistentType.dispose(); - int sourceIndex = this.persistentTypes.indexOf(ormPersistentType); - this.persistentTypes.remove(sourceIndex); - oldMapping.removeFromResourceModel(this.xmlEntityMappings); - int targetIndex = insertionIndex(ormPersistentType); - this.persistentTypes.add(targetIndex, ormPersistentType); - newMapping.addToResourceModel(this.xmlEntityMappings); - - newMapping.initializeFrom(oldMapping); - //not sure where else to put this, need to set the access on the resource model - ormPersistentType.setSpecifiedAccess(savedAccess); - fireItemMoved(PERSISTENT_TYPES_LIST, targetIndex, sourceIndex); - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - if (ormPersistentType.isFor(fullyQualifiedTypeName)) { - return ormPersistentType; - } - } - return null; - } - - public PersistenceUnitMetadata getPersistenceUnitMetadata() { - return this.persistenceUnitMetadata; - } - - public String getPackage() { - return this.package_; - } - - public void setPackage(String newPackage) { - String oldPackage = this.package_; - this.package_ = newPackage; - this.xmlEntityMappings.setPackage(newPackage); - firePropertyChanged(PACKAGE_PROPERTY, oldPackage, newPackage); - } - - public String getVersion() { - return this.xmlEntityMappings.getVersion(); - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String newDescription) { - String oldDescription = this.description; - this.description = newDescription; - this.xmlEntityMappings.setDescription(newDescription); - firePropertyChanged(DESCRIPTION_PROPERTY, oldDescription, newDescription); - } - - - // ********** access ********** - - public AccessType getAccess() { - return (this.specifiedAccess != null) ? this.specifiedAccess : this.defaultAccess; - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - public void setSpecifiedAccess(AccessType access) { - AccessType old = this.specifiedAccess; - this.specifiedAccess = access; - this.xmlEntityMappings.setAccess(AccessType.toOrmResourceModel(access)); - this.firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, old, access); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType access) { - AccessType old = this.defaultAccess; - this.defaultAccess = access; - this.firePropertyChanged(DEFAULT_ACCESS_PROPERTY, old, access); - } - - - // ********** schema ********** - - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.xmlEntityMappings.setSchema(schema); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - - // ********** catalog ********** - - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.xmlEntityMappings.setCatalog(catalog); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - this.firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - - // ********** schema container ********** - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - - // ********** ORM persistent types ********** - - public ListIterator<OrmPersistentType> persistentTypes() { - return new CloneListIterator<OrmPersistentType>(this.persistentTypes); - } - - protected Iterable<OrmPersistentType> getPersistentTypes() { - return new LiveCloneIterable<OrmPersistentType>(this.persistentTypes); - } - - public int persistentTypesSize() { - return this.persistentTypes.size(); - } - - public OrmPersistentType addPersistentType(String mappingKey, String className) { - OrmTypeMappingDefinition mappingDefinition = - getMappingFileDefinition().getOrmTypeMappingDefinition(mappingKey); - XmlTypeMapping typeMapping = - mappingDefinition.buildResourceMapping(getResourceNodeFactory()); - OrmPersistentType persistentType = buildPersistentType(typeMapping); - int index = insertionIndex(persistentType); - this.persistentTypes.add(index, persistentType); - if (className.startsWith(getPackage() + '.')) { - // adds short name if package name is specified - className = className.substring(getPackage().length() + 1); - } - persistentType.getMapping().addToResourceModel(this.xmlEntityMappings); - typeMapping.setClassName(className); - fireItemAdded(PERSISTENT_TYPES_LIST, index, persistentType); - return persistentType; - } - - protected int insertionIndex(OrmPersistentType ormPersistentType) { - return CollectionTools.insertionIndexOf( - this.persistentTypes, ormPersistentType, 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 removePersistentType(int index) { - OrmPersistentType persistentType = this.persistentTypes.get(index); - persistentType.dispose(); - this.persistentTypes.remove(index); - persistentType.getMapping().removeFromResourceModel(this.xmlEntityMappings); - fireItemRemoved(PERSISTENT_TYPES_LIST, index, persistentType); - } - - public void removePersistentType(OrmPersistentType persistentType) { - removePersistentType(this.persistentTypes.indexOf(persistentType)); - } - - protected void removePersistentType_(OrmPersistentType persistentType) { - persistentType.dispose(); - removeItemFromList(persistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - protected void movePersistentType_(int index, OrmPersistentType persistentType) { - moveItemInList(index, this.persistentTypes.indexOf(persistentType), this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - - // ********** sequence generators ********** - - public ListIterator<OrmSequenceGenerator> sequenceGenerators() { - return new CloneListIterator<OrmSequenceGenerator>(this.sequenceGenerators); - } - - public int sequenceGeneratorsSize() { - return this.sequenceGenerators.size(); - } - - public OrmSequenceGenerator addSequenceGenerator(int index) { - XmlSequenceGenerator resourceSequenceGenerator = this.buildResourceSequenceGenerator(); - OrmSequenceGenerator contextSequenceGenerator = this.buildSequenceGenerator(resourceSequenceGenerator); - this.sequenceGenerators.add(index, contextSequenceGenerator); - this.xmlEntityMappings.getSequenceGenerators().add(index, resourceSequenceGenerator); - fireItemAdded(SEQUENCE_GENERATORS_LIST, index, contextSequenceGenerator); - return contextSequenceGenerator; - } - - protected void addSequenceGenerator(int index, OrmSequenceGenerator sequenceGenerator) { - addItemToList(index, sequenceGenerator, this.sequenceGenerators, EntityMappings.SEQUENCE_GENERATORS_LIST); - } - - protected void addSequenceGenerator(OrmSequenceGenerator sequenceGenerator) { - this.addSequenceGenerator(this.sequenceGenerators.size(), sequenceGenerator); - } - - public void removeSequenceGenerator(OrmSequenceGenerator sequenceGenerator) { - removeSequenceGenerator(this.sequenceGenerators.indexOf(sequenceGenerator)); - } - - public void removeSequenceGenerator(int index) { - OrmSequenceGenerator removedSequenceGenerator = this.sequenceGenerators.remove(index); - fireItemRemoved(SEQUENCE_GENERATORS_LIST, index, removedSequenceGenerator); - this.xmlEntityMappings.getSequenceGenerators().remove(index); - } - - protected void removeSequenceGenerator_(OrmSequenceGenerator sequenceGenerator) { - removeItemFromList(sequenceGenerator, this.sequenceGenerators, EntityMappings.SEQUENCE_GENERATORS_LIST); - } - - public void moveSequenceGenerator(int targetIndex, int sourceIndex) { - CollectionTools.move(this.sequenceGenerators, targetIndex, sourceIndex); - this.xmlEntityMappings.getSequenceGenerators().move(targetIndex, sourceIndex); - fireItemMoved(EntityMappings.SEQUENCE_GENERATORS_LIST, targetIndex, sourceIndex); - } - - protected XmlSequenceGenerator buildResourceSequenceGenerator() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getXmlSequenceGenerator(), - XmlSequenceGenerator.class); - } - - // ********** table generators ********** - - public ListIterator<OrmTableGenerator> tableGenerators() { - return new CloneListIterator<OrmTableGenerator>(this.tableGenerators); - } - - public int tableGeneratorsSize() { - return this.tableGenerators.size(); - } - - public OrmTableGenerator addTableGenerator(int index) { - XmlTableGenerator resourceTableGenerator = buildResourceTableGenerator(); - OrmTableGenerator contextTableGenerator = buildTableGenerator(resourceTableGenerator); - this.tableGenerators.add(index, contextTableGenerator); - this.xmlEntityMappings.getTableGenerators().add(index, resourceTableGenerator); - fireItemAdded(TABLE_GENERATORS_LIST, index, contextTableGenerator); - return contextTableGenerator; - } - - protected void addTableGenerator(int index, OrmTableGenerator tableGenerator) { - addItemToList(index, tableGenerator, this.tableGenerators, EntityMappings.TABLE_GENERATORS_LIST); - } - - protected void addTableGenerator(OrmTableGenerator tableGenerator) { - this.addTableGenerator(this.tableGenerators.size(), tableGenerator); - } - - public void removeTableGenerator(OrmTableGenerator tableGenerator) { - removeTableGenerator(this.tableGenerators.indexOf(tableGenerator)); - } - - public void removeTableGenerator(int index) { - OrmTableGenerator removedTableGenerator = this.tableGenerators.remove(index); - this.xmlEntityMappings.getTableGenerators().remove(index); - fireItemRemoved(TABLE_GENERATORS_LIST, index, removedTableGenerator); - } - - protected void removeTableGenerator_(OrmTableGenerator tableGenerator) { - removeItemFromList(tableGenerator, this.tableGenerators, EntityMappings.TABLE_GENERATORS_LIST); - } - - public void moveTableGenerator(int targetIndex, int sourceIndex) { - CollectionTools.move(this.tableGenerators, targetIndex, sourceIndex); - this.xmlEntityMappings.getTableGenerators().move(targetIndex, sourceIndex); - fireItemMoved(EntityMappings.TABLE_GENERATORS_LIST, targetIndex, sourceIndex); - } - - protected XmlTableGenerator buildResourceTableGenerator() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getXmlTableGenerator(), - XmlTableGenerator.class); - } - - - // ********** named queries ********** - public OrmQueryContainer getQueryContainer() { - return this.queryContainer; - } - - - // ********** misc ********** - - //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 : this.getPersistentTypes()) { - if (persistentType.getName().equals(className)) { - return true; - } - } - return false; - } - - public OrmPersistenceUnitDefaults getPersistenceUnitDefaults() { - return getPersistenceUnitMetadata().getPersistenceUnitDefaults(); - } - - /** - * All orm.xml entity mappings must be able to generate a static metamodel - * because 1.0 orm.xml files can be referenced from 2.0 persistence.xml files. - */ - public void synchronizeStaticMetamodel() { - for (OrmPersistentType opt : this.getPersistentTypes()) { - opt.synchronizeStaticMetamodel(); - } - } - - - // ********** initialization ********** - - protected void initializePersistentTypes() { - for (XmlTypeMapping typeMapping : this.xmlEntityMappings.getTypeMappings()) { - addPersistentType(typeMapping); - } - } - - protected void initializeTableGenerators() { - for (XmlTableGenerator tableGenerator : this.xmlEntityMappings.getTableGenerators()) { - this.tableGenerators.add(buildTableGenerator(tableGenerator)); - } - } - - protected void initializeSequenceGenerators() { - for (XmlSequenceGenerator sequenceGenerator : this.xmlEntityMappings.getSequenceGenerators()) { - this.sequenceGenerators.add(buildSequenceGenerator(sequenceGenerator)); - } - } - - - // ********** update ********** - - public void update() { - this.setDescription(this.xmlEntityMappings.getDescription()); - this.setPackage(this.xmlEntityMappings.getPackage()); - - this.setDefaultAccess(this.getPersistenceUnit().getDefaultAccess()); - this.setSpecifiedAccess(this.getResourceAccess()); - - this.setDefaultCatalog(this.getPersistenceUnit().getDefaultCatalog()); - this.setSpecifiedCatalog(this.xmlEntityMappings.getCatalog()); - - this.setDefaultSchema(this.getPersistenceUnit().getDefaultSchema()); - this.setSpecifiedSchema(this.xmlEntityMappings.getSchema()); - - this.persistenceUnitMetadata.update(); - this.updatePersistentTypes(); - this.updateTableGenerators(); - this.updateSequenceGenerators(); - getQueryContainer().update(); - } - - protected AccessType getResourceAccess() { - return AccessType.fromOrmResourceModel(this.xmlEntityMappings.getAccess()); - } - - protected void updatePersistentTypes() { - Collection<OrmPersistentType> contextTypesToRemove = CollectionTools.collection(persistentTypes()); - Collection<OrmPersistentType> contextTypesToUpdate = new ArrayList<OrmPersistentType>(); - int resourceIndex = 0; - - List<XmlTypeMapping> xmlTypeMappings = this.xmlEntityMappings.getTypeMappings(); - for (XmlTypeMapping xmlTypeMapping : xmlTypeMappings.toArray(new XmlTypeMapping[xmlTypeMappings.size()])) { - boolean contextAttributeFound = false; - for (OrmPersistentType contextType : contextTypesToRemove) { - if (contextType.getMapping().getResourceTypeMapping() == xmlTypeMapping) { - movePersistentType_(resourceIndex, contextType); - contextTypesToRemove.remove(contextType); - contextTypesToUpdate.add(contextType); - contextAttributeFound = true; - break; - } - } - if (!contextAttributeFound) { - OrmPersistentType ormPersistentType = addPersistentType(xmlTypeMapping); - fireItemAdded(PERSISTENT_TYPES_LIST, persistentTypesSize(), ormPersistentType); - } - resourceIndex++; - } - for (OrmPersistentType contextType : contextTypesToRemove) { - removePersistentType_(contextType); - } - //first handle adding/removing of the persistent types, then update the others last, - //this causes less churn in the update process - for (OrmPersistentType contextType : contextTypesToUpdate) { - contextType.update(); - } - } - - //not firing change notification so this can be reused in initialize and update - protected OrmPersistentType addPersistentType(XmlTypeMapping resourceMapping) { - OrmPersistentType ormPersistentType = buildPersistentType(resourceMapping); - this.persistentTypes.add(ormPersistentType); - return ormPersistentType; - } - - protected void updateTableGenerators() { - // make a copy of the XML generators (to prevent ConcurrentModificationException) - Iterator<XmlTableGenerator> xmlGenerators = new CloneIterator<XmlTableGenerator>(this.xmlEntityMappings.getTableGenerators()); - - for (Iterator<OrmTableGenerator> contextGenerators = this.tableGenerators(); contextGenerators.hasNext(); ) { - OrmTableGenerator contextGenerator = contextGenerators.next(); - if (xmlGenerators.hasNext()) { - contextGenerator.update(xmlGenerators.next()); - } - else { - removeTableGenerator_(contextGenerator); - } - } - - while (xmlGenerators.hasNext()) { - addTableGenerator(buildTableGenerator(xmlGenerators.next())); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator resourceTableGenerator) { - return getXmlContextNodeFactory().buildOrmTableGenerator(this, resourceTableGenerator); - } - - protected void updateSequenceGenerators() { - // make a copy of the XML sequence generators (to prevent ConcurrentModificationException) - Iterator<XmlSequenceGenerator> xmlSequenceGenerators = new CloneIterator<XmlSequenceGenerator>(this.xmlEntityMappings.getSequenceGenerators());//prevent ConcurrentModificiationException - - for (Iterator<OrmSequenceGenerator> contextSequenceGenerators = this.sequenceGenerators(); contextSequenceGenerators.hasNext(); ) { - OrmSequenceGenerator contextSequenceGenerator = contextSequenceGenerators.next(); - if (xmlSequenceGenerators.hasNext()) { - contextSequenceGenerator.update(xmlSequenceGenerators.next()); - } - else { - removeSequenceGenerator_(contextSequenceGenerator); - } - } - - while (xmlSequenceGenerators.hasNext()) { - addSequenceGenerator(buildSequenceGenerator(xmlSequenceGenerators.next())); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator resourceSequenceGenerator) { - return getXmlContextNodeFactory().buildOrmSequenceGenerator(this, resourceSequenceGenerator); - } - - @Override - public void postUpdate() { - super.postUpdate(); - for (PersistentType persistentType : this.getPersistentTypes()) { - persistentType.postUpdate(); - } - } - - // ********** text ********** - - public JpaStructureNode getStructureNode(int textOffset) { - for (OrmPersistentType persistentType: this.getPersistentTypes()) { - if (persistentType.contains(textOffset)) { - return persistentType.getStructureNode(textOffset); - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - return (this.xmlEntityMappings != null) && this.xmlEntityMappings.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.xmlEntityMappings.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return null; - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateGenerators(messages); - this.queryContainer.validate(messages, reporter); - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - this.validatePersistentType(ormPersistentType, messages, reporter); - } - } - - protected void validateGenerators(List<IMessage> messages) { - for (Iterator<OrmGenerator> localGenerators = this.generators(); localGenerators.hasNext(); ) { - OrmGenerator localGenerator = localGenerators.next(); - for (Iterator<Generator> globalGenerators = this.getPersistenceUnit().generators(); globalGenerators.hasNext(); ) { - if (localGenerator.duplicates(globalGenerators.next())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {localGenerator.getName()}, - localGenerator, - localGenerator.getNameTextRange() - ) - ); - } - } - } - } - - /** - * Return all the generators, table and sequence. - */ - @SuppressWarnings("unchecked") - public Iterator<OrmGenerator> generators() { - return new CompositeIterator<OrmGenerator>( - this.tableGenerators(), - this.sequenceGenerators() - ); - } - - - protected void validatePersistentType(OrmPersistentType persistentType, List<IMessage> messages, IReporter reporter) { - try { - persistentType.validate(messages, reporter); - } catch (Throwable exception) { - JptCorePlugin.log(exception); - } - } - - - // ********** dispose ********** - - public void dispose() { - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - ormPersistentType.dispose(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAssociationOverrideRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAssociationOverrideRelationshipReference.java deleted file mode 100644 index 98c62d11d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAssociationOverrideRelationshipReference.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.AssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnInAssociationOverrideJoiningStrategy; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.utility.TextRange; - -public abstract class AbstractOrmAssociationOverrideRelationshipReference extends AbstractOrmXmlContextNode - implements OrmAssociationOverrideRelationshipReference -{ - - // cache the strategy for property change notification - protected JoiningStrategy cachedPredominantJoiningStrategy; - - protected OrmJoinColumnInAssociationOverrideJoiningStrategy joinColumnJoiningStrategy; - - protected AbstractOrmAssociationOverrideRelationshipReference(OrmAssociationOverride parent, XmlAssociationOverride xao) { - super(parent); - this.initializeJoiningStrategies(xao); - } - - protected OrmJoinColumnInAssociationOverrideJoiningStrategy buildJoinColumnJoiningStrategy(XmlAssociationOverride xao) { - return new GenericOrmJoinColumnInAssociationOverrideJoiningStrategy(this, xao); - } - - public void initializeFrom(AssociationOverrideRelationshipReference oldAssociationOverride) { - if (oldAssociationOverride.getJoinColumnJoiningStrategy().hasSpecifiedJoinColumns()) { - getJoinColumnJoiningStrategy().initializeFrom(oldAssociationOverride.getJoinColumnJoiningStrategy()); - } - } - - @Override - public OrmAssociationOverride getParent() { - return (OrmAssociationOverride) super.getParent(); - } - - public OrmAssociationOverride getAssociationOverride() { - return getParent(); - } - - public TypeMapping getTypeMapping() { - return getAssociationOverride().getOwner().getTypeMapping(); - } - - public Entity getEntity() { - TypeMapping typeMapping = getTypeMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - public boolean isOverridableAssociation() { - return false; - } - - public boolean isParentVirtual() { - return getAssociationOverride().isVirtual(); - } - - // **************** predominant joining strategy *************************** - - public JoiningStrategy getPredominantJoiningStrategy() { - return this.cachedPredominantJoiningStrategy; - } - - protected void setPredominantJoiningStrategy(JoiningStrategy newJoiningStrategy) { - JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; - this.cachedPredominantJoiningStrategy = newJoiningStrategy; - firePropertyChanged(PREDOMINANT_JOINING_STRATEGY_PROPERTY, oldJoiningStrategy, newJoiningStrategy); - } - - protected void initialize(XmlAssociationOverride associationOverride) { - initializeJoiningStrategies(associationOverride); - this.cachedPredominantJoiningStrategy = calculatePredominantJoiningStrategy(); - } - - protected void initializeJoiningStrategies(XmlAssociationOverride xao) { - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(xao); - } - - public void update(XmlAssociationOverride associationOverride) { - updateJoiningStrategies(associationOverride); - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); - } - - protected void updateJoiningStrategies(XmlAssociationOverride associationOverride) { - this.joinColumnJoiningStrategy.update(associationOverride); - } - - protected abstract JoiningStrategy calculatePredominantJoiningStrategy(); - - // **************** join columns ******************************************* - - - public OrmJoinColumnInAssociationOverrideJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.addStrategy(); - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return false; - } - - public RelationshipMapping getRelationshipMapping() { - return getAssociationOverride().getOwner().getRelationshipMapping(getAssociationOverride().getName()); - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return getRelationshipMapping().isOwnedBy(mapping); - } - - public boolean isRelationshipOwner() { - return getRelationshipMapping().isRelationshipOwner(); - } - - // ********** validation ********** - - - public TextRange getValidationTextRange() { - return getAssociationOverride().getValidationTextRange(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java deleted file mode 100644 index cd02558e5d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java +++ /dev/null @@ -1,258 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> - extends AbstractOrmXmlContextNode - implements OrmAttributeMapping -{ - protected String name; - - protected final T resourceAttributeMapping; - - protected AbstractOrmAttributeMapping(OrmPersistentAttribute parent, T resourceAttributeMapping) { - super(parent); - this.resourceAttributeMapping = resourceAttributeMapping; - this.name = this.getResourceMappingName(); - } - - protected JavaPersistentAttribute getJavaPersistentAttribute() { - return this.getPersistentAttribute().getJavaPersistentAttribute(); - } - - protected JavaResourcePersistentAttribute getJavaResourcePersistentAttribute() { - return this.getJavaPersistentAttribute().getResourcePersistentAttribute(); - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - this.resourceAttributeMapping.setName(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - this.getPersistentAttribute().nameChanged(old, name); - } - - protected void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - this.getPersistentAttribute().nameChanged(old, name); - } - - public OrmPersistentAttribute getPersistentAttribute() { - return (OrmPersistentAttribute) getParent(); - } - - public boolean isDefault() { - return false; - } - - public void initializeFromOrmAttributeMapping(OrmAttributeMapping oldMapping) { - setName(oldMapping.getName()); - } - - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - initializeFromOrmAttributeMapping((OrmAttributeMapping) oldMapping); - } - - public void initializeFromOrmBasicMapping(OrmBasicMapping oldMapping) { - initializeFromOrmColumnMapping(oldMapping); - } - - public void initializeFromOrmIdMapping(OrmIdMapping oldMapping) { - initializeFromOrmColumnMapping(oldMapping); - } - - public void initializeFromOrmTransientMapping(OrmTransientMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmBaseEmbeddedMapping(OrmBaseEmbeddedMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmEmbeddedMapping(OrmEmbeddedMapping oldMapping) { - initializeFromOrmBaseEmbeddedMapping(oldMapping); - } - - public void initializeFromOrmEmbeddedIdMapping(OrmEmbeddedIdMapping oldMapping) { - initializeFromOrmBaseEmbeddedMapping(oldMapping); - } - - public void initializeFromOrmVersionMapping(OrmVersionMapping oldMapping) { - initializeFromOrmColumnMapping(oldMapping); - } - - public void initializeFromOrmRelationshipMapping(OrmRelationshipMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmMultiRelationshipMapping(OrmMultiRelationshipMapping oldMapping) { - initializeFromOrmRelationshipMapping(oldMapping); - } - - public void initializeFromOrmSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - initializeFromOrmRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToManyMapping(OrmOneToManyMapping oldMapping) { - initializeFromOrmMultiRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToOneMapping(OrmManyToOneMapping oldMapping) { - initializeFromOrmSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToOneMapping(OrmOneToOneMapping oldMapping) { - initializeFromOrmSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToManyMapping(OrmManyToManyMapping oldMapping) { - initializeFromOrmMultiRelationshipMapping(oldMapping); - } - - public String getPrimaryKeyColumnName() { - return null; - } - - public OrmTypeMapping getTypeMapping() { - return this.getPersistentAttribute().getTypeMapping(); - } - - - public boolean isOverridableAttributeMapping() { - return false; - } - - public boolean isOverridableAssociationMapping() { - return false; - } - - public boolean isIdMapping() { - return false; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - // Default implementation - override where needed - return false; - } - - public T getResourceAttributeMapping() { - return this.resourceAttributeMapping; - } - - public void update() { - this.setName_(this.getResourceMappingName()); - } - - protected String getResourceMappingName() { - return this.resourceAttributeMapping.getName(); - } - - public boolean shouldValidateAgainstDatabase() { - return this.getTypeMapping().shouldValidateAgainstDatabase(); - } - - public boolean contains(int textOffset) { - return this.resourceAttributeMapping.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.resourceAttributeMapping.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return (this.getPersistentAttribute().isVirtual()) ? this.getTypeMapping().getAttributesTextRange() : this.resourceAttributeMapping.getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.resourceAttributeMapping.getNameTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateAttribute(messages); - this.validateMapping(messages); - } - - protected void validateAttribute(List<IMessage> messages) { - if (StringTools.stringIsEmpty(this.name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME, - this, - this.getValidationTextRange() - ) - ); - return; - } - } - - //TODO validation message - i think more info is needed in this message. include type mapping type? - protected void validateMapping(List<IMessage> messages) { - if ( ! this.getTypeMapping().attributeMappingKeyAllowed(this.getKey())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_MAPPING, - new String[] {this.name}, - this, - this.getValidationTextRange() - ) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java deleted file mode 100644 index f3759a1479..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, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmBaseColumn; -import org.eclipse.jpt.core.resource.orm.AbstractXmlColumn; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class AbstractOrmBaseColumn<T extends AbstractXmlColumn> extends AbstractOrmNamedColumn<T> - implements OrmBaseColumn -{ - protected String specifiedTable; - - protected String defaultTable; - - protected Boolean specifiedUnique; - - protected Boolean specifiedNullable; - - protected Boolean specifiedInsertable; - - protected Boolean specifiedUpdatable; - - protected AbstractOrmBaseColumn(XmlContextNode parent, OrmBaseColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFrom(BaseColumn oldColumn) { - super.initializeFrom(oldColumn); - setSpecifiedTable(oldColumn.getSpecifiedTable()); - setSpecifiedUnique(oldColumn.getSpecifiedUnique()); - setSpecifiedNullable(oldColumn.getSpecifiedNullable()); - setSpecifiedInsertable(oldColumn.getSpecifiedInsertable()); - setSpecifiedUpdatable(oldColumn.getSpecifiedUpdatable()); - } - - @Override - public OrmBaseColumn.Owner getOwner() { - return (OrmBaseColumn.Owner) super.getOwner(); - } - -// @Override -// protected void addInsignificantXmlFeatureIdsTo(Set<Integer> insignificantXmlFeatureIds) { -// super.addInsignificantXmlFeatureIdsTo(insignificantXmlFeatureIds); -// insignificantXmlFeatureIds.add(JpaCoreMappingsPackage.IABSTRACT_COLUMN__DEFAULT_TABLE); -// insignificantXmlFeatureIds.add(JpaCoreMappingsPackage.IABSTRACT_COLUMN__TABLE); -// } - - public String getTable() { - return (this.getSpecifiedTable() == null) ? getDefaultTable() : this.getSpecifiedTable(); - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - if (this.valuesAreDifferent(oldSpecifiedTable, newSpecifiedTable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setTable(newSpecifiedTable); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedTable != null) { - addResourceColumn(); - getResourceColumn().setTable(newSpecifiedTable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - protected void setDefaultTable(String newDefaultTable) { - String oldDefaultTable = this.defaultTable; - this.defaultTable = newDefaultTable; - firePropertyChanged(BaseColumn.DEFAULT_TABLE_PROPERTY, oldDefaultTable, newDefaultTable); - } - - public boolean isUnique() { - return (this.getSpecifiedUnique() == null) ? this.isDefaultUnique() : this.getSpecifiedUnique().booleanValue(); - } - - public boolean isDefaultUnique() { - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getSpecifiedUnique() { - return this.specifiedUnique; - } - - public void setSpecifiedUnique(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - if (this.valuesAreDifferent(oldSpecifiedUnique, newSpecifiedUnique)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setUnique(newSpecifiedUnique); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedUnique != null) { - addResourceColumn(); - getResourceColumn().setUnique(newSpecifiedUnique); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - protected void setSpecifiedUnique_(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - public boolean isNullable() { - return (this.getSpecifiedNullable() == null) ? this.isDefaultNullable() : this.getSpecifiedNullable().booleanValue(); - } - - public boolean isDefaultNullable() { - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getSpecifiedNullable() { - return this.specifiedNullable; - } - - public void setSpecifiedNullable(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - if (this.valuesAreDifferent(oldSpecifiedNullable, newSpecifiedNullable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setNullable(newSpecifiedNullable); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedNullable != null) { - addResourceColumn(); - getResourceColumn().setNullable(newSpecifiedNullable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - protected void setSpecifiedNullable_(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - public boolean isInsertable() { - return (this.getSpecifiedInsertable() == null) ? this.isDefaultInsertable() : this.getSpecifiedInsertable().booleanValue(); - } - - public boolean isDefaultInsertable() { - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getSpecifiedInsertable() { - return this.specifiedInsertable; - } - - public void setSpecifiedInsertable(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - if (this.valuesAreDifferent(oldSpecifiedInsertable, newSpecifiedInsertable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setInsertable(newSpecifiedInsertable); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedInsertable != null) { - addResourceColumn(); - getResourceColumn().setInsertable(newSpecifiedInsertable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - protected void setSpecifiedInsertable_(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - public boolean isUpdatable() { - return (this.getSpecifiedUpdatable() == null) ? this.isDefaultUpdatable() : this.getSpecifiedUpdatable().booleanValue(); - } - - public boolean isDefaultUpdatable() { - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getSpecifiedUpdatable() { - return this.specifiedUpdatable; - } - - public void setSpecifiedUpdatable(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - if (this.valuesAreDifferent(oldSpecifiedUpdatable, newSpecifiedUpdatable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setUpdatable(newSpecifiedUpdatable); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedUpdatable != null) { - addResourceColumn(); - getResourceColumn().setUpdatable(newSpecifiedUpdatable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - protected void setSpecifiedUpdatable_(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - @Override - protected String getOwningTableName() { - return this.getTable(); - } - - - public TextRange getTableTextRange() { - if (getResourceColumn() != null) { - TextRange textRange = getResourceColumn().getTableTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - @Override - protected void initialize(T column) { - super.initialize(column); - this.specifiedTable = this.getResourceTable(column); - this.defaultTable = this.buildDefaultTableName(); - //TODO default from java for all of these settings - this.specifiedNullable = this.getResourceNullable(column); - this.specifiedUpdatable = this.getResourceUpdatable(column); - this.specifiedUnique = this.getResourceUnique(column); - this.specifiedInsertable = this.getResourceInsertable(column); - } - - @Override - protected void update(T column) { - super.update(column); - setSpecifiedTable_(this.getResourceTable(column)); - setDefaultTable(this.buildDefaultTableName()); - setSpecifiedNullable_(this.getResourceNullable(column)); - setSpecifiedUpdatable_(this.getResourceUpdatable(column)); - setSpecifiedUnique_(this.getResourceUnique(column)); - setSpecifiedInsertable_(this.getResourceInsertable(column)); - } - - protected String getResourceTable(T column) { - return column == null ? null : column.getTable(); - } - - protected Boolean getResourceNullable(T column) { - return column == null ? null : column.getNullable(); - } - - protected Boolean getResourceUpdatable(T column) { - return column == null ? null : column.getUpdatable(); - } - - protected Boolean getResourceUnique(T column) { - return column == null ? null : column.getUnique(); - } - - protected Boolean getResourceInsertable(T column) { - return column == null ? null : column.getInsertable(); - } - - protected String buildDefaultTableName() { - return getOwner().getDefaultTableName(); - } - -} 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 187cd63064..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -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 abstract class AbstractOrmBaseEmbeddedMapping<T extends AbstractXmlEmbedded> extends AbstractOrmAttributeMapping<T> implements OrmBaseEmbeddedMapping -{ - protected OrmAttributeOverrideContainer attributeOverrideContainer; - - private Embeddable embeddable;//TODO hmm, why no property change notification for setting this?? - - protected AbstractOrmBaseEmbeddedMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.embeddable = embeddableFor(this.getJavaPersistentAttribute()); - this.attributeOverrideContainer = getXmlContextNodeFactory().buildOrmAttributeOverrideContainer(this, this, this.resourceAttributeMapping); - } - - @Override - public void initializeFromOrmBaseEmbeddedMapping(OrmBaseEmbeddedMapping oldMapping) { - super.initializeFromOrmBaseEmbeddedMapping(oldMapping); - this.attributeOverrideContainer.initializeFromAttributeOverrideContainer(oldMapping.getAttributeOverrideContainer()); - } - - public OrmAttributeOverrideContainer getAttributeOverrideContainer() { - return this.attributeOverrideContainer; - } - - - //************* AttributeOverrideContainer.Owner implementation ******************** - - public XmlColumn buildVirtualXmlColumn(ColumnMapping overridableColumnMapping) { - return new VirtualXmlAttributeOverrideColumn(overridableColumnMapping.getColumn()); - } - - public PersistentType getOverridablePersistentType() { - Embeddable embeddable = getEmbeddable(); - return embeddable == null ? null : embeddable.getPersistentType(); - } - - public Embeddable getEmbeddable() { - return this.embeddable; - } - - public Iterator<String> allOverridableAttributeNames() { - return new TransformationIterator<ColumnMapping, String>(this.allOverridableAttributes()) { - @Override - protected String transform(ColumnMapping attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<ColumnMapping> allOverridableAttributes() { - if (this.getEmbeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<AttributeMapping, ColumnMapping>(this.getEmbeddable().attributeMappings()) { - @Override - protected boolean accept(AttributeMapping o) { - return o.isOverridableAttributeMapping(); - } - }; - } - - public JavaBaseEmbeddedMapping getJavaEmbeddedMapping() { - JavaPersistentAttribute jpa = this.getJavaPersistentAttribute(); - if ((jpa != null) && this.valuesAreEqual(jpa.getMappingKey(), this.getKey())) { - return (JavaBaseEmbeddedMapping) jpa.getMapping(); - } - return null; - } - - - @Override - public void update() { - super.update(); - this.embeddable = embeddableFor(this.getJavaPersistentAttribute()); - getAttributeOverrideContainer().update(); - } - - //************ static methods ************ - - public static Embeddable embeddableFor(JavaPersistentAttribute javaPersistentAttribute) { - return (javaPersistentAttribute == null) ? null : javaPersistentAttribute.getEmbeddable(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBasicMapping.java deleted file mode 100644 index c48487dd8e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBasicMapping.java +++ /dev/null @@ -1,326 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmBasicMapping<T extends XmlBasic> - extends AbstractOrmAttributeMapping<T> - implements OrmBasicMapping -{ - protected final OrmColumn column; - - protected FetchType specifiedFetch; - - protected Boolean specifiedOptional; - - protected OrmConverter defaultConverter; - - protected OrmConverter specifiedConverter; - - protected AbstractOrmBasicMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.column = getXmlContextNodeFactory().buildOrmColumn(this, this); - this.column.initialize(this.getResourceColumn());//TODO pass in to factory - this.specifiedFetch = this.getResourceFetch(); - this.specifiedOptional = this.getResourceOptional(); - this.defaultConverter = getXmlContextNodeFactory().buildOrmNullConverter(this); - this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getDefaultFetch() { - return BasicMapping.DEFAULT_FETCH_TYPE; - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.resourceAttributeMapping.setFetch(FetchType.toOrmResourceModel(newSpecifiedFetch)); - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - public boolean isOptional() { - return (this.getSpecifiedOptional() == null) ? this.isDefaultOptional() : this.getSpecifiedOptional().booleanValue(); - } - - public boolean isDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - this.resourceAttributeMapping.setOptional(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - public OrmConverter getConverter() { - return getSpecifiedConverter() == null ? getDefaultConverter() : getSpecifiedConverter(); - } - - public OrmConverter getDefaultConverter() { - return this.defaultConverter; - } - - public OrmConverter getSpecifiedConverter() { - return this.specifiedConverter; - } - - protected String getSpecifedConverterType() { - if (this.specifiedConverter == null) { - return Converter.NO_CONVERTER; - } - return this.specifiedConverter.getType(); - } - - public void setSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(getSpecifedConverterType(), converterType)) { - return; - } - OrmConverter oldConverter = this.specifiedConverter; - OrmConverter newConverter = buildSpecifiedConverter(converterType); - this.specifiedConverter = null; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.specifiedConverter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setSpecifiedConverter(OrmConverter newConverter) { - OrmConverter oldConverter = this.specifiedConverter; - this.specifiedConverter = newConverter; - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmBasicMapping(this); - } - - - @Override - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromOrmColumnMapping(oldMapping); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public int getXmlSequence() { - return 20; - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - public OrmColumn getColumn() { - return this.column; - } - - public String getDefaultColumnName() { - return getName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - @Override - public void update() { - super.update(); - this.setSpecifiedFetch_(this.getResourceFetch()); - this.setSpecifiedOptional_(this.getResourceOptional()); - this.column.update(this.getResourceColumn()); - if (this.valuesAreEqual(getResourceConverterType(), getSpecifedConverterType())) { - getSpecifiedConverter().update(); - } - else { - setSpecifiedConverter(buildSpecifiedConverter(getResourceConverterType())); - } - } - - protected Boolean getResourceOptional() { - return this.resourceAttributeMapping.getOptional(); - } - - protected FetchType getResourceFetch() { - return FetchType.fromOrmResourceModel(this.resourceAttributeMapping.getFetch()); - } - - protected OrmConverter buildSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.ENUMERATED_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmEnumeratedConverter(this, this.resourceAttributeMapping); - } - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmTemporalConverter(this, this.resourceAttributeMapping); - } - if (this.valuesAreEqual(converterType, Converter.LOB_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmLobConverter(this, this.resourceAttributeMapping); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourceAttributeMapping.getEnumerated() != null) { - return Converter.ENUMERATED_CONVERTER; - } - else if (this.resourceAttributeMapping.getTemporal() != null) { - return Converter.TEMPORAL_CONVERTER; - } - else if (this.resourceAttributeMapping.isLob()) { - return Converter.LOB_CONVERTER; - } - - return null; - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getBasics().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getBasics().remove(this.resourceAttributeMapping); - } - - //***************** XmlColumn.Owner implementation **************** - - public XmlColumn getResourceColumn() { - return this.resourceAttributeMapping.getColumn(); - } - - public void addResourceColumn() { - this.resourceAttributeMapping.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - this.resourceAttributeMapping.setColumn(null); - } - - // ****************** validation **************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.shouldValidateAgainstDatabase()) { - this.validateColumn(messages); - } - } - - protected void validateColumn(List<IMessage> messages) { - String tableName = this.column.getTable(); - if (this.getTypeMapping().tableNameIsInvalid(tableName)) { - if (this.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {this.getName(), tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - if (this.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {this.getName(), this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddable.java deleted file mode 100644 index 58c47e39cc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddable.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public abstract class AbstractOrmEmbeddable extends AbstractOrmTypeMapping<XmlEmbeddable> implements OrmEmbeddable -{ - protected AbstractOrmEmbeddable(OrmPersistentType parent, XmlEmbeddable resourceMapping) { - super(parent, resourceMapping); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public int getXmlSequence() { - return 2; - } - - public JavaEmbeddable getJavaEmbeddable() { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getMappingKey() == MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY) { - return (JavaEmbeddable) javaPersistentType.getMapping(); - } - return null; - } - - /** - * This checks metaDataComplete before returning the JavaEmbeddable. - * As far as defaults are concerned, if metadataComplete is true, the JavaEmbeddable is ignored. - */ - protected JavaEmbeddable getJavaEmbeddableForDefaults() { - if (isMetadataComplete()) { - return null; - } - return getJavaEmbeddable(); - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - public void addToResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEmbeddables().add(this.resourceTypeMapping); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEmbeddables().remove(this.resourceTypeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java deleted file mode 100644 index 3d5d9b05bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddedMapping.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.RelationshipReference; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -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 abstract class AbstractOrmEmbeddedMapping<T extends XmlEmbedded> - extends AbstractOrmBaseEmbeddedMapping<T> - implements OrmEmbeddedMapping2_0 -{ - protected OrmAssociationOverrideContainer associationOverrideContainer; - - protected AbstractOrmEmbeddedMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - if (this.resourceAttributeMapping instanceof org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbedded) { - this.associationOverrideContainer = ((OrmXml2_0ContextNodeFactory) getXmlContextNodeFactory()).buildOrmAssociationOverrideContainer(this, this, (org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbedded) this.resourceAttributeMapping); - } - else { - this.associationOverrideContainer = ((OrmXml2_0ContextNodeFactory) getXmlContextNodeFactory()).buildOrmAssociationOverrideContainer(this, this, null); - } - } - - @Override - public void update() { - super.update(); - getAssociationOverrideContainer().update(); - } - - @Override - public void postUpdate() { - super.postUpdate(); - getAssociationOverrideContainer().postUpdate(); - } - - @Override - public JavaEmbeddedMapping2_0 getJavaEmbeddedMapping() { - return (JavaEmbeddedMapping2_0) super.getJavaEmbeddedMapping(); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmEmbeddedMapping(this); - } - - public int getXmlSequence() { - return 80; - } - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getEmbeddeds().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getEmbeddeds().remove(this.resourceAttributeMapping); - } - - - - public OrmAssociationOverrideContainer getAssociationOverrideContainer() { - return this.associationOverrideContainer; - } - - - //************* AttributeOverrideContainer.Owner implementation ******************** - - public Iterator<String> allOverridableAssociationNames() { - return new TransformationIterator<RelationshipMapping, String>(this.allOverridableAssociations()) { - @Override - protected String transform(RelationshipMapping overridableAssociation) { - return overridableAssociation.getName(); - } - }; - } - - public Iterator<RelationshipMapping> allOverridableAssociations() { - if (this.getEmbeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<AttributeMapping, RelationshipMapping>(this.getEmbeddable().attributeMappings()) { - @Override - protected boolean accept(AttributeMapping o) { - return o.isOverridableAssociationMapping(); - } - }; - } - - //********** OrmAssociationOverrideContainer.Owner implementation ********* - - public RelationshipReference getOverridableRelationshipReference(RelationshipMapping overridableAssociation) { - if (getPersistentAttribute().isVirtual()) { - JavaAssociationOverride javaAssociationOverride = getJavaAssociationOverrideNamed(overridableAssociation.getName()); - if (javaAssociationOverride != null && !javaAssociationOverride.isVirtual()) { - return javaAssociationOverride.getRelationshipReference(); - } - } - return overridableAssociation.getRelationshipReference(); - } - - protected JavaAssociationOverride getJavaAssociationOverrideNamed(String attributeName) { - if (getJavaEmbeddedMapping() != null) { - return getJavaEmbeddedMapping().getAssociationOverrideContainer().getAssociationOverrideNamed(attributeName); - } - return null; - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java deleted file mode 100644 index 9c65560e27..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java +++ /dev/null @@ -1,1834 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import 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.JpaPlatformVariation.Supported; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseJoinColumn; -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.InheritanceType; -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.RelationshipMapping; -import org.eclipse.jpt.core.context.RelationshipReference; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.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.java.JavaTable; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmQueryContainer; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.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.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.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmEntity - extends AbstractOrmTypeMapping<XmlEntity> - implements OrmEntity -{ - protected String specifiedName; - - protected String defaultName; - - protected String idClass; - - protected final OrmTable table; - - protected boolean specifiedTableIsAllowed; - - protected boolean tableIsUndefined; - - protected final List<OrmSecondaryTable> specifiedSecondaryTables; - - protected final List<OrmSecondaryTable> virtualSecondaryTables; - - protected final List<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected final List<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns; - - protected InheritanceType specifiedInheritanceStrategy; - - protected InheritanceType defaultInheritanceStrategy; - - protected String defaultDiscriminatorValue; - - protected String specifiedDiscriminatorValue; - - protected boolean specifiedDiscriminatorValueIsAllowed; - - protected boolean discriminatorValueIsUndefined; - - protected final OrmDiscriminatorColumn discriminatorColumn; - - protected boolean specifiedDiscriminatorColumnIsAllowed; - - protected boolean discriminatorColumnIsUndefined; - - protected final OrmGeneratorContainer generatorContainer; - - protected final OrmAttributeOverrideContainer attributeOverrideContainer; - - protected final OrmAssociationOverrideContainer associationOverrideContainer; - - protected final OrmQueryContainer queryContainer; - - protected Entity rootEntity; - - protected AbstractOrmEntity(OrmPersistentType parent, XmlEntity resourceMapping) { - super(parent, resourceMapping); - this.table = getXmlContextNodeFactory().buildOrmTable(this); - this.specifiedSecondaryTables = new ArrayList<OrmSecondaryTable>(); - this.virtualSecondaryTables = new ArrayList<OrmSecondaryTable>(); - this.discriminatorColumn = buildDiscriminatorColumn(); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - this.defaultPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - this.associationOverrideContainer = buildAssociationOverrideContainer(); - this.attributeOverrideContainer = buildAttributeOverrideContainer(); - this.queryContainer = this.buildQueryContainer(); - this.generatorContainer = this.buildGeneratorContainer(); - this.specifiedName = this.resourceTypeMapping.getName(); - this.defaultName = this.buildDefaultName(); - this.rootEntity = this.calculateRootEntity(); - this.initializeInheritance(this.getResourceInheritance()); - this.specifiedDiscriminatorColumnIsAllowed = this.buildSpecifiedDiscriminatorColumnIsAllowed(); - this.discriminatorColumnIsUndefined = this.buildDiscriminatorColumnIsUndefined(); - this.discriminatorColumn.initialize(this.resourceTypeMapping); //TODO pass in to constructor - this.specifiedDiscriminatorValueIsAllowed = this.buildSpecifiedDiscriminatorValueIsAllowed(); - this.discriminatorValueIsUndefined = this.buildDiscriminatorValueIsUndefined(); - this.specifiedDiscriminatorValue = this.resourceTypeMapping.getDiscriminatorValue(); - this.defaultDiscriminatorValue = this.buildDefaultDiscriminatorValue(); - this.specifiedTableIsAllowed = this.buildSpecifiedTableIsAllowed(); - this.tableIsUndefined = this.buildTableIsUndefined(); - this.table.initialize(this.resourceTypeMapping);//TODO pass in to constructor - this.initializeSpecifiedSecondaryTables(); - this.initializeVirtualSecondaryTables(); - this.initializeSpecifiedPrimaryKeyJoinColumns(); - this.initializeDefaultPrimaryKeyJoinColumns(); - this.initializeIdClass(this.getResourceIdClass()); - } - - protected OrmDiscriminatorColumn buildDiscriminatorColumn() { - return getXmlContextNodeFactory().buildOrmDiscriminatorColumn(this, buildDiscriminatorColumnOwner()); - } - - protected OrmDiscriminatorColumn.Owner buildDiscriminatorColumnOwner() { - return new OrmDiscriminatorColumn.Owner(){ - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractOrmEntity.this.getDbTable(tableName); - } - - public TypeMapping getTypeMapping() { - return AbstractOrmEntity.this; - } - - public String getDefaultColumnName() { - if (getResourceTypeMapping().getDiscriminatorColumn() == null) { - if (!isMetadataComplete()) { - if (getJavaEntity() != null && getJavaEntity().getDiscriminatorColumn().getSpecifiedName() != null) { - return getJavaEntity().getDiscriminatorColumn().getSpecifiedName(); - } - } - } - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getName() - : - isTablePerClass() ? - null - : - DiscriminatorColumn.DEFAULT_NAME; - } - - public int getDefaultLength() { - if (getResourceTypeMapping().getDiscriminatorColumn() == null) { - if (!isMetadataComplete()) { - if (getJavaEntity() != null && getJavaEntity().getDiscriminatorColumn().getSpecifiedLength() != null) { - return getJavaEntity().getDiscriminatorColumn().getSpecifiedLength().intValue(); - } - } - } - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getLength() - : - isTablePerClass() ? - 0//TODO think i want to return null here - : - DiscriminatorColumn.DEFAULT_LENGTH; - } - - public DiscriminatorType getDefaultDiscriminatorType() { - if (getResourceTypeMapping().getDiscriminatorColumn() == null) { - if (!isMetadataComplete()) { - if (getJavaEntity() != null && getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType() != null) { - return getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType(); - } - } - } - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getDiscriminatorType() - : - isTablePerClass() ? - null - : - DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE; - } - - public TextRange getValidationTextRange() { - return AbstractOrmEntity.this.getValidationTextRange(); - } - }; - } - - protected OrmAssociationOverrideContainer buildAssociationOverrideContainer() { - return getXmlContextNodeFactory().buildOrmAssociationOverrideContainer(this, this, this.resourceTypeMapping); - } - - protected OrmAttributeOverrideContainer buildAttributeOverrideContainer() { - return getXmlContextNodeFactory().buildOrmAttributeOverrideContainer(this, this, this.resourceTypeMapping); - } - - protected OrmGeneratorContainer buildGeneratorContainer() { - return getXmlContextNodeFactory().buildOrmGeneratorContainer(this, this.resourceTypeMapping); - } - - protected OrmQueryContainer buildQueryContainer() { - return getXmlContextNodeFactory().buildOrmQueryContainer(this, this.resourceTypeMapping); - } - - - // ******************* TypeMapping implementation ******************** - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - @Override - public String getPrimaryTableName() { - return this.table.getName(); - } - - @Override - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return this.table.getDbTable(); - } - - private static final org.eclipse.jpt.db.Table[] EMPTY_DB_TABLE_ARRAY = new org.eclipse.jpt.db.Table[0]; - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - // the JPA platform searches database objects for us - return this.getDataSource().selectDatabaseObjectForIdentifier( - ArrayTools.array(this.associatedDbTablesIncludingInherited(), EMPTY_DB_TABLE_ARRAY), - tableName - ); - } - - private Iterator<org.eclipse.jpt.db.Table> associatedDbTablesIncludingInherited() { - return new FilteringIterator<org.eclipse.jpt.db.Table, org.eclipse.jpt.db.Table>(this.associatedDbTablesIncludingInherited_()) { - @Override - protected boolean accept(org.eclipse.jpt.db.Table t) { - return t != null; - } - }; - } - - private Iterator<org.eclipse.jpt.db.Table> associatedDbTablesIncludingInherited_() { - return new TransformationIterator<Table, org.eclipse.jpt.db.Table>(this.associatedTablesIncludingInherited()) { - @Override - protected org.eclipse.jpt.db.Table transform(Table t) { - return t.getDbTable(); - } - }; - } - - @Override - public Schema getDbSchema() { - return this.table.getDbSchema(); - } - - public JavaEntity getJavaEntity() { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (JavaEntity) javaPersistentType.getMapping(); - } - return null; - } - - /** - * This checks metaDataComplete before returning the JavaEntity. - * As far as defaults are concerned, if metadataComplete is true, the JavaEntity is ignored. - */ - protected JavaEntity getJavaEntityForDefaults() { - if (isMetadataComplete()) { - return null; - } - return getJavaEntity(); - } - - - //****************** OrmAttributeOverrideContainer.Owner implementation ******************* - - public PersistentType getOverridablePersistentType() { - return getPersistentType().getSuperPersistentType(); - } - - public OrmTypeMapping getTypeMapping() { - return this; - } - - public XmlColumn buildVirtualXmlColumn(ColumnMapping overridableColumnMapping) { - JavaAttributeOverride javaAttributeOverride = getJavaAttributeOverrideNamed(overridableColumnMapping.getName()); - if (javaAttributeOverride == null) { - return new VirtualXmlAttributeOverrideColumn(overridableColumnMapping.getColumn()); - } - return new VirtualXmlColumn(this, javaAttributeOverride.getColumn()); - } - - protected JavaAttributeOverride getJavaAttributeOverrideNamed(String attributeName) { - if (getJavaEntity() != null) { - return getJavaEntity().getAttributeOverrideContainer().getAttributeOverrideNamed(attributeName); - } - return null; - } - - //****************** OrmAssociationOverrideContainer.Owner implementation ******************* - - public RelationshipReference getOverridableRelationshipReference(RelationshipMapping overridableAssociation) { - JavaAssociationOverride javaAssociationOverride = getJavaAssociationOverrideNamed(overridableAssociation.getName()); - if (javaAssociationOverride == null || javaAssociationOverride.isVirtual()) { - return overridableAssociation.getRelationshipReference(); - } - return javaAssociationOverride.getRelationshipReference(); - } - - protected JavaAssociationOverride getJavaAssociationOverrideNamed(String attributeName) { - if (getJavaEntity() != null) { - return getJavaEntity().getAssociationOverrideContainer().getAssociationOverrideNamed(attributeName); - } - 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.resourceTypeMapping.setName(newSpecifiedName); - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public OrmTable getTable() { - return this.table; - } - - public ListIterator<OrmSecondaryTable> secondaryTables() { - if (specifiedSecondaryTablesSize() > 0) { - return specifiedSecondaryTables(); - } - return virtualSecondaryTables(); - } - - public int secondaryTablesSize() { - if (specifiedSecondaryTablesSize() > 0) { - return specifiedSecondaryTablesSize(); - } - return virtualSecondaryTablesSize(); - } - - public ListIterator<OrmSecondaryTable> virtualSecondaryTables() { - return new CloneListIterator<OrmSecondaryTable>(this.virtualSecondaryTables); - } - - public int virtualSecondaryTablesSize() { - return this.virtualSecondaryTables.size(); - } - - protected void addVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - addItemToList(secondaryTable, this.virtualSecondaryTables, OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST); - } - - protected void removeVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.virtualSecondaryTables, OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST); - } - - public ListIterator<OrmSecondaryTable> specifiedSecondaryTables() { - return new CloneListIterator<OrmSecondaryTable>(this.specifiedSecondaryTables); - } - - public int specifiedSecondaryTablesSize() { - return this.specifiedSecondaryTables.size(); - } - - public OrmSecondaryTable addSpecifiedSecondaryTable(int index) { - if (!secondaryTablesDefinedInXml()) { - throw new IllegalStateException("Virtual secondary tables exist, must first call setSecondaryTablesDefinedInXml(true)"); //$NON-NLS-1$ - } - XmlSecondaryTable secondaryTableResource = OrmFactory.eINSTANCE.createXmlSecondaryTable(); - OrmSecondaryTable secondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(index, secondaryTable); - this.resourceTypeMapping.getSecondaryTables().add(index, secondaryTableResource); - fireItemAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); - return secondaryTable; - } - - public OrmSecondaryTable addSpecifiedSecondaryTable() { - return this.addSpecifiedSecondaryTable(this.specifiedSecondaryTables.size()); - } - - protected void addSpecifiedSecondaryTable(int index, OrmSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - protected void addSpecifiedSecondaryTable(OrmSecondaryTable secondaryTable) { - this.addSpecifiedSecondaryTable(this.specifiedSecondaryTables.size(), secondaryTable); - } - - public void removeSpecifiedSecondaryTable(SecondaryTable secondaryTable) { - this.removeSpecifiedSecondaryTable(this.specifiedSecondaryTables.indexOf(secondaryTable)); - } - - public void removeSpecifiedSecondaryTable(int index) { - OrmSecondaryTable removedSecondaryTable = this.specifiedSecondaryTables.remove(index); - this.resourceTypeMapping.getSecondaryTables().remove(index); - fireItemRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, removedSecondaryTable); - } - - protected void removeSpecifiedSecondaryTable_(OrmSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void moveSpecifiedSecondaryTable(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedSecondaryTables, targetIndex, sourceIndex); - this.resourceTypeMapping.getSecondaryTables().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, targetIndex, sourceIndex); - } - - public boolean containsSecondaryTable(String name) { - return containsSecondaryTable(name, secondaryTables()); - } - - public boolean containsSpecifiedSecondaryTable(String name) { - return containsSecondaryTable(name, specifiedSecondaryTables()); - } - - public boolean containsVirtualSecondaryTable(String name) { - return containsSecondaryTable(name, virtualSecondaryTables()); - } - - public boolean containsVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - return this.virtualSecondaryTables.contains(secondaryTable); - } - - protected boolean containsSecondaryTable(String name, ListIterator<OrmSecondaryTable> secondaryTables) { - for (OrmSecondaryTable secondaryTable : CollectionTools.iterable(secondaryTables)) { - String secondaryTableName = secondaryTable.getName(); - if (secondaryTableName != null && secondaryTableName.equals(name)) { - return true; - } - } - return false; - } - - public boolean secondaryTablesDefinedInXml() { - return virtualSecondaryTablesSize() == 0; - } - - public void setSecondaryTablesDefinedInXml(boolean defineInXml) { - if (defineInXml == secondaryTablesDefinedInXml()) { - return; - } - if (defineInXml) { - specifySecondaryTablesInXml(); - } - else { - removeSecondaryTablesFromXml(); - } - } - - /** - * This is used to take all the java secondary tables and specify them in the xml. You must - * use setSecondaryTablesDefinedInXml(boolean) before calling addSpecifiedSecondaryTable(). - * - * Yes this code looks odd, but be careful making changes to it - */ - protected void specifySecondaryTablesInXml() { - if (virtualSecondaryTablesSize() != 0) { - List<OrmSecondaryTable> virtualSecondaryTables1 = CollectionTools.list(this.virtualSecondaryTables()); - List<OrmSecondaryTable> virtualSecondaryTables2 = CollectionTools.list(this.virtualSecondaryTables()); - //remove all the virtual secondary tables without firing change notification. - for (OrmSecondaryTable virtualSecondaryTable : CollectionTools.iterable(virtualSecondaryTables())) { - this.virtualSecondaryTables.remove(virtualSecondaryTable); - } - //add specified secondary tables for each virtual secondary table. If the virtual secondary tables - //are not removed first, they will be removed as a side effect of adding the first specified secondary table. - //This screws up the change notification to the UI, since that change notification is in a different thread - for (OrmSecondaryTable virtualSecondaryTable : virtualSecondaryTables2) { - XmlSecondaryTable secondaryTableResource = OrmFactory.eINSTANCE.createXmlSecondaryTable(); - OrmSecondaryTable specifiedSecondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(specifiedSecondaryTable); - this.resourceTypeMapping.getSecondaryTables().add(secondaryTableResource); - specifiedSecondaryTable.initializeFrom(virtualSecondaryTable); - } - //fire change notification at the end - fireItemsRemoved(OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST, 0, virtualSecondaryTables1); - fireItemsAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, 0, this.specifiedSecondaryTables); - } - } - - protected void removeSecondaryTablesFromXml() { - if (specifiedSecondaryTablesSize() != 0) { - List<OrmSecondaryTable> specifiedSecondaryTablesCopy = CollectionTools.list(this.specifiedSecondaryTables()); - for (OrmSecondaryTable specifiedSecondaryTable : CollectionTools.iterable(specifiedSecondaryTables())) { - int index = this.specifiedSecondaryTables.indexOf(specifiedSecondaryTable); - this.specifiedSecondaryTables.remove(specifiedSecondaryTable); - if (this.specifiedSecondaryTables.size() == 0) { - initializeVirtualSecondaryTables(); - } - this.resourceTypeMapping.getSecondaryTables().remove(index); - } - fireItemsRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, 0, specifiedSecondaryTablesCopy); - if (this.virtualSecondaryTables.size() != 0) { - fireItemsAdded(OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST, 0, this.virtualSecondaryTables); - } - } - } - - protected Iterator<String> tableNames(Iterator<Table> tables) { - return new TransformationIterator<Table, String>(tables) { - @Override - protected String transform(Table t) { - return t.getName(); - } - }; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return this.nonNullTableNames(this.associatedTablesIncludingInherited()); - } - - protected Iterator<String> nonNullTableNames(Iterator<Table> tables) { - return new FilteringIterator<String, String>(this.tableNames(tables)) { - @Override - protected boolean accept(String o) { - return o != null; - } - }; - } - - public Iterator<Table> associatedTables() { - return new CompositeIterator<Table>(this.table, this.secondaryTables()); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return 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); - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return super.shouldValidateAgainstDatabase() && ! isAbstractTablePerClass(); - } - - public InheritanceType getInheritanceStrategy() { - return (this.getSpecifiedInheritanceStrategy() == null) ? this.getDefaultInheritanceStrategy() : this.getSpecifiedInheritanceStrategy(); - } - - public InheritanceType getDefaultInheritanceStrategy() { - return this.defaultInheritanceStrategy; - } - - protected void setDefaultInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.defaultInheritanceStrategy; - this.defaultInheritanceStrategy = newInheritanceType; - firePropertyChanged(DEFAULT_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - public InheritanceType getSpecifiedInheritanceStrategy() { - return this.specifiedInheritanceStrategy; - } - - public void setSpecifiedInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - if (oldInheritanceType != newInheritanceType) { - if (this.getResourceInheritance() != null) { - this.getResourceInheritance().setStrategy(InheritanceType.toOrmResourceModel(newInheritanceType)); - if (this.getResourceInheritance().isUnset()) { - removeResourceInheritance(); - } - } - else if (newInheritanceType != null) { - addResourceInheritance(); - getResourceInheritance().setStrategy(InheritanceType.toOrmResourceModel(newInheritanceType)); - } - } - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - protected void setSpecifiedInheritanceStrategy_(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - protected Inheritance getResourceInheritance() { - return this.resourceTypeMapping.getInheritance(); - } - - protected void addResourceInheritance() { - this.resourceTypeMapping.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - } - - protected void removeResourceInheritance() { - this.resourceTypeMapping.setInheritance(null); - } - - public OrmDiscriminatorColumn getDiscriminatorColumn() { - return this.discriminatorColumn; - } - - public OrmGeneratorContainer getGeneratorContainer() { - return this.generatorContainer; - } - - public String getDefaultDiscriminatorValue() { - return this.defaultDiscriminatorValue; - } - - protected void setDefaultDiscriminatorValue(String newDefaultDiscriminatorValue) { - String oldDefaultDiscriminatorValue = this.defaultDiscriminatorValue; - this.defaultDiscriminatorValue = newDefaultDiscriminatorValue; - firePropertyChanged(DEFAULT_DISCRIMINATOR_VALUE_PROPERTY, oldDefaultDiscriminatorValue, newDefaultDiscriminatorValue); - } - - public String getSpecifiedDiscriminatorValue() { - return this.specifiedDiscriminatorValue; - } - - public void setSpecifiedDiscriminatorValue(String newSpecifiedDiscriminatorValue) { - String oldSpecifiedDiscriminatorValue = this.specifiedDiscriminatorValue; - this.specifiedDiscriminatorValue = newSpecifiedDiscriminatorValue; - this.resourceTypeMapping.setDiscriminatorValue(newSpecifiedDiscriminatorValue); - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - public String getDiscriminatorValue() { - return (this.getSpecifiedDiscriminatorValue() == null) ? getDefaultDiscriminatorValue() : this.getSpecifiedDiscriminatorValue(); - } - - public boolean specifiedDiscriminatorValueIsAllowed() { - return this.specifiedDiscriminatorValueIsAllowed; - } - - protected void setSpecifiedDiscriminatorValueIsAllowed(boolean specifiedDiscriminatorValueIsAllowed) { - boolean old = this.specifiedDiscriminatorValueIsAllowed; - this.specifiedDiscriminatorValueIsAllowed = specifiedDiscriminatorValueIsAllowed; - firePropertyChanged(Entity.SPECIFIED_DISCRIMINATOR_VALUE_IS_ALLOWED_PROPERTY, old, specifiedDiscriminatorValueIsAllowed); - } - - public boolean discriminatorValueIsUndefined() { - return this.discriminatorValueIsUndefined; - } - - protected void setDiscriminatorValueIsUndefined(boolean discriminatorValueIsUndefined) { - boolean old = this.discriminatorValueIsUndefined; - this.discriminatorValueIsUndefined = discriminatorValueIsUndefined; - firePropertyChanged(Entity.DISCRIMINATOR_VALUE_IS_UNDEFINED_PROPERTY, old, discriminatorValueIsUndefined); - } - - public boolean specifiedDiscriminatorColumnIsAllowed() { - return this.specifiedDiscriminatorColumnIsAllowed; - } - - protected void setSpecifiedDiscriminatorColumnIsAllowed(boolean specifiedDiscriminatorColumnIsAllowed) { - boolean old = this.specifiedDiscriminatorColumnIsAllowed; - this.specifiedDiscriminatorColumnIsAllowed = specifiedDiscriminatorColumnIsAllowed; - firePropertyChanged(Entity.SPECIFIED_DISCRIMINATOR_COLUMN_IS_ALLOWED_PROPERTY, old, specifiedDiscriminatorColumnIsAllowed); - } - - public boolean discriminatorColumnIsUndefined() { - return this.discriminatorColumnIsUndefined; - } - - protected void setDiscriminatorColumnIsUndefined(boolean discriminatorColumnIsUndefined) { - boolean old = this.discriminatorColumnIsUndefined; - this.discriminatorColumnIsUndefined = discriminatorColumnIsUndefined; - firePropertyChanged(Entity.DISCRIMINATOR_COLUMN_IS_UNDEFINED_PROPERTY, old, discriminatorColumnIsUndefined); - } - - - public boolean specifiedTableIsAllowed() { - return this.specifiedTableIsAllowed; - } - - protected void setSpecifiedTableIsAllowed(boolean specifiedTableIsAllowed) { - boolean old = this.specifiedTableIsAllowed; - this.specifiedTableIsAllowed = specifiedTableIsAllowed; - firePropertyChanged(Entity.SPECIFIED_TABLE_IS_ALLOWED_PROPERTY, old, specifiedTableIsAllowed); - } - - public boolean tableIsUndefined() { - return this.tableIsUndefined; - } - - protected void setTableIsUndefined(boolean tableIsUndefined) { - boolean old = this.tableIsUndefined; - this.tableIsUndefined = tableIsUndefined; - firePropertyChanged(Entity.TABLE_IS_UNDEFINED_PROPERTY, old, tableIsUndefined); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumns); - } - - public int defaultPrimaryKeyJoinColumnsSize() { - return this.defaultPrimaryKeyJoinColumns.size(); - } - - public OrmPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - throw new UnsupportedOperationException("use defaultPrimaryKeyJoinColumns() instead"); //$NON-NLS-1$ - } - - protected void addDefaultPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn defaultPkJoinColumn) { - addItemToList(defaultPkJoinColumn, this.defaultPrimaryKeyJoinColumns, OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void removeDefaultPrimaryKeyJoinColumn(PrimaryKeyJoinColumn defaultPkJoinColumn) { - removeItemFromList(defaultPkJoinColumn, this.defaultPrimaryKeyJoinColumns, OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.specifiedPrimaryKeyJoinColumns.isEmpty() ? this.defaultPrimaryKeyJoinColumns() : this.specifiedPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.isEmpty() ? this.defaultPrimaryKeyJoinColumnsSize() : this.specifiedPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public OrmPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - if (!this.defaultPrimaryKeyJoinColumns.isEmpty()) { - this.defaultPrimaryKeyJoinColumns.clear(); - } - XmlPrimaryKeyJoinColumn resourcePkJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(); - OrmPrimaryKeyJoinColumn contextPkJoinColumn = buildPrimaryKeyJoinColumn(resourcePkJoinColumn); - this.specifiedPrimaryKeyJoinColumns.add(index, contextPkJoinColumn); - this.resourceTypeMapping.getPrimaryKeyJoinColumns().add(index, resourcePkJoinColumn); - - this.fireItemAdded(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, contextPkJoinColumn); - this.fireListCleared(OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - return contextPkJoinColumn; - } - - protected OrmBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.addSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.size(), primaryKeyJoinColumn); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(primaryKeyJoinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPrimaryKeyJoinColumn = this.specifiedPrimaryKeyJoinColumns.remove(index); - if (!containsSpecifiedPrimaryKeyJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - initializeDefaultPrimaryKeyJoinColumns(); - } - this.resourceTypeMapping.getPrimaryKeyJoinColumns().remove(index); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (!this.defaultPrimaryKeyJoinColumns.isEmpty()) { - fireListChanged(OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST, this.defaultPrimaryKeyJoinColumns); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.resourceTypeMapping.getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public OrmAttributeOverrideContainer getAttributeOverrideContainer() { - return this.attributeOverrideContainer; - } - - public OrmAssociationOverrideContainer getAssociationOverrideContainer() { - return this.associationOverrideContainer; - } - - public OrmQueryContainer getQueryContainer() { - return this.queryContainer; - } - - public char getIdClassEnclosingTypeSeparator() { - return '$'; - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (this.attributeValueHasChanged(oldIdClass, newIdClass)) { - if (this.getResourceIdClass() != null) { - this.getResourceIdClass().setClassName(newIdClass); - if (this.getResourceIdClass().isUnset()) { - removeResourceIdClass(); - } - } - else if (newIdClass != null) { - addResourceIdClass(); - getResourceIdClass().setClassName(newIdClass); - } - } - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected XmlIdClass getResourceIdClass() { - return this.resourceTypeMapping.getIdClass(); - } - - protected void addResourceIdClass() { - this.resourceTypeMapping.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - } - - protected void removeResourceIdClass() { - this.resourceTypeMapping.setIdClass(null); - } - - public Entity getParentEntity() { - for (Iterator<PersistentType> stream = getPersistentType().ancestors(); stream.hasNext();) { - TypeMapping tm = stream.next().getMapping(); - if (tm instanceof Entity) { - return (Entity) tm; - } - } - return this; - } - - /** - * Return the ultimate top of the inheritance hierarchy - * This method should never return null. The root - * is defined as the persistent type in the inheritance hierarchy - * that has no parent. The root should be an entity - * - * Non-entities in the hierarchy should be ignored, ie skip - * over them in the search for the root. - */ - protected Entity getRootEntity() { - return this.rootEntity; - } - - public String getDefaultTableName() { - JavaEntity javaEntity = this.getJavaEntity(); - if (javaEntity != null) { - JavaTable javaTable = javaEntity.getTable(); - if ( ! this.isMetadataComplete() - && ! this.table.isResourceSpecified() - && javaTable.getSpecifiedName() != null) { - return javaTable.getSpecifiedName(); - } - } - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getName() - : - this.isAbstractTablePerClass() ? - null - : - this.getName(); - } - - public String getDefaultSchema() { - JavaEntity javaEntity = this.getJavaEntity(); - if (javaEntity != null) { - JavaTable javaTable = javaEntity.getTable(); - if ( ! this.isMetadataComplete() - && ! this.table.isResourceSpecified() - && javaTable.getSpecifiedSchema() != null) { - return javaTable.getSpecifiedSchema(); - } - } - - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getSchema() - : - this.isAbstractTablePerClass() ? - null - : - this.getContextDefaultSchema(); - } - - public String getDefaultCatalog() { - JavaEntity javaEntity = this.getJavaEntity(); - if (javaEntity != null) { - JavaTable javaTable = javaEntity.getTable(); - if ( ! this.isMetadataComplete() - && ! this.table.isResourceSpecified() - && javaTable.getSpecifiedCatalog() != null) { - return javaTable.getSpecifiedCatalog(); - } - } - - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getCatalog() - : - this.isAbstractTablePerClass() ? - null - : - this.getContextDefaultCatalog(); - } - - /** - * Return whether the entity is a descendant of the root entity - * of a "single table" inheritance hierarchy. - */ - protected boolean isSingleTableDescendant() { - return this.isDescendant() && (this.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE); - } - - /** - * Return whether the entity is a descendant in (as opposed to the root of) - * an inheritance hierarchy. - */ - protected boolean isDescendant() { - return ! this.isRoot(); - } - - /** - * Return whether the entity is the top of an inheritance hierarchy. - */ - protected boolean isRoot() { - return this == this.getRootEntity(); - } - - /** - * Return whether the entity is the top of an inheritance hierarchy - * and has no descendants and no specified inheritance strategy has been defined. - */ - protected boolean isRootNoDescendantsNoStrategyDefined() { - return isRoot() && !getPersistenceUnit().isRootWithSubEntities(this.getName()) && getSpecifiedInheritanceStrategy() == null; - } - - /** - * Return whether the entity is abstract and is a part of a - * "table per class" inheritance hierarchy. - */ - protected boolean isAbstractTablePerClass() { - return isAbstract() && isTablePerClass(); - } - - /** - * Return whether the entity is a part of a "table per class" - * inheritance hierarchy. - */ - protected boolean isTablePerClass() { - return (this.getInheritanceStrategy() == InheritanceType.TABLE_PER_CLASS); - } - - /** - * Return whether the type is abstract, false if no java type exists. - */ - protected boolean isAbstract() { - JavaResourcePersistentType javaResourcePersistentType = getJavaResourcePersistentType(); - return javaResourcePersistentType == null ? false : javaResourcePersistentType.isAbstract(); - } - -// public String primaryKeyColumnName() { -// String pkColumnName = null; -// for (Iterator<IPersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { -// IPersistentAttribute attribute = stream.next(); -// String name = attribute.primaryKeyColumnName(); -// if (pkColumnName == null) { -// pkColumnName = name; -// } -// else if (name != null) { -// // if we encounter a composite primary key, return null -// return null; -// } -// } -// // if we encounter only a single primary key column name, return it -// return pkColumnName; -// } -// -// public String primaryKeyAttributeName() { -// String pkColumnName = null; -// String pkAttributeName = null; -// for (Iterator<IPersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { -// IPersistentAttribute attribute = stream.next(); -// String name = attribute.primaryKeyColumnName(); -// if (pkColumnName == null) { -// pkColumnName = name; -// pkAttributeName = attribute.getName(); -// } -// else if (name != null) { -// // if we encounter a composite primary key, return null -// return null; -// } -// } -// // if we encounter only a single primary key column name, return it -// return pkAttributeName; -// } -// - - - public int getXmlSequence() { - return 1; - } - - /** - * Return an iterator of Entities, each which inherits from the one before, - * and terminates at the root entity (or at the point of cyclicity). - */ - protected Iterator<TypeMapping> inheritanceHierarchy() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().inheritanceHierarchy()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - /** - * Return an iterator of Entities, each which inherits from the one before, - * and terminates at the root entity (or at the point of cyclicity). - */ - protected Iterator<TypeMapping> ancestors() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().ancestors()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - @Override - public Iterator<OrmColumnMapping> overridableAttributes() { - if (!isTablePerClass()) { - return EmptyIterator.instance(); - } - return new FilteringIterator<OrmAttributeMapping, OrmColumnMapping>(this.attributeMappings()) { - @Override - protected boolean accept(OrmAttributeMapping o) { - return o.isOverridableAttributeMapping(); - } - }; - } - - @Override - public Iterator<OrmRelationshipMapping> overridableAssociations() { - if (!isTablePerClass()) { - return EmptyIterator.instance(); - } - return new FilteringIterator<OrmAttributeMapping, OrmRelationshipMapping>(this.attributeMappings()) { - @Override - protected boolean accept(OrmAttributeMapping o) { - return o.isOverridableAssociationMapping(); - } - }; - } - - @Override - public Iterator<ColumnMapping> allOverridableAttributes() { - return new CompositeIterator<ColumnMapping>(new TransformationIterator<TypeMapping, Iterator<ColumnMapping>>(this.ancestors()) { - @Override - protected Iterator<ColumnMapping> transform(TypeMapping mapping) { - return mapping.overridableAttributes(); - } - }); - } - - @Override - public Iterator<RelationshipMapping> allOverridableAssociations() { - return new CompositeIterator<RelationshipMapping>(new TransformationIterator<TypeMapping, Iterator<RelationshipMapping>>(this.ancestors()) { - @Override - protected Iterator<RelationshipMapping> transform(TypeMapping mapping) { - return mapping.overridableAssociations(); - } - }); - } - -// -// public IAttributeOverride createAttributeOverride(int index) { -// return OrmFactory.eINSTANCE.createXmlAttributeOverride(new IEntity.AttributeOverrideOwner(this)); -// } -// -// public IAssociationOverride createAssociationOverride(int index) { -// return OrmFactory.eINSTANCE.createXmlAssociationOverride(new IEntity.AssociationOverrideOwner(this)); -// } -// -// public IAttributeOverride attributeOverrideNamed(String name) { -// return (IAttributeOverride) overrideNamed(name, getAttributeOverrides()); -// } -// -// public boolean containsAttributeOverride(String name) { -// return containsOverride(name, getAttributeOverrides()); -// } -// -// public boolean containsSpecifiedAttributeOverride(String name) { -// return containsOverride(name, getSpecifiedAttributeOverrides()); -// } -// -// public boolean containsAssociationOverride(String name) { -// return containsOverride(name, getAssociationOverrides()); -// } -// -// public boolean containsSpecifiedAssociationOverride(String name) { -// return containsOverride(name, getSpecifiedAssociationOverrides()); -// } -// -// private IOverride overrideNamed(String name, List<? extends IOverride> overrides) { -// for (IOverride override : overrides) { -// String overrideName = override.getName(); -// if (overrideName == null && name == null) { -// return override; -// } -// if (overrideName != null && overrideName.equals(name)) { -// return override; -// } -// } -// return null; -// } -// -// private boolean containsOverride(String name, List<? extends IOverride> overrides) { -// return overrideNamed(name, overrides) != null; -// } -// -// public boolean containsSpecifiedPrimaryKeyJoinColumns() { -// return !this.getSpecifiedPrimaryKeyJoinColumns().isEmpty(); -// } - - - protected void initializeInheritance(Inheritance inheritanceResource) { - this.specifiedInheritanceStrategy = this.getResourceInheritanceStrategy(inheritanceResource); - //no need to initialize defaultInheritanceStrategy, need to get all the persistentTypes in the model first - } - - protected void initializeSpecifiedSecondaryTables() { - for (XmlSecondaryTable secondaryTable : this.resourceTypeMapping.getSecondaryTables()) { - this.specifiedSecondaryTables.add(buildSecondaryTable(secondaryTable)); - } - } - - protected void initializeVirtualSecondaryTables() { - if (isMetadataComplete()) { - return; - } - if (getJavaEntity() == null) { - return; - } - if (specifiedSecondaryTablesSize() > 0) { - return; - } - ListIterator<JavaSecondaryTable> javaSecondaryTables = getJavaEntity().secondaryTables(); - while(javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - if (javaSecondaryTable.getName() != null) { - this.virtualSecondaryTables.add(buildVirtualSecondaryTable(javaSecondaryTable)); - } - } - } - - protected void initializeDefaultPrimaryKeyJoinColumns() { - if (isMetadataComplete()) { - return; - } - if (getJavaEntity() == null) { - this.defaultPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(null)); - return; - } - if (specifiedPrimaryKeyJoinColumnsSize() > 0) { - return; - } - ListIterator<JavaPrimaryKeyJoinColumn> javaPkJoinColumns = getJavaEntity().primaryKeyJoinColumns(); - while(javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - if (javaPkJoinColumn.getName() != null) { - this.defaultPrimaryKeyJoinColumns.add(buildVirtualPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - } - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns() { - for (XmlPrimaryKeyJoinColumn resourcePkJoinColumn : this.resourceTypeMapping.getPrimaryKeyJoinColumns()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(resourcePkJoinColumn)); - } - } - - protected void initializeIdClass(XmlIdClass idClassResource) { - this.idClass = this.getResourceIdClass(idClassResource); - } - - protected String getResourceIdClass(XmlIdClass idClassResource) { - return idClassResource == null ? null : idClassResource.getClassName(); - } - - @Override - public void update() { - super.update(); - this.setSpecifiedName(this.resourceTypeMapping.getName()); - this.setDefaultName(this.buildDefaultName()); - this.updateInheritance(this.getResourceInheritance()); - this.updateRootEntity(); - this.updateDiscriminatorColumn(); - this.updateDiscriminatorValue(); - this.setSpecifiedTableIsAllowed(this.buildSpecifiedTableIsAllowed()); - this.setTableIsUndefined(this.buildTableIsUndefined()); - this.table.update(this.resourceTypeMapping); - this.updateSpecifiedSecondaryTables(); - this.updateVirtualSecondaryTables(); - this.generatorContainer.update(); - this.updateSpecifiedPrimaryKeyJoinColumns(); - this.updateDefaultPrimaryKeyJoinColumns(); - getAttributeOverrideContainer().update(); - getAssociationOverrideContainer().update(); - getQueryContainer().update(); - this.updateIdClass(this.getResourceIdClass()); - } - - @Override - public void postUpdate() { - super.postUpdate(); - this.postUpdateDiscriminatorColumn(); - this.postUpdateDiscriminatorValue(); - } - - protected String buildDefaultName() { - if (!isMetadataComplete()) { - JavaEntity javaEntity = getJavaEntity(); - if (javaEntity != null) { - return javaEntity.getName(); - } - } - String className = getClass_(); - if (className != null) { - return ClassTools.shortNameForClassNamed(className); - } - return null; - } - - protected void updateDiscriminatorColumn() { - this.setSpecifiedDiscriminatorColumnIsAllowed(this.buildSpecifiedDiscriminatorColumnIsAllowed()); - getDiscriminatorColumn().update(this.resourceTypeMapping); - } - - protected void postUpdateDiscriminatorColumn() { - this.setDiscriminatorColumnIsUndefined(this.buildDiscriminatorColumnIsUndefined()); - this.getDiscriminatorColumn().postUpdate(); - } - - protected void updateDiscriminatorValue() { - this.setSpecifiedDiscriminatorValueIsAllowed(this.buildSpecifiedDiscriminatorValueIsAllowed()); - this.setSpecifiedDiscriminatorValue(this.resourceTypeMapping.getDiscriminatorValue()); - } - - protected void postUpdateDiscriminatorValue() { - this.setDiscriminatorValueIsUndefined(this.buildDiscriminatorValueIsUndefined()); - this.setDefaultDiscriminatorValue(this.buildDefaultDiscriminatorValue()); - } - - /** - * From the Spec: - * If the DiscriminatorValue annotation is not specified, a - * provider-specific function to generate a value representing - * the entity type is used for the value of the discriminator - * column. If the DiscriminatorType is STRING, the discriminator - * value default is the entity name. - * - * TODO extension point for provider-specific function? - */ - protected String buildDefaultDiscriminatorValue() { - if (!isMetadataComplete() && getJavaEntity() != null) { - return getJavaEntity().getDiscriminatorValue(); - } - if (discriminatorValueIsUndefined()) { - return null; - } - if (this.getDiscriminatorType() != DiscriminatorType.STRING) { - return null; - } - return this.getName(); - } - - protected DiscriminatorType getDiscriminatorType() { - return this.getDiscriminatorColumn().getDiscriminatorType(); - } - - protected JavaResourcePersistentType getJavaResourcePersistentType() { - if (getPersistentType().getJavaPersistentType() != null) { - return getPersistentType().getJavaPersistentType().getResourcePersistentType(); - } - return null; - } - - protected boolean buildSpecifiedDiscriminatorValueIsAllowed() { - return !isTablePerClass() && !isAbstract(); - } - - protected boolean buildDiscriminatorValueIsUndefined() { - return isTablePerClass() || isAbstract() || isRootNoDescendantsNoStrategyDefined(); - } - - protected boolean buildSpecifiedDiscriminatorColumnIsAllowed() { - return !isTablePerClass() && isRoot(); - } - - protected boolean buildDiscriminatorColumnIsUndefined() { - return isTablePerClass() || isRootNoDescendantsNoStrategyDefined(); - } - - protected boolean buildSpecifiedTableIsAllowed() { - return !isAbstractTablePerClass() && !isSingleTableDescendant(); - } - - protected boolean buildTableIsUndefined() { - return isAbstractTablePerClass(); - } - - - protected void updateInheritance(Inheritance inheritanceResource) { - this.setSpecifiedInheritanceStrategy_(this.getResourceInheritanceStrategy(inheritanceResource)); - this.setDefaultInheritanceStrategy(this.buildDefaultInheritanceStrategy()); - } - - protected void updateRootEntity() { - //I am making an assumption here that we don't need property change notification for rootEntity, this might be wrong - this.rootEntity = calculateRootEntity(); - if (this.rootEntity != this) { - this.rootEntity.addSubEntity(this); - } - } - - protected Entity calculateRootEntity() { - Entity rootEntity = this; - for (Iterator<PersistentType> stream = getPersistentType().inheritanceHierarchy(); stream.hasNext();) { - PersistentType persistentType = stream.next(); - if (persistentType.getMapping() instanceof Entity) { - rootEntity = (Entity) persistentType.getMapping(); - } - } - return rootEntity; - } - - public void addSubEntity(Entity subEntity) { - getPersistenceUnit().addRootWithSubEntities(getName()); - } - - protected void updateSpecifiedSecondaryTables() { - // make a copy of the XML tables (to prevent ConcurrentModificationException) - Iterator<XmlSecondaryTable> xmlTables = new CloneIterator<XmlSecondaryTable>(this.resourceTypeMapping.getSecondaryTables()); - - for (Iterator<OrmSecondaryTable> contextTables = this.specifiedSecondaryTables(); contextTables.hasNext(); ) { - OrmSecondaryTable contextTable = contextTables.next(); - if (xmlTables.hasNext()) { - contextTable.update(xmlTables.next()); - } - else { - removeSpecifiedSecondaryTable_(contextTable); - } - } - - while (xmlTables.hasNext()) { - addSpecifiedSecondaryTable(buildSecondaryTable(xmlTables.next())); - } - } - - //if any secondary-tables are specified in the xml file, then all of the java secondaryTables are overriden - protected void updateVirtualSecondaryTables() { - ListIterator<OrmSecondaryTable> secondaryTables = virtualSecondaryTables(); - ListIterator<JavaSecondaryTable> javaSecondaryTables = EmptyListIterator.instance(); - - if (getJavaEntity() != null && !isMetadataComplete() && specifiedSecondaryTablesSize() == 0) { - javaSecondaryTables = getJavaEntity().secondaryTables(); - } - while (secondaryTables.hasNext()) { - OrmSecondaryTable virtualSecondaryTable = secondaryTables.next(); - if (javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - virtualSecondaryTable.update(new VirtualXmlSecondaryTable(javaSecondaryTable)); - } - else { - removeVirtualSecondaryTable(virtualSecondaryTable); - } - } - - while (javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - addVirtualSecondaryTable(buildVirtualSecondaryTable(javaSecondaryTable)); - } - } - - protected OrmSecondaryTable buildSecondaryTable(XmlSecondaryTable xmlSecondaryTable) { - return getXmlContextNodeFactory().buildOrmSecondaryTable(this, xmlSecondaryTable); - } - - protected OrmSecondaryTable buildVirtualSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - return buildSecondaryTable(new VirtualXmlSecondaryTable(javaSecondaryTable)); - } - - protected InheritanceType getResourceInheritanceStrategy(Inheritance inheritanceResource) { - if (inheritanceResource == null) { - return null; - } - return InheritanceType.fromOrmResourceModel(inheritanceResource.getStrategy()); - } - - protected InheritanceType buildDefaultInheritanceStrategy() { - if ((this.getResourceInheritance() == null) - && ! this.isMetadataComplete() - && (this.getJavaEntity() != null)) { - return this.getJavaEntity().getInheritanceStrategy(); - } - return this.isRoot() ? InheritanceType.SINGLE_TABLE : this.getRootEntity().getInheritanceStrategy(); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns() { - // make a copy of the XML join columns (to prevent ConcurrentModificationException) - Iterator<XmlPrimaryKeyJoinColumn> xmlPkJoinColumns = new CloneIterator<XmlPrimaryKeyJoinColumn>(this.resourceTypeMapping.getPrimaryKeyJoinColumns()); - - for (Iterator<OrmPrimaryKeyJoinColumn> contextPkJoinColumns = this.specifiedPrimaryKeyJoinColumns(); contextPkJoinColumns.hasNext(); ) { - OrmPrimaryKeyJoinColumn contextPkJoinColumn = contextPkJoinColumns.next(); - if (xmlPkJoinColumns.hasNext()) { - contextPkJoinColumn.update(xmlPkJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(contextPkJoinColumn); - } - } - - while (xmlPkJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(xmlPkJoinColumns.next())); - } - } - - //if there are any specified pkJoinColumns, then no default pkJoinColumns - //if the java has specified pkJoinColumns, then those are the default pkJoinColumns - //otherwise, just 1 pkJoinColumn, defaults being null if multiple primaryKey columns - protected void updateDefaultPrimaryKeyJoinColumns() { - ListIterator<OrmPrimaryKeyJoinColumn> defaultPkJoinColumns = defaultPrimaryKeyJoinColumns(); - ListIterator<JavaPrimaryKeyJoinColumn> javaPkJoinColumns = EmptyListIterator.instance(); - - if (getJavaEntity() != null && !isMetadataComplete() && specifiedPrimaryKeyJoinColumnsSize() == 0) { - javaPkJoinColumns = getJavaEntity().primaryKeyJoinColumns(); - } - while (defaultPkJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn defaultPkJoinColumn = defaultPkJoinColumns.next(); - if (javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - defaultPkJoinColumn.update(new VirtualXmlPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - else { - if (defaultPrimaryKeyJoinColumnsSize() == 1) { - defaultPkJoinColumn.update(null); - } - else { - removeDefaultPrimaryKeyJoinColumn(defaultPkJoinColumn); - } - } - } - - while (javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - addDefaultPrimaryKeyJoinColumn(buildVirtualPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - - if (defaultPrimaryKeyJoinColumnsSize() == 0 && specifiedPrimaryKeyJoinColumnsSize() == 0) { - addDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(null)); - } - } - - protected OrmPrimaryKeyJoinColumn buildVirtualPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn javaSecondaryTable) { - return buildPrimaryKeyJoinColumn(new VirtualXmlPrimaryKeyJoinColumn(javaSecondaryTable)); - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - return getXmlContextNodeFactory().buildOrmPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner(), resourcePkJoinColumn); - } - - protected void updateIdClass(XmlIdClass idClassResource) { - this.setIdClass_(this.getResourceIdClass(idClassResource)); - } - - - // ************************************************************************* - - 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 = getAttributeOverrideContainer().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; - } - - public void addToResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEntities().add(this.resourceTypeMapping); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEntities().remove(this.resourceTypeMapping); - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - this.validateTable(messages, reporter); - this.validateId(messages); - this.validateInheritance(messages, reporter); - this.generatorContainer.validate(messages, reporter); - this.queryContainer.validate(messages, reporter); - this.attributeOverrideContainer.validate(messages, reporter); - this.associationOverrideContainer.validate(messages, reporter); - - for (Iterator<OrmSecondaryTable> stream = this.secondaryTables(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); - } - } - - protected void validateTable(List<IMessage> messages, IReporter reporter) { - if (isAbstractTablePerClass()) { - if (this.table.isResourceSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE, - new String[] {this.getName()}, - this, - this.getTable().getValidationTextRange() - ) - ); - } - return; - } - if (isSingleTableDescendant()) { - if (this.table.isResourceSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE, - new String[] {this.getName()}, - this, - this.getTable().getValidationTextRange() - ) - ); - } - return; - } - this.table.validate(messages, reporter); - } - - protected void validateId(List<IMessage> messages) { - if (this.entityHasNoId()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NO_ID, - new String[] {this.getName()}, - this, - this.getValidationTextRange() - ) - ); - } - } - - protected void validateInheritance(List<IMessage> messages, IReporter reporter) { - validateInheritanceStrategy(messages); - validateDiscriminatorColumn(messages, reporter); - validateDiscriminatorValue(messages); - } - - protected void validateDiscriminatorColumn(List<IMessage> messages, IReporter reporter) { - if (specifiedDiscriminatorColumnIsAllowed() && !discriminatorColumnIsUndefined()) { - getDiscriminatorColumn().validate(messages, reporter); - } - else if (getDiscriminatorColumn().isResourceSpecified()) { - if (!isRoot()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorColumnTextRange() - ) - ); - } - else if (isTablePerClass()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorColumnTextRange() - ) - ); - - } - } - } - - protected void validateDiscriminatorValue(List<IMessage> messages) { - if (discriminatorValueIsUndefined() && getSpecifiedDiscriminatorValue() != null) { - if (isAbstract()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorValueTextRange() - ) - ); - } - else if (isTablePerClass()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorValueTextRange() - ) - ); - } - } - } - - protected void validateInheritanceStrategy(List<IMessage> messages) { - Supported tablePerConcreteClassInheritanceIsSupported = getJpaPlatformVariation().getTablePerConcreteClassInheritanceIsSupported(); - if (tablePerConcreteClassInheritanceIsSupported == Supported.YES) { - return; - } - if ((getInheritanceStrategy() == InheritanceType.TABLE_PER_CLASS) && isRoot()) { - if (tablePerConcreteClassInheritanceIsSupported == Supported.NO) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM, - new String[] {this.getName()}, - this, - this.getInheritanceStrategyTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM, - new String[] {this.getName()}, - this, - this.getInheritanceStrategyTextRange() - ) - ); - } - } - } - - protected TextRange getDiscriminatorValueTextRange() { - return this.resourceTypeMapping.getDiscriminatorValueTextRange(); - } - - protected TextRange getDiscriminatorColumnTextRange() { - return this.resourceTypeMapping.getDiscriminatorColumn().getValidationTextRange(); - } - - protected TextRange getInheritanceStrategyTextRange() { - return this.resourceTypeMapping.getInheritanceStrategyTextRange(); - } - - private boolean entityHasNoId() { - return ! this.entityHasId(); - } - - private boolean entityHasId() { - for (Iterator<PersistentAttribute> stream = this.getPersistentType().allAttributes(); stream.hasNext(); ) { - if (stream.next().isIdAttribute()) { - return true; - } - } - return false; - } - - - class PrimaryKeyJoinColumnOwner implements OrmBaseJoinColumn.Owner - { - public TypeMapping getTypeMapping() { - return AbstractOrmEntity.this; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractOrmEntity.this.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getReferencedColumnDbTable() { - Entity parentEntity = AbstractOrmEntity.this.getParentEntity(); - return (parentEntity == null) ? null : parentEntity.getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return AbstractOrmEntity.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractOrmEntity.this.defaultPrimaryKeyJoinColumns.contains(joinColumn); - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return AbstractOrmEntity.this.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/AbstractOrmGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java deleted file mode 100644 index 25bcbf709c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.resource.orm.XmlGenerator; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * - */ -public abstract class AbstractOrmGenerator<T extends XmlGenerator> - extends AbstractOrmXmlContextNode - implements OrmGenerator -{ - - protected String name; - - protected Integer specifiedInitialValue; - protected int defaultInitialValue; - - protected Integer specifiedAllocationSize; - protected int defaultAllocationSize; - - protected T resourceGenerator; - - - protected AbstractOrmGenerator(XmlContextNode parent) { - super(parent); - } - - protected T getResourceGenerator() { - return this.resourceGenerator; - } - - - // ********** name ********** - - public String getName() { - return this.name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - this.getResourceGenerator().setName(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - protected void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - - // ********** initial value ********** - - public int getInitialValue() { - return (this.specifiedInitialValue != null) ? this.specifiedInitialValue.intValue() : this.defaultInitialValue; - } - - public Integer getSpecifiedInitialValue() { - return this.specifiedInitialValue; - } - - public void setSpecifiedInitialValue(Integer specifiedInitialValue) { - Integer old = this.specifiedInitialValue; - this.specifiedInitialValue = specifiedInitialValue; - this.getResourceGenerator().setInitialValue(specifiedInitialValue); - this.firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, old, specifiedInitialValue); - } - - protected void setSpecifiedInitialValue_(Integer specifiedInitialValue) { - Integer old = this.specifiedInitialValue; - this.specifiedInitialValue = specifiedInitialValue; - this.firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, old, specifiedInitialValue); - } - - public int getDefaultInitialValue() { - return this.defaultInitialValue; - } - - protected void setDefaultInitialValue(int defaultInitialValue) { - int old = this.defaultInitialValue; - this.defaultInitialValue = defaultInitialValue; - this.firePropertyChanged(DEFAULT_INITIAL_VALUE_PROPERTY, old, defaultInitialValue); - } - - - // ********** allocation size ********** - - public int getAllocationSize() { - return (this.specifiedAllocationSize != null) ? this.specifiedAllocationSize.intValue() : this.defaultAllocationSize; - } - - public Integer getSpecifiedAllocationSize() { - return this.specifiedAllocationSize; - } - - public void setSpecifiedAllocationSize(Integer specifiedAllocationSize) { - Integer old = this.specifiedAllocationSize; - this.specifiedAllocationSize = specifiedAllocationSize; - this.getResourceGenerator().setAllocationSize(specifiedAllocationSize); - this.firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, old, specifiedAllocationSize); - } - - protected void setSpecifiedAllocationSize_(Integer specifiedAllocationSize) { - Integer old = this.specifiedAllocationSize; - this.specifiedAllocationSize = specifiedAllocationSize; - this.firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, old, specifiedAllocationSize); - } - - public int getDefaultAllocationSize() { - return Generator.DEFAULT_ALLOCATION_SIZE; - } - - protected void setDefaultAllocationSize(int defaultAllocationSize) { - int old = this.defaultAllocationSize; - this.defaultAllocationSize = defaultAllocationSize; - this.firePropertyChanged(DEFAULT_ALLOCATION_SIZE_PROPERTY, old, defaultAllocationSize); - } - - - // ********** text ranges ********** - - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.getResourceGenerator().getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - TextRange nameTextRange = this.getResourceGenerator().getNameTextRange(); - return nameTextRange != null ? nameTextRange : getValidationTextRange(); - } - - - // ********** resource => context ********** - - protected void initialize(T xmlResourceGenerator) { - this.resourceGenerator = xmlResourceGenerator; - this.name = xmlResourceGenerator.getName(); - this.specifiedInitialValue = xmlResourceGenerator.getInitialValue(); - this.specifiedAllocationSize = xmlResourceGenerator.getAllocationSize(); - //TODO defaults - } - - protected void update(T xmlResourceGenerator) { - this.resourceGenerator = xmlResourceGenerator; - this.setName_(xmlResourceGenerator.getName()); - this.setSpecifiedInitialValue_(xmlResourceGenerator.getInitialValue()); - this.setSpecifiedAllocationSize_(xmlResourceGenerator.getAllocationSize()); - getPersistenceUnit().addGenerator(this); - //TODO defaults - } - - - // ********** database stuff ********** - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - protected abstract String getSchema(); - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - protected abstract String getCatalog(); - - - // ********** misc ********** - - public boolean isVirtual() { - return getResourceGenerator().isVirtual(); - } - - @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - public boolean overrides(Generator 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; - } - - public boolean duplicates(Generator other) { - return (this != other) - && ! StringTools.stringIsEmpty(this.name) - && this.name.equals(other.getName()) - && ! this.overrides(other) - && ! other.overrides(this); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmIdMapping.java deleted file mode 100644 index 42482043d8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmIdMapping.java +++ /dev/null @@ -1,337 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmIdMapping<T extends XmlId> - extends AbstractOrmAttributeMapping<T> - implements OrmIdMapping -{ - protected final OrmColumn column; - - protected OrmGeneratedValue generatedValue; - - protected OrmConverter defaultConverter; - protected OrmConverter specifiedConverter; - - protected final OrmGeneratorContainer generatorContainer; - - - protected AbstractOrmIdMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.column = getXmlContextNodeFactory().buildOrmColumn(this, this); - this.column.initialize(this.resourceAttributeMapping.getColumn());//TODO pass in to constructor - this.generatorContainer = buildGeneratorContainer(); - this.initializeGeneratedValue(); - this.defaultConverter = getXmlContextNodeFactory().buildOrmNullConverter(this); - this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); - } - - protected OrmGeneratorContainer buildGeneratorContainer() { - return getXmlContextNodeFactory().buildOrmGeneratorContainer(this, this.resourceAttributeMapping); - } - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public int getXmlSequence() { - return 0; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmIdMapping(this); - } - - @Override - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromOrmColumnMapping(oldMapping); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - - public OrmColumn getColumn() { - return this.column; - } - - public OrmConverter getConverter() { - return getSpecifiedConverter() == null ? getDefaultConverter() : getSpecifiedConverter(); - } - - public OrmConverter getDefaultConverter() { - return this.defaultConverter; - } - - public OrmConverter getSpecifiedConverter() { - return this.specifiedConverter; - } - - protected String getSpecifedConverterType() { - if (this.specifiedConverter == null) { - return Converter.NO_CONVERTER; - } - return this.specifiedConverter.getType(); - } - - public void setSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(getSpecifedConverterType(), converterType)) { - return; - } - OrmConverter oldConverter = this.specifiedConverter; - OrmConverter newConverter = buildSpecifiedConverter(converterType); - this.specifiedConverter = null; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.specifiedConverter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setSpecifiedConverter(OrmConverter newConverter) { - OrmConverter oldConverter = this.specifiedConverter; - this.specifiedConverter = newConverter; - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - public OrmGeneratedValue addGeneratedValue() { - if (getGeneratedValue() != null) { - throw new IllegalStateException("gemeratedValue already exists"); //$NON-NLS-1$ - } - XmlGeneratedValue resourceGeneratedValue = OrmFactory.eINSTANCE.createXmlGeneratedValue(); - this.generatedValue = buildGeneratedValue(resourceGeneratedValue); - this.resourceAttributeMapping.setGeneratedValue(resourceGeneratedValue); - firePropertyChanged(GENERATED_VALUE_PROPERTY, null, this.generatedValue); - return this.generatedValue; - } - - public void removeGeneratedValue() { - if (getGeneratedValue() == null) { - throw new IllegalStateException("gemeratedValue does not exist, cannot be removed"); //$NON-NLS-1$ - } - OrmGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = null; - this.resourceAttributeMapping.setGeneratedValue(null); - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, null); - } - - public OrmGeneratedValue getGeneratedValue() { - return this.generatedValue; - } - - protected void setGeneratedValue(OrmGeneratedValue newGeneratedValue) { - OrmGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = newGeneratedValue; - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, newGeneratedValue); - } - - public OrmGeneratorContainer getGeneratorContainer() { - return this.generatorContainer; - } - - @Override - public String getPrimaryKeyColumnName() { - return this.getColumn().getName(); - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public boolean isIdMapping() { - return true; - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getIds().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getIds().remove(this.resourceAttributeMapping); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public String getDefaultColumnName() { - return getName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - - protected void initializeGeneratedValue() { - if (this.resourceAttributeMapping.getGeneratedValue() != null) { - this.generatedValue = buildGeneratedValue(this.resourceAttributeMapping.getGeneratedValue()); - } - } - - protected OrmGeneratedValue buildGeneratedValue(XmlGeneratedValue resourceGeneratedValue) { - return getXmlContextNodeFactory().buildOrmGeneratedValue(this, resourceGeneratedValue); - } - - @Override - public void update() { - super.update(); - this.column.update(getResourceColumn()); - this.generatorContainer.update(); - this.updateGeneratedValue(); - if (this.valuesAreEqual(getResourceConverterType(), getSpecifedConverterType())) { - getSpecifiedConverter().update(); - } - else { - setSpecifiedConverter(buildSpecifiedConverter(getResourceConverterType())); - } - } - - - protected void updateGeneratedValue() { - if (this.resourceAttributeMapping.getGeneratedValue() == null) { - if (getGeneratedValue() != null) { - setGeneratedValue(null); - } - } - else { - if (getGeneratedValue() == null) { - setGeneratedValue(buildGeneratedValue(this.resourceAttributeMapping.getGeneratedValue())); - } - else { - getGeneratedValue().update(this.resourceAttributeMapping.getGeneratedValue()); - } - } - } - - protected OrmConverter buildSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmTemporalConverter(this, this.resourceAttributeMapping); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourceAttributeMapping.getTemporal() != null) { - return Converter.TEMPORAL_CONVERTER; - } - - return null; - } - - //***************** XmlColumn.Owner implementation **************** - - public XmlColumn getResourceColumn() { - return this.resourceAttributeMapping.getColumn(); - } - - public void addResourceColumn() { - this.resourceAttributeMapping.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - this.resourceAttributeMapping.setColumn(null); - } - - // ****************** validation **************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (this.shouldValidateAgainstDatabase()) { - this.validateColumn(messages); - } - if (this.generatedValue != null) { - this.generatedValue.validate(messages, reporter); - } - this.generatorContainer.validate(messages, reporter); - } - - protected void validateColumn(List<IMessage> messages) { - OrmPersistentAttribute pa = this.getPersistentAttribute(); - String tableName = this.column.getTable(); - if (this.getTypeMapping().tableNameIsInvalid(tableName)) { - if (pa.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {pa.getName(), tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - if (pa.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {pa.getName(), this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnJoiningStrategy.java deleted file mode 100644 index c9b24e8b2f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,409 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; -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.XmlJoinColumnsMapping; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmJoinColumnJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmJoinColumnJoiningStrategy -{ - protected OrmJoinColumn defaultJoinColumn; - - protected final Vector<OrmJoinColumn> specifiedJoinColumns = new Vector<OrmJoinColumn>(); - - protected final OrmJoinColumn.Owner joinColumnOwner; - - protected XmlJoinColumnsMapping resource; - - - protected AbstractOrmJoinColumnJoiningStrategy( - JoinColumnEnabledRelationshipReference parent, - XmlJoinColumnsMapping resource) { - super(parent); - this.resource = resource; - this.joinColumnOwner = this.buildJoinColumnOwner(); - this.initializeSpecifiedJoinColumns(); - this.initializeDefaultJoinColumn(); - } - - public void initializeFrom(JoinColumnJoiningStrategy oldStrategy) { - for (JoinColumn joinColumn : CollectionTools.iterable(oldStrategy.joinColumns())) { - JoinColumn newJoinColumn = this.addSpecifiedJoinColumn(this.specifiedJoinColumnsSize()); - newJoinColumn.setSpecifiedName(joinColumn.getName()); - newJoinColumn.setSpecifiedReferencedColumnName(joinColumn.getReferencedColumnName()); - } - } - - protected abstract OrmJoinColumn.Owner buildJoinColumnOwner(); - - protected void initializeSpecifiedJoinColumns() { - for (XmlJoinColumn resourceJoinColumn : this.resource.getJoinColumns()) { - this.specifiedJoinColumns.add(buildJoinColumn(resourceJoinColumn)); - } - } - - protected void initializeDefaultJoinColumn() { - if (mayHaveDefaultJoinColumn()) { - this.defaultJoinColumn = this.buildJoinColumn(null); - } - } - - @Override - public JoinColumnEnabledRelationshipReference getParent() { - return (JoinColumnEnabledRelationshipReference) super.getParent(); - } - - public JoinColumnEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public RelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public void addStrategy() { - if (specifiedJoinColumnsSize() == 0) { - addSpecifiedJoinColumn(0); - } - } - - public void removeStrategy() { - for (JoinColumn each : CollectionTools.iterable(specifiedJoinColumns())) { - removeSpecifiedJoinColumn(each); - } - } - - - // **************** join columns ******************************************* - - public ListIterator<OrmJoinColumn> joinColumns() { - return this.hasSpecifiedJoinColumns() ? - this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.hasSpecifiedJoinColumns() ? - this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - - // **************** default join column ************************************ - - public OrmJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(OrmJoinColumn joinColumn) { - OrmJoinColumn old = this.defaultJoinColumn; - this.defaultJoinColumn = joinColumn; - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, old, joinColumn); - } - - protected ListIterator<OrmJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<OrmJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - - // **************** specified join columns ********************************* - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean hasSpecifiedJoinColumns() { - return ! this.specifiedJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - OrmJoinColumn oldDefaultJoinColumn = this.defaultJoinColumn; - if (oldDefaultJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultJoinColumn = null; - } - XmlJoinColumn resourceJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumn(); - OrmJoinColumn contextJoinColumn = this.buildJoinColumn(resourceJoinColumn); - this.specifiedJoinColumns.add(index, contextJoinColumn); - this.resource.getJoinColumns().add(index, resourceJoinColumn); - this.fireItemAdded(SPECIFIED_JOIN_COLUMNS_LIST, index, contextJoinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, oldDefaultJoinColumn, null); - } - return contextJoinColumn; - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - this.addItemToList(index, joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedJoinColumn(OrmJoinColumn joinColumn) { - this.addSpecifiedJoinColumn(this.specifiedJoinColumns.size(), joinColumn); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (this.specifiedJoinColumns.isEmpty()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = this.buildJoinColumn(null); - } - this.resource.getJoinColumns().remove(index); - this.fireItemRemoved(SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.resource.getJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn resourceJoinColumn) { - return this.getXmlContextNodeFactory().buildOrmJoinColumn(this, this.joinColumnOwner, resourceJoinColumn); - } - - // **************** resource => context ************************************ - - public void update() { - updateSpecifiedJoinColumns(); - updateDefaultJoinColumn(); - } - - protected void updateSpecifiedJoinColumns() { - // make a copy of the XML join columns (to prevent ConcurrentModificationException) - Iterator<XmlJoinColumn> xmlJoinColumns = - new CloneIterator<XmlJoinColumn>(this.resource.getJoinColumns()); - - for (Iterator<OrmJoinColumn> contextJoinColumns = this.specifiedJoinColumns(); - contextJoinColumns.hasNext(); ) { - OrmJoinColumn contextJoinColumn = contextJoinColumns.next(); - if (xmlJoinColumns.hasNext()) { - contextJoinColumn.update(xmlJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(contextJoinColumn); - } - } - - while (xmlJoinColumns.hasNext()) { - addSpecifiedJoinColumn(buildJoinColumn(xmlJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn() { - if (mayHaveDefaultJoinColumn()) { - if (this.defaultJoinColumn == null) { - this.setDefaultJoinColumn(this.buildJoinColumn(null)); - } else { - this.defaultJoinColumn.update(null); - } - } else { - this.setDefaultJoinColumn(null); - } - } - - protected boolean mayHaveDefaultJoinColumn() { - return getRelationshipReference().mayHaveDefaultJoinColumn() - && ! hasSpecifiedJoinColumns(); - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (getRelationshipMapping().shouldValidateAgainstDatabase()) { - for (Iterator<OrmJoinColumn> stream = this.joinColumns(); stream.hasNext(); ) { - this.validateJoinColumn(stream.next(), messages); - } - } - } - - protected void validateJoinColumn(OrmJoinColumn joinColumn, List<IMessage> messages) { - if (getRelationshipMapping().getTypeMapping().tableNameIsInvalid(joinColumn.getTable())) { - if (this.getRelationshipMapping().getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {getRelationshipMapping().getName(), joinColumn.getTable(), joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {joinColumn.getTable(), joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange() - ) - ); - } - return; - } - validateJoinColumnName(joinColumn, messages); - validationJoinColumnReferencedColumnName(joinColumn, messages); - } - - protected void validateJoinColumnName(OrmJoinColumn joinColumn, List<IMessage> messages) { - if ( ! joinColumn.isResolved() && joinColumn.getDbTable() != null) { - if (joinColumn.getName() != null) { - if (getRelationshipMapping().getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {getRelationshipMapping().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() - ) - ); - } - } - else if (joinColumn.getOwner().joinColumnsSize() > 1) { - if (getRelationshipMapping().getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - new String[] {getRelationshipMapping().getName()}, - joinColumn, - joinColumn.getNameTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - joinColumn, - joinColumn.getNameTextRange() - ) - ); - } - } - } - } - - protected void validationJoinColumnReferencedColumnName(OrmJoinColumn joinColumn, List<IMessage> messages) { - if ( ! joinColumn.isReferencedColumnResolved() && joinColumn.getReferencedColumnDbTable() != null) { - if (joinColumn.getReferencedColumnName() != null) { - if (getRelationshipMapping().getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {getRelationshipMapping().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() - ) - ); - } - } - else if (joinColumn.getOwner().joinColumnsSize() > 1) { - if (getRelationshipMapping().getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - new String[] {getRelationshipMapping().getName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - joinColumn, - joinColumn.getReferencedColumnNameTextRange() - ) - ); - } - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinTableJoiningStrategy.java deleted file mode 100644 index 8187e411d6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinTableJoiningStrategy.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.JoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.JoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmJoinTableJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmJoinTableJoiningStrategy -{ - protected OrmJoinTable joinTable; - - - protected AbstractOrmJoinTableJoiningStrategy( - JoinTableEnabledRelationshipReference parent) { - super(parent); - } - - public void initializeFrom(JoinTableJoiningStrategy oldStrategy) { - JoinTable oldJoinTable = (oldStrategy.getJoinTable()); - if (oldJoinTable != null) { - this.addStrategy(); - this.getJoinTable().setSpecifiedCatalog(oldJoinTable.getSpecifiedCatalog()); - this.getJoinTable().setSpecifiedSchema(oldJoinTable.getSpecifiedSchema()); - this.getJoinTable().setSpecifiedName(oldJoinTable.getSpecifiedName()); - } - } - - @Override - public JoinTableEnabledRelationshipReference getParent() { - return (JoinTableEnabledRelationshipReference) super.getParent(); - } - - public JoinTableEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public RelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public String getJoinTableDefaultName() { - return MappingTools.buildJoinTableDefaultName(this.getRelationshipReference()); - } - - public void addStrategy() { - if (this.joinTable == null) { - XmlJoinTable resourceJoinTable = OrmFactory.eINSTANCE.createXmlJoinTable(); - this.joinTable = getXmlContextNodeFactory().buildOrmJoinTable(this, resourceJoinTable); - setResourceJoinTable(resourceJoinTable); - this.firePropertyChanged(JOIN_TABLE_PROPERTY, null, this.joinTable); - } - } - - public void removeStrategy() { - if (this.joinTable != null) { - OrmJoinTable oldJoinTable = this.joinTable; - this.joinTable = null; - removeResourceJoinTable(); - this.firePropertyChanged(JOIN_TABLE_PROPERTY, oldJoinTable, null); - } - } - - protected abstract void setResourceJoinTable(XmlJoinTable resourceJoinTable); - - - // **************** join table ********************************************* - - public OrmJoinTable getJoinTable() { - return this.joinTable; - } - - public OrmJoinTable addJoinTable() { - addStrategy(); - return this.joinTable; - } - - protected void setJoinTable_(OrmJoinTable newJoinTable) { - OrmJoinTable oldJoinTable = this.joinTable; - this.joinTable = newJoinTable; - this.firePropertyChanged(JOIN_TABLE_PROPERTY, oldJoinTable, newJoinTable); - } - - public XmlJoinTable addResourceJoinTable() { - XmlJoinTable resourceJoinTable = OrmFactory.eINSTANCE.createXmlJoinTable(); - setResourceJoinTable(resourceJoinTable); - return resourceJoinTable; - } - - protected boolean mayHaveJoinTable() { - return getResourceJoinTable() != null - || getRelationshipReference().mayHaveDefaultJoinTable(); - } - - - // **************** resource -> context ************************************ - - protected void initialize() { - if (mayHaveJoinTable()) { - this.joinTable = getXmlContextNodeFactory().buildOrmJoinTable(this, getResourceJoinTable()); - } - } - - public void update() { - if (mayHaveJoinTable()) { - if (this.joinTable == null) { - setJoinTable_(getXmlContextNodeFactory().buildOrmJoinTable(this, getResourceJoinTable())); - } - this.joinTable.update(); - } - else { - if (this.joinTable != null) { - // no resource, so no clean up - setJoinTable_(null); - } - } - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.joinTable != null && getRelationshipMapping().shouldValidateAgainstDatabase()) { - this.joinTable.validate(messages, reporter); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToManyMapping.java deleted file mode 100644 index 8a047bd472..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToManyMapping.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; - -public abstract class AbstractOrmManyToManyMapping<T extends XmlManyToMany> - extends AbstractOrmMultiRelationshipMapping<T> - implements OrmManyToManyMapping -{ - protected AbstractOrmManyToManyMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - } - - - @Override - protected OrmRelationshipReference buildRelationshipReference() { - return new GenericOrmManyToManyRelationshipReference(this, this.resourceAttributeMapping); - } - - public int getXmlSequence() { - return 70; - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToManyMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToManys().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToManys().remove(this.resourceAttributeMapping); - } - - @Override - public OrmManyToManyRelationshipReference getRelationshipReference() { - return (OrmManyToManyRelationshipReference) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneMapping.java deleted file mode 100644 index 14f7359de7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneMapping.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; - - -public abstract class AbstractOrmManyToOneMapping<T extends XmlManyToOne> - extends AbstractOrmSingleRelationshipMapping<T> - implements OrmManyToOneMapping2_0 -{ - protected AbstractOrmManyToOneMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - } - - - @Override - protected OrmRelationshipReference buildRelationshipReference() { - return new GenericOrmManyToOneRelationshipReference(this, this.resourceAttributeMapping); - } - - public int getXmlSequence() { - return 40; - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToOneMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToOnes().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToOnes().remove(this.resourceAttributeMapping); - } - - @Override - public OrmManyToOneRelationshipReference getRelationshipReference() { - return (OrmManyToOneRelationshipReference) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java deleted file mode 100644 index 816cbd1af8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlIdClass; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public abstract class AbstractOrmMappedSuperclass extends AbstractOrmTypeMapping<XmlMappedSuperclass> - implements OrmMappedSuperclass -{ - protected String idClass; - - protected AbstractOrmMappedSuperclass(OrmPersistentType parent, XmlMappedSuperclass resourceMapping) { - super(parent, resourceMapping); - this.idClass = this.getResourceIdClassName(this.getResourceIdClass()); - } - - public JavaMappedSuperclass getJavaMappedSuperclass() { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getMappingKey() == MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY) { - return (JavaMappedSuperclass) javaPersistentType.getMapping(); - } - return null; - } - - /** - * This checks metaDataComplete before returning the JavaMappedSuperclass. - * As far as defaults are concerned, if metadataComplete is true, the JavaMappedSuperclass is ignored. - */ - protected JavaMappedSuperclass getJavaMappedSuperclassForDefaults() { - if (isMetadataComplete()) { - return null; - } - return getJavaMappedSuperclass(); - } - - - public char getIdClassEnclosingTypeSeparator() { - return '$'; - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (this.attributeValueHasChanged(oldIdClass, newIdClass)) { - if (this.getResourceIdClass() != null) { - this.getResourceIdClass().setClassName(newIdClass); - if (this.getResourceIdClass().isUnset()) { - removeResourceIdClass(); - } - } - else if (newIdClass != null) { - addResourceIdClass(); - getResourceIdClass().setClassName(newIdClass); - } - } - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected XmlIdClass getResourceIdClass() { - return this.resourceTypeMapping.getIdClass(); - } - - protected void addResourceIdClass() { - this.resourceTypeMapping.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - } - - protected void removeResourceIdClass() { - this.resourceTypeMapping.setIdClass(null); - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - @Override - public Iterator<OrmColumnMapping> overridableAttributes() { - return new FilteringIterator<OrmAttributeMapping, OrmColumnMapping>(this.attributeMappings()) { - @Override - protected boolean accept(OrmAttributeMapping o) { - return o.isOverridableAttributeMapping(); - } - }; - } - - @Override - public Iterator<OrmRelationshipMapping> overridableAssociations() { - return new FilteringIterator<OrmAttributeMapping, OrmRelationshipMapping>(this.attributeMappings()) { - @Override - protected boolean accept(OrmAttributeMapping o) { - return o.isOverridableAssociationMapping(); - } - }; - } - - public int getXmlSequence() { - return 0; - } - - public void addToResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getMappedSuperclasses().add(this.resourceTypeMapping); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getMappedSuperclasses().remove(this.resourceTypeMapping); - } - - @Override - public void update() { - super.update(); - this.setIdClass_(this.getResourceIdClassName(this.getResourceIdClass())); - } - - protected String getResourceIdClassName(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/AbstractOrmMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java deleted file mode 100644 index df840ee3da..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; - -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.MultiRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlMultiRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.OrmFactory; - - -public abstract class AbstractOrmMultiRelationshipMapping<T extends AbstractXmlMultiRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> - implements OrmMultiRelationshipMapping -{ - protected String mapKey; - - protected String orderBy;//TODO change this to defaultOrderBy and specifiedOrderBy? - - protected boolean isNoOrdering; - - protected boolean isPkOrdering; - - protected boolean isCustomOrdering; - - - protected AbstractOrmMultiRelationshipMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.mapKey = this.getResourceMapKeyName(); - this.orderBy = this.getResourceOrderBy(); - if (this.orderBy == null) { - this.isNoOrdering = true; - } - else { - this.isCustomOrdering = true; - } - } - - - public FetchType getDefaultFetch() { - return MultiRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - - // **************** map key ************************************************ - - public String getMapKey() { - return this.mapKey; - } - - public void setMapKey(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - if (this.attributeValueHasChanged(oldMapKey, newMapKey)) { - if (this.getResourceMapKey() != null) { - this.getResourceMapKey().setName(newMapKey); - if (this.getResourceMapKey().isUnset()) { - removeResourceMapKey(); - } - } - else if (newMapKey != null) { - addResourceMapKey(); - getResourceMapKey().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 getResourceMapKey() { - return this.resourceAttributeMapping.getMapKey(); - } - - protected void removeResourceMapKey() { - this.resourceAttributeMapping.setMapKey(null); - } - - protected void addResourceMapKey() { - this.resourceAttributeMapping.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - } - - public Iterator<String> candidateMapKeyNames() { - return this.allTargetEntityAttributeNames(); - } - - - // **************** ordering *********************************************** - - public String getOrderBy() { - return this.orderBy; - } - - public void setOrderBy(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - this.resourceAttributeMapping.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) { - this.resourceAttributeMapping.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) { - this.resourceAttributeMapping.setOrderBy(""); //$NON-NLS-1$ - } - 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(""); //$NON-NLS-1$ - } - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - protected void setCustomOrdering_(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - - // **************** resource -> context ************************************ - - @Override - public void update() { - super.update(); - this.setMapKey_(this.getResourceMapKeyName()); - this.setOrderBy_(this.getResourceOrderBy()); - if (getOrderBy() == null) { - setNoOrdering_(true); - setPkOrdering_(false); - setCustomOrdering_(false); - } - else { - setNoOrdering_(false); - setPkOrdering_(false); - setCustomOrdering_(true); - } - } - - protected String getResourceMapKeyName() { - return this.resourceAttributeMapping.getMapKey() == null ? null : this.resourceAttributeMapping.getMapKey().getName(); - } - - protected String getResourceOrderBy() { - return this.resourceAttributeMapping.getOrderBy(); - } - - @Override - protected String getResourceDefaultTargetEntity() { - return this.getJavaPersistentAttribute().getMultiReferenceEntityTypeName(); - } -} 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 e837621c99..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.resource.orm.AbstractXmlNamedColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; - - -public abstract class AbstractOrmNamedColumn<T extends AbstractXmlNamedColumn> extends AbstractOrmXmlContextNode - implements OrmNamedColumn -{ - protected Owner owner; - - protected String specifiedName; - - protected String defaultName; - - protected String columnDefinition; - - protected AbstractOrmNamedColumn(XmlContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - public void initializeFrom(NamedColumn oldColumn) { - setSpecifiedName(oldColumn.getSpecifiedName()); - setColumnDefinition(oldColumn.getColumnDefinition()); - } - - protected abstract T getResourceColumn(); - - protected abstract void removeResourceColumn(); - - protected abstract void addResourceColumn(); - - public Owner getOwner() { - return this.owner; - } - - public String getName() { - return (this.specifiedName != null) ? this.specifiedName : this.defaultName; - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - if (this.attributeValueHasChanged(oldSpecifiedName, newSpecifiedName)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setName(newSpecifiedName); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedName != null) { - addResourceColumn(); - getResourceColumn().setName(newSpecifiedName); - } - } - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public String getColumnDefinition() { - return this.columnDefinition; - } - - public void setColumnDefinition(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - if (this.attributeValueHasChanged(oldColumnDefinition, newColumnDefinition)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setColumnDefinition(newColumnDefinition); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newColumnDefinition != null) { - addResourceColumn(); - getResourceColumn().setColumnDefinition(newColumnDefinition); - } - } - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - protected void setColumnDefinition_(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - public Column getDbColumn() { - Table table = this.getDbTable(); - return (table == null) ? null : table.getColumnForIdentifier(getName()); - } - - public Table getDbTable() { - return getOwner().getDbTable(this.getOwningTableName()); - } - - protected abstract String getOwningTableName(); - - public boolean isResolved() { - return getDbColumn() != null; - } - - public TextRange getNameTextRange() { - if (getResourceColumn() != null) { - TextRange textRange = getResourceColumn().getNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - public TextRange getValidationTextRange() { - TextRange textRange = getResourceColumn().getValidationTextRange(); - if (textRange != null) { - return textRange; - } - return getOwner().getValidationTextRange(); - } - - - // ******************* initialization from orm xml resource model ******************** - - protected void initialize(T column) { - this.specifiedName = this.getResourceColumnName(column); - this.defaultName = this.buildDefaultName(); - this.columnDefinition = this.getResourceColumnDefinition(column); - } - - protected void update(T column) { - setSpecifiedName_(this.getResourceColumnName(column)); - setDefaultName(this.buildDefaultName()); - setColumnDefinition_(this.getResourceColumnDefinition(column)); - } - - protected String getResourceColumnName(T column) { - return column == null ? null : column.getName(); - } - - protected String getResourceColumnDefinition(T column) { - return column == null ? null : column.getColumnDefinition(); - } - - /** - * Return the default column name. - */ - protected String buildDefaultName() { - return this.getOwner().getDefaultColumnName(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java deleted file mode 100644 index bb17a5b49b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; - - -public abstract class AbstractOrmOneToManyMapping<T extends XmlOneToMany> - extends AbstractOrmMultiRelationshipMapping<T> - implements OrmOneToManyMapping -{ - protected AbstractOrmOneToManyMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - } - - public int getXmlSequence() { - return 50; - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToManyMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToManys().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToManys().remove(this.resourceAttributeMapping); - } - - @Override - public OrmOneToManyRelationshipReference getRelationshipReference() { - return (OrmOneToManyRelationshipReference) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java deleted file mode 100644 index 09cf1d8505..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmOneToManyRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmOneToManyRelationshipReference -{ - protected OrmMappedByJoiningStrategy mappedByJoiningStrategy; - - protected OrmJoinTableJoiningStrategy joinTableJoiningStrategy; - - - protected AbstractOrmOneToManyRelationshipReference( - OrmOneToManyMapping parent, XmlOneToMany resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - - // initialize join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - } - - protected OrmMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericOrmMappedByJoiningStrategy(this, getResourceMapping()); - } - - protected OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new GenericOrmJoinTableJoiningStrategy(this, getResourceMapping()); - } - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromOwnableRelationshipReference(this); - newRelationshipReference.initializeFromJoinTableEnabledRelationshipReference(this); - } - - @Override - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - super.initializeFromOwnableRelationshipReference(oldRelationshipReference); - this.mappedByJoiningStrategy.setMappedByAttribute( - oldRelationshipReference.getMappedByJoiningStrategy().getMappedByAttribute()); - } - - @Override - public void initializeFromJoinTableEnabledRelationshipReference( - OrmJoinTableEnabledRelationshipReference oldRelationshipReference) { - super.initializeFromJoinTableEnabledRelationshipReference(oldRelationshipReference); - OrmJoinTable oldTable = - oldRelationshipReference.getJoinTableJoiningStrategy().getJoinTable(); - if (oldTable != null) { - this.joinTableJoiningStrategy.addJoinTable().initializeFrom(oldTable); - } - } - - @Override - public OrmOneToManyMapping getRelationshipMapping() { - return (OrmOneToManyMapping) getParent(); - } - - public XmlOneToMany getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return this.getMappedByJoiningStrategy().getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - - // **************** mapped by ********************************************** - - public OrmMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - } - - public boolean usesMappedByJoiningStrategy() { - return this.getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join table ********************************************* - - public OrmJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public void setJoinTableJoiningStrategy() { - // join table is default, so no need to add to resource - this.mappedByJoiningStrategy.removeStrategy(); - } - - public void unsetJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null; - } - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - - // update join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.mappedByJoiningStrategy.validate(messages, reporter); - this.joinTableJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneMapping.java deleted file mode 100644 index c7772ed612..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneMapping.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; - - -public abstract class AbstractOrmOneToOneMapping<T extends XmlOneToOne> - extends AbstractOrmSingleRelationshipMapping<T> - implements OrmOneToOneMapping2_0 -{ - protected AbstractOrmOneToOneMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - } - - - @Override - protected OrmRelationshipReference buildRelationshipReference() { - return new GenericOrmOneToOneRelationshipReference(this, this.resourceAttributeMapping); - } - - public int getXmlSequence() { - return 60; - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToOneMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToOnes().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToOnes().remove(this.resourceAttributeMapping); - } - - @Override - public OrmOneToOneRelationshipReference getRelationshipReference() { - return (OrmOneToOneRelationshipReference) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java deleted file mode 100644 index 9a7cb095b8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java +++ /dev/null @@ -1,290 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.PersistentAttribute2_0; -import org.eclipse.jpt.core.jpa2.context.StaticMetamodelField; -import org.eclipse.jpt.core.jpa2.context.orm.OrmPersistentAttribute2_0; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * ORM persistent attribute - */ -public abstract class AbstractOrmPersistentAttribute - extends AbstractOrmXmlContextNode - implements OrmPersistentAttribute2_0 -{ - protected final Owner owner; - - protected OrmAttributeMapping attributeMapping; - - protected JavaPersistentAttribute javaPersistentAttribute; - - protected AccessType defaultAccess; - - protected AbstractOrmPersistentAttribute(OrmPersistentType parent, Owner owner, XmlAttributeMapping resourceMapping) { - super(parent); - this.owner = owner; - this.attributeMapping = buildAttributeMapping(resourceMapping); - this.javaPersistentAttribute = findJavaPersistentAttribute(); - this.defaultAccess = buildDefaultAccess(); - } - - public XmlAttributeMapping getResourceAttributeMapping() { - return this.attributeMapping.getResourceAttributeMapping(); - } - - public JavaPersistentAttribute getJavaPersistentAttribute() { - return this.javaPersistentAttribute; - } - - protected void setJavaPersistentAttribute(JavaPersistentAttribute javaPersistentAttribute) { - JavaPersistentAttribute old = this.javaPersistentAttribute; - this.javaPersistentAttribute = javaPersistentAttribute; - this.firePropertyChanged(JAVA_PERSISTENT_ATTRIBUTE_PROPERTY, old, javaPersistentAttribute); - } - - protected OrmAttributeMapping buildAttributeMapping(XmlAttributeMapping resourceMapping) { - OrmAttributeMappingDefinition mappingDefinition = - getMappingFileDefinition().getOrmAttributeMappingDefinition(resourceMapping.getMappingKey()); - return mappingDefinition.buildContextMapping(this, resourceMapping, getXmlContextNodeFactory()); - } - - public String getId() { - return OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID; - } - - public AccessType getAccess() { - return getSpecifiedAccess() != null ? getSpecifiedAccess() : getDefaultAccess(); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newAccess) { - AccessType old = this.defaultAccess; - this.defaultAccess = newAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, old, this.defaultAccess); - } - - public String getName() { - return this.attributeMapping.getName(); - } - - public void nameChanged(String oldName, String newName) { - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public OrmAttributeMapping getSpecifiedMapping() { - return this.attributeMapping; - } - - public OrmAttributeMapping getMapping() { - return this.attributeMapping; - } - - public String getMappingKey() { - return this.attributeMapping.getKey(); - } - - public String getDefaultMappingKey() { - return null; - } - - public void setSpecifiedMappingKey(String newMappingKey) { - if (this.valuesAreEqual(this.getMappingKey(), newMappingKey)) { - return; - } - OrmAttributeMapping oldMapping = this.attributeMapping; - OrmAttributeMappingDefinition mappingDefinition = - getMappingFileDefinition().getOrmAttributeMappingDefinition(newMappingKey); - XmlAttributeMapping resourceAttributeMapping = - mappingDefinition.buildResourceMapping(getResourceNodeFactory()); - this.attributeMapping = buildAttributeMapping(resourceAttributeMapping); - - getPersistentType().changeMapping(this, oldMapping, this.attributeMapping); - firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, this.attributeMapping); - } - - 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"); //$NON-NLS-1$ - } - getPersistentType().makePersistentAttributeVirtual(this); - } - - public void makeSpecified() { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); //$NON-NLS-1$ - } - if (getMappingKey() == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - throw new IllegalStateException("Use makeSpecified(String) instead and specify a mapping type"); //$NON-NLS-1$ - } - getPersistentType().makePersistentAttributeSpecified(this); - } - - public void makeSpecified(String mappingKey) { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); //$NON-NLS-1$ - } - getPersistentType().makePersistentAttributeSpecified(this, mappingKey); - } - - public String getPrimaryKeyColumnName() { - return this.attributeMapping.getPrimaryKeyColumnName(); - } - - public boolean isIdAttribute() { - return this.attributeMapping.isIdMapping(); - } - - public void update() { - this.attributeMapping.update(); - this.setJavaPersistentAttribute(findJavaPersistentAttribute()); - this.owner.updateJavaPersistentAttribute(); - this.setDefaultAccess(buildDefaultAccess()); - } - - @Override - public void postUpdate() { - super.postUpdate(); - getMapping().postUpdate(); - } - - protected JavaPersistentAttribute findJavaPersistentAttribute() { - return this.owner.findJavaPersistentAttribute(this); - } - - protected AccessType buildDefaultAccess() { - return getPersistentType().getAccess(); - } - - public JpaStructureNode getStructureNode(int offset) { - return this; - } - - public boolean contains(int textOffset) { - if (isVirtual()) { - return false; - } - return this.attributeMapping.contains(textOffset); - } - - public TextRange getSelectionTextRange() { - if (isVirtual()) { - return null; - } - return this.attributeMapping.getSelectionTextRange(); - } - - public StaticMetamodelField getStaticMetamodelField() { - return (this.javaPersistentAttribute == null) ? null : - ((PersistentAttribute2_0) this.javaPersistentAttribute).getStaticMetamodelField(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateAttribute(messages); - this.validateModifiers(messages); - this.attributeMapping.validate(messages, reporter); - } - - protected void validateAttribute(List<IMessage> messages) { - if (this.javaPersistentAttribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME, - new String[] {this.getName(), this.getPersistentType().getMapping().getClass_()}, - this.attributeMapping, - this.attributeMapping.getNameTextRange() - ) - ); - } - } - - protected void validateModifiers(List<IMessage> messages) { - if (this.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - if (this.javaPersistentAttribute == null) { - return; - } - - if (this.javaPersistentAttribute.isField()) { - if (this.javaPersistentAttribute.isFinal()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD)); - } - if (this.javaPersistentAttribute.isPublic()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD)); - } - } else { - //TODO validation : need to have a validation message for final methods as well. - //From the JPA spec : No methods or persistent instance variables of the entity class may be final. - } - } - - protected IMessage buildAttributeMessage(String msgID) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - msgID, - new String[] {this.getName()}, - this, - getValidationTextRange() - ); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return getPersistentType().getMapping().getAttributesTextRange(); - } - return this.attributeMapping.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - public void dispose() { - //nothing to dispose - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java deleted file mode 100644 index fe9aedf3e6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlQuery; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - - -public abstract class AbstractOrmQuery<E extends XmlQuery> extends AbstractOrmXmlContextNode - implements OrmQuery -{ - - protected String name; - - protected String query; - - protected final List<OrmQueryHint> hints; - - protected E resourceQuery; - - protected AbstractOrmQuery(XmlContextNode parent, E resourceQuery) { - super(parent); - this.hints = new ArrayList<OrmQueryHint>(); - this.initialize(resourceQuery); - } - - protected E getResourceQuery() { - return this.resourceQuery; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.getResourceQuery().setName(newName); - firePropertyChanged(Query.NAME_PROPERTY, oldName, newName); - } - - public String getQuery() { - return this.query; - } - - public void setQuery(String newQuery) { - String oldQuery = this.query; - this.query = newQuery; - this.getResourceQuery().setQuery(newQuery); - firePropertyChanged(Query.QUERY_PROPERTY, oldQuery, newQuery); - } - - public ListIterator<OrmQueryHint> hints() { - return new CloneListIterator<OrmQueryHint>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public OrmQueryHint addHint(int index) { - XmlQueryHint resourceQueryHint = OrmFactory.eINSTANCE.createXmlQueryHint(); - OrmQueryHint contextQueryHint = buildQueryHint(resourceQueryHint); - this.hints.add(index, contextQueryHint); - this.getResourceQuery().getHints().add(index, resourceQueryHint); - this.fireItemAdded(Query.HINTS_LIST, index, contextQueryHint); - return contextQueryHint; - } - - protected void addHint(int index, OrmQueryHint queryHint) { - addItemToList(index, queryHint, this.hints, Query.HINTS_LIST); - } - - protected void addHint(OrmQueryHint queryHint) { - this.addHint(this.hints.size(), queryHint); - } - - public void removeHint(QueryHint queryHint) { - removeHint(this.hints.indexOf(queryHint)); - } - - public void removeHint(int index) { - OrmQueryHint queryHint = this.hints.remove(index); - this.getResourceQuery().getHints().remove(index); - fireItemRemoved(Query.HINTS_LIST, index, queryHint); - } - - protected void removeHint_(OrmQueryHint queryHint) { - removeItemFromList(queryHint, this.hints, Query.HINTS_LIST); - } - - public void moveHint(int targetIndex, int sourceIndex) { - this.getResourceQuery().getHints().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.hints, Query.HINTS_LIST); - } - - - protected void initialize(E xmlQuery) { - this.resourceQuery = xmlQuery; - this.name = xmlQuery.getName(); - this.query = xmlQuery.getQuery(); - this.initializeHints(); - } - - protected void initializeHints() { - for (XmlQueryHint resourceQueryHint : this.resourceQuery.getHints()) { - this.hints.add(buildQueryHint(resourceQueryHint)); - } - } - - protected OrmQueryHint buildQueryHint(XmlQueryHint resourceQueryHint) { - return getXmlContextNodeFactory().buildOrmQueryHint(this, resourceQueryHint); - } - - public void update(E xmlQuery) { - this.resourceQuery = xmlQuery; - this.setName(xmlQuery.getName()); - this.setQuery(xmlQuery.getQuery()); - this.updateHints(); - getPersistenceUnit().addQuery(this); - } - - protected void updateHints() { - // make a copy of the XML hints (to prevent ConcurrentModificationException) - Iterator<XmlQueryHint> xmlHints = new CloneIterator<XmlQueryHint>(this.resourceQuery.getHints()); - - for (Iterator<OrmQueryHint> contextHints = this.hints(); contextHints.hasNext(); ) { - OrmQueryHint contextHint = contextHints.next(); - if (xmlHints.hasNext()) { - contextHint.update(xmlHints.next()); - } - else { - removeHint_(contextHint); - } - } - - while (xmlHints.hasNext()) { - addHint(buildQueryHint(xmlHints.next())); - } - } - - public boolean overrides(Query other) { - // this isn't ideal, but it will have to do until we have further adopter input - return (this.name != null) - && this.name.equals(other.getName()) - && (other instanceof JavaQuery); - } - - public boolean duplicates(Query other) { - return (this != other) - && ! StringTools.stringIsEmpty(this.name) - && this.name.equals(other.getName()) - && ! this.overrides(other) - && ! other.overrides(this); - } - - public TextRange getValidationTextRange() { - return this.getResourceQuery().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.getResourceQuery().getNameTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java deleted file mode 100644 index 74398902c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmCascade; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmRelationshipMapping<T extends AbstractXmlRelationshipMapping> - extends AbstractOrmAttributeMapping<T> - implements OrmRelationshipMapping -{ - protected String specifiedTargetEntity; - protected String defaultTargetEntity; - protected Entity resolvedTargetEntity; - - protected final OrmRelationshipReference relationshipReference; - - protected final OrmCascade cascade; - - protected FetchType specifiedFetch; - - - protected AbstractOrmRelationshipMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.relationshipReference = buildRelationshipReference(); - this.cascade = getXmlContextNodeFactory().buildOrmCascade(this, this.resourceAttributeMapping); - this.specifiedTargetEntity = getResourceTargetEntity(); - this.defaultTargetEntity = buildDefaultTargetEntity(); - this.resolvedTargetEntity = buildResolvedTargetEntity(); - this.specifiedFetch = getResourceFetch(); - } - - - protected abstract OrmRelationshipReference buildRelationshipReference(); - - @Override - public OrmPersistentAttribute getParent() { - return (OrmPersistentAttribute) super.getParent(); - } - - public boolean isRelationshipOwner() { - return this.relationshipReference.isRelationshipOwner(); - } - - @Override - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.relationshipReference.isOwnedBy(mapping); - } - - @Override - public boolean isOverridableAssociationMapping() { - return this.relationshipReference.isOverridableAssociation(); - } - - - // **************** target entity ****************************************** - - public char getTargetEntityEnclosingTypeSeparator() { - return '$'; - } - - public String getTargetEntity() { - return (this.specifiedTargetEntity != null) ? this.specifiedTargetEntity : this.defaultTargetEntity; - } - - public String getSpecifiedTargetEntity() { - return this.specifiedTargetEntity; - } - - public void setSpecifiedTargetEntity(String targetEntity) { - String old = this.specifiedTargetEntity; - this.specifiedTargetEntity = targetEntity; - this.resourceAttributeMapping.setTargetEntity(targetEntity); - this.firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - protected void setSpecifiedTargetEntity_(String targetEntity) { - String old = this.specifiedTargetEntity; - this.specifiedTargetEntity = targetEntity; - this.firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - public String getDefaultTargetEntity() { - return this.defaultTargetEntity; - } - - protected void setDefaultTargetEntity(String targetEntity) { - String old = this.defaultTargetEntity; - this.defaultTargetEntity = targetEntity; - this.firePropertyChanged(DEFAULT_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - public Entity getResolvedTargetEntity() { - return this.resolvedTargetEntity; - } - - protected void setResolvedTargetEntity(Entity targetEntity) { - Entity old = this.resolvedTargetEntity; - this.resolvedTargetEntity = targetEntity; - this.firePropertyChanged(RESOLVED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - - // **************** reference ********************************************** - - public OrmRelationshipReference getRelationshipReference() { - return this.relationshipReference; - } - - - // **************** cascade ************************************************ - - public OrmCascade getCascade() { - return this.cascade; - } - - - // **************** fetch ************************************************** - - public FetchType getFetch() { - return (this.specifiedFetch != null) ? this.specifiedFetch : this.getDefaultFetch(); - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType fetch) { - FetchType old = this.specifiedFetch; - this.specifiedFetch = fetch; - this.resourceAttributeMapping.setFetch(FetchType.toOrmResourceModel(fetch)); - this.firePropertyChanged(SPECIFIED_FETCH_PROPERTY, old, fetch); - } - - protected void setSpecifiedFetch_(FetchType fetch) { - FetchType old = this.specifiedFetch; - this.specifiedFetch = fetch; - this.firePropertyChanged(SPECIFIED_FETCH_PROPERTY, old, fetch); - } - - - // **************** resource => context ************************************ - - @Override - public void update() { - super.update(); - this.setSpecifiedTargetEntity_(this.getResourceTargetEntity()); - this.setDefaultTargetEntity(this.buildDefaultTargetEntity()); - this.setResolvedTargetEntity(this.buildResolvedTargetEntity()); - this.relationshipReference.update(); - this.setSpecifiedFetch_(this.getResourceFetch()); - this.cascade.update(); - } - - protected String getResourceTargetEntity() { - return this.resourceAttributeMapping.getTargetEntity(); - } - - protected FetchType getResourceFetch() { - return FetchType.fromOrmResourceModel(this.resourceAttributeMapping.getFetch()); - } - - protected String buildDefaultTargetEntity() { - RelationshipMapping javaMapping = getJavaRelationshipMapping(); - if (javaMapping != null) { - if (getPersistentAttribute().isVirtual() && !getTypeMapping().isMetadataComplete()) { - return javaMapping.getTargetEntity(); - } - } - if (this.getJavaPersistentAttribute() != null) { - return getResourceDefaultTargetEntity(); - } - return null; - } - - protected RelationshipMapping getJavaRelationshipMapping() { - if (this.getJavaPersistentAttribute() == null) { - return null; - } - AttributeMapping javaAttributeMapping = this.getJavaPersistentAttribute().getMapping(); - if (javaAttributeMapping instanceof RelationshipMapping) { - return ((RelationshipMapping) javaAttributeMapping); - } - return null; - } - - protected abstract String getResourceDefaultTargetEntity(); - - protected Entity buildResolvedTargetEntity() { - String targetEntityName = this.getTargetEntity(); - if (targetEntityName == null) { - return null; - } - - // first try to resolve using only the locally specified name... - Entity targetEntity = this.getEntity(targetEntityName); - if (targetEntity != null) { - return targetEntity; - } - - // ...then try to resolve by prepending the global package name - String defaultPackageName = this.getDefaultPackageName(); - if (defaultPackageName == null) { - return null; - } - return this.getEntity(defaultPackageName + '.' + targetEntityName); - } - - protected String getDefaultPackageName() { - return this.getPersistentAttribute().getPersistentType().getDefaultPackage(); - } - - protected Entity getEntity(String typeName) { - return this.getPersistenceUnit().getEntity(typeName); - } - - - // ********** RelationshipMapping implementation ********** - - @Override - public void initializeFromOrmRelationshipMapping(OrmRelationshipMapping oldMapping) { - super.initializeFromOrmRelationshipMapping(oldMapping); - setSpecifiedTargetEntity(oldMapping.getSpecifiedTargetEntity()); - setSpecifiedFetch(oldMapping.getSpecifiedFetch()); - oldMapping.getRelationshipReference().initializeOn(this.relationshipReference); - this.cascade.initializeFrom(oldMapping.getCascade()); - //TODO should we set the fetch type from a BasicMapping?? - } - - public Iterator<String> allTargetEntityAttributeNames() { - Entity targetEntity = this.getResolvedTargetEntity(); - return (targetEntity == null) ? EmptyIterator.<String> instance() : targetEntity.getPersistentType().allAttributeNames(); - } - - public Iterator<String> candidateMappedByAttributeNames() { - return this.allTargetEntityAttributeNames(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - validateTargetEntity(messages); - this.relationshipReference.validate(messages, reporter); - } - - protected void validateTargetEntity(List<IMessage> messages) { - if (getTargetEntity() == null) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED, - new String[] {this.getName()}, - this, - this.getValidationTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TARGET_ENTITY_NOT_DEFINED, - new String[] {this.getName()}, - this, - this.getValidationTextRange() - ) - ); - } - } - else if (getResolvedTargetEntity() == null) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY, - new String[] {this.getName(), getTargetEntity()}, - this, - this.getValidationTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TARGET_ENTITY_IS_NOT_AN_ENTITY, - new String[] {getTargetEntity(), this.getName()}, - this, - this.getTargetEntityTextRange() - ) - ); - } - } - } - - protected TextRange getTextRange(TextRange textRange) { - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(); - } - - protected TextRange getTargetEntityTextRange() { - return this.getTextRange(this.getResourceAttributeMapping().getTargetEntityTextRange()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java deleted file mode 100644 index 80bd196088..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.AbstractXmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; - -public abstract class AbstractOrmRelationshipReference - extends AbstractOrmXmlContextNode - implements OrmRelationshipReference -{ - protected AbstractXmlRelationshipMapping resourceMapping; - - // cache the strategy for property change notification - protected JoiningStrategy cachedPredominantJoiningStrategy; - - - protected AbstractOrmRelationshipReference( - OrmRelationshipMapping parent, AbstractXmlRelationshipMapping resourceMapping) { - super(parent); - this.resourceMapping = resourceMapping; - this.initialize(); - } - - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - // no op - } - - public void initializeFromJoinColumnEnabledRelationshipReference( - OrmJoinColumnEnabledRelationshipReference oldRelationshipReference) { - // no op - } - - public void initializeFromJoinTableEnabledRelationshipReference( - OrmJoinTableEnabledRelationshipReference oldRelationshipReference) { - // no op - } - - public OrmRelationshipMapping getRelationshipMapping() { - return (OrmRelationshipMapping) getParent(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public Entity getEntity() { - TypeMapping typeMapping = getTypeMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - public boolean isOverridableAssociation() { - return getPredominantJoiningStrategy().isOverridableAssociation(); - } - - public boolean isParentVirtual() { - return getRelationshipMapping().getPersistentAttribute().isVirtual(); - } - - - // **************** predominant joining strategy *************************** - - public JoiningStrategy getPredominantJoiningStrategy() { - return this.cachedPredominantJoiningStrategy; - } - - protected void setPredominantJoiningStrategy(JoiningStrategy newJoiningStrategy) { - JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; - this.cachedPredominantJoiningStrategy = newJoiningStrategy; - firePropertyChanged(PREDOMINANT_JOINING_STRATEGY_PROPERTY, oldJoiningStrategy, newJoiningStrategy); - } - - - // **************** resource -> context ************************************ - - protected void initialize() { - initializeJoiningStrategies(); - this.cachedPredominantJoiningStrategy = calculatePredominantJoiningStrategy(); - } - - protected abstract void initializeJoiningStrategies(); - - - public void update() { - updateJoiningStrategies(); - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); - } - - protected abstract void updateJoiningStrategies(); - - protected abstract JoiningStrategy calculatePredominantJoiningStrategy(); - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange() { - return getRelationshipMapping().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSequenceGenerator.java deleted file mode 100644 index 4f3f6df0be..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSequenceGenerator.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; - -/** - * - */ -public abstract class AbstractOrmSequenceGenerator - extends AbstractOrmGenerator<XmlSequenceGenerator> - implements OrmSequenceGenerator -{ - - protected String specifiedSequenceName; - protected String defaultSequenceName; - - - protected AbstractOrmSequenceGenerator(XmlContextNode parent, XmlSequenceGenerator resourceSequenceGenerator) { - super(parent); - this.initialize(resourceSequenceGenerator); - } - - - @Override - public int getDefaultInitialValue() { - return SequenceGenerator.DEFAULT_INITIAL_VALUE; - } - - // ********** sequence name ********** - - public String getSequenceName() { - return (this.specifiedSequenceName != null) ? this.specifiedSequenceName : this.defaultSequenceName; - } - - public String getSpecifiedSequenceName() { - return this.specifiedSequenceName; - } - - public void setSpecifiedSequenceName(String specifiedSequenceName) { - String old = this.specifiedSequenceName; - this.specifiedSequenceName = specifiedSequenceName; - this.getResourceGenerator().setSequenceName(specifiedSequenceName); - this.firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, old, specifiedSequenceName); - } - - protected void setSpecifiedSequenceName_(String specifiedSequenceName) { - String old = this.specifiedSequenceName; - this.specifiedSequenceName = specifiedSequenceName; - this.firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, old, specifiedSequenceName); - } - - public String getDefaultSequenceName() { - return this.defaultSequenceName; - } - - protected void setDefaultSequenceName(String defaultSequenceName) { - String old = this.defaultSequenceName; - this.defaultSequenceName = defaultSequenceName; - this.firePropertyChanged(DEFAULT_SEQUENCE_NAME_PROPERTY, old, defaultSequenceName); - } - - - // ********** resource => context ********** - - @Override - protected void initialize(XmlSequenceGenerator sequenceGenerator) { - super.initialize(sequenceGenerator); - this.specifiedSequenceName = sequenceGenerator.getSequenceName(); - //TODO default sequence name - } - - @Override - public void update(XmlSequenceGenerator sequenceGenerator) { - super.update(sequenceGenerator); - this.setSpecifiedSequenceName_(sequenceGenerator.getSequenceName()); - //TODO default sequence name - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java deleted file mode 100644 index 0a5a3dd7c1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmSingleRelationshipMapping; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlDerivedId; -import org.eclipse.jpt.core.resource.orm.AbstractXmlSingleRelationshipMapping; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmSingleRelationshipMapping<T extends AbstractXmlSingleRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> - implements OrmSingleRelationshipMapping2_0 -{ - protected Boolean specifiedOptional; - - protected final OrmDerivedId2_0 derivedId; - - protected AbstractOrmSingleRelationshipMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.specifiedOptional = this.getResourceOptional(); - //TODO defaultOptional - this.derivedId = buildDerivedId(); - } - - @Override - public void initializeFromOrmSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - super.initializeFromOrmSingleRelationshipMapping(oldMapping); - getDerivedId().setValue(((OrmSingleRelationshipMapping2_0) oldMapping).getDerivedId().getValue()); - } - - @Override - protected String getResourceDefaultTargetEntity() { - return this.getJavaPersistentAttribute().getSingleReferenceEntityTypeName(); - } - - public FetchType getDefaultFetch() { - return DEFAULT_FETCH_TYPE; - } - - - // **************** optional *********************************************** - - public boolean isOptional() { - return (this.specifiedOptional != null) ? this.specifiedOptional.booleanValue() : this.isDefaultOptional(); - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean optional) { - Boolean old = this.specifiedOptional; - this.specifiedOptional = optional; - this.resourceAttributeMapping.setOptional(optional); - this.firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, old, optional); - } - - protected void setSpecifiedOptional_(Boolean optional) { - Boolean old = this.specifiedOptional; - this.specifiedOptional = optional; - this.firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, old, optional); - } - - public boolean isDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - // **************** 2.0 derived id *********************************************** - - protected OrmDerivedId2_0 buildDerivedId() { - //TODO ORM this can change once we collapse the orm resource model - if (this.resourceAttributeMapping instanceof XmlDerivedId) { - return ((OrmXml2_0ContextNodeFactory) getXmlContextNodeFactory()).buildOrmDerivedId(this, (XmlDerivedId) this.resourceAttributeMapping); - } - return ((OrmXml2_0ContextNodeFactory) getXmlContextNodeFactory()).buildOrmDerivedId(this, null); - } - - - public OrmDerivedId2_0 getDerivedId() { - return this.derivedId; - } - - @Override - public boolean isIdMapping() { - return this.derivedId.getValue(); - } - - - // **************** resource => context ************************************ - - @Override - public void update() { - super.update(); - this.setSpecifiedOptional_(this.getResourceOptional()); - this.derivedId.update(); - } - - protected Boolean getResourceOptional() { - return this.resourceAttributeMapping.getOptional(); - } - - - // **************** validation ************************************ - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.derivedId.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java deleted file mode 100644 index a1abd260cc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java +++ /dev/null @@ -1,475 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - -/** - * - */ -public abstract class AbstractOrmTable - extends AbstractOrmXmlContextNode - implements Table, UniqueConstraint.Owner -{ - protected String specifiedName; - protected String defaultName; - - protected String specifiedSchema; - protected String defaultSchema; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected final List<OrmUniqueConstraint> uniqueConstraints; - - - // ********** constructor ********** - - protected AbstractOrmTable(XmlContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<OrmUniqueConstraint>(); - } - - - // ********** abstract methods ********** - - /** - * Return null if no resource table exists. - */ - protected abstract AbstractXmlTable getResourceTable(); - - /** - * Return the added resource table. - */ - protected abstract AbstractXmlTable addResourceTable(); - - protected abstract void removeResourceTable(); - - protected abstract String buildDefaultName(); - - protected abstract String buildDefaultSchema(); - - protected abstract String buildDefaultCatalog(); - - - public boolean isResourceSpecified() { - return this.getResourceTable() != null; - } - - // ********** name ********** - - public String getName() { - return (this.specifiedName != null) ? this.specifiedName : this.defaultName; - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String name) { - String old = this.specifiedName; - this.specifiedName = name; - if (this.attributeValueHasChanged(old, name)) { - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.setName(name); - if (resourceTable.isUnset()) { - this.removeResourceTable(); - } - this.firePropertyChanged(SPECIFIED_NAME_PROPERTY, old, name); - } - } - - protected void setSpecifiedName_(String name) { - String old = this.specifiedName; - this.specifiedName = name; - this.firePropertyChanged(SPECIFIED_NAME_PROPERTY, old, name); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String name) { - String old = this.defaultName; - this.defaultName = name; - this.firePropertyChanged(DEFAULT_NAME_PROPERTY, old, name); - } - - - // ********** schema ********** - - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - if (this.attributeValueHasChanged(old, schema)) { - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.setSchema(schema); - if (resourceTable.isUnset()) { - this.removeResourceTable(); - } - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - } - - protected void setSpecifiedSchema_(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - - // ********** catalog ********** - - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - if (this.attributeValueHasChanged(old, catalog)) { - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.setCatalog(catalog); - if (resourceTable.isUnset()) { - this.removeResourceTable(); - } - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - } - - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - - // ********** unique constraints ********** - - public @SuppressWarnings("unchecked") ListIterator<OrmUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<OrmUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public OrmUniqueConstraint addUniqueConstraint(int index) { - XmlUniqueConstraint resourceConstraint = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - OrmUniqueConstraint contextConstraint = this.buildUniqueConstraint(resourceConstraint); - this.uniqueConstraints.add(index, contextConstraint); - - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.getUniqueConstraints().add(index, resourceConstraint); - - this.fireItemAdded(UNIQUE_CONSTRAINTS_LIST, index, contextConstraint); - return contextConstraint; - } - - protected void addUniqueConstraint(int index, OrmUniqueConstraint uniqueConstraint) { - this.addItemToList(index, uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - protected void addUniqueConstraint(OrmUniqueConstraint uniqueConstraint) { - this.addUniqueConstraint(this.uniqueConstraints.size(), uniqueConstraint); - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - OrmUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - this.getResourceTable().getUniqueConstraints().remove(index); - this.fireItemRemoved(UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - protected void removeUniqueConstraint_(OrmUniqueConstraint uniqueConstraint) { - this.removeItemFromList(uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getResourceTable().getUniqueConstraints().move(targetIndex, sourceIndex); - this.fireItemMoved(UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - - // ********** convenience methods ********** - - protected TextRange getTextRange(TextRange textRange) { - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(); - } - - protected TextRange getNameTextRange() { - return this.getTextRange(this.getResourceTableNameTextRange()); - } - - protected TextRange getResourceTableNameTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getNameTextRange(); - } - - protected TextRange getSchemaTextRange() { - return this.getTextRange(this.getResourceTableSchemaTextRange()); - } - - protected TextRange getResourceTableSchemaTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getSchemaTextRange(); - } - - protected TextRange getCatalogTextRange() { - return this.getTextRange(this.getResourceTableCatalogTextRange()); - } - - protected TextRange getResourceTableCatalogTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getCatalogTextRange(); - } - - protected OrmUniqueConstraint buildUniqueConstraint(XmlUniqueConstraint resourceUniqueConstraint) { - return this.getXmlContextNodeFactory().buildOrmUniqueConstraint(this, this, resourceUniqueConstraint); - } - - - // ********** resource => context ********** - - protected void initialize(AbstractXmlTable xmlTable) { - this.defaultName = this.buildDefaultName(); - this.specifiedName = this.getResourceTableName(xmlTable); - - this.defaultSchema = this.buildDefaultSchema(); - this.specifiedSchema = this.getResourceTableSchema(xmlTable); - - this.defaultCatalog = this.buildDefaultCatalog(); - this.specifiedCatalog = this.getResourceTableCatalog(xmlTable); - - this.initializeUniqueContraints(xmlTable); - } - - protected void initializeUniqueContraints(AbstractXmlTable xmlTable) { - if (xmlTable == null) { - return; - } - for (XmlUniqueConstraint uniqueConstraint : xmlTable.getUniqueConstraints()) { - this.uniqueConstraints.add(this.buildUniqueConstraint(uniqueConstraint)); - } - } - - protected void update(AbstractXmlTable xmlTable) { - this.setDefaultName(this.buildDefaultName()); - this.setSpecifiedName_(this.getResourceTableName(xmlTable)); - - this.setDefaultSchema(this.buildDefaultSchema()); - this.setSpecifiedSchema_(this.getResourceTableSchema(xmlTable)); - - this.setDefaultCatalog(this.buildDefaultCatalog()); - this.setSpecifiedCatalog_(this.getResourceTableCatalog(xmlTable)); - - this.updateUniqueConstraints(xmlTable); - } - - protected String getResourceTableName(AbstractXmlTable xmlTable) { - return (xmlTable == null) ? null : xmlTable.getName(); - } - - protected String getResourceTableSchema(AbstractXmlTable xmlTable) { - return (xmlTable == null) ? null : xmlTable.getSchema(); - } - - protected String getResourceTableCatalog(AbstractXmlTable xmlTable) { - return (xmlTable == null) ? null : xmlTable.getCatalog(); - } - - protected void updateUniqueConstraints(AbstractXmlTable xmlTable) { - Iterator<XmlUniqueConstraint> xmlConstraints = this.xmlUniqueConstraints(xmlTable); - - for (Iterator<OrmUniqueConstraint> contextConstraints = this.uniqueConstraints(); contextConstraints.hasNext(); ) { - OrmUniqueConstraint contextConstraint = contextConstraints.next(); - if (xmlConstraints.hasNext()) { - contextConstraint.update(xmlConstraints.next()); - } else { - this.removeUniqueConstraint_(contextConstraint); - } - } - - while (xmlConstraints.hasNext()) { - this.addUniqueConstraint(this.buildUniqueConstraint(xmlConstraints.next())); - } - } - - protected Iterator<XmlUniqueConstraint> xmlUniqueConstraints(AbstractXmlTable xmlTable) { - // make a copy of the XML constraints (to prevent ConcurrentModificationException) - return (xmlTable == null) ? EmptyIterator.<XmlUniqueConstraint>instance() - : new CloneIterator<XmlUniqueConstraint>(xmlTable.getUniqueConstraints()); - } - - public void initializeFrom(Table oldTable) { - this.setSpecifiedName(oldTable.getSpecifiedName()); - this.setSpecifiedCatalog(oldTable.getSpecifiedCatalog()); - this.setSpecifiedSchema(oldTable.getSpecifiedSchema()); - } - - - // ********** database stuff ********** - - public org.eclipse.jpt.db.Table getDbTable() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema == null) ? null : dbSchema.getTableForIdentifier(this.getName()); - } - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - public boolean isResolved() { - return this.getDbTable() != null; - } - - public boolean hasResolvedSchema() { - return this.getDbSchema() != null; - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public boolean hasResolvedCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) || (this.getDbCatalog(catalog) != null); - } - - - // ********** UniqueConstraint.Owner implementation ********** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.sortedColumnIdentifiers() : EmptyIterator.<String>instance(); - } - - - // ********** validation ********** - - public TextRange getValidationTextRange() { - return this.getTextRange(this.getResourceTableValidationTextRange()); - } - - protected TextRange getResourceTableValidationTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getValidationTextRange(); - } - - - // ********** misc ********** - - /** - * covariant override - */ - @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.getQualifiedName()); - } - - protected String getQualifiedName() { - return NameTools.buildQualifiedDatabaseObjectName(this.getCatalog(), this.getSchema(), this.getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java deleted file mode 100644 index 01e23fdaa1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java +++ /dev/null @@ -1,282 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmTypeMapping<T extends XmlTypeMapping> - extends AbstractOrmXmlContextNode - implements OrmTypeMapping -{ - protected String class_; - - public boolean defaultMetadataComplete; - - protected Boolean specifiedMetadataComplete; - - protected final T resourceTypeMapping; - - - protected AbstractOrmTypeMapping(OrmPersistentType parent, T resourceMapping) { - super(parent); - this.resourceTypeMapping = resourceMapping; - this.class_ = this.getResourceClassName(); - this.specifiedMetadataComplete = this.getResourceMetadataComplete(); - this.defaultMetadataComplete = this.getPersistentType().isDefaultMetadataComplete(); - } - - // **************** Type Mapping implementation ***************************** - - @Override - public OrmPersistentType getParent() { - return (OrmPersistentType) super.getParent(); - } - - public OrmPersistentType getPersistentType() { - return this.getParent(); - } - - protected JavaPersistentType getJavaPersistentType() { - return this.getPersistentType().getJavaPersistentType(); - } - - public boolean isMapped() { - return true; - } - - public String getPrimaryTableName() { - return null; - } - - public String getClass_() { - return this.class_; - } - - public void setClass(String newClass) { - String oldClass = this.class_; - this.class_ = newClass; - this.resourceTypeMapping.setClassName(newClass); - firePropertyChanged(CLASS_PROPERTY, oldClass, newClass); - getPersistentType().classChanged(oldClass, newClass); - } - - - public boolean isMetadataComplete() { - if (isDefaultMetadataComplete()) { - //entity-mappings/persistence-unit-metadata/xml-mapping-metadata-complete is specified, then it overrides - //anything set here - return true; - } - return (this.getSpecifiedMetadataComplete() == null) ? this.isDefaultMetadataComplete() : this.getSpecifiedMetadataComplete().booleanValue(); - } - - public boolean isDefaultMetadataComplete() { - return this.defaultMetadataComplete; - } - - protected void setDefaultMetadataComplete(boolean newDefaultMetadataComplete) { - boolean oldMetadataComplete = this.defaultMetadataComplete; - this.defaultMetadataComplete = newDefaultMetadataComplete; - firePropertyChanged(DEFAULT_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newDefaultMetadataComplete); - } - - public Boolean getSpecifiedMetadataComplete() { - return this.specifiedMetadataComplete; - } - - public void setSpecifiedMetadataComplete(Boolean newSpecifiedMetadataComplete) { - Boolean oldMetadataComplete = this.specifiedMetadataComplete; - this.specifiedMetadataComplete = newSpecifiedMetadataComplete; - this.resourceTypeMapping.setMetadataComplete(newSpecifiedMetadataComplete); - firePropertyChanged(SPECIFIED_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newSpecifiedMetadataComplete); - } - - /** - * ITypeMapping is changed and various ITypeMappings may have - * common settings. In this method initialize the new ITypeMapping (this) - * fromthe old ITypeMapping (oldMapping) - */ - public void initializeFrom(OrmTypeMapping oldMapping) { - this.setClass(oldMapping.getClass_()); - this.setSpecifiedMetadataComplete(oldMapping.getSpecifiedMetadataComplete()); - this.setDefaultMetadataComplete(oldMapping.isDefaultMetadataComplete()); - } - - public Table getPrimaryDbTable() { - return null; - } - - public Table getDbTable(String tableName) { - return null; - } - - public Schema getDbSchema() { - return null; - } - - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return true; - } - - public ListIterator<OrmAttributeMapping> attributeMappings() { - return new TransformationListIterator<OrmPersistentAttribute, OrmAttributeMapping>(getPersistentType().attributes()) { - @Override - protected OrmAttributeMapping transform(OrmPersistentAttribute next) { - return next.getMapping(); - } - }; - } - - public Iterator<OrmColumnMapping> overridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAttributeNames() { - return this.namesOf(this.overridableAttributes()); - } - - public Iterator<ColumnMapping> allOverridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAttributeNames() { - return this.namesOf(this.allOverridableAttributes()); - } - - public Iterator<OrmRelationshipMapping> overridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAssociationNames() { - return this.namesOf(this.overridableAssociations()); - } - - public Iterator<RelationshipMapping> allOverridableAssociations() { - return EmptyIterator.instance(); - } - - private Iterator<String> namesOf(Iterator<? extends AttributeMapping> attributeMappings) { - return new TransformationIterator<AttributeMapping, String>(attributeMappings) { - @Override - protected String transform(AttributeMapping attributeMapping) { - return attributeMapping.getName(); - } - }; - } - - public Iterator<String> allOverridableAssociationNames() { - return this.namesOf(this.allOverridableAssociations()); - } - - public T getResourceTypeMapping() { - return this.resourceTypeMapping; - } - - public void update() { - this.setClass(this.getResourceClassName()); - this.setSpecifiedMetadataComplete(this.getResourceMetadataComplete()); - this.setDefaultMetadataComplete(this.getPersistentType().isDefaultMetadataComplete()); - } - - protected String getResourceClassName() { - return this.resourceTypeMapping.getClassName(); - } - - protected Boolean getResourceMetadataComplete() { - return this.resourceTypeMapping.getMetadataComplete(); - } - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int offset) { - if (this.resourceTypeMapping.containsOffset(offset)) { - return getPersistentType(); - } - return null; - } - - public TextRange getSelectionTextRange() { - return this.resourceTypeMapping.getSelectionTextRange(); - } - - public TextRange getClassTextRange() { - return this.resourceTypeMapping.getClassTextRange(); - } - - public TextRange getAttributesTextRange() { - return this.resourceTypeMapping.getAttributesTextRange(); - } - - public boolean containsOffset(int textOffset) { - return (this.resourceTypeMapping != null) - && this.resourceTypeMapping.containsOffset(textOffset); - } - - //************************* validation ************************ - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateClass(messages); - } - - protected void validateClass(List<IMessage> messages) { - if (StringTools.stringIsEmpty(this.class_)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CLASS, - this, - this.getClassTextRange() - ) - ); - return; - } - } - - public boolean shouldValidateAgainstDatabase() { - return getPersistenceUnit().shouldValidateAgainstDatabase(); - } - - public TextRange getValidationTextRange() { - return this.resourceTypeMapping.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getPersistentType().getName()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmVersionMapping.java deleted file mode 100644 index 0675e35940..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmVersionMapping.java +++ /dev/null @@ -1,239 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmVersionMapping<T extends XmlVersion> - extends AbstractOrmAttributeMapping<T> - implements OrmVersionMapping -{ - protected final OrmColumn column; - - protected OrmConverter defaultConverter; - protected OrmConverter specifiedConverter; - - protected AbstractOrmVersionMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.column = getXmlContextNodeFactory().buildOrmColumn(this, this); - this.column.initialize(this.getResourceColumn());//TODO pass in to constructor - this.defaultConverter = getXmlContextNodeFactory().buildOrmNullConverter(this); - this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); - } - - public int getXmlSequence() { - return 30; - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmVersionMapping(this); - } - - @Override - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromOrmColumnMapping(oldMapping); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public OrmColumn getColumn() { - return this.column; - } - - public OrmConverter getConverter() { - return getSpecifiedConverter() == null ? getDefaultConverter() : getSpecifiedConverter(); - } - - public OrmConverter getDefaultConverter() { - return this.defaultConverter; - } - - public OrmConverter getSpecifiedConverter() { - return this.specifiedConverter; - } - - protected String getSpecifedConverterType() { - if (this.specifiedConverter == null) { - return Converter.NO_CONVERTER; - } - return this.specifiedConverter.getType(); - } - - public void setSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(getSpecifedConverterType(), converterType)) { - return; - } - OrmConverter oldConverter = this.specifiedConverter; - OrmConverter newConverter = buildSpecifiedConverter(converterType); - this.specifiedConverter = null; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.specifiedConverter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setSpecifiedConverter(OrmConverter newConverter) { - OrmConverter oldConverter = this.specifiedConverter; - this.specifiedConverter = newConverter; - firePropertyChanged(SPECIFIED_CONVERTER_PROPERTY, oldConverter, newConverter); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getVersions().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getVersions().remove(this.resourceAttributeMapping); - } - - public String getDefaultColumnName() { - return getName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - @Override - public void update() { - super.update(); - this.column.update(this.getResourceColumn()); - if (this.valuesAreEqual(getResourceConverterType(), getSpecifedConverterType())) { - getSpecifiedConverter().update(); - } - else { - setSpecifiedConverter(buildSpecifiedConverter(getResourceConverterType())); - } - } - - protected OrmConverter buildSpecifiedConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmTemporalConverter(this, this.resourceAttributeMapping); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourceAttributeMapping.getTemporal() != null) { - return Converter.TEMPORAL_CONVERTER; - } - - return null; - } - - //***************** XmlColumn.Owner implementation **************** - - public XmlColumn getResourceColumn() { - return this.resourceAttributeMapping.getColumn(); - } - - public void addResourceColumn() { - this.resourceAttributeMapping.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - this.resourceAttributeMapping.setColumn(null); - } - - // ****************** validation **************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (this.shouldValidateAgainstDatabase()) { - this.validateColumn(messages); - } - } - - protected void validateColumn(List<IMessage> messages) { - OrmPersistentAttribute pa = this.getPersistentAttribute(); - String tableName = this.column.getTable(); - if (this.getTypeMapping().tableNameIsInvalid(tableName)) { - if (pa.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {pa.getName(), tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - if (pa.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {pa.getName(), this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNode.java deleted file mode 100644 index 838380c151..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNode.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.context.orm.OrmXmlDefinition; -import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; - -/** - * Use this abstract class for context nodes that are part of an OrmXml file. - * This will not work for purely MappingFile implementations - */ -public abstract class AbstractOrmXmlContextNode - extends AbstractXmlContextNode - implements XmlContextNode -{ - - // ********** constructor ********** - - protected AbstractOrmXmlContextNode(JpaContextNode parent) { - super(parent); - } - - public OrmXmlDefinition getMappingFileDefinition() { - return (OrmXmlDefinition) getJpaPlatform().getMappingFileDefinition(getContentType()); - } - - public EFactory getResourceNodeFactory() { - return getMappingFileDefinition().getResourceNodeFactory(); - } - - public OrmXmlContextNodeFactory getXmlContextNodeFactory() { - return getMappingFileDefinition().getContextNodeFactory(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlDefinition.java deleted file mode 100644 index ae2f1db9b3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlDefinition.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.context.orm.OrmXmlDefinition; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Tools; -import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; - -/** - * All the state in the definition should be "static" (i.e. unchanging once it is initialized). - */ -public abstract class AbstractOrmXmlDefinition - implements OrmXmlDefinition -{ - private OrmTypeMappingDefinition[] ormTypeMappingDefinitions; - - private OrmAttributeMappingDefinition[] ormAttributeMappingDefinitions; - - private final OrmXmlContextNodeFactory factory; - - - /** - * zero-argument constructor - */ - protected AbstractOrmXmlDefinition() { - super(); - this.factory = buildContextNodeFactory(); - } - - - protected abstract OrmXmlContextNodeFactory buildContextNodeFactory(); - - public OrmXmlContextNodeFactory getContextNodeFactory() { - return this.factory; - } - - - // ********** ORM type mappings ********** - - public OrmTypeMappingDefinition getOrmTypeMappingDefinition(String mappingKey) { - for (OrmTypeMappingDefinition definition : CollectionTools.iterable(ormTypeMappingDefinitions())) { - if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) { - return definition; - } - } - throw new IllegalArgumentException("Illegal type mapping key: " + mappingKey); //$NON-NLS-1$ - } - - public ListIterator<OrmTypeMappingDefinition> ormTypeMappingDefinitions() { - return new ArrayListIterator<OrmTypeMappingDefinition>(getOrmTypeMappingDefinitions()); - } - - protected synchronized OrmTypeMappingDefinition[] getOrmTypeMappingDefinitions() { - if (this.ormTypeMappingDefinitions == null) { - this.ormTypeMappingDefinitions = this.buildOrmTypeMappingDefinitions(); - } - return this.ormTypeMappingDefinitions; - } - - /** - * Return an array of mapping definitions to use for types in mapping files of this type. - * The order is unimportant. - */ - protected abstract OrmTypeMappingDefinition[] buildOrmTypeMappingDefinitions(); - - - // ********** ORM attribute mappings ********** - - public OrmAttributeMappingDefinition getOrmAttributeMappingDefinition(String mappingKey) { - for (OrmAttributeMappingDefinition definition : CollectionTools.iterable(ormAttributeMappingDefinitions())) { - if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) { - return definition; - } - } - throw new IllegalArgumentException("Illegal type mapping key: " + mappingKey); //$NON-NLS-1$ - } - - public ListIterator<OrmAttributeMappingDefinition> ormAttributeMappingDefinitions() { - return new ArrayListIterator<OrmAttributeMappingDefinition>(getOrmAttributeMappingDefinitions()); - } - - protected synchronized OrmAttributeMappingDefinition[] getOrmAttributeMappingDefinitions() { - if (this.ormAttributeMappingDefinitions == null) { - this.ormAttributeMappingDefinitions = this.buildOrmAttributeMappingDefinitions(); - } - return this.ormAttributeMappingDefinitions; - } - - /** - * Return an array of mapping definitions to use for attributes in mapping files of this type. - * The order is unimportant. - */ - protected abstract OrmAttributeMappingDefinition[] buildOrmAttributeMappingDefinitions(); -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.java deleted file mode 100644 index c6b54c25a5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.BaseJoinColumn; -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.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnInAssociationOverrideJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn.Owner; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; - -public class GenericOrmJoinColumnInAssociationOverrideJoiningStrategy - extends AbstractOrmJoinColumnJoiningStrategy - implements OrmJoinColumnInAssociationOverrideJoiningStrategy -{ - - public GenericOrmJoinColumnInAssociationOverrideJoiningStrategy(OrmAssociationOverrideRelationshipReference parent, XmlAssociationOverride xao) { - super(parent, xao); - } - - @Override - protected Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - public TypeMapping getTypeMapping() { - return getAssociationOverride().getOwner().getTypeMapping(); - } - - public boolean isOverridableAssociation() { - return false; - } - - protected OrmAssociationOverride getAssociationOverride() { - return this.getRelationshipReference().getAssociationOverride(); - } - - @Override - public OrmAssociationOverrideRelationshipReference getRelationshipReference() { - return (OrmAssociationOverrideRelationshipReference) super.getRelationshipReference(); - } - - public TextRange getValidationTextRange() { - return getRelationshipReference().getValidationTextRange(); - } - - public void update(XmlAssociationOverride xao) { - //TODO can we make resource final and then just have an update() method? - //would need to update the association overrides with the same resource association override - this.resource = xao; - super.update(); - } - - - - // ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements OrmJoinColumn.Owner - { - protected JoinColumnOwner() { - super(); - } - - protected AssociationOverride getAssociationOverride() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipReference().getAssociationOverride(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public Entity getTargetEntity() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return getAssociationOverride().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return getAssociationOverride().getOwner().getRelationshipMapping(GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipReference().getAssociationOverride().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 getAssociationOverride().getOwner().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return false; - } - - public int joinColumnsSize() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getValidationTextRange(); - } - - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnJoiningStrategy.java deleted file mode 100644 index ea6b6feb20..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.BaseJoinColumn; -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.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn.Owner; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumnsMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; - -public class GenericOrmJoinColumnJoiningStrategy - extends AbstractOrmJoinColumnJoiningStrategy -{ - - public GenericOrmJoinColumnJoiningStrategy( - OrmJoinColumnEnabledRelationshipReference parent, - XmlJoinColumnsMapping resource) { - super(parent, resource); - } - - @Override - protected Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public boolean isOverridableAssociation() { - return true; - } - - @Override - public OrmJoinColumnEnabledRelationshipReference getRelationshipReference() { - return (OrmJoinColumnEnabledRelationshipReference) super.getRelationshipReference(); - } - - public TextRange getValidationTextRange() { - return this.getRelationshipReference().getValidationTextRange(); - } - - // ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements OrmJoinColumn.Owner - { - protected JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public Entity getTargetEntity() { - return getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return getRelationshipMapping().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericOrmJoinColumnJoiningStrategy.this.getRelationshipMapping(); - } - - 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 getRelationshipMapping().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmJoinColumnJoiningStrategy.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public int joinColumnsSize() { - return GenericOrmJoinColumnJoiningStrategy.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return GenericOrmJoinColumnJoiningStrategy.this.getValidationTextRange(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTableJoiningStrategy.java deleted file mode 100644 index 6d48894975..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTableJoiningStrategy.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlJoinTableMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmJoinTableJoiningStrategy - extends AbstractOrmJoinTableJoiningStrategy -{ - protected XmlJoinTableMapping resource; - - - public GenericOrmJoinTableJoiningStrategy( - OrmJoinTableEnabledRelationshipReference parent, - XmlJoinTableMapping resource) { - super(parent); - this.resource = resource; - this.initialize(); - } - - - @Override - public OrmJoinTableEnabledRelationshipReference getParent() { - return (OrmJoinTableEnabledRelationshipReference) super.getParent(); - } - - @Override - public OrmJoinTableEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - @Override - public OrmRelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - @Override - protected void setResourceJoinTable(XmlJoinTable resourceJoinTable) { - this.resource.setJoinTable(resourceJoinTable); - } - - public boolean isOverridableAssociation() { - return getJpaPlatformVariation().isJoinTableOverridable(); - } - - - // **************** join table ********************************************* - - @Override - public OrmJoinTable getJoinTable() { - return this.joinTable; - } - - @Override - public OrmJoinTable addJoinTable() { - addStrategy(); - return this.joinTable; - } - - @Override - protected void setJoinTable_(OrmJoinTable newJoinTable) { - OrmJoinTable oldJoinTable = this.joinTable; - this.joinTable = newJoinTable; - this.firePropertyChanged(JOIN_TABLE_PROPERTY, oldJoinTable, newJoinTable); - } - - @Override - public XmlJoinTable addResourceJoinTable() { - XmlJoinTable resourceJoinTable = OrmFactory.eINSTANCE.createXmlJoinTable(); - this.resource.setJoinTable(resourceJoinTable); - return resourceJoinTable; - } - - public void removeResourceJoinTable() { - this.resource.setJoinTable(null); - } - - @Override - protected boolean mayHaveJoinTable() { - return getResourceJoinTable() != null - || getRelationshipReference().mayHaveDefaultJoinTable(); - } - - public XmlJoinTable getResourceJoinTable() { - return this.resource.getJoinTable(); - } - - - // **************** resource -> context ************************************ - - @Override - public void update() { - if (mayHaveJoinTable()) { - if (this.joinTable == null) { - setJoinTable_(getXmlContextNodeFactory().buildOrmJoinTable(this, getResourceJoinTable())); - } - this.joinTable.update(); - } - else { - if (this.joinTable != null) { - // no resource, so no clean up - setJoinTable_(null); - } - } - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.joinTable != null && getRelationshipMapping().shouldValidateAgainstDatabase()) { - this.joinTable.validate(messages, reporter); - } - } - - public TextRange getValidationTextRange() { - return getRelationshipReference().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java deleted file mode 100644 index be0a784f15..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmManyToManyRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmManyToManyRelationshipReference -{ - protected OrmMappedByJoiningStrategy mappedByJoiningStrategy; - - protected OrmJoinTableJoiningStrategy joinTableJoiningStrategy; - - - public GenericOrmManyToManyRelationshipReference( - OrmManyToManyMapping parent, XmlManyToMany resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - - // initialize join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - } - - protected OrmMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericOrmMappedByJoiningStrategy(this, getResourceMapping()); - } - - protected OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new GenericOrmJoinTableJoiningStrategy(this, getResourceMapping()); - } - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromOwnableRelationshipReference(this); - newRelationshipReference.initializeFromJoinTableEnabledRelationshipReference(this); - } - - @Override - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - super.initializeFromOwnableRelationshipReference(oldRelationshipReference); - this.mappedByJoiningStrategy.setMappedByAttribute( - oldRelationshipReference.getMappedByJoiningStrategy().getMappedByAttribute()); - } - - @Override - public void initializeFromJoinTableEnabledRelationshipReference( - OrmJoinTableEnabledRelationshipReference oldRelationshipReference) { - super.initializeFromJoinTableEnabledRelationshipReference(oldRelationshipReference); - OrmJoinTable oldTable = - oldRelationshipReference.getJoinTableJoiningStrategy().getJoinTable(); - if (oldTable != null) { - this.joinTableJoiningStrategy.addJoinTable().initializeFrom(oldTable); - } - } - - - @Override - public OrmManyToManyMapping getRelationshipMapping() { - return (OrmManyToManyMapping) super.getRelationshipMapping(); - } - - public XmlManyToMany getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - else { - return this.joinTableJoiningStrategy; - } - } - - - // **************** mapped by ********************************************** - - public OrmMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public boolean usesMappedByJoiningStrategy() { - return getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join table joining strategy *************************** - - public OrmJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public void setJoinTableJoiningStrategy() { - // join table is the default strategy, so no need to add to resource - this.mappedByJoiningStrategy.removeStrategy(); - } - - public void unsetJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return getMappedByJoiningStrategy().getMappedByAttribute() == null; - } - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - - // update join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.mappedByJoiningStrategy.validate(messages, reporter); - this.joinTableJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java deleted file mode 100644 index 46104045a0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmManyToOneRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmManyToOneRelationshipReference -{ - protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; - - - public GenericOrmManyToOneRelationshipReference( - OrmManyToOneMapping parent, XmlManyToOne resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - } - - protected OrmJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { - return new GenericOrmJoinColumnJoiningStrategy(this, getResourceMapping()); - } - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromJoinColumnEnabledRelationshipReference(this); - } - - @Override - public void initializeFromJoinColumnEnabledRelationshipReference( - OrmJoinColumnEnabledRelationshipReference oldRelationshipReference) { - int index = 0; - for (JoinColumn joinColumn : - CollectionTools.iterable( - oldRelationshipReference.getJoinColumnJoiningStrategy().specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - @Override - public OrmManyToOneMapping getRelationshipMapping() { - return (OrmManyToOneMapping) getParent(); - } - - public XmlManyToOne getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return true; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return false; - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - // the only joining strategy - return this.joinColumnJoiningStrategy; - } - - - // **************** join columns ******************************************* - - public OrmJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - // join columns are default (only strategy in fact) so no need to add to resource - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return true; - } - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.joinColumnJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.joinColumnJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedByJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedByJoiningStrategy.java deleted file mode 100644 index 72d18f5858..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedByJoiningStrategy.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlMappedByMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmMappedByJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmMappedByJoiningStrategy -{ - protected XmlMappedByMapping resource; - - protected String mappedByAttribute; - - - public GenericOrmMappedByJoiningStrategy( - OrmOwnableRelationshipReference parent, - XmlMappedByMapping resource) { - super(parent); - this.resource = resource; - this.mappedByAttribute = this.resource.getMappedBy(); - } - - - @Override - public OrmOwnableRelationshipReference getParent() { - return (OrmOwnableRelationshipReference) super.getParent(); - } - - public OrmOwnableRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public boolean isOverridableAssociation() { - return false; - } - - public OrmRelationshipMapping getRelationshipMapping() { - return getParent().getRelationshipMapping(); - } - - public boolean relationshipIsOwnedBy(RelationshipMapping otherMapping) { - String thisEntity = - (getRelationshipReference().getEntity()) == null ? - null : getRelationshipReference().getEntity().getName(); - String targetEntity = - (getRelationshipMapping().getResolvedTargetEntity() == null) ? - null : getRelationshipMapping().getResolvedTargetEntity().getName(); - return StringTools.stringsAreEqual( - thisEntity, - targetEntity) - && StringTools.stringsAreEqual( - getMappedByAttribute(), - otherMapping.getName()); - } - - public String getMappedByAttribute() { - return this.mappedByAttribute; - } - - public void setMappedByAttribute(String newMappedByAttribute) { - String oldMappedByAttribute = this.mappedByAttribute; - this.mappedByAttribute = newMappedByAttribute; - this.resource.setMappedBy(newMappedByAttribute); - firePropertyChanged(MAPPED_BY_ATTRIBUTE_PROPERTY, oldMappedByAttribute, newMappedByAttribute); - } - - protected void setMappedByAttribute_(String newMappedByAttribute) { - String oldMappedByAttribute = this.mappedByAttribute; - this.mappedByAttribute = newMappedByAttribute; - firePropertyChanged(MAPPED_BY_ATTRIBUTE_PROPERTY, oldMappedByAttribute, newMappedByAttribute); - } - - public void addStrategy() { - if (this.mappedByAttribute == null) { - setMappedByAttribute(""); - } - } - - public void removeStrategy() { - if (this.mappedByAttribute != null) { - setMappedByAttribute(null); - } - } - - public void update() { - setMappedByAttribute_(this.resource.getMappedBy()); - } - - public Iterator<String> candidateMappedByAttributeNames() { - return getRelationshipMapping().allTargetEntityAttributeNames(); - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (getMappedByAttribute() == null) { - return; - } - - Entity targetEntity = this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return; // null target entity is validated elsewhere - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(this.mappedByAttribute); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {this.mappedByAttribute}, - this, - this.getValidationTextRange() - ) - ); - return; - } - - AttributeMapping mappedByMapping = attribute.getMapping(); - if ( ! this.getRelationshipReference().mayBeMappedBy(mappedByMapping)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {this.mappedByAttribute}, - this, - this.getValidationTextRange() - ) - ); - return; - } - - // if mappedByMapping is not a relationship owner, then it should have - // been flagged in above rule (mappedByIsValid) - if (! ((RelationshipMapping) mappedByMapping).isRelationshipOwner()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, - this.getValidationTextRange() - ) - ); - } - } - - public TextRange getValidationTextRange() { - TextRange mappedByTextRange = this.resource.getMappedByTextRange(); - return mappedByTextRange != null ? mappedByTextRange : getRelationshipReference().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java deleted file mode 100644 index 31b766c09f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmOneToOneRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmOneToOneRelationshipReference -{ - protected OrmMappedByJoiningStrategy mappedByJoiningStrategy; - - protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; - - protected OrmPrimaryKeyJoinColumnJoiningStrategy primaryKeyJoinColumnJoiningStrategy; - - - public GenericOrmOneToOneRelationshipReference( - OrmOneToOneMapping parent, XmlOneToOne resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - this.primaryKeyJoinColumnJoiningStrategy = buildPrimaryKeyJoinColumnJoiningStrategy(); - - // initialize join columns last, as the existence of a default join - // column is dependent on the other mechanisms (mappedBy, join table) - // not being specified - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - } - - protected OrmMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericOrmMappedByJoiningStrategy(this, getResourceMapping()); - } - - protected OrmJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { - return new GenericOrmJoinColumnJoiningStrategy(this, getResourceMapping()); - } - - protected OrmPrimaryKeyJoinColumnJoiningStrategy buildPrimaryKeyJoinColumnJoiningStrategy() { - return new GenericOrmPrimaryKeyJoinColumnJoiningStrategy(this, getResourceMapping()); - } - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromOwnableRelationshipReference(this); - newRelationshipReference.initializeFromJoinColumnEnabledRelationshipReference(this); - // no other primary key reference as of yet, so no initialization based on pk join columns - } - - @Override - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - this.mappedByJoiningStrategy.setMappedByAttribute( - oldRelationshipReference.getMappedByJoiningStrategy().getMappedByAttribute()); - } - - @Override - public void initializeFromJoinColumnEnabledRelationshipReference( - OrmJoinColumnEnabledRelationshipReference oldRelationshipReference) { - int index = 0; - for (JoinColumn joinColumn : - CollectionTools.iterable( - oldRelationshipReference.getJoinColumnJoiningStrategy().specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - @Override - public void initializeFromJoinTableEnabledRelationshipReference( - OrmJoinTableEnabledRelationshipReference oldRelationshipReference) { - // TODO no join table context model support as of yet - - } - - @Override - public OrmOneToOneMapping getRelationshipMapping() { - return (OrmOneToOneMapping) getParent(); - } - - public XmlOneToOne getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - else if (this.primaryKeyJoinColumnJoiningStrategy.primaryKeyJoinColumnsSize() > 0) { - return this.primaryKeyJoinColumnJoiningStrategy; - } - else { - return this.joinColumnJoiningStrategy; - } - } - - - // **************** mapped by ********************************************** - - public OrmMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public boolean usesMappedByJoiningStrategy() { - return getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join columns ******************************************* - - public OrmJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - // join columns are default, so no need to add annotations - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return this.getMappedByJoiningStrategy().getMappedByAttribute() == null - && this.getPrimaryKeyJoinColumnJoiningStrategy().primaryKeyJoinColumnsSize() == 0; - } - - - // **************** primary key join columns ******************************* - - public OrmPrimaryKeyJoinColumnJoiningStrategy getPrimaryKeyJoinColumnJoiningStrategy() { - return this.primaryKeyJoinColumnJoiningStrategy; - } - - public boolean usesPrimaryKeyJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.primaryKeyJoinColumnJoiningStrategy; - } - - public void setPrimaryKeyJoinColumnJoiningStrategy() { - this.primaryKeyJoinColumnJoiningStrategy.addStrategy(); - this.mappedByJoiningStrategy.removeStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public void unsetPrimaryKeyJoinColumnJoiningStrategy() { - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultPrimaryKeyJoinColumn() { - return false; - } - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - this.primaryKeyJoinColumnJoiningStrategy.update(); - - // update join columns last, as the existence of a default join - // column is dependent on the other mechanisms (mappedBy, join table) - // not being specified - this.joinColumnJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.mappedByJoiningStrategy.validate(messages, reporter); - this.primaryKeyJoinColumnJoiningStrategy.validate(messages, reporter); - this.joinColumnJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnJoiningStrategy.java deleted file mode 100644 index 4039e485cb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; - -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.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class GenericOrmPrimaryKeyJoinColumnJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmPrimaryKeyJoinColumnJoiningStrategy -{ - protected XmlOneToOne resource; - - protected final Vector<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = new Vector<OrmPrimaryKeyJoinColumn>(); - - protected final OrmJoinColumn.Owner joinColumnOwner; - - - public GenericOrmPrimaryKeyJoinColumnJoiningStrategy( - OrmPrimaryKeyJoinColumnEnabledRelationshipReference parent, - XmlOneToOne resource) { - super(parent); - this.resource = resource; - this.joinColumnOwner = this.buildJoinColumnOwner(); - this.initializePrimaryKeyJoinColumns(); - } - - protected OrmJoinColumn.Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected void initializePrimaryKeyJoinColumns() { - if (this.resource != null) { - for (XmlPrimaryKeyJoinColumn resourceJoinColumn : this.resource.getPrimaryKeyJoinColumns()) { - this.primaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(resourceJoinColumn)); - } - } - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn( - XmlPrimaryKeyJoinColumn resourceJoinColumn) { - return this.getXmlContextNodeFactory().buildOrmPrimaryKeyJoinColumn(this, this.joinColumnOwner, resourceJoinColumn); - } - - @Override - public OrmJoinColumnEnabledRelationshipReference getParent() { - return (OrmJoinColumnEnabledRelationshipReference) super.getParent(); - } - - public OrmJoinColumnEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public OrmRelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public void addStrategy() { - if (primaryKeyJoinColumnsSize() == 0) { - addPrimaryKeyJoinColumn(0); - } - } - - public void removeStrategy() { - for (PrimaryKeyJoinColumn each : CollectionTools.iterable(primaryKeyJoinColumns())) { - removePrimaryKeyJoinColumn(each); - } - } - - public boolean isOverridableAssociation() { - return false; - } - - - // **************** primary key join columns ******************************* - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.primaryKeyJoinColumns); - } - - public int primaryKeyJoinColumnsSize() { - return this.primaryKeyJoinColumns.size(); - } - - public boolean hasPrimaryKeyJoinColumns() { - return ! this.primaryKeyJoinColumns.isEmpty(); - } - - public OrmPrimaryKeyJoinColumn addPrimaryKeyJoinColumn(int index) { - XmlPrimaryKeyJoinColumn resourcePkJoinColumn = - OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(); - OrmPrimaryKeyJoinColumn contextPkJoinColumn = - this.buildPrimaryKeyJoinColumn(resourcePkJoinColumn); - this.primaryKeyJoinColumns.add(index, contextPkJoinColumn); - this.resource.getPrimaryKeyJoinColumns().add(index, resourcePkJoinColumn); - this.fireItemAdded(PRIMARY_KEY_JOIN_COLUMNS_LIST, index, contextPkJoinColumn); - return contextPkJoinColumn; - } - - protected void addPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn joinColumn) { - this.addItemToList(index, joinColumn, this.primaryKeyJoinColumns, PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn joinColumn) { - this.addPrimaryKeyJoinColumn(this.primaryKeyJoinColumns.size(), joinColumn); - } - - public void removePrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removePrimaryKeyJoinColumn(this.primaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removePrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPkJoinColumn = this.primaryKeyJoinColumns.remove(index); - this.resource.getPrimaryKeyJoinColumns().remove(index); - this.fireItemRemoved(PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPkJoinColumn); - } - - protected void removePrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.primaryKeyJoinColumns, PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void movePrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.primaryKeyJoinColumns, targetIndex, sourceIndex); - this.resource.getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - // **************** resource -> context ************************************ - - public void update() { - updatePrimaryKeyJoinColumns(); - } - - protected void updatePrimaryKeyJoinColumns() { - // make a copy of the XML PK join columns (to prevent ConcurrentModificationException) - Iterator<XmlPrimaryKeyJoinColumn> xmlPkJoinColumns = - new CloneIterator<XmlPrimaryKeyJoinColumn>(this.resource.getPrimaryKeyJoinColumns()); - - for (Iterator<OrmPrimaryKeyJoinColumn> contextPkJoinColumns = primaryKeyJoinColumns(); - contextPkJoinColumns.hasNext(); ) { - OrmPrimaryKeyJoinColumn contextPkJoinColumn = contextPkJoinColumns.next(); - if (xmlPkJoinColumns.hasNext()) { - contextPkJoinColumn.update(xmlPkJoinColumns.next()); - } - else { - removePrimaryKeyJoinColumn_(contextPkJoinColumn); - } - } - - while (xmlPkJoinColumns.hasNext()) { - addPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(xmlPkJoinColumns.next())); - } - } - - public TextRange getValidationTextRange() { - return this.getRelationshipReference().getValidationTextRange(); - } - - - // ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements OrmJoinColumn.Owner - { - protected JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public Entity getTargetEntity() { - return getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return getRelationshipMapping().getPersistentAttribute().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericOrmPrimaryKeyJoinColumnJoiningStrategy.this.getRelationshipMapping(); - } - - 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 getRelationshipMapping().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return false; - } - - public String getDefaultColumnName() { - return null; - } - - public int joinColumnsSize() { - return GenericOrmPrimaryKeyJoinColumnJoiningStrategy.this.primaryKeyJoinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return GenericOrmPrimaryKeyJoinColumnJoiningStrategy.this.getValidationTextRange(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmXmlContextNodeFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmXmlContextNodeFactory.java deleted file mode 100644 index 36d3a5c3f0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmXmlContextNodeFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.internal.AbstractOrmXmlContextNodeFactory; - -public class GenericOrmXmlContextNodeFactory extends AbstractOrmXmlContextNodeFactory -{ - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmAssociationOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmAssociationOverrideContainer.java deleted file mode 100644 index ed7b4f75b1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmAssociationOverrideContainer.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public class NullOrmAssociationOverrideContainer extends AbstractOrmXmlContextNode - implements OrmAssociationOverrideContainer -{ - - protected final OrmAssociationOverrideContainer.Owner owner; - - public NullOrmAssociationOverrideContainer(XmlContextNode parent, OrmAssociationOverrideContainer.Owner owner) { - super(parent); - this.owner = owner; - } - - public Owner getOwner() { - return this.owner; - } - - public ListIterator<OrmAssociationOverride> associationOverrides() { - return EmptyListIterator.instance(); - } - - public int associationOverridesSize() { - return 0; - } - - public ListIterator<OrmAssociationOverride> virtualAssociationOverrides() { - return EmptyListIterator.instance(); - } - - public int virtualAssociationOverridesSize() { - return 0; - } - - public ListIterator<OrmAssociationOverride> specifiedAssociationOverrides() { - return EmptyListIterator.instance(); - } - - public int specifiedAssociationOverridesSize() { - return 0; - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public OrmAssociationOverride getAssociationOverrideNamed(String name) { - return null; - } - - public void update() { - //no-op - } - - - public TextRange getValidationTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingDefinition.java deleted file mode 100644 index 210c6e2f79..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmBasicMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmBasicMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmBasicMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlBasic(), - XmlBasic.class); - } - - public OrmBasicMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmBasicMapping(parent, (XmlBasic) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlBasic(ormTypeMapping, (JavaBasicMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableDefinition.java deleted file mode 100644 index d908024b78..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableDefinition.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -/** - * default ORM Embeddable provider - */ -public class OrmEmbeddableDefinition - implements OrmTypeMappingDefinition -{ - // singleton - private static final OrmEmbeddableDefinition INSTANCE = - new OrmEmbeddableDefinition(); - - - /** - * Return the singleton - */ - public static OrmTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEmbeddableDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public XmlTypeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEmbeddable(), - XmlEmbeddable.class); - } - - public OrmEmbeddable buildContextMapping( - OrmPersistentType parent, - XmlTypeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEmbeddable(parent, (XmlEmbeddable) resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingDefinition.java deleted file mode 100644 index 133bd4fbb2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmEmbeddedIdMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmEmbeddedIdMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEmbeddedIdMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEmbeddedId(), - XmlEmbeddedId.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEmbeddedIdMapping(parent, (XmlEmbeddedId) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlEmbeddedId(ormTypeMapping, (JavaEmbeddedIdMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingDefinition.java deleted file mode 100644 index 26cd121b1a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmEmbeddedMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmEmbeddedMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEmbeddedMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEmbedded(), - XmlEmbedded.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEmbeddedMapping(parent, (XmlEmbedded) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlEmbedded(ormTypeMapping, (JavaEmbeddedMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityDefinition.java deleted file mode 100644 index cf734f64dc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityDefinition.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -/** - * default ORM Entity provider - */ -public class OrmEntityDefinition - implements OrmTypeMappingDefinition -{ - // singleton - private static final OrmEntityDefinition INSTANCE = - new OrmEntityDefinition(); - - - /** - * Return the singleton - */ - public static OrmTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEntityDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public XmlTypeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEntity(), - XmlEntity.class); - } - - public OrmEntity buildContextMapping( - OrmPersistentType parent, - XmlTypeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEntity(parent, (XmlEntity) resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingDefinition.java deleted file mode 100644 index afedc490bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmIdMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmIdMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmIdMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlId(), - XmlId.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmIdMapping(parent, (XmlId) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlId(ormTypeMapping, (JavaIdMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingDefinition.java deleted file mode 100644 index c719454455..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmManyToManyMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmManyToManyMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmManyToManyMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlManyToMany(), - XmlManyToMany.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmManyToManyMapping(parent, (XmlManyToMany) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlManyToMany(ormTypeMapping, (JavaManyToManyMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingDefinition.java deleted file mode 100644 index 2098c673e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmManyToOneMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmManyToOneMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmManyToOneMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlManyToOne(), - XmlManyToOne.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmManyToOneMapping(parent, (XmlManyToOne) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlManyToOne(ormTypeMapping, (JavaManyToOneMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassDefinition.java deleted file mode 100644 index c0e2f67d6f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassDefinition.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -/** - * default ORM MappedSuperclass definition - */ -public class OrmMappedSuperclassDefinition - implements OrmTypeMappingDefinition -{ - // singleton - private static final OrmMappedSuperclassDefinition INSTANCE = - new OrmMappedSuperclassDefinition(); - - - /** - * Return the singleton - */ - public static OrmTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmMappedSuperclassDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public XmlTypeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlMappedSuperclass(), - XmlMappedSuperclass.class); - } - - public OrmMappedSuperclass buildContextMapping( - OrmPersistentType parent, - XmlTypeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmMappedSuperclass(parent, (XmlMappedSuperclass) resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingDefinition.java deleted file mode 100644 index f7ea7d8ce8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmOneToManyMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmOneToManyMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmOneToManyMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlOneToMany(), - XmlOneToMany.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmOneToManyMapping(parent, (XmlOneToMany) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlOneToMany(ormTypeMapping, (JavaOneToManyMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingDefinition.java deleted file mode 100644 index 487b0497ea..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmOneToOneMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmOneToOneMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmOneToOneMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlOneToOne(), - XmlOneToOne.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmOneToOneMapping(parent, (XmlOneToOne) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlOneToOne(ormTypeMapping, (JavaOneToOneMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingDefinition.java deleted file mode 100644 index 6177649214..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmTransientMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmTransientMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmTransientMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlTransient(), - XmlTransient.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmTransientMapping(parent, (XmlTransient) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlTransient(ormTypeMapping, (JavaTransientMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingDefinition.java deleted file mode 100644 index abc841dda2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmVersionMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmVersionMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmVersionMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlVersion(), - XmlVersion.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmVersionMapping(parent, (XmlVersion) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlVersion(ormTypeMapping, (JavaVersionMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java deleted file mode 100644 index 9c28a4a1a5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.resource.orm.CascadeType; - -public class VirtualCascadeType extends CascadeType -{ - Cascade javaCascade; - - protected boolean metadataComplete; - - public VirtualCascadeType(Cascade javaCascade, boolean metadataComplete) { - super(); - this.javaCascade = javaCascade; - this.metadataComplete = metadataComplete; - } - - @Override - public boolean isCascadeAll() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isAll(); - } - - @Override - public void setCascadeAll(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadeMerge() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isMerge(); - } - - @Override - public void setCascadeMerge(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadePersist() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isPersist(); - } - - @Override - public void setCascadePersist(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadeRefresh() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isRefresh(); - } - - @Override - public void setCascadeRefresh(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadeRemove() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isRemove(); - } - - @Override - public void setCascadeRemove(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java deleted file mode 100644 index b94e86c0f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaMultiRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.MapKey; - -public class VirtualMapKey extends MapKey -{ - JavaMultiRelationshipMapping javaMultiRelationshipMapping; - - protected boolean metadataComplete; - - public VirtualMapKey(JavaMultiRelationshipMapping javaMultiRelationshipMapping, boolean metadataComplete) { - super(); - this.javaMultiRelationshipMapping = javaMultiRelationshipMapping; - this.metadataComplete = metadataComplete; - } - - @Override - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.javaMultiRelationshipMapping.getMapKey(); - } - - @Override - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAssociationOverride.java deleted file mode 100644 index 6f4af8edab..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAssociationOverride.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c)2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlAssociationOverride extends XmlAssociationOverride -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JoiningStrategy joiningStrategy; - - - public VirtualXmlAssociationOverride(String name, OrmTypeMapping ormTypeMapping, JoiningStrategy joiningStrategy) { - super(); - this.name = name; - this.ormTypeMapping = ormTypeMapping; - this.joiningStrategy = joiningStrategy; - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_ASSOCIATION_OVERRIDE__JOIN_COLUMNS); - if (this.joiningStrategy instanceof JoinColumnJoiningStrategy) { - for (JoinColumn joinColumn : - CollectionTools.iterable(((JoinColumnJoiningStrategy) this.joiningStrategy).joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - } - return joinColumns; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeMapping.java deleted file mode 100644 index 562ae7e94d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeMapping.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.xml.AbstractJpaEObject; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlAttributeMapping extends AbstractJpaEObject implements XmlAttributeMapping -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaAttributeMapping javaAttributeMapping; - - public VirtualXmlAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaAttributeMapping; - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - public String getMappingKey() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getPersistentAttribute().getDefaultMappingKey(); - } - return this.javaAttributeMapping.getKey(); - } - - public String getName() { - return this.javaAttributeMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - public TextRange getNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java deleted file mode 100644 index 86e3490191..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; - -public class VirtualXmlAttributeOverride extends XmlAttributeOverride -{ - - public VirtualXmlAttributeOverride(String name, XmlColumn xmlColumn) { - super(); - this.name = name; - this.column = xmlColumn; - } - - @Override - public String getName() { - return this.name; - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverrideColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverrideColumn.java deleted file mode 100644 index d1383f2d92..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverrideColumn.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Column; - -/** - * javax.persistence.Column - */ -public class VirtualXmlAttributeOverrideColumn - extends VirtualXmlColumn -{ - - public VirtualXmlAttributeOverrideColumn(Column column) { - super(null, column); - } - - @Override - public String getName() { - return this.column.getSpecifiedName(); - } - - @Override - public String getColumnDefinition() { - return this.column.getColumnDefinition(); - } - - @Override - public String getTable() { - return this.column.getSpecifiedTable(); - } - - @Override - public Boolean getInsertable() { - return this.column.getSpecifiedInsertable(); - } - - @Override - public Boolean getUpdatable() { - return this.column.getSpecifiedUpdatable(); - } - - @Override - public Boolean getNullable() { - return this.column.getSpecifiedNullable(); - } - - @Override - public Boolean getUnique() { - return this.column.getSpecifiedUnique(); - } - - @Override - public Integer getLength() { - return this.column.getSpecifiedLength(); - } - - @Override - public Integer getScale() { - return this.column.getSpecifiedScale(); - } - - @Override - public Integer getPrecision() { - return this.column.getSpecifiedPrecision(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java deleted file mode 100644 index d3f075932e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java +++ /dev/null @@ -1,173 +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.Converter; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualBasic is an implementation of Basic used when there is - * no tag in the orm.xml and an underlying javaBasicMapping exists. - */ -public class VirtualXmlBasic extends XmlBasic -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaBasicMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualXmlColumn column; - - public VirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaBasicMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaBasicMapping); - this.column = new VirtualXmlColumn(ormTypeMapping, javaBasicMapping.getColumn()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getOptional() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaAttributeMapping.isDefaultOptional()); - } - return Boolean.valueOf(this.javaAttributeMapping.isOptional()); - } - - @Override - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isLob() { - if (this.isOrmMetadataComplete()) { - return false; - } - return this.javaAttributeMapping.getConverter().getType() == Converter.LOB_CONVERTER; - } - - @Override - public void setLob(boolean newLob) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TemporalType getTemporal() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getConverter().getType() == Converter.TEMPORAL_CONVERTER) { - org.eclipse.jpt.core.context.TemporalType javaTemporalType = ((TemporalConverter) this.javaAttributeMapping.getConverter()).getTemporalType(); - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(javaTemporalType); - } - return null; - } - - @Override - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EnumType getEnumerated() { - if (this.javaAttributeMapping.getConverter().getType() != Converter.ENUMERATED_CONVERTER) { - return null; - } - org.eclipse.jpt.core.context.EnumType javaEnumeratedType; - if (this.isOrmMetadataComplete()) { - if (this.javaAttributeMapping.getDefaultConverter().getType() != Converter.ENUMERATED_CONVERTER) { - return null; - } - javaEnumeratedType = ((EnumeratedConverter) this.javaAttributeMapping.getDefaultConverter()).getSpecifiedEnumType(); - } - else { - javaEnumeratedType = ((EnumeratedConverter) this.javaAttributeMapping.getConverter()).getEnumType(); - } - return org.eclipse.jpt.core.context.EnumType.toOrmResourceModel(javaEnumeratedType); - } - - @Override - public void setEnumerated(EnumType newEnumerated) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getEnumeratedTextRange() { - return null; - } - - @Override - public TextRange getLobTextRange() { - return null; - } - - @Override - public TextRange getTemporalTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java deleted file mode 100644 index 86659456f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * A virtual column is used to represent the XmlColumn resource object - * within a virtual mapping. A virtual mapping is one which is not specified - * in the orm.xml file, but is implied from the underlying java. Virtual column - * is not used when the mapping is specified in the orm.xml, but the column tag does not exist. - * - * A virtual column delegates to the underlying java column for its state. The metadataComplete - * flag determines whether it will get specified or default information from the java column - * - */ -public class VirtualXmlColumn extends XmlColumn -{ - - protected Column column; - - protected OrmTypeMapping ormTypeMapping; - - - public VirtualXmlColumn(OrmTypeMapping ormTypeMapping, Column column) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.column = column; - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getColumnDefinition() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.column.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getInsertable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultInsertable()); - } - return Boolean.valueOf(this.column.isInsertable()); - } - - @Override - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getLength() { - if (this.isOrmMetadataComplete()) { - return Integer.valueOf(this.column.getDefaultLength()); - } - return Integer.valueOf(this.column.getLength()); - } - - @Override - public void setLength(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.isOrmMetadataComplete()) { - return this.column.getDefaultName(); - } - return this.column.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getNullable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultNullable()); - } - return Boolean.valueOf(this.column.isNullable()); - } - - @Override - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getPrecision() { - if (this.isOrmMetadataComplete()) { - return Integer.valueOf(this.column.getDefaultPrecision()); - } - return Integer.valueOf(this.column.getPrecision()); - } - - @Override - public void setPrecision(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getScale() { - if (this.isOrmMetadataComplete()) { - return Integer.valueOf(this.column.getDefaultScale()); - } - return Integer.valueOf(this.column.getScale()); - } - - @Override - public void setScale(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTable() { - if (!this.isOrmMetadataComplete()) { - if (this.column.getSpecifiedTable() != null) { - return this.column.getSpecifiedTable(); - } - } - return this.ormTypeMapping.getPrimaryTableName(); - } - - @Override - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUnique() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultUnique()); - } - return Boolean.valueOf(this.column.isUnique()); - } - - @Override - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUpdatable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultUpdatable()); - } - return Boolean.valueOf(this.column.isUpdatable()); - } - - @Override - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getTableTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java deleted file mode 100644 index 24dfaed2e2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualEmbedded is an implementation of Embedded used when there is - * no tag in the orm.xml and an underlying javaEmbeddedMapping exists. - */ -public class VirtualXmlEmbedded extends XmlEmbedded -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaEmbeddedMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaEmbeddedMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaEmbeddedMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.isOrmMetadataComplete()) { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn()); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java deleted file mode 100644 index 058723fb1b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualEmbeddedId is an implementation of EmbeddedId used when there is - * no tag in the orm.xml and an underlying javaEmbeddedIdMapping exists. - */ -public class VirtualXmlEmbeddedId extends XmlEmbeddedId -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaEmbeddedIdMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlEmbeddedId(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaEmbeddedIdMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaEmbeddedIdMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED_ID__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.isOrmMetadataComplete()) { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn()); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java deleted file mode 100644 index 828999cb40..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.resource.orm.GenerationType; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlGeneratedValue extends XmlGeneratedValue -{ - JavaIdMapping javaIdMapping; - - protected boolean metadataComplete; - - - public VirtualXmlGeneratedValue(JavaIdMapping javaIdMapping, boolean metadataComplete) { - super(); - this.javaIdMapping = javaIdMapping; - this.metadataComplete = metadataComplete; - } - - protected JavaGeneratedValue getJavaGeneratedValue() { - return this.javaIdMapping.getGeneratedValue(); - } - - - @Override - public String getGenerator() { - return this.metadataComplete ? null : this.getJavaGeneratedValue().getGenerator(); - } - - @Override - public GenerationType getStrategy() { - return this.metadataComplete ? null : org.eclipse.jpt.core.context.GenerationType.toOrmResourceModel(this.getJavaGeneratedValue().getStrategy()); - } - - @Override - public void setGenerator(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public void setStrategy(GenerationType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getGeneratorTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java deleted file mode 100644 index 9e50e0cffb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualId is an implementation of Id used when there is - * no tag in the orm.xml and an underlying javaIdMapping exists. - */ -public class VirtualXmlId extends XmlId -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaIdMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualXmlColumn column; - - protected final VirtualXmlGeneratedValue virtualGeneratedValue; - - protected final VirtualXmlTableGenerator virtualTableGenerator; - - protected final VirtualXmlSequenceGenerator virtualSequenceGenerator; - - - public VirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaIdMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaIdMapping); - this.column = new VirtualXmlColumn(ormTypeMapping, javaIdMapping.getColumn()); - this.virtualGeneratedValue = new VirtualXmlGeneratedValue(javaIdMapping, this.isOrmMetadataComplete()); - this.virtualTableGenerator = new VirtualXmlTableGenerator(javaIdMapping.getGeneratorContainer(), this.isOrmMetadataComplete()); - this.virtualSequenceGenerator = new VirtualXmlSequenceGenerator(javaIdMapping.getGeneratorContainer(), this.isOrmMetadataComplete()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TemporalType getTemporal() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getConverter().getType() == Converter.TEMPORAL_CONVERTER) { - org.eclipse.jpt.core.context.TemporalType javaTemporalType = ((TemporalConverter) this.javaAttributeMapping.getConverter()).getTemporalType(); - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(javaTemporalType); - } - return null; - } - - @Override - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public XmlGeneratedValue getGeneratedValue() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getGeneratedValue() != null) { - return this.virtualGeneratedValue; - } - return null; - } - - @Override - public void setGeneratedValue(XmlGeneratedValue value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlSequenceGenerator getSequenceGenerator() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getGeneratorContainer().getSequenceGenerator() != null) { - return this.virtualSequenceGenerator; - } - return null; - } - - @Override - public void setSequenceGenerator(XmlSequenceGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlTableGenerator getTableGenerator() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getGeneratorContainer().getTableGenerator() != null) { - return this.virtualTableGenerator; - } - return null; - } - - @Override - public void setTableGenerator(XmlTableGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public EnumType getEnumerated() { - throw new UnsupportedOperationException("enumerated not supported on id mappings"); //$NON-NLS-1$ - } - - @Override - public void setEnumerated(EnumType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public boolean isLob() { - throw new UnsupportedOperationException("lob not supported on id mappings"); //$NON-NLS-1$ - } - - @Override - public void setLob(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getEnumeratedTextRange() { - return null; - } - - @Override - public TextRange getLobTextRange() { - return null; - } - - @Override - public TextRange getTemporalTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java deleted file mode 100644 index 0e862c7c88..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlJoinColumn extends XmlJoinColumn -{ - protected JoinColumn javaJoinColumn; - - protected boolean metadataComplete; - - public VirtualXmlJoinColumn(JoinColumn javaJoinColumn, boolean metadataComplete) { - super(); - this.javaJoinColumn = javaJoinColumn; - this.metadataComplete = metadataComplete; - } - - @Override - public String getColumnDefinition() { - if (this.metadataComplete) { - return null; - } - return this.javaJoinColumn.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getInsertable() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultInsertable()); - } - return Boolean.valueOf(this.javaJoinColumn.isInsertable()); - } - - @Override - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultName(); - } - return this.javaJoinColumn.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getReferencedColumnName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultReferencedColumnName(); - } - return this.javaJoinColumn.getReferencedColumnName(); - } - - @Override - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getNullable() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultNullable()); - } - return Boolean.valueOf(this.javaJoinColumn.isNullable()); - } - - @Override - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultTable(); - } - return this.javaJoinColumn.getTable(); - } - - @Override - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUnique() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultUnique()); - } - return Boolean.valueOf(this.javaJoinColumn.isUnique()); - } - - @Override - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUpdatable() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultUpdatable()); - } - return Boolean.valueOf(this.javaJoinColumn.isUpdatable()); - } - - @Override - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getTableTextRange() { - return null; - } - - @Override - public TextRange getReferencedColumnNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java deleted file mode 100644 index 40b116a798..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlJoinTable - extends XmlJoinTable -{ - protected OrmTypeMapping ormTypeMapping; - - protected JoinTable joinTable; - - - public VirtualXmlJoinTable(OrmTypeMapping ormTypeMapping, JoinTable joinTable) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.joinTable = joinTable; - } - - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getName() { - if (this.isOrmMetadataComplete()) { - return this.joinTable.getDefaultName(); - } - return this.joinTable.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getCatalog() { - if (this.isOrmMetadataComplete()) { - return this.joinTable.getDefaultCatalog(); - } - return this.joinTable.getCatalog(); - } - - @Override - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getSchema() { - if (this.isOrmMetadataComplete()) { - return this.joinTable.getDefaultSchema(); - } - return this.joinTable.getSchema(); - } - - @Override - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - @Override - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__JOIN_COLUMNS); - if (this.joinTable == null) { - return joinColumns; - } - for (JoinColumn joinColumn : CollectionTools.iterable(this.joinTable.specifiedJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - @Override - public EList<XmlJoinColumn> getInverseJoinColumns() { - EList<XmlJoinColumn> inverseJoinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__INVERSE_JOIN_COLUMNS); - if (this.joinTable == null) { - return inverseJoinColumns; - } - for (JoinColumn joinColumn : CollectionTools.iterable(this.joinTable.specifiedInverseJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, isOrmMetadataComplete()); - inverseJoinColumns.add(xmlJoinColumn); - } - - return inverseJoinColumns; - } - - @Override - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_JOIN_TABLE__UNIQUE_CONSTRAINTS); - for (UniqueConstraint uniqueConstraint : CollectionTools.iterable(this.joinTable.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, isOrmMetadataComplete()); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getCatalogTextRange() { - return null; - } - - @Override - public TextRange getSchemaTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java deleted file mode 100644 index 6799f9d529..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java +++ /dev/null @@ -1,178 +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.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualManyToMany is an implementation of ManyToMany used when there is - * no tag in the orm.xml and an underlying javaManyToManyMapping exists. - */ -public class VirtualXmlManyToMany - extends XmlManyToMany -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaManyToManyMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - - public VirtualXmlManyToMany( - OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaManyToManyMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaManyToManyMapping); - this.virtualCascadeType = - new VirtualCascadeType(javaManyToManyMapping.getCascade(), this.isOrmMetadataComplete()); - this.mapKey = new VirtualMapKey(javaManyToManyMapping, this.isOrmMetadataComplete()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - public EList<XmlJoinColumn> getJoinColumns() { - return null; - } - - @Override - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - if (this.javaAttributeMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable() != null) { - return new VirtualXmlJoinTable( - this.ormTypeMapping, - this.javaAttributeMapping.getRelationshipReference(). - getJoinTableJoiningStrategy().getJoinTable()); - } - return null; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getMappedBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute(); - } - - @Override - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public MapKey getMapKey() { - return this.mapKey; - } - - @Override - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getOrderBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getOrderBy(); - } - - @Override - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getMappedByTextRange() { - return null; - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java deleted file mode 100644 index 3b70d598bf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java +++ /dev/null @@ -1,154 +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.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualManyToOne is an implementation of ManyToOne used when there is - * no tag in the orm.xml and an underlying javaManyToOneMapping exists. - */ -public class VirtualXmlManyToOne - extends XmlManyToOne -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaManyToOneMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - - public VirtualXmlManyToOne( - OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaManyToOneMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaManyToOneMapping); - this.virtualCascadeType = - new VirtualCascadeType(javaManyToOneMapping.getCascade(), this.isOrmMetadataComplete()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getOptional() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaAttributeMapping.isDefaultOptional()); - } - return Boolean.valueOf(this.javaAttributeMapping.isOptional()); - } - - @Override - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__JOIN_COLUMNS); - //TODO here i'm using joinColumns() while VirtualXmlJoinTable uses specifiedJoinColumns()??? - for (JavaJoinColumn joinColumn : - CollectionTools.iterable( - this.javaAttributeMapping.getRelationshipReference(). - getJoinColumnJoiningStrategy().joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - @Override - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - //TODO we don't yet support JoinTable in the context model for many-to-one mappings - return null;//this.virtualJoinTable; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java deleted file mode 100644 index e8a503d192..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualVersion is an implementation of Version used when there is - * no tag in the orm.xml and an underlying javaVersionMapping exists. - */ -public class VirtualXmlNullAttributeMapping extends XmlNullAttributeMapping -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaAttributeMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaAttributeMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaAttributeMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - public String getMappingKey() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getPersistentAttribute().getDefaultMappingKey(); - } - return this.javaAttributeMapping.getKey(); - } - - @Override - public String getName() { - return this.javaAttributeMapping.getPersistentAttribute().getName(); - } - - @Override - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java deleted file mode 100644 index a1b96dacd0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java +++ /dev/null @@ -1,180 +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.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualOneToMany is an implementation of OneToMany used when there is - * no tag in the orm.xml and an underlying javaOneToManyMapping exists. - */ -public class VirtualXmlOneToMany - extends XmlOneToMany -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaOneToManyMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - - public VirtualXmlOneToMany( - OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaOneToManyMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaOneToManyMapping); - this.virtualCascadeType = - new VirtualCascadeType(javaOneToManyMapping.getCascade(), this.isOrmMetadataComplete()); - this.mapKey = new VirtualMapKey(javaOneToManyMapping, this.isOrmMetadataComplete()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - return null; - } - - @Override - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - if (this.javaAttributeMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable() != null) { - return new VirtualXmlJoinTable( - this.ormTypeMapping, - this.javaAttributeMapping.getRelationshipReference(). - getJoinTableJoiningStrategy().getJoinTable()); - } - return null; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getMappedBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getRelationshipReference(). - getMappedByJoiningStrategy().getMappedByAttribute(); - } - - @Override - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public MapKey getMapKey() { - return this.mapKey; - } - - @Override - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getOrderBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getOrderBy(); - } - - @Override - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getMappedByTextRange() { - return null; - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java deleted file mode 100644 index b831d459c2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java +++ /dev/null @@ -1,190 +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.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualOneToOne is an implementation of OneToOne used when there is - * no tag in the orm.xml and an underlying javaOneToOneMapping exists. - */ -public class VirtualXmlOneToOne extends XmlOneToOne -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaOneToOneMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - - public VirtualXmlOneToOne( - OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaOneToOneMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaOneToOneMapping); - this.virtualCascadeType = - new VirtualCascadeType(javaOneToOneMapping.getCascade(), this.isOrmMetadataComplete()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getOptional() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaAttributeMapping.isDefaultOptional()); - } - return Boolean.valueOf(this.javaAttributeMapping.isOptional()); - } - - @Override - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - //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.javaAttributeMapping.getRelationshipReference(). - getJoinColumnJoiningStrategy().joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - @Override - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - //TODO we don't yet support JoinTable in the context model for many-to-one mappings - return null;//this.virtualJoinTable; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getMappedBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getRelationshipReference(). - getMappedByJoiningStrategy().getMappedByAttribute(); - } - - @Override - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> joinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_ONE_TO_ONE__PRIMARY_KEY_JOIN_COLUMNS); - if (!this.isOrmMetadataComplete()) { - for (JavaPrimaryKeyJoinColumn joinColumn : - CollectionTools.iterable( - this.javaAttributeMapping.getRelationshipReference(). - getPrimaryKeyJoinColumnJoiningStrategy().primaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(joinColumn/*, this.metadataComplete*/); - joinColumns.add(xmlJoinColumn); - } - } - return joinColumns; - } - - @Override - public TextRange getMappedByTextRange() { - return null; - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java deleted file mode 100644 index 34127e1e98..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * A virtual primary key join column is used to represent the XmlPrimaryKeyJoinColumn resource object - * within a virtual secondary table. A virtual secondary table is one which is not specified - * in the orm.xml file, but is implied from the underlying java. Virtual pk join column - * is not used when the secondary table is specified in the orm.xml. - * - * A virtual pk join column delegates to the underlying java pk join column for its state. - */ -public class VirtualXmlPrimaryKeyJoinColumn extends XmlPrimaryKeyJoinColumn -{ - - protected JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn; - - - protected VirtualXmlPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn) { - super(); - this.javaPrimaryKeyJoinColumn = javaPrimaryKeyJoinColumn; - } - - @Override - public String getName() { - return this.javaPrimaryKeyJoinColumn.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getColumnDefinition() { - return this.javaPrimaryKeyJoinColumn.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getReferencedColumnName() { - return this.javaPrimaryKeyJoinColumn.getReferencedColumnName(); - } - - @Override - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getReferencedColumnNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java deleted file mode 100644 index b25ddcb3f6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * A virtual secondary table is used to represent the XmlSecondaryTable resource object. - * A virtual secondary table is one which is not specified in the orm.xml file, - * but is implied from the underlying java. Virtual secondary table - * is not used when the secondary table is specified in the orm.xml. - * - * A virtual secondary table delegates to the underlying java secondary table for its state. - */ -public class VirtualXmlSecondaryTable extends XmlSecondaryTable -{ - - protected JavaSecondaryTable javaSecondaryTable; - - protected VirtualXmlSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - super(); - this.javaSecondaryTable = javaSecondaryTable; - } - - @Override - public String getName() { - return this.javaSecondaryTable.getSpecifiedName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getCatalog() { - return this.javaSecondaryTable.getSpecifiedCatalog(); - } - - @Override - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getSchema() { - return this.javaSecondaryTable.getSpecifiedSchema(); - } - - @Override - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //VirtualXmlSecondaryTable is rebuilt everytime, so rebuilding the joinColumns list as well - @Override - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> primaryKeyJoinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS); - - for (JavaPrimaryKeyJoinColumn pkJoinColumn : CollectionTools.iterable(this.javaSecondaryTable.specifiedPrimaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlPkJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(pkJoinColumn); - primaryKeyJoinColumns.add(xmlPkJoinColumn); - } - - return primaryKeyJoinColumns; - } - - @Override - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_SECONDARY_TABLE__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.javaSecondaryTable.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, true); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getCatalogTextRange() { - return null; - } - - @Override - public TextRange getSchemaTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java deleted file mode 100644 index 06a8ffb50d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlSequenceGenerator extends XmlSequenceGenerator -{ - JavaGeneratorContainer javaGeneratorHolder; - - protected boolean metadataComplete; - - - public VirtualXmlSequenceGenerator(JavaGeneratorContainer javaGeneratorHolder, boolean metadataComplete) { - super(); - this.javaGeneratorHolder = javaGeneratorHolder; - this.metadataComplete = metadataComplete; - } - - protected JavaSequenceGenerator getJavaSequenceGenerator() { - return this.javaGeneratorHolder.getSequenceGenerator(); - } - - @Override - public String getSequenceName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaSequenceGenerator().getSequenceName(); - } - - @Override - public void setSequenceName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaSequenceGenerator().getAllocationSize()); - } - - @Override - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaSequenceGenerator().getInitialValue()); - } - - @Override - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaSequenceGenerator().getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - @Override - public boolean isVirtual() { - return true; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java deleted file mode 100644 index 4bb32dd5e5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlTableGenerator extends XmlTableGenerator -{ - JavaGeneratorContainer javaGeneratorHolder; - - protected boolean metadataComplete; - - - public VirtualXmlTableGenerator(JavaGeneratorContainer javaGeneratorHolder, boolean metadataComplete) { - super(); - this.javaGeneratorHolder = javaGeneratorHolder; - this.metadataComplete = metadataComplete; - } - - protected JavaTableGenerator getJavaTableGenerator() { - return this.javaGeneratorHolder.getTableGenerator(); - } - - @Override - public String getCatalog() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getCatalog(); - } - - @Override - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getPkColumnName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getPkColumnName(); - } - - @Override - public void setPkColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getPkColumnValue() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getPkColumnValue(); - } - - @Override - public void setPkColumnValue(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getSchema() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getSchema(); - } - - @Override - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTable() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getTable(); - } - - @Override - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getValueColumnName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getValueColumnName(); - } - - @Override - public void setValueColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaTableGenerator().getAllocationSize()); - } - - @Override - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaTableGenerator().getInitialValue()); - } - - @Override - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - - @Override - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_TABLE_GENERATOR__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.getJavaTableGenerator().uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, this.metadataComplete); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - @Override - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - @Override - public boolean isVirtual() { - return true; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java deleted file mode 100644 index 63f2b4ae99..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualTransient is an implementation of Transient used when there is - * no tag in the orm.xml and an underlying javaTransientMapping exists. - */ -public class VirtualXmlTransient extends XmlTransient -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaTransientMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlTransient(OrmTypeMapping ormTypeMapping, JavaTransientMapping javaTransientMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaTransientMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaTransientMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java deleted file mode 100644 index c5070a843d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EDataTypeEList; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlUniqueConstraint extends XmlUniqueConstraint -{ - protected UniqueConstraint uniqueConstraint; - - protected boolean metadataComplete; - - protected VirtualXmlUniqueConstraint(UniqueConstraint uniqueConstraint, boolean metadataComplete) { - super(); - this.uniqueConstraint = uniqueConstraint; - this.metadataComplete = metadataComplete; - } - - @Override - public EList<String> getColumnNames() { - EList<String> columnNames = new EDataTypeEList<String>(String.class, this, OrmPackage.XML_UNIQUE_CONSTRAINT__COLUMN_NAMES); - - for (String columnName : CollectionTools.iterable(this.uniqueConstraint.columnNames())) { - columnNames.add(columnName); - } - return columnNames; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java deleted file mode 100644 index b23f94a7c0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualVersion is an implementation of Version used when there is - * no tag in the orm.xml and an underlying javaVersionMapping exists. - */ -public class VirtualXmlVersion extends XmlVersion -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaVersionMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualXmlColumn column; - - public VirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaVersionMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaVersionMapping); - this.column = new VirtualXmlColumn(ormTypeMapping, javaVersionMapping.getColumn()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TemporalType getTemporal() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getConverter().getType() == Converter.TEMPORAL_CONVERTER) { - org.eclipse.jpt.core.context.TemporalType javaTemporalType = ((TemporalConverter) this.javaAttributeMapping.getConverter()).getTemporalType(); - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(javaTemporalType); - } - return null; - } - - @Override - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public EnumType getEnumerated() { - throw new UnsupportedOperationException("enumerated not supported on version mappings"); //$NON-NLS-1$ - } - - @Override - public void setEnumerated(EnumType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public boolean isLob() { - throw new UnsupportedOperationException("lob not supported on version mappings"); //$NON-NLS-1$ - } - - @Override - public void setLob(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getEnumeratedTextRange() { - return null; - } - - @Override - public TextRange getLobTextRange() { - return null; - } - - @Override - public TextRange getTemporalTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java deleted file mode 100644 index 52d03b27ff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.List; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JarFile; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.java.JarFile2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.JarFileRef2_0; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef; -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.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualFile; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractJarFileRef - extends AbstractXmlContextNode - implements JarFileRef2_0 -{ - protected XmlJarFileRef xmlJarFileRef; - - protected String fileName; - - protected JarFile jarFile; - - - // **************** construction/initialization **************************** - - public AbstractJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { - super(parent); - this.xmlJarFileRef = xmlJarFileRef; - this.fileName = xmlJarFileRef.getFileName(); - this.jarFile = this.buildJarFile(); - } - - protected JarFile buildJarFile() { - if (StringTools.stringIsEmpty(this.fileName)) { - return null; - } - JavaResourcePackageFragmentRoot jrpfr = this.getJpaProject().getJavaResourcePackageFragmentRoot(this.getFileName()); - return (jrpfr == null) ? null : this.buildJarFile(jrpfr); - } - - @Override - public PersistenceUnit getParent() { - return (PersistenceUnit) super.getParent(); - } - - - // **************** file name ********************************************** - - public String getFileName() { - return this.fileName; - } - - public void setFileName(String newFileName) { - String old = this.fileName; - this.fileName = newFileName; - this.xmlJarFileRef.setFileName(newFileName); - this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); - } - - protected void setFileName_(String newFileName) { - String old = this.fileName; - this.fileName = newFileName; - this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); - } - - - // **************** JAR file *********************************************** - - public JarFile getJarFile() { - return this.jarFile; - } - - protected void setJarFile(JarFile jarFile) { - JarFile old = this.jarFile; - this.jarFile = jarFile; - this.firePropertyChanged(JAR_FILE_PROPERTY, old, jarFile); - } - - - // **************** JarFileRef impl **************************************** - - public PersistentType getPersistentType(String typeName) { - return (this.jarFile == null) ? null : this.jarFile.getPersistentType(typeName); - } - - public boolean containsOffset(int textOffset) { - return (this.xmlJarFileRef != null) && this.xmlJarFileRef.containsOffset(textOffset); - } - - - // **************** JpaStructureNode impl ********************************** - - public String getId() { - return PersistenceStructureNodes.JAR_FILE_REF_ID; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public TextRange getSelectionTextRange() { - return (this.xmlJarFileRef == null) ? null : this.xmlJarFileRef.getSelectionTextRange(); - } - - public void dispose() { - if (this.jarFile != null) { - this.jarFile.dispose(); - } - } - - - // **************** XmlContextNode impl ************************************ - - public TextRange getValidationTextRange() { - return (this.xmlJarFileRef == null) ? null : this.xmlJarFileRef.getValidationTextRange(); - } - - - // **************** updating *********************************************** - - public void update(XmlJarFileRef xjfr) { - this.xmlJarFileRef = xjfr; - this.setFileName_(xjfr.getFileName()); - this.updateJarFile(); - } - - protected void updateJarFile() { - JavaResourcePackageFragmentRoot jrpfr = null; - - if (! StringTools.stringIsEmpty(this.fileName)) { - - // first, attempt to resolve location specifically - jrpfr = javaPackageRoot_specifically(); - - // then ... guess, basically - if (jrpfr == null) { - jrpfr = javaPackageRoot_guess(); - } - } - - if (jrpfr == null) { - if (this.jarFile != null) { - this.jarFile.dispose(); - this.setJarFile(null); - } - } else { - if (this.jarFile == null) { - this.setJarFile(this.buildJarFile(jrpfr)); - } else { - this.jarFile.update(jrpfr); - } - } - } - - private JavaResourcePackageFragmentRoot javaPackageRoot_specifically() { - for (IPath deploymentPath : resolveDeploymentJarFilePath(new Path(this.fileName))) { - IVirtualFile virtualJar = ComponentCore.createFile(this.getProject(), deploymentPath); - IFile realJar = virtualJar.getUnderlyingFile(); - if (realJar.exists() && realJar.getProject().equals(this.getProject())) { - return getJpaProject().getJavaResourcePackageFragmentRoot(realJar.getProjectRelativePath().toString()); - } - } - - return null; - } - - private JavaResourcePackageFragmentRoot javaPackageRoot_guess() { - String jarFileName = new Path(this.fileName).lastSegment(); - for (JpaFile jpaFile : CollectionTools.iterable(getJpaProject().jpaFiles())) { - if (jpaFile.getFile().getName().equals(jarFileName) - && JptCorePlugin.JAR_CONTENT_TYPE.equals(jpaFile.getContentType())) { - return (JavaResourcePackageFragmentRoot) jpaFile.getResourceModel(); - } - } - - return null; - } - - /** - * Return an array of deployment paths that may correspond - * to the given persistence.xml jar file entry - */ - protected IPath[] resolveDeploymentJarFilePath(IPath jarFilePath) { - IPath root = this.getJarDeploymentRootPath(); - return this.projectHasWebFacet() ? - this.resolveDeploymentJarFilePathWeb(root, jarFilePath) : - this.resolveDeploymentJarFilePathNonWeb(root, jarFilePath); - } - - protected IPath getJarDeploymentRootPath() { - return JptCorePlugin.getJarDeploymentRootPath(this.getProject()); - } - - protected boolean projectHasWebFacet() { - return JptCorePlugin.projectHasWebFacet(this.getProject()); - } - - protected IPath[] resolveDeploymentJarFilePathWeb(IPath root, IPath jarFilePath) { - return new IPath[] { - // first path entry assumes form "../lib/other.jar" - root.append(jarFilePath.removeFirstSegments(1)), - // second path entry assumes form of first, without ".." ("lib/other.jar") - root.append(jarFilePath) - }; - } - - protected IPath[] resolveDeploymentJarFilePathNonWeb(IPath root, IPath jarFilePath) { - return new IPath[] { - // assumes form "../lib/other.jar" - root.append(jarFilePath) - }; - } - - - protected JarFile buildJarFile(JavaResourcePackageFragmentRoot jrpfr) { - return this.getJpaFactory().buildJarFile(this, jrpfr); - } - - protected IProject getProject() { - return this.getJpaProject().getProject(); - } - - - // **************** 2.0 static metamodel ******************** - - public void synchronizeStaticMetamodel() { - JarFile2_0 jf = (JarFile2_0) this.getJarFile(); - if (jf != null) { - jf.synchronizeStaticMetamodel(); - } - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (StringTools.stringIsEmpty(this.xmlJarFileRef.getFileName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE, - this, - this.getValidationTextRange() - ) - ); - return; - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING, - this, - this.getValidationTextRange() - ) - ); - - if (this.jarFile == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE, - new String[] {this.xmlJarFileRef.getFileName()}, - this, - this.getValidationTextRange() - ) - ); - return; - } - - this.jarFile.validate(messages, reporter); - } - - - // **************** misc *************************************************** - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.getFileName()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java deleted file mode 100644 index 76f734deb7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java +++ /dev/null @@ -1,246 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.List; -import org.eclipse.core.resources.IFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.MappingFile; -import org.eclipse.jpt.core.context.MappingFileDefinition; -import org.eclipse.jpt.core.context.MappingFilePersistenceUnitDefaults; -import org.eclipse.jpt.core.context.MappingFileRoot; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.persistence.MappingFileRef2_0; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractMappingFileRef - extends AbstractXmlContextNode - implements MappingFileRef2_0 -{ - protected String fileName; - - protected MappingFile mappingFile; - - - // ********** construction/initialization ********** - - protected AbstractMappingFileRef(PersistenceUnit parent, String resourceFileName) { - super(parent); - this.fileName = resourceFileName; - this.mappingFile = this.buildMappingFile(); - } - - protected MappingFile buildMappingFile() { - JpaXmlResource xmlResource = this.getXmlResource(); - return (xmlResource == null) ? null : this.buildMappingFile(xmlResource); - } - - @Override - public PersistenceUnit getParent() { - return (PersistenceUnit) super.getParent(); - } - - - // ********** JpaStructureNode implementation ********** - - public String getId() { - return PersistenceStructureNodes.MAPPING_FILE_REF_ID; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public void dispose() { - if (this.mappingFile != null) { - this.mappingFile.dispose(); - } - } - - - // ********** queries ********** - - public MappingFilePersistenceUnitDefaults getPersistenceUnitDefaults() { - MappingFileRoot root = this.getMappingFileRoot_(); - return (root == null) ? null : root.getPersistenceUnitDefaults(); - } - - /** - * #getMappingFileRoot() is already defined by JpaContextNode for the - * descendants of a "mapping file root" - we want something slightly - * different here... - */ - protected MappingFileRoot getMappingFileRoot_() { - return (this.mappingFile == null) ? null : this.mappingFile.getRoot(); - } - - public boolean persistenceUnitDefaultsExists() { - MappingFilePersistenceUnitDefaults defaults = this.getPersistenceUnitDefaults(); - return (defaults != null) && defaults.resourceExists(); - } - - public PersistentType getPersistentType(String typeName) { - return (this.mappingFile == null) ? null : this.mappingFile.getPersistentType(typeName); - } - - - // ********** file name ********** - - public String getFileName() { - return this.fileName; - } - - - // ********** mapping file ********** - - public MappingFile getMappingFile() { - return this.mappingFile; - } - - protected void setMappingFile(MappingFile mappingFile) { - MappingFile old = this.mappingFile; - this.mappingFile = mappingFile; - this.firePropertyChanged(MAPPING_FILE_PROPERTY, old, mappingFile); - } - - - // ********** 2.0 static metamodel ********** - - public void synchronizeStaticMetamodel() { - if (this.mappingFile != null) { - this.mappingFile.synchronizeStaticMetamodel(); - } - } - - // ********** updating ********** - - protected void update() { - this.updateMappingFile(); - } - - protected void updateMappingFile() { - JpaXmlResource xmlResource = this.getXmlResource(); - if (xmlResource != null) { - if (this.mappingFile == null) { - this.setMappingFile(this.buildMappingFile(xmlResource)); - } else { - // if the resource type has changed, rebuild the mapping file - if (this.mappingFile.getXmlResource() != xmlResource) { - this.mappingFile.dispose(); - this.setMappingFile(this.buildMappingFile(xmlResource)); - } else { - this.mappingFile.update(xmlResource); - } - } - } else { - if (this.mappingFile != null) { - this.mappingFile.dispose(); - this.setMappingFile(null); - } - } - } - - /** - * The XmlMappingFileRef resource is the Persistence xml resource. - * This returns the resource of the mapping file itself. - */ - protected JpaXmlResource getXmlResource() { - return this.fileName == null ? null : this.getJpaProject().getMappingFileXmlResource(this.fileName); - } - - protected MappingFile buildMappingFile(JpaXmlResource resource) { - MappingFileDefinition mappingFileDef = getJpaPlatform().getMappingFileDefinition(resource.getContentType()); - return (mappingFileDef == null) ? null : mappingFileDef.getContextNodeFactory().buildMappingFile(this, resource); - } - - @Override - public void postUpdate() { - super.postUpdate(); - if (this.mappingFile != null) { - this.mappingFile.postUpdate(); - } - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (StringTools.stringIsEmpty(this.fileName)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE, - this, - this.getValidationTextRange() - ) - ); - return; - } - - if (this.mappingFile == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - this.buildMissingMappingFileMessageID(), - new String[] {this.fileName}, - this, - this.getValidationTextRange() - ) - ); - return; - } - - if (this.mappingFile.getRoot() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_INVALID_MAPPING_FILE, - new String[] {this.fileName}, - this, - this.getValidationTextRange() - ) - ); - } - - this.mappingFile.validate(messages, reporter); - } - - protected String buildMissingMappingFileMessageID() { - return this.getPlatformFile().exists() ? - JpaValidationMessages.PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT - : - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE; - } - - protected IFile getPlatformFile() { - return this.getJpaProject().convertToPlatformFile(this.fileName); - } - - - // ********** misc ********** - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.fileName); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java deleted file mode 100644 index 477495a59a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java +++ /dev/null @@ -1,1455 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; -import java.util.Vector; -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.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.MappingFilePersistenceUnitDefaults; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.JarFileRef; -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.internal.context.AbstractXmlContextNode; -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.XmlJarFileRef; -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.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * persistence-unit - */ -public abstract class AbstractPersistenceUnit - extends AbstractXmlContextNode - 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 Vector<MappingFileRef> specifiedMappingFileRefs = new Vector<MappingFileRef>(); - protected MappingFileRef impliedMappingFileRef; - - protected final Vector<JarFileRef> jarFileRefs = new Vector<JarFileRef>(); - - protected final Vector<ClassRef> specifiedClassRefs = new Vector<ClassRef>(); - protected final Vector<ClassRef> impliedClassRefs = new Vector<ClassRef>(); - - protected Boolean specifiedExcludeUnlistedClasses; - - protected final Vector<Property> properties = new Vector<Property>(); - - /* global generator definitions, defined elsewhere in model */ - protected final Vector<Generator> generators = new Vector<Generator>(); - - /* global query definitions, defined elsewhere in model */ - protected final Vector<Query> queries = new Vector<Query>(); - - protected final Set<String> rootEntities = new HashSet<String>(); - - protected AccessType defaultAccess; - protected String defaultCatalog; - protected String defaultSchema; - protected boolean defaultCascadePersist; - - - // ********** construction/initialization ********** - - /** - * NB: Be careful changing the order of the statements in this method - * (bug 258701 is one reason). - */ - protected AbstractPersistenceUnit(Persistence parent, XmlPersistenceUnit xmlPersistenceUnit) { - super(parent); - this.xmlPersistenceUnit = xmlPersistenceUnit; - this.name = xmlPersistenceUnit.getName(); - this.specifiedExcludeUnlistedClasses = xmlPersistenceUnit.getExcludeUnlistedClasses(); - this.specifiedTransactionType = this.buildSpecifiedTransactionType(); - this.defaultTransactionType = this.buildDefaultTransactionType(); - this.description = xmlPersistenceUnit.getDescription(); - this.provider = xmlPersistenceUnit.getProvider(); - this.jtaDataSource = xmlPersistenceUnit.getJtaDataSource(); - this.nonJtaDataSource = xmlPersistenceUnit.getNonJtaDataSource(); - this.specifiedExcludeUnlistedClasses = xmlPersistenceUnit.getExcludeUnlistedClasses(); - - // initialize the properties before building the entities because the - // entities will need the properties - this.initializeProperties(); - - this.initializeJarFileRefs(); - - //initialize specified classRefs before mappingFileRefs because of - //JpaFile rootStructureNode, we want the mapping file to "win", - //as it would in a Jpa runtime implementation - this.initializeSpecifiedClassRefs(); - this.initializeMappingFileRefs(); - //initialize implied classRefs last since they depend on both - //specified classRefs and mappingFileRefs - this.initializeImpliedClassRefs(); - this.initializePersistenceUnitDefaults(); - } - - /** - * These lists are just copies of what is distributed across the context - * model; so, if they have (virtually) changed, the resulting update has - * already been triggered. We don't need to trigger another one here. - */ - @Override - protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) { - super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - nonUpdateAspectNames.add(GENERATORS_LIST); - nonUpdateAspectNames.add(QUERIES_LIST); - } - - protected void initializeJarFileRefs() { - for (XmlJarFileRef xmlJarFileRef : this.xmlPersistenceUnit.getJarFiles()) { - this.jarFileRefs.add(this.buildJarFileRef(xmlJarFileRef)); - } - } - - protected void initializeProperties() { - XmlProperties xmlProperties = this.xmlPersistenceUnit.getProperties(); - if (xmlProperties == null) { - return; - } - for (XmlProperty xmlProperty : xmlProperties.getProperties()) { - this.properties.add(this.buildProperty(xmlProperty)); - } - } - - protected void initializeSpecifiedClassRefs() { - for (XmlJavaClassRef xmlJavaClassRef : this.xmlPersistenceUnit.getClasses()) { - this.specifiedClassRefs.add(this.buildClassRef(xmlJavaClassRef)); - } - } - - protected void initializeMappingFileRefs() { - for (XmlMappingFileRef xmlMappingFileRef : this.xmlPersistenceUnit.getMappingFiles()) { - this.specifiedMappingFileRefs.add(this.buildSpecifiedMappingFileRef(xmlMappingFileRef)); - } - if ( ! this.impliedMappingFileIsSpecified() && this.impliedMappingFileExists()) { - this.impliedMappingFileRef = this.buildImpliedMappingFileRef(); - } - } - - protected void initializeImpliedClassRefs() { - if ( ! this.excludesUnlistedClasses()) { - this.initializeImpliedClassRefs_(); - } - } - - protected void initializeImpliedClassRefs_() { - for (Iterator<String> stream = this.getJpaProject().mappedJavaSourceClassNames(); stream.hasNext(); ) { - String typeName = stream.next(); - if ( ! this.specifiesPersistentType(typeName)) { - this.impliedClassRefs.add(this.buildClassRef(typeName)); - } - } - } - - protected void initializePersistenceUnitDefaults() { - MappingFilePersistenceUnitDefaults defaults = this.getDefaults(); - this.defaultAccess = this.buildDefaultAccess(defaults); - this.defaultCatalog = this.buildDefaultCatalog(defaults); - this.defaultSchema = this.buildDefaultSchema(defaults); - this.defaultCascadePersist = this.buildDefaultCascadePersist(defaults); - } - - - // ********** JpaContextNode implementation ********** - - @Override - public Persistence getParent() { - return (Persistence) super.getParent(); - } - - @Override - public PersistenceUnit getPersistenceUnit() { - return this; - } - - - // ********** JpaStructureNode implementation ********** - - public String getId() { - return PersistenceStructureNodes.PERSISTENCE_UNIT_ID; - } - - public TextRange getSelectionTextRange() { - return this.xmlPersistenceUnit.getSelectionTextRange(); - } - - public void dispose() { - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - stream.next().dispose(); - } - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext(); ) { - stream.next().dispose(); - } - } - - - // ********** name ********** - - public String getName() { - return this.name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - this.xmlPersistenceUnit.setName(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - - // ********** transaction type ********** - - public PersistenceUnitTransactionType getTransactionType() { - return (this.specifiedTransactionType != null) ? this.specifiedTransactionType : this.defaultTransactionType; - } - - public PersistenceUnitTransactionType getSpecifiedTransactionType() { - return this.specifiedTransactionType; - } - - public void setSpecifiedTransactionType(PersistenceUnitTransactionType specifiedTransactionType) { - PersistenceUnitTransactionType old = this.specifiedTransactionType; - this.specifiedTransactionType = specifiedTransactionType; - this.xmlPersistenceUnit.setTransactionType(PersistenceUnitTransactionType.toXmlResourceModel(specifiedTransactionType)); - this.firePropertyChanged(SPECIFIED_TRANSACTION_TYPE_PROPERTY, old, specifiedTransactionType); - } - - public PersistenceUnitTransactionType getDefaultTransactionType() { - return this.defaultTransactionType; - } - - protected void setDefaultTransactionType(PersistenceUnitTransactionType defaultTransactionType) { - PersistenceUnitTransactionType old = this.defaultTransactionType; - this.defaultTransactionType = defaultTransactionType; - this.firePropertyChanged(DEFAULT_TRANSACTION_TYPE_PROPERTY, old, defaultTransactionType); - } - - - // ********** description ********** - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - String old = this.description; - this.description = description; - this.xmlPersistenceUnit.setDescription(description); - this.firePropertyChanged(DESCRIPTION_PROPERTY, old, description); - } - - - // ********** provider ********** - - public String getProvider() { - return this.provider; - } - - public void setProvider(String provider) { - String old = this.provider; - this.provider = provider; - this.xmlPersistenceUnit.setProvider(provider); - this.firePropertyChanged(PROVIDER_PROPERTY, old, provider); - } - - - // ********** JTA/non-JTA data source ********** - - public String getJtaDataSource() { - return this.jtaDataSource; - } - - public void setJtaDataSource(String jtaDataSource) { - String old = this.jtaDataSource; - this.jtaDataSource = jtaDataSource; - this.xmlPersistenceUnit.setJtaDataSource(jtaDataSource); - this.firePropertyChanged(JTA_DATA_SOURCE_PROPERTY, old, jtaDataSource); - } - - public String getNonJtaDataSource() { - return this.nonJtaDataSource; - } - - public void setNonJtaDataSource(String nonJtaDataSource) { - String old = this.nonJtaDataSource; - this.nonJtaDataSource = nonJtaDataSource; - this.xmlPersistenceUnit.setNonJtaDataSource(nonJtaDataSource); - this.firePropertyChanged(NON_JTA_DATA_SOURCE_PROPERTY, old, nonJtaDataSource); - } - - - // ********** mapping file refs ********** - - public ListIterator<MappingFileRef> mappingFileRefs() { - return (this.impliedMappingFileRef == null) ? this.specifiedMappingFileRefs() : this.combinedMappingFileRefs(); - } - - protected ListIterator<MappingFileRef> combinedMappingFileRefs() { - return new CompositeListIterator<MappingFileRef>(this.specifiedMappingFileRefs(), this.impliedMappingFileRef); - } - - public int mappingFileRefsSize() { - return (this.impliedMappingFileRef == null) ? this.specifiedMappingFileRefsSize() : this.combinedMappingFileRefsSize(); - } - - protected int combinedMappingFileRefsSize() { - return this.specifiedMappingFileRefsSize() + 1; - } - - public Iterator<MappingFileRef> mappingFileRefsContaining(final String typeName) { - return new FilteringIterator<MappingFileRef, MappingFileRef> (this.mappingFileRefs()) { - @Override - protected boolean accept(MappingFileRef mappingFileRef) { - return mappingFileRef.getPersistentType(typeName) != null; - } - }; - } - - - // ********** specified mapping file refs ********** - - public ListIterator<MappingFileRef> specifiedMappingFileRefs() { - return new CloneListIterator<MappingFileRef>(this.specifiedMappingFileRefs); - } - - public int specifiedMappingFileRefsSize() { - return this.specifiedMappingFileRefs.size(); - } - - public MappingFileRef addSpecifiedMappingFileRef() { - return this.addSpecifiedMappingFileRef(this.specifiedMappingFileRefs.size()); - } - - public MappingFileRef addSpecifiedMappingFileRef(int index) { - XmlMappingFileRef xmlMappingFileRef = this.buildXmlMappingFileRef(); - MappingFileRef mappingFileRef = this.buildSpecifiedMappingFileRef(xmlMappingFileRef); - this.specifiedMappingFileRefs.add(index, mappingFileRef); - this.xmlPersistenceUnit.getMappingFiles().add(index, xmlMappingFileRef); - this.fireItemAdded(SPECIFIED_MAPPING_FILE_REFS_LIST, index, mappingFileRef); - return mappingFileRef; - } - - protected XmlMappingFileRef buildXmlMappingFileRef() { - return PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - } - - public void removeSpecifiedMappingFileRef(MappingFileRef mappingFileRef) { - this.removeSpecifiedMappingFileRef(this.specifiedMappingFileRefs.indexOf(mappingFileRef)); - } - - public void removeSpecifiedMappingFileRef(int index) { - MappingFileRef mappingFileRef = this.specifiedMappingFileRefs.remove(index); - mappingFileRef.dispose(); - this.xmlPersistenceUnit.getMappingFiles().remove(index); - this.fireItemRemoved(SPECIFIED_MAPPING_FILE_REFS_LIST, index, mappingFileRef); - } - - protected void addSpecifiedMappingFileRef_(MappingFileRef mappingFileRef) { - this.addItemToList(mappingFileRef, this.specifiedMappingFileRefs, SPECIFIED_MAPPING_FILE_REFS_LIST); - } - - protected void removeSpecifiedMappingFileRef_(MappingFileRef mappingFileRef) { - mappingFileRef.dispose(); - this.removeItemFromList(mappingFileRef, this.specifiedMappingFileRefs, SPECIFIED_MAPPING_FILE_REFS_LIST); - } - - - // ********** implied mapping file ref ********** - - public MappingFileRef getImpliedMappingFileRef() { - return this.impliedMappingFileRef; - } - - protected MappingFileRef setImpliedMappingFileRef() { - if (this.impliedMappingFileRef != null) { - throw new IllegalStateException("The implied mapping file ref is already set."); //$NON-NLS-1$ - } - this.impliedMappingFileRef = this.buildImpliedMappingFileRef(); - this.firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, null, this.impliedMappingFileRef); - return this.impliedMappingFileRef; - } - - protected MappingFileRef buildImpliedMappingFileRef() { - return this.getJpaFactory().buildImpliedMappingFileRef(this); - } - - protected void unsetImpliedMappingFileRef() { - if (this.impliedMappingFileRef == null) { - throw new IllegalStateException("The implied mapping file ref is already unset."); //$NON-NLS-1$ - } - MappingFileRef old = this.impliedMappingFileRef; - this.impliedMappingFileRef.dispose(); - this.impliedMappingFileRef = null; - this.firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, old, null); - } - - - // ********** JAR file refs ********** - - public ListIterator<JarFileRef> jarFileRefs() { - return new CloneListIterator<JarFileRef>(this.jarFileRefs); - } - - public int jarFileRefsSize() { - return this.jarFileRefs.size(); - } - - public JarFileRef addJarFileRef() { - return this.addJarFileRef(this.jarFileRefs.size()); - } - - public JarFileRef addJarFileRef(int index) { - XmlJarFileRef xmlJarFileRef = this.buildXmlJarFileRef(); - JarFileRef jarFileRef = this.buildJarFileRef(xmlJarFileRef); - this.jarFileRefs.add(index, jarFileRef); - this.xmlPersistenceUnit.getJarFiles().add(index, xmlJarFileRef); - this.fireItemAdded(JAR_FILE_REFS_LIST, index, jarFileRef); - return jarFileRef; - } - - protected XmlJarFileRef buildXmlJarFileRef() { - return PersistenceFactory.eINSTANCE.createXmlJarFileRef(); - } - - public void removeJarFileRef(JarFileRef jarFileRef) { - this.removeJarFileRef(this.jarFileRefs.indexOf(jarFileRef)); - } - - public void removeJarFileRef(int index) { - JarFileRef jarFileRef = this.jarFileRefs.remove(index); - jarFileRef.dispose(); - this.xmlPersistenceUnit.getJarFiles().remove(index); - this.fireItemRemoved(JAR_FILE_REFS_LIST, index, jarFileRef); - } - - protected void addJarFileRef_(JarFileRef jarFileRef) { - this.addItemToList(jarFileRef, this.jarFileRefs, JAR_FILE_REFS_LIST); - } - - protected void removeJarFileRef_(JarFileRef jarFileRef) { - jarFileRef.dispose(); - this.removeItemFromList(jarFileRef, this.jarFileRefs, JAR_FILE_REFS_LIST); - } - - - // ********** class refs ********** - - @SuppressWarnings("unchecked") - public Iterator<ClassRef> classRefs() { - return new CompositeIterator<ClassRef>( - this.specifiedClassRefs(), - this.impliedClassRefs() - ); - } - - public int classRefsSize() { - return this.specifiedClassRefs.size() + this.impliedClassRefs.size(); - } - - - // ********** specified class refs ********** - - public ListIterator<ClassRef> specifiedClassRefs() { - return new CloneListIterator<ClassRef>(this.specifiedClassRefs); - } - - public int specifiedClassRefsSize() { - return this.specifiedClassRefs.size(); - } - - public ClassRef addSpecifiedClassRef() { - return this.addSpecifiedClassRef(this.specifiedClassRefs.size()); - } - - public ClassRef addSpecifiedClassRef(int index) { - XmlJavaClassRef xmlClassRef = this.buildXmlJavaClassRef(); - ClassRef classRef = this.buildClassRef(xmlClassRef); - this.specifiedClassRefs.add(index, classRef); - this.xmlPersistenceUnit.getClasses().add(index, xmlClassRef); - this.fireItemAdded(SPECIFIED_CLASS_REFS_LIST, index, classRef); - return classRef; - } - - protected XmlJavaClassRef buildXmlJavaClassRef() { - return PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - } - - public void removeSpecifiedClassRef(ClassRef classRef) { - this.removeSpecifiedClassRef(this.specifiedClassRefs.indexOf(classRef)); - } - - public void removeSpecifiedClassRef(int index) { - ClassRef classRef = this.specifiedClassRefs.remove(index); - classRef.dispose(); - this.xmlPersistenceUnit.getClasses().remove(index); - this.fireItemRemoved(SPECIFIED_CLASS_REFS_LIST, index, classRef); - } - - protected void addSpecifiedClassRef_(ClassRef classRef) { - this.addItemToList(classRef, this.specifiedClassRefs, SPECIFIED_CLASS_REFS_LIST); - } - - protected void removeSpecifiedClassRef_(ClassRef classRef) { - classRef.dispose(); - this.removeItemFromList(classRef, this.specifiedClassRefs, SPECIFIED_CLASS_REFS_LIST); - } - - - // ********** implied class refs ********** - - public Iterator<ClassRef> impliedClassRefs() { - return new CloneIterator<ClassRef>(this.impliedClassRefs); - } - - public int impliedClassRefsSize() { - return this.impliedClassRefs.size(); - } - - protected ClassRef addImpliedClassRef(String className) { - ClassRef classRef = this.buildClassRef(className); - this.addItemToCollection(classRef, this.impliedClassRefs, IMPLIED_CLASS_REFS_COLLECTION); - return classRef; - } - - protected ClassRef buildClassRef(String className) { - return this.getJpaFactory().buildClassRef(this, className); - } - - protected void removeImpliedClassRef(ClassRef classRef) { - classRef.dispose(); - this.removeItemFromCollection(classRef, this.impliedClassRefs, IMPLIED_CLASS_REFS_COLLECTION); - } - - - // ********** exclude unlisted classes ********** - - public boolean excludesUnlistedClasses() { - return (this.specifiedExcludeUnlistedClasses != null) ? this.specifiedExcludeUnlistedClasses.booleanValue() : this.getDefaultExcludeUnlistedClasses(); - } - - public Boolean getSpecifiedExcludeUnlistedClasses() { - return this.specifiedExcludeUnlistedClasses; - } - - public void setSpecifiedExcludeUnlistedClasses(Boolean specifiedExcludeUnlistedClasses) { - Boolean old = this.specifiedExcludeUnlistedClasses; - this.specifiedExcludeUnlistedClasses = specifiedExcludeUnlistedClasses; - this.xmlPersistenceUnit.setExcludeUnlistedClasses(this.specifiedExcludeUnlistedClasses); - this.firePropertyChanged(SPECIFIED_EXCLUDE_UNLISTED_CLASSES_PROPERTY, old, specifiedExcludeUnlistedClasses); - } - - public boolean getDefaultExcludeUnlistedClasses() { - return false; // ??? - } - - - // ********** properties ********** - - public ListIterator<Property> properties() { - return new CloneListIterator<Property>(this.properties); - } - - protected Iterable<Property> getProperties() { - return new LiveCloneIterable<Property>(this.properties); - } - - public int propertiesSize() { - return this.properties.size(); - } - - public Property getProperty(String propertyName) { - if (propertyName == null) { - throw new NullPointerException(); - } - for (Property property : this.getProperties()) { - if (propertyName.equals(property.getName())) { - return property; - } - } - return null; - } - - public Iterator<Property> propertiesWithNamePrefix(final String propertyNamePrefix) { - if (propertyNamePrefix == null) { - throw new NullPointerException(); - } - return new FilteringIterator<Property, Property>(this.properties()) { - @Override - protected boolean accept(Property property) { - String pName = property.getName(); - return (pName != null) && pName.startsWith(propertyNamePrefix); - } - }; - } - - public Property addProperty() { - return this.addProperty(this.properties.size()); - } - - public Property addProperty(int index) { - return this.addProperty(this.buildXmlProperty(), index); - } - - protected XmlProperty buildXmlProperty() { - return PersistenceFactory.eINSTANCE.createXmlProperty(); - } - - protected Property addProperty(XmlProperty xmlProperty, int index) { - Property property = this.buildProperty(xmlProperty); - - XmlProperties xmlProperties = this.xmlPersistenceUnit.getProperties(); - if (xmlProperties == null) { - xmlProperties = this.buildXmlProperties(); - this.xmlPersistenceUnit.setProperties(xmlProperties); - } - - this.properties.add(index, property); - xmlProperties.getProperties().add(index, xmlProperty); - this.fireItemAdded(PROPERTIES_LIST, index, property); - if (property.getName() != null) { - this.propertyAdded(property.getName(), property.getValue()); - } - return property; - } - - protected Property buildProperty(XmlProperty xmlProperty) { - return this.getJpaFactory().buildProperty(this, xmlProperty); - } - - protected XmlProperties buildXmlProperties() { - return PersistenceFactory.eINSTANCE.createXmlProperties(); - } - - public void setProperty(String propertyName, String value) { - this.setProperty(propertyName, value, false); - } - - public void setProperty(String propertyName, String value, boolean duplicatePropertyNamesAllowed) { - Property prev = this.getProperty(propertyName); - if (prev == null) { - if (value != null) { - this.addProperty(propertyName, value); // add [first] property - } - } else { - if (duplicatePropertyNamesAllowed) { - if (value == null) { - // do nothing? - } else { - this.addProperty(propertyName, value); // add [duplicate] property - } - } else { - if (value == null) { - this.removeProperty(prev); // remove existing property - } else { - prev.setValue(value); // change existing property - } - } - } - } - - protected void addProperty(String propertyName, String value) { - Property property = this.addProperty(); - property.setName(propertyName); - property.setValue(value); - } - - public void removeProperty(Property property) { - this.removeProperty(this.properties.indexOf(property)); - } - - public void removeProperty(String propertyName) { - if (propertyName == null) { - throw new NullPointerException(); - } - for (ListIterator<Property> stream = this.properties.listIterator(); stream.hasNext(); ) { - Property property = stream.next(); - if (propertyName.equals(property.getName())) { - this.removeProperty(stream.previousIndex()); - return; - } - } - throw new IllegalArgumentException("invalid property name: " + propertyName); //$NON-NLS-1$ - } - - public void removeProperty(String propertyName, String value) { - if ((propertyName == null) || (value == null)) { - throw new NullPointerException(); - } - for (ListIterator<Property> stream = this.properties.listIterator(); stream.hasNext(); ) { - Property property = stream.next(); - if (propertyName.equals(property.getName()) && value.equals(property.getValue())) { - this.removeProperty(stream.previousIndex()); - return; - } - } - throw new IllegalArgumentException("invalid property name/value pair: " + propertyName + " = " + value); //$NON-NLS-1$ //$NON-NLS-2$ - } - - protected void removeProperty(int index) { - Property removedProperty = this.properties.remove(index); - this.xmlPersistenceUnit.getProperties().getProperties().remove(index); - - if (this.xmlPersistenceUnit.getProperties().getProperties().isEmpty()) { - this.xmlPersistenceUnit.setProperties(null); - } - - this.fireItemRemoved(PROPERTIES_LIST, index, removedProperty); - if (removedProperty.getName() != null) { - this.propertyRemoved(removedProperty.getName()); - } - } - - protected void addProperty_(int index, Property property) { - this.addItemToList(index, property, this.properties, PROPERTIES_LIST); - if (property.getName() != null) { - this.propertyAdded(property.getName(), property.getValue()); - } - } - - protected void removeProperty_(int index) { - removeProperty_(this.properties.get(index)); - } - - protected void removeProperty_(Property property) { - this.removeItemFromList(property, this.properties, PROPERTIES_LIST); - if (property.getName() != null) { - this.propertyRemoved(property.getName()); - } - } - - protected void moveProperty_(int index, Property property) { - this.moveItemInList(index, this.properties.indexOf(property), this.properties, PROPERTIES_LIST); - } - - public void propertyNameChanged(String oldPropertyName, String newPropertyName, String value) { - if (oldPropertyName == null && value == null) { - //this is a property that is currently being added, we don't need to deal with it until the value is set - return; - } - if (oldPropertyName != null) { - this.propertyRemoved(oldPropertyName); - } - if (newPropertyName != null) { - this.propertyAdded(newPropertyName, value); - } - } - - public void propertyValueChanged(String propertyName, String newValue) { - // do nothing, override in subclasses as necessary - } - - public void propertyAdded(String propertyName, String value) { - this.propertyValueChanged(propertyName, value); - } - - public void propertyRemoved(@SuppressWarnings("unused") String propertyName) { - // do nothing, override in subclasses as necessary - } - - // ********** ORM persistence unit defaults ********** - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType defaultAccess) { - AccessType old = this.defaultAccess; - this.defaultAccess = defaultAccess; - this.firePropertyChanged(DEFAULT_ACCESS_PROPERTY, old, defaultAccess); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String defaultCatalog) { - String old = this.defaultCatalog; - this.defaultCatalog = defaultCatalog; - this.firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, defaultCatalog); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String defaultSchema) { - String old = this.defaultSchema; - this.defaultSchema = defaultSchema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, defaultSchema); - } - - public boolean getDefaultCascadePersist() { - return this.defaultCascadePersist; - } - - protected void setDefaultCascadePersist(boolean defaultCascadePersist) { - boolean old = this.defaultCascadePersist; - this.defaultCascadePersist = defaultCascadePersist; - this.firePropertyChanged(DEFAULT_CASCADE_PERSIST_PROPERTY, old, defaultCascadePersist); - } - - - // ********** generators ********** - - public ListIterator<Generator> generators() { - return new CloneListIterator<Generator>(this.generators); - } - - public int generatorsSize() { - return this.generators.size(); - } - - public void addGenerator(Generator generator) { - this.generators.add(generator); - } - - public String[] uniqueGeneratorNames() { - HashSet<String> names = new HashSet<String>(this.generators.size()); - this.addNonNullGeneratorNamesTo(names); - return names.toArray(new String[names.size()]); - } - - protected void addNonNullGeneratorNamesTo(Set<String> names) { - for (Iterator<Generator> stream = this.generators(); stream.hasNext(); ) { - String generatorName = stream.next().getName(); - if (generatorName != null) { - names.add(generatorName); - } - } - } - - - // ********** queries ********** - - public ListIterator<Query> queries() { - return new CloneListIterator<Query>(this.queries); - } - - public int queriesSize() { - return this.queries.size(); - } - - public void addQuery(Query query) { - this.queries.add(query); - } - - public void addRootWithSubEntities(String entityName) { - this.rootEntities.add(entityName); - } - - public boolean isRootWithSubEntities(String entityName) { - return this.rootEntities.contains(entityName); - } - - // ********** updating ********** - - public void update(XmlPersistenceUnit xpu) { - this.xmlPersistenceUnit = xpu; - - // the 'generators' and 'queries' lists are simply cleared out with each - // "update" and completely rebuilt as the "update" cascades through - // the persistence unit. When the persistence unit's "update" is - // complete, the lists have been populated and we fire the change event. - // @see #addGenerator(Generator) (and references) - // @see #addQuery(Query) (and references) - this.generators.clear(); - this.queries.clear(); - - this.rootEntities.clear(); - - this.setName(xpu.getName()); - this.setSpecifiedTransactionType(this.buildSpecifiedTransactionType()); - this.setDefaultTransactionType(this.buildDefaultTransactionType()); - this.setDescription(xpu.getDescription()); - this.setProvider(xpu.getProvider()); - this.setJtaDataSource(xpu.getJtaDataSource()); - this.setNonJtaDataSource(xpu.getNonJtaDataSource()); - this.updateJarFileRefs(); - - // update 'specifiedClassRefs' before 'mappingFileRefs' because of - // JpaFile rootStructureNode, we want the mapping file to "win", - // as it would in a JPA runtime implementation - this.updateSpecifiedClassRefs(); - this.updateMappingFileRefs(); - - // update 'impliedClassRefs' last since it depends on the contents of - // both 'specifiedClassRefs' and 'mappingFileRefs' - this.updateImpliedClassRefs(); - - this.setSpecifiedExcludeUnlistedClasses(xpu.getExcludeUnlistedClasses()); - this.updateProperties(); - this.updatePersistenceUnitDefaults(); - - // see comment at top of method - this.fireListChanged(GENERATORS_LIST, this.generators); - this.fireListChanged(QUERIES_LIST, this.queries); - } - - @Override - public void postUpdate() { - super.postUpdate(); - for (ClassRef classRef : CollectionTools.iterable(this.specifiedClassRefs())) { - classRef.postUpdate(); - } - for (ClassRef classRef : CollectionTools.iterable(this.impliedClassRefs())) { - classRef.postUpdate(); - } - for (MappingFileRef mappingFileRef : CollectionTools.iterable(this.specifiedMappingFileRefs())) { - mappingFileRef.postUpdate(); - } - if (this.impliedMappingFileRef != null) { - this.impliedMappingFileRef.postUpdate(); - } - } - - protected PersistenceUnitTransactionType buildSpecifiedTransactionType() { - return PersistenceUnitTransactionType.fromXmlResourceModel(this.xmlPersistenceUnit.getTransactionType()); - } - - /** - * 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." - */ - protected PersistenceUnitTransactionType buildDefaultTransactionType() { - return PersistenceUnitTransactionType.JTA; //return JTA for now, fixing regression in bug 277524 - } - - /** - * Since this is a *list*, we simply loop through the elements and match - * the context to the resource element by index, not by name like we do - * with 'impliedClassRefs'. - */ - protected void updateJarFileRefs() { - // make a copy of the XML file refs (to prevent ConcurrentModificationException) - Iterator<XmlJarFileRef> xmlFileRefs = new CloneIterator<XmlJarFileRef>(this.xmlPersistenceUnit.getJarFiles()); - - for (Iterator<JarFileRef> contextFileRefs = this.jarFileRefs(); contextFileRefs.hasNext(); ) { - JarFileRef contextFileRef = contextFileRefs.next(); - if (xmlFileRefs.hasNext()) { - contextFileRef.update(xmlFileRefs.next()); - } else { - this.removeJarFileRef_(contextFileRef); - } - } - - while (xmlFileRefs.hasNext()) { - this.addJarFileRef_(this.buildJarFileRef(xmlFileRefs.next())); - } - } - - protected JarFileRef buildJarFileRef(XmlJarFileRef xmlJarFileRef) { - return this.getJpaFactory().buildJarFileRef(this, xmlJarFileRef); - } - - /** - * Since this is a *list*, we simply loop through the elements and match - * the context to the resource element by index, not by name like we do - * with 'impliedClassRefs'. - */ - protected void updateSpecifiedClassRefs() { - // make a copy of the XML class refs (to prevent ConcurrentModificationException) - Iterator<XmlJavaClassRef> xmlClassRefs = new CloneIterator<XmlJavaClassRef>(this.xmlPersistenceUnit.getClasses()); - - for (Iterator<ClassRef> contextClassRefs = this.specifiedClassRefs(); contextClassRefs.hasNext(); ) { - ClassRef contextClassRef = contextClassRefs.next(); - if (xmlClassRefs.hasNext()) { - contextClassRef.update(xmlClassRefs.next()); - } else { - this.removeSpecifiedClassRef_(contextClassRef); - } - } - - while (xmlClassRefs.hasNext()) { - this.addSpecifiedClassRef_(this.buildClassRef(xmlClassRefs.next())); - } - } - - protected ClassRef buildClassRef(XmlJavaClassRef xmlClassRef) { - return this.getJpaFactory().buildClassRef(this, xmlClassRef); - } - - /** - * Since this is a *list*, we simply loop through the elements and match - * the context to the resource element by index, not by name like we do - * with 'impliedClassRefs'. - */ - protected void updateMappingFileRefs() { - // first update the specified mapping file refs... - // make a copy of the XML file refs (to prevent ConcurrentModificationException) - Iterator<XmlMappingFileRef> xmlFileRefs = new CloneIterator<XmlMappingFileRef>(this.xmlPersistenceUnit.getMappingFiles()); - - for (Iterator<MappingFileRef> contextFileRefs = this.specifiedMappingFileRefs(); contextFileRefs.hasNext(); ) { - MappingFileRef contextFileRef = contextFileRefs.next(); - if (xmlFileRefs.hasNext()) { - contextFileRef.update(xmlFileRefs.next()); - } else { - this.removeSpecifiedMappingFileRef_(contextFileRef); - } - } - - while (xmlFileRefs.hasNext()) { - this.addSpecifiedMappingFileRef_(this.buildSpecifiedMappingFileRef(xmlFileRefs.next())); - } - - // ...then update the implied mapping file ref - if (this.impliedMappingFileIsSpecified()) { - if (this.impliedMappingFileRef != null) { - this.unsetImpliedMappingFileRef(); - } - } else { - if (this.impliedMappingFileExists()) { - if (this.impliedMappingFileRef == null) { - this.setImpliedMappingFileRef(); - } - this.impliedMappingFileRef.update(null); - } else { - if (this.impliedMappingFileRef != null) { - this.unsetImpliedMappingFileRef(); - } - } - } - } - - protected MappingFileRef buildSpecifiedMappingFileRef(XmlMappingFileRef xmlMappingFileRef) { - return this.getJpaFactory().buildMappingFileRef(this, xmlMappingFileRef); - } - - protected boolean impliedMappingFileIsSpecified() { - String impliedMappingFileName = JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH; - for (Iterator<MappingFileRef> stream = this.specifiedMappingFileRefs(); stream.hasNext(); ) { - if (impliedMappingFileName.equals(stream.next().getFileName())) { - return true; - } - } - return false; - } - - protected boolean impliedMappingFileExists() { - return getJpaProject().getDefaultOrmXmlResource() != null; - } - - protected void updateImpliedClassRefs() { - if (this.excludesUnlistedClasses()) { - this.clearImpliedClassRefs_(); - } else { - this.updateImpliedClassRefs_(); - } - } - - protected void updateImpliedClassRefs_() { - HashBag<ClassRef> impliedRefsToRemove = CollectionTools.bag(this.impliedClassRefs(), this.impliedClassRefsSize()); - ArrayList<ClassRef> impliedRefsToUpdate = new ArrayList<ClassRef>(this.impliedClassRefsSize()); - - for (Iterator<String> mappedClassNames = this.getJpaProject().mappedJavaSourceClassNames(); mappedClassNames.hasNext(); ) { - String mappedClassName = mappedClassNames.next(); - if ( ! this.specifiesPersistentType(mappedClassName)) { - boolean match = false; - for (Iterator<ClassRef> classRefs = impliedRefsToRemove.iterator(); classRefs.hasNext(); ) { - ClassRef classRef = classRefs.next(); - if (mappedClassName.equals(classRef.getClassName())) { - classRefs.remove(); - impliedRefsToUpdate.add(classRef); - match = true; - break; - } - } - if ( ! match) { - this.addImpliedClassRef(mappedClassName); - } - } - } - for (ClassRef classRef : impliedRefsToRemove) { - this.removeImpliedClassRef(classRef); - } - // handle adding and removing implied class refs first, update the - // remaining implied class refs last; this reduces the churn during "update" - for (ClassRef classRef : impliedRefsToUpdate) { - classRef.update(classRef.getClassName()); - } - } - - protected void clearImpliedClassRefs_() { - for (Iterator<ClassRef> stream = this.impliedClassRefs(); stream.hasNext(); ) { - this.removeImpliedClassRef(stream.next()); - } - } - - /** - * Match the elements based on the XmlProperty resource object and also keep the order - * the same as the source. - */ - protected void updateProperties() { - HashBag<Property> contextPropertiesToRemove = CollectionTools.bag(this.properties(), this.propertiesSize()); - int resourceIndex = 0; - - for (Iterator<XmlProperty> xmlProperties = this.xmlProperties(); xmlProperties.hasNext(); ) { - XmlProperty xmlProperty = xmlProperties.next(); - boolean match = false; - for (Iterator<Property> contextProperties = contextPropertiesToRemove.iterator(); contextProperties.hasNext();) { - Property contextProperty = contextProperties.next(); - if (contextProperty.getXmlProperty() == xmlProperty) { - contextProperties.remove(); - this.moveProperty_(resourceIndex, contextProperty); - contextProperty.update(); - match = true; - break; - } - } - if ( ! match) { - this.addProperty_(resourceIndex, this.buildProperty(xmlProperty)); - } - resourceIndex++; - } - for (Property contextProperty : contextPropertiesToRemove) { - this.removeProperty_(contextProperty); - } - } - - protected Iterator<XmlProperty> xmlProperties() { - XmlProperties xmlProperties = this.xmlPersistenceUnit.getProperties(); - // make a copy of the XML properties (to prevent ConcurrentModificationException) - return (xmlProperties != null) ? new CloneIterator<XmlProperty>(xmlProperties.getProperties()) : EmptyIterator.<XmlProperty>instance(); - } - - protected int xmlPropertiesSize() { - XmlProperties xmlProperties = this.xmlPersistenceUnit.getProperties(); - return xmlProperties == null ? 0 : xmlProperties.getProperties().size(); - } - - protected void updatePersistenceUnitDefaults() { - MappingFilePersistenceUnitDefaults defaults = this.getDefaults(); - this.setDefaultAccess(this.buildDefaultAccess(defaults)); - this.setDefaultCatalog(this.buildDefaultCatalog(defaults)); - this.setDefaultSchema(this.buildDefaultSchema(defaults)); - this.setDefaultCascadePersist(this.buildDefaultCascadePersist(defaults)); - } - - /** - * return the first persistence unit defaults we encounter in a mapping file - */ - protected MappingFilePersistenceUnitDefaults getDefaults() { - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext(); ) { - MappingFileRef mappingFileRef = stream.next(); - if (mappingFileRef.persistenceUnitDefaultsExists()) { - return mappingFileRef.getPersistenceUnitDefaults(); - } - } - return null; - } - - protected AccessType buildDefaultAccess(MappingFilePersistenceUnitDefaults defaults) { - return (defaults == null) ? null : defaults.getAccess(); - } - - protected String buildDefaultCatalog(MappingFilePersistenceUnitDefaults defaults) { - String catalog = (defaults == null) ? null : defaults.getCatalog(); - return (catalog != null) ? catalog : this.getJpaProject().getDefaultCatalog(); - } - - protected String buildDefaultSchema(MappingFilePersistenceUnitDefaults defaults) { - String schema = (defaults == null) ? null : defaults.getSchema(); - return (schema != null) ? schema : this.getJpaProject().getDefaultSchema(); - } - - protected boolean buildDefaultCascadePersist(MappingFilePersistenceUnitDefaults defaults) { - return (defaults == null) ? false : defaults.isCascadePersist(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - validateMappingFiles(messages, reporter); - validateClassRefs(messages, reporter); - validateJarFileRefs(messages, reporter); - } - - protected void validateMappingFiles(List<IMessage> messages, IReporter reporter) { - this.checkForMultiplePersistenceUnitDefaults(messages); - this.checkForDuplicateMappingFiles(messages); - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext();) { - stream.next().validate(messages, reporter); - } - } - - protected void checkForMultiplePersistenceUnitDefaults(List<IMessage> messages) { - Iterator<MappingFileRef> stream = mappingFileRefs(); - while (stream.hasNext()) { - if (stream.next().persistenceUnitDefaultsExists()) { - break; - } - } - while (stream.hasNext()) { - MappingFileRef mappingFileRef = stream.next(); - if (mappingFileRef.persistenceUnitDefaultsExists()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_DEFAULTS, - new String[] {mappingFileRef.getFileName()}, - mappingFileRef - ) - ); - } - } - } - - protected void checkForDuplicateMappingFiles(List<IMessage> messages) { - HashBag<String> fileNames = new HashBag<String>(); - CollectionTools.addAll(fileNames, this.mappingFileRefNames()); - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext(); ) { - MappingFileRef mappingFileRef = stream.next(); - String fileName = mappingFileRef.getFileName(); - if (fileNames.count(fileName) > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE, - new String[] {fileName}, - mappingFileRef, - mappingFileRef.getValidationTextRange() - ) - ); - } - } - } - - protected Iterator<String> mappingFileRefNames() { - return new TransformationIterator<MappingFileRef, String>(this.mappingFileRefs()) { - @Override - protected String transform(MappingFileRef mappingFileRef) { - return mappingFileRef.getFileName(); - } - }; - } - - protected void validateClassRefs(List<IMessage> messages, IReporter reporter) { - this.checkForDuplicateClasses(messages); - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); - } - } - - protected void checkForDuplicateClasses(List<IMessage> messages) { - HashBag<String> classNames = new HashBag<String>(); - CollectionTools.addAll(classNames, this.classRefNames()); - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - ClassRef classRef = stream.next(); - String className = classRef.getClassName(); - if ((className != null) && (classNames.count(className) > 1)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_CLASS, - new String[] {className}, - classRef, - classRef.getValidationTextRange() - ) - ); - } - } - } - - protected Iterator<String> classRefNames() { - return new TransformationIterator<ClassRef, String>(this.classRefs()) { - @Override - protected String transform(ClassRef classRef) { - return classRef.getClassName(); - } - }; - } - - protected void validateJarFileRefs(List<IMessage> messages, IReporter reporter) { - checkForDuplicateJarFileRefs(messages); - for (JarFileRef each : CollectionTools.iterable(jarFileRefs())) { - each.validate(messages, reporter); - } - } - - protected void checkForDuplicateJarFileRefs(List<IMessage> messages) { - HashBag<String> jarFileNames = new HashBag<String>(); - CollectionTools.addAll(jarFileNames, jarFileNames()); - for (JarFileRef jarFileRef : CollectionTools.iterable(jarFileRefs())) { - String jarFileName = jarFileRef.getFileName(); - if ((jarFileName != null) && (jarFileNames.count(jarFileName) > 1)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_JAR_FILE, - new String[] {jarFileName}, - jarFileRef, - jarFileRef.getValidationTextRange() - ) - ); - } - } - } - - protected Iterator<String> jarFileNames() { - return new TransformationIterator<JarFileRef, String>(jarFileRefs()) { - @Override - protected String transform(JarFileRef jarFileRef) { - return jarFileRef.getFileName(); - } - }; - } - - - // ********** misc ********** - - public JpaStructureNode getStructureNode(int textOffset) { - for (Iterator<JarFileRef> stream = this.jarFileRefs(); stream.hasNext(); ) { - JarFileRef jarFileRef = stream.next(); - if (jarFileRef.containsOffset(textOffset)) { - return jarFileRef; - } - } - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext(); ) { - MappingFileRef mappingFileRef = stream.next(); - if (mappingFileRef.containsOffset(textOffset)) { - return mappingFileRef; - } - } - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - ClassRef classRef = stream.next(); - if (classRef.containsOffset(textOffset)) { - return classRef; - } - } - return this; - } - - public boolean shouldValidateAgainstDatabase() { - return connectionProfileIsActive(); - } - - public TextRange getValidationTextRange() { - return this.xmlPersistenceUnit.getValidationTextRange(); - } - - public PersistentType getPersistentType(String typeName) { - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext(); ) { - PersistentType persistentType = stream.next().getPersistentType(typeName); - if (persistentType != null) { - return persistentType; - } - } - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - ClassRef classRef = stream.next(); - if (classRef.isFor(typeName)) { - return classRef.getJavaPersistentType(); - } - } - for (Iterator<JarFileRef> stream = this.jarFileRefs(); stream.hasNext(); ) { - PersistentType persistentType = stream.next().getPersistentType(typeName); - if (persistentType != null) { - return persistentType; - } - } - return null; - } - - public boolean specifiesPersistentType(String className) { - for (Iterator<ClassRef> stream = this.specifiedClassRefs(); stream.hasNext(); ) { - if (className.equals(stream.next().getClassName())) { - return true; - } - } - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext(); ) { - if (stream.next().getPersistentType(className) != null) { - return true; - } - } - return false; - } - - public Entity getEntity(String typeName) { - PersistentType persistentType = this.getPersistentType(typeName); - if (persistentType == null) { - return null; - } - TypeMapping typeMapping = persistentType.getMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - public Embeddable getEmbeddable(String typeName) { - PersistentType persistentType = this.getPersistentType(typeName); - if (persistentType == null) { - return null; - } - TypeMapping typeMapping = persistentType.getMapping(); - return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null; - } - - public boolean containsOffset(int textOffset) { - return (this.xmlPersistenceUnit != null) && this.xmlPersistenceUnit.containsOffset(textOffset); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java deleted file mode 100644 index 368b210e97..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java +++ /dev/null @@ -1,394 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; - -/** - * AbstractPersistenceUnitProperties - */ -public abstract class AbstractPersistenceUnitProperties extends AbstractModel - implements PersistenceUnitProperties -{ - private PersistenceUnit persistenceUnit; - - // key = PersistenceUnit property key; value = property id - private Map<String, String> propertyNames; - - private static final long serialVersionUID = 1L; - - // ********** constructors / initialization ********** - protected AbstractPersistenceUnitProperties(PersistenceUnit parent) { - super(); - this.initialize(parent); - } - - protected void initialize(PersistenceUnit parent) { - this.persistenceUnit = parent; - - this.initializePropertyNames(); - this.initializeProperties(); - this.postInitializeProperties(); - } - - protected void initializePropertyNames() { - this.propertyNames = new HashMap<String, String>(); - this.addPropertyNames(this.propertyNames); - } - - /** - * Initializes properties with values from the persistence unit. - */ - protected abstract void initializeProperties(); - - /** - * Does all post treatment in this method after the properties are initialized - */ - protected void postInitializeProperties() { - // do nothing by default - } - - // ********** behavior ********** - public PersistenceUnit getPersistenceUnit() { - return this.persistenceUnit; - } - - public JpaProject getJpaProject() { - return this.persistenceUnit.getJpaProject(); - } - - private Map<String, String> propertyNames() { - return this.propertyNames; - } - /** - * Adds property names key/value pairs, used by the methods: itemIsProperty - * and propertyIdFor. - * - * key = property key; value = property id - */ - protected abstract void addPropertyNames(Map<String, String> pNames); - - /** - * Method used for identifying the given property. - */ - public boolean itemIsProperty(PersistenceUnit.Property item) { - if (item == null) { - throw new NullPointerException(); - } - return this.propertyNames().keySet().contains(item.getName()); - } - - /** - * Returns the property name used for change notification of the given - * property. - */ - public String propertyIdOf(PersistenceUnit.Property property) { - String propertyId = this.propertyNames().get(property.getName()); - if (propertyId == null) { - throw new IllegalArgumentException("Illegal property: " + property); //$NON-NLS-1$ - } - return propertyId; - } - - /* - * Get the PersistenceUnit property key of the given property - */ - protected String persistenceUnitKeyOf(String propertyId) { - for (String persistenceUnitKey : this.propertyNames().keySet()) { - if (this.propertyNames().get(persistenceUnitKey).equals(propertyId)) { - return persistenceUnitKey; - } - } - throw new IllegalArgumentException("Illegal property ID: " + propertyId); //$NON-NLS-1$ - } - - // ******** Convenience methods ******** - /** - * Put into persistenceUnit properties. - * - * @param key - - * property name - * @param value - - * property value - */ - protected void putProperty(String key, Object value) { - this.putProperty(key, value, false); - } - - @SuppressWarnings("unchecked") - protected void putProperty(String key, Object value, boolean allowDuplicates) { - String persistenceUnitKey = this.persistenceUnitKeyOf(key); - if ((value != null) && value.getClass().isEnum()) { - this.putEnumValue(persistenceUnitKey, (Enum) value, allowDuplicates); - } - else { - this.putPersistenceUnitProperty(persistenceUnitKey, null, value, allowDuplicates); - } - } - - private void putPersistenceUnitProperty(String key, String keySuffix, Object value, boolean allowDuplicates) { - String persistenceUnitKey = (keySuffix == null) ? key : key + keySuffix; - String stringValue = (value == null) ? null : value.toString(); - this.getPersistenceUnit().setProperty(persistenceUnitKey, stringValue, allowDuplicates); - } - - /** - * Removes a persistenceUnit property. - * - * @param key - - * property name - * @param value - - * property value - */ - protected void removeProperty(String key, String value) { - String persistenceUnitKey = this.persistenceUnitKeyOf(key); - - this.getPersistenceUnit().removeProperty(persistenceUnitKey, value); - } - - /** - * Returns true when the given key exits in the PersistenceXml. - */ - protected boolean persistenceUnitKeyExists(String persistenceUnitKey) { - return (this.getStringValue(persistenceUnitKey) != null); - } - - // ****** get/set String convenience methods ******* - /** - * Returns the String value of the given Property from the PersistenceXml. - */ - protected String getStringValue(String persistenceUnitKey) { - PersistenceUnit.Property p = this.getPersistenceUnit().getProperty(persistenceUnitKey); - return (p == null) ? null : p.getValue(); - } - - protected String getStringValue(String key, String keySuffix) { - return this.getStringValue((keySuffix == null) ? key : key + keySuffix); - } - - /** - * Put the given String value into the PersistenceXml. - * @param key - - * property key - * @param newValue - * value to be associated with the key - */ - protected void putStringValue(String key, String newValue) { - this.putStringValue(key, null, newValue, false); - } - - /** - * Put the given String value into the PersistenceXml. - * @param key - * property key - * @param newValue - * value to be associated with the key - * @param allowDuplicate - */ - protected void putStringValue(String key, String newValue, boolean allowDuplicate) { - this.putStringValue(key, null, newValue, allowDuplicate); - } - - /** - * Put the given String value into the PersistenceXml. - * @param key - * property key - * @param keySuffix - * e.g. entity name - * @param newValue - * value to be associated with the key - * @param allowDuplicate - */ - protected void putStringValue(String key, String keySuffix, String newValue, boolean allowDuplicate) { - this.putPersistenceUnitProperty(key, keySuffix, newValue, allowDuplicate); - } - - // ****** Integer convenience methods ******* - /** - * Returns the Integer value of the given Property from the PersistenceXml. - */ - protected Integer getIntegerValue(String persistenceUnitKey) { - PersistenceUnit.Property p = this.getPersistenceUnit().getProperty(persistenceUnitKey); - return (p == null) ? null : getIntegerValueOf(p.getValue()); - } - - protected Integer getIntegerValue(String key, String keySuffix) { - return this.getIntegerValue((keySuffix == null) ? key : key + keySuffix); - } - - /** - * Put the given Integer value into the PersistenceXml. - * @param key - - * property key - * @param newValue - * value to be associated with the key - */ - protected void putIntegerValue(String key, Integer newValue) { - this.putIntegerValue(key, null, newValue, false); - } - - /** - * Put the given Integer value into the PersistenceXml. - * @param key - * property key - * @param newValue - * value to be associated with the key - * @param allowDuplicate - */ - protected void putIntegerValue(String key, Integer newValue, boolean allowDuplicate) { - this.putIntegerValue(key, null, newValue, allowDuplicate); - } - - /** - * Put the given Integer value into the PersistenceXml. - * @param key - * property key - * @param keySuffix - * e.g. entity name - * @param newValue - * value to be associated with the key - * @param allowDuplicate - */ - protected void putIntegerValue(String key, String keySuffix, Integer newValue, boolean allowDuplicate) { - this.putPersistenceUnitProperty(key, keySuffix, newValue, allowDuplicate); - } - - // ****** Boolean convenience methods ******* - /** - * Returns the Boolean value of the given Property from the PersistenceXml. - */ - protected Boolean getBooleanValue(String persistenceUnitKey) { - PersistenceUnit.Property p = this.getPersistenceUnit().getProperty(persistenceUnitKey); - return (p == null) ? null : getBooleanValueOf(p.getValue()); - } - - protected Boolean getBooleanValue(String key, String keySuffix) { - return this.getBooleanValue((keySuffix == null) ? key : key + keySuffix); - } - - /** - * Put the given Boolean value into the PersistenceXml. - * @param key - * property key - * @param newValue - * value to be associated with the key - */ - protected void putBooleanValue(String key, Boolean newValue) { - this.putBooleanValue(key, null, newValue, false); - } - - /** - * Put the given Boolean value into the PersistenceXml. - * @param key - * property key - * @param newValue - * value to be associated with the key - * @param allowDuplicate - */ - protected void putBooleanValue(String key, Boolean newValue, boolean allowDuplicate) { - this.putBooleanValue(key, null, newValue, allowDuplicate); - } - - /** - * Put the given Boolean value into the PersistenceXml. - * @param key - * property key - * @param keySuffix - * e.g. entity name - * @param newValue - * value to be associated with the key - * @param allowDuplicate - */ - protected void putBooleanValue(String key, String keySuffix, Boolean newValue, boolean allowDuplicate) { - this.putPersistenceUnitProperty(key, keySuffix, newValue, allowDuplicate); - } - - // ****** Enum convenience methods ******* - /** - * Returns the Enum value of the given Property from the PersistenceXml. - */ - protected <T extends Enum<T>> T getEnumValue(String persistenceUnitKey, T[] enumValues) { - PersistenceUnit.Property p = this.getPersistenceUnit().getProperty(persistenceUnitKey); - return (p == null) ? null : getEnumValueOf(p.getValue(), enumValues); - } - - protected <T extends Enum<T>> T getEnumValue(String key, String keySuffix, T[] enumValues) { - return this.getEnumValue((keySuffix == null) ? key : key + keySuffix, enumValues); - } - - /** - * Put the given Enum value into the PersistenceXml. - * - * @param key - - * property key - */ - protected <T extends Enum<T>> void putEnumValue(String key, T newValue) { - this.putEnumValue(key, null, newValue, false); - } - - protected <T extends Enum<T>> void putEnumValue(String key, T newValue, boolean allowDuplicate) { - this.putEnumValue(key, null, newValue, allowDuplicate); - } - - protected <T extends Enum<T>> void putEnumValue(String key, String keySuffix, T newValue, boolean allowDuplicate) { - this.putPersistenceUnitProperty(key, keySuffix, getPropertyStringValueOf(newValue), allowDuplicate); - } - - // ****** Static methods ******* - - public static Boolean getBooleanValueOf(String puStringValue) { - if (puStringValue == null) { - return null; - } - return Boolean.valueOf(puStringValue); - } - - public static Integer getIntegerValueOf(String puStringValue) { - if (puStringValue == null) { - return null; - } - return Integer.valueOf(puStringValue); - } - - /** - * Returns the enum constant of the specified enum type with the specified - * Property string value. - */ - public static <T extends Enum<T>> T getEnumValueOf(String puStringValue, T[] enumValues) { - for (T enumValue : enumValues) { - if (getPropertyStringValueOf(enumValue).equals(puStringValue)) { - return enumValue; - } - } - return null; - } - - /** - * Returns the Property string value of the given property value. - */ - public static String getPropertyStringValueOf(Object value) { - if (value == null) { - return null; - } - if (value.getClass().isEnum()) { - return (String) ClassTools.staticFieldValue(value.getClass(), value.toString().toUpperCase(Locale.ENGLISH)); - } - return value.toString(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java deleted file mode 100644 index a618f9f372..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.facet; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProperties; - -@SuppressWarnings("nls") -public interface JpaFacetDataModelProperties - extends IDataModelProperties -{ - String PREFIX = "JpaFacetDataModelProperties"; - String PREFIX_ = PREFIX + '.'; - - /** - * Internal, type IRuntime, identifies runtime associated with project - * Used only in conjunction with validation of other properties, because this information - * is otherwise inaccessible to this data model - */ - String RUNTIME = PREFIX_ + "RUNTIME"; - - /** - * Required, type String, identifies Jpa Platform - */ - String PLATFORM_ID = PREFIX_ + "PLATFORM_ID"; - - /** - * Required, type LibraryInstallDelegate, the library install delegate used to configure JPA provider library - */ - String LIBRARY_PROVIDER_DELEGATE = PREFIX_ + "LIBRARY_PROVIDER_DELEGATE"; - - /** - * Not required, type String, identifies database connection - */ - String CONNECTION = PREFIX_ + "CONNECTION"; - - /** - * Required, type Boolean, identifies whether database connection is active - */ - String CONNECTION_ACTIVE = PREFIX_ + "CONNECTION_ACTIVE"; - - /** - * Required, type Boolean, identifies if the user wishes to add the database driver jars to the classpath - */ - String USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH = PREFIX_ + "USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH"; - - /** - * Not required, type String, identifies the database driver library added to the classpath - */ - String DB_DRIVER_NAME = PREFIX_ + "DB_DRIVER_NAME"; - - /** - * Required, type Boolean, identifies if the user wishes to override default Catalog name - */ - String USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG = PREFIX_ + "USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG"; - - /** - * Not required, type String, identifies the user overridden default Catalog name - */ - String USER_OVERRIDE_DEFAULT_CATALOG = PREFIX_ + "USER_OVERRIDE_DEFAULT_CATALOG"; - - /** - * Required, type Boolean, identifies if the user wishes to override default schema name - */ - String USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA = PREFIX_ + "USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA"; - - /** - * Not required, type String, identifies the user overridden default schema name - */ - String USER_OVERRIDE_DEFAULT_SCHEMA = PREFIX_ + "USER_OVERRIDE_DEFAULT_SCHEMA"; - - /** - * Required, type boolean, opposite of LIST_ANNOTATED_CLASSES, identifies - * whether all annotated classes are to be automatically included as part of - * all persistence units - */ - String DISCOVER_ANNOTATED_CLASSES = PREFIX_ + "DISCOVER_ANNOTATED_CLASSES"; - - /** - * Required, type boolean, opposite of DISCOVER_ANNOTATED_CLASSES, identifies - * if annotated classes should be listed in the persistence.xml in order to - * be considered part of a persistence unit - * (This additional setting is necessary in order to use synchHelper within - * the wizard - there must be a unique property for each radio button. Stupid - * but true) - */ - String LIST_ANNOTATED_CLASSES = PREFIX_ + "LIST_ANNOTATED_CLASSES"; - - /** - * Required, type boolean, details whether orm.xml should be created - */ - String CREATE_ORM_XML = PREFIX_ + "CREATE_ORM_XML"; -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java deleted file mode 100644 index edce672254..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java +++ /dev/null @@ -1,736 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.facet; - -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.JpaPlatformRegistry; -import org.eclipse.jpt.core.internal.JptCoreMessages; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.DatabaseFinder; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; - -public class JpaFacetDataModelProvider - extends FacetInstallDataModelProvider - implements JpaFacetDataModelProperties -{ - private LibraryInstallDelegate defaultLibraryProvider; - - /** cache the connection profile - change it whenever the user selects a different name */ - private ConnectionProfile connectionProfile; - - - private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; - - private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = - buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED); - - private static final IStatus CONNECTION_NOT_CONNECTED_STATUS = - buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED); - - private static final IStatus USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS = - buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED); - - private static final IStatus USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS = - buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED); - - - /** - * required default constructor - */ - public JpaFacetDataModelProvider() { - super(); - } - - @Override - public Set<String> getPropertyNames() { - @SuppressWarnings("unchecked") Set<String> propertyNames = super.getPropertyNames(); - propertyNames.add(RUNTIME); - propertyNames.add(PLATFORM_ID); - propertyNames.add(LIBRARY_PROVIDER_DELEGATE); - propertyNames.add(CONNECTION); - propertyNames.add(CONNECTION_ACTIVE); - propertyNames.add(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); - propertyNames.add(DB_DRIVER_NAME); - propertyNames.add(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); - propertyNames.add(USER_OVERRIDE_DEFAULT_CATALOG); - propertyNames.add(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); - propertyNames.add(USER_OVERRIDE_DEFAULT_SCHEMA); - propertyNames.add(DISCOVER_ANNOTATED_CLASSES); - propertyNames.add(LIST_ANNOTATED_CLASSES); - propertyNames.add(CREATE_ORM_XML); - return propertyNames; - } - - - // ********** properties ********** - - private String getPlatformId() { - return (String) this.getProperty(PLATFORM_ID); - } - - private String getConnectionName() { - return (String) this.getProperty(CONNECTION); - } - - private boolean userWantsToAddDbDriverJarsToClasspath() { - return this.getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH); - } - - private String getDriverName() { - return (String) this.getProperty(DB_DRIVER_NAME); - } - - private boolean userWantsToOverrideDefaultCatalog() { - return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG); - } - - private String getUserOverrideDefaultCatalog() { - return (String) this.getProperty(USER_OVERRIDE_DEFAULT_CATALOG); - } - - private boolean userWantsToOverrideDefaultSchema() { - return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); - } - - private String getUserOverrideDefaultSchema() { - return (String) this.getProperty(USER_OVERRIDE_DEFAULT_SCHEMA); - } - - private boolean discoverAnnotatedClasses() { - return this.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES); - } - - private IFacetedProjectWorkingCopy getFacetedProjectWorkingCopy() { - return (IFacetedProjectWorkingCopy) this.getProperty(FACETED_PROJECT_WORKING_COPY); - } - - private IProjectFacetVersion getProjectFacetVersion() { - return (IProjectFacetVersion) this.getProperty(FACET_VERSION); - } - - private IRuntime getRuntime() { - return (IRuntime) this.getProperty(RUNTIME); - } - - private LibraryInstallDelegate getLibraryInstallDelegate() { - return (LibraryInstallDelegate) this.getProperty(LIBRARY_PROVIDER_DELEGATE); - } - - - // ********** enabled ********** - - @Override - public boolean isPropertyEnabled(String propertyName) { - if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { - return (this.getConnectionProfile() != null); - } - if (propertyName.equals(DB_DRIVER_NAME)) { - return this.userWantsToAddDbDriverJarsToClasspath(); - } - - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { - return this.connectionIsActive() && this.databaseSupportsCatalogs(); - } - if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return this.userWantsToOverrideDefaultCatalog(); - } - - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - return this.connectionIsActive(); - } - if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return this.userWantsToOverrideDefaultSchema(); - } - - return super.isPropertyEnabled(propertyName); - } - - - // ********** defaults ********** - - @Override - public Object getDefaultProperty(String propertyName) { - if (propertyName.equals(RUNTIME)) { - return null; - } - if (propertyName.equals(FACET_ID)) { - return JptCorePlugin.FACET_ID; - } - if (propertyName.equals(PLATFORM_ID)) { - return JptCorePlugin.getDefaultJpaPlatformId(); - } - if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { - return this.getDefaultLibraryProvider(); - } - if (propertyName.equals(CONNECTION)) { - return null; - } - if (propertyName.equals(CONNECTION_ACTIVE)) { - return Boolean.valueOf(this.connectionIsActive()); - } - if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { - return Boolean.FALSE; - } - if (propertyName.equals(DB_DRIVER_NAME)) { - return this.getDefaultDriverName(); - } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { - return Boolean.FALSE; - } - if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return this.getDefaultCatalogIdentifier(); - } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - return Boolean.FALSE; - } - if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return this.getDefaultSchemaIdentifier(); - } - if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { - return Boolean.valueOf(this.runtimeSupportsEjb30()); - } - if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { - return Boolean.valueOf( ! this.discoverAnnotatedClasses()); - } - if (propertyName.equals(CREATE_ORM_XML)) { - return Boolean.TRUE; - } - - return super.getDefaultProperty(propertyName); - } - - private LibraryInstallDelegate getDefaultLibraryProvider() { - // delegate itself changes, not the instance of delegate - if (this.defaultLibraryProvider == null) { - this.defaultLibraryProvider = this.buildDefaultLibraryProvider(); - } - return defaultLibraryProvider; - } - - private LibraryInstallDelegate buildDefaultLibraryProvider() { - IFacetedProjectWorkingCopy fpjwc = this.getFacetedProjectWorkingCopy(); - if (fpjwc == null) { - return null; - } - IProjectFacetVersion pfv = this.getProjectFacetVersion(); - if (pfv == null) { - return null; - } - LibraryInstallDelegate lp = new LibraryInstallDelegate(fpjwc, pfv, this.buildEnablementVariables()); - lp.addListener(this.buildLibraryProviderListener()); - return lp; - } - - private Map<String, Object> buildEnablementVariables() { - Map<String, Object> enablementVariables = new HashMap<String, Object>(); - enablementVariables.put(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, this.getPlatformId()); - return enablementVariables; - } - - private IPropertyChangeListener buildLibraryProviderListener() { - return new IPropertyChangeListener() { - public void propertyChanged(String property, Object oldValue, Object newValue ) { - JpaFacetDataModelProvider.this.getDataModel().notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG); - } - }; - } - - private String getDefaultDriverName() { - ConnectionProfile cp = this.getConnectionProfile(); - return (cp == null) ? null : cp.getDriverName(); - } - - private String getDefaultCatalogIdentifier() { - Database db = this.getDatabase(); - return (db == null) ? null : db.getDefaultCatalogIdentifier(); - } - - private String getDefaultSchemaIdentifier() { - SchemaContainer sc = this.getSchemaContainer(); - return (sc == null) ? null : sc.getDefaultSchemaIdentifier(); - } - - private boolean runtimeSupportsEjb30() { - IRuntime runtime = this.getRuntime(); - return (runtime != null) && runtime.supports(this.getEJB30()); - } - - private IProjectFacetVersion getEJB30() { - return ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ - } - - - // ********** synchronize data model ********** - - /** - * The specified property's value has changed to the specified value. - * Return whether to fire a VALUE_CHG DataModelEvent. - */ - @Override - public boolean propertySet(String propertyName, Object propertyValue) { - boolean ok = super.propertySet(propertyName, propertyValue); - - if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) { - //no-op - } - else if (propertyName.equals(FACET_VERSION)) { - this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG); - } - else if (propertyName.equals(RUNTIME)) { - LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); - if (lid != null) { - // may be null while model is being built up - // ... or in tests - lid.refresh(); - } - this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); - } - else if (propertyName.equals(PLATFORM_ID)) { - LibraryInstallDelegate lid = this.getLibraryInstallDelegate(); - if (lid != null) { - // may be null while model is being built up - // ... or in tests - lid.setEnablementContextVariable(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, propertyValue); - } - } - else if (propertyName.equals(CONNECTION)) { - this.setBooleanProperty(CONNECTION_ACTIVE, this.connectionIsActive()); - - // JpaFacetWizardPage sets the connection when the user adds a new connection - // implying that there is a new set of valid connections to choose from - this.model.notifyPropertyChange(CONNECTION, IDataModel.VALID_VALUES_CHG); - - // db driver - if (propertyValue == null) { // connection set to '<None>' - this.setBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, false); - } - this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG); - this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG); - - // catalog - if ((propertyValue != null) && this.databaseSupportsCatalogs()) { // connection set to something that supports catalogs - this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, this.getDefaultCatalogIdentifier()); - } else { // connection either '<None>' or non-catalog database - this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); - } - this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); - - // schema - if (propertyValue == null) { // connection set to '<None>' - this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); - } else { - this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, this.getDefaultSchemaIdentifier()); - } - this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); - } - else if (propertyName.equals(CONNECTION_ACTIVE)) { - // catalog - if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive - this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false); - } - this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG); - - // schema - if (this.propertyValueIsFalse(propertyValue)) { // connection is inactive - this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false); - } - this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); - } - else if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { - this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG); - if (this.propertyValueIsFalse(propertyValue)) { - this.setProperty(DB_DRIVER_NAME, null); - } - } - else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG); - if (this.propertyValueIsFalse(propertyValue)) { - this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null); - } - } - else if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, this.getDefaultSchemaIdentifier()); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); - } - else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); - if (this.propertyValueIsFalse(propertyValue)) { - this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); - } - } - else if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { - this.setBooleanProperty(LIST_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); - } - else if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { - this.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue)); - } - return ok; - } - - private boolean propertyValueIsFalse(Object propertyValue) { - return ! this.propertyValueIsTrue(propertyValue); - } - - private boolean propertyValueIsTrue(Object propertyValue) { - return ((Boolean) propertyValue).booleanValue(); - } - - - // ********** property descriptors ********** - - @Override - public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { - if (propertyName.equals(PLATFORM_ID)) { - return this.buildValidPlatformDescriptors(); - } - - if (propertyName.equals(CONNECTION)) { - return this.buildValidConnectionDescriptors(); - } - - if (propertyName.equals(DB_DRIVER_NAME)) { - return this.buildValidDriverDescriptors(); - } - - if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return this.buildValidCatalogDescriptors(); - } - - if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return this.buildValidSchemaDescriptors(); - } - - return super.getValidPropertyDescriptors(propertyName); - } - - private DataModelPropertyDescriptor[] buildValidPlatformDescriptors() { - List<String> platformIDs = CollectionTools.list(JpaPlatformRegistry.instance().jpaPlatformIds()); - DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[platformIDs.size()]; - for (int i = 0; i < descriptors.length; i++) { - descriptors[i] = this.buildPlatformIdDescriptor(platformIDs.get(i)); - } - return ArrayTools.sort(descriptors, this.buildDescriptorComparator()); - } - - /** - * sort the descriptors by 'description' (as opposed to 'value') - */ - private Comparator<DataModelPropertyDescriptor> buildDescriptorComparator() { - return new Comparator<DataModelPropertyDescriptor>() { - public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) { - return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription())); - } - }; - } - - private DataModelPropertyDescriptor[] buildValidConnectionDescriptors() { - List<String> connectionNames = this.buildValidConnectionNames(); - DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[connectionNames.size()]; - for (int i = 0; i < descriptors.length; i++) { - descriptors[i] = this.buildConnectionDescriptor(connectionNames.get(i)); - } - return descriptors; - } - - /** - * put a null entry at the top of the list (for <none>) - */ - private List<String> buildValidConnectionNames() { - List<String> connectionNames = CollectionTools.sort(CollectionTools.list(this.connectionProfileNames())); - connectionNames.add(0, null); - return connectionNames; - } - - private DataModelPropertyDescriptor[] buildValidDriverDescriptors() { - return new DataModelPropertyDescriptor[] { new DataModelPropertyDescriptor(this.getDriverName()) }; - } - - private DataModelPropertyDescriptor[] buildValidCatalogDescriptors() { - Database db = this.getDatabase(); - return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidCatalogIdentifiers(db)); - } - - /** - * pre-condition: 'db' is not null - */ - private List<String> buildValidCatalogIdentifiers(Database db) { - // use catalog *identifiers* since the string ends up being the "default" for various text entries - return this.buildValidStrings(db.sortedCatalogIdentifiers(), this.getDefaultCatalogIdentifier()); - } - - private DataModelPropertyDescriptor[] buildValidSchemaDescriptors() { - Database db = this.getDatabase(); - return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidSchemaIdentifiers()); - } - - private List<String> buildValidSchemaIdentifiers() { - return this.buildValidStrings(this.schemaIdentifiers(), this.getDefaultSchemaIdentifier()); - } - - private Iterator<String> schemaIdentifiers() { - SchemaContainer sc = this.getSchemaContainer(); - // use schema *identifiers* since the string ends up being the "default" for various text entries - return (sc != null) ? sc.sortedSchemaIdentifiers() : EmptyIterator.<String>instance(); - } - - /** - * put an entry for the default at the top of the list - */ - private List<String> buildValidStrings(Iterator<String> stream, String defaultString) { - List<String> strings = CollectionTools.list(stream); - if ((defaultString != null) && ! strings.contains(defaultString)) { - strings.add(0, defaultString); - } - return strings; - } - - private DataModelPropertyDescriptor[] buildDescriptors(List<String> strings) { - DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[strings.size()]; - for (int i = 0; i < descriptors.length; i++) { - descriptors[i] = new DataModelPropertyDescriptor(strings.get(i)); - } - return descriptors; - } - - private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; - - /** - * platform and connection have 'description's (in addition to 'value's) - */ - @Override - public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { - if (propertyName.equals(PLATFORM_ID)) { - return this.buildPlatformIdDescriptor(this.getPlatformId()); - } - if (propertyName.equals(CONNECTION)) { - return this.buildConnectionDescriptor(this.getConnectionName()); - } - return super.getPropertyDescriptor(propertyName); - } - - DataModelPropertyDescriptor buildPlatformIdDescriptor(String platformId) { - return new DataModelPropertyDescriptor(platformId, this.getPlatformLabel(platformId)); - } - - private String getPlatformLabel(String platformId) { - return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId); - } - - private DataModelPropertyDescriptor buildConnectionDescriptor(String connectionName) { - String description = (connectionName == null) ? JptCoreMessages.NONE : null; - return new DataModelPropertyDescriptor(connectionName, description); - } - - - // ********** database ********** - - private SchemaContainer getSchemaContainer() { - return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase(); - } - - private Catalog getCatalog() { - String name = this.getUserOverrideDefaultCatalog(); - return (name == null) ? null : this.getCatalog(name); - } - - /** - * pre-condition: 'name' is not null - */ - private Catalog getCatalog(String name) { - Database db = this.getDatabase(); - return (db == null) ? null : db.getCatalogForIdentifier(name); - } - - private boolean databaseSupportsCatalogs() { - Database db = this.getDatabase(); - return (db != null) && db.supportsCatalogs(); - } - - private Database getDatabase() { - ConnectionProfile cp = this.getConnectionProfile(); - return (cp == null) ? null : cp.getDatabase(); - } - - private boolean connectionIsActive() { - ConnectionProfile cp = this.getConnectionProfile(); - return (cp != null) && cp.isActive(); - } - - private ConnectionProfile getConnectionProfile() { - String name = this.getConnectionName(); - return (name == null) ? null : this.getConnectionProfile(name); - } - - /** - * pre-condition: 'name' is not null - */ - private ConnectionProfile getConnectionProfile(String name) { - if (this.cachedConnectionProfileIsStale(name)) { - this.connectionProfile = this.buildConnectionProfile(name); - } - return this.connectionProfile; - } - - private boolean cachedConnectionProfileIsStale(String name) { - return (this.connectionProfile == null) || ! this.connectionProfile.getName().equals(name); - } - - private ConnectionProfile buildConnectionProfile(String name) { - return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance()); - } - - private Iterator<String> connectionProfileNames() { - return this.getConnectionProfileFactory().connectionProfileNames(); - } - - private ConnectionProfileFactory getConnectionProfileFactory() { - // we don't have a JPA project yet, so go to the db plug-in directly to get the factory - return JptDbPlugin.instance().getConnectionProfileFactory(); - } - - - // ********** validation ********** - - @Override - public IStatus validate(String propertyName) { - if (propertyName.equals(PLATFORM_ID)) { - return this.validatePlatformId(); - } - if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) { - return this.getLibraryInstallDelegate().validate(); - } - if (propertyName.equals(CONNECTION)) { - return this.validateConnection(); - } - if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH) - || propertyName.equals(DB_DRIVER_NAME)) { - return this.validateDbDriverName(); - } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG) - || propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) { - return this.validateUserOverrideDefaultCatalog(); - } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) - || propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return this.validateUserOverrideDefaultSchema(); - } - if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { - return this.validatePersistentClassManagement(); - } - - return super.validate(propertyName); - } - - private IStatus validatePlatformId() { - return (this.getPlatformId() == null) ? PLATFORM_NOT_SPECIFIED_STATUS : OK_STATUS; - } - - private IStatus validateConnection() { - String connectionName = this.getConnectionName(); - return (connectionName == null) ? OK_STATUS : this.validateNonNullConnection(connectionName); - } - - private IStatus validateNonNullConnection(String connectionName) { - ConnectionProfile cp = this.getConnectionProfile(connectionName); - if (cp == null) { - return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName)); - } - if ( ! cp.isActive()) { - return CONNECTION_NOT_CONNECTED_STATUS; - } - return OK_STATUS; - } - - private IStatus validateDbDriverName() { - return OK_STATUS; - } - - private IStatus validateUserOverrideDefaultCatalog() { - if (this.userWantsToOverrideDefaultCatalog()) { - if (this.getUserOverrideDefaultCatalog() == null) { - return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS; - } - } - return OK_STATUS; - } - - private IStatus validateUserOverrideDefaultSchema() { - if (this.userWantsToOverrideDefaultSchema()) { - if (this.getUserOverrideDefaultSchema() == null) { - return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; - } - } - return OK_STATUS; - } - - private IStatus validatePersistentClassManagement() { - // TODO warning if "discovery" is used, but no runtime specified ?? - // boolean discoverAnnotatedClasses = this.discoverAnnotatedClasses(); - return OK_STATUS; - } - - - // ********** static methods ********** - - private static IStatus buildInfoStatus(String message) { - return buildStatus(IStatus.INFO, message); - } - -// private static IStatus buildWarningStatus(String message) { -// return buildStatus(IStatus.WARNING, message); -// } - - private static IStatus buildErrorStatus(String message) { - return buildStatus(IStatus.ERROR, message); - } - - private static IStatus buildStatus(int severity, String message) { - return new Status(severity, JptCorePlugin.PLUGIN_ID, message); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java deleted file mode 100644 index f3d56c1637..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.facet; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.IClasspathContainer; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IDelegate; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - -/** - * We don't really "install" the JPA facet here. We simply store all the various - * data model properties in the appropriate preferences. These settings will - * used in the POST_INSTALL event listener to build the JPA project. - */ -public class JpaFacetInstallDelegate - implements IDelegate, JpaFacetDataModelProperties -{ - - public void execute(IProject project, IProjectFacetVersion fv, - Object config, IProgressMonitor monitor) throws CoreException { - monitor = this.nonNullMonitor(monitor); - try { - this.execute_(project, fv, config, monitor); - } finally { - monitor.done(); - } - } - - private void execute_(IProject project, @SuppressWarnings("unused") IProjectFacetVersion fv, - Object config, IProgressMonitor monitor) throws CoreException { - - monitor.beginTask("", 1); //$NON-NLS-1$ - - // NB: WTP Natures (including the JavaEMFNature) - // should already be added, as this facet should - // always coexist with a module facet. - - IJavaProject javaProject = JavaCore.create(project); - IDataModel dataModel = (IDataModel) config; - - // project settings - JptCorePlugin.setJpaPlatformId(project, dataModel.getStringProperty(PLATFORM_ID)); - JptCorePlugin.setConnectionProfileName(project, dataModel.getStringProperty(CONNECTION)); - if (dataModel.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) { - JptCorePlugin.setUserOverrideDefaultCatalog(project, dataModel.getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG)); - } - if (dataModel.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - JptCorePlugin.setUserOverrideDefaultSchema(project, dataModel.getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA)); - } - - this.addDbDriverLibraryToClasspath(javaProject, dataModel, monitor); - - JptCorePlugin.setDiscoverAnnotatedClasses(project, dataModel.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES)); - - // defaults settings - JptCorePlugin.setDefaultJpaPlatformId(dataModel.getStringProperty(PLATFORM_ID)); - - //Delegate to LibraryInstallDelegate to configure the project classpath - ((LibraryInstallDelegate) dataModel.getProperty(JpaFacetDataModelProperties.LIBRARY_PROVIDER_DELEGATE)).execute(new NullProgressMonitor()); - - monitor.worked(1); - } - - private void addDbDriverLibraryToClasspath(IJavaProject javaProject, IDataModel dataModel, IProgressMonitor monitor) throws CoreException { - if( ! dataModel.getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) { - return; - } - String driverName = dataModel.getStringProperty(DB_DRIVER_NAME); - - IClasspathContainer container = JptDbPlugin.instance().buildDriverClasspathContainerFor(driverName); - IClasspathEntry entry = JavaCore.newContainerEntry(container.getPath()); - this.addClasspathEntryToProject(entry, javaProject, monitor); - } - - private void addClasspathEntryToProject(IClasspathEntry classpathEntry, IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { - - // if the classpathEntry is already there, do nothing - IClasspathEntry[] classpath = javaProject.getRawClasspath(); - if (ArrayTools.contains(classpath, classpathEntry)) { - return; - } - - // add the given classpathEntry to the project classpath - int len = classpath.length; - IClasspathEntry[] newClasspath = new IClasspathEntry[len + 1]; - System.arraycopy(classpath, 0, newClasspath, 0, len); - newClasspath[len] = classpathEntry; - javaProject.setRawClasspath(newClasspath, monitor); - } - - private IProgressMonitor nonNullMonitor(IProgressMonitor monitor) { - return (monitor != null) ? monitor : new NullProgressMonitor(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUninstallDelegate.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUninstallDelegate.java deleted file mode 100644 index acdfa2dff5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetUninstallDelegate.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 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.facet; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.wst.common.project.facet.core.IDelegate; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - -public class JpaFacetUninstallDelegate - implements IDelegate -{ - public void execute(IProject project, IProjectFacetVersion fv, - Object config, IProgressMonitor monitor) throws CoreException { - - // There is nothing to do here. Everything is taken care of by the - // JpaModelManager *whenever* the facet is removed (even via meta-file - // editing and CVS updating), but this delegate needs to be here because - // it is required by the facet extension point action element, and that - // is required by the facet UI to allow uninstallation of this facet. - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaLibraryProviderConstants.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaLibraryProviderConstants.java deleted file mode 100644 index 626ae91738..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaLibraryProviderConstants.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.facet; - -public interface JpaLibraryProviderConstants -{ - public static final String EXPR_VAR_JPA_PLATFORM - = "jpaPlatform"; //$NON-NLS-1$ -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/LegacyJpaLibraryProviderDetector.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/LegacyJpaLibraryProviderDetector.java deleted file mode 100644 index 3c3bef9618..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/LegacyJpaLibraryProviderDetector.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.facet; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider; -import org.eclipse.jst.common.project.facet.core.libprov.LegacyLibraryProviderDetector; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework; -import org.eclipse.wst.common.project.facet.core.IProjectFacet; - -public class LegacyJpaLibraryProviderDetector - extends LegacyLibraryProviderDetector -{ - public static final String LEGACY_JPA_LIBRARY_PROVIDER_ID - = "jpa-legacy-library-provider"; //$NON-NLS-1$ - - - @Override - public ILibraryProvider detect( - final IProject project, final IProjectFacet facet) { - if (facet.getId().equals(JptCorePlugin.FACET_ID)) { - return LibraryProviderFramework.getProvider(LEGACY_JPA_LIBRARY_PROVIDER_ID); - } - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/LegacyJpaLibraryProviderInstallOperation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/LegacyJpaLibraryProviderInstallOperation.java deleted file mode 100644 index 2b286e642d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/LegacyJpaLibraryProviderInstallOperation.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.facet; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperation; -import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig; - -public class LegacyJpaLibraryProviderInstallOperation - extends LibraryProviderOperation -{ - @Override - public void execute( - LibraryProviderOperationConfig config, IProgressMonitor monitor) - throws CoreException { - // no op - nothing to uninstall - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaDataSource.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaDataSource.java deleted file mode 100644 index 6629a9c028..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaDataSource.java +++ /dev/null @@ -1,227 +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.jpa1; - -import org.eclipse.jpt.core.JpaDataSource; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.AbstractJpaNode; -import org.eclipse.jpt.db.ConnectionAdapter; -import org.eclipse.jpt.db.ConnectionListener; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.ConnectionProfileListener; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.DatabaseObject; - -/** - * GenericJpaDataSource - */ -public class GenericJpaDataSource - extends AbstractJpaNode - implements JpaDataSource -{ - /** - * cache the connection profile name so we can detect when - * it changes and notify listeners - */ - protected String connectionProfileName; - - protected transient ConnectionProfile connectionProfile; - - /** - * listen for the connection to be added or removed or its name changed - */ - protected final ConnectionProfileListener connectionProfileListener; - - /** - * listen for the connection to be opened or closed - */ - protected final ConnectionListener connectionListener; - - private static final long serialVersionUID = 1L; - - - // ********** constructor/initialization ********** - - public GenericJpaDataSource(JpaProject jpaProject, String connectionProfileName) { - super(jpaProject); - //moving the building of the connection profile before the connectionProfileListener - //is added. Need to make sure the loading of db profiles is completed before - //listening, otherwise we get notifications before our model is finished being built. - //this means our updater is called before it is set which results in an IllegalStateException. - //Hopefully this change is temporary and DTP will fix bug 246270 where I suggest they - //not fire events when building profiles. - this.connectionProfileName = connectionProfileName; - this.connectionProfile = this.buildConnectionProfile(connectionProfileName); - - this.connectionProfileListener = this.buildConnectionProfileListener(); - this.getConnectionProfileFactory().addConnectionProfileListener(this.connectionProfileListener); - - this.connectionListener = this.buildConnectionListener(); - if (this.connectionProfile != null) { - this.connectionProfile.addConnectionListener(this.connectionListener); - } - } - - protected ConnectionProfileFactory getConnectionProfileFactory() { - return this.getJpaPlatform().getConnectionProfileFactory(); - } - - protected ConnectionProfileListener buildConnectionProfileListener() { - return new LocalConnectionProfileListener(); - } - - protected ConnectionListener buildConnectionListener() { - return new LocalConnectionListener(); - } - - - // ********** JpaDataSource implementation ********** - - public String getConnectionProfileName() { - return this.connectionProfileName; - } - - public void setConnectionProfileName(String connectionProfileName) { - String old = this.connectionProfileName; - this.connectionProfileName = connectionProfileName; - if (this.attributeValueHasChanged(old, connectionProfileName)) { - this.firePropertyChanged(CONNECTION_PROFILE_NAME_PROPERTY, old, connectionProfileName); - // synch the connection profile when the name changes - this.setConnectionProfile(this.buildConnectionProfile(connectionProfileName)); - JptCorePlugin.setConnectionProfileName(getJpaProject().getProject(), connectionProfileName); - } - } - - public ConnectionProfile getConnectionProfile() { - return this.connectionProfile; - } - - @Override - public boolean connectionProfileIsActive() { - ConnectionProfile cp = this.connectionProfile; - return (cp != null) && cp.isActive(); - } - - @Override - public Database getDatabase() { - ConnectionProfile cp = this.connectionProfile; - return (cp == null) ? null : cp.getDatabase(); - } - - public <T extends DatabaseObject> T selectDatabaseObjectForIdentifier(T[] databaseObjects, String identifier) { - Database db = this.getDatabase(); - return (db == null) ? null : db.selectDatabaseObjectForIdentifier(databaseObjects, identifier); - } - - public void dispose() { - if (this.connectionProfile != null) { - this.connectionProfile.removeConnectionListener(this.connectionListener); - } - this.getConnectionProfileFactory().removeConnectionProfileListener(this.connectionProfileListener); - } - - - // ********** internal methods ********** - - protected ConnectionProfile buildConnectionProfile(String name) { - return this.getConnectionProfileFactory().buildConnectionProfile(name, this.getJpaPlatform().getDatabaseFinder()); - } - - protected void setConnectionProfile(ConnectionProfile connectionProfile) { - ConnectionProfile old = this.connectionProfile; - if (old != null) { - old.removeConnectionListener(this.connectionListener); - } - this.connectionProfile = connectionProfile; - if (connectionProfile != null) { - connectionProfile.addConnectionListener(this.connectionListener); - } - this.firePropertyChanged(CONNECTION_PROFILE_PROPERTY, old, connectionProfile); - } - - - // ********** overrides ********** - - @Override - public void toString(StringBuilder sb) { - sb.append(this.connectionProfileName); - } - - - // ********** member classes ********** - - /** - * Listen for a connection profile with our name being removed. - * Also listen for our connection's name being changed. - */ - protected class LocalConnectionProfileListener implements ConnectionProfileListener { - - protected LocalConnectionProfileListener() { - super(); - } - - public void connectionProfileAdded(String name) { - // check to see if a connection profile with our name was added - // (assume our connection profile is null) - if (GenericJpaDataSource.this.connectionProfile == null) { - if (name.equals(GenericJpaDataSource.this.getConnectionProfileName())) { - GenericJpaDataSource.this.setConnectionProfileName(name); // this will trigger creation of CP - } - } - } - - public void connectionProfileRemoved(String name) { - if (GenericJpaDataSource.this.connectionProfile == null) { - return; - } - if (name.equals(GenericJpaDataSource.this.connectionProfile.getName())) { - GenericJpaDataSource.this.setConnectionProfile(null); - } - } - - public void connectionProfileRenamed(String oldName, String newName) { - if (GenericJpaDataSource.this.connectionProfile == null) { - if (newName.equals(GenericJpaDataSource.this.connectionProfileName)) { - GenericJpaDataSource.this.setConnectionProfileName(newName); - } - return; - } - // the connection profile will already have the new name, - // we just need to synch the name held by the data source - if (newName.equals(GenericJpaDataSource.this.connectionProfile.getName())) { - GenericJpaDataSource.this.setConnectionProfileName(newName); - // bug 232225 - also update project setting when connection profile - // name has changed - JptCorePlugin.setConnectionProfileName(getJpaProject().getProject(), newName); - } - } - } - - - /** - * Whenever the connection is opened or closed trigger a project update. - */ - protected class LocalConnectionListener extends ConnectionAdapter { - - @Override - public void opened(ConnectionProfile profile) { - GenericJpaDataSource.this.getJpaProject().update(); - } - - @Override - public void closed(ConnectionProfile profile) { - GenericJpaDataSource.this.getJpaProject().update(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaFactory.java deleted file mode 100644 index 65c0f5237c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaFactory.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1; - -import org.eclipse.jpt.core.internal.AbstractJpaFactory; - -/** - * Generic JPA - */ -public class GenericJpaFactory - extends AbstractJpaFactory -{ - public GenericJpaFactory() { - super(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaFile.java deleted file mode 100644 index c1651bc2ac..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaFile.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModel; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.internal.AbstractJpaNode; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; - -/** - * The transition between a JPA project and the resource model associated - * with a file. - * Hold the associated root structure nodes, which are hooks to the - * context model. - */ -public class GenericJpaFile - extends AbstractJpaNode - implements JpaFile -{ - /** - * typically a .java or .xml file. - */ - protected final IFile file; - - /** - * cache the content type - */ - protected final IContentType contentType; - - /** - * the resource model corresponding to the file - */ - protected final JpaResourceModel resourceModel; - - /** - * the root structure (context model) nodes corresponding to the resource - * model - */ - protected final Hashtable<Object, JpaStructureNode> rootStructureNodes; - - - // ********** construction ********** - - public GenericJpaFile(JpaProject jpaProject, IFile file, IContentType contentType, JpaResourceModel resourceModel) { - super(jpaProject); - this.file = file; - this.contentType = contentType; - this.resourceModel = resourceModel; - this.rootStructureNodes = new Hashtable<Object, JpaStructureNode>(); - } - - /** - * Changes to ROOT_STRUCTURE_NODES_COLLECTION do not need to trigger a - * project update. Only the UI cares about the root structure nodes. - * If a project update is allowed to happen, an infinite loop will result - * if any java class is specified in more than one location in the - * persistence unit. - */ - @Override - protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) { - super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - nonUpdateAspectNames.add(ROOT_STRUCTURE_NODES_COLLECTION); - } - - - // ********** file ********** - - public IFile getFile() { - return this.file; - } - - public IContentType getContentType() { - return this.contentType; - } - - public JpaResourceModel getResourceModel() { - return this.resourceModel; - } - - public JpaResourceModel getResourceModel(IContentType ct) { - return this.contentType.isKindOf(ct) ? this.resourceModel : null; - } - - - // ********** root structure nodes ********** - - public Iterator<JpaStructureNode> rootStructureNodes() { - return this.getRootStructureNodes().iterator(); - } - - protected Iterable<JpaStructureNode> getRootStructureNodes() { - return new LiveCloneIterable<JpaStructureNode>(this.rootStructureNodes.values()); - } - - public int rootStructureNodesSize() { - return this.rootStructureNodes.size(); - } - - public void addRootStructureNode(Object key, JpaStructureNode rootStructureNode) { - JpaStructureNode old = this.rootStructureNodes.put(key, rootStructureNode); - if (rootStructureNode != old) { - if (old != null) { - this.fireItemRemoved(ROOT_STRUCTURE_NODES_COLLECTION, old); - } - this.fireItemAdded(ROOT_STRUCTURE_NODES_COLLECTION, rootStructureNode); - } - } - - public void removeRootStructureNode(Object key) { - this.fireItemRemoved(ROOT_STRUCTURE_NODES_COLLECTION, this.rootStructureNodes.remove(key)); - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (JpaStructureNode rootNode : this.getRootStructureNodes()) { - JpaStructureNode node = rootNode.getStructureNode(textOffset); - if (node != null) { - return node; - } - } - return null; - } - - - // ********** misc ********** - - @Override - public void toString(StringBuilder sb) { - sb.append(this.file); - sb.append('['); - sb.append(this.contentType.getName()); - sb.append(']'); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaProject.java deleted file mode 100644 index f4c7a20cda..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/GenericJpaProject.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.internal.AbstractJpaProject; - -/** - * Not much different from the abstract JPA project. - */ -public class GenericJpaProject - extends AbstractJpaProject -{ - - // ********** constructor/initialization ********** - - public GenericJpaProject(JpaProject.Config config) throws CoreException { - super(config); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java deleted file mode 100644 index 65999987f4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericRootContextNode.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context; - -import java.util.List; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.MappingFileRoot; -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.context.AbstractJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.JpaRootContextNode2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceXml2_0; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericRootContextNode - extends AbstractJpaContextNode - implements JpaRootContextNode2_0 -{ - /* This object has no parent, so it must point to the JPA project explicitly. */ - protected final JpaProject jpaProject; - - /* Main context object. */ - protected PersistenceXml persistenceXml; - - - public GenericRootContextNode(JpaProject jpaProject) { - super(null); - if (jpaProject == null) { - throw new NullPointerException(); - } - this.jpaProject = jpaProject; - JpaXmlResource resource = getPersistenceXmlResource(); - if (resource != null) { - this.persistenceXml = buildPersistenceXml(resource); - } - } - - - @Override - protected boolean requiresParent() { - return false; - } - - - // **************** JpaNode impl ******************************************* - - @Override - public JpaProject getJpaProject() { - return this.jpaProject; - } - - @Override - public IResource getResource() { - return this.getProject(); - } - - protected IProject getProject() { - return this.jpaProject.getProject(); - } - - - // **************** JpaContextNode impl ************************************ - - @Override - public PersistenceUnit getPersistenceUnit() { - // No PersistenceUnit in this context - return null; - } - - @Override - public MappingFileRoot getMappingFileRoot() { - // No MappingFileRoot 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); - } - - // **************** 2.0 static metamodel **************** - - public void synchronizeStaticMetamodel() { - PersistenceXml2_0 p_xml = (PersistenceXml2_0) this.getPersistenceXml(); - if (p_xml != null) { - p_xml.synchronizeStaticMetamodel(); - } - } - - // **************** updating *********************************************** - - public void update(IProgressMonitor monitor) { - JpaXmlResource resource = getPersistenceXmlResource(); - - if (resource != null) { - if (this.persistenceXml == null) { - this.setPersistenceXml(this.buildPersistenceXml(resource)); - } else { - this.persistenceXml.update(resource); - } - } else { - this.setPersistenceXml(null); - } - } - - @Override - public void postUpdate() { - super.postUpdate(); - if (this.persistenceXml != null) { - this.persistenceXml.postUpdate(); - } - } - - protected JpaXmlResource getPersistenceXmlResource() { - return this.jpaProject.getPersistenceXmlResource(); - } - - protected PersistenceXml buildPersistenceXml(JpaXmlResource resource) { - return this.getJpaFactory().buildPersistenceXml(this, resource); - } - - - // **************** Validation ********************************************* - - public void validate(List<IMessage> messages, IReporter reporter) { - if (reporter.isCancelled()) { - throw new ValidationCancelledException(); - } - - if (this.persistenceXml == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - this.buildMissingFileMessageID(), - this - ) - ); - return; - } - if ( ! this.jpaProject.discoversAnnotatedClasses()) { - this.validateOrphanClasses(messages); - } - this.persistenceXml.validate(messages, reporter); - } - - protected String buildMissingFileMessageID() { - return this.getPlatformFile().exists() ? - JpaValidationMessages.PERSISTENCE_XML_INVALID_CONTENT - : - JpaValidationMessages.PROJECT_NO_PERSISTENCE_XML; - } - - protected IFile getPlatformFile() { - return this.jpaProject.convertToPlatformFile(JptCorePlugin.DEFAULT_PERSISTENCE_XML_FILE_PATH); - } - - protected void validateOrphanClasses(List<IMessage> messages) { - Persistence persistence = this.persistenceXml.getPersistence(); - if (persistence == null) { - return; // handled with other validation - } - if (persistence.persistenceUnitsSize() != 1) { - return; // the context model currently only supports 1 persistence unit - } - - PersistenceUnit persistenceUnit = persistence.persistenceUnits().next(); - HashBag<String> annotatedClassNames = CollectionTools.bag(this.jpaProject.annotatedJavaSourceClassNames()); - HashBag<String> orphans = annotatedClassNames.clone(); - for (String annotatedClassName : annotatedClassNames) { - if (persistenceUnit.specifiesPersistentType(annotatedClassName)) { - orphans.remove(annotatedClassName); - } - } - - // TODO remove 'jrcu' - // replace jrcu.getFile() with jrpt.getFile() - // replace jrpt.getMappingAnnotation().getTextRange(jrcu.buildASTRoot()) - // with jrpt.getMappingAnnotation().getTextRange() - // (new method #getTextRange() ?) - for (String orphan : orphans) { - JavaResourcePersistentType jrpt = this.jpaProject.getJavaResourcePersistentType(orphan); - JavaResourceCompilationUnit jrcu = jrpt.getJavaResourceCompilationUnit(); - if (jrpt.isMapped()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_MAPPED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT, - new String[] {jrpt.getName()}, - jrcu.getFile(), - jrpt.getNameTextRange(jrcu.buildASTRoot()) - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_ANNOTATED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT, - new String[] {jrpt.getName()}, - jrcu.getFile(), - jrpt.getNameTextRange(jrcu.buildASTRoot()) - ) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java deleted file mode 100644 index c0028bdf62..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.content.IContentType; -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.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.JarFileRef; -import org.eclipse.jpt.core.internal.context.AbstractJpaContextNode; -import org.eclipse.jpt.core.jpa2.context.java.JarFile2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentType2_0; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * Context JAR file - */ -public class GenericJarFile - extends AbstractJpaContextNode - implements JarFile2_0, PersistentType.Owner -{ - protected JavaResourcePackageFragmentRoot jarResourcePackageFragmentRoot; - protected final Vector<JavaPersistentType> javaPersistentTypes = new Vector<JavaPersistentType>(); - - - // ********** constructor/initialization ********** - - public GenericJarFile(JarFileRef parent, JavaResourcePackageFragmentRoot jarResourcePackageFragmentRoot) { - super(parent); - this.jarResourcePackageFragmentRoot = jarResourcePackageFragmentRoot; - CollectionTools.addAll(this.javaPersistentTypes, this.buildJavaPersistentTypes()); - } - - protected Iterator<JavaPersistentType> buildJavaPersistentTypes() { - return new TransformationIterator<JavaResourcePersistentType, JavaPersistentType>(this.javaResourcePersistentTypes()) { - @Override - protected JavaPersistentType transform(JavaResourcePersistentType jrpt) { - return GenericJarFile.this.buildJavaPersistentType(jrpt); - } - }; - } - - /** - * the resource JAR holds only annotated types, so we can use them all for - * building the context types - */ - protected Iterator<JavaResourcePersistentType> javaResourcePersistentTypes() { - return this.jarResourcePackageFragmentRoot.persistentTypes(); - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourcePersistentType jrpt) { - return this.getJpaFactory().buildJavaPersistentType(this, jrpt); - } - - - // ********** JpaStructureNode implementation ********** - - public String getId() { - return null; - } - - @Override - public IContentType getContentType() { - return JptCorePlugin.JAR_CONTENT_TYPE; - } - - public TextRange getSelectionTextRange() { - return null; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return null; - } - - public void dispose() { - // nothing yet - } - - - // ********** JarFile implementation ********** - - public JavaPersistentType getPersistentType(String typeName) { - for (JavaPersistentType pt : this.getJavaPersistentTypes()) { - if (pt.getName().equals(typeName)) { - return pt; - } - } - return null; - } - - public Iterator<JavaPersistentType> javaPersistentTypes() { - return this.getJavaPersistentTypes().iterator(); - } - - protected Iterable<JavaPersistentType> getJavaPersistentTypes() { - return new LiveCloneIterable<JavaPersistentType>(this.javaPersistentTypes); - } - - public int javaPersistentTypesSize() { - return this.javaPersistentTypes.size(); - } - - protected JavaPersistentType addJavaPersistentType(JavaResourcePersistentType jrpt) { - JavaPersistentType javaPersistentType = this.buildJavaPersistentType(jrpt); - this.addItemToCollection(javaPersistentType, this.javaPersistentTypes, JAVA_PERSISTENT_TYPES_COLLECTION); - return javaPersistentType; - } - - protected void removeJavaPersistentType(JavaPersistentType javaPersistentType ) { - this.removeItemFromCollection(javaPersistentType, this.javaPersistentTypes, JAVA_PERSISTENT_TYPES_COLLECTION); - } - - - // ********** PersistentType.Owner implementation ********** - - public AccessType getDefaultPersistentTypeAccess() { - return this.getPersistenceUnit().getDefaultAccess(); - } - - public AccessType getOverridePersistentTypeAccess() { - // no access type at this level overrides any local access type specification - return null; - } - - - // ********** JpaNode implementation ********** - - @Override - public IResource getResource() { - return this.jarResourcePackageFragmentRoot.getFile(); - } - - - // ********** updating ********** - - public void update(JavaResourcePackageFragmentRoot jrpfr) { - this.jarResourcePackageFragmentRoot = jrpfr; - this.updateJavaPersistentTypes(); - } - - protected void updateJavaPersistentTypes() { - HashBag<JavaPersistentType> contextTypesToRemove = CollectionTools.bag(this.javaPersistentTypes(), this.javaPersistentTypes.size()); - ArrayList<JavaPersistentType> contextTypesToUpdate = new ArrayList<JavaPersistentType>(this.javaPersistentTypes.size()); - - for (Iterator<JavaResourcePersistentType> resourceTypes = this.javaResourcePersistentTypes(); resourceTypes.hasNext(); ) { - JavaResourcePersistentType resourceType = resourceTypes.next(); - boolean match = false; - for (Iterator<JavaPersistentType> contextTypes = contextTypesToRemove.iterator(); contextTypes.hasNext(); ) { - JavaPersistentType contextType = contextTypes.next(); - if (contextType.getResourcePersistentType() == resourceType) { - contextTypes.remove(); - contextTypesToUpdate.add(contextType); - match = true; - break; - } - } - if ( ! match) { - this.addJavaPersistentType(resourceType); - } - } - for (JavaPersistentType contextType : contextTypesToRemove) { - this.removeJavaPersistentType(contextType); - } - // handle adding and removing java persistent types first, update the - // remaining java persistent types last; this reduces the churn during "update" - for (JavaPersistentType contextType : contextTypesToUpdate) { - contextType.update(); - } - } - - - // ********** validation ********** - - public void validate(List<IMessage> messages, IReporter reporter) { - if (reporter.isCancelled()) { - throw new ValidationCancelledException(); - } - // TODO validate 'javaPersistentTypes' - } - - - // ********** 2.0 static metamodel ********** - - public void synchronizeStaticMetamodel() { - for (JavaPersistentType jpt : this.getJavaPersistentTypes()) { - ((JavaPersistentType2_0) jpt).synchronizeStaticMetamodel(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverride.java deleted file mode 100644 index 888e1b7df4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverride.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaOverride; -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.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaAssociationOverride extends AbstractJavaOverride - implements JavaAssociationOverride -{ - - protected final JavaAssociationOverrideRelationshipReference relationshipReference; - - public GenericJavaAssociationOverride(JavaJpaContextNode parent, AssociationOverride.Owner owner) { - super(parent, owner); - this.relationshipReference = buildRelationshipReference(); - } - - public void initializeFrom(AssociationOverride oldAssociationOverride) { - this.setName(oldAssociationOverride.getName()); - this.relationshipReference.initializeFrom(oldAssociationOverride.getRelationshipReference()); - } - - protected JavaAssociationOverrideRelationshipReference buildRelationshipReference() { - return getJpaFactory().buildJavaAssociationOverrideRelationshipReference(this); - } - - public JavaAssociationOverrideRelationshipReference getRelationshipReference() { - return this.relationshipReference; - } - - @Override - public JavaAssociationOverride setVirtual(boolean virtual) { - return (JavaAssociationOverride) super.setVirtual(virtual); - } - - @Override - protected AssociationOverrideAnnotation getOverrideAnnotation() { - return (AssociationOverrideAnnotation) super.getOverrideAnnotation(); - } - - @Override - public AssociationOverride.Owner getOwner() { - return (AssociationOverride.Owner) super.getOwner(); - } - - @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; - } - result = this.relationshipReference.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - public void initialize(AssociationOverrideAnnotation associationOverride) { - super.initialize(associationOverride); - this.relationshipReference.initialize(associationOverride); - } - - public void update(AssociationOverrideAnnotation associationOverride) { - super.update(associationOverride); - this.relationshipReference.update(associationOverride); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.connectionProfileIsActive()) { - this.validateJoinColumns(messages, astRoot); - } - } - - protected void validateJoinColumns(List<IMessage> messages, CompilationUnit astRoot) { - for (Iterator<JavaJoinColumn> stream = this.getRelationshipReference().getJoinColumnJoiningStrategy().joinColumns(); stream.hasNext(); ) { - this.validateJoinColumn(stream.next(), messages, astRoot); - } - } - - protected void validateJoinColumn(JavaJoinColumn joinColumn, List<IMessage> messages, CompilationUnit astRoot) { - String tableName = joinColumn.getTable(); - if (this.getOwner().getTypeMapping().tableNameIsInvalid(tableName)) { - if (this.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {this.getName(), tableName, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot) - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot) - ) - ); - } - return; - } - - if ( ! joinColumn.isResolved()) { - if (this.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {this.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 ( ! joinColumn.isReferencedColumnResolved()) { - if (this.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {this.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) - ) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverrideContainer.java deleted file mode 100644 index 251a31a74a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverrideContainer.java +++ /dev/null @@ -1,383 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -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.CompositeListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaAssociationOverrideContainer extends AbstractJavaJpaContextNode - implements JavaAssociationOverrideContainer -{ - protected JavaResourcePersistentMember javaResourcePersistentMember; - - protected final AssociationOverrideContainer.Owner owner; - - protected final List<JavaAssociationOverride> specifiedAssociationOverrides; - - protected final List<JavaAssociationOverride> virtualAssociationOverrides; - - public GenericJavaAssociationOverrideContainer(JavaJpaContextNode parent, AssociationOverrideContainer.Owner owner) { - super(parent); - this.owner = owner; - this.specifiedAssociationOverrides = new ArrayList<JavaAssociationOverride>(); - this.virtualAssociationOverrides = new ArrayList<JavaAssociationOverride>(); - } - - public Owner getOwner() { - return this.owner; - } - - 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()); - } - - 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; - } - - - @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.javaResourcePersistentMember.addAnnotation( - index, AssociationOverrideAnnotation.ANNOTATION_NAME, - AssociationOverridesAnnotation.ANNOTATION_NAME); - associationOverride.initialize(associationOverrideResource); - this.fireItemAdded(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, SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - protected void addSpecifiedAssociationOverride(JavaAssociationOverride associationOverride) { - this.addSpecifiedAssociationOverride(this.specifiedAssociationOverrides.size(), associationOverride); - } - - protected void removeSpecifiedAssociationOverride_(JavaAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.specifiedAssociationOverrides, SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAssociationOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentMember.moveAnnotation( - targetIndex, sourceIndex, AssociationOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(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 update. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAssociationOverride virtualAssociationOverride = null; - if (associationOverrideName != null) { - for (RelationshipMapping overridableAssociation : CollectionTools.iterable(getOwner().allOverridableAssociations())) { - if (overridableAssociation.getName().equals(associationOverrideName)) { - //store the virtualAttributeOverride so we can fire change notification later - virtualAssociationOverride = buildVirtualAssociationOverride(overridableAssociation); - this.virtualAssociationOverrides.add(virtualAssociationOverride); - break; - } - } - } - - this.javaResourcePersistentMember.removeAnnotation( - index, AssociationOverrideAnnotation.ANNOTATION_NAME, - AssociationOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); - - if (virtualAssociationOverride != null) { - fireItemAdded(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.javaResourcePersistentMember.addAnnotation( - index, AssociationOverrideAnnotation.ANNOTATION_NAME, - AssociationOverridesAnnotation.ANNOTATION_NAME); - newAssociationOverride.initialize(attributeOverrideResource); - - int virtualIndex = this.virtualAssociationOverrides.indexOf(oldAssociationOverride); - this.virtualAssociationOverrides.remove(virtualIndex); - - newAssociationOverride.initializeFrom(oldAssociationOverride); - - this.fireItemRemoved(VIRTUAL_ASSOCIATION_OVERRIDES_LIST, virtualIndex, oldAssociationOverride); - this.fireItemAdded(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, newAssociationOverride); - - return newAssociationOverride; - } - - protected void addVirtualAssociationOverride(JavaAssociationOverride associationOverride) { - addItemToList(associationOverride, this.virtualAssociationOverrides, VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeVirtualAssociationOverride(JavaAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.virtualAssociationOverrides, VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - - - public void initialize(JavaResourcePersistentMember resourcePersistentMember) { - this.javaResourcePersistentMember = resourcePersistentMember; - this.initializeSpecifiedAssociationOverrides(); - this.initializeVirtualAssociationOverrides(); - } - - protected void initializeSpecifiedAssociationOverrides() { - for (Iterator<NestableAnnotation> stream = - this.javaResourcePersistentMember.annotations( - AssociationOverrideAnnotation.ANNOTATION_NAME, - AssociationOverridesAnnotation.ANNOTATION_NAME); - stream.hasNext(); ) { - this.specifiedAssociationOverrides.add( - buildAssociationOverride((AssociationOverrideAnnotation) stream.next())); - } - } - - protected void initializeVirtualAssociationOverrides() { - for (RelationshipMapping overridableAssociation : CollectionTools.iterable(getOwner().allOverridableAssociations())) { - JavaAssociationOverride associationOverride = getAssociationOverrideNamed(overridableAssociation.getName()); - if (associationOverride == null) { - this.virtualAssociationOverrides.add(buildVirtualAssociationOverride(overridableAssociation)); - } - } - } - - public void update(JavaResourcePersistentMember resourcePersistentMember) { - this.javaResourcePersistentMember = resourcePersistentMember; - this.updateSpecifiedAssociationOverrides(); - } - - @Override - public void postUpdate() { - super.postUpdate(); - - //In postUpdate because the joiningStrategy is not initialized on relationship mappings. - //if we fix the issue that we do not initialize java mappings, but they instead get initialized - //during the first update, then we can probably move this. - updateVirtualAssociationOverrides(); - } - - - protected void updateSpecifiedAssociationOverrides() { - ListIterator<JavaAssociationOverride> associationOverrides = specifiedAssociationOverrides(); - Iterator<NestableAnnotation> resourceAssociationOverrides = - this.javaResourcePersistentMember.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(buildAssociationOverride((AssociationOverrideAnnotation) resourceAssociationOverrides.next())); - } - } - - protected JavaAssociationOverride buildAssociationOverride(AssociationOverrideAnnotation associationOverrideResource) { - JavaAssociationOverride associationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); - associationOverride.initialize(associationOverrideResource); - return associationOverride; - } - - protected JavaAssociationOverride buildVirtualAssociationOverride(RelationshipMapping overridableAssociation) { - return buildAssociationOverride(buildVirtualAssociationOverrideAnnotation(overridableAssociation)); - } - - protected AssociationOverrideAnnotation buildVirtualAssociationOverrideAnnotation(RelationshipMapping overridableAssociation) { - JoiningStrategy joiningStrategy = overridableAssociation.getRelationshipReference().getPredominantJoiningStrategy(); - return getJpaFactory().buildJavaVirtualAssociationOverrideAnnotation(this.javaResourcePersistentMember, overridableAssociation.getName(), joiningStrategy); - } - - protected void updateVirtualAssociationOverrides() { - for (RelationshipMapping overridableAssociation : CollectionTools.iterable(getOwner().allOverridableAssociations())) { - JavaAssociationOverride associationOverride = getAssociationOverrideNamed(overridableAssociation.getName()); - if (associationOverride == null) { - addVirtualAssociationOverride(buildVirtualAssociationOverride(overridableAssociation)); - } - else if (associationOverride.isVirtual()) { - associationOverride.update(buildVirtualAssociationOverrideAnnotation(overridableAssociation)); - } - } - - Collection<String> associationNames = CollectionTools.collection(getOwner().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); - } - } - } - - - //******************** 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 (JavaAssociationOverride override : CollectionTools.iterable(this.associationOverrides())) { - result = override.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - //********** Validation ******************************************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - - for (Iterator<JavaAssociationOverride> stream = this.associationOverrides(); stream.hasNext();) { - stream.next().validate(messages, reporter, astRoot); - } - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.javaResourcePersistentMember.getTextRange(astRoot); - } - - - // ********** association override owner ********** - - class AssociationOverrideOwner implements AssociationOverride.Owner { - - public RelationshipMapping getRelationshipMapping(String attributeName) { - return MappingTools.getRelationshipMapping(attributeName, getOwner().getOverridablePersistentType()); - } - - public boolean isVirtual(BaseOverride override) { - return GenericJavaAssociationOverrideContainer.this.virtualAssociationOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride attributeOverride) { - return GenericJavaAssociationOverrideContainer.this.setAssociationOverrideVirtual(virtual, (JavaAssociationOverride) attributeOverride); - } - - public TypeMapping getTypeMapping() { - return getOwner().getTypeMapping(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverrideRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverrideRelationshipReference.java deleted file mode 100644 index 9c18c1ee73..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAssociationOverrideRelationshipReference.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.AssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaAssociationOverrideRelationshipReference; - -public class GenericJavaAssociationOverrideRelationshipReference extends AbstractJavaAssociationOverrideRelationshipReference -{ - - public GenericJavaAssociationOverrideRelationshipReference(JavaAssociationOverride parent) { - super(parent); - } - - public void initializeFrom(AssociationOverrideRelationshipReference oldAssociationOverride) { - if (oldAssociationOverride.getJoinColumnJoiningStrategy().hasSpecifiedJoinColumns()) { - getJoinColumnJoiningStrategy().initializeFrom(oldAssociationOverride.getJoinColumnJoiningStrategy()); - } - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAttributeOverride.java deleted file mode 100644 index 43b798086c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAttributeOverride.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.context.java.AbstractJavaOverride; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -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 getOverrideAnnotation() { - return (AttributeOverrideAnnotation) super.getOverrideAnnotation(); - } - - @Override - public AttributeOverride.Owner getOwner() { - return (AttributeOverride.Owner) super.getOwner(); - } - - public ColumnAnnotation getResourceColumn() { - return this.getOverrideAnnotation().getNonNullColumn(); - } - - public ColumnAnnotation getResourceColumnOrNull() { - return this.getOverrideAnnotation().getColumn(); - } - - 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().getPrimaryTableName(); - } - - 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 initialize(AttributeOverrideAnnotation attributeOverrideResource) { - super.initialize(attributeOverrideResource); - this.column.initialize(this.getResourceColumn()); - } - - public void update(AttributeOverrideAnnotation attributeOverrideResource) { - super.update(attributeOverrideResource); - this.column.update(this.getResourceColumn()); - } - - @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 validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.connectionProfileIsActive()) { - this.validateColumn(messages, astRoot); - } - } - - protected void validateColumn(List<IMessage> messages, CompilationUnit astRoot) { - String tableName = this.column.getTable(); - if (this.getTypeMapping().tableNameIsInvalid(tableName)) { - if (this.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE, - new String[] {this.getName(), tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange(astRoot) - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange(astRoot) - ) - ); - } - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - if (this.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] {this.getName(), this.column.getName()}, - this.column, - this.column.getNameTextRange(astRoot) - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange(astRoot) - ) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAttributeOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAttributeOverrideContainer.java deleted file mode 100644 index 3c733ffe85..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaAttributeOverrideContainer.java +++ /dev/null @@ -1,371 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.BaseOverride; -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.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.java.VirtualAttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -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.CompositeListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaAttributeOverrideContainer extends AbstractJavaJpaContextNode - implements JavaAttributeOverrideContainer -{ - protected JavaResourcePersistentMember javaResourcePersistentMember; - - protected final List<JavaAttributeOverride> specifiedAttributeOverrides; - - protected final List<JavaAttributeOverride> virtualAttributeOverrides; - - protected final Owner owner; - - public GenericJavaAttributeOverrideContainer(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - this.specifiedAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - } - - public Owner getOwner() { - return this.owner; - } - - @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.javaResourcePersistentMember.addAnnotation( - index, AttributeOverrideAnnotation.ANNOTATION_NAME, - AttributeOverridesAnnotation.ANNOTATION_NAME); - attributeOverride.initialize(attributeOverrideResource); - this.fireItemAdded(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 update. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (ColumnMapping columnMapping : CollectionTools.iterable(getOwner().allOverridableAttributes())) { - if (columnMapping.getName().equals(attributeOverrideName)) { - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(columnMapping); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - break; - } - } - } - - this.javaResourcePersistentMember.removeAnnotation( - index, AttributeOverrideAnnotation.ANNOTATION_NAME, - AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(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.javaResourcePersistentMember.addAnnotation( - index, AttributeOverrideAnnotation.ANNOTATION_NAME, - AttributeOverridesAnnotation.ANNOTATION_NAME); - newAttributeOverride.initialize(attributeOverrideResource); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(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, SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void addSpecifiedAttributeOverride(JavaAttributeOverride attributeOverride) { - this.addSpecifiedAttributeOverride(this.specifiedAttributeOverrides.size(), attributeOverride); - } - - protected void removeSpecifiedAttributeOverride_(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentMember.moveAnnotation( - targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - protected void addVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, 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 void initialize(JavaResourcePersistentMember resourcePersistentMember) { - this.javaResourcePersistentMember = resourcePersistentMember; - this.initializeSpecifiedAttributeOverrides(); - this.initializeVirtualAttributeOverrides(); - } - - protected void initializeSpecifiedAttributeOverrides() { - for (Iterator<NestableAnnotation> stream = - this.javaResourcePersistentMember.annotations( - AttributeOverrideAnnotation.ANNOTATION_NAME, - AttributeOverridesAnnotation.ANNOTATION_NAME); - stream.hasNext(); ) { - this.specifiedAttributeOverrides.add( - buildAttributeOverride((AttributeOverrideAnnotation) stream.next())); - } - } - - protected void initializeVirtualAttributeOverrides() { - for (ColumnMapping overridableAttribute : CollectionTools.iterable(getOwner().allOverridableAttributes())) { - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(overridableAttribute.getName()); - if (attributeOverride == null) { - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(overridableAttribute)); - } - } - } - - public void update(JavaResourcePersistentMember resourcePersistentMember) { - this.javaResourcePersistentMember = resourcePersistentMember; - this.updateSpecifiedAttributeOverrides(); - this.updateVirtualAttributeOverrides(); - } - - protected void updateSpecifiedAttributeOverrides() { - ListIterator<JavaAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - Iterator<NestableAnnotation> resourceAttributeOverrides = - this.javaResourcePersistentMember.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(buildAttributeOverride((AttributeOverrideAnnotation) resourceAttributeOverrides.next())); - } - } - - protected JavaAttributeOverride buildAttributeOverride(AttributeOverrideAnnotation attributeOverrideResource) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); - attributeOverride.initialize(attributeOverrideResource); - return attributeOverride; - } - - protected JavaAttributeOverride buildVirtualAttributeOverride(ColumnMapping overridableAttribute) { - return buildAttributeOverride(buildVirtualAttributeOverrideAnnotation(overridableAttribute)); - } - - protected VirtualAttributeOverrideAnnotation buildVirtualAttributeOverrideAnnotation(ColumnMapping overridableAttribute) { - return new VirtualAttributeOverrideAnnotation(this.javaResourcePersistentMember, overridableAttribute.getName(),overridableAttribute.getColumn()); - } - - protected void updateVirtualAttributeOverrides() { - for (ColumnMapping overridableAttribute : CollectionTools.iterable(getOwner().allOverridableAttributes())) { - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(overridableAttribute.getName()); - if (attributeOverride == null) { - addVirtualAttributeOverride(buildVirtualAttributeOverride(overridableAttribute)); - } - else if (attributeOverride.isVirtual()) { - attributeOverride.update(buildVirtualAttributeOverrideAnnotation(overridableAttribute)); - } - } - - Collection<String> attributeNames = CollectionTools.collection(getOwner().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); - } - } - } - - - //******************** 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 (JavaAttributeOverride override : CollectionTools.iterable(this.attributeOverrides())) { - result = override.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - //********** Validation ******************************************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - for (Iterator<JavaAttributeOverride> stream = this.attributeOverrides(); stream.hasNext();) { - stream.next().validate(messages, reporter, astRoot); - } - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.javaResourcePersistentMember.getTextRange(astRoot); - } - - - - // ********** attribute override owner ********** - - class AttributeOverrideOwner implements AttributeOverride.Owner { - - public ColumnMapping getColumnMapping(String attributeName) { - return MappingTools.getColumnMapping(attributeName, getOwner().getOverridablePersistentType()); - } - - public boolean isVirtual(BaseOverride override) { - return GenericJavaAttributeOverrideContainer.this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride attributeOverride) { - return GenericJavaAttributeOverrideContainer.this.setAttributeOverrideVirtual(virtual, (JavaAttributeOverride) attributeOverride); - } - - public TypeMapping getTypeMapping() { - return getOwner().getTypeMapping(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaBasicMapping.java deleted file mode 100644 index 9d6fa7b60d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaBasicMapping.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaBasicMapping; - - -public class GenericJavaBasicMapping extends AbstractJavaBasicMapping -{ - public GenericJavaBasicMapping(JavaPersistentAttribute parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaCascade.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaCascade.java deleted file mode 100644 index 8cb5e73a0f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaCascade.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.java.JavaCascade; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaCascade extends AbstractJavaJpaContextNode implements JavaCascade -{ - protected boolean all; - - protected boolean persist; - - protected boolean merge; - - protected boolean remove; - - protected boolean refresh; - - protected RelationshipMappingAnnotation relationshipMapping; - - public GenericJavaCascade(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); - } - - protected void setAll_(boolean newAll) { - boolean oldAll = this.all; - this.all = 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); - } - - protected void setPersist_(boolean newPersist) { - boolean oldPersist = this.persist; - this.persist = 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); - } - - protected void setMerge_(boolean newMerge) { - boolean oldMerge = this.merge; - this.merge = 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); - } - - protected void setRemove_(boolean newRemove) { - boolean oldRemove = this.remove; - this.remove = 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); - } - - protected void setRefresh_(boolean newRefresh) { - boolean oldRefresh = this.refresh; - this.refresh = 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/jpa1/context/java/GenericJavaColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaColumn.java deleted file mode 100644 index ca9f448ba6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaColumn.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.internal.context.java.AbstractJavaBaseColumn; -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 initialize(ColumnAnnotation column) { - super.initialize(column); - this.specifiedLength = this.getResourceLength(column); - this.specifiedPrecision = this.getResourcePrecision(column); - this.specifiedScale = this.getResourceScale(column); - } - - @Override - public JavaColumn.Owner getOwner() { - return (JavaColumn.Owner) super.getOwner(); - } - - @Override - protected ColumnAnnotation getResourceColumn() { - return this.getOwner().getResourceColumn(); - } - - public int getLength() { - return (this.getSpecifiedLength() == null) ? getDefaultLength() : this.getSpecifiedLength().intValue(); - } - - public int getDefaultLength() { - return Column.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - getResourceColumn().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 int getPrecision() { - return (this.getSpecifiedPrecision() == null) ? getDefaultPrecision() : this.getSpecifiedPrecision().intValue(); - } - - public int getDefaultPrecision() { - return Column.DEFAULT_PRECISION; - } - - public Integer getSpecifiedPrecision() { - return this.specifiedPrecision; - } - - public void setSpecifiedPrecision(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - getResourceColumn().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 int getScale() { - return (this.getSpecifiedScale() == null) ? getDefaultScale() : this.getSpecifiedScale().intValue(); - } - - public int getDefaultScale() { - return Column.DEFAULT_SCALE; - } - - public Integer getSpecifiedScale() { - return this.specifiedScale; - } - - public void setSpecifiedScale(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - getResourceColumn().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 = getResourceColumn().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - @Override - public void update(ColumnAnnotation column) { - super.update(column); - this.setSpecifiedLength_(this.getResourceLength(column)); - this.setSpecifiedPrecision_(this.getResourcePrecision(column)); - this.setSpecifiedScale_(this.getResourceScale(column)); - } - - protected Integer getResourceLength(ColumnAnnotation column) { - return column.getLength(); - } - - protected Integer getResourcePrecision(ColumnAnnotation column) { - return column.getPrecision(); - } - - protected Integer getResourceScale(ColumnAnnotation column) { - return column.getScale(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaDiscriminatorColumn.java deleted file mode 100644 index 50c93e70e1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaDiscriminatorColumn.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.List; -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.internal.context.java.AbstractJavaNamedColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaDiscriminatorColumn extends AbstractJavaNamedColumn<DiscriminatorColumnAnnotation> - implements JavaDiscriminatorColumn -{ - - protected DiscriminatorType specifiedDiscriminatorType; - - protected DiscriminatorType defaultDiscriminatorType; - - protected Integer specifiedLength; - - protected int defaultLength; - - protected JavaResourcePersistentMember persistenceResource; - - public GenericJavaDiscriminatorColumn(JavaEntity parent, JavaDiscriminatorColumn.Owner owner) { - super(parent, owner); - } - - public void initialize(JavaResourcePersistentMember persistentResource) { - this.persistenceResource = persistentResource; - this.initialize(this.getResourceColumn()); - } - - @Override - public void initialize(DiscriminatorColumnAnnotation column) { - super.initialize(column); - this.defaultDiscriminatorType = this.buildDefaultDiscriminatorType(); - this.defaultLength = this.buildDefaultLength(); - this.specifiedDiscriminatorType = this.getResourceDiscriminatorType(column); - this.specifiedLength = this.getResourceLength(column); - } - - @Override - public JavaDiscriminatorColumn.Owner getOwner() { - return (JavaDiscriminatorColumn.Owner) super.getOwner(); - } - - protected JavaEntity getJavaEntity() { - return (JavaEntity) super.getParent(); - } - - @Override - protected DiscriminatorColumnAnnotation getResourceColumn() { - return (DiscriminatorColumnAnnotation) this.persistenceResource. - getNonNullAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME); - } - - public boolean isResourceSpecified() { - return getResourceColumn().isSpecified(); - } - - public DiscriminatorType getDiscriminatorType() { - return (this.getSpecifiedDiscriminatorType() == null) ? this.getDefaultDiscriminatorType() : this.getSpecifiedDiscriminatorType(); - } - - public DiscriminatorType getDefaultDiscriminatorType() { - return this.defaultDiscriminatorType; - } - - protected void setDefaultDiscriminatorType(DiscriminatorType discriminatorType) { - DiscriminatorType old = this.defaultDiscriminatorType; - this.defaultDiscriminatorType = discriminatorType; - firePropertyChanged(DEFAULT_DISCRIMINATOR_TYPE_PROPERTY, old, discriminatorType); - } - - public DiscriminatorType getSpecifiedDiscriminatorType() { - return this.specifiedDiscriminatorType; - } - - public void setSpecifiedDiscriminatorType(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - getResourceColumn().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 int getLength() { - return (this.getSpecifiedLength() == null) ? this.getDefaultLength() : this.getSpecifiedLength().intValue(); - } - - public int getDefaultLength() { - return this.defaultLength; - } - - protected void setDefaultLength(int defaultLength) { - int old = this.defaultLength; - this.defaultLength = defaultLength; - firePropertyChanged(DEFAULT_LENGTH_PROPERTY, old, defaultLength); - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - getResourceColumn().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().getPrimaryTableName(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getResourceColumn().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.getResourceColumn()); - } - - @Override - public void update(DiscriminatorColumnAnnotation discriminatorColumn) { - //don't call super because postUpdate() handles updating the default column name - this.setSpecifiedName_(discriminatorColumn.getName()); - this.setColumnDefinition_(discriminatorColumn.getColumnDefinition()); - this.setSpecifiedDiscriminatorType_(this.getResourceDiscriminatorType(discriminatorColumn)); - this.setSpecifiedLength_(this.getResourceLength(discriminatorColumn)); - } - - @Override - /** - * Using postUpdate since these defaults are dependent on the entity hierarchy - */ - public void postUpdate() { - super.postUpdate(); - this.setDefaultName(this.buildDefaultName()); - this.setDefaultDiscriminatorType(this.buildDefaultDiscriminatorType()); - this.setDefaultLength(this.buildDefaultLength()); - } - - protected DiscriminatorType getResourceDiscriminatorType(DiscriminatorColumnAnnotation discriminatorColumn) { - return DiscriminatorType.fromJavaResourceModel(discriminatorColumn.getDiscriminatorType()); - } - - protected Integer getResourceLength(DiscriminatorColumnAnnotation discriminatorColumn) { - return discriminatorColumn.getLength(); - } - - @Override - public JavaEntity getParent() { - return (JavaEntity) super.getParent(); - } - - protected int buildDefaultLength() { - return this.getOwner().getDefaultLength(); - } - - protected DiscriminatorType buildDefaultDiscriminatorType() { - return this.getOwner().getDefaultDiscriminatorType(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.connectionProfileIsActive()) { - if ( ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.DISCRIMINATOR_COLUMN_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange(astRoot) - ) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddable.java deleted file mode 100644 index 38a2c98167..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddable.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaEmbeddable; -import org.eclipse.jpt.utility.internal.ArrayTools; - - -public class GenericJavaEmbeddable - extends AbstractJavaEmbeddable -{ - public GenericJavaEmbeddable(JavaPersistentType parent) { - super(parent); - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - //generic only allows basic and transient within an Embeddable - return ArrayTools.contains(ALLOWED_ATTRIBUTE_MAPPING_KEYS, attributeMappingKey); - } - - public static final String[] ALLOWED_ATTRIBUTE_MAPPING_KEYS = - new String[] { - MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, - MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY - }; -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddedIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddedIdMapping.java deleted file mode 100644 index cecd583e01..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddedIdMapping.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.internal.context.java.AbstractJavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; - - -public class GenericJavaEmbeddedIdMapping - extends AbstractJavaBaseEmbeddedMapping<EmbeddedIdAnnotation> - implements JavaEmbeddedIdMapping -{ - - public GenericJavaEmbeddedIdMapping(JavaPersistentAttribute parent) { - super(parent); - } - - //****************** JavaAttributeMapping implementation ******************* - - 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/jpa1/context/java/GenericJavaEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddedMapping.java deleted file mode 100644 index 5f44917f8e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEmbeddedMapping.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.Iterator; -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.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.jpa2.JpaFactory2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.ArrayTools; -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 GenericJavaEmbeddedMapping - extends AbstractJavaBaseEmbeddedMapping<EmbeddedAnnotation> - implements JavaEmbeddedMapping2_0 -{ - protected final JavaAssociationOverrideContainer associationOverrideContainer; - - public GenericJavaEmbeddedMapping(JavaPersistentAttribute parent) { - super(parent); - this.associationOverrideContainer = ((JpaFactory2_0) this.getJpaFactory()).buildJavaAssociationOverrideContainer(this, this); - } - - @Override - protected void initialize() { - super.initialize(); - this.associationOverrideContainer.initialize(this.resourcePersistentAttribute); - } - - @Override - protected void update() { - super.update(); - this.associationOverrideContainer.update(this.resourcePersistentAttribute); - } - - @Override - public void postUpdate() { - super.postUpdate(); - this.associationOverrideContainer.postUpdate(); - } - - //****************** JavaAttributeMapping implementation ******************* - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedAnnotation.ANNOTATION_NAME; - } - - //****************** AbstractJavaAttributeMapping implementation ******************* - @Override - protected String[] buildSupportingAnnotationNames() { - if (getJpaPlatformVersion().is2_0Compatible()) { - return ArrayTools.addAll( - super.buildSupportingAnnotationNames(), - JPA.ASSOCIATION_OVERRIDE, - JPA.ASSOCIATION_OVERRIDES); - } - return super.buildSupportingAnnotationNames(); - } - - - //****************** association overrides - 2.0 supports this ******************* - - public JavaAssociationOverrideContainer getAssociationOverrideContainer() { - return this.associationOverrideContainer; - } - - public Iterator<String> allOverridableAssociationNames() { - return new TransformationIterator<RelationshipMapping, String>(this.allOverridableAssociations()) { - @Override - protected String transform(RelationshipMapping attribute) { - return attribute.getName(); - } - }; - } - - //TODO hmm, is this only for 2.0??? - public Iterator<RelationshipMapping> allOverridableAssociations() { - if (this.getEmbeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<AttributeMapping, RelationshipMapping>(this.getEmbeddable().attributeMappings()) { - @Override - protected boolean accept(AttributeMapping o) { - return o.isOverridableAssociationMapping(); - } - }; - } - - - @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 = getAssociationOverrideContainer().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEntity.java deleted file mode 100644 index 676f7ec1a7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEntity.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity; - -public class GenericJavaEntity - extends AbstractJavaEntity -{ - public GenericJavaEntity(JavaPersistentType parent) { - super(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEnumeratedConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEnumeratedConverter.java deleted file mode 100644 index 69c03c3f65..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEnumeratedConverter.java +++ /dev/null @@ -1,103 +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.jpa1.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaEnumeratedConverter; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaEnumeratedConverter extends AbstractJavaJpaContextNode - implements JavaEnumeratedConverter -{ - private EnumType specifiedEnumType; - - private JavaResourcePersistentAttribute resourcePersistenceAttribute; - - public GenericJavaEnumeratedConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa) { - super(parent); - this.initialize(jrpa); - } - - @Override - public JavaAttributeMapping getParent() { - return (JavaAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.ENUMERATED_CONVERTER; - } - - protected String getAnnotationName() { - return EnumeratedAnnotation.ANNOTATION_NAME; - } - - public void addToResourceModel() { - this.resourcePersistenceAttribute.addAnnotation(getAnnotationName()); - } - - public void removeFromResourceModel() { - this.resourcePersistenceAttribute.removeAnnotation(getAnnotationName()); - } - - public EnumType getEnumType() { - return getSpecifiedEnumType() == null ? getDefaultEnumType() : getSpecifiedEnumType(); - } - - public EnumType getDefaultEnumType() { - return EnumeratedConverter.DEFAULT_ENUM_TYPE; - } - - public EnumType getSpecifiedEnumType() { - return this.specifiedEnumType; - } - - public void setSpecifiedEnumType(EnumType newSpecifiedEnumType) { - EnumType oldSpecifiedEnumType = this.specifiedEnumType; - this.specifiedEnumType = newSpecifiedEnumType; - this.getResourceEnumerated().setValue(EnumType.toJavaResourceModel(newSpecifiedEnumType)); - firePropertyChanged(EnumeratedConverter.SPECIFIED_ENUM_TYPE_PROPERTY, oldSpecifiedEnumType, newSpecifiedEnumType); - } - - protected void setSpecifiedEnumType_(EnumType newSpecifiedEnumType) { - EnumType oldSpecifiedEnumType = this.specifiedEnumType; - this.specifiedEnumType = newSpecifiedEnumType; - firePropertyChanged(EnumeratedConverter.SPECIFIED_ENUM_TYPE_PROPERTY, oldSpecifiedEnumType, newSpecifiedEnumType); - } - - protected EnumeratedAnnotation getResourceEnumerated() { - return (EnumeratedAnnotation) this.resourcePersistenceAttribute. - getAnnotation(getAnnotationName()); - } - - protected void initialize(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistenceAttribute = jrpa; - this.specifiedEnumType = this.specifiedEnumType(getResourceEnumerated()); - } - - public void update(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistenceAttribute = jrpa; - this.setSpecifiedEnumType_(this.specifiedEnumType(getResourceEnumerated())); - } - - protected EnumType specifiedEnumType(EnumeratedAnnotation resourceEnumerated) { - return resourceEnumerated == null ? null : EnumType.fromJavaResourceModel(resourceEnumerated.getValue()); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getResourceEnumerated().getTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java deleted file mode 100644 index de24ea665f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratedValue.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.Iterator; -import java.util.List; -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.Generator; -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -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.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * - */ -public class GenericJavaGeneratedValue - extends AbstractJavaJpaContextNode - implements JavaGeneratedValue -{ - private GeneratedValueAnnotation resourceGeneratedValue; - - private GenerationType specifiedStrategy; - - private String specifiedGenerator; - - // always null? - private String defaultGenerator = null; - - - public GenericJavaGeneratedValue(JavaIdMapping parent) { - super(parent); - } - - public void initialize(GeneratedValueAnnotation generatedValueAnnotation) { - this.resourceGeneratedValue = generatedValueAnnotation; - this.specifiedStrategy = this.buildSpecifiedStrategy(); - this.specifiedGenerator = generatedValueAnnotation.getGenerator(); - } - - - // ********** strategy ********** - - public GenerationType getStrategy() { - return (this.specifiedStrategy != null) ? this.specifiedStrategy : this.getDefaultStrategy(); - } - - public GenerationType getDefaultStrategy() { - return GeneratedValue.DEFAULT_STRATEGY; - } - - public GenerationType getSpecifiedStrategy() { - return this.specifiedStrategy; - } - - public void setSpecifiedStrategy(GenerationType strategy) { - GenerationType old = this.specifiedStrategy; - this.specifiedStrategy = strategy; - this.resourceGeneratedValue.setStrategy(GenerationType.toJavaResourceModel(strategy)); - this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); - } - - protected void setSpecifiedStrategy_(GenerationType strategy) { - GenerationType old = this.specifiedStrategy; - this.specifiedStrategy = strategy; - this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); - } - - - // ********** generator ********** - - public String getGenerator() { - return (this.specifiedGenerator != null) ? this.specifiedGenerator : this.defaultGenerator; - } - - public String getDefaultGenerator() { - return this.defaultGenerator; - } - - public String getSpecifiedGenerator() { - return this.specifiedGenerator; - } - - public void setSpecifiedGenerator(String generator) { - String old = this.specifiedGenerator; - this.specifiedGenerator = generator; - this.resourceGeneratedValue.setGenerator(generator); - this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); - } - - protected void setSpecifiedGenerator_(String generator) { - String old = this.specifiedGenerator; - this.specifiedGenerator = generator; - this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); - } - - - // ********** text ranges ********** - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.resourceGeneratedValue.getTextRange(astRoot); - } - - public TextRange getGeneratorTextRange(CompilationUnit astRoot) { - return this.resourceGeneratedValue.getGeneratorTextRange(astRoot); - } - - - // ********** completion proposals ********** - - @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.generatorTouches(pos, astRoot)) { - return this.javaCandidateGeneratorNames(filter); - } - return null; - } - - protected boolean generatorTouches(int pos, CompilationUnit astRoot) { - return this.resourceGeneratedValue.generatorTouches(pos, astRoot); - } - - protected Iterator<String> javaCandidateGeneratorNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateGeneratorNames(filter)); - } - - protected Iterator<String> candidateGeneratorNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateGeneratorNames(), filter); - } - - protected Iterator<String> candidateGeneratorNames() { - return new TransformationIterator<Generator, String>(this.candidateGenerators()) { - @Override - protected String transform(Generator generator) { - return generator.getName(); - } - }; - } - - protected Iterator<Generator> candidateGenerators() { - return this.getPersistenceUnit().generators(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - - String generator = this.getGenerator(); - if (generator == null) { - return; - } - - for (Iterator<Generator> stream = this.getPersistenceUnit().generators(); stream.hasNext(); ) { - if (generator.equals(stream.next().getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generator}, - this.getParent(), - this.getGeneratorTextRange(astRoot) - ) - ); - } - - - // ********** update from resource model ********** - - public void update(GeneratedValueAnnotation generatedValueAnnotation) { - this.resourceGeneratedValue = generatedValueAnnotation; - this.setSpecifiedStrategy_(this.buildSpecifiedStrategy()); - this.setSpecifiedGenerator_(generatedValueAnnotation.getGenerator()); - } - - protected GenerationType buildSpecifiedStrategy() { - return GenerationType.fromJavaResourceModel(this.resourceGeneratedValue.getStrategy()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java deleted file mode 100644 index 1f4586a705..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -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.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -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.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaGeneratorContainer extends AbstractJavaJpaContextNode - implements JavaGeneratorContainer -{ - protected JavaResourcePersistentMember javaResourcePersistentMember; - - protected JavaSequenceGenerator sequenceGenerator; - - protected JavaTableGenerator tableGenerator; - - public GenericJavaGeneratorContainer(JavaJpaContextNode parent) { - super(parent); - } - - @Override - public JavaJpaContextNode getParent() { - return (JavaJpaContextNode) super.getParent(); - } - - public JavaTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); //$NON-NLS-1$ - } - this.tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - TableGeneratorAnnotation tableGeneratorResource = - (TableGeneratorAnnotation) this.javaResourcePersistentMember. - addAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - this.tableGenerator.initialize(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"); //$NON-NLS-1$ - } - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - this.javaResourcePersistentMember.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"); //$NON-NLS-1$ - } - this.sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - SequenceGeneratorAnnotation sequenceGeneratorResource = - (SequenceGeneratorAnnotation) this.javaResourcePersistentMember. - addAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - this.sequenceGenerator.initialize(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"); //$NON-NLS-1$ - } - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - this.javaResourcePersistentMember.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); - } - - - public void initialize(JavaResourcePersistentMember jrpm) { - this.javaResourcePersistentMember = jrpm; - this.initializeTableGenerator(); - this.initializeSequenceGenerator(); - } - - protected void initializeTableGenerator() { - TableGeneratorAnnotation tableGeneratorResource = getResourceTableGenerator(); - if (tableGeneratorResource != null) { - this.tableGenerator = buildTableGenerator(tableGeneratorResource); - } - } - - protected void initializeSequenceGenerator() { - SequenceGeneratorAnnotation sequenceGeneratorResource = getResourceSequenceGenerator(); - if (sequenceGeneratorResource != null) { - this.sequenceGenerator = buildSequenceGenerator(sequenceGeneratorResource); - } - } - - public void update(JavaResourcePersistentMember jrpm) { - this.javaResourcePersistentMember = jrpm; - this.updateTableGenerator(); - this.updateSequenceGenerator(); - } - - protected void updateTableGenerator() { - TableGeneratorAnnotation tableGeneratorResource = getResourceTableGenerator(); - 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 generator = getJpaFactory().buildJavaTableGenerator(this); - generator.initialize(tableGeneratorResource); - return generator; - } - - protected TableGeneratorAnnotation getResourceTableGenerator() { - return (TableGeneratorAnnotation) this.javaResourcePersistentMember. - getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - } - - protected void updateSequenceGenerator() { - SequenceGeneratorAnnotation sequenceGeneratorResource = getResourceSequenceGenerator(); - 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 generator = getJpaFactory().buildJavaSequenceGenerator(this); - generator.initialize(sequenceGeneratorResource); - return generator; - } - - protected SequenceGeneratorAnnotation getResourceSequenceGenerator() { - return (SequenceGeneratorAnnotation) this.javaResourcePersistentMember. - getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - } - - - //******************** 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; - } - 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 validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.validateGenerators(messages, astRoot); - } - - protected void validateGenerators(List<IMessage> messages, CompilationUnit astRoot) { - for (Iterator<JavaGenerator> localGenerators = this.generators(); localGenerators.hasNext(); ) { - JavaGenerator localGenerator = localGenerators.next(); - for (Iterator<Generator> globalGenerators = this.getPersistenceUnit().generators(); globalGenerators.hasNext(); ) { - if (localGenerator.duplicates(globalGenerators.next())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {localGenerator.getName()}, - localGenerator, - localGenerator.getNameTextRange(astRoot) - ) - ); - } - } - } - } - - protected final Iterator<JavaGenerator> generators() { - ArrayList<JavaGenerator> generators = new ArrayList<JavaGenerator>(); - this.addGeneratorsTo(generators); - return generators.iterator(); - } - - protected void addGeneratorsTo(ArrayList<JavaGenerator> generators) { - if (this.sequenceGenerator != null) { - generators.add(this.sequenceGenerator); - } - if (this.tableGenerator != null) { - generators.add(this.tableGenerator); - } - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.javaResourcePersistentMember.getTextRange(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaIdMapping.java deleted file mode 100644 index 97620c7e05..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaIdMapping.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaIdMapping; - - -public class GenericJavaIdMapping - extends AbstractJavaIdMapping -{ - - public GenericJavaIdMapping(JavaPersistentAttribute parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java deleted file mode 100644 index fe00f95b2e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinColumn.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -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.internal.context.java.AbstractJavaBaseColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -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; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -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 getResourceColumn() { - 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 getReferencedColumnDbTable() { - return getOwner().getReferencedColumnDbTable(); - } - - public Column getReferencedDbColumn() { - Table table = this.getReferencedColumnDbTable(); - return (table == null) ? null : table.getColumnForIdentifier(this.getReferencedColumnName()); - } - - @Override - public boolean tableIsAllowed() { - return this.getOwner().tableIsAllowed(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return getResourceColumn().referencedColumnNameTouches(pos, astRoot); - } - - @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.javaCandidateReferencedColumnNames(filter); - } - return null; - } - - private Iterator<String> javaCandidateReferencedColumnNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateReferencedColumnNames(filter)); - } - - private Iterator<String> candidateReferencedColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateReferencedColumnNames(), filter); - } - - private Iterator<String> candidateReferencedColumnNames() { - Table table = this.getOwner().getReferencedColumnDbTable(); - return (table != null) ? table.sortedColumnIdentifiers() : EmptyIterator.<String> instance(); - } - - public boolean isReferencedColumnResolved() { - return getReferencedDbColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - TextRange textRange = getResourceColumn().getReferencedColumnNameTextRange(astRoot); - return (textRange != null) ? textRange : getOwner().getValidationTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void initialize(JoinColumnAnnotation annotation) { - this.joinColumn = annotation; - super.initialize(annotation); - this.specifiedReferencedColumnName = annotation.getReferencedColumnName(); - this.defaultReferencedColumnName = this.buildDefaultReferencedColumnName(); - } - - @Override - public void update(JoinColumnAnnotation annotation) { - this.joinColumn = annotation; - super.update(annotation); - this.setSpecifiedReferencedColumnName_(annotation.getReferencedColumnName()); - this.setDefaultReferencedColumnName(this.buildDefaultReferencedColumnName()); - } - - @Override - protected String buildDefaultName() { - return MappingTools.buildJoinColumnDefaultName(this); - } - - protected String buildDefaultReferencedColumnName() { - return MappingTools.buildJoinColumnDefaultReferencedColumnName(this.getOwner()); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - validateName(messages, astRoot); - validateReferencedColumnName(messages, astRoot); - } - - protected void validateName(List<IMessage> messages, CompilationUnit astRoot) { - if ( ! this.isResolved() && getDbTable() != null) { - if (getName() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange(astRoot) - ) - ); - } - else if (getOwner().joinColumnsSize() > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - this, - this.getNameTextRange(astRoot) - ) - ); - } - //If the name is null and there is only one join-column, one of these validation messages will apply - // 1. target entity does not have a primary key - // 2. target entity is not specified - // 3. target entity is not an entity - } - } - - protected void validateReferencedColumnName(List<IMessage> messages, CompilationUnit astRoot) { - if ( ! this.isReferencedColumnResolved() && getReferencedColumnDbTable() != null) { - if (getReferencedColumnName() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {this.getReferencedColumnName(), this.getName()}, - this, - this.getReferencedColumnNameTextRange(astRoot) - ) - ); - } - else if (getOwner().joinColumnsSize() > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS, - this, - this.getNameTextRange(astRoot) - ) - ); - } - //If the referenced column name is null and there is only one join-column, one of these validation messages will apply - // 1. target entity does not have a primary key - // 2. target entity is not specified - // 3. target entity is not an entity - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinTable.java deleted file mode 100644 index 1f3f841016..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaJoinTable.java +++ /dev/null @@ -1,725 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; - -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.JoinColumn; -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.JavaJoinTableJoiningStrategy; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaTable; -import org.eclipse.jpt.core.internal.resource.java.NullJoinColumnAnnotation; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * Java join table - */ -public class GenericJavaJoinTable - extends AbstractJavaTable - implements JavaJoinTable -{ - - protected JavaJoinColumn defaultJoinColumn; - - protected final Vector<JavaJoinColumn> specifiedJoinColumns = new Vector<JavaJoinColumn>(); - protected final JavaJoinColumn.Owner joinColumnOwner; - - protected JavaJoinColumn defaultInverseJoinColumn; - - protected final Vector<JavaJoinColumn> specifiedInverseJoinColumns = new Vector<JavaJoinColumn>(); - protected final JavaJoinColumn.Owner inverseJoinColumnOwner; - - - public GenericJavaJoinTable(JavaJoinTableJoiningStrategy parent) { - super(parent); - this.joinColumnOwner = this.buildJoinColumnOwner(); - this.inverseJoinColumnOwner = this.buildInverseJoinColumnOwner(); - } - - protected JavaJoinColumn.Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected JavaJoinColumn.Owner buildInverseJoinColumnOwner() { - return new InverseJoinColumnOwner(); - } - - public RelationshipMapping getRelationshipMapping() { - return this.getParent().getRelationshipReference().getRelationshipMapping(); - } - - public void initialize(JoinTableAnnotation joinTable) { - super.initialize(joinTable); - this.initializeSpecifiedJoinColumns(joinTable); - this.initializeDefaultJoinColumn(joinTable); - this.initializeSpecifiedInverseJoinColumns(joinTable); - this.initializeDefaultInverseJoinColumn(joinTable); - } - - public void update(JoinTableAnnotation joinTable) { - super.update(joinTable); - this.updateSpecifiedJoinColumns(joinTable); - this.updateDefaultJoinColumn(joinTable); - this.updateSpecifiedInverseJoinColumns(joinTable); - this.updateDefaultInverseJoinColumn(joinTable); - } - - - // ********** AbstractJavaTable implementation ********** - - @Override - public JavaJoinTableJoiningStrategy getParent() { - return (JavaJoinTableJoiningStrategy) super.getParent(); - } - - @Override - protected String getAnnotationName() { - return JoinTableAnnotation.ANNOTATION_NAME; - } - - @Override - protected String buildDefaultName() { - return this.getParent().getJoinTableDefaultName(); - } - - @Override - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - @Override - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - @Override - protected JoinTableAnnotation getAnnotation() { - return this.getParent().getAnnotation(); - } - - - // ********** Table implementation ********** - - public boolean isResourceSpecified() { - return this.getAnnotation().isSpecified(); - } - - - // ********** join columns ********** - - public ListIterator<JavaJoinColumn> joinColumns() { - return this.hasSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.hasSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public void convertDefaultToSpecifiedJoinColumn() { - MappingTools.convertJoinTableDefaultToSpecifiedJoinColumn(this); - } - - protected JavaJoinColumn buildJoinColumn(JoinColumnAnnotation joinColumnAnnotation) { - return this.buildJoinColumn(joinColumnAnnotation, this.joinColumnOwner); - } - - - // ********** default join column ********** - - public JavaJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(JavaJoinColumn defaultJoinColumn) { - JavaJoinColumn old = this.defaultJoinColumn; - this.defaultJoinColumn = defaultJoinColumn; - this.firePropertyChanged(DEFAULT_JOIN_COLUMN, old, defaultJoinColumn); - } - - 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; - } - - protected void initializeDefaultJoinColumn(JoinTableAnnotation joinTableAnnotation) { - if (this.shouldBuildDefaultJoinColumn()) { - this.defaultJoinColumn = this.buildJoinColumn(new NullJoinColumnAnnotation(joinTableAnnotation)); - } - } - - protected void updateDefaultJoinColumn(JoinTableAnnotation joinTableAnnotation) { - if (this.shouldBuildDefaultJoinColumn()) { - if (this.defaultJoinColumn == null) { - this.setDefaultJoinColumn(this.buildJoinColumn(new NullJoinColumnAnnotation(joinTableAnnotation))); - } else { - this.defaultJoinColumn.update(new NullJoinColumnAnnotation(joinTableAnnotation)); - } - } else { - this.setDefaultJoinColumn(null); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return ! this.hasSpecifiedJoinColumns(); - } - - - // ********** specified join columns ********** - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean hasSpecifiedJoinColumns() { - return this.specifiedJoinColumns.size() != 0; - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - // Clear out the default now so it doesn't get removed during an update and - // cause change notifications to be sent to the UI in the wrong order. - // If the default is already null, nothing will happen. - JoinColumn oldDefault = this.defaultJoinColumn; - this.defaultJoinColumn = null; - - JavaJoinColumn joinColumn = this.getJpaFactory().buildJavaJoinColumn(this, this.joinColumnOwner); - this.specifiedJoinColumns.add(index, joinColumn); - JoinTableAnnotation joinTableAnnotation = this.getAnnotation(); - JoinColumnAnnotation joinColumnAnnotation = joinTableAnnotation.addJoinColumn(index); - joinColumn.initialize(joinColumnAnnotation); - this.fireItemAdded(SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - - this.firePropertyChanged(DEFAULT_JOIN_COLUMN, oldDefault, null); - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - this.addItemToList(index, joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedJoinColumn(JavaJoinColumn joinColumn) { - this.addSpecifiedJoinColumn(this.specifiedJoinColumns.size(), joinColumn); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if ( ! this.hasSpecifiedJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = this.buildJoinColumn(new NullJoinColumnAnnotation(this.getAnnotation())); - } - this.getAnnotation().removeJoinColumn(index); - this.fireItemRemoved(SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(JavaJoinColumn joinColumn) { - this.removeItemFromList(joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getAnnotation().moveJoinColumn(targetIndex, sourceIndex); - this.fireItemMoved(SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void clearSpecifiedJoinColumns() { - // for now, we have to remove annotations one at a time... - for (int i = this.specifiedJoinColumns.size(); i-- > 0; ) { - this.removeSpecifiedJoinColumn(i); - } - } - - protected void initializeSpecifiedJoinColumns(JoinTableAnnotation joinTableAnnotation) { - for (ListIterator<JoinColumnAnnotation> stream = joinTableAnnotation.joinColumns(); stream.hasNext(); ) { - this.specifiedJoinColumns.add(this.buildJoinColumn(stream.next())); - } - } - - protected void updateSpecifiedJoinColumns(JoinTableAnnotation joinTableAnnotation) { - ListIterator<JavaJoinColumn> joinColumns = this.specifiedJoinColumns(); - ListIterator<JoinColumnAnnotation> joinColumnAnnotations = joinTableAnnotation.joinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (joinColumnAnnotations.hasNext()) { - joinColumn.update(joinColumnAnnotations.next()); - } else { - this.removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (joinColumnAnnotations.hasNext()) { - this.addSpecifiedJoinColumn(this.buildJoinColumn(joinColumnAnnotations.next())); - } - } - - - // ********** inverse join columns ********** - - public ListIterator<JavaJoinColumn> inverseJoinColumns() { - return this.hasSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumns() : this.defaultInverseJoinColumns(); - } - - public int inverseJoinColumnsSize() { - return this.hasSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumnsSize() : this.defaultInverseJoinColumnsSize(); - } - - public void convertDefaultToSpecifiedInverseJoinColumn() { - MappingTools.convertJoinTableDefaultToSpecifiedInverseJoinColumn(this); - } - - protected JavaJoinColumn buildInverseJoinColumn(JoinColumnAnnotation joinColumnAnnotation) { - return this.buildJoinColumn(joinColumnAnnotation, this.inverseJoinColumnOwner); - } - - - // ********** default inverse join column ********** - - public JavaJoinColumn getDefaultInverseJoinColumn() { - return this.defaultInverseJoinColumn; - } - - protected void setDefaultInverseJoinColumn(JavaJoinColumn defaultInverseJoinColumn) { - JavaJoinColumn old = this.defaultInverseJoinColumn; - this.defaultInverseJoinColumn = defaultInverseJoinColumn; - this.firePropertyChanged(DEFAULT_INVERSE_JOIN_COLUMN, old, defaultInverseJoinColumn); - } - - 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; - } - - protected void initializeDefaultInverseJoinColumn(JoinTableAnnotation joinTableAnnotation) { - if (this.shouldBuildDefaultInverseJoinColumn()) { - this.defaultInverseJoinColumn = this.buildInverseJoinColumn(new NullJoinColumnAnnotation(joinTableAnnotation)); - } - } - - protected boolean shouldBuildDefaultInverseJoinColumn() { - return ! this.hasSpecifiedInverseJoinColumns(); - } - - protected void updateDefaultInverseJoinColumn(JoinTableAnnotation joinTableAnnotation) { - if (this.shouldBuildDefaultInverseJoinColumn()) { - if (this.defaultInverseJoinColumn == null) { - this.setDefaultInverseJoinColumn(this.buildInverseJoinColumn(new NullJoinColumnAnnotation(joinTableAnnotation))); - } else { - this.defaultInverseJoinColumn.update(new NullJoinColumnAnnotation(joinTableAnnotation)); - } - } else { - this.setDefaultInverseJoinColumn(null); - } - } - - - // ********** specified inverse join columns ********** - - public ListIterator<JavaJoinColumn> specifiedInverseJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedInverseJoinColumns); - } - - public int specifiedInverseJoinColumnsSize() { - return this.specifiedInverseJoinColumns.size(); - } - - public boolean hasSpecifiedInverseJoinColumns() { - return this.specifiedInverseJoinColumns.size() != 0; - } - - public JavaJoinColumn addSpecifiedInverseJoinColumn(int index) { - // Clear out the default now so it doesn't get removed during an update and - // cause change notifications to be sent to the UI in the wrong order. - // If the default is already null, nothing will happen. - JoinColumn oldDefault = this.defaultInverseJoinColumn; - this.defaultInverseJoinColumn = null; - - JavaJoinColumn inverseJoinColumn = this.getJpaFactory().buildJavaJoinColumn(this, this.inverseJoinColumnOwner); - this.specifiedInverseJoinColumns.add(index, inverseJoinColumn); - JoinTableAnnotation joinTableAnnotation = this.getAnnotation(); - JoinColumnAnnotation joinColumnAnnotation = joinTableAnnotation.addInverseJoinColumn(index); - inverseJoinColumn.initialize(joinColumnAnnotation); - this.fireItemAdded(SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, inverseJoinColumn); - - this.firePropertyChanged(DEFAULT_INVERSE_JOIN_COLUMN, oldDefault, null); - return inverseJoinColumn; - } - - protected void addSpecifiedInverseJoinColumn(int index, JavaJoinColumn inverseJoinColumn) { - this.addItemToList(index, inverseJoinColumn, this.specifiedInverseJoinColumns, SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedInverseJoinColumn(JavaJoinColumn inverseJoinColumn) { - this.addSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.size(), inverseJoinColumn); - } - - public void removeSpecifiedInverseJoinColumn(JoinColumn inverseJoinColumn) { - this.removeSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.indexOf(inverseJoinColumn)); - } - - public void removeSpecifiedInverseJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedInverseJoinColumns.remove(index); - if ( ! this.hasSpecifiedInverseJoinColumns()) { - //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 = this.buildInverseJoinColumn(new NullJoinColumnAnnotation(this.getAnnotation())); - } - this.getAnnotation().removeInverseJoinColumn(index); - this.fireItemRemoved(SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultInverseJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(DEFAULT_INVERSE_JOIN_COLUMN, null, this.defaultInverseJoinColumn); - } - } - - protected void removeSpecifiedInverseJoinColumn_(JavaJoinColumn joinColumn) { - this.removeItemFromList(joinColumn, this.specifiedInverseJoinColumns, SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedInverseJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedInverseJoinColumns, targetIndex, sourceIndex); - this.getAnnotation().moveInverseJoinColumn(targetIndex, sourceIndex); - this.fireItemMoved(SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void clearSpecifiedInverseJoinColumns() { - // for now, we have to remove annotations one at a time... - for (int i = this.specifiedInverseJoinColumns.size(); i-- > 0; ) { - this.removeSpecifiedInverseJoinColumn(i); - } - } - - protected void initializeSpecifiedInverseJoinColumns(JoinTableAnnotation joinTableAnnotation) { - for (ListIterator<JoinColumnAnnotation> stream = joinTableAnnotation.inverseJoinColumns(); stream.hasNext(); ) { - this.specifiedInverseJoinColumns.add(this.buildInverseJoinColumn(stream.next())); - } - } - - protected void updateSpecifiedInverseJoinColumns(JoinTableAnnotation joinTableAnnotation) { - ListIterator<JavaJoinColumn> joinColumns = this.specifiedInverseJoinColumns(); - ListIterator<JoinColumnAnnotation> joinColumnAnnotations = joinTableAnnotation.inverseJoinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (joinColumnAnnotations.hasNext()) { - joinColumn.update(joinColumnAnnotations.next()); - } else { - this.removeSpecifiedInverseJoinColumn_(joinColumn); - } - } - - while (joinColumnAnnotations.hasNext()) { - this.addSpecifiedInverseJoinColumn(this.buildInverseJoinColumn(joinColumnAnnotations.next())); - } - } - - - // ********** Java completion proposals ********** - - @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; - } - - - // ********** misc ********** - - protected JavaJoinColumn buildJoinColumn(JoinColumnAnnotation joinColumnAnnotation, JavaJoinColumn.Owner owner) { - JavaJoinColumn joinColumn = this.getJpaFactory().buildJavaJoinColumn(this, owner); - joinColumn.initialize(joinColumnAnnotation); - return joinColumn; - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.getRelationshipMapping().shouldValidateAgainstDatabase()) { - this.validateAgainstDatabase(messages, reporter, astRoot); - } - } - - protected void validateAgainstDatabase(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - if ( ! this.hasResolvedCatalog()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_CATALOG, - new String[] {this.getCatalog(), this.getName()}, - this, - this.getCatalogTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {this.getSchema(), this.getName()}, - this, - this.getSchemaTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.isResolved()) { - if (getName() != null) { //if name is null, the validation will be handled elsewhere, such as the target entity is not defined - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange(astRoot)) - ); - } - return; - } - - this.validateJoinColumns(this.joinColumns(), messages, reporter, astRoot); - this.validateJoinColumns(this.inverseJoinColumns(), messages, reporter, astRoot); - } - - protected void validateJoinColumns(Iterator<JavaJoinColumn> joinColumns, List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - while (joinColumns.hasNext()) { - joinColumns.next().validate(messages, reporter, astRoot); - } - } - - - // ********** join column owner adapters ********** - - /** - * just a little common behavior - */ - protected abstract class AbstractJoinColumnOwner - implements JavaJoinColumn.Owner - { - protected AbstractJoinColumnOwner() { - super(); - } - - public TypeMapping getTypeMapping() { - return GenericJavaJoinTable.this.getParent().getRelationshipReference().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 "back-pointer" JoinColumns; - * these point at the source/owning entity - */ - protected class JoinColumnOwner - extends AbstractJoinColumnOwner - { - protected JoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericJavaJoinTable.this.getParent().getRelationshipReference().getEntity(); - } - - public String getAttributeName() { - Entity targetEntity = GenericJavaJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - for (PersistentAttribute each : - CollectionTools.iterable( - targetEntity.getPersistentType().allAttributes())) { - if (each.getMapping().isOwnedBy(this.getRelationshipMapping())) { - return each.getName(); - } - } - return null; - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - return (dbTable != null) ? dbTable : this.getTypeMapping().getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getReferencedColumnDbTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaJoinTable.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public int joinColumnsSize() { - return GenericJavaJoinTable.this.joinColumnsSize(); - } - } - - - /** - * owner for "forward-pointer" JoinColumns; - * these point at the target/inverse entity - */ - protected class InverseJoinColumnOwner - extends AbstractJoinColumnOwner - { - protected InverseJoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericJavaJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericJavaJoinTable.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 getReferencedColumnDbTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaJoinTable.this.defaultInverseJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public int joinColumnsSize() { - return GenericJavaJoinTable.this.inverseJoinColumnsSize(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaLobConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaLobConverter.java deleted file mode 100644 index 0ab1f95469..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaLobConverter.java +++ /dev/null @@ -1,70 +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.jpa1.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaLobConverter; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -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.core.utility.TextRange; - -public class GenericJavaLobConverter extends AbstractJavaJpaContextNode - implements JavaLobConverter -{ - private JavaResourcePersistentAttribute resourcePersistentAttribute; - - - public GenericJavaLobConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa) { - super(parent); - this.initialize(jrpa); - } - - @Override - public JavaAttributeMapping getParent() { - return (JavaAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.LOB_CONVERTER; - } - - protected String getAnnotationName() { - return LobAnnotation.ANNOTATION_NAME; - } - - public void addToResourceModel() { - this.resourcePersistentAttribute.addAnnotation(getAnnotationName()); - } - - public void removeFromResourceModel() { - this.resourcePersistentAttribute.removeAnnotation(getAnnotationName()); - } - - protected TemporalAnnotation getResourceLob() { - return (TemporalAnnotation) this.resourcePersistentAttribute. - getAnnotation(getAnnotationName()); - } - - protected void initialize(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistentAttribute = jrpa; - } - - public void update(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistentAttribute = jrpa; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return getResourceLob().getTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaManyToManyMapping.java deleted file mode 100644 index 4d0780cc47..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaManyToManyMapping.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaManyToManyMapping; - - -public class GenericJavaManyToManyMapping - extends AbstractJavaManyToManyMapping -{ - public GenericJavaManyToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaManyToOneMapping.java deleted file mode 100644 index 535861906d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaManyToOneMapping.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaManyToOneMapping; - - -public class GenericJavaManyToOneMapping - extends AbstractJavaManyToOneMapping -{ - public GenericJavaManyToOneMapping(JavaPersistentAttribute parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaMappedSuperclass.java deleted file mode 100644 index 3b19e3a6e7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaMappedSuperclass.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaMappedSuperclass; - -public class GenericJavaMappedSuperclass extends AbstractJavaMappedSuperclass -{ - - public GenericJavaMappedSuperclass(JavaPersistentType parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java deleted file mode 100644 index ab5d1a5d28..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.internal.context.java.AbstractJavaQuery; -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 getResourceQuery() { - return (NamedNativeQueryAnnotation) super.getResourceQuery(); - } - - public char getResultClassEnclosingTypeSeparator() { - return '.'; - } - - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - getResourceQuery().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; - getResourceQuery().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 initialize(NamedNativeQueryAnnotation resourceQuery) { - super.initialize(resourceQuery); - this.resultClass = resourceQuery.getResultClass(); - this.resultSetMapping = resourceQuery.getResultSetMapping(); - } - - public void update(NamedNativeQueryAnnotation resourceQuery) { - super.update(resourceQuery); - this.setResultClass_(resourceQuery.getResultClass()); - this.setResultSetMapping_(resourceQuery.getResultSetMapping()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNamedQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNamedQuery.java deleted file mode 100644 index d227c50b13..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNamedQuery.java +++ /dev/null @@ -1,38 +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.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaQuery; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; - - - -public class GenericJavaNamedQuery extends AbstractJavaQuery implements JavaNamedQuery -{ - - public GenericJavaNamedQuery(JavaJpaContextNode parent) { - super(parent); - } - - @Override - protected NamedQueryAnnotation getResourceQuery() { - return (NamedQueryAnnotation) super.getResourceQuery(); - } - - public void initialize(NamedQueryAnnotation resourceQuery) { - super.initialize(resourceQuery); - } - - public void update(NamedQueryAnnotation resourceQuery) { - super.update(resourceQuery); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNullAttributeMapping.java deleted file mode 100644 index bff9875102..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNullAttributeMapping.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaAttributeMapping; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public class GenericJavaNullAttributeMapping - extends AbstractJavaAttributeMapping<Annotation> -{ - public GenericJavaNullAttributeMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return null; - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNullConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNullConverter.java deleted file mode 100644 index 3c23fe6d0d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaNullConverter.java +++ /dev/null @@ -1,52 +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.jpa1.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaConverter; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaNullConverter extends AbstractJavaJpaContextNode - implements JavaConverter -{ - - public GenericJavaNullConverter(JavaAttributeMapping parent) { - super(parent); - } - - @Override - public JavaAttributeMapping getParent() { - return (JavaAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.NO_CONVERTER; - } - - public void addToResourceModel() { - //do nothing - } - - public void removeFromResourceModel() { - //do nothin - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return null; - } - - public void update(JavaResourcePersistentAttribute jrpa) { - //do nothing - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyMapping.java deleted file mode 100644 index 4b0dee2d33..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyMapping.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaRelationshipReference; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToManyMapping; - - -public class GenericJavaOneToManyMapping - extends AbstractJavaOneToManyMapping -{ - - public GenericJavaOneToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - - @Override - protected JavaRelationshipReference buildRelationshipReference() { - return new GenericJavaOneToManyRelationshipReference(this); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyRelationshipReference.java deleted file mode 100644 index d85cb0692e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToManyRelationshipReference.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToManyRelationshipReference; - -public class GenericJavaOneToManyRelationshipReference - extends AbstractJavaOneToManyRelationshipReference -{ - - public GenericJavaOneToManyRelationshipReference(JavaOneToManyMapping parent) { - super(parent); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - return this.joinTableJoiningStrategy; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToOneMapping.java deleted file mode 100644 index 365e45a6da..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaOneToOneMapping.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToOneMapping; - - -public class GenericJavaOneToOneMapping - extends AbstractJavaOneToOneMapping -{ - public GenericJavaOneToOneMapping(JavaPersistentAttribute parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentAttribute.java deleted file mode 100644 index 7d052c2afb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentAttribute.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; - -/** - * Generic Java persistent attribute - */ -public class GenericJavaPersistentAttribute - extends AbstractJavaPersistentAttribute -{ - - public GenericJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa) { - super(parent, jrpa); - } - - - // ********** AccessHolder implementation ********** - - /** - * GenericJavaPersistentAttribute does not support specified access (no access element in 1.0), so we return null - */ - public AccessType getSpecifiedAccess() { - return null; - } - - public void setSpecifiedAccess(AccessType specifiedAccess) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentType.java deleted file mode 100644 index 963887add8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentType.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -public class GenericJavaPersistentType - extends AbstractJavaPersistentType -{ - - public GenericJavaPersistentType(PersistentType.Owner parent, JavaResourcePersistentType jrpt) { - super(parent, jrpt); - } - - - // **************** access type ******************************************* - - /** - * GenericJavaPersistentType does not support specified access (no Access annotation in 1.0), - * so we return null - */ - @Override - protected AccessType buildSpecifiedAccess() { - return null; - } - - /** - * GenericJavaPersistentType does not support specified access (no Access annotation in 1.0) - */ - public void setSpecifiedAccess(AccessType specifiedAccess) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java deleted file mode 100644 index ddfa8a782e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.internal.context.java.AbstractJavaNamedColumn; -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 resourcePrimaryKeyJoinColumn; - - public GenericJavaPrimaryKeyJoinColumn(JavaJpaContextNode parent, JavaBaseJoinColumn.Owner owner) { - super(parent, owner); - } - - @Override - public void initialize(PrimaryKeyJoinColumnAnnotation column) { - this.resourcePrimaryKeyJoinColumn = column; - super.initialize(column); - this.specifiedReferencedColumnName = this.getResourceReferencedColumnName(column); - this.defaultReferencedColumnName = this.buildDefaultReferencedColumnName(); - } - - //************** JavaNamedColumn implementation *************** - @Override - public JavaBaseJoinColumn.Owner getOwner() { - return (JavaBaseJoinColumn.Owner) super.getOwner(); - } - - @Override - protected PrimaryKeyJoinColumnAnnotation getResourceColumn() { - return this.resourcePrimaryKeyJoinColumn; - } - - //************** 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; - getResourceColumn().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().getPrimaryTableName(); - } - - public Column getReferencedDbColumn() { - Table table = this.getReferencedColumnDbTable(); - return (table == null) ? null : table.getColumnForIdentifier(this.getReferencedColumnName()); - } - - public Table getReferencedColumnDbTable() { - return getOwner().getReferencedColumnDbTable(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.getResourceColumn().referencedColumnNameTouches(pos, astRoot); - } - - @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.javaCandidateReferencedColumnNames(filter); - } - return null; - } - - private Iterator<String> javaCandidateReferencedColumnNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateReferencedColumnNames(filter)); - } - - private Iterator<String> candidateReferencedColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateReferencedColumnNames(), filter); - } - - private Iterator<String> candidateReferencedColumnNames() { - Table table = this.getOwner().getReferencedColumnDbTable(); - return (table != null) ? table.sortedColumnIdentifiers() : EmptyIterator.<String> instance(); - } - - public boolean isReferencedColumnResolved() { - return getReferencedDbColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return this.getResourceColumn().getReferencedColumnNameTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getResourceColumn().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - @Override - public void update(PrimaryKeyJoinColumnAnnotation resourceColumn) { - this.resourcePrimaryKeyJoinColumn = resourceColumn; - super.update(resourceColumn); - this.setSpecifiedReferencedColumnName_(this.getResourceReferencedColumnName(resourceColumn)); - this.setDefaultReferencedColumnName(this.buildDefaultReferencedColumnName()); - } - - protected String getResourceReferencedColumnName(PrimaryKeyJoinColumnAnnotation resourceColumn) { - return resourceColumn.getReferencedColumnName(); - } - - //TODO not correct when we start supporting primaryKeyJoinColumns in 1-1 mappings - protected String buildDefaultReferencedColumnName() { - return buildDefaultName(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append("=>"); //$NON-NLS-1$ - sb.append(this.getReferencedColumnName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryContainer.java deleted file mode 100644 index 3baaedc7bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryContainer.java +++ /dev/null @@ -1,293 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaQueryContainer; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -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.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.NestableAnnotation; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode - implements JavaQueryContainer -{ - protected JavaResourcePersistentMember javaResourcePersistentMember; - - protected final List<JavaNamedQuery> namedQueries; - - protected final List<JavaNamedNativeQuery> namedNativeQueries; - - public GenericJavaQueryContainer(JavaJpaContextNode parent) { - super(parent); - this.namedQueries = new ArrayList<JavaNamedQuery>(); - this.namedNativeQueries = new ArrayList<JavaNamedNativeQuery>(); - } - - @Override - public JavaJpaContextNode getParent() { - return (JavaJpaContextNode) super.getParent(); - } - - - 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.javaResourcePersistentMember. - addAnnotation( - index, NamedQueryAnnotation.ANNOTATION_NAME, - NamedQueriesAnnotation.ANNOTATION_NAME); - namedQuery.initialize(namedQueryAnnotation); - fireItemAdded(NAMED_QUERIES_LIST, index, namedQuery); - return namedQuery; - } - - protected void addNamedQuery(int index, JavaNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, NAMED_QUERIES_LIST); - } - - protected void addNamedQuery(JavaNamedQuery namedQuery) { - this.addNamedQuery(this.namedQueries.size(), namedQuery); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - JavaNamedQuery removedNamedQuery = this.namedQueries.remove(index); - this.javaResourcePersistentMember.removeAnnotation( - index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - fireItemRemoved(NAMED_QUERIES_LIST, index, removedNamedQuery); - } - - protected void removeNamedQuery_(JavaNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - this.javaResourcePersistentMember.moveAnnotation( - targetIndex, sourceIndex, NamedQueriesAnnotation.ANNOTATION_NAME); - fireItemMoved(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.javaResourcePersistentMember. - addAnnotation( - index, NamedNativeQueryAnnotation.ANNOTATION_NAME, - NamedNativeQueriesAnnotation.ANNOTATION_NAME); - namedNativeQuery.initialize(namedNativeQueryAnnotation); - fireItemAdded(NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - return namedNativeQuery; - } - - protected void addNamedNativeQuery(int index, JavaNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); - } - - protected void addNamedNativeQuery(JavaNamedNativeQuery namedNativeQuery) { - this.addNamedNativeQuery(this.namedNativeQueries.size(), namedNativeQuery); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - this.removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - JavaNamedNativeQuery removedNamedNativeQuery = this.namedNativeQueries.remove(index); - this.javaResourcePersistentMember.removeAnnotation( - index, NamedNativeQueryAnnotation.ANNOTATION_NAME, - NamedNativeQueriesAnnotation.ANNOTATION_NAME); - fireItemRemoved(NAMED_NATIVE_QUERIES_LIST, index, removedNamedNativeQuery); - } - - protected void removeNamedNativeQuery_(JavaNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - this.javaResourcePersistentMember.moveAnnotation( - targetIndex, sourceIndex, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - fireItemMoved(NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); - } - - - - public void initialize(JavaResourcePersistentMember jrpm) { - this.javaResourcePersistentMember = jrpm; - this.initializeNamedQueries(); - this.initializeNamedNativeQueries(); - } - - protected void initializeNamedQueries() { - for (Iterator<NestableAnnotation> stream = this.javaResourcePersistentMember. - annotations( - NamedQueryAnnotation.ANNOTATION_NAME, - NamedQueriesAnnotation.ANNOTATION_NAME); - stream.hasNext(); ) { - this.namedQueries.add(buildNamedQuery((NamedQueryAnnotation) stream.next())); - } - } - - protected void initializeNamedNativeQueries() { - for (Iterator<NestableAnnotation> stream = this.javaResourcePersistentMember. - annotations( - NamedNativeQueryAnnotation.ANNOTATION_NAME, - NamedNativeQueriesAnnotation.ANNOTATION_NAME); - stream.hasNext(); ) { - this.namedNativeQueries.add(buildNamedNativeQuery((NamedNativeQueryAnnotation) stream.next())); - } - } - - protected JavaNamedQuery buildNamedQuery(NamedQueryAnnotation namedQueryResource) { - JavaNamedQuery namedQuery = getJpaFactory().buildJavaNamedQuery(this); - namedQuery.initialize(namedQueryResource); - return namedQuery; - } - - protected JavaNamedNativeQuery buildNamedNativeQuery(NamedNativeQueryAnnotation namedNativeQueryResource) { - JavaNamedNativeQuery namedNativeQuery = getJpaFactory().buildJavaNamedNativeQuery(this); - namedNativeQuery.initialize(namedNativeQueryResource); - return namedNativeQuery; - } - - public void update(JavaResourcePersistentMember jrpm) { - this.javaResourcePersistentMember = jrpm; - this.updateNamedQueries(); - this.updateNamedNativeQueries(); - } - - protected void updateNamedQueries() { - ListIterator<JavaNamedQuery> queries = namedQueries(); - Iterator<NestableAnnotation> resourceNamedQueries = - this.javaResourcePersistentMember.annotations( - NamedQueryAnnotation.ANNOTATION_NAME, - NamedQueriesAnnotation.ANNOTATION_NAME); - - while (queries.hasNext()) { - JavaNamedQuery namedQuery = queries.next(); - if (resourceNamedQueries.hasNext()) { - namedQuery.update((NamedQueryAnnotation) resourceNamedQueries.next()); - } - else { - removeNamedQuery_(namedQuery); - } - } - - while (resourceNamedQueries.hasNext()) { - addNamedQuery(buildNamedQuery((NamedQueryAnnotation) resourceNamedQueries.next())); - } - } - - protected void updateNamedNativeQueries() { - ListIterator<JavaNamedNativeQuery> queries = namedNativeQueries(); - Iterator<NestableAnnotation> resourceNamedNativeQueries = - this.javaResourcePersistentMember.annotations( - NamedNativeQueryAnnotation.ANNOTATION_NAME, - NamedNativeQueriesAnnotation.ANNOTATION_NAME); - - while (queries.hasNext()) { - JavaNamedNativeQuery namedQuery = queries.next(); - if (resourceNamedNativeQueries.hasNext()) { - namedQuery.update((NamedNativeQueryAnnotation) resourceNamedNativeQueries.next()); - } - else { - removeNamedNativeQuery_(namedQuery); - } - } - - while (resourceNamedNativeQueries.hasNext()) { - addNamedNativeQuery(buildNamedNativeQuery((NamedNativeQueryAnnotation) resourceNamedNativeQueries.next())); - } - } - - - //********** Validation ******************************************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - this.validateQueries(messages, astRoot); - } - - protected void validateQueries(List<IMessage> messages, CompilationUnit astRoot) { - for (Iterator<JavaQuery> localQueries = this.queries(); localQueries.hasNext(); ) { - JavaQuery localQuery = localQueries.next(); - for (Iterator<Query> globalQueries = this.getPersistenceUnit().queries(); globalQueries.hasNext(); ) { - if (localQuery.duplicates(globalQueries.next())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {localQuery.getName()}, - localQuery, - localQuery.getNameTextRange(astRoot) - ) - ); - } - } - } - } - - - @SuppressWarnings("unchecked") - public Iterator<JavaQuery> queries() { - return new CompositeIterator<JavaQuery>(this.namedNativeQueries(), this.namedQueries()); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.javaResourcePersistentMember.getTextRange(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryHint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryHint.java deleted file mode 100644 index e1e3b48891..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryHint.java +++ /dev/null @@ -1,77 +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.jpa1.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.internal.context.java.AbstractJavaJpaContextNode; -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 resourceQueryHint; - - 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.resourceQueryHint.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.resourceQueryHint.setValue(newValue); - firePropertyChanged(QueryHint.VALUE_PROPERTY, oldValue, newValue); - } - - - public void initialize(QueryHintAnnotation resourceQueryHint) { - this.resourceQueryHint = resourceQueryHint; - this.name = resourceQueryHint.getName(); - this.value = resourceQueryHint.getValue(); - } - - public void update(QueryHintAnnotation resourceQueryHint) { - this.resourceQueryHint = resourceQueryHint; - this.setName(resourceQueryHint.getName()); - this.setValue(resourceQueryHint.getValue()); - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.resourceQueryHint.getTextRange(astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaSecondaryTable.java deleted file mode 100644 index f39103bdf1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaSecondaryTable.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.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.context.java.AbstractJavaTable; -import org.eclipse.jpt.core.internal.resource.java.NullPrimaryKeyJoinColumnAnnotation; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * - */ -public class GenericJavaSecondaryTable - extends AbstractJavaTable - implements JavaSecondaryTable -{ - protected final List<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - protected final JavaBaseJoinColumn.Owner primaryKeyJoinColumnOwner; - - protected JavaPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - protected SecondaryTableAnnotation resourceSecondaryTable; - - public GenericJavaSecondaryTable(JavaEntity parent) { - super(parent); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - this.primaryKeyJoinColumnOwner = this.buildPrimaryKeyJoinColumnOwner(); - } - - protected JavaBaseJoinColumn.Owner buildPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - @Override - public JavaEntity getParent() { - return (JavaEntity) super.getParent(); - } - - - //***************** AbstractJavaTable implementation ******************** - - @Override - protected String getAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - - @Override - protected SecondaryTableAnnotation getAnnotation() { - return this.resourceSecondaryTable; - } - - public boolean isResourceSpecified() { - return true; - } - - // a secondary table doesn't have a default name - @Override - protected String buildDefaultName() { - return null; - } - - @Override - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - @Override - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - - //***************** 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(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) { - // Clear out the default now so it doesn't get removed during an update and - // cause change notifications to be sent to the UI in the wrong order. - JavaPrimaryKeyJoinColumn oldDefault = this.defaultPrimaryKeyJoinColumn; - this.defaultPrimaryKeyJoinColumn = null; - - JavaPrimaryKeyJoinColumn pkJoinColumn = this.getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, this.primaryKeyJoinColumnOwner); - this.specifiedPrimaryKeyJoinColumns.add(index, pkJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnAnnotation = this.resourceSecondaryTable.addPkJoinColumn(index); - pkJoinColumn.initialize(pkJoinColumnAnnotation); - this.fireItemAdded(SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, pkJoinColumn); - - this.firePropertyChanged(DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefault, null); - return pkJoinColumn; - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.addSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.size(), primaryKeyJoinColumn); - } - - 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 NullPrimaryKeyJoinColumnAnnotation(this.resourceSecondaryTable)); - } - this.resourceSecondaryTable.removePkJoinColumn(index); - fireItemRemoved(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, SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.resourceSecondaryTable.movePkJoinColumn(targetIndex, sourceIndex); - fireItemMoved(SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public JavaEntity getJavaEntity() { - return getParent(); - } - - - //********************* updating ************************ - - public void initialize(SecondaryTableAnnotation secondaryTable) { - super.initialize(secondaryTable); - this.resourceSecondaryTable = 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 NullPrimaryKeyJoinColumnAnnotation(secondaryTable)); - } - - - public void update(SecondaryTableAnnotation sta) { - this.resourceSecondaryTable = sta; - super.update(sta); - this.updateSpecifiedPrimaryKeyJoinColumns(sta); - this.updateDefaultPrimaryKeyJoinColumn(sta); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns(SecondaryTableAnnotation sta) { - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<PrimaryKeyJoinColumnAnnotation> resourcePrimaryKeyJoinColumns = sta.pkJoinColumns(); - - while (primaryKeyJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update(resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(resourcePrimaryKeyJoinColumns.next())); - } - } - - protected void updateDefaultPrimaryKeyJoinColumn(SecondaryTableAnnotation sta) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumnAnnotation(sta))); - } - else { - this.defaultPrimaryKeyJoinColumn.update(new NullPrimaryKeyJoinColumnAnnotation(sta)); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation resourcePrimaryKeyJoinColumn) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, this.primaryKeyJoinColumnOwner); - primaryKeyJoinColumn.initialize(resourcePrimaryKeyJoinColumn); - return primaryKeyJoinColumn; - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.connectionProfileIsActive()) { - this.validateAgainstDatabase(messages, astRoot); - } - for (Iterator<JavaPrimaryKeyJoinColumn> stream = this.primaryKeyJoinColumns(); stream.hasNext(); ) { - stream.next().validate(messages, reporter, astRoot); - } - } - - protected void validateAgainstDatabase(List<IMessage> messages, CompilationUnit astRoot) { - if ( ! this.hasResolvedCatalog()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_CATALOG, - new String[] {this.getCatalog(), this.getName()}, - this, - this.getCatalogTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_SCHEMA, - new String[] {this.getSchema(), this.getName()}, - this, - this.getSchemaTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange(astRoot) - ) - ); - return; - } - } - - - // ********** 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; - } - - - // ********** PK join column owner adapter ********** - - protected 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 getReferencedColumnDbTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaSecondaryTable.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return getJavaEntity().getPrimaryKeyColumnName(); - - } - - private int joinColumnsSize() { - return GenericJavaSecondaryTable.this.primaryKeyJoinColumnsSize(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaSequenceGenerator.java deleted file mode 100644 index 66ff8640b4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaSequenceGenerator.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaSequenceGenerator; - -/** - * - */ -public class GenericJavaSequenceGenerator extends AbstractJavaSequenceGenerator -{ - - public GenericJavaSequenceGenerator(JavaJpaContextNode parent) { - super(parent); - } - - // ********** database stuff ********** - - /** - * The JPA spec does not allow a sequence to have a schema. - */ - @Override - protected String getSchema() { - return this.getContextDefaultSchema(); - } - - /** - * The JPA spec does not allow a sequence to have a catalog. - */ - @Override - protected String getCatalog() { - return this.getContextDefaultCatalog(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTable.java deleted file mode 100644 index ec81d5fb15..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTable.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaTable; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaTable - extends AbstractJavaTable - implements JavaTable -{ - protected JavaResourcePersistentMember resourcePersistentMember; - - public GenericJavaTable(JavaEntity parent) { - super(parent); - } - - public void initialize(JavaResourcePersistentMember pr) { - this.resourcePersistentMember = pr; - initialize(getAnnotation()); - } - - //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 getAnnotation() { - //TODO get the NullTable from the resource model or build it here in the context model?? - return (TableAnnotation) this.resourcePersistentMember. - getNonNullAnnotation(getAnnotationName()); - } - - public boolean isResourceSpecified() { - return getAnnotation().isSpecified(); - } - - @Override - protected String getAnnotationName() { - return TableAnnotation.ANNOTATION_NAME; - } - - @Override - public JavaEntity getParent() { - return (JavaEntity) super.getParent(); - } - - protected JavaEntity getJavaEntity() { - return getParent(); - } - - @Override - protected String buildDefaultName() { - return this.getJavaEntity().getDefaultTableName(); - } - - /** - * Just to remember: - * Entity.getDefaultSchema() - * check inheritance - get default schema from root - * EntityMappings.getSchema() - * check for specified schema - * PersistenceUnit.getDefaultSchema() - * OrmPersistenceUnitDefaults.getSchema() - * JpaProject.getDefaultSchema() - * check for user override project setting - * Catalog.getDefaultSchema() - * or - * Database.getDefaultSchema() - */ - @Override - protected String buildDefaultSchema() { - return this.getJavaEntity().getDefaultSchema(); - } - - @Override - protected String buildDefaultCatalog() { - return this.getJavaEntity().getDefaultCatalog(); - } - - public void update(JavaResourcePersistentMember jrpm) { - this.resourcePersistentMember = jrpm; - this.update(getAnnotation()); - } - - - //******************* validation ********************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - if (this.connectionProfileIsActive()) { - this.validateAgainstDatabase(messages, astRoot); - } - } - - protected void validateAgainstDatabase(List<IMessage> messages, CompilationUnit astRoot) { - if ( ! this.hasResolvedCatalog()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_CATALOG, - new String[] {this.getCatalog(), this.getName()}, - this, - this.getCatalogTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA, - new String[] {this.getSchema(), this.getName()}, - this, - this.getSchemaTextRange(astRoot) - ) - ); - return; - } - - if ( ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange(astRoot) - ) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java deleted file mode 100644 index bb598dfa4d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTableGenerator.java +++ /dev/null @@ -1,531 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaGenerator; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -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.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 class GenericJavaTableGenerator - extends AbstractJavaGenerator - implements JavaTableGenerator, UniqueConstraint.Owner -{ - protected String specifiedTable; - protected String defaultTable; - - protected String specifiedSchema; - protected String defaultSchema; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedPkColumnName; - protected String defaultPkColumnName; - - protected String specifiedValueColumnName; - protected String defaultValueColumnName; - - protected String specifiedPkColumnValue; - protected String defaultPkColumnValue; - - protected final List<JavaUniqueConstraint> uniqueConstraints; - - - // ********** constructor ********** - - public GenericJavaTableGenerator(JavaJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<JavaUniqueConstraint>(); - } - - - // ********** table ********** - - public String getTable() { - return (this.specifiedTable != null) ? this.specifiedTable : this.defaultTable; - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String table) { - String old = this.specifiedTable; - this.specifiedTable = table; - this.getResourceGenerator().setTable(table); - this.firePropertyChanged(SPECIFIED_TABLE_PROPERTY, old, table); - } - - protected void setSpecifiedTable_(String table) { - String old = this.specifiedTable; - this.specifiedTable = table; - this.firePropertyChanged(SPECIFIED_TABLE_PROPERTY, old, table); - } - - /** - * The default table is determined by the JPA implementation. - */ - public String getDefaultTable() { - return this.defaultTable; - } - - - // ********** schema ********** - - @Override - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.getResourceGenerator().setSchema(schema); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - protected void setSpecifiedSchema_(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - - // ********** catalog ********** - - @Override - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.getResourceGenerator().setCatalog(catalog); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - protected void setSpecifiedCatalog_(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - - // ********** primary key column name ********** - - public String getPkColumnName() { - return (this.specifiedPkColumnName != null) ? this.specifiedPkColumnName : this.defaultPkColumnName; - } - - public String getSpecifiedPkColumnName() { - return this.specifiedPkColumnName; - } - - public void setSpecifiedPkColumnName(String name) { - String old = this.specifiedPkColumnName; - this.specifiedPkColumnName = name; - this.getResourceGenerator().setPkColumnName(name); - this.firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, old, name); - } - - protected void setSpecifiedPkColumnName_(String name) { - String old = this.specifiedPkColumnName; - this.specifiedPkColumnName = name; - this.firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, old, name); - } - - /** - * The default primary key column name is determined by the JPA - * implementation. - */ - public String getDefaultPkColumnName() { - return this.defaultPkColumnName; - } - - - // ********** value column name ********** - - public String getValueColumnName() { - return (this.specifiedValueColumnName != null) ? this.specifiedValueColumnName : this.defaultValueColumnName; - } - - public String getSpecifiedValueColumnName() { - return this.specifiedValueColumnName; - } - - public void setSpecifiedValueColumnName(String name) { - String old = this.specifiedValueColumnName; - this.specifiedValueColumnName = name; - this.getResourceGenerator().setValueColumnName(name); - this.firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, old, name); - } - - protected void setSpecifiedValueColumnName_(String name) { - String old = this.specifiedValueColumnName; - this.specifiedValueColumnName = name; - this.firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, old, name); - } - - public String getDefaultValueColumnName() { - return this.defaultValueColumnName; - } - - - // ********** primary key column value ********** - - public String getPkColumnValue() { - return (this.specifiedPkColumnValue != null) ? this.specifiedPkColumnValue : this.defaultPkColumnValue; - } - - public String getSpecifiedPkColumnValue() { - return this.specifiedPkColumnValue; - } - - public void setSpecifiedPkColumnValue(String value) { - String old = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = value; - this.getResourceGenerator().setPkColumnValue(value); - this.firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, old, value); - } - - protected void setSpecifiedPkColumnValue_(String value) { - String old = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = value; - this.firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, old, value); - } - - 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.getResourceGenerator().addUniqueConstraint(index); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - this.fireItemAdded(UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - JavaUniqueConstraint uniqueConstraint = this.uniqueConstraints.remove(index); - this.getResourceGenerator().removeUniqueConstraint(index); - this.fireItemRemoved(UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getResourceGenerator().moveUniqueConstraint(targetIndex, sourceIndex); - this.fireItemMoved(UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void addUniqueConstraint(int index, JavaUniqueConstraint uniqueConstraint) { - this.addItemToList(index, uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - protected void addUniqueConstraint(JavaUniqueConstraint uniqueConstraint) { - this.addUniqueConstraint(this.uniqueConstraints.size(), uniqueConstraint); - } - - protected void removeUniqueConstraint_(JavaUniqueConstraint uniqueConstraint) { - this.removeItemFromList(uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.sortedColumnIdentifiers() : EmptyIterator.<String>instance(); - } - - - // ********** resource => context ********** - - public void initialize(TableGeneratorAnnotation tableGeneratorAnnotation) { - super.initialize(tableGeneratorAnnotation); - this.specifiedTable = tableGeneratorAnnotation.getTable(); - this.defaultSchema = this.buildDefaultSchema(); - this.specifiedSchema = tableGeneratorAnnotation.getSchema(); - this.defaultCatalog = this.buildDefaultCatalog(); - this.specifiedCatalog = tableGeneratorAnnotation.getCatalog(); - this.specifiedPkColumnName = tableGeneratorAnnotation.getPkColumnName(); - this.specifiedValueColumnName = tableGeneratorAnnotation.getValueColumnName(); - this.specifiedPkColumnValue = tableGeneratorAnnotation.getPkColumnValue(); - this.initializeUniqueConstraints(tableGeneratorAnnotation); - } - - protected void initializeUniqueConstraints(TableGeneratorAnnotation tableGeneratorAnnotation) { - for (Iterator<UniqueConstraintAnnotation> stream = tableGeneratorAnnotation.uniqueConstraints(); stream.hasNext(); ) { - this.uniqueConstraints.add(this.buildUniqueConstraint(stream.next())); - } - } - - public void update(TableGeneratorAnnotation tableGeneratorAnnotation) { - super.update(tableGeneratorAnnotation); - this.setSpecifiedTable_(tableGeneratorAnnotation.getTable()); - this.setDefaultSchema(this.buildDefaultSchema()); - this.setSpecifiedSchema_(tableGeneratorAnnotation.getSchema()); - this.setDefaultCatalog(this.buildDefaultCatalog()); - this.setSpecifiedCatalog_(tableGeneratorAnnotation.getCatalog()); - this.setSpecifiedPkColumnName_(tableGeneratorAnnotation.getPkColumnName()); - this.setSpecifiedValueColumnName_(tableGeneratorAnnotation.getValueColumnName()); - this.setSpecifiedPkColumnValue_(tableGeneratorAnnotation.getPkColumnValue()); - this.updateUniqueConstraints(tableGeneratorAnnotation); - } - - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - protected void updateUniqueConstraints(TableGeneratorAnnotation tableGeneratorAnnotation) { - ListIterator<JavaUniqueConstraint> contextConstraints = this.uniqueConstraints(); - ListIterator<UniqueConstraintAnnotation> resourceConstraints = tableGeneratorAnnotation.uniqueConstraints(); - - while (contextConstraints.hasNext()) { - JavaUniqueConstraint uniqueConstraint = contextConstraints.next(); - if (resourceConstraints.hasNext()) { - uniqueConstraint.update(resourceConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceConstraints.hasNext()) { - addUniqueConstraint(buildUniqueConstraint(resourceConstraints.next())); - } - } - - protected JavaUniqueConstraint buildUniqueConstraint(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - return uniqueConstraint; - } - - - // ********** database stuff ********** - - public Table getDbTable() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema == null) ? null : dbSchema.getTableForIdentifier(this.getTable()); - } - - - // ********** Java completion proposals ********** - - @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: - * table, schema, catalog, pkColumnName, valueColumnName - */ - @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.tableTouches(pos, astRoot)) { - return this.javaCandidateTables(filter); - } - if (this.schemaTouches(pos, astRoot)) { - return this.javaCandidateSchemata(filter); - } - if (this.catalogTouches(pos, astRoot)) { - return this.javaCandidateCatalogs(filter); - } - if (this.pkColumnNameTouches(pos, astRoot)) { - return this.javaCandidateColumnNames(filter); - } - if (this.valueColumnNameTouches(pos, astRoot)) { - return this.javaCandidateColumnNames(filter); - } - return null; - } - - // ********** code assist: table - - protected boolean tableTouches(int pos, CompilationUnit astRoot) { - return this.getResourceGenerator().tableTouches(pos, astRoot); - } - - protected Iterator<String> javaCandidateTables(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateTables(filter)); - } - - protected Iterator<String> candidateTables(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateTables(), filter); - } - - protected Iterator<String> candidateTables() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema != null) ? dbSchema.sortedTableIdentifiers() : EmptyIterator.<String> instance(); - } - - // ********** code assist: schema - - protected boolean schemaTouches(int pos, CompilationUnit astRoot) { - return this.getResourceGenerator().schemaTouches(pos, astRoot); - } - - protected Iterator<String> javaCandidateSchemata(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateSchemata(filter)); - } - - protected Iterator<String> candidateSchemata(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateSchemata(), filter); - } - - protected Iterator<String> candidateSchemata() { - SchemaContainer schemaContainer = this.getDbSchemaContainer(); - return (schemaContainer != null) ? schemaContainer.sortedSchemaIdentifiers() : EmptyIterator.<String> instance(); - } - - // ********** code assist: catalog - - protected boolean catalogTouches(int pos, CompilationUnit astRoot) { - return this.getResourceGenerator().catalogTouches(pos, astRoot); - } - - protected Iterator<String> javaCandidateCatalogs(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateCatalogs(filter)); - } - - protected Iterator<String> candidateCatalogs(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateCatalogs(), filter); - } - - protected Iterator<String> candidateCatalogs() { - Database db = this.getDatabase(); - return (db != null) ? db.sortedCatalogIdentifiers() : EmptyIterator.<String> instance(); - } - - // ********** code assist: pkColumnName - - protected boolean pkColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.getResourceGenerator().pkColumnNameTouches(pos, astRoot); - } - - protected Iterator<String> javaCandidateColumnNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateColumnNames(filter)); - } - - protected Iterator<String> candidateColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateColumnNames(), filter); - } - - protected Iterator<String> candidateColumnNames() { - Table table = this.getDbTable(); - return (table != null) ? table.sortedColumnIdentifiers() : EmptyIterator.<String> instance(); - } - - // ********** code assist: valueColumnName - - protected boolean valueColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.getResourceGenerator().valueColumnNameTouches(pos, astRoot); - } - - - // ********** misc ********** - - @Override - protected TableGeneratorAnnotation getResourceGenerator() { - return (TableGeneratorAnnotation) super.getResourceGenerator(); - } - - public int getDefaultInitialValue() { - return DEFAULT_INITIAL_VALUE; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java deleted file mode 100644 index c52983e206..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java +++ /dev/null @@ -1,95 +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.jpa1.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaTemporalConverter; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaTemporalConverter extends AbstractJavaJpaContextNode - implements JavaTemporalConverter -{ - private TemporalType temporalType; - - private JavaResourcePersistentAttribute resourcePersistentAttribute; - - public GenericJavaTemporalConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa) { - super(parent); - this.initialize(jrpa); - } - - @Override - public JavaAttributeMapping getParent() { - return (JavaAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.TEMPORAL_CONVERTER; - } - - protected String getAnnotationName() { - return TemporalAnnotation.ANNOTATION_NAME; - } - - public void addToResourceModel() { - this.resourcePersistentAttribute.addAnnotation(getAnnotationName()); - } - - public void removeFromResourceModel() { - this.resourcePersistentAttribute.removeAnnotation(getAnnotationName()); - } - - public TemporalType getTemporalType() { - return this.temporalType; - } - - public void setTemporalType(TemporalType newTemporalType) { - TemporalType oldTemporalType = this.temporalType; - this.temporalType = newTemporalType; - this.getResourceTemporal().setValue(TemporalType.toJavaResourceModel(newTemporalType)); - firePropertyChanged(TEMPORAL_TYPE_PROPERTY, oldTemporalType, newTemporalType); - } - - protected void setTemporalType_(TemporalType newTemporalType) { - TemporalType oldTemporalType = this.temporalType; - this.temporalType = newTemporalType; - firePropertyChanged(TEMPORAL_TYPE_PROPERTY, oldTemporalType, newTemporalType); - } - - - protected TemporalAnnotation getResourceTemporal() { - return (TemporalAnnotation) this.resourcePersistentAttribute. - getAnnotation(getAnnotationName()); - } - - protected void initialize(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistentAttribute = jrpa; - this.temporalType = this.temporalType(getResourceTemporal()); - } - - public void update(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistentAttribute = jrpa; - this.setTemporalType_(this.temporalType(getResourceTemporal())); - } - - protected TemporalType temporalType(TemporalAnnotation resourceTemporal) { - return resourceTemporal == null ? null : TemporalType.fromJavaResourceModel(resourceTemporal.getValue()); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getResourceTemporal().getTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTransientMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTransientMapping.java deleted file mode 100644 index 51023530d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTransientMapping.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaAttributeMapping; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -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; - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.java deleted file mode 100644 index 64246c7f3d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaUniqueConstraint.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.jpa1.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.internal.context.java.AbstractJavaJpaContextNode; -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 resourceUniqueConstraint; - - 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.resourceUniqueConstraint.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.resourceUniqueConstraint.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.resourceUniqueConstraint.moveColumnName(targetIndex, sourceIndex); - fireItemMoved(UniqueConstraint.COLUMN_NAMES_LIST, targetIndex, sourceIndex); - } - - public void initialize(UniqueConstraintAnnotation uca) { - this.resourceUniqueConstraint = uca; - this.initializeColumnNames(uca); - } - - protected void initializeColumnNames(UniqueConstraintAnnotation uca) { - ListIterator<String> annotationColumnNames = uca.columnNames(); - - for (String resourceColumnName : CollectionTools.iterable(annotationColumnNames)) { - this.columnNames.add(resourceColumnName); - } - } - - public void update(UniqueConstraintAnnotation uca) { - this.resourceUniqueConstraint = uca; - this.updateColumnNames(uca); - } - - protected void updateColumnNames(UniqueConstraintAnnotation uca) { - ListIterator<String> annotationColumnNames = uca.columnNames(); - - int index = 0; - for (String resourceColumnName : CollectionTools.iterable(annotationColumnNames)) { - if (columnNamesSize() > index) { - if (this.columnNames.get(index) != resourceColumnName) { - addColumnName_(index, resourceColumnName); - } - } - else { - addColumnName_(index, resourceColumnName); - } - index++; - } - - for ( ; index < columnNamesSize(); ) { - removeColumnName_(index); - } - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.resourceUniqueConstraint.getTextRange(astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.columnNames); - } - - - // ********** code-assist ********** - - @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.javaCandidateColumnNames(filter); - } - return null; - } - - private boolean columnNamesTouches(int pos, CompilationUnit astRoot) { - return this.resourceUniqueConstraint.columnNamesTouches(pos, astRoot); - } - - private Iterator<String> javaCandidateColumnNames(Filter<String> filter) { - return StringTools.convertToJavaStringLiterals(this.candidateColumnNames(filter)); - } - - private Iterator<String> candidateColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateColumnNames(), filter); - } - - private Iterator<String> candidateColumnNames() { - return this.getOwner().candidateUniqueConstraintColumnNames(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaVersionMapping.java deleted file mode 100644 index 2c989ab68a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaVersionMapping.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaVersionMapping; - - -public class GenericJavaVersionMapping - extends AbstractJavaVersionMapping -{ - - public GenericJavaVersionMapping(JavaPersistentAttribute parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/NullJavaAssociationOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/NullJavaAssociationOverrideContainer.java deleted file mode 100644 index 9905c47733..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/NullJavaAssociationOverrideContainer.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public class NullJavaAssociationOverrideContainer extends AbstractJavaJpaContextNode - implements JavaAssociationOverrideContainer -{ - protected final AssociationOverrideContainer.Owner owner; - - public NullJavaAssociationOverrideContainer(JavaJpaContextNode parent, AssociationOverrideContainer.Owner owner) { - super(parent); - this.owner = owner; - } - - public void initialize(JavaResourcePersistentMember jrpm) { - // no-op - } - - public void update(JavaResourcePersistentMember jrpm) { - // no-op - } - - public Owner getOwner() { - return this.owner; - } - - public JavaAssociationOverride getAssociationOverrideNamed(String name) { - return null; - } - - @SuppressWarnings("unchecked") - public ListIterator<JavaAssociationOverride> associationOverrides() { - return EmptyListIterator.instance(); - } - - public int associationOverridesSize() { - return 0; - } - - public ListIterator<JavaAssociationOverride> virtualAssociationOverrides() { - return EmptyListIterator.instance(); - } - - public int virtualAssociationOverridesSize() { - return 0; - } - - public ListIterator<JavaAssociationOverride> specifiedAssociationOverrides() { - return EmptyListIterator.instance(); - } - - public int specifiedAssociationOverridesSize() { - return 0; - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - - //********** Validation ******************************************** - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/VirtualAssociationOverride1_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/VirtualAssociationOverride1_0Annotation.java deleted file mode 100644 index 2738d5cfb1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/VirtualAssociationOverride1_0Annotation.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.java; - -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.internal.context.java.VirtualAssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; - -/** - * javax.persistence.AssociationOverride - */ -public class VirtualAssociationOverride1_0Annotation - extends VirtualAssociationOverrideAnnotation -{ - - public VirtualAssociationOverride1_0Annotation(JavaResourcePersistentMember parent, String name, JoiningStrategy joiningStrategy) { - super(parent, name, joiningStrategy); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericEntityMappings.java deleted file mode 100644 index fb2b0dac0c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericEntityMappings.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.internal.context.orm.AbstractEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; - -public class GenericEntityMappings - extends AbstractEntityMappings -{ - - public GenericEntityMappings(OrmXml parent, XmlEntityMappings resource) { - super(parent, resource); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverride.java deleted file mode 100644 index 06803909c0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverride.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmAssociationOverride extends AbstractOrmXmlContextNode - implements OrmAssociationOverride -{ - protected final AssociationOverride.Owner owner; - - protected transient XmlAssociationOverride resourceAssociationOverride; - - protected String name; - - protected final OrmAssociationOverrideRelationshipReference relationshipReference; - - - public GenericOrmAssociationOverride(XmlContextNode parent, AssociationOverride.Owner owner, XmlAssociationOverride xmlAssociationOverride) { - super(parent); - this.owner = owner; - this.relationshipReference = buildRelationshipReference(xmlAssociationOverride); - this.resourceAssociationOverride = xmlAssociationOverride; - this.name = xmlAssociationOverride.getName(); - } - - protected OrmAssociationOverrideRelationshipReference buildRelationshipReference(XmlAssociationOverride xmlAssociationOverride) { - return getXmlContextNodeFactory().buildOrmAssociationOverrideRelationshipReference(this, xmlAssociationOverride); - } - - public void initializeFrom(AssociationOverride oldAssociationOverride) { - this.setName(oldAssociationOverride.getName()); - this.relationshipReference.initializeFrom(oldAssociationOverride.getRelationshipReference()); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public OrmAssociationOverride setVirtual(boolean virtual) { - return (OrmAssociationOverride) getOwner().setVirtual(virtual, this); - } - - public Owner getOwner() { - return this.owner; - } - - public OrmAssociationOverrideRelationshipReference getRelationshipReference() { - return this.relationshipReference; - } - - // ********** AssociationOverride implementation ********** - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.resourceAssociationOverride.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 void update(XmlAssociationOverride xao) { - this.resourceAssociationOverride = xao; - this.setName_(xao.getName()); - this.relationshipReference.update(xao); - } - - public TextRange getValidationTextRange() { - return this.resourceAssociationOverride.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverrideContainer.java deleted file mode 100644 index 8a155e6814..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverrideContainer.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.RelationshipReference; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverrideContainer; -import org.eclipse.jpt.core.resource.xml.EmfTools; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmAssociationOverrideContainer extends AbstractOrmXmlContextNode - implements OrmAssociationOverrideContainer -{ - protected final XmlAssociationOverrideContainer resourceAssociationOverrideContainer; - - protected final List<OrmAssociationOverride> specifiedAssociationOverrides; - - protected final List<OrmAssociationOverride> virtualAssociationOverrides; - - protected final OrmAssociationOverrideContainer.Owner owner; - - public GenericOrmAssociationOverrideContainer(XmlContextNode parent, OrmAssociationOverrideContainer.Owner owner, XmlAssociationOverrideContainer resource) { - super(parent); - this.owner = owner; - this.resourceAssociationOverrideContainer = resource; - this.specifiedAssociationOverrides = new ArrayList<OrmAssociationOverride>(); - this.virtualAssociationOverrides = new ArrayList<OrmAssociationOverride>(); - this.initializeSpecifiedAssociationOverrides(); - this.initializeVirtualAssociationOverrides(); - } - - public Owner getOwner() { - return this.owner; - } - - @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(); - } - - protected void addVirtualAssociationOverride(OrmAssociationOverride associationOverride) { - addItemToList(associationOverride, this.virtualAssociationOverrides, VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeVirtualAssociationOverride(OrmAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.virtualAssociationOverrides, VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - protected OrmAssociationOverride setAssociationOverrideVirtual(boolean virtual, OrmAssociationOverride associationOverride) { - if (virtual) { - return setAssociationOverrideVirtual(associationOverride); - } - return setAssociationOverrideSpecified(associationOverride); - } - - protected OrmAssociationOverride setAssociationOverrideVirtual(OrmAssociationOverride 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 - OrmAssociationOverride virtualAssociationOverride = null; - if (associationOverrideName != null) { - for (RelationshipMapping overridableAssociation : CollectionTools.iterable(getOwner().allOverridableAssociations())) { - if (overridableAssociation.getName().equals(associationOverrideName)) { - //store the virtualAssociationOverride so we can fire change notification later - virtualAssociationOverride = buildVirtualAssociationOverride(overridableAssociation); - this.virtualAssociationOverrides.add(virtualAssociationOverride); - } - } - } - - this.resourceAssociationOverrideContainer.getAssociationOverrides().remove(index); - fireItemRemoved(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); - - if (virtualAssociationOverride != null) { - fireItemAdded(VIRTUAL_ASSOCIATION_OVERRIDES_LIST, virtualAssociationOverridesSize() - 1, virtualAssociationOverride); - } - return virtualAssociationOverride; - } - - protected OrmAssociationOverride setAssociationOverrideSpecified(OrmAssociationOverride oldAssociationOverride) { - int index = specifiedAssociationOverridesSize(); - XmlAssociationOverride xmlAssociationOverride = buildResourceAssociationOverride(); - OrmAssociationOverride newAssociationOverride = buildAssociationOverride(xmlAssociationOverride); - this.specifiedAssociationOverrides.add(index, newAssociationOverride); - - this.resourceAssociationOverrideContainer.getAssociationOverrides().add(xmlAssociationOverride); - - int defaultIndex = this.virtualAssociationOverrides.indexOf(oldAssociationOverride); - this.virtualAssociationOverrides.remove(defaultIndex); - - newAssociationOverride.initializeFrom(oldAssociationOverride); - - this.fireItemRemoved(VIRTUAL_ASSOCIATION_OVERRIDES_LIST, defaultIndex, oldAssociationOverride); - this.fireItemAdded(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, newAssociationOverride); - - return newAssociationOverride; - } - - 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, SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - protected void addSpecifiedAssociationOverride(OrmAssociationOverride associationOverride) { - this.addSpecifiedAssociationOverride(this.specifiedAssociationOverrides.size(), associationOverride); - } - - protected void removeSpecifiedAssociationOverride_(OrmAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.specifiedAssociationOverrides, SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAssociationOverrides, targetIndex, sourceIndex); - this.resourceAssociationOverrideContainer.getAssociationOverrides().move(targetIndex, sourceIndex); - fireItemMoved(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - 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; - } - - - protected void initializeVirtualAssociationOverrides() { - for (RelationshipMapping overridableAssociation : CollectionTools.iterable(getOwner().allOverridableAssociations())) { - OrmAssociationOverride ormAssociationOverride = getAssociationOverrideNamed(overridableAssociation.getName()); - if (ormAssociationOverride == null) { - this.virtualAssociationOverrides.add(buildVirtualAssociationOverride(overridableAssociation)); - } - } - } - - protected OrmAssociationOverride buildVirtualAssociationOverride(RelationshipMapping overridableAssociation) { - return buildAssociationOverride(buildVirtualXmlAssociationOverride(overridableAssociation)); - } - - protected XmlAssociationOverride buildVirtualXmlAssociationOverride(RelationshipMapping overridableAssociation) { - RelationshipReference relationshipReference = getOwner().getOverridableRelationshipReference(overridableAssociation); - return buildVirtualXmlAssociationOverride(overridableAssociation.getName(), relationshipReference.getPredominantJoiningStrategy()); - } - - protected XmlAssociationOverride buildVirtualXmlAssociationOverride(String name, JoiningStrategy joiningStrategy) { - return getXmlContextNodeFactory().buildVirtualXmlAssociationOverride(name, getOwner().getTypeMapping(), joiningStrategy); - } - - protected void initializeSpecifiedAssociationOverrides() { - for (XmlAssociationOverride associationOverride : this.resourceAssociationOverrideContainer.getAssociationOverrides()) { - this.specifiedAssociationOverrides.add(buildAssociationOverride(associationOverride)); - } - } - - public void update() { - this.updateSpecifiedAssociationOverrides(); - this.updateVirtualAssociationOverrides(); - } - - protected void updateSpecifiedAssociationOverrides() { - // make a copy of the XML overrides (to prevent ConcurrentModificationException) - Iterator<XmlAssociationOverride> xmlOverrides = new CloneIterator<XmlAssociationOverride>(this.resourceAssociationOverrideContainer.getAssociationOverrides()); - - for (Iterator<OrmAssociationOverride> contextOverrides = this.specifiedAssociationOverrides(); contextOverrides.hasNext(); ) { - OrmAssociationOverride contextOverride = contextOverrides.next(); - if (xmlOverrides.hasNext()) { - contextOverride.update(xmlOverrides.next()); - } - else { - removeSpecifiedAssociationOverride_(contextOverride); - } - } - - while (xmlOverrides.hasNext()) { - addSpecifiedAssociationOverride(buildAssociationOverride(xmlOverrides.next())); - } - } - - protected void updateVirtualAssociationOverrides() { - Iterator<RelationshipMapping> overridableAssociations = getOwner().allOverridableAssociations(); - ListIterator<OrmAssociationOverride> virtualAssociationOverridesCopy = virtualAssociationOverrides(); - - for (RelationshipMapping overridableAssociation : CollectionTools.iterable(overridableAssociations)) { - OrmAssociationOverride ormAssociationOverride = getAssociationOverrideNamed(overridableAssociation.getName()); - if (ormAssociationOverride != null && !ormAssociationOverride.isVirtual()) { - continue; - } - if (ormAssociationOverride != null) { - if (virtualAssociationOverridesCopy.hasNext()) { - OrmAssociationOverride virtualAssociationOverride = virtualAssociationOverridesCopy.next(); - virtualAssociationOverride.update(buildVirtualXmlAssociationOverride(overridableAssociation)); - } - else { - addVirtualAssociationOverride(buildVirtualAssociationOverride(overridableAssociation)); - } - } - else { - addVirtualAssociationOverride(buildVirtualAssociationOverride(overridableAssociation)); - } - } - for (OrmAssociationOverride virtualAssociationOverride : CollectionTools.iterable(virtualAssociationOverridesCopy)) { - removeVirtualAssociationOverride(virtualAssociationOverride); - } - } - - protected OrmAssociationOverride buildAssociationOverride(XmlAssociationOverride associationOverride) { - return getXmlContextNodeFactory().buildOrmAssociationOverride(this, buildAssociationOverrideOwner(), associationOverride); - } - - protected XmlAssociationOverride buildResourceAssociationOverride() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getXmlAssociationOverride(), - XmlAssociationOverride.class); - } - - protected AssociationOverride.Owner buildAssociationOverrideOwner() { - return new AssociationOverrideOwner(); - } - - //************ validation *************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - for (Iterator<OrmAssociationOverride> stream = this.associationOverrides(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); - } - } - - public TextRange getValidationTextRange() { - return this.resourceAssociationOverrideContainer.getValidationTextRange(); - } - - - - class AssociationOverrideOwner implements AssociationOverride.Owner { - - public RelationshipMapping getRelationshipMapping(String attributeName) { - return MappingTools.getRelationshipMapping(attributeName, getOwner().getOverridablePersistentType()); - } - - public boolean isVirtual(BaseOverride override) { - return GenericOrmAssociationOverrideContainer.this.virtualAssociationOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - return GenericOrmAssociationOverrideContainer.this.setAssociationOverrideVirtual(virtual, (OrmAssociationOverride) override); - } - - public TypeMapping getTypeMapping() { - return getOwner().getTypeMapping(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverrideRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverrideRelationshipReference.java deleted file mode 100644 index 32e785991e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAssociationOverrideRelationshipReference.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; - -public class GenericOrmAssociationOverrideRelationshipReference extends AbstractOrmAssociationOverrideRelationshipReference -{ - - public GenericOrmAssociationOverrideRelationshipReference(OrmAssociationOverride parent, XmlAssociationOverride xao) { - super(parent, xao); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAttributeOverride.java deleted file mode 100644 index 16cf947f5b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAttributeOverride.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public class GenericOrmAttributeOverride extends AbstractOrmXmlContextNode - implements OrmAttributeOverride, OrmColumn.Owner -{ - - protected String name; - - private final Owner owner; - - protected XmlAttributeOverride resourceAttributeOverride; - - - protected final OrmColumn column; - - public GenericOrmAttributeOverride(XmlContextNode parent, AttributeOverride.Owner owner, XmlAttributeOverride resourceAttributeOverride) { - super(parent); - this.owner = owner; - this.column = getXmlContextNodeFactory().buildOrmColumn(this, this); - this.resourceAttributeOverride = resourceAttributeOverride; - this.name = resourceAttributeOverride.getName(); - this.column.initialize(resourceAttributeOverride.getColumn()); - } - - @Override - public XmlContextNode getParent() { - return (XmlContextNode) 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.resourceAttributeOverride.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().getPrimaryTableName(); - } - - protected ColumnMapping getColumnMapping() { - return getOwner().getColumnMapping(getName()); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public TextRange getValidationTextRange() { - TextRange textRange = this.resourceAttributeOverride.getValidationTextRange(); - return textRange == null ? getParent().getValidationTextRange() : textRange; - } - - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getResourceColumn() { - return this.resourceAttributeOverride.getColumn(); - } - - public void addResourceColumn() { - this.resourceAttributeOverride.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - this.resourceAttributeOverride.setColumn(null); - } - - - //***************** updating **************** - - public void update(XmlAttributeOverride xmlAttributeOverride) { - this.resourceAttributeOverride = xmlAttributeOverride; - this.setName_(xmlAttributeOverride.getName()); - this.column.update(xmlAttributeOverride.getColumn()); - } - - //****************** validation ******************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.connectionProfileIsActive()) { - this.validateColumn(messages); - } - } - - protected void validateColumn(List<IMessage> messages) { - String tableName = this.column.getTable(); - if (this.getTypeMapping().tableNameIsInvalid(tableName)) { - if (this.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE, - new String[] {this.getName(), tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {tableName, this.column.getName()}, - this.column, - this.column.getTableTextRange() - ) - ); - } - return; - } - - if ( ! this.column.isResolved() && this.column.getDbTable() != null) { - if (this.isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] {this.getName(), this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.column.getName()}, - this.column, - this.column.getNameTextRange() - ) - ); - } - } - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAttributeOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAttributeOverrideContainer.java deleted file mode 100644 index dbc82974de..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmAttributeOverrideContainer.java +++ /dev/null @@ -1,340 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -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.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverrideContainer; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmAttributeOverrideContainer extends AbstractOrmXmlContextNode - implements OrmAttributeOverrideContainer -{ - private final XmlAttributeOverrideContainer resourceAttributeOverrideContainer; - - protected final List<OrmAttributeOverride> specifiedAttributeOverrides; - - protected final List<OrmAttributeOverride> virtualAttributeOverrides; - - protected final Owner owner; - - public GenericOrmAttributeOverrideContainer(XmlContextNode parent, Owner owner, XmlAttributeOverrideContainer resource) { - super(parent); - this.owner = owner; - this.resourceAttributeOverrideContainer = resource; - this.specifiedAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.initializeSpecifiedAttributeOverrides(); - this.initializeVirtualAttributeOverrides(); - } - - public void initializeFromAttributeOverrideContainer(OrmAttributeOverrideContainer oldContainer) { - int index = 0; - for (OrmAttributeOverride attributeOverride : CollectionTools.iterable(oldContainer.specifiedAttributeOverrides())) { - OrmAttributeOverride newAttributeOverride = addSpecifiedAttributeOverride(index++); - newAttributeOverride.setName(attributeOverride.getName()); - newAttributeOverride.getColumn().initializeFrom(attributeOverride.getColumn()); - } - } - - public Owner getOwner() { - return this.owner; - } - - @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, VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, 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 update. This causes the UI to be flaky, since change notification might not occur in the correct order - OrmAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (ColumnMapping overridableAttribute : CollectionTools.iterable(getOwner().allOverridableAttributes())) { - if (overridableAttribute.getName().equals(attributeOverrideName)) { - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(overridableAttribute); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - } - } - } - - this.resourceAttributeOverrideContainer.getAttributeOverrides().remove(index); - fireItemRemoved(SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected OrmAttributeOverride setAttributeOverrideSpecified(OrmAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverride(); - OrmAttributeOverride newAttributeOverride = getXmlContextNodeFactory().buildOrmAttributeOverride(this, createAttributeOverrideOwner(), xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - this.resourceAttributeOverrideContainer.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(VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(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 OrmAttributeOverride addSpecifiedAttributeOverride(int index) { - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverride(); - OrmAttributeOverride attributeOverride = buildAttributeOverride(xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, attributeOverride); - this.resourceAttributeOverrideContainer.getAttributeOverrides().add(index, xmlAttributeOverride); - this.fireItemAdded(SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - return attributeOverride; - } - - protected void addSpecifiedAttributeOverride(int index, OrmAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void addSpecifiedAttributeOverride(OrmAttributeOverride attributeOverride) { - this.addSpecifiedAttributeOverride(this.specifiedAttributeOverrides.size(), attributeOverride); - } - - protected void removeSpecifiedAttributeOverride_(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.resourceAttributeOverrideContainer.getAttributeOverrides().move(targetIndex, sourceIndex); - fireItemMoved(SPECIFIED_ATTRIBUTE_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()); - } - - 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; - } - - protected void initializeVirtualAttributeOverrides() { - for (ColumnMapping overridableAttribute : CollectionTools.iterable(getOwner().allOverridableAttributes())) { - OrmAttributeOverride ormAttributeOverride = getAttributeOverrideNamed(overridableAttribute.getName()); - if (ormAttributeOverride == null) { - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(overridableAttribute)); - } - } - } - - protected void initializeSpecifiedAttributeOverrides() { - for (XmlAttributeOverride attributeOverride : this.resourceAttributeOverrideContainer.getAttributeOverrides()) { - this.specifiedAttributeOverrides.add(buildAttributeOverride(attributeOverride)); - } - } - - public void update() { - this.updateSpecifiedAttributeOverrides(); - this.updateVirtualAttributeOverrides(); - } - - protected OrmAttributeOverride buildVirtualAttributeOverride(ColumnMapping columnMapping) { - return buildAttributeOverride(buildVirtualXmlAttributeOverride(columnMapping)); - } - - protected XmlAttributeOverride buildVirtualXmlAttributeOverride(ColumnMapping columnMapping) { - XmlColumn xmlColumn = getOwner().buildVirtualXmlColumn(columnMapping); - return new VirtualXmlAttributeOverride(columnMapping.getName(), xmlColumn); - } - - - protected void updateSpecifiedAttributeOverrides() { - // make a copy of the XML overrides (to prevent ConcurrentModificationException) - Iterator<XmlAttributeOverride> xmlOverrides = new CloneIterator<XmlAttributeOverride>(this.resourceAttributeOverrideContainer.getAttributeOverrides()); - - for (Iterator<OrmAttributeOverride> contextOverrides = this.specifiedAttributeOverrides(); contextOverrides.hasNext(); ) { - OrmAttributeOverride contextOverride = contextOverrides.next(); - if (xmlOverrides.hasNext()) { - contextOverride.update(xmlOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(contextOverride); - } - } - - while (xmlOverrides.hasNext()) { - addSpecifiedAttributeOverride(buildAttributeOverride(xmlOverrides.next())); - } - } - - protected void updateVirtualAttributeOverrides() { - Iterator<ColumnMapping> overridableAttributes = getOwner().allOverridableAttributes(); - ListIterator<OrmAttributeOverride> virtualAttributeOverridesCopy = virtualAttributeOverrides(); - - for (ColumnMapping overridableAttribute : CollectionTools.iterable(overridableAttributes)) { - OrmAttributeOverride ormAttributeOverride = getAttributeOverrideNamed(overridableAttribute.getName()); - if (ormAttributeOverride != null && !ormAttributeOverride.isVirtual()) { - continue; - } - if (ormAttributeOverride != null) { - if (virtualAttributeOverridesCopy.hasNext()) { - OrmAttributeOverride virtualAttributeOverride = virtualAttributeOverridesCopy.next(); - virtualAttributeOverride.update(buildVirtualXmlAttributeOverride(overridableAttribute)); - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(overridableAttribute)); - } - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(overridableAttribute)); - } - } - for (OrmAttributeOverride virtualAttributeOverride : CollectionTools.iterable(virtualAttributeOverridesCopy)) { - removeVirtualAttributeOverride(virtualAttributeOverride); - } - } - - protected OrmAttributeOverride buildAttributeOverride(XmlAttributeOverride attributeOverride) { - return getXmlContextNodeFactory().buildOrmAttributeOverride(this, createAttributeOverrideOwner(), attributeOverride); - } - - protected AttributeOverride.Owner createAttributeOverrideOwner() { - return new AttributeOverrideOwner(); - } - //************ validation *************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - for (Iterator<OrmAttributeOverride> stream = this.attributeOverrides(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); - } - } - - public TextRange getValidationTextRange() { - return this.resourceAttributeOverrideContainer.getValidationTextRange(); - } - - - - - class AttributeOverrideOwner implements AttributeOverride.Owner { - - public ColumnMapping getColumnMapping(String attributeName) { - return MappingTools.getColumnMapping(attributeName, getOwner().getOverridablePersistentType()); - } - - public boolean isVirtual(BaseOverride override) { - return GenericOrmAttributeOverrideContainer.this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - return GenericOrmAttributeOverrideContainer.this.setAttributeOverrideVirtual(virtual, (OrmAttributeOverride) override); - } - - public TypeMapping getTypeMapping() { - return getOwner().getTypeMapping(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmBasicMapping.java deleted file mode 100644 index 406105dc9f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmBasicMapping.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmBasicMapping; -import org.eclipse.jpt.core.resource.orm.XmlBasic; - - -public class GenericOrmBasicMapping extends AbstractOrmBasicMapping<XmlBasic> -{ - - public GenericOrmBasicMapping(OrmPersistentAttribute parent, XmlBasic resourceMapping) { - super(parent, resourceMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmCascade.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmCascade.java deleted file mode 100644 index 43d61cfcd0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmCascade.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.orm.OrmCascade; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.AbstractXmlRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericOrmCascade extends AbstractOrmXmlContextNode implements OrmCascade -{ - protected boolean all; - - protected boolean persist; - - protected boolean merge; - - protected boolean remove; - - protected boolean refresh; - - - protected final AbstractXmlRelationshipMapping relationshipMapping; - - public GenericOrmCascade(OrmRelationshipMapping parent, AbstractXmlRelationshipMapping relationshipMapping) { - super(parent); - this.relationshipMapping = relationshipMapping; - CascadeType cascade = getResourceCascade(); - this.all = this.getResourceAll(cascade); - this.persist = this.getResourcePersist(cascade); - this.merge = this.getResourceMerge(cascade); - this.remove = this.getResourceRemove(cascade); - this.refresh = this.getResourceRefresh(cascade); - } - - 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.getResourceCascade() != null) { - this.getResourceCascade().setCascadeAll(newAll); - if (this.getResourceCascade().isUnset()) { - removeResourceCascade(); - } - } - else if (newAll != false) { - addResourceCascade(); - getResourceCascade().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.getResourceCascade() != null) { - this.getResourceCascade().setCascadePersist(newPersist); - if (this.getResourceCascade().isUnset()) { - removeResourceCascade(); - } - } - else if (newPersist != false) { - addResourceCascade(); - getResourceCascade().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.getResourceCascade() != null) { - this.getResourceCascade().setCascadeMerge(newMerge); - if (this.getResourceCascade().isUnset()) { - removeResourceCascade(); - } - } - else if (newMerge != false) { - addResourceCascade(); - getResourceCascade().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.getResourceCascade() != null) { - this.getResourceCascade().setCascadeRemove(newRemove); - if (this.getResourceCascade().isUnset()) { - removeResourceCascade(); - } - } - else if (newRemove != false) { - addResourceCascade(); - getResourceCascade().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.getResourceCascade() != null) { - this.getResourceCascade().setCascadeRefresh(newRefresh); - if (this.getResourceCascade().isUnset()) { - removeResourceCascade(); - } - } - else if (newRefresh != false) { - addResourceCascade(); - getResourceCascade().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 getResourceCascade() { - return this.relationshipMapping.getCascade(); - } - - protected void removeResourceCascade() { - this.relationshipMapping.setCascade(null); - } - - protected void addResourceCascade() { - this.relationshipMapping.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - } - - public void update() { - CascadeType cascade = getResourceCascade(); - this.setAll_(this.getResourceAll(cascade)); - this.setPersist_(this.getResourcePersist(cascade)); - this.setMerge_(this.getResourceMerge(cascade)); - this.setRemove_(this.getResourceRemove(cascade)); - this.setRefresh_(this.getResourceRefresh(cascade)); - } - - protected boolean getResourceAll(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeAll(); - } - - protected boolean getResourcePersist(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadePersist(); - } - - protected boolean getResourceMerge(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeMerge(); - } - - protected boolean getResourceRemove(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeRemove(); - } - - protected boolean getResourceRefresh(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeRefresh(); - } - - public TextRange getValidationTextRange() { - return this.getResourceCascade().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmColumn.java deleted file mode 100644 index b3fbae1658..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmColumn.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmBaseColumn; -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(XmlContextNode 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 int getLength() { - return (this.getSpecifiedLength() == null) ? getDefaultLength() : this.getSpecifiedLength().intValue(); - } - - public int getDefaultLength() { - return Column.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - if (this.valuesAreDifferent(oldSpecifiedLength, newSpecifiedLength)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setLength(newSpecifiedLength); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedLength != null) { - addResourceColumn(); - getResourceColumn().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 int getPrecision() { - return (this.getSpecifiedPrecision() == null) ? getDefaultPrecision() : this.getSpecifiedPrecision().intValue(); - } - - public int getDefaultPrecision() { - return Column.DEFAULT_PRECISION; - } - - public Integer getSpecifiedPrecision() { - return this.specifiedPrecision; - } - - public void setSpecifiedPrecision(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - if (this.valuesAreDifferent(oldSpecifiedPrecision, newSpecifiedPrecision)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setPrecision(newSpecifiedPrecision); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedPrecision != null) { - addResourceColumn(); - getResourceColumn().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 int getScale() { - return (this.getSpecifiedScale() == null) ? getDefaultScale() : this.getSpecifiedScale().intValue(); - } - - public int getDefaultScale() { - return Column.DEFAULT_SCALE; - } - - public Integer getSpecifiedScale() { - return this.specifiedScale; - } - - public void setSpecifiedScale(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - if (this.valuesAreDifferent(oldSpecifiedScale, newSpecifiedScale)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setScale(newSpecifiedScale); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedScale != null) { - addResourceColumn(); - getResourceColumn().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 getResourceColumn() { - return getOwner().getResourceColumn(); - } - - @Override - protected void addResourceColumn() { - getOwner().addResourceColumn(); - } - - @Override - protected void removeResourceColumn() { - getOwner().removeResourceColumn(); - } - - @Override - public void initialize(XmlColumn column) { - super.initialize(column); - this.specifiedLength = this.getResourceLength(column); - this.specifiedPrecision = this.getResourcePrecision(column); - this.specifiedScale = this.getResourceScale(column); - } - - @Override - public void update(XmlColumn column) { - super.update(column); - this.setSpecifiedLength_(this.getResourceLength(column)); - this.setSpecifiedPrecision_(this.getResourcePrecision(column)); - this.setSpecifiedScale_(this.getResourceScale(column)); - } - - protected Integer getResourceLength(XmlColumn column) { - return column == null ? null : column.getLength(); - } - - protected Integer getResourcePrecision(XmlColumn column) { - return column == null ? null : column.getPrecision(); - } - - protected Integer getResourceScale(XmlColumn column) { - return column == null ? null : column.getScale(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmDiscriminatorColumn.java deleted file mode 100644 index f646db22c1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmDiscriminatorColumn.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmNamedColumn; -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.XmlDiscriminatorColumn; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmDiscriminatorColumn extends AbstractOrmNamedColumn<XmlDiscriminatorColumn> - implements OrmDiscriminatorColumn -{ - - protected DiscriminatorType specifiedDiscriminatorType; - - protected DiscriminatorType defaultDiscriminatorType; - - protected Integer specifiedLength; - - protected int defaultLength; - - protected XmlEntity entity; - - public GenericOrmDiscriminatorColumn(XmlContextNode parent, OrmDiscriminatorColumn.Owner owner) { - super(parent, owner); - } - - @Override - public OrmDiscriminatorColumn.Owner getOwner() { - return (OrmDiscriminatorColumn.Owner) super.getOwner(); - } - - public DiscriminatorType getDiscriminatorType() { - return (this.getSpecifiedDiscriminatorType() == null) ? this.getDefaultDiscriminatorType() : this.getSpecifiedDiscriminatorType(); - } - - public DiscriminatorType getDefaultDiscriminatorType() { - return this.defaultDiscriminatorType; - } - - protected void setDefaultDiscriminatorType(DiscriminatorType discriminatorType) { - DiscriminatorType old = this.defaultDiscriminatorType; - this.defaultDiscriminatorType = discriminatorType; - firePropertyChanged(DEFAULT_DISCRIMINATOR_TYPE_PROPERTY, old, discriminatorType); - } - - public DiscriminatorType getSpecifiedDiscriminatorType() { - return this.specifiedDiscriminatorType; - } - - public void setSpecifiedDiscriminatorType(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - if (oldDiscriminatorType != newSpecifiedDiscriminatorType) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setDiscriminatorType(DiscriminatorType.toOrmResourceModel(newSpecifiedDiscriminatorType)); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedDiscriminatorType != null) { - addResourceColumn(); - this.getResourceColumn().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 int getLength() { - return (this.getSpecifiedLength() == null) ? this.getDefaultLength() : this.getSpecifiedLength().intValue(); - } - - public int getDefaultLength() { - return this.defaultLength; - } - - protected void setDefaultLength(int defaultLength) { - int old = this.defaultLength; - this.defaultLength = defaultLength; - firePropertyChanged(DEFAULT_LENGTH_PROPERTY, old, defaultLength); - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - if (this.valuesAreDifferent(oldSpecifiedLength, newSpecifiedLength)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setLength(newSpecifiedLength); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedLength != null) { - addResourceColumn(); - getResourceColumn().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 getOwningTableName() { - return this.getOwner().getTypeMapping().getPrimaryTableName(); - } - - - - @Override - public XmlDiscriminatorColumn getResourceColumn() { - return this.entity.getDiscriminatorColumn(); - } - - @Override - protected void addResourceColumn() { - this.entity.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - } - - @Override - protected void removeResourceColumn() { - this.entity.setDiscriminatorColumn(null); - } - - public boolean isResourceSpecified() { - return getResourceColumn() != null; - } - - public void initialize(XmlEntity xmlEntity) { - this.entity = xmlEntity; - this.initialize(this.getResourceColumn()); - } - - public void update(XmlEntity xmlEntity) { - this.entity = xmlEntity; - this.update(this.getResourceColumn()); - } - - - @Override - protected void initialize(XmlDiscriminatorColumn column) { - super.initialize(column); - this.defaultDiscriminatorType = this.buildDefaultDiscriminatorType(); - this.defaultLength = this.buildDefaultLength(); - this.specifiedLength = this.getResourceLength(column); - this.specifiedDiscriminatorType = this.getResourceDiscriminatorType(column); - } - - @Override - protected void update(XmlDiscriminatorColumn column) { - //don't call super because postUpdate() handles updating the default column name - this.setSpecifiedName_(this.getResourceColumnName(column)); - this.setColumnDefinition_(this.getResourceColumnDefinition(column)); - this.setSpecifiedLength_(this.getResourceLength(column)); - this.setSpecifiedDiscriminatorType_(this.getResourceDiscriminatorType(column)); - } - - @Override - /** - * Using postUpdate since these defaults are dependent on the entity hierarchy - */ - public void postUpdate() { - super.postUpdate(); - this.setDefaultName(this.buildDefaultName()); - this.setDefaultDiscriminatorType(this.buildDefaultDiscriminatorType()); - this.setDefaultLength(this.buildDefaultLength()); - } - - protected Integer getResourceLength(XmlDiscriminatorColumn column) { - return column == null ? null : column.getLength(); - } - - protected DiscriminatorType getResourceDiscriminatorType(XmlDiscriminatorColumn column) { - return column == null ? null : DiscriminatorType.fromOrmResourceModel(column.getDiscriminatorType()); - } - - protected int buildDefaultLength() { - return this.getOwner().getDefaultLength(); - } - - protected DiscriminatorType buildDefaultDiscriminatorType() { - return this.getOwner().getDefaultDiscriminatorType(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.connectionProfileIsActive()) { - if ( ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.DISCRIMINATOR_COLUMN_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange() - ) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddable.java deleted file mode 100644 index f0c0c8d0a5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddable.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEmbeddable; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.utility.internal.ArrayTools; - - -public class GenericOrmEmbeddable - extends AbstractOrmEmbeddable -{ - public GenericOrmEmbeddable(OrmPersistentType parent, XmlEmbeddable resourceMapping) { - super(parent, resourceMapping); - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return ArrayTools.contains(GenericJavaEmbeddable.ALLOWED_ATTRIBUTE_MAPPING_KEYS, attributeMappingKey); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddedIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddedIdMapping.java deleted file mode 100644 index e14c322340..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddedIdMapping.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.internal.context.orm.AbstractOrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; - - -public class GenericOrmEmbeddedIdMapping - extends AbstractOrmBaseEmbeddedMapping<XmlEmbeddedId> - implements OrmEmbeddedIdMapping -{ - - public GenericOrmEmbeddedIdMapping(OrmPersistentAttribute parent, XmlEmbeddedId resourceMapping) { - super(parent, resourceMapping); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmEmbeddedIdMapping(this); - } - - public int getXmlSequence() { - return 10; - } - - //*************** AttributeMapping implementation ********************* - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public boolean isIdMapping() { - return true; - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getEmbeddedIds().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getEmbeddedIds().remove(this.resourceAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddedMapping.java deleted file mode 100644 index 9237b1553f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEmbeddedMapping.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEmbeddedMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; - - -public class GenericOrmEmbeddedMapping - extends AbstractOrmEmbeddedMapping<XmlEmbedded> -{ - - public GenericOrmEmbeddedMapping(OrmPersistentAttribute parent, XmlEmbedded resourceMapping) { - super(parent, resourceMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEntity.java deleted file mode 100644 index 26af651193..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEntity.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntity; - -public class GenericOrmEntity - extends AbstractOrmEntity -{ - - public GenericOrmEntity(OrmPersistentType parent, XmlEntity resourceMapping) { - super(parent, resourceMapping); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEnumeratedConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEnumeratedConverter.java deleted file mode 100644 index 24a8209eff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEnumeratedConverter.java +++ /dev/null @@ -1,94 +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.jpa1.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.XmlConvertibleMapping; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmEnumeratedConverter extends AbstractOrmXmlContextNode - implements EnumeratedConverter, OrmConverter -{ - private EnumType specifiedEnumType; - - private XmlConvertibleMapping resourceConvertibleMapping; - - public GenericOrmEnumeratedConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - super(parent); - this.initialize(resourceMapping); - } - - @Override - public OrmAttributeMapping getParent() { - return (OrmAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.ENUMERATED_CONVERTER; - } - - public EnumType getEnumType() { - return getSpecifiedEnumType() == null ? getDefaultEnumType() : getSpecifiedEnumType(); - } - - public EnumType getDefaultEnumType() { - //there is no default enumType in xml, if you specify the enumerated element, you must - //specify either ORDINAL or STRING - return null; - } - - public EnumType getSpecifiedEnumType() { - return this.specifiedEnumType; - } - - public void setSpecifiedEnumType(EnumType newSpecifiedEnumType) { - EnumType oldSpecifiedEnumType = this.specifiedEnumType; - this.specifiedEnumType = newSpecifiedEnumType; - this.resourceConvertibleMapping.setEnumerated(EnumType.toOrmResourceModel(newSpecifiedEnumType)); - firePropertyChanged(EnumeratedConverter.SPECIFIED_ENUM_TYPE_PROPERTY, oldSpecifiedEnumType, newSpecifiedEnumType); - } - - protected void setSpecifiedEnumType_(EnumType newSpecifiedEnumType) { - EnumType oldSpecifiedEnumType = this.specifiedEnumType; - this.specifiedEnumType = newSpecifiedEnumType; - firePropertyChanged(EnumeratedConverter.SPECIFIED_ENUM_TYPE_PROPERTY, oldSpecifiedEnumType, newSpecifiedEnumType); - } - - protected void initialize(XmlConvertibleMapping resourceConvertibleMapping) { - this.resourceConvertibleMapping = resourceConvertibleMapping; - this.specifiedEnumType = this.specifiedEnumType(); - } - - public void update() { - this.setSpecifiedEnumType_(this.specifiedEnumType()); - } - - protected EnumType specifiedEnumType() { - return EnumType.fromOrmResourceModel(this.resourceConvertibleMapping.getEnumerated()); - } - - public TextRange getValidationTextRange() { - return this.resourceConvertibleMapping.getEnumeratedTextRange(); - } - - public void addToResourceModel() { - this.resourceConvertibleMapping.setEnumerated(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL); - } - - public void removeFromResourceModel() { - this.resourceConvertibleMapping.setEnumerated(null); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmGeneratedValue.java deleted file mode 100644 index 860d5a8f61..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmGeneratedValue.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * - */ -public class GenericOrmGeneratedValue - extends AbstractOrmXmlContextNode - implements OrmGeneratedValue -{ - protected XmlGeneratedValue resourceGeneratedValue; - - protected GenerationType specifiedStrategy; - - protected String specifiedGenerator; - protected String defaultGenerator; - - - public GenericOrmGeneratedValue(XmlContextNode parent, XmlGeneratedValue resourceGeneratedValue) { - super(parent); - this.initialize(resourceGeneratedValue); - } - - protected void initialize(XmlGeneratedValue xmlGeneratedValue) { - this.resourceGeneratedValue = xmlGeneratedValue; - this.specifiedStrategy = this.buildStrategy(); - this.specifiedGenerator = xmlGeneratedValue.getGenerator(); - //TODO - this.defaultGenerator = null; - } - - @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - - // ********** strategy ********** - - public GenerationType getStrategy() { - return (this.specifiedStrategy != null) ? this.specifiedStrategy : this.getDefaultStrategy(); - } - - public GenerationType getDefaultStrategy() { - return GeneratedValue.DEFAULT_STRATEGY; - } - - public GenerationType getSpecifiedStrategy() { - return this.specifiedStrategy; - } - - public void setSpecifiedStrategy(GenerationType strategy) { - GenerationType old = this.specifiedStrategy; - this.specifiedStrategy = strategy; - this.resourceGeneratedValue.setStrategy(GenerationType.toOrmResourceModel(strategy)); - this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); - } - - protected void setSpecifiedStrategy_(GenerationType strategy) { - GenerationType old = this.specifiedStrategy; - this.specifiedStrategy = strategy; - this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); - } - - - // ********** generator ********** - - public String getGenerator() { - return (this.specifiedGenerator != null) ? this.specifiedGenerator : this.defaultGenerator; - } - - public String getDefaultGenerator() { - return this.defaultGenerator; - } - - protected void setDefaultGenerator(String generator) { - String old = this.defaultGenerator; - this.defaultGenerator = generator; - this.firePropertyChanged(DEFAULT_GENERATOR_PROPERTY, old, generator); - } - - public String getSpecifiedGenerator() { - return this.specifiedGenerator; - } - - public void setSpecifiedGenerator(String generator) { - String old = this.specifiedGenerator; - this.specifiedGenerator = generator; - this.resourceGeneratedValue.setGenerator(generator); - this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); - } - - protected void setSpecifiedGenerator_(String generator) { - String old = this.specifiedGenerator; - this.specifiedGenerator = generator; - this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); - } - - - // ********** text ranges ********** - - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.resourceGeneratedValue.getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } - - public TextRange getGeneratorTextRange() { - TextRange textRange = this.resourceGeneratedValue.getGeneratorTextRange(); - return textRange != null ? textRange : getValidationTextRange(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - String generator = this.getGenerator(); - if (generator == null) { - return; - } - - for (Iterator<Generator> stream = this.getPersistenceUnit().generators(); stream.hasNext(); ) { - if (generator.equals(stream.next().getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generator}, - this.getParent(), - this.getGeneratorTextRange() - ) - ); - } - - - // ********** update from resource model ********** - - public void update(XmlGeneratedValue xmlGeneratedValue) { - this.resourceGeneratedValue = xmlGeneratedValue; - this.setSpecifiedStrategy_(this.buildStrategy()); - this.setSpecifiedGenerator_(xmlGeneratedValue.getGenerator()); - //TODO - this.setDefaultGenerator(null); - } - - protected GenerationType buildStrategy() { - return GenerationType.fromOrmResourceModel(this.resourceGeneratedValue.getStrategy()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java deleted file mode 100644 index 09b01312bf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java +++ /dev/null @@ -1,227 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlGeneratorContainer; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.xml.EmfTools; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmGeneratorContainer extends AbstractOrmXmlContextNode - implements OrmGeneratorContainer -{ - protected OrmSequenceGenerator sequenceGenerator; - - protected OrmTableGenerator tableGenerator; - - protected final XmlGeneratorContainer resourceGeneratorContainer; - - public GenericOrmGeneratorContainer(XmlContextNode parent, XmlGeneratorContainer resourceGeneratorContainer) { - super(parent); - this.resourceGeneratorContainer = resourceGeneratorContainer; - this.initializeSequenceGenerator(); - this.initializeTableGenerator(); - } - - public OrmSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); //$NON-NLS-1$ - } - XmlSequenceGenerator resourceSequenceGenerator = buildResourceSequenceGenerator(); - this.sequenceGenerator = buildSequenceGenerator(resourceSequenceGenerator); - this.resourceGeneratorContainer.setSequenceGenerator(resourceSequenceGenerator); - 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"); //$NON-NLS-1$ - } - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - this.resourceGeneratorContainer.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"); //$NON-NLS-1$ - } - XmlTableGenerator resourceTableGenerator = buildResourceTableGenerator(); - this.tableGenerator = buildTableGenerator(resourceTableGenerator); - this.resourceGeneratorContainer.setTableGenerator(resourceTableGenerator); - 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"); //$NON-NLS-1$ - } - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - this.resourceGeneratorContainer.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); - } - - protected void initializeSequenceGenerator() { - if (this.resourceGeneratorContainer.getSequenceGenerator() != null) { - this.sequenceGenerator = buildSequenceGenerator(this.resourceGeneratorContainer.getSequenceGenerator()); - } - } - - protected XmlSequenceGenerator buildResourceSequenceGenerator() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getXmlSequenceGenerator(), - XmlSequenceGenerator.class); - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator resourceSequenceGenerator) { - return getXmlContextNodeFactory().buildOrmSequenceGenerator(this, resourceSequenceGenerator); - } - - protected void initializeTableGenerator() { - if (this.resourceGeneratorContainer.getTableGenerator() != null) { - this.tableGenerator = buildTableGenerator(this.resourceGeneratorContainer.getTableGenerator()); - } - } - - protected XmlTableGenerator buildResourceTableGenerator() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getXmlTableGenerator(), - XmlTableGenerator.class); - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator resourceTableGenerator) { - return getXmlContextNodeFactory().buildOrmTableGenerator(this, resourceTableGenerator); - } - - public void update() { - this.updateSequenceGenerator(); - this.updateTableGenerator(); - } - - protected void updateSequenceGenerator() { - if (this.resourceGeneratorContainer.getSequenceGenerator() == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(this.resourceGeneratorContainer.getSequenceGenerator())); - } - else { - getSequenceGenerator().update(this.resourceGeneratorContainer.getSequenceGenerator()); - } - } - } - - protected void updateTableGenerator() { - if (this.resourceGeneratorContainer.getTableGenerator() == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(this.resourceGeneratorContainer.getTableGenerator())); - } - else { - getTableGenerator().update(this.resourceGeneratorContainer.getTableGenerator()); - } - } - } - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateGenerators(messages); - } - - protected void validateGenerators(List<IMessage> messages) { - for (Iterator<OrmGenerator> localGenerators = this.generators(); localGenerators.hasNext(); ) { - OrmGenerator localGenerator = localGenerators.next(); - for (Iterator<Generator> globalGenerators = this.getPersistenceUnit().generators(); globalGenerators.hasNext(); ) { - if (localGenerator.duplicates(globalGenerators.next())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {localGenerator.getName()}, - localGenerator, - localGenerator.getNameTextRange() - ) - ); - } - } - } - } - - protected Iterator<OrmGenerator> generators() { - ArrayList<OrmGenerator> generators = new ArrayList<OrmGenerator>(); - this.addGeneratorsTo(generators); - return generators.iterator(); - } - - protected void addGeneratorsTo(ArrayList<OrmGenerator> generators) { - if (this.sequenceGenerator != null) { - generators.add(this.sequenceGenerator); - } - if (this.tableGenerator != null) { - generators.add(this.tableGenerator); - } - } - - public TextRange getValidationTextRange() { - return this.resourceGeneratorContainer.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmIdMapping.java deleted file mode 100644 index 7675b12575..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmIdMapping.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmIdMapping; -import org.eclipse.jpt.core.resource.orm.XmlId; - -public class GenericOrmIdMapping extends AbstractOrmIdMapping<XmlId> -{ - - public GenericOrmIdMapping(OrmPersistentAttribute parent, XmlId resourceMapping) { - super(parent, resourceMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmJoinColumn.java deleted file mode 100644 index ac81567c05..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmJoinColumn.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmBaseColumn; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmJoinColumn extends AbstractOrmBaseColumn<XmlJoinColumn> implements OrmJoinColumn -{ - - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected XmlJoinColumn resourceJoinColumn; - - public GenericOrmJoinColumn(XmlContextNode parent, OrmJoinColumn.Owner owner, XmlJoinColumn resourceJoinColumn) { - super(parent, owner); - this.initialize(resourceJoinColumn); - } - - 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; - getResourceColumn().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 - public OrmJoinColumn.Owner getOwner() { - return (OrmJoinColumn.Owner) this.owner; - } - - public Table getReferencedColumnDbTable() { - return getOwner().getReferencedColumnDbTable(); - } - - public Column getReferencedDbColumn() { - Table table = getReferencedColumnDbTable(); - return (table == null) ? null : table.getColumnForIdentifier(getReferencedColumnName()); - } - - public boolean isReferencedColumnResolved() { - return getReferencedDbColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange() { - if (getResourceColumn() != null) { - TextRange textRange = getResourceColumn().getReferencedColumnNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - - @Override - protected XmlJoinColumn getResourceColumn() { - return this.resourceJoinColumn; - } - - @Override - protected void addResourceColumn() { - //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 removeResourceColumn() { - //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 - protected void initialize(XmlJoinColumn xjc) { - this.resourceJoinColumn = xjc; - super.initialize(xjc); - this.specifiedReferencedColumnName = buildSpecifiedReferencedColumnName(xjc); - this.defaultReferencedColumnName = buildDefaultReferencedColumnName(); - } - - @Override - public void update(XmlJoinColumn xjc) { - this.resourceJoinColumn = xjc; - super.update(xjc); - this.setSpecifiedReferencedColumnName_(buildSpecifiedReferencedColumnName(xjc)); - this.setDefaultReferencedColumnName(buildDefaultReferencedColumnName()); - } - - protected String buildSpecifiedReferencedColumnName(XmlJoinColumn xjc) { - return (xjc == null) ? null : xjc.getReferencedColumnName(); - } - - @Override - protected String buildDefaultName() { - return MappingTools.buildJoinColumnDefaultName(this); - } - - protected String buildDefaultReferencedColumnName() { - return MappingTools.buildJoinColumnDefaultReferencedColumnName(this.getOwner()); - } - - - //******************* validation *********************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - validateName(messages); - validateReferencedColumnName(messages); - } - - protected void validateName(List<IMessage> messages) { - if ( ! this.isResolved() && getDbTable() != null) { - if (getName() != null) { - messages.add(this.buildUnresolvedMessage()); - } - else if (getOwner().joinColumnsSize() > 1) { - - } - } - } - - protected void validateReferencedColumnName(List<IMessage> messages) { - if ( ! this.isReferencedColumnResolved() && getReferencedColumnDbTable() != null) { - if (getReferencedColumnName() != null) { - messages.add(this.buildUnresolvedMessage()); - } - else if (getOwner().joinColumnsSize() > 1) { - - } - } - } - - protected IMessage buildUnresolvedMessage() { - OrmRelationshipMapping mapping = (OrmRelationshipMapping) this.getOwner().getRelationshipMapping(); - return mapping.getPersistentAttribute().isVirtual() ? this.buildVirtualUnresolvedNameMessage(mapping) : this.buildNonVirtualUnresolvedNameMessage(); - } - - protected IMessage buildVirtualUnresolvedNameMessage(OrmRelationshipMapping mapping) { - return this.buildMessage( - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {mapping.getName(), this.getName()}, - this.getNameTextRange() - ); - } - - protected IMessage buildNonVirtualUnresolvedNameMessage() { - return this.buildMessage( - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {this.getName()}, - this.getNameTextRange() - ); - } - - protected IMessage buildUnresolvedReferenceColumnNameMessage() { - OrmRelationshipMapping mapping = (OrmRelationshipMapping) this.getOwner().getRelationshipMapping(); - return mapping.getPersistentAttribute().isVirtual() ? this.buildVirtualUnresolvedReferenceColumnNameMessage(mapping) : this.buildNonVirtualUnresolvedReferenceColumnNameMessage(); - } - - protected IMessage buildVirtualUnresolvedReferenceColumnNameMessage(OrmRelationshipMapping mapping) { - return this.buildMessage( - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {mapping.getName(), this.getName()}, - this.getReferencedColumnNameTextRange() - ); - } - - protected IMessage buildNonVirtualUnresolvedReferenceColumnNameMessage() { - return this.buildMessage( - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {this.getName()}, - this.getReferencedColumnNameTextRange() - ); - } - - protected IMessage buildMessage(String msgID, String[] parms, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage(IMessage.HIGH_SEVERITY, msgID, parms, this, textRange); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmJoinTable.java deleted file mode 100644 index 3ef58d4473..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmJoinTable.java +++ /dev/null @@ -1,765 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; - -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.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.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmTable; -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.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * orm.xml join table - */ -public class GenericOrmJoinTable - extends AbstractOrmTable - implements OrmJoinTable -{ - protected OrmJoinColumn defaultJoinColumn; - - protected final Vector<OrmJoinColumn> specifiedJoinColumns = new Vector<OrmJoinColumn>(); - protected final OrmJoinColumn.Owner joinColumnOwner; - - protected OrmJoinColumn defaultInverseJoinColumn; - - protected final Vector<OrmJoinColumn> specifiedInverseJoinColumns = new Vector<OrmJoinColumn>(); - protected final OrmJoinColumn.Owner inverseJoinColumnOwner; - - - public GenericOrmJoinTable(OrmJoinTableJoiningStrategy parent, XmlJoinTable resourceJoinTable) { - super(parent); - this.joinColumnOwner = this.buildJoinColumnOwner(); - this.inverseJoinColumnOwner = this.buildInverseJoinColumnOwner(); - this.initialize(resourceJoinTable); - } - - protected OrmJoinColumn.Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected OrmJoinColumn.Owner buildInverseJoinColumnOwner() { - return new InverseJoinColumnOwner(); - } - - public RelationshipMapping getRelationshipMapping() { - return getParent().getRelationshipReference().getRelationshipMapping(); - } - - public void initializeFrom(JoinTable oldJoinTable) { - super.initializeFrom(oldJoinTable); - for (Iterator<OrmJoinColumn> stream = oldJoinTable.specifiedJoinColumns(); stream.hasNext(); ) { - this.addSpecifiedJoinColumnFrom(stream.next()); - } - for (Iterator<OrmJoinColumn> stream = oldJoinTable.specifiedInverseJoinColumns(); stream.hasNext(); ) { - this.addSpecifiedInverseJoinColumnFrom(stream.next()); - } - } - - protected void initialize(XmlJoinTable joinTable) { - super.initialize(joinTable); - this.initializeSpecifiedJoinColumns(joinTable); - this.initializeDefaultJoinColumn(); - this.initializeSpecifiedInverseJoinColumns(joinTable); - this.initializeDefaultInverseJoinColumn(); - } - - public void update() { - this.update(this.getResourceTable()); - } - - protected void update(XmlJoinTable joinTable) { - super.update(joinTable); - this.updateSpecifiedJoinColumns(joinTable); - this.updateDefaultJoinColumn(); - this.updateSpecifiedInverseJoinColumns(joinTable); - this.updateDefaultInverseJoinColumn(); - } - - - // ********** AbstractOrmTable implementation ********** - - @Override - public OrmJoinTableJoiningStrategy getParent() { - return (OrmJoinTableJoiningStrategy) super.getParent(); - } - - @Override - protected String buildDefaultName() { - return this.getParent().getJoinTableDefaultName(); - } - - /** - * if the join table is on the "mappedBy" side, it's bogus; - * so don't give it a default schema - */ - @Override - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - @Override - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - @Override - protected XmlJoinTable getResourceTable() { - return this.getParent().getResourceJoinTable(); - } - - @Override - protected XmlJoinTable addResourceTable() { - return getParent().addResourceJoinTable(); - } - - @Override - protected void removeResourceTable() { - getParent().removeResourceJoinTable(); - } - - - // ********** join columns ********** - - public ListIterator<OrmJoinColumn> joinColumns() { - return this.hasSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.hasSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public void convertDefaultToSpecifiedJoinColumn() { - MappingTools.convertJoinTableDefaultToSpecifiedJoinColumn(this); - } - - - // ********** default join column ********** - - public OrmJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(OrmJoinColumn defaultJoinColumn) { - OrmJoinColumn old = this.defaultJoinColumn; - this.defaultJoinColumn = defaultJoinColumn; - this.firePropertyChanged(DEFAULT_JOIN_COLUMN, old, defaultJoinColumn); - } - - 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; - } - - protected void initializeDefaultJoinColumn() { - if (this.shouldBuildDefaultJoinColumn()) { - this.defaultJoinColumn = this.buildJoinColumn(null); - } - } - - protected void updateDefaultJoinColumn() { - if (this.shouldBuildDefaultJoinColumn()) { - if (this.defaultJoinColumn == null) { - this.setDefaultJoinColumn(this.buildJoinColumn(null)); - } else { - this.defaultJoinColumn.update(null); - } - } else { - this.setDefaultJoinColumn(null); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return ! this.hasSpecifiedJoinColumns(); - } - - - // ********** specified join columns ********** - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean hasSpecifiedJoinColumns() { - return this.specifiedJoinColumns.size() != 0; - } - - protected void addSpecifiedJoinColumnFrom(OrmJoinColumn oldJoinColumn) { - OrmJoinColumn newJoinColumn = this.addSpecifiedJoinColumn(this.specifiedJoinColumns.size()); - newJoinColumn.initializeFrom(oldJoinColumn); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - if (this.getResourceTable() == null) { - this.addResourceTable(); - } - XmlJoinColumn xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumn(); - OrmJoinColumn joinColumn = this.buildJoinColumn(xmlJoinColumn); - this.specifiedJoinColumns.add(index, joinColumn); - this.getResourceTable().getJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - this.addItemToList(index, joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedJoinColumn(OrmJoinColumn joinColumn) { - this.addSpecifiedJoinColumn(this.specifiedJoinColumns.size(), joinColumn); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if ( ! this.hasSpecifiedJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = this.buildJoinColumn(null); - } - this.getResourceTable().getJoinColumns().remove(index); - this.fireItemRemoved(SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(OrmJoinColumn joinColumn) { - this.removeItemFromList(joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getResourceTable().getJoinColumns().move(targetIndex, sourceIndex); - this.fireItemMoved(SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void clearSpecifiedJoinColumns() { - this.specifiedJoinColumns.clear(); - this.defaultJoinColumn = this.buildJoinColumn(null); - this.getResourceTable().getJoinColumns().clear(); - this.fireListCleared(SPECIFIED_JOIN_COLUMNS_LIST); - this.firePropertyChanged(DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn resourceJoinColumn) { - return this.buildJoinColumn(resourceJoinColumn, this.joinColumnOwner); - } - - protected void initializeSpecifiedJoinColumns(XmlJoinTable xmlJoinTable) { - if (xmlJoinTable != null) { - for (XmlJoinColumn xmlJoinColumn : xmlJoinTable.getJoinColumns()) { - this.specifiedJoinColumns.add(this.buildJoinColumn(xmlJoinColumn)); - } - } - } - - protected void updateSpecifiedJoinColumns(XmlJoinTable xmlJoinTable) { - Iterator<XmlJoinColumn> xmlJoinColumns = this.xmlJoinColumns(xmlJoinTable); - - for (Iterator<OrmJoinColumn> contextJoinColumns = this.specifiedJoinColumns(); contextJoinColumns.hasNext(); ) { - OrmJoinColumn contextJoinColumn = contextJoinColumns.next(); - if (xmlJoinColumns.hasNext()) { - contextJoinColumn.update(xmlJoinColumns.next()); - } else { - this.removeSpecifiedJoinColumn_(contextJoinColumn); - } - } - - while (xmlJoinColumns.hasNext()) { - this.addSpecifiedJoinColumn(this.buildJoinColumn(xmlJoinColumns.next())); - } - } - - protected Iterator<XmlJoinColumn> xmlJoinColumns(XmlJoinTable xmlJoinTable) { - // make a copy of the XML join columns (to prevent ConcurrentModificationException) - return (xmlJoinTable == null) ? EmptyIterator.<XmlJoinColumn>instance() - : new CloneIterator<XmlJoinColumn>(xmlJoinTable.getJoinColumns()); - } - - - // ********** inverse join columns ********** - - public ListIterator<OrmJoinColumn> inverseJoinColumns() { - return this.hasSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumns() : this.defaultInverseJoinColumns(); - } - - public int inverseJoinColumnsSize() { - return this.hasSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumnsSize() : this.defaultInverseJoinColumnsSize(); - } - - public void convertDefaultToSpecifiedInverseJoinColumn() { - MappingTools.convertJoinTableDefaultToSpecifiedInverseJoinColumn(this); - } - - - // ********** default inverse join column ********** - - public OrmJoinColumn getDefaultInverseJoinColumn() { - return this.defaultInverseJoinColumn; - } - - protected void setDefaultInverseJoinColumn(OrmJoinColumn defaultInverseJoinColumn) { - OrmJoinColumn old = this.defaultInverseJoinColumn; - this.defaultInverseJoinColumn = defaultInverseJoinColumn; - this.firePropertyChanged(DEFAULT_INVERSE_JOIN_COLUMN, old, defaultInverseJoinColumn); - } - - 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; - } - - protected void initializeDefaultInverseJoinColumn() { - if (this.shouldBuildDefaultInverseJoinColumn()) { - this.defaultInverseJoinColumn = this.buildInverseJoinColumn(null); - } - } - - protected void updateDefaultInverseJoinColumn() { - if (this.shouldBuildDefaultInverseJoinColumn()) { - if (this.defaultInverseJoinColumn == null) { - this.setDefaultInverseJoinColumn(this.buildInverseJoinColumn(null)); - } else { - this.defaultInverseJoinColumn.update(null); - } - } else { - this.setDefaultInverseJoinColumn(null); - } - } - - protected boolean shouldBuildDefaultInverseJoinColumn() { - return ! this.hasSpecifiedInverseJoinColumns(); - } - - - // ********** specified inverse join columns ********** - - public ListIterator<OrmJoinColumn> specifiedInverseJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedInverseJoinColumns); - } - - public int specifiedInverseJoinColumnsSize() { - return this.specifiedInverseJoinColumns.size(); - } - - public boolean hasSpecifiedInverseJoinColumns() { - return !this.specifiedInverseJoinColumns.isEmpty(); - } - - protected void addSpecifiedInverseJoinColumnFrom(OrmJoinColumn oldJoinColumn) { - OrmJoinColumn newJoinColumn = this.addSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.size()); - newJoinColumn.initializeFrom(oldJoinColumn); - } - - public OrmJoinColumn addSpecifiedInverseJoinColumn(int index) { - if (this.getResourceTable() == null) { - this.addResourceTable(); - } - XmlJoinColumn xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumn(); - OrmJoinColumn joinColumn = this.buildInverseJoinColumn(xmlJoinColumn); - this.specifiedInverseJoinColumns.add(index, joinColumn); - this.getResourceTable().getInverseJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected void addSpecifiedInverseJoinColumn(int index, OrmJoinColumn joinColumn) { - this.addItemToList(index, joinColumn, this.specifiedInverseJoinColumns, SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedInverseJoinColumn(OrmJoinColumn joinColumn) { - this.addSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.size(), joinColumn); - } - - public void removeSpecifiedInverseJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedInverseJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedInverseJoinColumns.remove(index); - if ( ! this.hasSpecifiedInverseJoinColumns()) { - //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 = this.buildInverseJoinColumn(null); - } - this.getResourceTable().getInverseJoinColumns().remove(index); - this.fireItemRemoved(SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultInverseJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(DEFAULT_INVERSE_JOIN_COLUMN, null, this.defaultInverseJoinColumn); - } - } - - protected void removeSpecifiedInverseJoinColumn_(OrmJoinColumn joinColumn) { - this.removeItemFromList(joinColumn, this.specifiedInverseJoinColumns, SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedInverseJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedInverseJoinColumns, targetIndex, sourceIndex); - this.getResourceTable().getInverseJoinColumns().move(targetIndex, sourceIndex); - this.fireItemMoved(SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void clearSpecifiedInverseJoinColumns() { - this.specifiedInverseJoinColumns.clear(); - this.defaultInverseJoinColumn = this.buildInverseJoinColumn(null); - this.getResourceTable().getInverseJoinColumns().clear(); - this.fireListCleared(SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - this.firePropertyChanged(DEFAULT_INVERSE_JOIN_COLUMN, null, this.defaultInverseJoinColumn); - } - - protected OrmJoinColumn buildInverseJoinColumn(XmlJoinColumn resourceJoinColumn) { - return this.buildJoinColumn(resourceJoinColumn, this.inverseJoinColumnOwner); - } - - protected void initializeSpecifiedInverseJoinColumns(XmlJoinTable xmlJoinTable) { - if (xmlJoinTable != null) { - for (XmlJoinColumn xmlJoinColumn : xmlJoinTable.getInverseJoinColumns()) { - this.specifiedInverseJoinColumns.add(this.buildInverseJoinColumn(xmlJoinColumn)); - } - } - } - - protected void updateSpecifiedInverseJoinColumns(XmlJoinTable xmlJoinTable) { - Iterator<XmlJoinColumn> xmlJoinColumns = this.xmlInverseJoinColumns(xmlJoinTable); - - for (ListIterator<OrmJoinColumn> contextJoinColumns = this.specifiedInverseJoinColumns(); contextJoinColumns.hasNext(); ) { - OrmJoinColumn contextColumn = contextJoinColumns.next(); - if (xmlJoinColumns.hasNext()) { - contextColumn.update(xmlJoinColumns.next()); - } else { - this.removeSpecifiedInverseJoinColumn_(contextColumn); - } - } - - while (xmlJoinColumns.hasNext()) { - this.addSpecifiedInverseJoinColumn(this.buildInverseJoinColumn(xmlJoinColumns.next())); - } - } - - protected Iterator<XmlJoinColumn> xmlInverseJoinColumns(XmlJoinTable xmlJoinTable) { - // make a copy of the XML join columns (to prevent ConcurrentModificationException) - return (xmlJoinTable == null) ? EmptyIterator.<XmlJoinColumn>instance() - : new CloneIterator<XmlJoinColumn>(xmlJoinTable.getInverseJoinColumns()); - } - - - // ********** misc ********** - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn resourceJoinColumn, OrmJoinColumn.Owner owner) { - return this.getXmlContextNodeFactory().buildOrmJoinColumn(this, owner, resourceJoinColumn); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.connectionProfileIsActive()) { - this.validateAgainstDatabase(messages, reporter); - } - } - - protected void validateAgainstDatabase(List<IMessage> messages, IReporter reporter) { - RelationshipMapping mapping = this.getRelationshipMapping(); - - if ( ! this.hasResolvedCatalog()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_CATALOG, - new String[] {mapping.getName(), this.getCatalog(), this.getName()}, - this, - this.getCatalogTextRange() - ) - ); - - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_CATALOG, - new String[] {this.getCatalog(), this.getName()}, - this, - this.getCatalogTextRange() - ) - ); - } - return; - } - - if ( ! this.hasResolvedSchema()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {mapping.getName(), this.getSchema(), this.getName()}, - this, - this.getSchemaTextRange() - ) - ); - } else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {this.getSchema(), this.getName()}, - this, - this.getSchemaTextRange() - ) - ); - } - return; - } - if ( ! this.isResolved()) { - if (getName() != null) { //if name is null, the validation will be handled elsewhere, such as the target entity is not defined - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_NAME, - new String[] {mapping.getName(), this.getName()}, - this, - this.getNameTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange()) - ); - } - } - return; - } - - this.validateJoinColumns(this.joinColumns(), messages, reporter); - this.validateJoinColumns(this.inverseJoinColumns(), messages, reporter); - } - - protected void validateJoinColumns(Iterator<OrmJoinColumn> joinColumns, List<IMessage> messages, IReporter reporter) { - while (joinColumns.hasNext()) { - joinColumns.next().validate(messages, reporter); - } - } - - - // ********** join column owner adapters ********** - - /** - * just a little common behavior - */ - protected abstract class AbstractJoinColumnOwner - implements OrmJoinColumn.Owner - { - protected AbstractJoinColumnOwner() { - super(); - } - - public TypeMapping getTypeMapping() { - return GenericOrmJoinTable.this.getParent().getRelationshipReference().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) { - String joinTableName = GenericOrmJoinTable.this.getName(); - return (joinTableName == null) ? null : (joinTableName.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 "back-pointer" JoinColumns; - * these point at the source/owning entity - */ - protected class JoinColumnOwner - extends AbstractJoinColumnOwner - { - protected JoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericOrmJoinTable.this.getParent().getRelationshipReference().getEntity(); - } - - public String getAttributeName() { - Entity targetEntity = GenericOrmJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - for (PersistentAttribute each : CollectionTools.iterable(targetEntity.getPersistentType().allAttributes())) { - if (each.getMapping().isOwnedBy(this.getRelationshipMapping())) { - return each.getName(); - } - } - return null; - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - return (dbTable != null) ? dbTable : this.getTypeMapping().getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getReferencedColumnDbTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmJoinTable.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public int joinColumnsSize() { - return GenericOrmJoinTable.this.joinColumnsSize(); - } - } - - - /** - * owner for "forward-pointer" JoinColumns; - * these point at the target/inverse entity - */ - protected class InverseJoinColumnOwner - extends AbstractJoinColumnOwner - { - protected 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 = this.getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getReferencedColumnDbTable() { - Entity targetEntity = this.getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmJoinTable.this.defaultInverseJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public int joinColumnsSize() { - return GenericOrmJoinTable.this.inverseJoinColumnsSize(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmLobConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmLobConverter.java deleted file mode 100644 index 42fd684272..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmLobConverter.java +++ /dev/null @@ -1,58 +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.jpa1.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.LobConverter; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.XmlConvertibleMapping; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmLobConverter extends AbstractOrmXmlContextNode - implements LobConverter, OrmConverter -{ - private XmlConvertibleMapping resourceConvertibleMapping; - - public GenericOrmLobConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - super(parent); - this.initialize(resourceMapping); - } - - @Override - public OrmAttributeMapping getParent() { - return (OrmAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.LOB_CONVERTER; - } - - public void initialize(XmlConvertibleMapping resourceConvertibleMapping) { - this.resourceConvertibleMapping = resourceConvertibleMapping; - } - - public void update() { - //do nothing - } - - public TextRange getValidationTextRange() { - return this.resourceConvertibleMapping.getLobTextRange(); - } - - public void addToResourceModel() { - this.resourceConvertibleMapping.setLob(true); - } - - public void removeFromResourceModel() { - this.resourceConvertibleMapping.setLob(false); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmManyToManyMapping.java deleted file mode 100644 index 8e234abd99..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmManyToManyMapping.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmManyToManyMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; - -public class GenericOrmManyToManyMapping - extends AbstractOrmManyToManyMapping<XmlManyToMany> - implements OrmManyToManyMapping -{ - public GenericOrmManyToManyMapping(OrmPersistentAttribute parent, XmlManyToMany resourceMapping) { - super(parent, resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmManyToOneMapping.java deleted file mode 100644 index 022dca900a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmManyToOneMapping.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmManyToOneMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; - -public class GenericOrmManyToOneMapping - extends AbstractOrmManyToOneMapping<XmlManyToOne> -{ - public GenericOrmManyToOneMapping(OrmPersistentAttribute parent, XmlManyToOne resourceMapping) { - super(parent, resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmMappedSuperclass.java deleted file mode 100644 index bbb9ea11cf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmMappedSuperclass.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; - - -public class GenericOrmMappedSuperclass extends AbstractOrmMappedSuperclass -{ - - public GenericOrmMappedSuperclass(OrmPersistentType parent, XmlMappedSuperclass resourceMapping) { - super(parent, resourceMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java deleted file mode 100644 index 43fa8e2a73..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; - - -public class GenericOrmNamedNativeQuery extends AbstractOrmQuery<XmlNamedNativeQuery> - implements OrmNamedNativeQuery -{ - - protected String resultClass; - - protected String resultSetMapping; - - - public GenericOrmNamedNativeQuery(XmlContextNode parent, XmlNamedNativeQuery resourceQuery) { - super(parent, resourceQuery); - } - - public char getResultClassEnclosingTypeSeparator() { - return '$'; - } - - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - getResourceQuery().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; - getResourceQuery().setResultSetMapping(newResultSetMapping); - firePropertyChanged(NamedNativeQuery.RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - - @Override - protected void initialize(XmlNamedNativeQuery resourceQuery) { - super.initialize(resourceQuery); - this.resultClass = resourceQuery.getResultClass(); - this.resultSetMapping = resourceQuery.getResultSetMapping(); - } - - @Override - public void update(XmlNamedNativeQuery resourceQuery) { - super.update(resourceQuery); - this.setResultClass(resourceQuery.getResultClass()); - this.setResultSetMapping(resourceQuery.getResultSetMapping()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java deleted file mode 100644 index cba78423e0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java +++ /dev/null @@ -1,25 +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.jpa1.context.orm; - -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; - - -public class GenericOrmNamedQuery extends AbstractOrmQuery<XmlNamedQuery> implements OrmNamedQuery -{ - - public GenericOrmNamedQuery(XmlContextNode parent, XmlNamedQuery resourceNamedQuery) { - super(parent, resourceNamedQuery); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNullAttributeMapping.java deleted file mode 100644 index fe1d04fdc2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNullAttributeMapping.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmAttributeMapping; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; - - -public class GenericOrmNullAttributeMapping - extends AbstractOrmAttributeMapping<XmlNullAttributeMapping> -{ - - public GenericOrmNullAttributeMapping(OrmPersistentAttribute parent, XmlNullAttributeMapping resourceMapping) { - super(parent, resourceMapping); - } - - public int getXmlSequence() { - return -1; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmAttributeMapping(this); - } - - public String getKey() { - return null; - } - - public void addToResourceModel(Attributes resourceAttributes) { - throw new UnsupportedOperationException(); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNullConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNullConverter.java deleted file mode 100644 index 4bd82741ee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmNullConverter.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.jpa1.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmNullConverter extends AbstractOrmXmlContextNode - implements OrmConverter -{ - - public GenericOrmNullConverter(OrmAttributeMapping parent) { - super(parent); - } - - @Override - public OrmAttributeMapping getParent() { - return (OrmAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.NO_CONVERTER; - } - - public TextRange getValidationTextRange() { - return null; - } - - public void update() { - // do nothing, null implementation - } - - public void addToResourceModel() { - // do nothing, null implementation - } - - public void removeFromResourceModel() { - // do nothing, null implementation - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyMapping.java deleted file mode 100644 index facb180a33..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyMapping.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmOneToManyMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; - - -public class GenericOrmOneToManyMapping extends AbstractOrmOneToManyMapping<XmlOneToMany> -{ - - public GenericOrmOneToManyMapping(OrmPersistentAttribute parent, XmlOneToMany resourceMapping) { - super(parent, resourceMapping); - } - - @Override - protected OrmRelationshipReference buildRelationshipReference() { - return new GenericOrmOneToManyRelationshipReference(this, this.resourceAttributeMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyRelationshipReference.java deleted file mode 100644 index 81e6dfcc21..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToManyRelationshipReference.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmOneToManyRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; - -public class GenericOrmOneToManyRelationshipReference - extends AbstractOrmOneToManyRelationshipReference -{ - - public GenericOrmOneToManyRelationshipReference( - OrmOneToManyMapping parent, XmlOneToMany resource) { - super(parent, resource); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - return this.joinTableJoiningStrategy; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToOneMapping.java deleted file mode 100644 index 3c0a879492..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmOneToOneMapping.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmOneToOneMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; - - -public class GenericOrmOneToOneMapping extends AbstractOrmOneToOneMapping<XmlOneToOne> -{ - - public GenericOrmOneToOneMapping(OrmPersistentAttribute parent, XmlOneToOne resourceMapping) { - super(parent, resourceMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentAttribute.java deleted file mode 100644 index 282848d631..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentAttribute.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.List; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmPersistentAttribute extends AbstractOrmPersistentAttribute -{ - - public GenericOrmPersistentAttribute(OrmPersistentType parent, Owner owner, XmlAttributeMapping resourceMapping) { - super(parent, owner, resourceMapping); - } - - //****************** AccessHolder implementation ******************* - - /** - * GenericOrmPersistentAttribute does not support specified access (no access element in 1.0), so we return null - */ - public AccessType getSpecifiedAccess() { - return null; - } - - public void setSpecifiedAccess(AccessType newSpecifiedAccess) { - throw new UnsupportedOperationException("specifiedAccess is not supported for GenericOrmPersistentAttribute"); //$NON-NLS-1$ - } - - @Override - protected void validateAttribute(List<IMessage> messages) { - super.validateAttribute(messages); - if (this.javaPersistentAttribute != null) { - JavaPersistentType javaPersistentType = getPersistentType().getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getAttributeNamed(this.javaPersistentAttribute.getName()) == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED, - new String[] {this.getName(), this.getPersistentType().getMapping().getClass_()}, - this.attributeMapping, - this.attributeMapping.getNameTextRange() - ) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java deleted file mode 100644 index 1c5655e658..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java +++ /dev/null @@ -1,993 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.ClassTools; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmPersistentType - extends AbstractOrmXmlContextNode - implements OrmPersistentType -{ - protected final List<OrmPersistentAttribute> specifiedPersistentAttributes; - - protected final List<OrmPersistentAttribute> virtualPersistentAttributes; - - protected AccessType defaultAccess; - - protected AccessType specifiedAccess; - - protected OrmTypeMapping typeMapping; - - protected PersistentType superPersistentType; - - protected JavaPersistentType javaPersistentType; - - - public GenericOrmPersistentType(EntityMappings parent, XmlTypeMapping resourceMapping) { - super(parent); - this.specifiedPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); - this.virtualPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); - this.typeMapping = buildTypeMapping(resourceMapping); - this.specifiedAccess = this.getResourceAccess(); - this.defaultAccess = this.buildDefaultAccess(); - this.javaPersistentType = this.buildJavaPersistentType(); - this.superPersistentType = this.buildSuperPersistentType(); - this.initializePersistentAttributes(); - } - - - // ********** OrmPersistentType implementation ********** - - @Override - public EntityMappings getParent() { - return (EntityMappings) super.getParent(); - } - - protected EntityMappings getEntityMappings() { - return this.getParent(); - } - - public String getDefaultPackage() { - return this.getEntityMappings().getDefaultPersistentTypePackage(); - } - - public boolean isDefaultMetadataComplete() { - return this.getEntityMappings().isDefaultPersistentTypeMetadataComplete(); - } - - public String getId() { - return OrmStructureNodes.PERSISTENT_TYPE_ID; - } - - public boolean isFor(String typeName) { - String className = this.getName(); - if (className == null) { - return false; - } - if (className.equals(typeName)) { - return true; - } - String defaultPackage = this.getDefaultPackage(); - if (defaultPackage == null) { - return false; - } - return (defaultPackage + '.' + className).equals(typeName); - } - - protected OrmTypeMapping buildTypeMapping(XmlTypeMapping resourceMapping) { - OrmTypeMappingDefinition mappingDefintion = - getMappingFileDefinition().getOrmTypeMappingDefinition(resourceMapping.getMappingKey()); - return mappingDefintion.buildContextMapping(this, resourceMapping, getXmlContextNodeFactory()); - } - - public OrmTypeMapping getMapping() { - return this.typeMapping; - } - - - // **************** PersistentType.Owner implementation ***************************** - - public AccessType getOverridePersistentTypeAccess() { - if (this.getSpecifiedAccess() != null) { - return this.getSpecifiedAccess(); - } - - if (this.superPersistentType instanceof OrmPersistentType) { - AccessType accessType = ((OrmPersistentType) this.superPersistentType).getSpecifiedAccess(); - if (accessType != null) { - return accessType; - } - } - - if (this.getMapping().isMetadataComplete()) { - AccessType accessType = this.getOwnerDefaultAccess(); - if (accessType != null) { - return accessType; - } - } - - // no override access type - return null; - } - - public AccessType getDefaultPersistentTypeAccess() { - if (this.superPersistentType instanceof OrmPersistentType) { - AccessType accessType = ((OrmPersistentType) this.superPersistentType).getDefaultAccess(); - if (accessType != null) { - return accessType; - } - } - - return this.getOwnerDefaultAccess(); - } - - // ********** PersistentType implementation ********** - - public void setMappingKey(String newMappingKey) { - if (this.valuesAreEqual(this.getMappingKey(), newMappingKey)) { - return; - } - OrmTypeMapping oldMapping = getMapping(); - OrmTypeMappingDefinition mappingDefintion = - getMappingFileDefinition().getOrmTypeMappingDefinition(newMappingKey); - XmlTypeMapping resourceTypeMapping = - mappingDefintion.buildResourceMapping(getResourceNodeFactory()); - this.typeMapping = buildTypeMapping(resourceTypeMapping); - this.getEntityMappings().changeMapping(this, oldMapping, this.typeMapping); - firePropertyChanged(MAPPING_PROPERTY, oldMapping, this.typeMapping); - } - - public Iterator<PersistentType> inheritanceHierarchy() { - return this.inheritanceHierarchyOf(this); - } - - public Iterator<PersistentType> ancestors() { - return this.inheritanceHierarchyOf(this.superPersistentType); - } - - protected Iterator<PersistentType> inheritanceHierarchyOf(PersistentType start) { - // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(start) { - @Override - protected PersistentType nextLink(PersistentType persistentType) { - return persistentType.getSuperPersistentType(); - } - }; - } - - public PersistentType getSuperPersistentType() { - return this.superPersistentType; - } - - protected void setSuperPersistentType(PersistentType superPersistentType) { - PersistentType old = this.superPersistentType; - this.superPersistentType = superPersistentType; - this.firePropertyChanged(SUPER_PERSISTENT_TYPE_PROPERTY, old, superPersistentType); - } - - 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.getResourceTypeMapping().setAccess(AccessType.toOrmResourceModel(newSpecifiedAccess)); - firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, oldSpecifiedAccess, newSpecifiedAccess); - } - - public AccessType getAccess() { - return (this.getSpecifiedAccess() == null) ? this.getDefaultAccess() : this.getSpecifiedAccess(); - } - - public AccessType getOwnerOverrideAccess() { - return this.getEntityMappings().getOverridePersistentTypeAccess(); - } - - public AccessType getOwnerDefaultAccess() { - return this.getEntityMappings().getDefaultPersistentTypeAccess(); - } - - public void changeMapping(OrmPersistentAttribute ormPersistentAttribute, OrmAttributeMapping oldMapping, OrmAttributeMapping newMapping) { - int sourceIndex = this.specifiedPersistentAttributes.indexOf(ormPersistentAttribute); - this.specifiedPersistentAttributes.remove(sourceIndex); - oldMapping.removeFromResourceModel(getResourceAttributes()); - int targetIndex = insertionIndex(ormPersistentAttribute); - this.specifiedPersistentAttributes.add(targetIndex, ormPersistentAttribute); - newMapping.addToResourceModel(getResourceAttributes()); - oldMapping.initializeOn(newMapping); - fireItemMoved(ATTRIBUTES_LIST, targetIndex, sourceIndex); - } - - public void makePersistentAttributeVirtual(OrmPersistentAttribute ormPersistentAttribute) { - if (ormPersistentAttribute.isVirtual()) { - throw new IllegalStateException("Attribute is already virtual"); //$NON-NLS-1$ - } - JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute(); - OrmPersistentAttribute virtualPersistentAttribute = null; - if (javaPersistentAttribute != null) { - virtualPersistentAttribute = addVirtualPersistentAttribute(javaPersistentAttribute.getResourcePersistentAttribute()); - } - 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"); //$NON-NLS-1$ - } - if (this.valuesAreEqual(mappingKey, MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY)) { - throw new IllegalStateException("Use makePersistentAttributeSpecified(OrmPersistentAttribute, String) instead and specify a mapping type"); //$NON-NLS-1$ - } - - Attributes resourceAttributes = getResourceAttributes(); - if (resourceAttributes == null) { - resourceAttributes = createResourceAttributes(); - getMapping().getResourceTypeMapping().setAttributes(resourceAttributes); - } - - OrmAttributeMappingDefinition mappingDefintion = - getMappingFileDefinition().getOrmAttributeMappingDefinition(mappingKey); - XmlAttributeMapping resourceMapping = - mappingDefintion.buildResourceMapping(getResourceNodeFactory()); - - OrmPersistentAttribute newPersistentAttribute = buildSpecifiedOrmPersistentAttribute(resourceMapping); - int insertionIndex = insertionIndex(newPersistentAttribute); - this.specifiedPersistentAttributes.add(insertionIndex, newPersistentAttribute); - newPersistentAttribute.getMapping().addToResourceModel(resourceAttributes); - - int removalIndex = this.virtualPersistentAttributes.indexOf(ormPersistentAttribute); - this.virtualPersistentAttributes.remove(ormPersistentAttribute); - newPersistentAttribute.getSpecifiedMapping().setName(ormPersistentAttribute.getName()); - if (ormPersistentAttribute.getJavaPersistentAttribute().getSpecifiedAccess() != null) { - newPersistentAttribute.setSpecifiedAccess(ormPersistentAttribute.getJavaPersistentAttribute().getSpecifiedAccess()); - } - - fireItemAdded(ATTRIBUTES_LIST, insertionIndex, newPersistentAttribute); - fireItemRemoved(VIRTUAL_ATTRIBUTES_LIST, removalIndex, ormPersistentAttribute); - } - - protected XmlTypeMapping getResourceTypeMapping() { - return this.typeMapping.getResourceTypeMapping(); - } - - protected Attributes getResourceAttributes() { - return this.getResourceTypeMapping().getAttributes(); - } - - protected Attributes createResourceAttributes() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getAttributes(), - Attributes.class); - } - - 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 getSpecifiedAttributeFor(final JavaResourcePersistentAttribute jrpa) { - for (OrmPersistentAttribute persistentAttribute : CollectionTools.iterable(specifiedAttributes())) { - if (persistentAttribute.getJavaPersistentAttribute() == null) { - continue; - } - if ( jrpa.equals(persistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute())) { - return persistentAttribute; - } - } - return null; - } - - @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, VIRTUAL_ATTRIBUTES_LIST); - } - - protected void removeVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - removeItemFromList(ormPersistentAttribute, this.virtualPersistentAttributes, VIRTUAL_ATTRIBUTES_LIST); - } - - protected void moveVirtualPersistentAttribute_(int index, OrmPersistentAttribute attribute) { - moveItemInList(index, this.virtualPersistentAttributes.indexOf(attribute), this.virtualPersistentAttributes, VIRTUAL_ATTRIBUTES_LIST); - } - - public boolean containsVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - return this.virtualPersistentAttributes.contains(ormPersistentAttribute); - } - - public OrmPersistentAttribute addSpecifiedPersistentAttribute(String mappingKey, String attributeName) { - Attributes resourceAttributes = getResourceAttributes(); - if (resourceAttributes == null) { - resourceAttributes = createResourceAttributes(); - getMapping().getResourceTypeMapping().setAttributes(resourceAttributes); - } - - OrmAttributeMappingDefinition mappingDefintion = - getMappingFileDefinition().getOrmAttributeMappingDefinition(mappingKey); - XmlAttributeMapping resourceMapping = - mappingDefintion.buildResourceMapping(getResourceNodeFactory()); - OrmPersistentAttribute persistentAttribute = - buildSpecifiedOrmPersistentAttribute(resourceMapping); - int index = insertionIndex(persistentAttribute); - this.specifiedPersistentAttributes.add(index, persistentAttribute); - persistentAttribute.getMapping().addToResourceModel(resourceAttributes); - - persistentAttribute.getSpecifiedMapping().setName(attributeName); - fireItemAdded(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 removeSpecifiedPersistentAttribute_(OrmPersistentAttribute ormPersistentAttribute) { - removeItemFromList(ormPersistentAttribute, this.specifiedPersistentAttributes, ATTRIBUTES_LIST); - } - - protected void moveSpecifiedPersistentAttribute_(int index, OrmPersistentAttribute attribute) { - moveItemInList(index, this.specifiedPersistentAttributes.indexOf(attribute), this.specifiedPersistentAttributes, ATTRIBUTES_LIST); - } - - public void removeSpecifiedPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - int index = this.specifiedPersistentAttributes.indexOf(ormPersistentAttribute); - this.specifiedPersistentAttributes.remove(ormPersistentAttribute); - ormPersistentAttribute.getMapping().removeFromResourceModel(getResourceAttributes()); - if (getResourceAttributes().isUnset()) { - this.typeMapping.getResourceTypeMapping().setAttributes(null); - } - fireItemRemoved(ATTRIBUTES_LIST, index, ormPersistentAttribute); - } - - public String getName() { - return this.getMapping().getClass_(); - } - - public String getShortName(){ - String className = this.getName(); - return (className == null) ? null : ClassTools.shortNameForClassNamed(className); - } - - 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 this.javaPersistentType; - } - - protected void setJavaPersistentType(JavaPersistentType newJavaPersistentType) { - JavaPersistentType oldJavaPersistentType = this.javaPersistentType; - this.javaPersistentType = newJavaPersistentType; - firePropertyChanged(JAVA_PERSISTENT_TYPE_PROPERTY, oldJavaPersistentType, newJavaPersistentType); - } - - protected AccessType getResourceAccess() { - return AccessType.fromOrmResourceModel(this.getResourceTypeMapping().getAccess()); - } - - protected AccessType buildDefaultAccess() { - if (! getMapping().isMetadataComplete()) { - if (this.javaPersistentType != null) { - if (javaPersistentTypeHasSpecifiedAccess()) { - return this.javaPersistentType.getAccess(); - } - if (this.superPersistentType != null) { - return this.superPersistentType.getAccess(); - } - } - } - AccessType access = getMappingFileRoot().getAccess(); - return access != null ? access : AccessType.FIELD; //default to FIELD if no specified access found - } - - protected boolean javaPersistentTypeHasSpecifiedAccess() { - return this.javaPersistentType.getSpecifiedAccess() != null || - this.javaPersistentType.hasAnyAnnotatedAttributes(); - } - - protected JavaPersistentType buildJavaPersistentType() { - JavaResourcePersistentType jrpt = this.getJavaResourcePersistentType(); - return (jrpt == null) ? null : this.buildJavaPersistentType(jrpt); - } - - protected JavaResourcePersistentType getJavaResourcePersistentType() { - String className = this.getName(); - if (className == null) { - return null; - } - className = className.replace('$', '.'); - - // first try to resolve using only the locally specified name... - JavaResourcePersistentType jrpt = this.getJavaResourcePersistentType(className); - if (jrpt != null) { - return jrpt; - } - - // ...then try to resolve by prepending the global package name - String defaultPackage = this.getDefaultPackage(); - if (defaultPackage == null) { - return null; - } - return this.getJavaResourcePersistentType(defaultPackage + '.' + className); - } - - protected JavaResourcePersistentType getJavaResourcePersistentType(String className) { - return this.getJpaProject().getJavaResourcePersistentType(className); - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourcePersistentType jrpt) { - return getJpaFactory().buildJavaPersistentType(this, jrpt); - } - - protected void initializePersistentAttributes() { - this.initializeSpecifiedPersistentAttributes(); - this.initializeVirtualPersistentAttributes(); - } - - protected OrmPersistentAttribute buildSpecifiedOrmPersistentAttribute(XmlAttributeMapping resourceMapping) { - return buildOrmPersistentAttribute(buildSpecifiedPersistentAttributeOwner(), resourceMapping); - } - - protected OrmPersistentAttribute.Owner buildSpecifiedPersistentAttributeOwner() { - return new SpecifiedPersistentAttributeOwner(); - } - - /** - * All orm.xml persistent types must be able to generate a static metamodel - * because 1.0 orm.xml files can be referenced from 2.0 persistence.xml files. - */ - public void synchronizeStaticMetamodel() { - // if we get here, it's safe to assume the JPA project is 2.0 - if (this.javaPersistentType != null) { - ((JpaProject2_0) this.getJpaProject()).synchronizeStaticMetamodel(this); - } - } - - protected class SpecifiedPersistentAttributeOwner implements OrmPersistentAttribute.Owner { - - private JavaPersistentAttribute cachedJavaPersistentAttribute; - - public JavaPersistentAttribute findJavaPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - if (GenericOrmPersistentType.this.javaPersistentType == null) { - return null; - } - String ormName = ormPersistentAttribute.getName(); - if (ormName == null) { - return null; - } - AccessType ormAccess = ormPersistentAttribute.getAccess(); - - JavaPersistentAttribute javaPersistentAttribute = this.findExistingJavaPersistentAttribute(ormName); - if ((javaPersistentAttribute != null) && (javaPersistentAttribute.getAccess() == ormAccess)) { - this.cachedJavaPersistentAttribute = null; // we only want to cache the persistent attribute if we build it - return javaPersistentAttribute; - } - - // if 'javaPersistentAttribute' is null, it might exist in a superclass that is not persistent, we need to build it ourselves. - // if access is different, we won't be able to find the corresponding java persistent attribute, it won't exist so we build it ourselves - return this.buildJavaPersistentAttribute(ormName, ormAccess); - } - - protected JavaPersistentAttribute findExistingJavaPersistentAttribute(String attributeName) { - return GenericOrmPersistentType.this.javaPersistentType.getAttributeNamed(attributeName); - } - - protected JavaPersistentAttribute buildJavaPersistentAttribute(String ormName, AccessType ormAccess) { - JavaResourcePersistentAttribute jrpa = this.getJavaResourcePersistentAttribute(this.getJavaResourcePersistentType(), ormName, ormAccess); - if (this.cachedJavaPersistentAttribute != null && - this.cachedJavaPersistentAttribute.getResourcePersistentAttribute() == jrpa) { - return this.cachedJavaPersistentAttribute; - } - return this.cachedJavaPersistentAttribute = (jrpa == null) ? null : GenericOrmPersistentType.this.buildJavaPersistentAttribute(jrpa); - } - - protected JavaResourcePersistentType getJavaResourcePersistentType() { - return GenericOrmPersistentType.this.javaPersistentType.getResourcePersistentType(); - } - - protected JavaResourcePersistentAttribute getJavaResourcePersistentAttribute(JavaResourcePersistentType javaResourcePersistentType, String ormName, AccessType ormAccess) { - for (Iterator<JavaResourcePersistentAttribute> stream = this.attributes(javaResourcePersistentType, ormAccess); stream.hasNext(); ) { - JavaResourcePersistentAttribute jrpa = stream.next(); - if (jrpa.getName().equals(ormName)) { - return jrpa; - } - } - // climb up inheritance hierarchy - String superclassName = javaResourcePersistentType.getSuperclassQualifiedName(); - if (superclassName == null) { - return null; - } - JavaResourcePersistentType superclass = GenericOrmPersistentType.this.getJavaResourcePersistentType(superclassName); - if (superclass == null) { - return null; - } - // recurse - return this.getJavaResourcePersistentAttribute(superclass, ormName, ormAccess); - } - - protected Iterator<JavaResourcePersistentAttribute> attributes(JavaResourcePersistentType javaResourcePersistentType, AccessType ormAccess) { - return (ormAccess == AccessType.PROPERTY) ? javaResourcePersistentType.persistableProperties() : javaResourcePersistentType.persistableFields(); - } - - public void updateJavaPersistentAttribute() { - if (this.cachedJavaPersistentAttribute != null) { - this.cachedJavaPersistentAttribute.update(); - } - //else { - //don't update, we don't own the java persistent attribute, - //it will be updated through the java context model - //} - } - } - - protected JavaPersistentAttribute buildJavaPersistentAttribute(JavaResourcePersistentAttribute jrpa) { - return this.getJpaFactory().buildJavaPersistentAttribute(this, jrpa); - } - - protected OrmPersistentAttribute buildVirtualOrmPersistentAttribute(JavaAttributeMapping javaAttributeMapping, XmlAttributeMapping resourceMapping) { - return buildOrmPersistentAttribute(buildVirtualPersistentAttributeOwner(javaAttributeMapping.getPersistentAttribute()), resourceMapping); - } - - protected OrmPersistentAttribute buildOrmPersistentAttribute(OrmPersistentAttribute.Owner owner, XmlAttributeMapping resourceMapping) { - return getXmlContextNodeFactory().buildOrmPersistentAttribute(this, owner, resourceMapping); - } - - protected OrmPersistentAttribute.Owner buildVirtualPersistentAttributeOwner(final JavaPersistentAttribute javaPersistentAttribute) { - return new OrmPersistentAttribute.Owner() { - public JavaPersistentAttribute findJavaPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - return javaPersistentAttribute; - } - - public void updateJavaPersistentAttribute() { - //update the attribute, since we own it and it will not get updated otherwise - javaPersistentAttribute.update(); - } - }; - } - - protected void initializeSpecifiedPersistentAttributes() { - Attributes attributes = this.getResourceAttributes(); - if (attributes == null) { - return; - } - for (XmlAttributeMapping resourceMapping : attributes.getAttributeMappings()) { - addSpecifiedPersistentAttribute(resourceMapping); - } - } - - protected void initializeVirtualPersistentAttributes() { - Iterator<JavaResourcePersistentAttribute> javaResourceAttributes = javaPersistentAttributes(); - - while (javaResourceAttributes.hasNext()) { - JavaResourcePersistentAttribute javaResourceAttribute = javaResourceAttributes.next(); - if (getSpecifiedAttributeFor(javaResourceAttribute) == null) { - addVirtualPersistentAttribute(javaResourceAttribute); - } - } - } - - protected Iterator<JavaResourcePersistentAttribute> javaPersistentAttributes() { - return (this.javaPersistentType == null) ? EmptyListIterator.<JavaResourcePersistentAttribute>instance() : - this.javaPersistentAttributes(this.javaPersistentType.getResourcePersistentType()); - } - - protected Iterator<JavaResourcePersistentAttribute> javaPersistentAttributes(JavaResourcePersistentType resourcePersistentType) { - AccessType access = getSpecifiedAccess(); - if (access == null && !getMapping().isMetadataComplete()) { - access = getJavaPersistentType().getSpecifiedAccess(); - } - if (access == null) { - access = this.getDefaultAccess(); - } - return resourcePersistentType.persistableAttributes(AccessType.toJavaResourceModel(access)); - } - - protected PersistentType buildSuperPersistentType() { - return (this.javaPersistentType == null) ? null : this.javaPersistentType.getSuperPersistentType(); - } - - public void update() { - this.setSpecifiedAccess(this.getResourceAccess()); - this.setDefaultAccess(this.buildDefaultAccess()); - this.getMapping().update(); - this.updateJavaPersistentType(); - this.updateSuperPersistentType(); - this.updatePersistentAttributes(); - } - - protected void updateJavaPersistentType() { - JavaResourcePersistentType jrpt = this.getJavaResourcePersistentType(); - if (jrpt == null) { - this.setJavaPersistentType(null); - } else { - if (this.javaPersistentType == null) { - this.setJavaPersistentType(this.buildJavaPersistentType(jrpt)); - } else { - this.javaPersistentType.update(jrpt); - } - } - } - - protected void updateSuperPersistentType() { - PersistentType spt = this.buildSuperPersistentType(); - // check for circular inheritance - if ((spt == null) || CollectionTools.contains(spt.inheritanceHierarchy(), this)) { - this.setSuperPersistentType(null); - } else { - this.setSuperPersistentType(spt); - } - } - - protected void updatePersistentAttributes() { - this.updateSpecifiedPersistentAttributes(); - this.updateVirtualPersistentAttributes(); - } - - protected void updateSpecifiedPersistentAttributes() { - Attributes attributes = this.getResourceAttributes(); - Collection<OrmPersistentAttribute> contextAttributesToRemove = CollectionTools.collection(specifiedAttributes()); - Collection<OrmPersistentAttribute> contextAttributesToUpdate = new ArrayList<OrmPersistentAttribute>(); - int resourceIndex = 0; - - if (attributes != null) { - for (XmlAttributeMapping resourceMapping : attributes.getAttributeMappings()) { - boolean contextAttributeFound = false; - for (OrmPersistentAttribute contextAttribute : contextAttributesToRemove) { - if (contextAttribute.getMapping().getResourceAttributeMapping() == resourceMapping) { - moveSpecifiedPersistentAttribute_(resourceIndex, contextAttribute); - contextAttributesToRemove.remove(contextAttribute); - contextAttributesToUpdate.add(contextAttribute); - contextAttributeFound = true; - break; - } - } - if (!contextAttributeFound) { - OrmPersistentAttribute ormPersistentAttribute = addSpecifiedPersistentAttribute(resourceMapping); - fireItemAdded(ATTRIBUTES_LIST, specifiedAttributesSize(), ormPersistentAttribute); - } - resourceIndex++; - } - } - for (OrmPersistentAttribute contextAttribute : contextAttributesToRemove) { - removeSpecifiedPersistentAttribute_(contextAttribute); - } - //first handle adding/removing of the persistent attributes, then update the others last, - //this causes less churn in the update process - for (OrmPersistentAttribute contextAttribute : contextAttributesToUpdate) { - contextAttribute.update(); - } - } - - //not firing change notification so this can be reused in initialize and update - protected OrmPersistentAttribute addSpecifiedPersistentAttribute(XmlAttributeMapping resourceMapping) { - OrmPersistentAttribute ormPersistentAttribute = buildSpecifiedOrmPersistentAttribute(resourceMapping); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - return ormPersistentAttribute; - } - - protected void updateVirtualPersistentAttributes() { - Collection<OrmPersistentAttribute> contextAttributesToRemove = CollectionTools.collection(virtualAttributes()); - Collection<OrmPersistentAttribute> contextAttributesToUpdate = new ArrayList<OrmPersistentAttribute>(); - int resourceIndex = 0; - - Iterator<JavaResourcePersistentAttribute> javaResourceAttributes = this.javaPersistentAttributes(); - for (JavaResourcePersistentAttribute javaResourceAttribute : CollectionTools.iterable(javaResourceAttributes)) { - OrmPersistentAttribute specifiedAttribute = getSpecifiedAttributeFor(javaResourceAttribute); - if (specifiedAttribute == null) { - JavaPersistentAttribute javaAttribute = getJpaFactory().buildJavaPersistentAttribute(this, javaResourceAttribute); - JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); - if (getMapping().isMetadataComplete()) { - javaAttributeMapping = javaAttribute.getDefaultMapping(); - } - boolean contextAttributeFound = false; - for (OrmPersistentAttribute contextAttribute : contextAttributesToRemove) { - JavaPersistentAttribute javaPersistentAttribute = contextAttribute.getJavaPersistentAttribute(); - if (javaPersistentAttribute.getResourcePersistentAttribute() == javaResourceAttribute) { - if (this.valuesAreEqual(contextAttribute.getMappingKey(), javaAttributeMapping.getKey())) { - //the mapping key would change if metaDataComplete flag changes, rebuild the orm attribute - moveVirtualPersistentAttribute_(resourceIndex, contextAttribute); - contextAttributesToRemove.remove(contextAttribute); - contextAttributesToUpdate.add(contextAttribute); - contextAttributeFound = true; - break; - } - } - } - if (!contextAttributeFound) { - OrmPersistentAttribute virtualPersistentAttribute = addVirtualPersistentAttribute(javaAttributeMapping); - fireItemAdded(VIRTUAL_ATTRIBUTES_LIST, virtualAttributesSize() - 1, virtualPersistentAttribute); - } - resourceIndex++; - } - } - - for (OrmPersistentAttribute contextAttribute : contextAttributesToRemove) { - removeVirtualPersistentAttribute(contextAttribute); - } - //first handle adding/removing of the persistent attributes, then update the others last, - //this causes less churn in the update process - for (OrmPersistentAttribute contextAttribute : contextAttributesToUpdate) { - contextAttribute.update(); - } - } - - protected OrmPersistentAttribute addVirtualPersistentAttribute(JavaResourcePersistentAttribute resourceAttribute) { - JavaPersistentAttribute javaAttribute = getJpaFactory().buildJavaPersistentAttribute(this, resourceAttribute); - - JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); - if (getMapping().isMetadataComplete()) { - javaAttributeMapping = javaAttribute.getDefaultMapping(); - } - return addVirtualPersistentAttribute(javaAttributeMapping); - } - - //not firing change notification so this can be reused in initialize and update - protected OrmPersistentAttribute addVirtualPersistentAttribute(JavaAttributeMapping javaAttributeMapping) { - OrmAttributeMappingDefinition mappingDefintion = - getMappingFileDefinition().getOrmAttributeMappingDefinition(javaAttributeMapping.getKey()); - XmlAttributeMapping resourceMapping = - mappingDefintion.buildVirtualResourceMapping(getMapping(), javaAttributeMapping, getXmlContextNodeFactory()); - OrmPersistentAttribute virtualPersistentAttribute = buildVirtualOrmPersistentAttribute(javaAttributeMapping, resourceMapping); - this.virtualPersistentAttributes.add(virtualPersistentAttribute); - return virtualPersistentAttribute; - } - - 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; - } - return (this.superPersistentType == null) ? null : this.superPersistentType.resolveAttribute(attributeName); - } - - @Override - public void postUpdate() { - super.postUpdate(); - if (this.javaPersistentType != null) { - this.javaPersistentType.postUpdate(); - } - getMapping().postUpdate(); - for (PersistentAttribute attribute : CollectionTools.iterable(attributes())) { - attribute.postUpdate(); - } - } - - 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.typeMapping.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.typeMapping.getSelectionTextRange(); - } - - //******************** validation ********************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateClass(messages); - this.validateMapping(messages, reporter); - this.validateAttributes(messages, reporter); - } - - protected void validateClass(List<IMessage> messages) { - if (this.javaPersistentType == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNRESOLVED_CLASS, - new String[] {this.getName()}, - this, - this.getMapping().getClassTextRange() - ) - ); - } - } - - protected void validateMapping(List<IMessage> messages, IReporter reporter) { - try { - this.typeMapping.validate(messages, reporter); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - - protected void validateAttributes(List<IMessage> messages, IReporter reporter) { - for (Iterator<OrmPersistentAttribute> stream = this.attributes(); stream.hasNext(); ) { - this.validateAttribute(stream.next(), messages, reporter); - } - } - - protected void validateAttribute(OrmPersistentAttribute attribute, List<IMessage> messages, IReporter reporter) { - try { - attribute.validate(messages, reporter); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - - public TextRange getValidationTextRange() { - return this.typeMapping.getValidationTextRange(); - } - - public void dispose() { - if (this.javaPersistentType != null) { - this.javaPersistentType.dispose(); - } - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPrimaryKeyJoinColumn.java deleted file mode 100644 index b469580539..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmNamedColumn; -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 resourcePkJoinColumn; - - public GenericOrmPrimaryKeyJoinColumn(XmlContextNode parent, OrmBaseJoinColumn.Owner owner, XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - super(parent, owner); - this.initialize(resourcePkJoinColumn); - } - - public void initializeFrom(PrimaryKeyJoinColumn oldPkJoinColumn) { - super.initializeFrom(oldPkJoinColumn); - setSpecifiedReferencedColumnName(oldPkJoinColumn.getSpecifiedReferencedColumnName()); - } - - @Override - protected XmlPrimaryKeyJoinColumn getResourceColumn() { - return this.resourcePkJoinColumn; - } - - @Override - protected void addResourceColumn() { - //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 removeResourceColumn() { - //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; - getResourceColumn().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 getReferencedDbColumn() { - Table table = this.getReferencedColumnDbTable(); - return (table == null) ? null : table.getColumnForIdentifier(this.getReferencedColumnName()); - } - - public Table getReferencedColumnDbTable() { - return getOwner().getReferencedColumnDbTable(); - } - - @Override - protected String getOwningTableName() { - return this.getOwner().getTypeMapping().getPrimaryTableName(); - } - - public boolean isReferencedColumnResolved() { - return getReferencedDbColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange() { - if (getResourceColumn() != null) { - TextRange textRange = getResourceColumn().getReferencedColumnNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - @Override - protected void initialize(XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - this.resourcePkJoinColumn = resourcePkJoinColumn; - super.initialize(resourcePkJoinColumn); - this.specifiedReferencedColumnName = getResourceReferencedColumnName(); - this.defaultReferencedColumnName = buildDefaultReferencedColumnName(); - } - - @Override - public void update(XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - this.resourcePkJoinColumn = resourcePkJoinColumn; - super.update(resourcePkJoinColumn); - this.setSpecifiedReferencedColumnName_(getResourceReferencedColumnName()); - this.setDefaultReferencedColumnName(buildDefaultReferencedColumnName()); - } - - protected String getResourceReferencedColumnName() { - return this.resourcePkJoinColumn == null ? null : this.resourcePkJoinColumn.getReferencedColumnName(); - } - - //TODO not correct when we start supporting primaryKeyJoinColumns in 1-1 mappings - protected String buildDefaultReferencedColumnName() { - return buildDefaultName(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java deleted file mode 100644 index b866bb0041..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -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.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryContainer; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -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.XmlNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlQueryContainer; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmQueryContainer extends AbstractOrmXmlContextNode - implements OrmQueryContainer -{ - private final XmlQueryContainer resourceQueryContainer; - - protected final List<OrmNamedQuery> namedQueries; - - protected final List<OrmNamedNativeQuery> namedNativeQueries; - - - public GenericOrmQueryContainer(XmlContextNode parent, XmlQueryContainer resourceQueryContainer) { - super(parent); - this.resourceQueryContainer = resourceQueryContainer; - this.namedQueries = new ArrayList<OrmNamedQuery>(); - this.namedNativeQueries = new ArrayList<OrmNamedNativeQuery>(); - this.initializeNamedQueries(); - this.initializeNamedNativeQueries(); - } - - public ListIterator<OrmNamedQuery> namedQueries() { - return new CloneListIterator<OrmNamedQuery>(this.namedQueries); - } - - public int namedQueriesSize() { - return this.namedQueries.size(); - } - - public OrmNamedQuery addNamedQuery(int index) { - XmlNamedQuery resourceNamedQuery = OrmFactory.eINSTANCE.createXmlNamedQuery(); - OrmNamedQuery contextNamedQuery = buildNamedQuery(resourceNamedQuery); - this.namedQueries.add(index, contextNamedQuery); - this.resourceQueryContainer.getNamedQueries().add(index, resourceNamedQuery); - this.fireItemAdded(NAMED_QUERIES_LIST, index, contextNamedQuery); - return contextNamedQuery; - } - - protected void addNamedQuery(int index, OrmNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, NAMED_QUERIES_LIST); - } - - protected void addNamedQuery(OrmNamedQuery namedQuery) { - this.addNamedQuery(this.namedQueries.size(), namedQuery); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - OrmNamedQuery namedQuery = this.namedQueries.remove(index); - this.resourceQueryContainer.getNamedQueries().remove(index); - fireItemRemoved(NAMED_QUERIES_LIST, index, namedQuery); - } - - protected void removeNamedQuery_(OrmNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - this.resourceQueryContainer.getNamedQueries().move(targetIndex, sourceIndex); - fireItemMoved(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) { - XmlNamedNativeQuery resourceNamedNativeQuery = OrmFactory.eINSTANCE.createXmlNamedNativeQuery(); - OrmNamedNativeQuery contextNamedNativeQuery = buildNamedNativeQuery(resourceNamedNativeQuery); - this.namedNativeQueries.add(index, contextNamedNativeQuery); - this.resourceQueryContainer.getNamedNativeQueries().add(index, resourceNamedNativeQuery); - this.fireItemAdded(NAMED_NATIVE_QUERIES_LIST, index, contextNamedNativeQuery); - return contextNamedNativeQuery; - } - - protected void addNamedNativeQuery(int index, OrmNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); - } - - protected void addNamedNativeQuery(OrmNamedNativeQuery namedNativeQuery) { - this.addNamedNativeQuery(this.namedNativeQueries.size(), namedNativeQuery); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - this.removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = this.namedNativeQueries.remove(index); - this.resourceQueryContainer.getNamedNativeQueries().remove(index); - fireItemRemoved(NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - } - - protected void removeNamedNativeQuery_(OrmNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - this.resourceQueryContainer.getNamedNativeQueries().move(targetIndex, sourceIndex); - fireItemMoved(NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); - } - - - protected void initializeNamedQueries() { - for (XmlNamedQuery namedQuery : this.resourceQueryContainer.getNamedQueries()) { - this.namedQueries.add(buildNamedQuery(namedQuery)); - } - } - - protected void initializeNamedNativeQueries() { - for (XmlNamedNativeQuery namedNativeQuery : this.resourceQueryContainer.getNamedNativeQueries()) { - this.namedNativeQueries.add(buildNamedNativeQuery(namedNativeQuery)); - } - } - - public void update() { - this.updateNamedQueries(); - this.updateNamedNativeQueries(); - } - - protected void updateNamedQueries() { - // make a copy of the XML queries (to prevent ConcurrentModificationException) - Iterator<XmlNamedQuery> xmlQueries = new CloneIterator<XmlNamedQuery>(this.resourceQueryContainer.getNamedQueries()); - - for (Iterator<OrmNamedQuery> contextQueries = this.namedQueries(); contextQueries.hasNext(); ) { - OrmNamedQuery contextQuery = contextQueries.next(); - if (xmlQueries.hasNext()) { - contextQuery.update(xmlQueries.next()); - } - else { - removeNamedQuery_(contextQuery); - } - } - - while (xmlQueries.hasNext()) { - addNamedQuery(buildNamedQuery(xmlQueries.next())); - } - } - - protected OrmNamedQuery buildNamedQuery(XmlNamedQuery resourceNamedQuery) { - return getXmlContextNodeFactory().buildOrmNamedQuery(this, resourceNamedQuery); - } - - protected void updateNamedNativeQueries() { - // make a copy of the XML queries (to prevent ConcurrentModificationException) - Iterator<XmlNamedNativeQuery> xmlQueries = new CloneIterator<XmlNamedNativeQuery>(this.resourceQueryContainer.getNamedNativeQueries()); - - for (Iterator<OrmNamedNativeQuery> contextQueries = this.namedNativeQueries(); contextQueries.hasNext(); ) { - OrmNamedNativeQuery contextQuery = contextQueries.next(); - if (xmlQueries.hasNext()) { - contextQuery.update(xmlQueries.next()); - } - else { - removeNamedNativeQuery_(contextQuery); - } - } - - while (xmlQueries.hasNext()) { - addNamedNativeQuery(buildNamedNativeQuery(xmlQueries.next())); - } - } - - protected OrmNamedNativeQuery buildNamedNativeQuery(XmlNamedNativeQuery resourceNamedNativeQuery) { - return getXmlContextNodeFactory().buildOrmNamedNativeQuery(this, resourceNamedNativeQuery); - } - - - //************ validation *************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateQueries(messages); - } - - protected void validateQueries(List<IMessage> messages) { - for (Iterator<OrmQuery> localQueries = this.queries(); localQueries.hasNext(); ) { - OrmQuery localQuery = localQueries.next(); - for (Iterator<Query> globalQueries = this.getPersistenceUnit().queries(); globalQueries.hasNext(); ) { - if (localQuery.duplicates(globalQueries.next())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {localQuery.getName()}, - localQuery, - localQuery.getNameTextRange()) - ); - } - } - } - } - - /** - * Return all the queries, named and named native. - */ - @SuppressWarnings("unchecked") - protected Iterator<OrmQuery> queries() { - return new CompositeIterator<OrmQuery>( - namedQueries(), - namedNativeQueries() - ); - } - - public TextRange getValidationTextRange() { - return this.resourceQueryContainer.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmQueryHint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmQueryHint.java deleted file mode 100644 index bd36a92e53..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmQueryHint.java +++ /dev/null @@ -1,77 +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.jpa1.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.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericOrmQueryHint extends AbstractOrmXmlContextNode implements OrmQueryHint -{ - - protected String name; - - protected String value; - - protected XmlQueryHint resourceQueryHint; - - public GenericOrmQueryHint(OrmQuery parent, XmlQueryHint resourceQueryHint) { - super(parent); - this.initialize(resourceQueryHint); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.resourceQueryHint.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.resourceQueryHint.setValue(newValue); - firePropertyChanged(QueryHint.VALUE_PROPERTY, oldValue, newValue); - } - - protected void initialize(XmlQueryHint resourceQueryHint) { - this.resourceQueryHint = resourceQueryHint; - this.name = resourceQueryHint.getName(); - this.value = resourceQueryHint.getValue(); - } - - public void update(XmlQueryHint resourceQueryHint) { - this.resourceQueryHint = resourceQueryHint; - this.setName(resourceQueryHint.getName()); - this.setValue(resourceQueryHint.getValue()); - } - - public TextRange getValidationTextRange() { - return this.resourceQueryHint.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmSecondaryTable.java deleted file mode 100644 index 12a320eeb9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmSecondaryTable.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; - -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.context.orm.AbstractOrmTable; -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.CloneIterator; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * orm.xml secondary table - */ -public class GenericOrmSecondaryTable - extends AbstractOrmTable - implements OrmSecondaryTable -{ - protected XmlSecondaryTable secondaryTable; - - protected final Vector<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns = new Vector<OrmPrimaryKeyJoinColumn>(); - - protected OrmPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - protected final OrmBaseJoinColumn.Owner joinColumnOwner; - - - public GenericOrmSecondaryTable(OrmEntity parent, XmlSecondaryTable xmlSecondaryTable) { - super(parent); - this.joinColumnOwner = this.buildJoinColumnOwner(); - this.initialize(xmlSecondaryTable); - } - - protected OrmBaseJoinColumn.Owner buildJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - 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 resourcePkJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(); - OrmPrimaryKeyJoinColumn contextPkJoinColumn = buildPrimaryKeyJoinColumn(resourcePkJoinColumn); - this.specifiedPrimaryKeyJoinColumns.add(index, contextPkJoinColumn); - this.secondaryTable.getPrimaryKeyJoinColumns().add(index, resourcePkJoinColumn); - - this.fireItemAdded(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, contextPkJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return contextPkJoinColumn; - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.addSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.size(), primaryKeyJoinColumn); - } - - 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 = buildPrimaryKeyJoinColumn(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 XmlSecondaryTable getResourceTable() { - return this.secondaryTable; - } - - @Override - protected XmlSecondaryTable addResourceTable() { - //secondaryTables are part of a collection, the secondary-table element will be removed/added - //when the XmlSecondaryTable is removed/added to the XmlEntity collection - throw new IllegalStateException("resource table is missing"); //$NON-NLS-1$ - } - - @Override - protected void removeResourceTable() { - //secondaryTables are part of a collection, the secondary-table element will be removed/added - //when the XmlSecondaryTable is removed/added to the XmlEntity collection - } - - protected void initialize(XmlSecondaryTable xst) { - this.secondaryTable = xst; - super.initialize(xst); - this.initializeSpecifiedPrimaryKeyJoinColumns(); - this.initializeDefaultPrimaryKeyJoinColumn(); - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns() { - for (XmlPrimaryKeyJoinColumn resourcePkJoinColumn : this.secondaryTable.getPrimaryKeyJoinColumns()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(resourcePkJoinColumn)); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(null); - } - - public void update(XmlSecondaryTable xst) { - this.secondaryTable = xst; - super.update(xst); - this.updateSpecifiedPrimaryKeyJoinColumns(); - this.updateDefaultPrimaryKeyJoinColumn(); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns() { - // make a copy of the XML PK join columns (to prevent ConcurrentModificationException) - Iterator<XmlPrimaryKeyJoinColumn> xmlPkJoinColumns = new CloneIterator<XmlPrimaryKeyJoinColumn>(this.secondaryTable.getPrimaryKeyJoinColumns()); - - for (Iterator<OrmPrimaryKeyJoinColumn> contextPkJoinColumns = this.specifiedPrimaryKeyJoinColumns(); contextPkJoinColumns.hasNext(); ) { - OrmPrimaryKeyJoinColumn contextPkJoinColumn = contextPkJoinColumns.next(); - if (xmlPkJoinColumns.hasNext()) { - contextPkJoinColumn.update(xmlPkJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(contextPkJoinColumn); - } - } - - while (xmlPkJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(xmlPkJoinColumns.next())); - } - } - - protected void updateDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(null)); - } - else { - this.defaultPrimaryKeyJoinColumn.update(null); - } - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - return getXmlContextNodeFactory().buildOrmPrimaryKeyJoinColumn(this, this.joinColumnOwner, resourcePkJoinColumn); - } - - /** - * a secondary table doesn't have a default name - */ - @Override - protected String buildDefaultName() { - return null; - } - - @Override - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - @Override - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.connectionProfileIsActive()) { - this.validateAgainstDatabase(messages); - } - for (Iterator<OrmPrimaryKeyJoinColumn> stream = this.primaryKeyJoinColumns(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); - } - } - - protected void validateAgainstDatabase(List<IMessage> messages) { - if ( ! this.hasResolvedCatalog()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_CATALOG, - new String[] {this.getCatalog(), this.getName()}, - this, - this.getCatalogTextRange() - ) - ); - return; - } - - if ( ! this.hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_SCHEMA, - new String[] {this.getSchema(), this.getName()}, - this, - this.getSchemaTextRange() - ) - ); - return; - } - - if ( ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange() - ) - ); - return; - } - } - - - // ********** pk join column owner adapter ********** - - class PrimaryKeyJoinColumnOwner - implements OrmBaseJoinColumn.Owner - { - public TypeMapping getTypeMapping() { - return GenericOrmSecondaryTable.this.getOrmEntity(); - } - - public Table getDbTable(String tableName) { - return GenericOrmSecondaryTable.this.getDbTable(); - } - - public Table getReferencedColumnDbTable() { - 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() { - return null; - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmSequenceGenerator.java deleted file mode 100644 index a7805c1564..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmSequenceGenerator.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; - -/** - * - */ -public class GenericOrmSequenceGenerator - extends AbstractOrmSequenceGenerator -{ - - public GenericOrmSequenceGenerator(XmlContextNode parent, XmlSequenceGenerator resourceSequenceGenerator) { - super(parent, resourceSequenceGenerator); - } - - // ********** database stuff ********** - - /** - * The JPA spec does not allow a sequence to have a schema. - */ - @Override - protected String getSchema() { - return this.getContextDefaultSchema(); - } - - /** - * The JPA spec does not allow a sequence to have a catalog. - */ - @Override - protected String getCatalog() { - return this.getContextDefaultCatalog(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTable.java deleted file mode 100644 index 63fcf35496..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTable.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmTable; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * - */ -public class GenericOrmTable - extends AbstractOrmTable - implements OrmTable -{ - protected XmlEntity resourceEntity; - - public GenericOrmTable(OrmEntity parent) { - super(parent); - } - - public OrmEntity getOrmEntity() { - return (OrmEntity) super.getParent(); - } - - @Override - protected XmlTable getResourceTable() { - return this.resourceEntity.getTable(); - } - - @Override - protected XmlTable addResourceTable() { - XmlTable resourceTable = OrmFactory.eINSTANCE.createXmlTable(); - this.resourceEntity.setTable(resourceTable); - return resourceTable; - } - - @Override - protected void removeResourceTable() { - this.resourceEntity.setTable(null); - } - - public void initialize(XmlEntity xmlEntity) { - this.resourceEntity = xmlEntity; - this.initialize(this.getResourceTable()); - } - - public void update(XmlEntity xmlEntity) { - this.resourceEntity = xmlEntity; - this.update(this.getResourceTable()); - } - - @Override - protected String buildDefaultName() { - return this.getOrmEntity().getDefaultTableName(); - } - - @Override - protected String buildDefaultSchema() { - return this.getOrmEntity().getDefaultSchema(); - } - - @Override - protected String buildDefaultCatalog() { - return this.getOrmEntity().getDefaultCatalog(); - } - - //*********** Validation ******************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.connectionProfileIsActive()) { - this.validateAgainstDatabase(messages); - } - } - - protected void validateAgainstDatabase(List<IMessage> messages) { - if ( ! this.hasResolvedCatalog()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_CATALOG, - new String[] {this.getCatalog(), this.getName()}, - this, - this.getCatalogTextRange() - ) - ); - return; - } - - if ( ! this.hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA, - new String[] {this.getSchema(), this.getName()}, - this, - this.getSchemaTextRange() - ) - ); - return; - } - - if ( ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange() - ) - ); - return; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTableGenerator.java deleted file mode 100644 index a25f930bc0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTableGenerator.java +++ /dev/null @@ -1,420 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmGenerator; -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.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - -/** - * - */ -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; - - - // ********** constructor ********** - - public GenericOrmTableGenerator(XmlContextNode parent, XmlTableGenerator resourceTableGenerator) { - super(parent); - this.uniqueConstraints = new ArrayList<OrmUniqueConstraint>(); - this.initialize(resourceTableGenerator); - } - - @Override - public int getDefaultInitialValue() { - return TableGenerator.DEFAULT_INITIAL_VALUE; - } - - // ********** table ********** - - public String getTable() { - return (this.specifiedTable != null) ? this.specifiedTable : this.defaultTable; - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String table) { - String old = this.specifiedTable; - this.specifiedTable = table; - this.getResourceGenerator().setTable(table); - this.firePropertyChanged(SPECIFIED_TABLE_PROPERTY, old, table); - } - - protected void setSpecifiedTable_(String table) { - String old = this.specifiedTable; - this.specifiedTable = table; - this.firePropertyChanged(SPECIFIED_TABLE_PROPERTY, old, table); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - protected void setDefaultTable(String table) { - String old = this.defaultTable; - this.defaultTable = table; - this.firePropertyChanged(DEFAULT_TABLE_PROPERTY, old, table); - } - - - // ********** schema ********** - - @Override - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.getResourceGenerator().setSchema(schema); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - protected void setSpecifiedSchema_(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - - // ********** catalog ********** - - @Override - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.getResourceGenerator().setCatalog(catalog); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - protected void setSpecifiedCatalog_(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - - // ********** primary key column name ********** - - public String getPkColumnName() { - return (this.specifiedPkColumnName != null) ? this.specifiedPkColumnName : this.defaultPkColumnName; - } - - public String getSpecifiedPkColumnName() { - return this.specifiedPkColumnName; - } - - public void setSpecifiedPkColumnName(String name) { - String old = this.specifiedPkColumnName; - this.specifiedPkColumnName = name; - this.getResourceGenerator().setPkColumnName(name); - this.firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, old, name); - } - - protected void setSpecifiedPkColumnName_(String name) { - String old = this.specifiedPkColumnName; - this.specifiedPkColumnName = name; - this.firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, old, name); - } - - public String getDefaultPkColumnName() { - return this.defaultPkColumnName; - } - - protected void setDefaultPkColumnName(String name) { - String old = this.defaultPkColumnName; - this.defaultPkColumnName = name; - this.firePropertyChanged(DEFAULT_PK_COLUMN_NAME_PROPERTY, old, name); - } - - - // ********** value column name ********** - - public String getValueColumnName() { - return (this.specifiedValueColumnName != null) ? this.specifiedValueColumnName : this.defaultValueColumnName; - } - - public String getSpecifiedValueColumnName() { - return this.specifiedValueColumnName; - } - - public void setSpecifiedValueColumnName(String name) { - String old = this.specifiedValueColumnName; - this.specifiedValueColumnName = name; - this.getResourceGenerator().setValueColumnName(name); - this.firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, old, name); - } - - protected void setSpecifiedValueColumnName_(String name) { - String old = this.specifiedValueColumnName; - this.specifiedValueColumnName = name; - this.firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, old, name); - } - - public String getDefaultValueColumnName() { - return this.defaultValueColumnName; - } - - protected void setDefaultValueColumnName(String name) { - String old = this.defaultValueColumnName; - this.defaultValueColumnName = name; - this.firePropertyChanged(DEFAULT_VALUE_COLUMN_NAME_PROPERTY, old, name); - } - - - // ********** primary key column value ********** - - public String getPkColumnValue() { - return (this.specifiedPkColumnValue != null) ? this.specifiedPkColumnValue : this.defaultPkColumnValue; - } - - public String getSpecifiedPkColumnValue() { - return this.specifiedPkColumnValue; - } - - public void setSpecifiedPkColumnValue(String value) { - String old = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = value; - this.getResourceGenerator().setPkColumnValue(value); - this.firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, old, value); - } - - protected void setSpecifiedPkColumnValue_(String value) { - String old = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = value; - this.firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, old, value); - } - - public String getDefaultPkColumnValue() { - return this.defaultPkColumnValue; - } - - public void setDefaultPkColumnValue(String value) { - String old = this.defaultPkColumnValue; - this.defaultPkColumnValue = value; - this.firePropertyChanged(DEFAULT_PK_COLUMN_VALUE_PROPERTY, old, value); - } - - - // ********** 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 resourceUC = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - OrmUniqueConstraint contextUC = this.buildUniqueConstraint(resourceUC); - this.uniqueConstraints.add(index, contextUC); - this.getResourceGenerator().getUniqueConstraints().add(index, resourceUC); - this.fireItemAdded(UNIQUE_CONSTRAINTS_LIST, index, contextUC); - return contextUC; - } - - protected void addUniqueConstraint(int index, OrmUniqueConstraint uniqueConstraint) { - this.addItemToList(index, uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - protected void addUniqueConstraint(OrmUniqueConstraint uniqueConstraint) { - this.addUniqueConstraint(this.uniqueConstraints.size(), uniqueConstraint); - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - OrmUniqueConstraint uniqueConstraint = this.uniqueConstraints.remove(index); - this.getResourceGenerator().getUniqueConstraints().remove(index); - this.fireItemRemoved(UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - } - - protected void removeUniqueConstraint_(OrmUniqueConstraint uniqueConstraint) { - this.removeItemFromList(uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getResourceGenerator().getUniqueConstraints().move(targetIndex, sourceIndex); - this.fireItemMoved(UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.sortedColumnIdentifiers() : EmptyIterator.<String>instance(); - } - - - // ********** resource => context ********** - - @Override - protected void initialize(XmlTableGenerator xmlTableGenerator) { - super.initialize(xmlTableGenerator); - this.specifiedTable = xmlTableGenerator.getTable(); - this.defaultSchema = this.buildDefaultSchema(); - this.specifiedSchema = xmlTableGenerator.getSchema(); - this.defaultCatalog = this.buildDefaultCatalog(); - this.specifiedCatalog = xmlTableGenerator.getCatalog(); - this.specifiedPkColumnName = xmlTableGenerator.getPkColumnName(); - this.specifiedValueColumnName = xmlTableGenerator.getValueColumnName(); - this.specifiedPkColumnValue = xmlTableGenerator.getPkColumnValue(); - this.initializeUniqueContraints(); - } - - protected void initializeUniqueContraints() { - if (this.resourceGenerator == null) { - return; - } - for (XmlUniqueConstraint uniqueConstraint : this.resourceGenerator.getUniqueConstraints()) { - this.uniqueConstraints.add(this.buildUniqueConstraint(uniqueConstraint)); - } - } - - @Override - public void update(XmlTableGenerator xmlTableGenerator) { - super.update(xmlTableGenerator); - this.setSpecifiedTable_(xmlTableGenerator.getTable()); - this.setDefaultSchema(this.buildDefaultSchema()); - this.setSpecifiedSchema_(xmlTableGenerator.getSchema()); - this.setDefaultCatalog(this.buildDefaultCatalog()); - this.setSpecifiedCatalog_(xmlTableGenerator.getCatalog()); - this.setSpecifiedPkColumnName_(xmlTableGenerator.getPkColumnName()); - this.setSpecifiedValueColumnName_(xmlTableGenerator.getValueColumnName()); - this.setSpecifiedPkColumnValue_(xmlTableGenerator.getPkColumnValue()); - // TODO defaults - this.updateUniqueConstraints(); - } - - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - protected void updateUniqueConstraints() { - Iterator<XmlUniqueConstraint> xmlConstraints = this.xmlUniqueConstraints(); - - for (Iterator<OrmUniqueConstraint> contextConstraints = this.uniqueConstraints(); contextConstraints.hasNext(); ) { - OrmUniqueConstraint contextConstraint = contextConstraints.next(); - if (xmlConstraints.hasNext()) { - contextConstraint.update(xmlConstraints.next()); - } - else { - this.removeUniqueConstraint_(contextConstraint); - } - } - - while (xmlConstraints.hasNext()) { - this.addUniqueConstraint(this.buildUniqueConstraint(xmlConstraints.next())); - } - } - - protected Iterator<XmlUniqueConstraint> xmlUniqueConstraints() { - // make a copy of the XML constraints (to prevent ConcurrentModificationException) - return (this.resourceGenerator == null) ? EmptyIterator.<XmlUniqueConstraint>instance() - : new CloneIterator<XmlUniqueConstraint>(this.resourceGenerator.getUniqueConstraints()); - } - - protected OrmUniqueConstraint buildUniqueConstraint(XmlUniqueConstraint resourceUniqueConstraint) { - return this.getXmlContextNodeFactory().buildOrmUniqueConstraint(this, this, resourceUniqueConstraint); - } - - - // ********** database stuff ********** - - public Table getDbTable() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema == null) ? null : dbSchema.getTableForIdentifier(this.getTable()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java deleted file mode 100644 index 4c42284b06..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.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.jpa1.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.XmlConvertibleMapping; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmTemporalConverter extends AbstractOrmXmlContextNode - implements TemporalConverter, OrmConverter -{ - private TemporalType temporalType; - - private XmlConvertibleMapping resourceConvertibleMapping; - - public GenericOrmTemporalConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceConvertableMapping) { - super(parent); - this.initialize(resourceConvertableMapping); - } - - @Override - public OrmAttributeMapping getParent() { - return (OrmAttributeMapping) super.getParent(); - } - - public String getType() { - return Converter.TEMPORAL_CONVERTER; - } - - public TemporalType getTemporalType() { - return this.temporalType; - } - - public void setTemporalType(TemporalType newTemporalType) { - TemporalType oldTemporalType = this.temporalType; - this.temporalType = newTemporalType; - this.resourceConvertibleMapping.setTemporal(TemporalType.toOrmResourceModel(newTemporalType)); - firePropertyChanged(TEMPORAL_TYPE_PROPERTY, oldTemporalType, newTemporalType); - } - - protected void setTemporalType_(TemporalType newTemporalType) { - TemporalType oldTemporalType = this.temporalType; - this.temporalType = newTemporalType; - firePropertyChanged(TEMPORAL_TYPE_PROPERTY, oldTemporalType, newTemporalType); - } - - - protected void initialize(XmlConvertibleMapping resourceConvertibleMapping) { - this.resourceConvertibleMapping = resourceConvertibleMapping; - this.temporalType = this.temporalType(); - } - - public void update() { - this.setTemporalType_(this.temporalType()); - } - - protected TemporalType temporalType() { - return TemporalType.fromOrmResourceModel(this.resourceConvertibleMapping.getTemporal()); - } - - - public TextRange getValidationTextRange() { - return this.resourceConvertibleMapping.getTemporalTextRange(); - } - - public void addToResourceModel() { - this.resourceConvertibleMapping.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - } - - public void removeFromResourceModel() { - this.resourceConvertibleMapping.setTemporal(null); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTransientMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTransientMapping.java deleted file mode 100644 index cbb8e46e7f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmTransientMapping.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.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.internal.context.orm.AbstractOrmAttributeMapping; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlTransient; - - -public class GenericOrmTransientMapping - extends AbstractOrmAttributeMapping<XmlTransient> - implements OrmTransientMapping -{ - - public GenericOrmTransientMapping(OrmPersistentAttribute parent, XmlTransient resourceMapping) { - super(parent, resourceMapping); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmTransientMapping(this); - } - - public int getXmlSequence() { - return 90; - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getTransients().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getTransients().remove(this.resourceAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmUniqueConstraint.java deleted file mode 100644 index 76f6615a58..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmUniqueConstraint.java +++ /dev/null @@ -1,126 +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.jpa1.context.orm; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -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 AbstractOrmXmlContextNode - implements OrmUniqueConstraint -{ - - protected final List<String> columnNames; - - protected XmlUniqueConstraint resourceUniqueConstraint; - - protected Owner owner; - - public GenericOrmUniqueConstraint(XmlContextNode parent, Owner owner, XmlUniqueConstraint resourceUniqueConstraint) { - super(parent); - this.owner = owner; - this.columnNames = new ArrayList<String>(); - this.initialize(resourceUniqueConstraint); - } - - 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.resourceUniqueConstraint.getColumnNames().add(index, columnName); - fireItemAdded(COLUMN_NAMES_LIST, index, columnName); - } - - protected void addColumnName_(int index, String columnName) { - this.addItemToList(index, columnName, this.columnNames, COLUMN_NAMES_LIST); - } - - protected void addColumnName_(String columnName) { - this.addItemToList(columnName, this.columnNames, COLUMN_NAMES_LIST); - } - - protected void setColumnName_(int index, String columnName) { - this.setItemInList(index, columnName, this.columnNames, COLUMN_NAMES_LIST); - } - - public void removeColumnName(String columnName) { - this.removeColumnName(this.columnNames.indexOf(columnName)); - } - - public void removeColumnName(int index) { - String removedColumnName = this.columnNames.remove(index); - this.resourceUniqueConstraint.getColumnNames().remove(index); - fireItemRemoved(COLUMN_NAMES_LIST, index, removedColumnName); - } - - protected void removeColumnName_(int index) { - this.removeItemFromList(index, this.columnNames, COLUMN_NAMES_LIST); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - CollectionTools.move(this.columnNames, targetIndex, sourceIndex); - this.resourceUniqueConstraint.getColumnNames().move(targetIndex, sourceIndex); - fireItemMoved(COLUMN_NAMES_LIST, targetIndex, sourceIndex); - } - - public TextRange getValidationTextRange() { - return this.resourceUniqueConstraint.getValidationTextRange(); - } - - protected void initialize(XmlUniqueConstraint xmlUniqueConstraint) { - this.resourceUniqueConstraint = xmlUniqueConstraint; - this.initializeColumnNames(); - } - - protected void initializeColumnNames() { - for (String annotationColumnName : this.resourceUniqueConstraint.getColumnNames()) { - this.columnNames.add(annotationColumnName); - } - } - - public void update(XmlUniqueConstraint xmlUniqueConstraint) { - this.resourceUniqueConstraint = xmlUniqueConstraint; - this.updateColumnNames(); - } - - protected void updateColumnNames() { - int index = 0; - for (String xmlColumnName : this.resourceUniqueConstraint.getColumnNames()) { - if (this.columnNames.size() > index) { - if ( ! this.columnNames.get(index).equals(xmlColumnName)) { - this.setColumnName_(index, xmlColumnName); - } - } - else { - this.addColumnName_(xmlColumnName); - } - index++; - } - - while (index < this.columnNames.size()) { - this.removeColumnName_(index); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmVersionMapping.java deleted file mode 100644 index 0d74de740f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmVersionMapping.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmVersionMapping; -import org.eclipse.jpt.core.resource.orm.XmlVersion; - - -public class GenericOrmVersionMapping extends AbstractOrmVersionMapping<XmlVersion> -{ - - public GenericOrmVersionMapping(OrmPersistentAttribute parent, XmlVersion resourceMapping) { - super(parent, resourceMapping); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java deleted file mode 100644 index 81a0e5e7f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.MappingFileRoot; -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.persistence.MappingFileRef; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.xml.EmfTools; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmXml - extends AbstractOrmXmlContextNode - implements OrmXml -{ - protected JpaXmlResource xmlResource; - - protected EntityMappings entityMappings; - - - public GenericOrmXml(MappingFileRef parent, JpaXmlResource resource) { - super(parent); - if (!resource.getContentType().isKindOf(JptCorePlugin.MAPPING_FILE_CONTENT_TYPE)) { - throw new IllegalArgumentException(resource + " does not have mapping file content type"); //$NON-NLS-1$ - } - this.xmlResource = resource; - XmlEntityMappings xmlEntityMappings = (XmlEntityMappings) this.xmlResource.getRootObject(); - if (xmlEntityMappings != null) { - this.entityMappings = this.buildEntityMappings(xmlEntityMappings); - } - } - - - // ********** overrides ********** - - @Override - public MappingFileRef getParent() { - return (MappingFileRef) super.getParent(); - } - - @Override - public IResource getResource() { - return this.xmlResource.getFile(); - } - - @Override - public MappingFileRoot getMappingFileRoot() { - return getEntityMappings(); - } - - - // ********** JpaStructureNode implementation ********** - - public String getId() { - // isn't actually displayed, so needs no details page - return null; - } - - @Override - public IContentType getContentType() { - return this.xmlResource.getContentType(); - } - - - // ********** MappingFile implementation ********** - - public JpaXmlResource getXmlResource() { - return this.xmlResource; - } - - public MappingFileRoot getRoot() { - return getEntityMappings(); - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - return (this.entityMappings == null) ? null : this.entityMappings.getPersistentType(fullyQualifiedTypeName); - } - - /** - * All orm.xml mapping files must be able to generate a static metamodel - * because 1.0 orm.xml files can be referenced from 2.0 persistence.xml files. - */ - public void synchronizeStaticMetamodel() { - this.getEntityMappings().synchronizeStaticMetamodel(); - } - - - // ********** entity mappings ********** - - public EntityMappings getEntityMappings() { - return this.entityMappings; - } - - protected void setEntityMappings(EntityMappings entityMappings) { - EntityMappings old = this.entityMappings; - this.entityMappings = entityMappings; - this.firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, old, entityMappings); - } - - public EntityMappings addEntityMappings() { - if (this.entityMappings != null) { - throw new IllegalStateException(); - } - - XmlEntityMappings xmlEntityMappings = this.buildEntityMappingsResource(); - this.entityMappings = this.buildEntityMappings(xmlEntityMappings); - this.xmlResource.getContents().add(xmlEntityMappings); - this.firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, null, this.entityMappings); - return this.entityMappings; - } - - protected XmlEntityMappings buildEntityMappingsResource() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getXmlEntityMappings(), - XmlEntityMappings.class); - } - - public void removeEntityMappings() { - if (this.entityMappings == null) { - throw new IllegalStateException(); - } - this.getJpaFile(this.xmlResource.getFile()).removeRootStructureNode(this.xmlResource); - this.entityMappings.dispose(); - EntityMappings old = this.entityMappings; - - this.entityMappings = null; - EObject xmlEntityMappings = this.xmlResource.getRootObject(); //TODO helper removeEntityMappings method on ormResource?? - this.xmlResource.getContents().remove(xmlEntityMappings); - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, old, null); - } - - - // ********** updating ********** - - public void update(JpaXmlResource resource) { - if (!resource.getContentType().isKindOf(JptCorePlugin.MAPPING_FILE_CONTENT_TYPE)) { - throw new IllegalArgumentException(resource + " does not have mapping file content type"); //$NON-NLS-1$ - } - this.xmlResource = resource; - this.update(); - } - - protected void update() { - XmlEntityMappings oldXmlEntityMappings = - (this.entityMappings == null) ? null : this.entityMappings.getXmlEntityMappings(); - XmlEntityMappings newXmlEntityMappings = (XmlEntityMappings) this.xmlResource.getRootObject(); - - // if the old and new xml entity mappings are different instances, - // we scrap the old and rebuild. this can happen when the resource - // model drastically changes, such as a cvs checkout or an edit reversion - if (oldXmlEntityMappings != newXmlEntityMappings) { - if (this.entityMappings != null) { - this.getJpaFile(this.xmlResource.getFile()).removeRootStructureNode(this.xmlResource); - this.entityMappings.dispose(); - this.setEntityMappings(null); - } - } - - if (newXmlEntityMappings != null) { - if (this.entityMappings != null) { - this.getJpaFile(this.xmlResource.getFile()).addRootStructureNode(this.xmlResource, this.entityMappings); - this.entityMappings.update(); - } else { - this.setEntityMappings(this.buildEntityMappings(newXmlEntityMappings)); - } - } - } - - protected EntityMappings buildEntityMappings(XmlEntityMappings xmlEntityMappings) { - return getXmlContextNodeFactory().buildEntityMappings(this, xmlEntityMappings); - } - - @Override - public void postUpdate() { - super.postUpdate(); - if (this.entityMappings != null) { - this.entityMappings.postUpdate(); - } - } - - - // ********** text ********** - - public JpaStructureNode getStructureNode(int textOffset) { - if (this.entityMappings.containsOffset(textOffset)) { - return this.entityMappings.getStructureNode(textOffset); - } - return this; - } - - // never actually selected - public TextRange getSelectionTextRange() { - return TextRange.Empty.instance(); - } - - public TextRange getValidationTextRange() { - return TextRange.Empty.instance(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.entityMappings != null) { - this.entityMappings.validate(messages, reporter); - } - } - - - // ********** dispose ********** - - public void dispose() { - if (this.entityMappings != null) { - this.entityMappings.dispose(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXmlDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXmlDefinition.java deleted file mode 100644 index 86718dcc2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXmlDefinition.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.NullOrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.context.orm.OrmXmlDefinition; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlDefinition; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmXmlContextNodeFactory; -import org.eclipse.jpt.core.internal.context.orm.OrmBasicMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddableDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddedIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddedMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEntityDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmManyToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmManyToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmMappedSuperclassDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmOneToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmOneToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmTransientMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmVersionMappingDefinition; -import org.eclipse.jpt.core.resource.orm.OrmFactory; - -public class GenericOrmXmlDefinition - extends AbstractOrmXmlDefinition -{ - // singleton - private static final OrmXmlDefinition INSTANCE = - new GenericOrmXmlDefinition(); - - - /** - * Return the singleton - */ - public static OrmXmlDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private GenericOrmXmlDefinition() { - super(); - } - - - public EFactory getResourceNodeFactory() { - return OrmFactory.eINSTANCE; - } - - @Override - protected OrmXmlContextNodeFactory buildContextNodeFactory() { - return new GenericOrmXmlContextNodeFactory(); - } - - public IContentType getContentType() { - return JptCorePlugin.ORM_XML_CONTENT_TYPE; - } - - - // ********** ORM type mappings ********** - - @Override - protected OrmTypeMappingDefinition[] buildOrmTypeMappingDefinitions() { - // order should not matter here, but we'll use the same order as for java - // (@see {@link GenericJpaPlatformProvider}) - return new OrmTypeMappingDefinition[] { - OrmEntityDefinition.instance(), - OrmEmbeddableDefinition.instance(), - OrmMappedSuperclassDefinition.instance()}; - } - - - // ********** ORM attribute mappings ********** - - @Override - protected OrmAttributeMappingDefinition[] buildOrmAttributeMappingDefinitions() { - // order should not matter here, but we'll use the same order as for java - // (@see {@link GenericJpaPlatformProvider}) - return new OrmAttributeMappingDefinition[] { - OrmTransientMappingDefinition.instance(), - OrmIdMappingDefinition.instance(), - OrmVersionMappingDefinition.instance(), - OrmBasicMappingDefinition.instance(), - OrmEmbeddedMappingDefinition.instance(), - OrmEmbeddedIdMappingDefinition.instance(), - OrmManyToManyMappingDefinition.instance(), - OrmManyToOneMappingDefinition.instance(), - OrmOneToManyMappingDefinition.instance(), - OrmOneToOneMappingDefinition.instance(), - NullOrmAttributeMappingDefinition.instance()}; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericPersistenceUnitDefaults.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericPersistenceUnitDefaults.java deleted file mode 100644 index 905254d008..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericPersistenceUnitDefaults.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -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; -import org.eclipse.jpt.db.SchemaContainer; - -/** - * - */ -public class GenericPersistenceUnitDefaults - extends AbstractOrmXmlContextNode - implements OrmPersistenceUnitDefaults -{ - protected final XmlEntityMappings xmlEntityMappings; - - protected AccessType access; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - protected boolean cascadePersist; - - - // ********** constructor/initialization ********** - - public GenericPersistenceUnitDefaults(PersistenceUnitMetadata parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.xmlEntityMappings = xmlEntityMappings; - XmlPersistenceUnitDefaults resourceDefaults = this.getResourceDefaults(); - if (resourceDefaults != null) { - this.access = AccessType.fromOrmResourceModel(resourceDefaults.getAccess()); - this.specifiedCatalog = resourceDefaults.getCatalog(); - this.specifiedSchema = resourceDefaults.getSchema(); - this.cascadePersist = resourceDefaults.isCascadePersist(); - } - this.defaultCatalog = this.getJpaProject().getDefaultCatalog(); - this.defaultSchema = this.getJpaProject().getDefaultSchema(); - } - - public boolean resourceExists() { - return getResourceDefaults() != null; - } - - @Override - public PersistenceUnitMetadata getParent() { - return (PersistenceUnitMetadata) super.getParent(); - } - - protected XmlPersistenceUnitMetadata getResourcePersistenceUnitMetadata() { - return getParent().getResourcePersistenceUnitMetadata(); - } - - protected XmlPersistenceUnitMetadata createResourcePersistenceUnitMetadata() { - return getParent().createResourcePersistenceUnitMetadata(); - } - - // ********** access ********** - - public AccessType getAccess() { - return this.access; - } - - public void setAccess(AccessType access) { - AccessType old = this.access; - this.access = access; - if (access != old) { - XmlPersistenceUnitDefaults resourceDefaults = this.getResourceDefaults(); - if (resourceDefaults == null) { - resourceDefaults = this.buildResourceDefaults(); - } - resourceDefaults.setAccess(AccessType.toOrmResourceModel(access)); - this.checkResourceDefaults(resourceDefaults); - this.firePropertyChanged(ACCESS_PROPERTY, old, access); - } - } - - protected void setAccess_(AccessType access) { - AccessType old = this.access; - this.access = access; - this.firePropertyChanged(ACCESS_PROPERTY, old, access); - } - - - // ********** schema container ********** - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - - // ********** catalog ********** - - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - if (this.attributeValueHasChanged(old, catalog)) { - XmlPersistenceUnitDefaults resourceDefaults = this.getResourceDefaults(); - if (resourceDefaults == null) { - resourceDefaults = this.buildResourceDefaults(); - } - resourceDefaults.setCatalog(catalog); - this.checkResourceDefaults(resourceDefaults); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - } - - protected void setSpecifiedCatalog_(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - this.firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - - // ********** schema ********** - - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - if (this.attributeValueHasChanged(old, schema)) { - XmlPersistenceUnitDefaults resourceDefaults = this.getResourceDefaults(); - if (resourceDefaults == null) { - resourceDefaults = this.buildResourceDefaults(); - } - resourceDefaults.setSchema(schema); - this.checkResourceDefaults(resourceDefaults); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - } - - protected void setSpecifiedSchema_(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - - // ********** cascadePersist ********** - - public boolean isCascadePersist() { - return this.cascadePersist; - } - - public void setCascadePersist(boolean cascadePersist) { - boolean old = this.cascadePersist; - this.cascadePersist = cascadePersist; - if (cascadePersist != old) { - XmlPersistenceUnitDefaults resourceDefaults = this.getResourceDefaults(); - if (resourceDefaults == null) { - resourceDefaults = this.buildResourceDefaults(); - } - resourceDefaults.setCascadePersist(cascadePersist); - this.checkResourceDefaults(resourceDefaults); - this.firePropertyChanged(CASCADE_PERSIST_PROPERTY, old, cascadePersist); - } - } - - protected void setCascadePersist_(boolean cp) { - boolean old = this.cascadePersist; - this.cascadePersist = cp; - this.firePropertyChanged(CASCADE_PERSIST_PROPERTY, old, cp); - } - - - // ********** behavior ********** - - /** - * build the resource defaults and the resource metadata if necessary - */ - protected XmlPersistenceUnitDefaults buildResourceDefaults() { - XmlPersistenceUnitMetadata resourceMetadata = getResourcePersistenceUnitMetadata(); - if (resourceMetadata == null) { - resourceMetadata = createResourcePersistenceUnitMetadata(); - this.xmlEntityMappings.setPersistenceUnitMetadata(resourceMetadata); - } - XmlPersistenceUnitDefaults resourceDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - resourceMetadata.setPersistenceUnitDefaults(resourceDefaults); - return resourceDefaults; - } - - /** - * clear the resource defaults and the resource metadata if appropriate - */ - protected void checkResourceDefaults(XmlPersistenceUnitDefaults resourceDefaults) { - if (resourceDefaults.isUnset()) { - XmlPersistenceUnitMetadata metadata = this.xmlEntityMappings.getPersistenceUnitMetadata(); - metadata.setPersistenceUnitDefaults(null); - if (metadata.isUnset()) { - this.xmlEntityMappings.setPersistenceUnitMetadata(null); - } - } - } - - public void update() { - XmlPersistenceUnitDefaults resourceDefaults = this.getResourceDefaults(); - if (resourceDefaults == null) { - this.setAccess_(null); - this.setSpecifiedCatalog_(null); - this.setSpecifiedSchema_(null); - this.setCascadePersist_(false); - } else { - this.setAccess_(AccessType.fromOrmResourceModel(resourceDefaults.getAccess())); - this.setSpecifiedCatalog_(resourceDefaults.getCatalog()); - this.setSpecifiedSchema_(resourceDefaults.getSchema()); - this.setCascadePersist_(resourceDefaults.isCascadePersist()); - } - this.setDefaultCatalog(this.getJpaProject().getDefaultCatalog()); - this.setDefaultSchema(this.getJpaProject().getDefaultSchema()); - } - - public TextRange getValidationTextRange() { - XmlPersistenceUnitDefaults resourceDefaults = this.getResourceDefaults(); - return (resourceDefaults != null) ? resourceDefaults.getValidationTextRange() : this.xmlEntityMappings.getValidationTextRange(); - } - - protected XmlPersistenceUnitDefaults getResourceDefaults() { - XmlPersistenceUnitMetadata metadata = getResourcePersistenceUnitMetadata(); - return (metadata == null) ? null : metadata.getPersistenceUnitDefaults(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericPersistenceUnitMetadata.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericPersistenceUnitMetadata.java deleted file mode 100644 index b3f2e1bd8e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericPersistenceUnitMetadata.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.orm; - -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.xml.EmfTools; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericPersistenceUnitMetadata extends AbstractOrmXmlContextNode - implements PersistenceUnitMetadata -{ - protected boolean xmlMappingMetadataComplete; - - protected final OrmPersistenceUnitDefaults persistenceUnitDefaults; - - protected final XmlEntityMappings xmlEntityMappings; - - public GenericPersistenceUnitMetadata(EntityMappings parent, XmlEntityMappings resource) { - super(parent); - this.xmlEntityMappings = resource; - this.xmlMappingMetadataComplete = this.getResourceXmlMappingMetadataComplete(); - this.persistenceUnitDefaults = getXmlContextNodeFactory().buildPersistenceUnitDefaults(this, this.xmlEntityMappings); - } - - public XmlPersistenceUnitMetadata createResourcePersistenceUnitMetadata() { - return EmfTools.create( - getResourceNodeFactory(), - OrmPackage.eINSTANCE.getXmlPersistenceUnitMetadata(), - XmlPersistenceUnitMetadata.class); - } - - public boolean isXmlMappingMetadataComplete() { - return this.xmlMappingMetadataComplete; - } - - public void setXmlMappingMetadataComplete(boolean newXmlMappingMetadataComplete) { - boolean oldXmlMappingMetadataComplete = this.xmlMappingMetadataComplete; - this.xmlMappingMetadataComplete = newXmlMappingMetadataComplete; - if (oldXmlMappingMetadataComplete != newXmlMappingMetadataComplete) { - if (this.getResourcePersistenceUnitMetadata() != null) { - this.getResourcePersistenceUnitMetadata().setXmlMappingMetadataComplete(newXmlMappingMetadataComplete); - if (this.getResourcePersistenceUnitMetadata().isUnset()) { - this.xmlEntityMappings.setPersistenceUnitMetadata(null); - } - } - else if (newXmlMappingMetadataComplete) { - this.xmlEntityMappings.setPersistenceUnitMetadata(createResourcePersistenceUnitMetadata()); - this.getResourcePersistenceUnitMetadata().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 OrmPersistenceUnitDefaults getPersistenceUnitDefaults() { - return this.persistenceUnitDefaults; - } - - public void update() { - this.setXmlMappingMetadataComplete_(this.getResourceXmlMappingMetadataComplete()); - this.persistenceUnitDefaults.update(); - } - - - protected boolean getResourceXmlMappingMetadataComplete() { - XmlPersistenceUnitMetadata resourcePersistenceUnitMetadata = getResourcePersistenceUnitMetadata(); - return resourcePersistenceUnitMetadata != null ? resourcePersistenceUnitMetadata.isXmlMappingMetadataComplete() : false; - } - - public XmlPersistenceUnitMetadata getResourcePersistenceUnitMetadata() { - return this.xmlEntityMappings.getPersistenceUnitMetadata(); - } - - public TextRange getValidationTextRange() { - if (getResourcePersistenceUnitMetadata() != null) { - return getResourcePersistenceUnitMetadata().getValidationTextRange(); - } - return this.xmlEntityMappings.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java deleted file mode 100644 index 7bb081c74c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java +++ /dev/null @@ -1,306 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import java.util.Iterator; -import java.util.List; - -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.java.JavaPersistentType; -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.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentType2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.ClassRef2_0; -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.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * Context persistence.xml class reference - */ -public class GenericClassRef - extends AbstractXmlContextNode - implements ClassRef2_0 -{ - // this is null for an "implied" class ref - protected XmlJavaClassRef xmlJavaClassRef; - - protected String className; - - protected JavaPersistentType javaPersistentType; - - - // ********** construction/initialization ********** - - /** - * Construct an "specified" class ref; i.e. a class ref with - * an explicit entry in the persistence.xml. - */ - public GenericClassRef(PersistenceUnit parent, XmlJavaClassRef classRef) { - this(parent, classRef, classRef.getJavaClass()); - } - - /** - * Construct an "implied" class ref; i.e. a class ref without - * an explicit entry in the persistence.xml. - */ - public GenericClassRef(PersistenceUnit parent, String className) { - this(parent, null, className); - } - - protected GenericClassRef(PersistenceUnit parent, XmlJavaClassRef classRef, String className) { - super(parent); - this.initialize(classRef, className); - } - - protected void initialize(XmlJavaClassRef classRef, String typeName) { - this.xmlJavaClassRef = classRef; - this.className = typeName; - this.javaPersistentType = this.buildJavaPersistentType(); - } - - @Override - public PersistenceUnit getParent() { - return (PersistenceUnit) super.getParent(); - } - - - // ********** JpaStructureNode implementation ********** - - public String getId() { - return PersistenceStructureNodes.CLASS_REF_ID; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public TextRange getSelectionTextRange() { - return this.isVirtual() ? null : this.xmlJavaClassRef.getSelectionTextRange(); - } - - public void dispose() { - if (this.javaPersistentType != null) { - this.javaPersistentType.dispose(); - } - } - - - // ********** PersistentType.Owner implementation ********** - - public AccessType getOverridePersistentTypeAccess() { - // no access type at this level overrides any local access type specification - return null; - } - - public AccessType getDefaultPersistentTypeAccess() { - return this.getPersistenceUnit().getDefaultAccess(); - } - - - // ********** queries ********** - - public boolean isFor(String typeName) { - return (this.className != null) && this.className.equals(typeName); - } - - public boolean isVirtual() { - return this.xmlJavaClassRef == null; - } - - public boolean containsOffset(int textOffset) { - return this.isNotVirtual() && this.xmlJavaClassRef.containsOffset(textOffset); - } - - protected boolean isNotVirtual() { - return ! this.isVirtual(); - } - - - // ********** class name ********** - - public String getClassName() { - return this.className; - } - - public void setClassName(String className) { - String old = this.className; - this.className = className; - this.xmlJavaClassRef.setJavaClass(className); - this.firePropertyChanged(CLASS_NAME_PROPERTY, old, className); - } - - protected void setClassName_(String newClassName) { - String old = this.className; - this.className = newClassName; - this.firePropertyChanged(CLASS_NAME_PROPERTY, old, newClassName); - } - - - // ********** java persistent type ********** - - public JavaPersistentType getJavaPersistentType() { - return this.javaPersistentType; - } - - protected void setJavaPersistentType(JavaPersistentType javaPersistentType) { - JavaPersistentType old = this.javaPersistentType; - this.javaPersistentType = javaPersistentType; - this.firePropertyChanged(JAVA_PERSISTENT_TYPE_PROPERTY, old, javaPersistentType); - } - - protected JavaPersistentType buildJavaPersistentType() { - JavaResourcePersistentType jrpt = this.getJavaResourcePersistentType(); - return (jrpt == null) ? null : this.buildJavaPersistentType(jrpt); - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourcePersistentType jrpt) { - return this.getJpaFactory().buildJavaPersistentType(this, jrpt); - } - - protected void updateJavaPersistentType() { - JavaResourcePersistentType jrpt = this.getJavaResourcePersistentType(); - if (jrpt == null) { - if (this.javaPersistentType != null) { - this.javaPersistentType.dispose(); - this.setJavaPersistentType(null); - } - } else { - if (this.javaPersistentType == null) { - this.setJavaPersistentType(this.buildJavaPersistentType(jrpt)); - } else { - this.javaPersistentType.update(jrpt); - } - } - } - - protected JavaResourcePersistentType getJavaResourcePersistentType() { - return (this.className == null) ? null : this.getJpaProject().getJavaResourcePersistentType(this.className.replace('$', '.')); - } - - - // ********** 2.0 static metamodel ********** - - public void synchronizeStaticMetamodel() { - JavaPersistentType2_0 jpt = (JavaPersistentType2_0) this.getJavaPersistentType(); - if (jpt != null) { - jpt.synchronizeStaticMetamodel(); - } - } - - // ********** updating ********** - - public void update(XmlJavaClassRef classRef) { - this.update(classRef, classRef.getJavaClass()); - } - - public void update(String typeName) { - this.update(null, typeName); - } - - protected void update(XmlJavaClassRef classRef, String typeName) { - this.xmlJavaClassRef = classRef; - this.setClassName_(typeName); - this.updateJavaPersistentType(); - } - - @Override - public void postUpdate() { - super.postUpdate(); - if (this.javaPersistentType != null) { - this.javaPersistentType.postUpdate(); - } - } - - // ********** XmlContextNode implementation ********** - - public TextRange getValidationTextRange() { - return this.isVirtual() ? null : this.xmlJavaClassRef.getValidationTextRange(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (StringTools.stringIsEmpty(this.className)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_CLASS, - this, - this.getValidationTextRange() - ) - ); - return; - } - - if (this.javaPersistentType == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_CLASS, - new String[] {this.className}, - this, - this.getValidationTextRange() - ) - ); - return; - } - - // 190062 validate Java class only if this is the only reference to it - boolean validateJavaPersistentType = true; - for (Iterator<MappingFileRef> stream = this.getPersistenceUnit().mappingFileRefsContaining(this.className); stream.hasNext(); ) { - validateJavaPersistentType = false; - MappingFileRef mappingFileRef = stream.next(); - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.LOW_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_REDUNDANT_CLASS, - new String[] {this.className, mappingFileRef.getFileName()}, - this, - this.getValidationTextRange() - ) - ); - } - - if (validateJavaPersistentType) { - this.validateJavaPersistentType(messages, reporter); - } - } - - protected void validateJavaPersistentType(List<IMessage> messages, IReporter reporter) { - try { - this.javaPersistentType.validate(messages, reporter); - } catch (Throwable t) { - JptCorePlugin.log(t); - } - } - - - // ********** misc ********** - - @Override - public void toString(StringBuilder sb) { - sb.append(this.className); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericJarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericJarFileRef.java deleted file mode 100644 index 80b33e73c8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericJarFileRef.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.persistence.AbstractJarFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef; - -/** - * Context JAR file reference (from the persistence unit) - */ -public class GenericJarFileRef - extends AbstractJarFileRef -{ - public GenericJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { - super(parent, xmlJarFileRef); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java deleted file mode 100644 index f07ae911ce..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.persistence.AbstractMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericMappingFileRef - extends AbstractMappingFileRef -{ - protected XmlMappingFileRef xmlMappingFileRef; - - - // **************** construction/initialization **************************** - - public GenericMappingFileRef(PersistenceUnit parent, XmlMappingFileRef xmlMappingFileRef) { - super(parent, xmlMappingFileRef.getFileName()); - this.xmlMappingFileRef = xmlMappingFileRef; - } - - - // **************** file name ********************************************** - - public void setFileName(String newFileName) { - String old = this.fileName; - this.fileName = newFileName; - this.xmlMappingFileRef.setFileName(newFileName); - this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); - } - - protected void setFileName_(String newFileName) { - String old = this.fileName; - this.fileName = newFileName; - this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); - } - - - // **************** MappingFileRef impl ************************************ - - public void update(XmlMappingFileRef mappingFileRef) { - this.xmlMappingFileRef = mappingFileRef; - this.setFileName_(this.getResourceFileName()); - super.update(); - } - - protected String getResourceFileName() { - return this.xmlMappingFileRef.getFileName(); - } - - public boolean isImplied() { - return false; - } - - public boolean containsOffset(int textOffset) { - return this.xmlMappingFileRef.containsOffset(textOffset); - } - - - // **************** JpaStructureNode impl ********************************** - - public TextRange getSelectionTextRange() { - return this.xmlMappingFileRef.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return this.xmlMappingFileRef.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistence.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistence.java deleted file mode 100644 index 1d95405323..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistence.java +++ /dev/null @@ -1,248 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaStructureNode; -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.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.persistence.Persistence2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -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; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericPersistence - extends AbstractXmlContextNode - implements Persistence2_0 -{ - 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.xmlPersistence = xmlPersistence; - this.initializePersistenceUnits(); - } - - public String getId() { - return PersistenceStructureNodes.PERSISTENCE_ID; - } - - public XmlPersistence getXmlPersistence() { - return this.xmlPersistence; - } - - @Override - public PersistenceXml getParent() { - return (PersistenceXml) super.getParent(); - } - - // **************** persistence units ************************************** - - public ListIterator<PersistenceUnit> persistenceUnits() { - return (this.persistenceUnit == null) ? EmptyListIterator.<PersistenceUnit>instance() : this.persistenceUnits_(); - } - - protected ListIterator<PersistenceUnit> persistenceUnits_() { - return new SingleElementListIterator<PersistenceUnit>(this.persistenceUnit); - } - - public int persistenceUnitsSize() { - return (this.persistenceUnit == null) ? 0 : 1; - } - - public PersistenceUnit addPersistenceUnit() { - return addPersistenceUnit(persistenceUnitsSize()); - } - - public PersistenceUnit addPersistenceUnit(int index) { - if (index > 0 || this.persistenceUnit != null) { - throw new IllegalStateException("This implementation does not support multiple persistence units."); //$NON-NLS-1$ - } - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - this.persistenceUnit = buildPersistenceUnit(xmlPersistenceUnit); - this.xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - fireItemAdded(PERSISTENCE_UNITS_LIST, index, this.persistenceUnit); - return this.persistenceUnit; - } - - public void removePersistenceUnit(PersistenceUnit pu) { - if (pu != this.persistenceUnit) { - throw new IllegalArgumentException("Invalid persistence unit: " + pu); //$NON-NLS-1$ - } - removePersistenceUnit(0); - } - - public void removePersistenceUnit(int index) { - if (index > 0 || this.persistenceUnit == null) { - throw new IndexOutOfBoundsException("index: " + index); //$NON-NLS-1$ - } - PersistenceUnit oldPersistenceUnit = this.persistenceUnit; - this.persistenceUnit.dispose(); - this.persistenceUnit = null; - this.xmlPersistence.getPersistenceUnits().remove(index); - fireItemRemoved(PERSISTENCE_UNITS_LIST, index, oldPersistenceUnit); - } - - protected void addPersistenceUnit_(PersistenceUnit newPersistenceUnit) { - this.persistenceUnit = newPersistenceUnit; - fireItemAdded(PERSISTENCE_UNITS_LIST, 0, this.persistenceUnit); - } - - protected void removePersistenceUnit_(PersistenceUnit oldPersistenceUnit) { - this.persistenceUnit.dispose(); - this.persistenceUnit = null; - fireItemRemoved(PERSISTENCE_UNITS_LIST, 0, oldPersistenceUnit); - } - - // **************** 2.0 static metamodel ********************************** - - public void synchronizeStaticMetamodel() { - for (Iterator<PersistenceUnit> stream = this.persistenceUnits(); stream.hasNext(); ) { - ((PersistenceUnit2_0) stream.next()).synchronizeStaticMetamodel(); - } - } - - // **************** updating *********************************************** - - protected void initializePersistenceUnits() { - // only adding one here, until we support multiple persistence units - if (this.xmlPersistence.getPersistenceUnits().size() > 0) { - this.persistenceUnit = buildPersistenceUnit(this.xmlPersistence.getPersistenceUnits().get(0)); - } - } - - public void update(XmlPersistence persistence) { - this.xmlPersistence = persistence; - XmlPersistenceUnit xmlPersistenceUnit = null; - if (persistence.getPersistenceUnits().size() > 0) { - xmlPersistenceUnit = persistence.getPersistenceUnits().get(0); - } - - if (this.persistenceUnit != null) { - if (xmlPersistenceUnit != null) { - this.persistenceUnit.update(xmlPersistenceUnit); - } - else { - removePersistenceUnit_(this.persistenceUnit); - } - } - else { - if (xmlPersistenceUnit != null) { - addPersistenceUnit_(buildPersistenceUnit(xmlPersistenceUnit)); - } - } - } - - @Override - public void postUpdate() { - super.postUpdate(); - if (this.persistenceUnit != null) { - this.persistenceUnit.postUpdate(); - } - } - - protected PersistenceUnit buildPersistenceUnit(XmlPersistenceUnit xmlPersistenceUnit) { - return this.getJpaFactory().buildPersistenceUnit(this, xmlPersistenceUnit); - } - - - // ************************************************************************* - - @Override - public PersistenceUnit getPersistenceUnit() { - throw new UnsupportedOperationException("No PersistenceUnit in this context"); //$NON-NLS-1$ - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (PersistenceUnit pu : CollectionTools.iterable(persistenceUnits())) { - if (pu.containsOffset(textOffset)) { - return pu.getStructureNode(textOffset); - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - return (this.xmlPersistence == null) ? false : this.xmlPersistence.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.xmlPersistence.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return this.xmlPersistence.getValidationTextRange(); - } - - public void dispose() { - for (PersistenceUnit pu : CollectionTools.iterable(persistenceUnits())) { - pu.dispose(); - } - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.checkForMultiplePersistenceUnits(messages); - this.validatePersistenceUnit(messages, reporter); - } - - /** - * extraneous persistence units can be - * accessed through the XmlPersistence resource object - */ - protected void checkForMultiplePersistenceUnits(List<IMessage> messages) { - if (this.xmlPersistence.getPersistenceUnits().size() > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS, - this, - this.getValidationTextRange() - ) - ); - } - } - - protected void validatePersistenceUnit(List<IMessage> messages, IReporter reporter) { - if (this.persistenceUnit == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_NO_PERSISTENCE_UNIT, - this, - this.getValidationTextRange() - ) - ); - return; - } - this.persistenceUnit.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnit.java deleted file mode 100644 index f64d46c892..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnit.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; - -/** - * generic persistence-unit - */ -public class GenericPersistenceUnit - extends AbstractPersistenceUnit -{ - public GenericPersistenceUnit(Persistence parent, XmlPersistenceUnit xmlPersistenceUnit) { - super(parent, xmlPersistenceUnit); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java deleted file mode 100644 index 227fbd3aa5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * Straightforward implementation of the persistence unit property. - * Notifies the persistence unit of any changes to the property. - */ -public class GenericPersistenceUnitProperty - extends AbstractXmlContextNode - implements PersistenceUnit.Property -{ - protected final XmlProperty xmlProperty; - protected String name; - protected String value; - - - public GenericPersistenceUnitProperty(PersistenceUnit parent, XmlProperty xmlProperty) { - super(parent); - this.xmlProperty = xmlProperty; - this.name = xmlProperty.getName(); - this.value = xmlProperty.getValue(); - } - - @Override - public PersistenceUnit getParent() { - return (PersistenceUnit) super.getParent(); - } - - public XmlProperty getXmlProperty() { - return this.xmlProperty; - } - - // ********** name ********** - - public String getName() { - return this.name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - if (attributeValueHasChanged(old, name)) { - this.xmlProperty.setName(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - getParent().propertyNameChanged(old, this.name, this.value); - } - } - - - // ********** value ********** - - public String getValue() { - return this.value; - } - - public void setValue(String value) { - String old = this.value; - this.value = value; - if (attributeValueHasChanged(old, value)) { - this.xmlProperty.setValue(value); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - getParent().propertyValueChanged(this.name, value); - } - } - - - // ********** updating ********** - - public void update() { - this.setName(this.xmlProperty.getName()); - this.setValue(this.xmlProperty.getValue()); - } - - - // ********** validation ********** - - public TextRange getValidationTextRange() { - return this.xmlProperty.getValidationTextRange(); - } - - - // ********** misc ********** - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - sb.append(" = "); //$NON-NLS-1$ - sb.append(this.value); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceXml.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceXml.java deleted file mode 100644 index 91a465403e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceXml.java +++ /dev/null @@ -1,230 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -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.internal.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.persistence.Persistence2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceXml2_0; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * - */ -public class GenericPersistenceXml - extends AbstractXmlContextNode - implements PersistenceXml2_0 -{ - protected JpaXmlResource persistenceXmlResource; - - protected Persistence persistence; - - - public GenericPersistenceXml(JpaRootContextNode parent, JpaXmlResource resource) { - super(parent); - if (!resource.getContentType().isKindOf(JptCorePlugin.PERSISTENCE_FILE_CONTENT_TYPE)) { - throw new IllegalArgumentException("Resource " + resource + " must have persistence xml content type"); //$NON-NLS-1$ //$NON-NLS-2$ - } - this.persistenceXmlResource = resource; - if (resource.getRootObject() != null) { - this.persistence = buildPersistence((XmlPersistence) resource.getRootObject()); - } - } - - public JpaXmlResource getXmlResource() { - return this.persistenceXmlResource; - } - - // **************** JpaNode impl ******************************************* - - @Override - public IResource getResource() { - return this.persistenceXmlResource.getFile(); - } - - - // **************** JpaStructureNode impl ********************************** - - public String getId() { - // isn't actually displayed, so needs no details page - return null; - } - - @Override - public IContentType getContentType() { - return this.persistenceXmlResource.getContentType(); - } - - - // **************** persistence ******************************************** - - public Persistence getPersistence() { - return this.persistence; - } - - public Persistence addPersistence() { - if (this.persistence != null) { - throw new IllegalStateException(); - } - - XmlPersistence xmlPersistence = PersistenceFactory.eINSTANCE.createXmlPersistence(); - this.persistence = buildPersistence(xmlPersistence); - this.persistenceXmlResource.getContents().add(xmlPersistence); - firePropertyChanged(PERSISTENCE_PROPERTY, null, this.persistence); - return this.persistence; - } - - public void removePersistence() { - if (this.persistence == null) { - throw new IllegalStateException(); - } - getJpaFile(this.persistenceXmlResource.getFile()).removeRootStructureNode(this.persistenceXmlResource); - this.persistence.dispose(); - Persistence oldPersistence = this.persistence; - this.persistence = null; - XmlPersistence xmlPersistence = (XmlPersistence) this.persistenceXmlResource.getRootObject(); - this.persistenceXmlResource.getContents().remove(xmlPersistence); - firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, null); - } - - protected void setPersistence(Persistence newPersistence) { - Persistence oldPersistence = this.persistence; - this.persistence = newPersistence; - firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, newPersistence); - } - - - // **************** 2.0 static metamodel ******************** - - public void synchronizeStaticMetamodel() { - Persistence2_0 p = (Persistence2_0) this.getPersistence(); - if (p != null) { - p.synchronizeStaticMetamodel(); - } - } - - // **************** updating *********************************************** - - //TODO I haven't yet figured out if we do not need the resource object passed in now. - //I don't think we will even build AbstractPersistenceXml if the resource object is null - //I'm pretty sure this won't change now, but need to investigate - KFB - public void update(JpaXmlResource persistenceResource) { - XmlPersistence oldXmlPersistence = - (this.persistence == null) ? null : this.persistence.getXmlPersistence(); - XmlPersistence newXmlPersistence = (XmlPersistence) persistenceResource.getRootObject(); - - this.persistenceXmlResource = persistenceResource; - - // if the old and new xml persistences are different instances, - // we scrap the old and rebuild. this can happen when the resource - // model drastically changes, such as a cvs checkout or an edit reversion - if (oldXmlPersistence != newXmlPersistence) { - if (this.persistence != null) { - this.getJpaFile(this.persistenceXmlResource.getFile()).removeRootStructureNode(this.persistenceXmlResource); - this.persistence.dispose(); - this.setPersistence(null); - } - } - - if (newXmlPersistence != null) { - if (this.persistence != null) { - this.getJpaFile(this.persistenceXmlResource.getFile()).addRootStructureNode(this.persistenceXmlResource, this.persistence); - this.persistence.update(newXmlPersistence); - } - else { - setPersistence(buildPersistence(newXmlPersistence)); - } - } - else { - if (this.persistence != null) { - this.getJpaFile(this.persistenceXmlResource.getFile()).removeRootStructureNode(this.persistenceXmlResource); - this.persistence.dispose(); - } - setPersistence(null); - } - } - - @Override - public void postUpdate() { - super.postUpdate(); - if (this.persistence != null) { - this.persistence.postUpdate(); - } - } - - protected Persistence buildPersistence(XmlPersistence xmlPersistence) { - return getJpaFactory().buildPersistence(this, xmlPersistence); - } - - - // ************************************************************************* - - @Override - public PersistenceUnit getPersistenceUnit() { - throw new UnsupportedOperationException("No Persistence Unit in this context"); //$NON-NLS-1$ - } - - - public JpaStructureNode getStructureNode(int textOffset) { - if (this.persistence.containsOffset(textOffset)) { - return this.persistence.getStructureNode(textOffset); - } - return this; - } - - // never actually selected - public TextRange getSelectionTextRange() { - return TextRange.Empty.instance(); - } - - public TextRange getValidationTextRange() { - return TextRange.Empty.instance(); - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (this.persistence == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_XML_INVALID_CONTENT, - this - ) - ); - return; - } - - this.persistence.validate(messages, reporter); - } - - public void dispose() { - this.persistence.dispose(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java deleted file mode 100644 index 45612f10a6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.context.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.persistence.AbstractMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.utility.TextRange; - -public class ImpliedMappingFileRef - extends AbstractMappingFileRef -{ - - // ********** construction/initialization ********** - - public ImpliedMappingFileRef(PersistenceUnit parent, String resourceFileName) { - super(parent, resourceFileName); - } - - public boolean isImplied() { - return true; - } - - public void setFileName(String fileName) { - throw new UnsupportedOperationException("Cannot set an implied mapping file ref's 'fileName'"); //$NON-NLS-1$ - } - - public TextRange getSelectionTextRange() { - return null; - } - - public TextRange getValidationTextRange() { - return this.getPersistenceUnit().getValidationTextRange(); - } - - public boolean containsOffset(int textOffset) { - return false; - } - - public void update(XmlMappingFileRef mappingFileRef) { - if (mappingFileRef != null) { - throw new IllegalArgumentException("mappingFileRef should be null for an implied mapping file"); //$NON-NLS-1$ - } - super.update(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinaryAssociationOverride1_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinaryAssociationOverride1_0Annotation.java deleted file mode 100644 index 2837174908..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinaryAssociationOverride1_0Annotation.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; - -/** - * javax.persistence.AssociationOverride - */ -public final class BinaryAssociationOverride1_0Annotation - extends BinaryAssociationOverrideAnnotation -{ - - public BinaryAssociationOverride1_0Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinaryAssociationOverrides1_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinaryAssociationOverrides1_0Annotation.java deleted file mode 100644 index 6648edb213..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinaryAssociationOverrides1_0Annotation.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; - -/** - * javax.persistence.AssociationOverrides - */ -public final class BinaryAssociationOverrides1_0Annotation - extends BinaryAssociationOverridesAnnotation -{ - - public BinaryAssociationOverrides1_0Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - @Override - protected NestableAssociationOverrideAnnotation buildAssociationOverride(Object jdtAssociationOverride) { - return new BinaryAssociationOverride1_0Annotation(this, (IAnnotation) jdtAssociationOverride); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinarySequenceGenerator1_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinarySequenceGenerator1_0Annotation.java deleted file mode 100644 index 573dfee8ec..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/binary/BinarySequenceGenerator1_0Annotation.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinarySequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; - -/** - * javax.persistence.SequenceGenerator - */ -public final class BinarySequenceGenerator1_0Annotation - extends BinarySequenceGeneratorAnnotation -{ - - public BinarySequenceGenerator1_0Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceAssociationOverride1_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceAssociationOverride1_0Annotation.java deleted file mode 100644 index 617747551f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceAssociationOverride1_0Annotation.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.resource.java.source; - -import org.eclipse.jpt.core.internal.resource.java.source.SourceAssociationOverrideAnnotation; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AssociationOverride - */ -public final class SourceAssociationOverride1_0Annotation - extends SourceAssociationOverrideAnnotation -{ - - // ********** construction/initialization ********** - - public SourceAssociationOverride1_0Annotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - } - - // ********** static methods ********** - - public static SourceAssociationOverride1_0Annotation buildAssociationOverride(JavaResourceNode parent, Member member) { - return new SourceAssociationOverride1_0Annotation(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - static SourceAssociationOverride1_0Annotation buildNestedAssociationOverride(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new SourceAssociationOverride1_0Annotation(parent, member, idaa, annotationAdapter); - } - - protected static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(attributeOverridesAdapter, index, JPA.ASSOCIATION_OVERRIDE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceAssociationOverrides1_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceAssociationOverrides1_0Annotation.java deleted file mode 100644 index 859946da3f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceAssociationOverrides1_0Annotation.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.resource.java.source; - -import org.eclipse.jpt.core.internal.resource.java.source.SourceAssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AssociationOverrides - */ -public final class SourceAssociationOverrides1_0Annotation - extends SourceAssociationOverridesAnnotation -{ - - public SourceAssociationOverrides1_0Annotation(JavaResourceNode parent, Member member) { - super(parent, member); - } - - @Override - protected NestableAssociationOverrideAnnotation buildAssociationOverride(int index) { - return SourceAssociationOverride1_0Annotation.buildNestedAssociationOverride(this, this.member, index, this.daa); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceSequenceGenerator1_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceSequenceGenerator1_0Annotation.java deleted file mode 100644 index 27ac7f42a3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/resource/java/source/SourceSequenceGenerator1_0Annotation.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa1.resource.java.source; - -import org.eclipse.jpt.core.internal.resource.java.source.SourceSequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.SequenceGenerator - */ -public final class SourceSequenceGenerator1_0Annotation - extends SourceSequenceGeneratorAnnotation -{ - - public SourceSequenceGenerator1_0Annotation(JavaResourceNode parent, Member member) { - super(parent, member); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaAnnotationDefinitionProvider.java deleted file mode 100644 index cf0a15e942..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaAnnotationDefinitionProvider.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import java.util.List; -import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.internal.AbstractJpaAnnotationDefintionProvider; -import org.eclipse.jpt.core.internal.jpa2.resource.java.Access2_0AnnotationDefinition; -import org.eclipse.jpt.core.internal.jpa2.resource.java.AssociationOverride2_0AnnotationDefinition; -import org.eclipse.jpt.core.internal.jpa2.resource.java.AssociationOverrides2_0AnnotationDefinition; -import org.eclipse.jpt.core.internal.jpa2.resource.java.SequenceGenerator2_0AnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AttributeOverrideAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AttributeOverridesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.BasicAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.DiscriminatorColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.DiscriminatorValueAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddedAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddedIdAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EntityAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EnumeratedAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.GeneratedValueAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.IdAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.IdClassAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.InheritanceAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinColumnsAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinTableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.LobAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ManyToManyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ManyToOneAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.MapKeyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.MappedSuperclassAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedNativeQueriesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedNativeQueryAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedQueriesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedQueryAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OneToManyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OneToOneAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OrderByAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.PrimaryKeyJoinColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.PrimaryKeyJoinColumnsAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SecondaryTableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SecondaryTablesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TableGeneratorAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TemporalAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TransientAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.VersionAnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; - -/** - * Support for existing JPA 1.0 annotations, new JPA 2.0 annotations, and - * augmented support for annotations changed from 1.0 to 2.0 - */ -public class Generic2_0JpaAnnotationDefinitionProvider - extends AbstractJpaAnnotationDefintionProvider -{ - // singleton - private static final JpaAnnotationDefinitionProvider INSTANCE = - new Generic2_0JpaAnnotationDefinitionProvider(); - - - /** - * Return the singleton - */ - public static JpaAnnotationDefinitionProvider instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private Generic2_0JpaAnnotationDefinitionProvider() { - super(); - } - - - @Override - protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(Access2_0AnnotationDefinition.instance()); - definitions.add(AssociationOverride2_0AnnotationDefinition.instance()); - definitions.add(AssociationOverrides2_0AnnotationDefinition.instance()); - definitions.add(AttributeOverrideAnnotationDefinition.instance()); - definitions.add(AttributeOverridesAnnotationDefinition.instance()); - definitions.add(DiscriminatorColumnAnnotationDefinition.instance()); - definitions.add(DiscriminatorValueAnnotationDefinition.instance()); - definitions.add(EmbeddableAnnotationDefinition.instance()); - definitions.add(EntityAnnotationDefinition.instance()); - definitions.add(IdClassAnnotationDefinition.instance()); - definitions.add(InheritanceAnnotationDefinition.instance()); - definitions.add(MappedSuperclassAnnotationDefinition.instance()); - definitions.add(NamedQueryAnnotationDefinition.instance()); - definitions.add(NamedQueriesAnnotationDefinition.instance()); - definitions.add(NamedNativeQueryAnnotationDefinition.instance()); - definitions.add(NamedNativeQueriesAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnsAnnotationDefinition.instance()); - definitions.add(SecondaryTableAnnotationDefinition.instance()); - definitions.add(SecondaryTablesAnnotationDefinition.instance()); - definitions.add(SequenceGenerator2_0AnnotationDefinition.instance()); - definitions.add(TableAnnotationDefinition.instance()); - definitions.add(TableGeneratorAnnotationDefinition.instance()); - } - - @Override - protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(EmbeddableAnnotationDefinition.instance()); - definitions.add(EntityAnnotationDefinition.instance()); - definitions.add(MappedSuperclassAnnotationDefinition.instance()); - } - - @Override - protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(Access2_0AnnotationDefinition.instance()); - definitions.add(AssociationOverride2_0AnnotationDefinition.instance()); - definitions.add(AssociationOverrides2_0AnnotationDefinition.instance()); - definitions.add(AttributeOverrideAnnotationDefinition.instance()); - definitions.add(AttributeOverridesAnnotationDefinition.instance()); - definitions.add(BasicAnnotationDefinition.instance()); - definitions.add(ColumnAnnotationDefinition.instance()); - definitions.add(EmbeddedAnnotationDefinition.instance()); - definitions.add(EmbeddedIdAnnotationDefinition.instance()); - definitions.add(EnumeratedAnnotationDefinition.instance()); - definitions.add(GeneratedValueAnnotationDefinition.instance()); - definitions.add(IdAnnotationDefinition.instance()); - definitions.add(JoinColumnAnnotationDefinition.instance()); - definitions.add(JoinColumnsAnnotationDefinition.instance()); - definitions.add(JoinTableAnnotationDefinition.instance()); - definitions.add(LobAnnotationDefinition.instance()); - definitions.add(ManyToManyAnnotationDefinition.instance()); - definitions.add(ManyToOneAnnotationDefinition.instance()); - definitions.add(MapKeyAnnotationDefinition.instance()); - definitions.add(OneToManyAnnotationDefinition.instance()); - definitions.add(OneToOneAnnotationDefinition.instance()); - definitions.add(OrderByAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnAnnotationDefinition.instance()); - definitions.add(PrimaryKeyJoinColumnsAnnotationDefinition.instance()); - definitions.add(SequenceGenerator2_0AnnotationDefinition.instance()); - definitions.add(TableGeneratorAnnotationDefinition.instance()); - definitions.add(TemporalAnnotationDefinition.instance()); - definitions.add(TransientAnnotationDefinition.instance()); - definitions.add(VersionAnnotationDefinition.instance()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformFactory.java deleted file mode 100644 index e23c481017..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaPlatformFactory; -import org.eclipse.jpt.core.JpaPlatformVariation; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider; -import org.eclipse.jpt.core.internal.GenericJpaPlatform; - -/** - * All the state in the JPA platform should be "static" (i.e. unchanging once - * it is initialized). - */ -public class Generic2_0JpaPlatformFactory - implements JpaPlatformFactory -{ - /** - * zero-argument constructor - */ - public Generic2_0JpaPlatformFactory() { - super(); - } - - - public JpaPlatform buildJpaPlatform(String id) { - return new GenericJpaPlatform( - id, - this.buildJpaVersion(), - new GenericJpaFactory2_0(), - new GenericJpaAnnotationProvider(Generic2_0JpaAnnotationDefinitionProvider.instance()), - Generic2_0JpaPlatformProvider.instance(), - this.buildJpaPlatformVariation()); - } - - private JpaPlatform.Version buildJpaVersion() { - return new JpaPlatform.Version() { - public boolean is2_0Compatible() { - return true; - } - - public int getJpaVersion() { - return 2; - } - }; - } - - protected JpaPlatformVariation buildJpaPlatformVariation() { - return new JpaPlatformVariation() { - //table_per_class inheritance support is optional in the 2.0 spec - public Supported getTablePerConcreteClassInheritanceIsSupported() { - return Supported.MAYBE; - } - public boolean isJoinTableOverridable() { - return true; - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformProvider.java deleted file mode 100644 index 593be3353c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Generic2_0JpaPlatformProvider.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.jpt.core.JpaPlatformProvider; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.context.MappingFileDefinition; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.internal.AbstractJpaPlatformProvider; -import org.eclipse.jpt.core.internal.JarResourceModelProvider; -import org.eclipse.jpt.core.internal.JavaResourceModelProvider; -import org.eclipse.jpt.core.internal.OrmResourceModelProvider; -import org.eclipse.jpt.core.internal.PersistenceResourceModelProvider; -import org.eclipse.jpt.core.internal.context.java.JavaBasicMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddableDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEntityDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaManyToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaManyToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaMappedSuperclassDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaOneToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaOneToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaTransientMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaVersionMappingDefinition; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmXmlDefinition; -import org.eclipse.jpt.core.internal.jpa2.context.java.JavaIdMappingDefinition2_0; -import org.eclipse.jpt.core.internal.jpa2.context.orm.GenericOrmXml2_0Definition; - -/** - * All the state in the JPA platform should be "static" (i.e. unchanging once - * it is initialized). - */ -public class Generic2_0JpaPlatformProvider - extends AbstractJpaPlatformProvider -{ - public static final String ID = "generic2_0"; //$NON-NLS-1$ - - - // singleton - private static final JpaPlatformProvider INSTANCE = - new Generic2_0JpaPlatformProvider(); - - - /** - * Return the singleton - */ - public static JpaPlatformProvider instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private Generic2_0JpaPlatformProvider() { - super(); - } - - - // ********** resource models ********** - - @Override - protected JpaResourceModelProvider[] buildResourceModelProviders() { - // order should not be important here - return new JpaResourceModelProvider[] { - JavaResourceModelProvider.instance(), - JarResourceModelProvider.instance(), - PersistenceResourceModelProvider.instance(), - OrmResourceModelProvider.instance(), - Persistence2_0ResourceModelProvider.instance(), - Orm2_0ResourceModelProvider.instance()}; - } - - - // ********** Java type mappings ********** - - @Override - protected JavaTypeMappingDefinition[] buildNonNullJavaTypeMappingDefinitions() { - // order determined by analyzing order that reference implementation (eclipselink) uses - return new JavaTypeMappingDefinition[] { - JavaEntityDefinition.instance(), - JavaEmbeddableDefinition.instance(), - JavaMappedSuperclassDefinition.instance()}; - } - - - // ********** Java attribute mappings ********** - - @Override - protected JavaAttributeMappingDefinition[] buildNonNullDefaultJavaAttributeMappingDefinitions() { - // order determined by analyzing order that reference implementation (toplink) uses - return new JavaAttributeMappingDefinition[] { - JavaEmbeddedMappingDefinition.instance(), - JavaBasicMappingDefinition.instance()}; - } - - @Override - protected JavaAttributeMappingDefinition[] buildNonNullSpecifiedJavaAttributeMappingDefinitions() { - // order determined by analyzing order that reference implementation (toplink) uses - return new JavaAttributeMappingDefinition[] { - JavaTransientMappingDefinition.instance(), - //JavaElementCollectionMappingProvider.instance(), - JavaIdMappingDefinition2_0.instance(), - JavaVersionMappingDefinition.instance(), - JavaBasicMappingDefinition.instance(), - JavaEmbeddedMappingDefinition.instance(), - JavaEmbeddedIdMappingDefinition.instance(), - JavaManyToManyMappingDefinition.instance(), - JavaManyToOneMappingDefinition.instance(), - JavaOneToManyMappingDefinition.instance(), - JavaOneToOneMappingDefinition.instance()}; - } - - - // ********** Mapping Files ********** - - @Override - protected MappingFileDefinition[] buildMappingFileDefinitions() { - return new MappingFileDefinition[] { - GenericOrmXmlDefinition.instance(), - GenericOrmXml2_0Definition.instance()}; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericJpaFactory2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericJpaFactory2_0.java deleted file mode 100644 index 64de3f01d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericJpaFactory2_0.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.AssociationOverrideContainer.Owner; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.internal.AbstractJpaFactory; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaAssociationOverrideRelationshipReference2_0; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaDerivedId2_0; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaEmbeddable2_0; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaPersistentAttribute2_0; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaPersistentType2_0; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaSequenceGenerator2_0; -import org.eclipse.jpt.core.internal.jpa2.context.java.VirtualAssociationOverride2_0Annotation; -import org.eclipse.jpt.core.internal.jpa2.context.orm.GenericOrmDerivedId2_0; -import org.eclipse.jpt.core.internal.jpa2.context.persistence.GenericPersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.jpa2.PersistentTypeStaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.StaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.Persistence2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlDerivedId; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; - - -/** - * Central class that allows extenders to easily replace implementations of - * various Dali interfaces. - */ -public class GenericJpaFactory2_0 - extends AbstractJpaFactory -{ - - public GenericJpaFactory2_0() { - super(); - } - - // ********** Core Model ********** - - @Override - public StaticMetamodelSynchronizer buildStaticMetamodelSynchronizer(JpaProject2_0 jpaProject) { - return new GenericStaticMetamodelSynchronizer(jpaProject); - } - - @Override - public PersistentTypeStaticMetamodelSynchronizer buildPersistentTypeStaticMetamodelSynchronizer(StaticMetamodelSynchronizer staticMetamodelSynchronizer, PersistentType persistentType) { - return new GenericPersistentTypeStaticMetamodelSynchronizer(staticMetamodelSynchronizer, persistentType); - } - - - // ********** Persistence Context Model ********** - - @Override - public PersistenceUnit2_0 buildPersistenceUnit(Persistence parent, XmlPersistenceUnit xmlPersistenceUnit) { - return new GenericPersistenceUnit2_0((Persistence2_0) parent, xmlPersistenceUnit); - } - - - // ********** Java Context Model ********** - - @Override - public JavaPersistentType buildJavaPersistentType(PersistentType.Owner owner, JavaResourcePersistentType jrpt) { - return new GenericJavaPersistentType2_0(owner, jrpt); - } - - @Override - public JavaPersistentAttribute buildJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa) { - return new GenericJavaPersistentAttribute2_0(parent, jrpa); - } - - @Override - public JavaEmbeddable buildJavaEmbeddable(JavaPersistentType parent) { - return new GenericJavaEmbeddable2_0(parent); - } - - @Override - public JavaSequenceGenerator buildJavaSequenceGenerator(JavaJpaContextNode parent) { - return new GenericJavaSequenceGenerator2_0(parent); - } - - //The 2.0 JPA spec supports association overrides on an embedded mapping while the 1.0 spec did not - @Override - public JavaAssociationOverrideContainer buildJavaAssociationOverrideContainer(JavaEmbeddedMapping2_0 parent, Owner owner) { - return new GenericJavaAssociationOverrideContainer(parent, owner); - } - - @Override - public JavaAssociationOverrideRelationshipReference buildJavaAssociationOverrideRelationshipReference(JavaAssociationOverride parent) { - return new GenericJavaAssociationOverrideRelationshipReference2_0(parent); - } - - @Override - public AssociationOverrideAnnotation buildJavaVirtualAssociationOverrideAnnotation(JavaResourcePersistentMember jrpm, String name, JoiningStrategy joiningStrategy) { - return new VirtualAssociationOverride2_0Annotation(jrpm, name, joiningStrategy); - } - - @Override - public JavaDerivedId2_0 buildJavaDerivedId(JavaSingleRelationshipMapping2_0 parent) { - return new GenericJavaDerivedId2_0(parent); - } - - - // ********** Orm Context Model ********** - - public OrmDerivedId2_0 buildOrmDerivedId(OrmSingleRelationshipMapping2_0 parent, XmlDerivedId resource) { - return new GenericOrmDerivedId2_0(parent, resource); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeStaticMetamodelSynchronizer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeStaticMetamodelSynchronizer.java deleted file mode 100644 index 3ff5033ad1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericPersistentTypeStaticMetamodelSynchronizer.java +++ /dev/null @@ -1,510 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeSet; -import java.util.Map.Entry; - -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.jpa2.PersistentTypeStaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.StaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.context.PersistentAttribute2_0; -import org.eclipse.jpt.core.jpa2.context.StaticMetamodelField; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.IndentingPrintWriter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; - -import com.ibm.icu.text.Collator; -import com.ibm.icu.text.DateFormat; - -/** - * - */ -@SuppressWarnings("nls") -public class GenericPersistentTypeStaticMetamodelSynchronizer - implements PersistentTypeStaticMetamodelSynchronizer -{ - protected final StaticMetamodelSynchronizer staticMetamodelSynchronizer; - protected final PersistentType persistentType; - protected final String metamodelClassName; - - - public GenericPersistentTypeStaticMetamodelSynchronizer(StaticMetamodelSynchronizer staticMetamodelSynchronizer, PersistentType persistentType) { - super(); - this.staticMetamodelSynchronizer = staticMetamodelSynchronizer; - this.persistentType = persistentType; - this.metamodelClassName = this.buildMetamodelClassName(); - } - - // TODO - protected String buildMetamodelClassName() { - return this.buildMetamodelClassName(this.persistentType.getName()); - } - - protected String buildMetamodelClassName(String className) { - return className + '_'; - } - - // TODO - protected String getPackageName() { - return ClassTools.packageNameForClassNamed(this.metamodelClassName); - } - - protected IPackageFragment buildPackageFragment() { - IPackageFragmentRoot sourceFolder = this.staticMetamodelSynchronizer.getSourceFolder(); - String pkgName = this.getPackageName(); - IPackageFragment packageFragment = sourceFolder.getPackageFragment(pkgName); - if (packageFragment.exists()) { - return packageFragment; - } - try { - return sourceFolder.createPackageFragment(pkgName, true, null); - } catch (JavaModelException ex) { - throw new RuntimeException(ex); - } - } - - public void synchronize() { - try { - this.synchronize_(); - } catch (JavaModelException ex) { - throw new RuntimeException(ex); - } - } - - protected void synchronize_() throws JavaModelException { - // TODO check for @Generated annotation - String fileName = ClassTools.shortNameForClassNamed(this.metamodelClassName) + ".java"; - String source = this.buildSource(); - IPackageFragment pkg = this.buildPackageFragment(); - pkg.createCompilationUnit(fileName, source, true, null); - } - - /** - * build the "body" source first; then build the "package" and "imports" source - * and concatenate the "body" source to it - */ - protected String buildSource() { - // build the body source first so we can gather up the import statements - BodySourceWriter bodySourceWriter = this.buildBodySourceWriter(); - - StringWriter sw = new StringWriter(bodySourceWriter.getLength() + 2000); - PrintWriter pw = new PrintWriter(sw); - this.printPackageAndImportsOn(pw, bodySourceWriter); - pw.print(bodySourceWriter.getSource()); - return sw.toString(); - } - - protected BodySourceWriter buildBodySourceWriter() { - BodySourceWriter pw = new BodySourceWriter(this.getPackageName(), this.metamodelClassName); - this.printBodySourceOn(pw); - return pw; - } - - protected void printBodySourceOn(BodySourceWriter pw) { - this.printClassDeclarationOn(pw); - pw.print(" {"); - pw.println(); - - pw.indent(); - this.printAttributesOn(pw); - pw.undent(); - - pw.print('}'); - pw.println(); // EOF - } - - - // ********** class declaration ********** - - protected void printClassDeclarationOn(BodySourceWriter pw) { - this.printGeneratedAnnotationOn(pw); - this.printStaticMetamodelAnnotationOn(pw); - - pw.print("public class "); - pw.printTypeDeclaration(this.metamodelClassName); - PersistentType superPersistentType = this.persistentType.getSuperPersistentType(); - if (superPersistentType != null) { - pw.print(" extends "); - pw.printTypeDeclaration(this.buildMetamodelClassName(superPersistentType.getName())); - } - } - - protected void printStaticMetamodelAnnotationOn(BodySourceWriter pw) { - pw.printAnnotation(JPA2_0.STATIC_METAMODEL); - pw.print('('); - pw.printTypeDeclaration(this.persistentType.getName()); - pw.print(".class"); - pw.print(')'); - pw.println(); - } - - // TODO - comment? - protected void printGeneratedAnnotationOn(BodySourceWriter pw) { - pw.printAnnotation("javax.annotation.Generated"); - pw.print('('); - pw.printStringLiteral("Dali" + ' ' + DateFormat.getDateTimeInstance().format(new Date())); - pw.print(')'); - pw.println(); - } - - - // ********** attributes ********** - - protected void printAttributesOn(BodySourceWriter pw) { - for (Iterator<PersistentAttribute> stream = this.persistentType.attributes(); stream.hasNext(); ) { - this.printAttributeOn(stream.next(), pw); - } - } - - protected void printAttributeOn(PersistentAttribute persistentAttribute, BodySourceWriter pw) { - StaticMetamodelField field = ((PersistentAttribute2_0) persistentAttribute).getStaticMetamodelField(); - if (field != null) { - this.printFieldOn(field, pw); - } - } - - protected void printFieldOn(StaticMetamodelField field, BodySourceWriter pw) { - for (String modifier : field.getModifiers()) { - pw.print(modifier); - pw.print(' '); - } - pw.printTypeDeclaration(field.getTypeName()); - pw.print('<'); - for (Iterator<String> stream = field.getTypeArgumentNames().iterator(); stream.hasNext(); ) { - pw.printTypeDeclaration(stream.next()); - if (stream.hasNext()) { - pw.print(", "); - } - } - pw.print('>'); - pw.print(' '); - pw.print(field.getName()); - pw.print(';'); - pw.println(); - } - - - // ********** package and imports ********** - - protected void printPackageAndImportsOn(PrintWriter pw, BodySourceWriter bodySourceWriter) { - if (this.getPackageName().length() != 0) { - pw.print("package "); - pw.print(this.getPackageName()); - pw.print(';'); - pw.println(); - pw.println(); - } - - for (String import_ : bodySourceWriter.getImports()) { - pw.print("import "); - pw.print(import_); - pw.print(';'); - pw.println(); - } - pw.println(); - } - - - // ********** source writer ********** - - /** - * Extend IndentingPrintWriter with some methods that facilitate building - * class source code. - */ - protected static class BodySourceWriter - extends IndentingPrintWriter - { - protected final String packageName; - protected final String className; - // key = short class name; value = import package - protected final HashMap<String, ImportPackage> imports = new HashMap<String, ImportPackage>(); - - protected BodySourceWriter(String packageName, String className) { - super(new StringWriter(2000)); - this.packageName = packageName; - this.className = className; - } - - protected String getSource() { - return this.out.toString(); - } - - protected int getLength() { - return ((StringWriter) this.out).getBuffer().length(); - } - - protected void printVisibility(String visibilityModifier) { - if (visibilityModifier.length() != 0) { - this.print(visibilityModifier); - this.print(' '); - } - } - - protected void printAnnotation(String annotationName) { - this.print('@'); - this.printTypeDeclaration(annotationName); - } - - protected void printTypeDeclaration(String typeDeclaration) { - this.print(this.buildImportedTypeDeclaration(typeDeclaration)); - } - - protected void printField(String fieldName, String typeDeclaration, String visibility) { - this.printVisibility(visibility); - this.printTypeDeclaration(typeDeclaration); - this.print(' '); - this.print(fieldName); - this.print(';'); - this.println(); - this.println(); - } - - protected void printParameterizedField(String fieldName, String typeDeclaration, String parameterTypeDeclaration, String visibility) { - this.printVisibility(visibility); - this.printTypeDeclaration(typeDeclaration); - this.print('<'); - this.printTypeDeclaration(parameterTypeDeclaration); - this.print('>'); - this.print(' '); - this.print(fieldName); - this.print(';'); - this.println(); - this.println(); - } - - /** - * Convert the specified string to a String Literal and print it, - * adding the surrounding double-quotes and escaping characters - * as necessary. - */ - void printStringLiteral(String string) { - StringTools.convertToJavaStringLiteralOn(string, this); - } - - - // ********** imports ********** - - // ***** writing - /** - * Return the specified class's "imported" name. - * The class declaration must be of the form: - * "int" - * "int[]" (not "[I") - * "java.lang.Object" - * "java.lang.Object[]" (not "[Ljava.lang.Object;") - * "java.util.Map.Entry" (not "java.util.Map$Entry") - * "java.util.Map.Entry[][]" (not "[[Ljava.util.Map$Entry;") - * - * To really do this right, we would need to gather all the types from - * the "unamed" (default) package that were referenced in the - * compilation unit beforehand. *Any* collisions with one of these - * types would have to be fully qualified (whether it was from - * 'java.lang' or the same package as the current compilation unit). - * In other words, if we have any types from the "unnamed" package, - * results are unpredictable.... - */ - protected String buildImportedTypeDeclaration(String typeDeclaration) { - if (this.typeDeclarationIsMemberClass(typeDeclaration)) { - // no need for an import, just return the partially-qualified name - return this.buildMemberClassTypeDeclaration(typeDeclaration); - } - int last = typeDeclaration.lastIndexOf('.'); - String currentPackageName = (last == -1) ? "" : typeDeclaration.substring(0, last); - String shortTypeDeclaration = typeDeclaration.substring(last + 1); - String shortElementTypeName = shortTypeDeclaration; - while (shortElementTypeName.endsWith("[]")) { - shortElementTypeName = shortElementTypeName.substring(0, shortElementTypeName.length() - 2); - } - ImportPackage prev = this.imports.get(shortElementTypeName); - if (prev == null) { - // this is the first class with this short element type name - this.imports.put(shortElementTypeName, new ImportPackage(currentPackageName)); - return shortTypeDeclaration; - } - if (prev.packageName.equals(currentPackageName)) { - // this element type has already been imported - return shortTypeDeclaration; - } - if (currentPackageName.equals(this.packageName) && - prev.packageName.equals("java.lang")) { - // we force the 'java.lang' class to be explicitly imported - prev.collision = true; - } - // another class with the same short element type name has been - // previously imported, so this one must be used fully-qualified - return typeDeclaration; - } - - /** - * e.g. "foo.bar.Employee.PK" will return true - */ - protected boolean typeDeclarationIsMemberClass(String typeDeclaration) { - return (typeDeclaration.length() > this.className.length()) - && typeDeclaration.startsWith(this.className) - && (typeDeclaration.charAt(this.className.length()) == '.'); - } - - /** - * e.g. "foo.bar.Employee.PK" will return "Employee.PK" - * this prevents collisions with other imported classes (e.g. "joo.jar.PK") - */ - protected String buildMemberClassTypeDeclaration(String typeDeclaration) { - int index = this.packageName.length(); - if (index != 0) { - index++; // bump past the '.' - } - return typeDeclaration.substring(index); - } - - // ***** reading - protected Iterable<String> getImports() { - return this.getSortedRequiredImports(); - } - - /** - * transform our map entries to class names - */ - protected Iterable<String> getSortedRequiredImports() { - return new TransformationIterable<Map.Entry<String, ImportPackage>, String>(this.getSortedRequiredImportEntries(), this.buildImportEntriesTransformer()); - } - - protected Transformer<Map.Entry<String, ImportPackage>, String> buildImportEntriesTransformer() { - return IMPORT_ENTRIES_TRANSFORMER; - } - - protected static final Transformer<Map.Entry<String, ImportPackage>, String> IMPORT_ENTRIES_TRANSFORMER = new ImportEntriesTransformer(); - - protected static class ImportEntriesTransformer - implements Transformer<Map.Entry<String, ImportPackage>, String> - { - public String transform(Entry<String, ImportPackage> importEntry) { - String pkg = importEntry.getValue().packageName; - String type = importEntry.getKey(); - StringBuilder sb = new StringBuilder(pkg.length() + 1 + type.length()); - sb.append(pkg); - sb.append('.'); - sb.append(type); - return sb.toString(); - } - } - - /** - * sort by package first, then class (*not* by fully-qualified class name) - */ - protected Iterable<Map.Entry<String, ImportPackage>> getSortedRequiredImportEntries() { - TreeSet<Map.Entry<String, ImportPackage>> sortedEntries = new TreeSet<Map.Entry<String, ImportPackage>>(this.buildImportEntriesComparator()); - CollectionTools.addAll(sortedEntries, this.getRequiredImportEntries()); - return sortedEntries; - } - - protected Comparator<Map.Entry<String, ImportPackage>> buildImportEntriesComparator() { - return IMPORT_ENTRIES_COMPARATOR; - } - - protected static final Comparator<Map.Entry<String, ImportPackage>> IMPORT_ENTRIES_COMPARATOR = new ImportEntriesComparator(); - - protected static class ImportEntriesComparator - implements Comparator<Map.Entry<String, ImportPackage>> - { - public int compare(Map.Entry<String, ImportPackage> e1, Map.Entry<String, ImportPackage> e2) { - Collator collator = Collator.getInstance(); - int pkg = collator.compare(e1.getValue().packageName, e2.getValue().packageName); - return (pkg == 0) ? collator.compare(e1.getKey(), e2.getKey()) : pkg; - } - } - - /** - * strip off any non-required imports (e.g. "java.lang.Object') - */ - protected Iterable<Map.Entry<String, ImportPackage>> getRequiredImportEntries() { - return new FilteringIterable<Map.Entry<String, ImportPackage>, Map.Entry<String, ImportPackage>>(this.imports.entrySet(), this.buildRequiredImportEntriesFilter()); - } - - protected Filter<Map.Entry<String, ImportPackage>> buildRequiredImportEntriesFilter() { - return new RequiredImportEntriesFilter(); - } - - protected class RequiredImportEntriesFilter - implements Filter<Map.Entry<String, ImportPackage>> - { - public boolean accept(Map.Entry<String, ImportPackage> importEntry) { - return this.packageMustBeImported(importEntry.getValue()); - } - - protected boolean packageMustBeImported(ImportPackage importPackage) { - String pkg = importPackage.packageName; - if (pkg.equals("")) { - // cannot import a type from the "unnamed" package - return false; - } - if (pkg.equals("java.lang")) { - // we must import from 'java.lang' if we also have a class in the same package - return importPackage.collision; - } - if (pkg.equals(BodySourceWriter.this.packageName)) { - // we never need to import a class from the same package - return false; - } - return true; - } - } - - /** - * We need a 'collision' flag for when we encounter a class from - * 'java.lang' followed by a class from the current compilation unit's - * package. We will need to include the explicit import of the - * 'java.lang' class and all the references to the other class will - * have to be fully-qualified. - * - * If the classes are encountered in the opposite order (i.e. the class - * from the current compilation unit's package followed by the class - * from 'java.lang'), we do *not* need to import the first class while - * all the references to the 'java.lang' class will be fully-qualified. - * - * Unfortunately, we still have a problem: if we reference a class from - * 'java.lang' and there is a conflicting class from the current - * compilation unit's package (but that class is *not* revealed to us - * here), the simple name will be resolved to the non-'java.lang' class. - * Unless we simply force an import of *all* 'java.lang' classes.... :-( - * - * This shouldn't happen very often. :-) - */ - protected static class ImportPackage { - protected final String packageName; - protected boolean collision = false; - - protected ImportPackage(String packageName) { - super(); - this.packageName = packageName; - } - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericStaticMetamodelSynchronizer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericStaticMetamodelSynchronizer.java deleted file mode 100644 index 190d89bad7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/GenericStaticMetamodelSynchronizer.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.jpa2.JpaFactory2_0; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.jpa2.PersistentTypeStaticMetamodelSynchronizer; -import org.eclipse.jpt.core.jpa2.StaticMetamodelSynchronizer; - -/** - * - */ -public class GenericStaticMetamodelSynchronizer - implements StaticMetamodelSynchronizer -{ - protected final JpaProject2_0 jpaProject; - - public GenericStaticMetamodelSynchronizer(JpaProject2_0 jpaProject) { - super(); - this.jpaProject = jpaProject; - } - - protected JpaFactory2_0 getJpaFactory() { - return (JpaFactory2_0) this.jpaProject.getJpaPlatform().getJpaFactory(); - } - - public void synchronize(PersistentType persistentType) { - this.buildPersistentTypeStaticMetamodelSynchronizer(persistentType).synchronize(); - } - - protected PersistentTypeStaticMetamodelSynchronizer buildPersistentTypeStaticMetamodelSynchronizer(PersistentType persistentType) { - return this.getJpaFactory().buildPersistentTypeStaticMetamodelSynchronizer(this, persistentType); - } - - public JpaProject2_0 getJpaProject() { - return this.jpaProject; - } - - public IPackageFragmentRoot getSourceFolder() { - return this.jpaProject.getStaticMetaModelSourceFolder(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/NullPersistentTypeStaticMetamodelSynchronizer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/NullPersistentTypeStaticMetamodelSynchronizer.java deleted file mode 100644 index 88a71a1fb1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/NullPersistentTypeStaticMetamodelSynchronizer.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.jpt.core.jpa2.PersistentTypeStaticMetamodelSynchronizer; - -/** - * - */ -public class NullPersistentTypeStaticMetamodelSynchronizer - implements PersistentTypeStaticMetamodelSynchronizer -{ - - - public NullPersistentTypeStaticMetamodelSynchronizer() { - super(); - } - - public void synchronize() { - //no-op - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/NullStaticMetamodelSynchronizer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/NullStaticMetamodelSynchronizer.java deleted file mode 100644 index 0f05480c2a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/NullStaticMetamodelSynchronizer.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.jpa2.StaticMetamodelSynchronizer; - -/** - * - */ -public class NullStaticMetamodelSynchronizer - implements StaticMetamodelSynchronizer -{ - protected final JpaProject2_0 jpaProject; - - public NullStaticMetamodelSynchronizer(JpaProject2_0 jpaProject) { - super(); - this.jpaProject = jpaProject; - } - - public void synchronize(PersistentType persistentType) { - //no-op - } - - public JpaProject2_0 getJpaProject() { - return this.jpaProject; - } - - public IPackageFragmentRoot getSourceFolder() { - return this.jpaProject.getStaticMetaModelSourceFolder(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Orm2_0ResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Orm2_0ResourceModelProvider.java deleted file mode 100644 index 0678ce1894..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Orm2_0ResourceModelProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.jpa2.resource.orm.Orm2_0XmlResourceProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; - -/** - * orm.xml - */ -public class Orm2_0ResourceModelProvider - implements JpaResourceModelProvider -{ - // singleton - private static final JpaResourceModelProvider INSTANCE = new Orm2_0ResourceModelProvider(); - - /** - * Return the singleton. - */ - public static JpaResourceModelProvider instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Orm2_0ResourceModelProvider() { - super(); - } - - public IContentType getContentType() { - return JptCorePlugin.ORM2_0_XML_CONTENT_TYPE; - } - - public JpaXmlResource buildResourceModel(JpaProject jpaProject, IFile file) { - return Orm2_0XmlResourceProvider.getXmlResourceProvider(file).getXmlResource(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Persistence2_0ResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Persistence2_0ResourceModelProvider.java deleted file mode 100644 index 60f78648f3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/Persistence2_0ResourceModelProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.jpa2.resource.persistence.Persistence2_0XmlResourceProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; - -/** - * persistence.xml - */ -public class Persistence2_0ResourceModelProvider - implements JpaResourceModelProvider -{ - // singleton - private static final JpaResourceModelProvider INSTANCE = new Persistence2_0ResourceModelProvider(); - - /** - * Return the singleton. - */ - public static JpaResourceModelProvider instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Persistence2_0ResourceModelProvider() { - super(); - } - - public IContentType getContentType() { - return JptCorePlugin.PERSISTENCE2_0_XML_CONTENT_TYPE; - } - - public JpaXmlResource buildResourceModel(JpaProject jpaProject, IFile file) { - return Persistence2_0XmlResourceProvider.getXmlResourceProvider(file).getXmlResource(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/SimpleStaticMetamodelField.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/SimpleStaticMetamodelField.java deleted file mode 100644 index 2da5f1bf8a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/SimpleStaticMetamodelField.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context; - -import org.eclipse.jpt.core.jpa2.context.StaticMetamodelField; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * Straightforward implementation. - */ -public class SimpleStaticMetamodelField - implements StaticMetamodelField -{ - protected final Iterable<String> modifiers; - protected final String typeName; - protected final Iterable<String> typeArgumentNames; - protected final String name; - - public SimpleStaticMetamodelField( - Iterable<String> modifiers, - String typeName, - Iterable<String> typeArgumentNames, - String name - ) { - super(); - if (modifiers == null) { - throw new NullPointerException(); - } - if (typeName == null) { - throw new NullPointerException(); - } - if (typeArgumentNames == null) { - throw new NullPointerException(); - } - if (name == null) { - throw new NullPointerException(); - } - this.modifiers = modifiers; - this.typeName = typeName; - this.typeArgumentNames = typeArgumentNames; - this.name = name; - } - - public Iterable<String> getModifiers() { - return this.modifiers; - } - - public String getTypeName() { - return this.typeName; - } - - public Iterable<String> getTypeArgumentNames() { - return this.typeArgumentNames; - } - - public String getName() { - return this.name; - } - - @Override - public int hashCode() { - return CollectionTools.hashCode(this.modifiers) ^ - this.typeName.hashCode() ^ - CollectionTools.hashCode(this.typeArgumentNames) ^ - this.name.hashCode(); - } - - @Override - public boolean equals(Object o) { - if ( ! (o instanceof StaticMetamodelField)) { - return false; - } - StaticMetamodelField other = (StaticMetamodelField) o; - return CollectionTools.elementsAreEqual(this.getModifiers(), other.getModifiers()) && - this.getTypeName().equals(other.getTypeName()) && - CollectionTools.elementsAreEqual(this.getTypeArgumentNames(), other.getTypeArgumentNames()) && - this.getName().equals(other.getName()); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - for (String modifier : this.modifiers) { - sb.append(modifier); - sb.append(' '); - } - sb.append(this.typeName); - sb.append('<'); - for (String typeArgumentName : this.typeArgumentNames) { - sb.append(typeArgumentName); - sb.append(", "); //$NON-NLS-1$ - } - sb.setLength(sb.length() - 2); - sb.append('>'); - sb.append(' '); - sb.append(this.name); - return sb.toString(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaAssociationOverrideRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaAssociationOverrideRelationshipReference2_0.java deleted file mode 100644 index 367280e54e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaAssociationOverrideRelationshipReference2_0.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.AssociationOverrideRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaAssociationOverrideRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaJoinTableInAssociationOverrideJoiningStrategy2_0; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaAssociationOverrideRelationshipReference2_0 extends AbstractJavaAssociationOverrideRelationshipReference - implements JavaAssociationOverrideRelationshipReference2_0 -{ - - protected final JavaJoinTableInAssociationOverrideJoiningStrategy2_0 joinTableJoiningStrategy; - - public GenericJavaAssociationOverrideRelationshipReference2_0(JavaAssociationOverride parent) { - super(parent); - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - } - - public void initializeFrom(AssociationOverrideRelationshipReference oldAssociationOverride) { - if (oldAssociationOverride.getJoinColumnJoiningStrategy().hasSpecifiedJoinColumns()) { - getJoinColumnJoiningStrategy().initializeFrom(oldAssociationOverride.getJoinColumnJoiningStrategy()); - } - else { - getJoinTableJoiningStrategy().initializeFrom(((AssociationOverrideRelationshipReference2_0) oldAssociationOverride).getJoinTableJoiningStrategy()); - } - } - - protected JavaJoinTableInAssociationOverrideJoiningStrategy2_0 buildJoinTableJoiningStrategy() { - return new GenericJavaJoinTableInAssociationOverrideJoiningStrategy2_0(this); - } - - @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.joinTableJoiningStrategy.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - @Override - protected void initializeJoiningStrategies(AssociationOverrideAnnotation associationOverride) { - super.initializeJoiningStrategies(associationOverride); - this.joinTableJoiningStrategy.initialize((AssociationOverride2_0Annotation) associationOverride); - } - - @Override - protected void updateJoiningStrategies(AssociationOverrideAnnotation associationOverride) { - super.updateJoiningStrategies(associationOverride); - this.joinTableJoiningStrategy.update((AssociationOverride2_0Annotation) associationOverride); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.joinColumnJoiningStrategy.hasSpecifiedJoinColumns()) { - return this.joinColumnJoiningStrategy; - } - return this.joinTableJoiningStrategy; - } - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); -// if (this.connectionProfileIsActive()) { -// this.validateJoinTable(messages, astRoot); -// } - } - - - - // **************** join columns ******************************************* - - - public JavaJoinTableInAssociationOverrideJoiningStrategy2_0 getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public void setJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.addStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public void unsetJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return getAssociationOverride().isVirtual(); - } - - @Override - public void setJoinColumnJoiningStrategy() { - super.setJoinColumnJoiningStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaDerivedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaDerivedId2_0.java deleted file mode 100644 index b3d24271d4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaDerivedId2_0.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaSingleRelationshipMapping2_0; -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.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericJavaDerivedId2_0 - extends AbstractJavaJpaContextNode - implements JavaDerivedId2_0 -{ - protected boolean value; - - - public GenericJavaDerivedId2_0(JavaSingleRelationshipMapping2_0 parent) { - super(parent); - } - - - @Override - public JavaSingleRelationshipMapping2_0 getParent() { - return (JavaSingleRelationshipMapping2_0) super.getParent(); - } - - protected JavaResourcePersistentAttribute getResourceAttribute() { - return getParent().getPersistentAttribute().getResourcePersistentAttribute(); - } - - public boolean getValue() { - return this.value; - } - - public void setValue(boolean newValue) { - if (this.value == newValue) { - return; - } - boolean oldValue = this.value; - this.value = newValue; - - if (newValue) { - addIdAnnotation(); - } - else { - removeIdAnnotation(); - } - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - protected void setValue_(boolean newValue) { - boolean oldValue = this.value; - this.value = newValue; - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - protected boolean getResourceDerivedId() { - return getIdAnnotation() != null; - } - - protected IdAnnotation getIdAnnotation() { - return (IdAnnotation) getResourceAttribute().getAnnotation(JPA.ID); - } - - protected void addIdAnnotation() { - getResourceAttribute().addAnnotation(JPA.ID); - } - - protected void removeIdAnnotation() { - getResourceAttribute().removeAnnotation(JPA.ID); - } - - public void initialize() { - this.value = getResourceDerivedId(); - } - - public void update() { - this.setValue_(getResourceDerivedId()); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - IdAnnotation annotation = this.getIdAnnotation(); - return annotation == null ? null : annotation.getTextRange(astRoot); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - // no validation rules - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaEmbeddable2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaEmbeddable2_0.java deleted file mode 100644 index 4e9bd8353c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaEmbeddable2_0.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaEmbeddable; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.utility.internal.ArrayTools; - - -public class GenericJavaEmbeddable2_0 - extends AbstractJavaEmbeddable -{ - public GenericJavaEmbeddable2_0(JavaPersistentType parent) { - super(parent); - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return ArrayTools.contains(ALLOWED_ATTRIBUTE_MAPPING_KEYS, attributeMappingKey); - } - - public static final String[] ALLOWED_ATTRIBUTE_MAPPING_KEYS = - new String[] { - MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, - MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, - MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, - MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, - MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, - MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, - MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, - MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY - }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaJoinTableInAssociationOverrideJoiningStrategy2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaJoinTableInAssociationOverrideJoiningStrategy2_0.java deleted file mode 100644 index c909eff6af..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaJoinTableInAssociationOverrideJoiningStrategy2_0.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJoinTableJoiningStrategy; -import org.eclipse.jpt.core.jpa2.context.java.JavaAssociationOverrideRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaJoinTableInAssociationOverrideJoiningStrategy2_0; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaJoinTableInAssociationOverrideJoiningStrategy2_0 - extends AbstractJavaJoinTableJoiningStrategy - implements JavaJoinTableInAssociationOverrideJoiningStrategy2_0 -{ - protected transient AssociationOverride2_0Annotation associationOverrideAnnotation; - - public GenericJavaJoinTableInAssociationOverrideJoiningStrategy2_0(JavaAssociationOverrideRelationshipReference2_0 parent) { - super(parent); - } - - public boolean isOverridableAssociation() { - return false; - } - - @Override - public JavaAssociationOverrideRelationshipReference2_0 getRelationshipReference() { - return (JavaAssociationOverrideRelationshipReference2_0) super.getRelationshipReference(); - } - - // **************** join table ********************************************* - - public JoinTableAnnotation getAnnotation() { - return this.associationOverrideAnnotation.getNonNullJoinTable(); - } - @Override - protected JoinTableAnnotation addAnnotation() { - return this.associationOverrideAnnotation.addJoinTable(); - } - - @Override - protected void removeAnnotation() { - this.associationOverrideAnnotation.removeJoinTable(); - } - - - public void initialize(AssociationOverride2_0Annotation associationOverride) { - this.associationOverrideAnnotation = associationOverride; - super.initialize(); - } - - public void update(AssociationOverride2_0Annotation associationOverride) { - this.associationOverrideAnnotation = associationOverride; - super.update(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getRelationshipReference().getValidationTextRange(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java deleted file mode 100644 index aefe7cfc6c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribute; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; - -/** - * EclipseLink 1.1 persistent attribute - */ -public class GenericJavaPersistentAttribute2_0 - extends AbstractJavaPersistentAttribute -{ - protected AccessType specifiedAccess; - - - public GenericJavaPersistentAttribute2_0(PersistentType parent, JavaResourcePersistentAttribute resourcePersistentAttribute) { - super(parent, resourcePersistentAttribute); - this.specifiedAccess = this.buildSpecifiedAccess(); - } - - - // ********** AccessHolder implementation ********** - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - /** - * Don't support changing to specified access on a java persistent attribute, this - * involves a larger process of moving the annotations to the corresponding field/property - * which may or may not exist or might need to be created. - */ - public void setSpecifiedAccess(AccessType specifiedAccess) { - throw new UnsupportedOperationException(); - } - - protected void setSpecifiedAccess_(AccessType specifiedAccess) { - AccessType old = this.specifiedAccess; - this.specifiedAccess = specifiedAccess; - this.firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, old, specifiedAccess); - } - - protected AccessType buildSpecifiedAccess() { - Access2_0Annotation accessAnnotation = - (Access2_0Annotation) this.resourcePersistentAttribute. - getAnnotation(Access2_0Annotation.ANNOTATION_NAME); - return accessAnnotation == null ? null : AccessType.fromJavaResourceModel(accessAnnotation.getValue()); - } - - @Override - public void update() { - super.update(); - this.setSpecifiedAccess_(this.buildSpecifiedAccess()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentType2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentType2_0.java deleted file mode 100644 index 9fb85d3e20..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentType2_0.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import java.util.Iterator; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentType; -import org.eclipse.jpt.core.jpa2.JpaProject2_0; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -public class GenericJavaPersistentType2_0 - extends AbstractJavaPersistentType -{ - public GenericJavaPersistentType2_0(PersistentType.Owner parent, JavaResourcePersistentType jrpt) { - super(parent, jrpt); - } - - /** - * covariant override - */ - @Override - public JpaProject2_0 getJpaProject() { - return (JpaProject2_0) super.getJpaProject(); - } - - protected Access2_0Annotation getAccessAnnotation() { - return (Access2_0Annotation) this.resourcePersistentType. - getNonNullAnnotation(getAccessAnnotationName()); - } - - protected String getAccessAnnotationName() { - return Access2_0Annotation.ANNOTATION_NAME; - } - - @Override - protected AccessType buildSpecifiedAccess() { - return this.getResourceAccess(); - } - - public void setSpecifiedAccess(AccessType specifiedAccess) { - AccessType old = this.specifiedAccess; - this.specifiedAccess = specifiedAccess; - this.getAccessAnnotation().setValue(AccessType.toJavaResourceModel(specifiedAccess)); - this.firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, old, specifiedAccess); - } - - protected void setSpecifiedAccess_(AccessType specifiedAccess) { - AccessType old = this.specifiedAccess; - this.specifiedAccess = specifiedAccess; - this.firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, old, specifiedAccess); - } - - @Override - protected Iterator<JavaResourcePersistentAttribute> resourceAttributes() { - return (this.specifiedAccess == null) - ? super.resourceAttributes() - : this.resourcePersistentType.persistableAttributes(AccessType.toJavaResourceModel(this.specifiedAccess)); - } - - @Override - public void updateAccess() { - super.updateAccess(); - this.setSpecifiedAccess_(this.getResourceAccess()); - } - - protected AccessType getResourceAccess() { - return AccessType.fromJavaResourceModel(this.getAccessAnnotation().getValue()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0.java deleted file mode 100644 index 242ab12a17..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaSequenceGenerator; -import org.eclipse.jpt.core.jpa2.context.SequenceGenerator2_0; -import org.eclipse.jpt.core.jpa2.resource.java.SequenceGenerator2_0Annotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; - -/** - * Generic2_0JavaSequenceGenerator - */ -public class GenericJavaSequenceGenerator2_0 extends AbstractJavaSequenceGenerator - implements SequenceGenerator2_0 -{ - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - public GenericJavaSequenceGenerator2_0(JavaJpaContextNode parent) { - super(parent); - } - - // ********** catalog ********** - - @Override - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.getResourceGenerator().setCatalog(catalog); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - protected void setSpecifiedCatalog_(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - // ********** schema ********** - - @Override - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.getResourceGenerator().setSchema(schema); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - protected void setSpecifiedSchema_(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - // ********** resource => context ********** - - @Override - public void initialize(SequenceGeneratorAnnotation resourceSequenceGenerator) { - super.initialize(resourceSequenceGenerator); - SequenceGenerator2_0Annotation resource = (SequenceGenerator2_0Annotation) resourceSequenceGenerator; - - this.defaultCatalog = this.buildDefaultCatalog(); - this.specifiedCatalog = resource.getCatalog(); - this.defaultSchema = this.buildDefaultSchema(); - this.specifiedSchema = resource.getSchema(); - } - - @Override - public void update(SequenceGeneratorAnnotation resourceSequenceGenerator) { - super.update(resourceSequenceGenerator); - SequenceGenerator2_0Annotation resource = (SequenceGenerator2_0Annotation) resourceSequenceGenerator; - - this.setDefaultCatalog(this.buildDefaultCatalog()); - this.setSpecifiedCatalog_(resource.getCatalog()); - this.setDefaultSchema(this.buildDefaultSchema()); - this.setSpecifiedSchema_(resource.getSchema()); - } - - @Override - protected SequenceGenerator2_0Annotation getResourceGenerator() { - return (SequenceGenerator2_0Annotation) super.getResourceGenerator(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/JavaIdMappingDefinition2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/JavaIdMappingDefinition2_0.java deleted file mode 100644 index 29aa664540..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/JavaIdMappingDefinition2_0.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaIdMappingDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; - -public class JavaIdMappingDefinition2_0 - extends AbstractJavaIdMappingDefinition -{ - // singleton - private static final JavaIdMappingDefinition2_0 INSTANCE = - new JavaIdMappingDefinition2_0(); - - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaIdMappingDefinition2_0() { - super(); - } - - - @Override - public boolean testSpecified(JavaPersistentAttribute persistentAttribute) { - return super.testSpecified(persistentAttribute) && ! testDerivedId(persistentAttribute); - } - - /** - * Return whether the Id annotation, if present, is used as a supporting annotation for - * 1-1 or M-1 mapping, rather than as a primary mapping annotation - */ - protected boolean testDerivedId(JavaPersistentAttribute persistentAttribute) { - JavaResourcePersistentAttribute resourceAttribute = - persistentAttribute.getResourcePersistentAttribute(); - return resourceAttribute.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME) != null - || resourceAttribute.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME) != null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/NullJavaDerivedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/NullJavaDerivedId2_0.java deleted file mode 100644 index 56ae0466d5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/NullJavaDerivedId2_0.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.utility.TextRange; - -public class NullJavaDerivedId2_0 - extends AbstractJavaJpaContextNode - implements JavaDerivedId2_0 -{ - - public NullJavaDerivedId2_0(JavaSingleRelationshipMapping2_0 parent) { - super(parent); - } - - public boolean getValue() { - return false; - } - - public void setValue(boolean newValue) { - throw new UnsupportedOperationException(); - } - - - public void initialize() { - //no-op - } - - public void update() { - //no-op - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/VirtualAssociationOverride2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/VirtualAssociationOverride2_0Annotation.java deleted file mode 100644 index 8ef6bcc0f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/VirtualAssociationOverride2_0Annotation.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import org.eclipse.jpt.core.context.JoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.internal.context.java.VirtualAssociationOverrideAnnotation; -import org.eclipse.jpt.core.internal.resource.java.NullJoinTableAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember.AnnotationInitializer; - -/** - * javax.persistence.AssociationOverride - */ -public final class VirtualAssociationOverride2_0Annotation - extends VirtualAssociationOverrideAnnotation - implements AssociationOverride2_0Annotation -{ - - private final JoinTableAnnotation joinTable; - - public VirtualAssociationOverride2_0Annotation(JavaResourcePersistentMember parent, String name, JoiningStrategy joiningStrategy) { - super(parent, name, joiningStrategy); - this.joinTable = this.buildJoinTable(); - } - - protected JoinTableAnnotation buildJoinTable() { - if (this.joiningStrategy instanceof JoinTableJoiningStrategy) { - return new VirtualAssociationOverrideJoinTableAnnotation(this, ((JoinTableJoiningStrategy)this.joiningStrategy).getJoinTable()); - } - return new NullJoinTableAnnotation(this); - } - - // ***** join table - - public JoinTableAnnotation getJoinTable() { - return this.joinTable; - } - - public JoinTableAnnotation getNonNullJoinTable() { - return this.joinTable; - } - - public JoinTableAnnotation addJoinTable() { - throw new UnsupportedOperationException(); - } - - public void removeJoinTable() { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation addJoinTable(AnnotationInitializer initializer) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/VirtualAssociationOverrideJoinTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/VirtualAssociationOverrideJoinTableAnnotation.java deleted file mode 100644 index 62b0475fd2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/VirtualAssociationOverrideJoinTableAnnotation.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.java; - -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.internal.context.java.VirtualAssociationOverrideJoinColumnAnnotation; -import org.eclipse.jpt.core.internal.resource.java.NullJoinTableAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public final class VirtualAssociationOverrideJoinTableAnnotation extends NullJoinTableAnnotation - implements JoinTableAnnotation -{ - private JoinTable joinTable; //TODO uniqueConstraints - - private final Vector<JoinColumnAnnotation> joinColumns; - - private final Vector<JoinColumnAnnotation> inverseJoinColumns; - - public VirtualAssociationOverrideJoinTableAnnotation(AssociationOverride2_0Annotation parent, JoinTable joinTable) { - super(parent); - this.joinTable = joinTable; - this.joinColumns = this.buildJoinColumns(); - this.inverseJoinColumns = this.buildInverseJoinColumns(); - } - - @Override - protected JoinTableAnnotation addAnnotation() { - throw new UnsupportedOperationException(); - } - - private Vector<JoinColumnAnnotation> buildJoinColumns() { - Vector<JoinColumnAnnotation> result = new Vector<JoinColumnAnnotation>(this.joinTable.joinColumnsSize()); - for (JoinColumn joinColumn : CollectionTools.iterable(this.joinTable.joinColumns())) { - result.add(new VirtualAssociationOverrideJoinColumnAnnotation(this, joinColumn)); - } - return result; - } - - private Vector<JoinColumnAnnotation> buildInverseJoinColumns() { - Vector<JoinColumnAnnotation> result = new Vector<JoinColumnAnnotation>(this.joinTable.inverseJoinColumnsSize()); - for (JoinColumn joinColumn : CollectionTools.iterable(this.joinTable.inverseJoinColumns())) { - result.add(new VirtualAssociationOverrideJoinColumnAnnotation(this, joinColumn)); - } - return result; - } - - @Override - public String getName() { - return this.joinTable.getSpecifiedName(); - } - - @Override - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - @Override - public String getCatalog() { - return this.joinTable.getCatalog(); - } - - @Override - public void setCatalog(String catalog) { - throw new UnsupportedOperationException(); - } - - @Override - public String getSchema() { - return this.joinTable.getSchema(); - } - - @Override - public void setSchema(String schema) { - throw new UnsupportedOperationException(); - } - - // ***** join columns - @Override - public ListIterator<JoinColumnAnnotation> joinColumns() { - return this.joinColumns.listIterator(); - } - - @Override - public JoinColumnAnnotation joinColumnAt(int index) { - return this.joinColumns.elementAt(index); - } - - @Override - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - @Override - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - // ***** inverse join columns - @Override - public ListIterator<JoinColumnAnnotation> inverseJoinColumns() { - return this.inverseJoinColumns.listIterator(); - } - - @Override - public JoinColumnAnnotation inverseJoinColumnAt(int index) { - return this.inverseJoinColumns.elementAt(index); - } - - @Override - public int indexOfInverseJoinColumn(JoinColumnAnnotation joinColumn) { - return this.inverseJoinColumns.indexOf(joinColumn); - } - - @Override - public int inverseJoinColumnsSize() { - return this.inverseJoinColumns.size(); - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmAssociationOverrideRelationshipReference2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmAssociationOverrideRelationshipReference2_0.java deleted file mode 100644 index e99b72734d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmAssociationOverrideRelationshipReference2_0.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.AssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.AssociationOverrideRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmAssociationOverrideRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmJoinTableInAssociationOverrideJoiningStrategy2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlAssociationOverride; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmAssociationOverrideRelationshipReference2_0 extends AbstractOrmAssociationOverrideRelationshipReference - implements OrmAssociationOverrideRelationshipReference2_0 -{ - - protected OrmJoinTableInAssociationOverrideJoiningStrategy2_0 joinTableJoiningStrategy; - - // cache the strategy for property change notification - protected JoiningStrategy cachedPredominantJoiningStrategy; - - public GenericOrmAssociationOverrideRelationshipReference2_0(OrmAssociationOverride parent, XmlAssociationOverride xao) { - super(parent, xao); - } - - protected OrmJoinTableInAssociationOverrideJoiningStrategy2_0 buildJoinTableJoiningStrategy(XmlAssociationOverride xao) { - return new GenericOrmJoinTableInAssociationOverrideJoiningStrategy2_0(this, xao); - } - - @Override - public void initializeFrom(AssociationOverrideRelationshipReference oldAssociationOverride) { - if (oldAssociationOverride.getJoinColumnJoiningStrategy().hasSpecifiedJoinColumns()) { - getJoinColumnJoiningStrategy().initializeFrom(oldAssociationOverride.getJoinColumnJoiningStrategy()); - } - else { - getJoinTableJoiningStrategy().initializeFrom(((AssociationOverrideRelationshipReference2_0) oldAssociationOverride).getJoinTableJoiningStrategy()); - } - } - - @Override - protected void initializeJoiningStrategies(org.eclipse.jpt.core.resource.orm.XmlAssociationOverride xao) { - super.initializeJoiningStrategies(xao); - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy((XmlAssociationOverride) xao); - } - - @Override - protected void updateJoiningStrategies(org.eclipse.jpt.core.resource.orm.XmlAssociationOverride xao) { - super.updateJoiningStrategies(xao); - this.joinTableJoiningStrategy.update((XmlAssociationOverride) xao); - } - - @Override - protected JoiningStrategy calculatePredominantJoiningStrategy() { - if (this.joinColumnJoiningStrategy.hasSpecifiedJoinColumns()) { - return this.joinColumnJoiningStrategy; - } - return this.joinTableJoiningStrategy; - } - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); -// if (this.connectionProfileIsActive()) { -// this.validateJoinTable(messages, astRoot); -// } - } - - - - // **************** join table ******************************************* - - - public OrmJoinTableInAssociationOverrideJoiningStrategy2_0 getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public void setJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.addStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public void unsetJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return getAssociationOverride().isVirtual(); - } - - @Override - public void setJoinColumnJoiningStrategy() { - super.setJoinColumnJoiningStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmDerivedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmDerivedId2_0.java deleted file mode 100644 index 30aa0645b8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmDerivedId2_0.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlDerivedId; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmDerivedId2_0 - extends AbstractOrmXmlContextNode - implements OrmDerivedId2_0 -{ - protected XmlDerivedId resource; - - protected boolean value; - - - public GenericOrmDerivedId2_0(OrmSingleRelationshipMapping2_0 parent, XmlDerivedId resource) { - super(parent); - this.resource = resource; - this.value = getResourceToContextValue(); - } - - - @Override - public OrmSingleRelationshipMapping2_0 getParent() { - return (OrmSingleRelationshipMapping2_0) super.getParent(); - } - - public boolean getValue() { - return this.value; - } - - public void setValue(boolean newValue) { - boolean oldValue = this.value; - this.value = newValue; - this.resource.setId(getContextToResourceValue()); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - protected void setValue_(boolean newValue) { - boolean oldValue = this.value; - this.value = newValue; - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - public void update() { - setValue_(getResourceToContextValue()); - } - - protected boolean getResourceToContextValue() { - return (resource.getId() == null) ? false : resource.getId().booleanValue(); - } - - protected Boolean getContextToResourceValue() { - return (this.value) ? Boolean.TRUE : null; - } - - public TextRange getValidationTextRange() { - return this.resource.getDerivedIdTextRange(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - // no validation rules - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmEmbeddable2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmEmbeddable2_0.java deleted file mode 100644 index 9380b5a504..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmEmbeddable2_0.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEmbeddable; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaEmbeddable2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.utility.internal.ArrayTools; - - -public class GenericOrmEmbeddable2_0 - extends AbstractOrmEmbeddable -{ - public GenericOrmEmbeddable2_0(OrmPersistentType parent, XmlEmbeddable resourceMapping) { - super(parent, resourceMapping); - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return ArrayTools.contains(GenericJavaEmbeddable2_0.ALLOWED_ATTRIBUTE_MAPPING_KEYS, attributeMappingKey); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmJoinTableInAssociationOverrideJoiningStrategy2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmJoinTableInAssociationOverrideJoiningStrategy2_0.java deleted file mode 100644 index 7d38c2ea01..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmJoinTableInAssociationOverrideJoiningStrategy2_0.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.jpa2.context.orm.OrmAssociationOverrideRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmJoinTableInAssociationOverrideJoiningStrategy2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmJoinTableInAssociationOverrideJoiningStrategy2_0 - extends AbstractOrmJoinTableJoiningStrategy - implements OrmJoinTableInAssociationOverrideJoiningStrategy2_0 -{ - protected transient XmlAssociationOverride resourceAssociationOverride; - - public GenericOrmJoinTableInAssociationOverrideJoiningStrategy2_0(OrmAssociationOverrideRelationshipReference2_0 parent, XmlAssociationOverride xao) { - super(parent); - this.resourceAssociationOverride = xao; - this.initialize(); - } - - public boolean isOverridableAssociation() { - return false; - } - - @Override - public OrmAssociationOverrideRelationshipReference2_0 getRelationshipReference() { - return (OrmAssociationOverrideRelationshipReference2_0) super.getRelationshipReference(); - } - - // **************** join table ********************************************* - - @Override - protected void setResourceJoinTable(XmlJoinTable resourceJoinTable) { - this.resourceAssociationOverride.setJoinTable(resourceJoinTable); - } - - public XmlJoinTable getResourceJoinTable() { - return this.resourceAssociationOverride.getJoinTable(); - } - - public void removeResourceJoinTable() { - this.resourceAssociationOverride.setJoinTable(null); - } - - public void update(XmlAssociationOverride resourceAssociationOverride) { - this.resourceAssociationOverride = resourceAssociationOverride; - super.update(); - } - - public TextRange getValidationTextRange() { - return this.resourceAssociationOverride.getValidationTextRange(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0.java deleted file mode 100644 index c4bfc6940a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.XmlAccessHolder; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; - - -public class GenericOrmPersistentAttribute2_0 - extends AbstractOrmPersistentAttribute -{ - - protected AccessType specifiedAccess; - - public GenericOrmPersistentAttribute2_0(OrmPersistentType parent, Owner owner, XmlAttributeMapping resourceMapping) { - super(parent, owner, resourceMapping); - this.specifiedAccess = getResourceAccess(); - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - public void setSpecifiedAccess(AccessType newSpecifiedAccess) { - AccessType oldAccess = this.specifiedAccess; - this.specifiedAccess = newSpecifiedAccess; - ((XmlAccessHolder) this.getResourceAttributeMapping()).setAccess(AccessType.toOrmResourceModel(newSpecifiedAccess)); - firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, oldAccess, newSpecifiedAccess); - } - - protected void setSpecifiedAccess_(AccessType newSpecifiedAccess) { - AccessType oldAccess = this.specifiedAccess; - this.specifiedAccess = newSpecifiedAccess; - firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, oldAccess, newSpecifiedAccess); - } - - @Override - public void update() { - super.update(); - setSpecifiedAccess_(getResourceAccess()); - } - - protected AccessType getResourceAccess() { - return AccessType.fromOrmResourceModel(((XmlAccessHolder) getResourceAttributeMapping()).getAccess()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0.java deleted file mode 100644 index 8ff54b3a8b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmSequenceGenerator; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSequenceGenerator2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlSequenceGenerator; - -/** - * Generic2_0OrmSequenceGenerator - */ -public class GenericOrmSequenceGenerator2_0 extends AbstractOrmSequenceGenerator - implements OrmSequenceGenerator2_0 -{ - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - public GenericOrmSequenceGenerator2_0(XmlContextNode parent, XmlSequenceGenerator resourceSequenceGenerator) { - super(parent, resourceSequenceGenerator); - } - - // ********** catalog ********** - - @Override - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.getResourceGenerator().setCatalog(catalog); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - protected void setSpecifiedCatalog_(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - protected String buildDefaultCatalog() { - return this.getContextDefaultCatalog(); - } - - // ********** schema ********** - - @Override - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.getResourceGenerator().setSchema(schema); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - protected void setSpecifiedSchema_(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - protected String buildDefaultSchema() { - return this.getContextDefaultSchema(); - } - - // ********** resource => context ********** - - @Override - protected void initialize(org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator xmlResource) { - super.initialize(xmlResource); - XmlSequenceGenerator xmlResource2_0 = (XmlSequenceGenerator) xmlResource; - - this.defaultCatalog = this.buildDefaultCatalog(); - this.specifiedCatalog = xmlResource2_0.getCatalog(); - this.defaultSchema = this.buildDefaultSchema(); - this.specifiedSchema = xmlResource2_0.getSchema(); - } - - @Override - public void update(org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator xmlResource) { - super.update(xmlResource); - XmlSequenceGenerator xmlResource2_0 = (XmlSequenceGenerator) xmlResource; - - this.setDefaultCatalog(this.buildDefaultCatalog()); - this.setSpecifiedCatalog_(xmlResource2_0.getCatalog()); - this.setDefaultSchema(this.buildDefaultSchema()); - this.setSpecifiedSchema_(xmlResource2_0.getSchema()); - } - - @Override - protected XmlSequenceGenerator getResourceGenerator() { - return (XmlSequenceGenerator) super.getResourceGenerator(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0ContextNodeFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0ContextNodeFactory.java deleted file mode 100644 index 3d4dd25d61..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0ContextNodeFactory.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer.Owner; -import org.eclipse.jpt.core.internal.AbstractOrmXmlContextNodeFactory; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAssociationOverrideContainer; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlBasic; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlDerivedId; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlId; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlTransient; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverrideContainer; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; - -public class GenericOrmXml2_0ContextNodeFactory extends AbstractOrmXmlContextNodeFactory -{ - - @Override - public OrmEmbeddable buildOrmEmbeddable(OrmPersistentType parent, org.eclipse.jpt.core.resource.orm.XmlEmbeddable resourceMapping) { - return new GenericOrmEmbeddable2_0(parent, (XmlEmbeddable) resourceMapping); - } - - @Override - public OrmPersistentAttribute buildOrmPersistentAttribute(OrmPersistentType parent, OrmPersistentAttribute.Owner owner, org.eclipse.jpt.core.resource.orm.XmlAttributeMapping resourceMapping) { - return new GenericOrmPersistentAttribute2_0(parent, owner, resourceMapping); - } - - @Override - public OrmAssociationOverrideRelationshipReference buildOrmAssociationOverrideRelationshipReference(OrmAssociationOverride parent, org.eclipse.jpt.core.resource.orm.XmlAssociationOverride associationOverride) { - return new GenericOrmAssociationOverrideRelationshipReference2_0(parent, (XmlAssociationOverride) associationOverride); - } - - @Override - public OrmSequenceGenerator buildOrmSequenceGenerator(XmlContextNode parent, org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator resourceSequenceGenerator) { - return new GenericOrmSequenceGenerator2_0(parent, (XmlSequenceGenerator) resourceSequenceGenerator); - } - - @Override - public OrmDerivedId2_0 buildOrmDerivedId(OrmSingleRelationshipMapping2_0 parent, XmlDerivedId resource) { - return new GenericOrmDerivedId2_0(parent, resource); - } - - @Override - public OrmAssociationOverrideContainer buildOrmAssociationOverrideContainer(OrmEmbeddedMapping2_0 parent, Owner owner, XmlAssociationOverrideContainer resourceAssociationOverrideContainer) { - return new GenericOrmAssociationOverrideContainer(parent, owner, resourceAssociationOverrideContainer); - } - - - // ********** ORM Virtual Resource Model ********** - - @Override - public XmlAssociationOverride buildVirtualXmlAssociationOverride(String name, OrmTypeMapping parent, JoiningStrategy joiningStrategy) { - return new VirtualXmlAssociationOverride2_0(name, parent, joiningStrategy); - } - - @Override - public XmlBasic buildVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { - return new VirtualXmlBasic2_0(ormTypeMapping, javaBasicMapping); - } - - @Override - public XmlId buildVirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { - return new VirtualXmlId2_0(ormTypeMapping, javaIdMapping); - } - - @Override - public XmlEmbeddedId buildVirtualXmlEmbeddedId(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - return new VirtualXmlEmbeddedId2_0(ormTypeMapping, javaEmbeddedIdMapping); - } - - @Override - public XmlEmbedded buildVirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { - return new VirtualXmlEmbedded2_0(ormTypeMapping, javaEmbeddedMapping); - } - - @Override - public XmlManyToMany buildVirtualXmlManyToMany(OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { - return new VirtualXmlManyToMany2_0(ormTypeMapping, javaManyToManyMapping); - } - - @Override - public XmlManyToOne buildVirtualXmlManyToOne(OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { - return new VirtualXmlManyToOne2_0(ormTypeMapping, (JavaManyToOneMapping2_0) javaManyToOneMapping); - } - - @Override - public XmlOneToMany buildVirtualXmlOneToMany(OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { - return new VirtualXmlOneToMany2_0(ormTypeMapping, javaOneToManyMapping); - } - - @Override - public XmlOneToOne buildVirtualXmlOneToOne(OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { - return new VirtualXmlOneToOne2_0(ormTypeMapping, (JavaOneToOneMapping2_0) javaOneToOneMapping); - } - - @Override - public XmlTransient buildVirtualXmlTransient(OrmTypeMapping ormTypeMapping, JavaTransientMapping javaTransientMapping) { - return new VirtualXmlTransient2_0(ormTypeMapping, javaTransientMapping); - } - - @Override - public XmlVersion buildVirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { - return new VirtualXmlVersion2_0(ormTypeMapping, javaVersionMapping); - } - - @Override - public XmlNullAttributeMapping buildVirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - return new VirtualXmlNullAttributeMapping2_0(ormTypeMapping, javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0Definition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0Definition.java deleted file mode 100644 index 93582e2868..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmXml2_0Definition.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.NullOrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.context.orm.OrmXmlDefinition; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmBasicMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddableDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddedIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddedMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmEntityDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmManyToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmManyToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmMappedSuperclassDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmOneToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmOneToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmTransientMappingDefinition; -import org.eclipse.jpt.core.internal.context.orm.OrmVersionMappingDefinition; -import org.eclipse.jpt.core.jpa2.resource.orm.Orm2_0Factory; - -public class GenericOrmXml2_0Definition - extends AbstractOrmXmlDefinition -{ - // singleton - private static final OrmXmlDefinition INSTANCE = - new GenericOrmXml2_0Definition(); - - - /** - * Return the singleton - */ - public static OrmXmlDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private GenericOrmXml2_0Definition() { - super(); - } - - - public EFactory getResourceNodeFactory() { - return Orm2_0Factory.eINSTANCE; - } - - @Override - protected OrmXmlContextNodeFactory buildContextNodeFactory() { - return new GenericOrmXml2_0ContextNodeFactory(); - } - - public IContentType getContentType() { - return JptCorePlugin.ORM2_0_XML_CONTENT_TYPE; - } - - - // ********** ORM type mappings ********** - - @Override - protected OrmTypeMappingDefinition[] buildOrmTypeMappingDefinitions() { - // order should not matter here, but we'll use the same order as for java - // (@see {@link Generic2_0JpaPlatformProvider}) - return new OrmTypeMappingDefinition[] { - OrmEntityDefinition.instance(), - OrmEmbeddableDefinition.instance(), - OrmMappedSuperclassDefinition.instance()}; - } - - - // ********** ORM attribute mappings ********** - - @Override - protected OrmAttributeMappingDefinition[] buildOrmAttributeMappingDefinitions() { - // order should not matter here, but we'll use the same order as for java - // (@see {@link Generic2_0JpaPlatformProvider}) - return new OrmAttributeMappingDefinition[] { - OrmTransientMappingDefinition.instance(), - //OrmElementCollectionMappingProvider.instance(), - OrmIdMappingDefinition.instance(), - OrmVersionMappingDefinition.instance(), - OrmBasicMappingDefinition.instance(), - OrmEmbeddedMappingDefinition.instance(), - OrmEmbeddedIdMappingDefinition.instance(), - OrmManyToManyMappingDefinition.instance(), - OrmManyToOneMappingDefinition.instance(), - OrmOneToManyMappingDefinition.instance(), - OrmOneToOneMappingDefinition.instance(), - NullOrmAttributeMappingDefinition.instance()}; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/NullOrmDerivedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/NullOrmDerivedId2_0.java deleted file mode 100644 index e8e05bee85..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/NullOrmDerivedId2_0.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedId2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.utility.TextRange; - -public class NullOrmDerivedId2_0 - extends AbstractOrmXmlContextNode - implements OrmDerivedId2_0 -{ - - public NullOrmDerivedId2_0(OrmSingleRelationshipMapping2_0 parent) { - super(parent); - } - - public boolean getValue() { - return false; - } - - public void setValue(boolean newValue) { - //no-op - setValue is called when morphing a mapping, we can't throw an UnsupportedOperationException - } - - public void update() { - //no-op - } - - public TextRange getValidationTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlAssociationOverride2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlAssociationOverride2_0.java deleted file mode 100644 index 37c4f20ba3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlAssociationOverride2_0.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c)2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.JoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlAssociationOverride; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlJoinTable; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; - -public class VirtualXmlAssociationOverride2_0 extends XmlAssociationOverride -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JoiningStrategy joiningStrategy; - - protected final VirtualXmlAssociationOverride virtualXmlAssociationOverride; - - public VirtualXmlAssociationOverride2_0(String name, OrmTypeMapping ormTypeMapping, JoiningStrategy joiningStrategy) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.joiningStrategy = joiningStrategy; - this.virtualXmlAssociationOverride = new VirtualXmlAssociationOverride(name, ormTypeMapping, joiningStrategy); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getName() { - return this.virtualXmlAssociationOverride.getName(); - } - - @Override - public void setName(String value) { - this.virtualXmlAssociationOverride.setName(value); - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - return this.virtualXmlAssociationOverride.getJoinColumns(); - } - - @Override - public XmlJoinTable getJoinTable() { - if (this.joiningStrategy instanceof JoinTableJoiningStrategy) { - JoinTable joinTable = ((JoinTableJoiningStrategy) this.joiningStrategy).getJoinTable(); - if (joinTable != null) { - return new VirtualXmlJoinTable( - this.ormTypeMapping, - joinTable); - } - } - return null; - } - - @Override - public void setJoinTable(XmlJoinTable newJoinTable) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlBasic2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlBasic2_0.java deleted file mode 100644 index 20b042d8fc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlBasic2_0.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlBasic; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.AccessType; -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.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 VirtualXmlBasic2_0 extends XmlBasic -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaBasicMapping javaAttributeMapping; - - protected final VirtualXmlBasic virtualXmlBasic; - - public VirtualXmlBasic2_0(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaBasicMapping; - this.virtualXmlBasic = new VirtualXmlBasic(ormTypeMapping, javaBasicMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlBasic.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlBasic.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlBasic.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlBasic.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.virtualXmlBasic.getColumn(); - } - - @Override - public void setColumn(XmlColumn value) { - this.virtualXmlBasic.setColumn(value); - } - - @Override - public FetchType getFetch() { - return this.virtualXmlBasic.getFetch(); - } - - @Override - public void setFetch(FetchType newFetch) { - this.virtualXmlBasic.setFetch(newFetch); - } - - @Override - public Boolean getOptional() { - return this.virtualXmlBasic.getOptional(); - } - - @Override - public void setOptional(Boolean newOptional) { - this.virtualXmlBasic.setOptional(newOptional); - } - - @Override - public boolean isLob() { - return this.virtualXmlBasic.isLob(); - } - - @Override - public void setLob(boolean newLob) { - this.virtualXmlBasic.setLob(newLob); - } - - @Override - public TextRange getLobTextRange() { - return this.virtualXmlBasic.getLobTextRange(); - } - - @Override - public TemporalType getTemporal() { - return this.virtualXmlBasic.getTemporal(); - } - - @Override - public void setTemporal(TemporalType setTemporal){ - this.virtualXmlBasic.setTemporal(setTemporal); - } - - @Override - public TextRange getTemporalTextRange() { - return this.virtualXmlBasic.getTemporalTextRange(); - } - - @Override - public EnumType getEnumerated() { - return this.virtualXmlBasic.getEnumerated(); - } - - @Override - public void setEnumerated(EnumType setEnumerated) { - this.virtualXmlBasic.setEnumerated(setEnumerated); - } - - @Override - public TextRange getEnumeratedTextRange() { - return null; - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlEmbedded2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlEmbedded2_0.java deleted file mode 100644 index 769f0fa635..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlEmbedded2_0.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlEmbedded; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -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 VirtualXmlEmbedded2_0 extends XmlEmbedded -{ - - protected OrmTypeMapping ormTypeMapping; - - protected final JavaEmbeddedMapping javaAttributeMapping; - - protected final VirtualXmlEmbedded virtualXmlEmbedded; - - public VirtualXmlEmbedded2_0(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaEmbeddedMapping; - this.virtualXmlEmbedded = new VirtualXmlEmbedded(ormTypeMapping, javaEmbeddedMapping); - } - - @Override - public String getMappingKey() { - return this.virtualXmlEmbedded.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlEmbedded.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlEmbedded.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlEmbedded.getNameTextRange(); - } - - @Override - public EList<XmlAttributeOverride> getAttributeOverrides() { - return this.virtualXmlEmbedded.getAttributeOverrides(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlEmbeddedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlEmbeddedId2_0.java deleted file mode 100644 index 500135c556..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlEmbeddedId2_0.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlEmbeddedId; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -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 VirtualXmlEmbeddedId2_0 extends XmlEmbeddedId -{ - - protected OrmTypeMapping ormTypeMapping; - - protected final JavaEmbeddedIdMapping javaAttributeMapping; - - protected final VirtualXmlEmbeddedId virtualXmlEmbeddedId; - - public VirtualXmlEmbeddedId2_0(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaEmbeddedIdMapping; - this.virtualXmlEmbeddedId = new VirtualXmlEmbeddedId(ormTypeMapping, javaEmbeddedIdMapping); - } - - @Override - public String getMappingKey() { - return this.virtualXmlEmbeddedId.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlEmbeddedId.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlEmbeddedId.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlEmbeddedId.getNameTextRange(); - } - - @Override - public EList<XmlAttributeOverride> getAttributeOverrides() { - return this.virtualXmlEmbeddedId.getAttributeOverrides(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlId2_0.java deleted file mode 100644 index bad130a966..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlId2_0.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlId; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -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 VirtualXmlId2_0 extends XmlId -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaIdMapping javaAttributeMapping; - - protected final VirtualXmlId virtualXmlId; - - protected final VirtualXmlSequenceGenerator2_0 virtualSequenceGenerator; - - public VirtualXmlId2_0(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaIdMapping; - this.virtualXmlId = new VirtualXmlId(ormTypeMapping, javaIdMapping); - this.virtualSequenceGenerator = new VirtualXmlSequenceGenerator2_0(javaIdMapping.getGeneratorContainer(), this.isOrmMetadataComplete()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlId.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlId.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlId.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlId.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.virtualXmlId.getColumn(); - } - - @Override - public void setColumn(XmlColumn value) { - this.virtualXmlId.setColumn(value); - } - - @Override - public TemporalType getTemporal() { - return this.virtualXmlId.getTemporal(); - } - - @Override - public void setTemporal(TemporalType newTemporal){ - this.virtualXmlId.setTemporal(newTemporal); - } - - @Override - public TextRange getTemporalTextRange() { - return this.virtualXmlId.getTemporalTextRange(); - } - - @Override - public XmlGeneratedValue getGeneratedValue() { - return this.virtualXmlId.getGeneratedValue(); - } - - @Override - public void setGeneratedValue(XmlGeneratedValue value) { - this.virtualXmlId.setGeneratedValue(value); - } - - @Override - public XmlSequenceGenerator getSequenceGenerator() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getGeneratorContainer().getSequenceGenerator() != null) { - return this.virtualSequenceGenerator; - } - return null; - } - - @Override - public void setSequenceGenerator(XmlSequenceGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlTableGenerator getTableGenerator() { - return this.virtualXmlId.getTableGenerator(); - } - - @Override - public void setTableGenerator(XmlTableGenerator value) { - this.virtualXmlId.setTableGenerator(value); - } - - @Override - public EnumType getEnumerated() { - return this.virtualXmlId.getEnumerated(); - } - - @Override - public void setEnumerated(EnumType value) { - this.virtualXmlId.setEnumerated(value); - } - - @Override - public TextRange getEnumeratedTextRange() { - return this.virtualXmlId.getEnumeratedTextRange(); - } - - @Override - public boolean isLob() { - return this.virtualXmlId.isLob(); - } - - @Override - public void setLob(boolean value) { - this.virtualXmlId.setLob(value); - } - - @Override - public TextRange getLobTextRange() { - return this.virtualXmlId.getLobTextRange(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java deleted file mode 100644 index a67bf11ae5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlManyToMany; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.AccessType; -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.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 VirtualXmlManyToMany2_0 extends XmlManyToMany -{ - - protected OrmTypeMapping ormTypeMapping; - - protected final JavaManyToManyMapping javaAttributeMapping; - - protected final VirtualXmlManyToMany virtualXmlManyToMany; - - public VirtualXmlManyToMany2_0(OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaManyToManyMapping; - this.virtualXmlManyToMany = new VirtualXmlManyToMany(ormTypeMapping, javaManyToManyMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlManyToMany.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlManyToMany.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlManyToMany.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlManyToMany.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - return this.virtualXmlManyToMany.getFetch(); - } - - @Override - public void setFetch(FetchType newFetch) { - this.virtualXmlManyToMany.setFetch(newFetch); - } - - public EList<XmlJoinColumn> getJoinColumns() { - return this.virtualXmlManyToMany.getJoinColumns(); - } - - @Override - public CascadeType getCascade() { - return this.virtualXmlManyToMany.getCascade(); - } - - @Override - public void setCascade(CascadeType value) { - this.virtualXmlManyToMany.setCascade(value); - } - - @Override - public XmlJoinTable getJoinTable() { - return this.virtualXmlManyToMany.getJoinTable(); - } - - @Override - public void setJoinTable(XmlJoinTable value) { - this.virtualXmlManyToMany.setJoinTable(value); - } - - @Override - public String getTargetEntity() { - return this.virtualXmlManyToMany.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - this.virtualXmlManyToMany.setTargetEntity(value); - } - - @Override - public String getMappedBy() { - return this.virtualXmlManyToMany.getMappedBy(); - } - - @Override - public void setMappedBy(String value) { - this.virtualXmlManyToMany.setMappedBy(value); - } - - - @Override - public MapKey getMapKey() { - return this.virtualXmlManyToMany.getMapKey(); - } - - @Override - public void setMapKey(MapKey value) { - this.virtualXmlManyToMany.setMapKey(value); - } - - @Override - public String getOrderBy() { - return this.virtualXmlManyToMany.getOrderBy(); - } - - @Override - public void setOrderBy(String value) { - this.virtualXmlManyToMany.setOrderBy(value); - } - - @Override - public TextRange getMappedByTextRange() { - return this.virtualXmlManyToMany.getMappedByTextRange(); - } - - @Override - public TextRange getTargetEntityTextRange() { - return this.virtualXmlManyToMany.getTargetEntityTextRange(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java deleted file mode 100644 index b2e7ff0aef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlManyToOne; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlManyToOne2_0 extends XmlManyToOne -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaManyToOneMapping2_0 javaAttributeMapping; - - protected final VirtualXmlManyToOne virtualXmlManyToOne; - - - public VirtualXmlManyToOne2_0( - OrmTypeMapping ormTypeMapping, - JavaManyToOneMapping2_0 javaManyToOneMapping) { - - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaManyToOneMapping; - this.virtualXmlManyToOne = new VirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlManyToOne.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlManyToOne.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlManyToOne.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlManyToOne.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - return this.virtualXmlManyToOne.getFetch(); - } - - @Override - public void setFetch(FetchType newFetch) { - this.virtualXmlManyToOne.setFetch(newFetch); - } - - @Override - public Boolean getOptional() { - return this.virtualXmlManyToOne.getOptional(); - } - - @Override - public void setOptional(Boolean newOptional) { - this.virtualXmlManyToOne.setOptional(newOptional); - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - return this.virtualXmlManyToOne.getJoinColumns(); - } - - @Override - public CascadeType getCascade() { - return this.virtualXmlManyToOne.getCascade(); - } - - @Override - public void setCascade(CascadeType value) { - this.virtualXmlManyToOne.setCascade(value); - } - - @Override - public XmlJoinTable getJoinTable() { - return this.virtualXmlManyToOne.getJoinTable(); - } - - @Override - public void setJoinTable(XmlJoinTable value) { - this.virtualXmlManyToOne.setJoinTable(value); - } - - @Override - public String getTargetEntity() { - return this.virtualXmlManyToOne.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - this.virtualXmlManyToOne.setTargetEntity(value); - } - - @Override - public TextRange getTargetEntityTextRange() { - return this.virtualXmlManyToOne.getTargetEntityTextRange(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getId() { - if (isOrmMetadataComplete()) { - return null; - } - boolean javaIdValue = this.javaAttributeMapping.getDerivedId().getValue(); - return (javaIdValue) ? Boolean.TRUE : null; - } - - @Override - public void setId(Boolean newId) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlNullAttributeMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlNullAttributeMapping2_0.java deleted file mode 100644 index 280ab40c06..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlNullAttributeMapping2_0.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlNullAttributeMapping; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.AccessType; -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 VirtualXmlNullAttributeMapping2_0 extends XmlNullAttributeMapping implements XmlAttributeMapping -{ - - protected OrmTypeMapping ormTypeMapping; - - protected final JavaAttributeMapping javaAttributeMapping; - - protected final VirtualXmlNullAttributeMapping virtualXmlNullAttributeMapping; - - public VirtualXmlNullAttributeMapping2_0(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaAttributeMapping; - this.virtualXmlNullAttributeMapping = new VirtualXmlNullAttributeMapping(ormTypeMapping, javaAttributeMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - public String getMappingKey() { - return this.virtualXmlNullAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlNullAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlNullAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlNullAttributeMapping.getNameTextRange(); - } - - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java deleted file mode 100644 index dc48306400..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlOneToMany; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.AccessType; -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.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 VirtualXmlOneToMany2_0 extends XmlOneToMany -{ - - protected OrmTypeMapping ormTypeMapping; - - protected final JavaOneToManyMapping javaAttributeMapping; - - protected final VirtualXmlOneToMany virtualXmlOneToMany; - - public VirtualXmlOneToMany2_0( - OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaOneToManyMapping; - this.virtualXmlOneToMany = new VirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlOneToMany.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlOneToMany.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlOneToMany.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlOneToMany.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - return this.virtualXmlOneToMany.getFetch(); - } - - @Override - public void setFetch(FetchType newFetch) { - this.virtualXmlOneToMany.setFetch(newFetch); - } - - @Override - public CascadeType getCascade() { - return this.virtualXmlOneToMany.getCascade(); - } - - @Override - public void setCascade(CascadeType value) { - this.virtualXmlOneToMany.setCascade(value); - } - - @Override - public XmlJoinTable getJoinTable() { - return this.virtualXmlOneToMany.getJoinTable(); - } - - @Override - public void setJoinTable(XmlJoinTable value) { - this.virtualXmlOneToMany.setJoinTable(value); - } - - @Override - public String getTargetEntity() { - return this.virtualXmlOneToMany.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - this.virtualXmlOneToMany.setTargetEntity(value); - } - - @Override - public String getMappedBy() { - return this.virtualXmlOneToMany.getMappedBy(); - } - - @Override - public void setMappedBy(String value) { - this.virtualXmlOneToMany.setMappedBy(value); - } - - - @Override - public MapKey getMapKey() { - return this.virtualXmlOneToMany.getMapKey(); - } - - @Override - public void setMapKey(MapKey value) { - this.virtualXmlOneToMany.setMapKey(value); - } - - @Override - public String getOrderBy() { - return this.virtualXmlOneToMany.getOrderBy(); - } - - @Override - public void setOrderBy(String value) { - this.virtualXmlOneToMany.setOrderBy(value); - } - - @Override - public TextRange getMappedByTextRange() { - return this.virtualXmlOneToMany.getMappedByTextRange(); - } - - @Override - public TextRange getTargetEntityTextRange() { - return this.virtualXmlOneToMany.getTargetEntityTextRange(); - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - return this.virtualXmlOneToMany.getJoinColumns(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java deleted file mode 100644 index 308dc4fb21..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlOneToOne; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlOneToOne2_0 extends XmlOneToOne -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaOneToOneMapping2_0 javaAttributeMapping; - - protected final VirtualXmlOneToOne virtualXmlOneToOne; - - - public VirtualXmlOneToOne2_0( - OrmTypeMapping ormTypeMapping, - JavaOneToOneMapping2_0 javaOneToOneMapping) { - - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaOneToOneMapping; - this.virtualXmlOneToOne = new VirtualXmlOneToOne(ormTypeMapping, javaOneToOneMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlOneToOne.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlOneToOne.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlOneToOne.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlOneToOne.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - return this.virtualXmlOneToOne.getFetch(); - } - - @Override - public void setFetch(FetchType newFetch) { - this.virtualXmlOneToOne.setFetch(newFetch); - } - - @Override - public Boolean getOptional() { - return this.virtualXmlOneToOne.getOptional(); - } - - @Override - public void setOptional(Boolean newOptional) { - this.virtualXmlOneToOne.setOptional(newOptional); - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - return this.virtualXmlOneToOne.getJoinColumns(); - } - - @Override - public CascadeType getCascade() { - return this.virtualXmlOneToOne.getCascade(); - } - - @Override - public void setCascade(CascadeType value) { - this.virtualXmlOneToOne.setCascade(value); - } - - @Override - public XmlJoinTable getJoinTable() { - return this.virtualXmlOneToOne.getJoinTable(); - } - - @Override - public void setJoinTable(XmlJoinTable value) { - this.virtualXmlOneToOne.setJoinTable(value); - } - - @Override - public String getTargetEntity() { - return this.virtualXmlOneToOne.getTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - this.virtualXmlOneToOne.setTargetEntity(value); - } - - @Override - public String getMappedBy() { - return this.virtualXmlOneToOne.getMappedBy(); - } - - @Override - public void setMappedBy(String value) { - this.virtualXmlOneToOne.setMappedBy(value); - } - - @Override - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - return this.virtualXmlOneToOne.getPrimaryKeyJoinColumns(); - } - - @Override - public TextRange getMappedByTextRange() { - return this.virtualXmlOneToOne.getMappedByTextRange(); - } - - @Override - public TextRange getTargetEntityTextRange() { - return this.virtualXmlOneToOne.getTargetEntityTextRange(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getId() { - if (isOrmMetadataComplete()) { - return null; - } - boolean javaIdValue = this.javaAttributeMapping.getDerivedId().getValue(); - return (javaIdValue) ? Boolean.TRUE : null; - } - - @Override - public void setId(Boolean newId) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlSequenceGenerator2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlSequenceGenerator2_0.java deleted file mode 100644 index 945516ab7d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlSequenceGenerator2_0.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlSequenceGenerator; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaSequenceGenerator2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * Generic2_0VirtualXmlSequenceGenerator - */ -public class VirtualXmlSequenceGenerator2_0 extends XmlSequenceGenerator -{ - protected final JavaGeneratorContainer javaGeneratorHolder; - - protected final boolean metadataComplete; - - protected final VirtualXmlSequenceGenerator virtualXmlSequenceGenerator; - - public VirtualXmlSequenceGenerator2_0(JavaGeneratorContainer javaGeneratorHolder, boolean metadataComplete) { - super(); - this.javaGeneratorHolder = javaGeneratorHolder; - this.metadataComplete = metadataComplete; - this.virtualXmlSequenceGenerator = new VirtualXmlSequenceGenerator(javaGeneratorHolder, metadataComplete); - } - - protected JavaSequenceGenerator getJavaSequenceGenerator() { - return this.javaGeneratorHolder.getSequenceGenerator(); - } - - @Override - public String getCatalog() { - return ((GenericJavaSequenceGenerator2_0)this.getJavaSequenceGenerator()).getCatalog(); - } - - @Override - public void setCatalog(String newCatalog) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getSchema() { - return ((GenericJavaSequenceGenerator2_0)this.getJavaSequenceGenerator()).getSchema(); - } - - @Override - public void setSchema(String newSchema) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getAllocationSize() { - return this.virtualXmlSequenceGenerator.getAllocationSize(); - } - - @Override - public void setAllocationSize(Integer newAllocationSize) { - this.virtualXmlSequenceGenerator.setAllocationSize(newAllocationSize); - } - - @Override - public Integer getInitialValue() { - return this.virtualXmlSequenceGenerator.getInitialValue(); - } - - @Override - public void setInitialValue(Integer newInitialValue) { - this.virtualXmlSequenceGenerator.setInitialValue(newInitialValue); - } - - @Override - public String getName() { - return this.virtualXmlSequenceGenerator.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlSequenceGenerator.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlSequenceGenerator.getNameTextRange(); - } - - @Override - public String getSequenceName() { - return this.virtualXmlSequenceGenerator.getSequenceName(); - } - - @Override - public void setSequenceName(String newSequenceName) { - this.virtualXmlSequenceGenerator.setSequenceName(newSequenceName); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlTransient2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlTransient2_0.java deleted file mode 100644 index bb795b8d02..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlTransient2_0.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlTransient; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.AccessType; -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 VirtualXmlTransient2_0 extends XmlTransient -{ - - protected OrmTypeMapping ormTypeMapping; - - protected final JavaTransientMapping javaAttributeMapping; - - protected final VirtualXmlTransient virtualXmlTransient; - - public VirtualXmlTransient2_0(OrmTypeMapping ormTypeMapping, JavaTransientMapping javaTransientMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaTransientMapping; - this.virtualXmlTransient = new VirtualXmlTransient(ormTypeMapping, javaTransientMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlTransient.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlTransient.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlTransient.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlTransient.getNameTextRange(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlVersion2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlVersion2_0.java deleted file mode 100644 index 6c2bc523e5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlVersion2_0.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.VirtualXmlVersion; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.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 VirtualXmlVersion2_0 extends XmlVersion -{ - - protected OrmTypeMapping ormTypeMapping; - - protected final JavaVersionMapping javaAttributeMapping; - - protected final VirtualXmlVersion virtualXmlVersion; - - public VirtualXmlVersion2_0(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaVersionMapping; - this.virtualXmlVersion = new VirtualXmlVersion(ormTypeMapping, javaVersionMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlVersion.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlVersion.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlVersion.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlVersion.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.virtualXmlVersion.getColumn(); - } - - @Override - public void setColumn(XmlColumn value) { - this.virtualXmlVersion.setColumn(value); - } - - @Override - public TemporalType getTemporal() { - return this.virtualXmlVersion.getTemporal(); - } - - @Override - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EnumType getEnumerated() { - return this.virtualXmlVersion.getEnumerated(); - } - - @Override - public void setEnumerated(EnumType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isLob() { - return this.virtualXmlVersion.isLob(); - } - - @Override - public void setLob(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getEnumeratedTextRange() { - return this.virtualXmlVersion.getEnumeratedTextRange(); - } - - @Override - public TextRange getLobTextRange() { - return this.virtualXmlVersion.getLobTextRange(); - } - - @Override - public TextRange getTemporalTextRange() { - return this.virtualXmlVersion.getTemporalTextRange(); - } - - @Override - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel(this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - @Override - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/GenericPersistenceUnit2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/GenericPersistenceUnit2_0.java deleted file mode 100644 index 67ea2b8b0f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/GenericPersistenceUnit2_0.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.persistence; - -import java.util.Iterator; - -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.JarFileRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnit; -import org.eclipse.jpt.core.internal.jpa2.context.persistence.connection.GenericConnection2_0; -import org.eclipse.jpt.core.internal.jpa2.context.persistence.options.GenericOptions2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.ClassRef2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.JarFileRef2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.MappingFileRef2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.Persistence2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.connection.JpaConnection2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.options.JpaOptions2_0; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; - -/** - * JPA 2.0 persistence-unit - */ -public class GenericPersistenceUnit2_0 - extends AbstractPersistenceUnit - implements PersistenceUnit2_0 -{ - private JpaConnection2_0 connection; - private JpaOptions2_0 options; - - // ********** constructors ********** - public GenericPersistenceUnit2_0(Persistence2_0 parent, XmlPersistenceUnit xmlPersistenceUnit) { - super(parent, xmlPersistenceUnit); - } - - // ********** properties ********** - @Override - protected void initializeProperties() { - super.initializeProperties(); - this.connection = new GenericConnection2_0(this); - this.options = new GenericOptions2_0(this); - } - - @Override - public void propertyValueChanged(String propertyName, String newValue) { - super.propertyValueChanged(propertyName, newValue); - this.connection.propertyValueChanged(propertyName, newValue); - this.options.propertyValueChanged(propertyName, newValue); - } - - @Override - public void propertyRemoved(String propertyName) { - super.propertyRemoved(propertyName); - this.connection.propertyRemoved(propertyName); - this.options.propertyRemoved(propertyName); - } - - public JpaConnection2_0 getConnection() { - return this.connection; - } - - public JpaOptions2_0 getOptions() { - return this.options; - } - - - // ********** JPA 2.0 Static Metamodel ********** - - public void synchronizeStaticMetamodel() { - for (Iterator<MappingFileRef> stream = this.mappingFileRefs(); stream.hasNext(); ) { - ((MappingFileRef2_0) stream.next()).synchronizeStaticMetamodel(); - } - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - ((ClassRef2_0) stream.next()).synchronizeStaticMetamodel(); - } - for (Iterator<JarFileRef> stream = this.jarFileRefs(); stream.hasNext(); ) { - ((JarFileRef2_0) stream.next()).synchronizeStaticMetamodel(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/connection/GenericConnection2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/connection/GenericConnection2_0.java deleted file mode 100644 index 48f975c8b0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/connection/GenericConnection2_0.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.persistence.connection; - -import java.util.Map; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnitProperties; -import org.eclipse.jpt.core.jpa2.context.persistence.connection.JpaConnection2_0; - -/** - * GenericConnection2_0 - */ -public class GenericConnection2_0 extends AbstractPersistenceUnitProperties - implements JpaConnection2_0 -{ - // ********** GenericConnection properties ********** - private String driver; - private String url; - private String user; - private String password; - - - // ********** constructors ********** - public GenericConnection2_0(PersistenceUnit parent) { - super(parent); - } - - // ********** initialization ********** - /** - * Initializes properties with values from the persistence unit. - */ - @Override - protected void initializeProperties() { - this.driver = - this.getStringValue(PERSISTENCE_JDBC_DRIVER); - this.url = - this.getStringValue(PERSISTENCE_JDBC_URL); - this.user = - this.getStringValue(PERSISTENCE_JDBC_USER); - this.password = - this.getStringValue(PERSISTENCE_JDBC_PASSWORD); - } - - // ********** behavior ********** - - public void propertyValueChanged(String propertyName, String newValue) { - if (propertyName.equals(PERSISTENCE_JDBC_DRIVER)) { - this.driverChanged(newValue); - } - else if (propertyName.equals(PERSISTENCE_JDBC_URL)) { - this.urlChanged(newValue); - } - else if (propertyName.equals(PERSISTENCE_JDBC_USER)) { - this.userChanged(newValue); - } - else if (propertyName.equals(PERSISTENCE_JDBC_PASSWORD)) { - this.passwordChanged(newValue); - } - } - - public void propertyRemoved(String propertyName) { - if (propertyName.equals(PERSISTENCE_JDBC_DRIVER)) { - this.driverChanged(null); - } - else if (propertyName.equals(PERSISTENCE_JDBC_URL)) { - this.urlChanged(null); - } - else if (propertyName.equals(PERSISTENCE_JDBC_USER)) { - this.userChanged(null); - } - else if (propertyName.equals(PERSISTENCE_JDBC_PASSWORD)) { - this.passwordChanged(null); - } - } - - /** - * Adds property names key/value pairs, where: - * key = PU property key - * value = property id - */ - @Override - protected void addPropertyNames(Map<String, String> propertyNames) { - propertyNames.put( - PERSISTENCE_JDBC_DRIVER, - DRIVER_PROPERTY); - propertyNames.put( - PERSISTENCE_JDBC_URL, - URL_PROPERTY); - propertyNames.put( - PERSISTENCE_JDBC_USER, - USER_PROPERTY); - propertyNames.put( - PERSISTENCE_JDBC_PASSWORD, - PASSWORD_PROPERTY); - } - - // ********** Driver ********** - public String getDriver() { - return this.driver; - } - - public void setDriver(String newDriver) { - String old = this.driver; - this.driver = newDriver; - this.putProperty(DRIVER_PROPERTY, newDriver); - this.firePropertyChanged(DRIVER_PROPERTY, old, newDriver); - } - - private void driverChanged(String newValue) { - String old = this.driver; - this.driver = newValue; - this.firePropertyChanged(DRIVER_PROPERTY, old, newValue); - } - - public String getDefaultDriver() { - return DEFAULT_JDBC_DRIVER; - } - - // ********** URL ********** - public String getUrl() { - return this.url; - } - - public void setUrl(String newUrl) { - String old = this.url; - this.url = newUrl; - this.putProperty(URL_PROPERTY, newUrl); - this.firePropertyChanged(URL_PROPERTY, old, newUrl); - } - - private void urlChanged(String newValue) { - String old = this.url; - this.url = newValue; - this.firePropertyChanged(URL_PROPERTY, old, newValue); - } - - public String getDefaultUrl() { - return DEFAULT_JDBC_URL; - } - - // ********** User ********** - public String getUser() { - return this.user; - } - - public void setUser(String newUser) { - String old = this.user; - this.user = newUser; - this.putProperty(USER_PROPERTY, newUser); - this.firePropertyChanged(USER_PROPERTY, old, newUser); - } - - private void userChanged(String newValue) { - String old = this.user; - this.user = newValue; - this.firePropertyChanged(USER_PROPERTY, old, newValue); - } - - public String getDefaultUser() { - return DEFAULT_JDBC_USER; - } - - // ********** Password ********** - public String getPassword() { - return this.password; - } - - public void setPassword(String newPassword) { - String old = this.password; - this.password = newPassword; - this.putProperty(PASSWORD_PROPERTY, newPassword); - this.firePropertyChanged(PASSWORD_PROPERTY, old, newPassword); - } - - private void passwordChanged(String newValue) { - String old = this.password; - this.password = newValue; - this.firePropertyChanged(PASSWORD_PROPERTY, old, newValue); - } - - public String getDefaultPassword() { - return DEFAULT_JDBC_PASSWORD; - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/GenericOptions2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/GenericOptions2_0.java deleted file mode 100644 index e210c71f78..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/persistence/options/GenericOptions2_0.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.context.persistence.options; - -import java.util.Map; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnitProperties; -import org.eclipse.jpt.core.jpa2.context.persistence.options.JpaOptions2_0; - -/** - * JPA 2.0 options - */ -public class GenericOptions2_0 extends AbstractPersistenceUnitProperties - implements JpaOptions2_0 -{ - // ********** GenericConnection properties ********** - private Integer lockTimeout; - private Integer queryTimeout; - private String validationGroupPrePersist; - private String validationGroupPreUpdate; - private String validationGroupPreRemove; - - - // ********** constructors ********** - public GenericOptions2_0(PersistenceUnit parent) { - super(parent); - } - - // ********** initialization ********** - /** - * Initializes properties with values from the persistence unit. - */ - @Override - protected void initializeProperties() { - this.lockTimeout = - this.getIntegerValue(PERSISTENCE_LOCK_TIMEOUT); - this.queryTimeout = - this.getIntegerValue(PERSISTENCE_QUERY_TIMEOUT); - this.validationGroupPrePersist = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST); - this.validationGroupPreUpdate = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE); - this.validationGroupPreRemove = - this.getStringValue(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE); - } - - // ********** behavior ********** - - public void propertyValueChanged(String propertyName, String newValue) { - if (propertyName.equals(PERSISTENCE_LOCK_TIMEOUT)) { - this.lockTimeoutChanged(newValue); - } - else if (propertyName.equals(PERSISTENCE_QUERY_TIMEOUT)) { - this.queryTimeoutChanged(newValue); - } - else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST)) { - this.validationGroupPrePersistChanged(newValue); - } - else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE)) { - this.validationGroupPreUpdateChanged(newValue); - } - else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE)) { - this.validationGroupPreRemoveChanged(newValue); - } - } - - public void propertyRemoved(String propertyName) { - if (propertyName.equals(PERSISTENCE_LOCK_TIMEOUT)) { - this.lockTimeoutChanged(null); - } - else if (propertyName.equals(PERSISTENCE_QUERY_TIMEOUT)) { - this.queryTimeoutChanged(null); - } - else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST)) { - this.validationGroupPrePersistChanged(null); - } - else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE)) { - this.validationGroupPreUpdateChanged(null); - } - else if (propertyName.equals(PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE)) { - this.validationGroupPreRemoveChanged(null); - } - } - - /** - * Adds property names key/value pairs, where: - * key = PU property key - * value = property id - */ - @Override - protected void addPropertyNames(Map<String, String> propertyNames) { - propertyNames.put( - PERSISTENCE_LOCK_TIMEOUT, - LOCK_TIMEOUT_PROPERTY); - propertyNames.put( - PERSISTENCE_QUERY_TIMEOUT, - QUERY_TIMEOUT_PROPERTY); - propertyNames.put( - PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST, - VALIDATION_GROUP_PRE_PERSIST_PROPERTY); - propertyNames.put( - PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE, - VALIDATION_GROUP_PRE_UPDATE_PROPERTY); - propertyNames.put( - PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE, - VALIDATION_GROUP_PRE_REMOVE_PROPERTY); - } - - // ********** LockTimeout ********** - public Integer getLockTimeout() { - return this.lockTimeout; - } - - public void setLockTimeout(Integer newLockTimeout) { - Integer old = this.lockTimeout; - this.lockTimeout = newLockTimeout; - this.putProperty(LOCK_TIMEOUT_PROPERTY, newLockTimeout); - this.firePropertyChanged(LOCK_TIMEOUT_PROPERTY, old, newLockTimeout); - } - - private void lockTimeoutChanged(String stringValue) { - Integer newValue = getIntegerValueOf(stringValue); - - Integer old = this.lockTimeout; - this.lockTimeout = newValue; - this.firePropertyChanged(LOCK_TIMEOUT_PROPERTY, old, newValue); - } - - public Integer getDefaultLockTimeout() { - return DEFAULT_LOCK_TIMEOUT; - } - - // ********** QueryTimeout ********** - public Integer getQueryTimeout() { - return this.queryTimeout; - } - - public void setQueryTimeout(Integer newQueryTimeout) { - Integer old = this.queryTimeout; - this.queryTimeout = newQueryTimeout; - this.putProperty(QUERY_TIMEOUT_PROPERTY, newQueryTimeout); - this.firePropertyChanged(QUERY_TIMEOUT_PROPERTY, old, newQueryTimeout); - } - - private void queryTimeoutChanged(String stringValue) { - Integer newValue = getIntegerValueOf(stringValue); - - Integer old = this.queryTimeout; - this.queryTimeout = newValue; - this.firePropertyChanged(QUERY_TIMEOUT_PROPERTY, old, newValue); - } - - public Integer getDefaultQueryTimeout() { - return DEFAULT_QUERY_TIMEOUT; - } - - // ********** ValidationGroupPrePersist ********** - public String getValidationGroupPrePersist() { - return this.validationGroupPrePersist; - } - - public void setValidationGroupPrePersist(String newValidationGroupPrePersist) { - String old = this.validationGroupPrePersist; - this.validationGroupPrePersist = newValidationGroupPrePersist; - this.putProperty(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, newValidationGroupPrePersist); - this.firePropertyChanged(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, old, newValidationGroupPrePersist); - } - - private void validationGroupPrePersistChanged(String newValue) { - String old = this.validationGroupPrePersist; - this.validationGroupPrePersist = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_PERSIST_PROPERTY, old, newValue); - } - - public String getDefaultValidationGroupPrePersist() { - return DEFAULT_VALIDATION_GROUP_PRE_PERSIST; - } - - // ********** ValidationGroupPreUpdate ********** - public String getValidationGroupPreUpdate() { - return this.validationGroupPreUpdate; - } - - public void setValidationGroupPreUpdate(String newValidationGroupPreUpdate) { - String old = this.validationGroupPreUpdate; - this.validationGroupPreUpdate = newValidationGroupPreUpdate; - this.putProperty(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, newValidationGroupPreUpdate); - this.firePropertyChanged(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, old, newValidationGroupPreUpdate); - } - - private void validationGroupPreUpdateChanged(String newValue) { - String old = this.validationGroupPreUpdate; - this.validationGroupPreUpdate = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_UPDATE_PROPERTY, old, newValue); - } - - public String getDefaultValidationGroupPreUpdate() { - return DEFAULT_VALIDATION_GROUP_PRE_UPDATE; - } - - // ********** ValidationGroupPreRemove ********** - public String getValidationGroupPreRemove() { - return this.validationGroupPreRemove; - } - - public void setValidationGroupPreRemove(String newValidationGroupPreRemove) { - String old = this.validationGroupPreRemove; - this.validationGroupPreRemove = newValidationGroupPreRemove; - this.putProperty(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, newValidationGroupPreRemove); - this.firePropertyChanged(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, old, newValidationGroupPreRemove); - } - - private void validationGroupPreRemoveChanged(String newValue) { - String old = this.validationGroupPreRemove; - this.validationGroupPreRemove = newValue; - this.firePropertyChanged(VALIDATION_GROUP_PRE_REMOVE_PROPERTY, old, newValue); - } - - public String getDefaultValidationGroupPreRemove() { - return DEFAULT_VALIDATION_GROUP_PRE_REMOVE; - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/operations/Orm2_0FileCreationOperation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/operations/Orm2_0FileCreationOperation.java deleted file mode 100644 index 92cecba43e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/operations/Orm2_0FileCreationOperation.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.operations; - -import java.util.Iterator; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -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.jpa2.resource.orm.Orm2_0XmlResourceProvider; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; -import org.eclipse.jpt.core.jpa2.resource.orm.Orm2_0Factory; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlPersistenceUnitDefaults; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public class Orm2_0FileCreationOperation extends AbstractDataModelOperation - implements OrmFileCreationDataModelProperties -{ - public Orm2_0FileCreationOperation(IDataModel dataModel) { - super(dataModel); - } - - - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // Create source folder if it does not exist - IFolder folder = createSourceFolder(); - // Create orm file - IFile file = createMappingFile(folder); - // Add orm file to persistence unit if specified - addMappingFileToPersistenceXml(file); - return OK_STATUS; - } - - protected IProject getProject() throws ExecutionException { - String projectName = (String) getDataModel().getProperty(PROJECT_NAME); - IProject project = ProjectUtilities.getProject(projectName); - if (project == null) { - throw new ExecutionException("No project name specified"); //$NON-NLS-1$ - } - return project; - } - - protected JpaProject getJpaProject() throws ExecutionException { - IProject project = getProject(); - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - if (jpaProject == null) { - throw new ExecutionException("Project does not have JPA content"); //$NON-NLS-1$ - } - return jpaProject; - } - - protected PersistenceUnit getPersistenceUnit() throws ExecutionException { - String pUnitName = getDataModel().getStringProperty(PERSISTENCE_UNIT); - JpaProject jpaProject = getJpaProject(); - PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml(); - if (persistenceXml == null) { - throw new ExecutionException("Project does not have a persistence.xml file"); //$NON-NLS-1$ - } - Persistence persistence = persistenceXml.getPersistence(); - if (persistence == null) { - throw new ExecutionException("persistence.xml does not have a persistence node."); //$NON-NLS-1$ - } - for (Iterator<PersistenceUnit> stream = persistence.persistenceUnits(); stream.hasNext(); ) { - PersistenceUnit pUnit = stream.next(); - if (pUnitName.equals(pUnit.getName())) { - return pUnit; - } - } - throw new ExecutionException("persistence.xml does not have persistence unit named \'" + pUnitName + "\'"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * This method will return the source folder as specified in the data model. - * It will create the source folder if it does not exist. It will not add - * it as a source folder to the project build path if it is not already. - * This method may return null. - */ - // copied from NewJavaClassOperation - protected IFolder createSourceFolder() throws ExecutionException { - // Get the source folder name from the data model - String folderPath = this.model.getStringProperty(SOURCE_FOLDER); - IProject project = getProject(); - IFolder folder = project.getWorkspace().getRoot().getFolder(new Path(folderPath)); - // If folder does not exist, create the folder with the specified path - if (! folder.exists()) { - try { - folder.create(true, true, null); - } catch (CoreException e) { - throw new ExecutionException("Could not create folder", e); //$NON-NLS-1$ - } - } - // Return the source folder - return folder; - } - - protected IFile createMappingFile(IFolder folder) { - String filePath = getDataModel().getStringProperty(FILE_PATH); - IFile file = folder.getFile(new Path(filePath)); - final AbstractXmlResourceProvider resourceProvider = getXmlResourceProvider(file); - final JpaXmlResource xmlResource; - try { - xmlResource = resourceProvider.createFileAndResource(); - } - catch (CoreException e) { - JptCorePlugin.log(e); - return null; - } - xmlResource.modify(new Runnable() { - public void run() { - AccessType defaultAccess = (AccessType) getDataModel().getProperty(DEFAULT_ACCESS); - if (defaultAccess != null) { - XmlPersistenceUnitMetadata puMetadata = createXmlPersistenceUnitMetadata(); - ((XmlEntityMappings) xmlResource.getRootObject()).setPersistenceUnitMetadata(puMetadata); - XmlPersistenceUnitDefaults puDefaults = createXmlPersistenceUnitDefaults(); - puMetadata.setPersistenceUnitDefaults(puDefaults); - puDefaults.setAccess(defaultAccess); - } - } - }); - return file; - } - - protected XmlPersistenceUnitMetadata createXmlPersistenceUnitMetadata() { - return Orm2_0Factory.eINSTANCE.createXmlPersistenceUnitMetadata(); - } - - protected XmlPersistenceUnitDefaults createXmlPersistenceUnitDefaults() { - return Orm2_0Factory.eINSTANCE.createXmlPersistenceUnitDefaults(); - } - - protected AbstractXmlResourceProvider getXmlResourceProvider(IFile file) { - return Orm2_0XmlResourceProvider.getXmlResourceProvider(file); - } - - protected void addMappingFileToPersistenceXml(IFile file) throws ExecutionException { - if (! getDataModel().getBooleanProperty(ADD_TO_PERSISTENCE_UNIT)) { - return; - } - JpaProject jpaProject = JptCorePlugin.getJpaProject(file.getProject()); - JpaXmlResource resource = jpaProject.getPersistenceXmlResource(); - - final PersistenceUnit pUnit = getPersistenceUnit(); - - resource.modify(new Runnable() { - public void run() { - String filePath = getDataModel().getStringProperty(FILE_PATH); - for (Iterator<MappingFileRef> stream = pUnit.specifiedMappingFileRefs(); stream.hasNext(); ) { - if (filePath.equals(stream.next().getFileName())) { - return; - } - } - MappingFileRef mfRef = pUnit.addSpecifiedMappingFileRef(); - mfRef.setFileName(new Path(filePath).toPortableString()); - } - }); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/Access2_0AnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/Access2_0AnnotationDefinition.java deleted file mode 100644 index ec2cd71009..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/Access2_0AnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.binary.BinaryAccess2_0Annotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.source.SourceAccess2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Access - */ -public final class Access2_0AnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new Access2_0AnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private Access2_0AnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceAccess2_0Annotation(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullAccess2_0Annotation(parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryAccess2_0Annotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return Access2_0Annotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/AssociationOverride2_0AnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/AssociationOverride2_0AnnotationDefinition.java deleted file mode 100644 index d885db7ebf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/AssociationOverride2_0AnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.binary.BinaryAssociationOverride2_0Annotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.source.SourceAssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AssociationOverride - */ -public final class AssociationOverride2_0AnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new AssociationOverride2_0AnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private AssociationOverride2_0AnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourceAssociationOverride2_0Annotation.buildAssociationOverride(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryAssociationOverride2_0Annotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return AssociationOverrideAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/AssociationOverrides2_0AnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/AssociationOverrides2_0AnnotationDefinition.java deleted file mode 100644 index 3d9b6239d1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/AssociationOverrides2_0AnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.binary.BinaryAssociationOverrides2_0Annotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.source.SourceAssociationOverrides2_0Annotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AssociationOverrides - */ -public final class AssociationOverrides2_0AnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new AssociationOverrides2_0AnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private AssociationOverrides2_0AnnotationDefinition() { - super(); - } - - public AssociationOverridesAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceAssociationOverrides2_0Annotation(parent, member); - } - - public AssociationOverridesAnnotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryAssociationOverrides2_0Annotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return AssociationOverridesAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAccess2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAccess2_0Annotation.java deleted file mode 100644 index d3990a5aaf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAccess2_0Annotation.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.NullAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Access - */ -public class NullAccess2_0Annotation - extends NullAnnotation - implements Access2_0Annotation -{ - - protected NullAccess2_0Annotation(JavaResourcePersistentMember parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected Access2_0Annotation addAnnotation() { - return (Access2_0Annotation) super.addAnnotation(); - } - - // ***** value - public AccessType getValue() { - return null; - } - - public void setValue(AccessType value) { - if (value != null) { - this.addAnnotation().setValue(value); - } - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAssociationOverrideJoinTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAssociationOverrideJoinTableAnnotation.java deleted file mode 100644 index ef40c1d9f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAssociationOverrideJoinTableAnnotation.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java; - -import org.eclipse.jpt.core.internal.resource.java.NullJoinTableAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember.AnnotationInitializer; - -/** - * javax.persistence.JoinTable found in a javax.persistence.AssociationOverride annotation - */ -public class NullAssociationOverrideJoinTableAnnotation - extends NullJoinTableAnnotation -{ - public NullAssociationOverrideJoinTableAnnotation(AssociationOverride2_0Annotation parent) { - super(parent); - } - - private AssociationOverride2_0Annotation getAssociationOverride2_0Annotation() { - return (AssociationOverride2_0Annotation) this.parent; - } - - @Override - protected JoinTableAnnotation addAnnotation() { - return this.getAssociationOverride2_0Annotation().addJoinTable(); - } - - @Override - protected JoinColumnAnnotation addAnnotation(AnnotationInitializer initializer) { - return this.getAssociationOverride2_0Annotation().addJoinTable(initializer); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationDefinition.java deleted file mode 100644 index 4efd835771..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.binary.BinarySequenceGenerator2_0Annotation; -import org.eclipse.jpt.core.internal.jpa2.resource.java.source.SourceSequenceGenerator2_0Annotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * SequenceGenerator2_0AnnotationDefinition - */ -public final class SequenceGenerator2_0AnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new SequenceGenerator2_0AnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SequenceGenerator2_0AnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceSequenceGenerator2_0Annotation(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinarySequenceGenerator2_0Annotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return SequenceGeneratorAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAccess2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAccess2_0Annotation.java deleted file mode 100644 index c4fc19b2bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAccess2_0Annotation.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Access - */ -public final class BinaryAccess2_0Annotation - extends BinaryAnnotation - implements Access2_0Annotation -{ - private AccessType value; - - - public BinaryAccess2_0Annotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.value = this.buildValue(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setValue_(this.buildValue()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** AccessAnnotation implementation ********** - - // ***** value - public AccessType getValue() { - return this.value; - } - - public void setValue(AccessType value) { - throw new UnsupportedOperationException(); - } - - private void setValue_(AccessType value) { - AccessType old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private AccessType buildValue() { - return AccessType.fromJavaAnnotationValue(this.getJdtMemberValue(JPA2_0.ACCESS)); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverride2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverride2_0Annotation.java deleted file mode 100644 index 27e2fcb276..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverride2_0Annotation.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.NullJoinTableAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAssociationOverrideAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryJoinTableAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember.AnnotationInitializer; - -/** - * BinarySequenceGenerator2_0Annotation - */ -public final class BinaryAssociationOverride2_0Annotation - extends BinaryAssociationOverrideAnnotation - implements AssociationOverride2_0Annotation -{ - private JoinTableAnnotation joinTable; - - public BinaryAssociationOverride2_0Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.joinTable = this.buildJoinTable(); - } - - @Override - public void update() { - super.update(); - this.updateJoinTable(); - } - - - // ********** AssociationOverride2_0Annotation implementation ********** - - // ***** joinTable - public JoinTableAnnotation getJoinTable() { - return this.joinTable; - } - - public JoinTableAnnotation getNonNullJoinTable() { - return (this.joinTable != null) ? this.joinTable : new NullJoinTableAnnotation(this); - } - - public JoinTableAnnotation addJoinTable() { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation addJoinTable(AnnotationInitializer initializer) { - throw new UnsupportedOperationException(); - } - - public void removeJoinTable() { - throw new UnsupportedOperationException(); - } - - private JoinTableAnnotation buildJoinTable() { - IAnnotation jdtJoinTable = this.getJdtJoinTable(); - return (jdtJoinTable == null) ? null : this.buildJoinTable(jdtJoinTable); - } - - private JoinTableAnnotation buildJoinTable(IAnnotation jdtJoinTable) { - return new BinaryJoinTableAnnotation(this, jdtJoinTable); - } - - private IAnnotation getJdtJoinTable() { - return (IAnnotation) this.getJdtMemberValue(JPA2_0.ASSOCIATION_OVERRIDE__JOIN_TABLE); - } - - private void setJoinTable(JoinTableAnnotation column) { - JoinTableAnnotation old = this.joinTable; - this.joinTable = column; - this.firePropertyChanged(JOIN_TABLE_PROPERTY, old, column); - } - - // TODO - private void updateJoinTable() { - throw new UnsupportedOperationException(); -// IAnnotation jdtJoinTable = this.getJdtJoinTable(); -// if (jdtJoinTable == null) { -// this.setJoinTable(null); -// } else { -// if (this.column == null) { -// this.setJoinTable(this.buildJoinTable(jdtJoinTable)); -// } else { -// this.column.update(jdtJoinTable); -// } -// } - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverrides2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverrides2_0Annotation.java deleted file mode 100644 index d47f13bc82..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverrides2_0Annotation.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; - -/** - * javax.persistence.AssociationOverrides - */ -public class BinaryAssociationOverrides2_0Annotation - extends BinaryAssociationOverridesAnnotation -{ - - public BinaryAssociationOverrides2_0Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - @Override - protected NestableAssociationOverrideAnnotation buildAssociationOverride(Object jdtAssociationOverride) { - return new BinaryAssociationOverride2_0Annotation(this, (IAnnotation) jdtAssociationOverride); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinarySequenceGenerator2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinarySequenceGenerator2_0Annotation.java deleted file mode 100644 index 6919129230..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinarySequenceGenerator2_0Annotation.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.binary.BinarySequenceGeneratorAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.SequenceGenerator2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * BinarySequenceGenerator2_0Annotation - */ -public final class BinarySequenceGenerator2_0Annotation - extends BinarySequenceGeneratorAnnotation - implements SequenceGenerator2_0Annotation -{ - private String catalog; - private String schema; - - - public BinarySequenceGenerator2_0Annotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.catalog = this.buildCatalog(); - this.schema = this.buildSchema(); - } - - @Override - public void update() { - super.update(); - this.setCatalog_(this.buildCatalog()); - this.setSchema_(this.buildSchema()); - } - - // ********** SequenceGenerator2_0Annotation implementation ********** - - // ********** catalog ********** - - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String catalog) { - throw new UnsupportedOperationException(); - } - - private void setCatalog_(String catalog) { - String old = this.catalog; - this.catalog = catalog; - this.firePropertyChanged(CATALOG_PROPERTY, old, catalog); - } - - private String buildCatalog() { - return (String) this.getJdtMemberValue(JPA2_0.SEQUENCE_GENERATOR__CATALOG); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ********** schema ********** - - public String getSchema() { - return this.schema; - } - - public void setSchema(String schema) { - throw new UnsupportedOperationException(); - } - - private void setSchema_(String schema) { - String old = this.schema; - this.schema = schema; - this.firePropertyChanged(SCHEMA_PROPERTY, old, schema); - } - - private String buildSchema() { - return (String) this.getJdtMemberValue(JPA2_0.SEQUENCE_GENERATOR__SCHEMA); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAccess2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAccess2_0Annotation.java deleted file mode 100644 index 318d880818..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAccess2_0Annotation.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Access - */ -public final class SourceAccess2_0Annotation - extends SourceAnnotation<Member> - implements Access2_0Annotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); - private final AnnotationElementAdapter<String> valueAdapter; - private AccessType value; - - - public SourceAccess2_0Annotation(JavaResourcePersistentMember parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(member, VALUE_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.buildValue(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.buildValue(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** AccessAnnotation implementation ********** - - // ***** value - public AccessType getValue() { - return this.value; - } - - public void setValue(AccessType value) { - if (this.attributeValueHasNotChanged(this.value, value)) { - return; - } - AccessType old = this.value; - this.value = value; - this.valueAdapter.setValue(AccessType.toJavaAnnotationValue(value)); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private AccessType buildValue(CompilationUnit astRoot) { - return AccessType.fromJavaAnnotationValue(this.valueAdapter.getValue(astRoot)); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA2_0.ACCESS__VALUE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverride2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverride2_0Annotation.java deleted file mode 100644 index 02cf8620ad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverride2_0Annotation.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.jpa2.resource.java.NullAssociationOverrideJoinTableAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceAssociationOverrideAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceJoinTableAnnotation; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember.AnnotationInitializer; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * SourceSequenceGenerator2_0Annotation - */ -public final class SourceAssociationOverride2_0Annotation - extends SourceAssociationOverrideAnnotation - implements AssociationOverride2_0Annotation -{ - private final MemberAnnotationAdapter joinTableAdapter; - private NestableJoinTableAnnotation joinTable; - - - // ********** constructor ********** - public SourceAssociationOverride2_0Annotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.joinTableAdapter = new MemberAnnotationAdapter(this.member, buildJoinTableAnnotationAdapter(this.daa)); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - if (this.joinTableAdapter.getAnnotation(astRoot) != null) { - this.joinTable = buildJoinTableAnnotation(this, this.member, this.daa); - this.joinTable.initialize(astRoot); - } - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.updateJoinTable(astRoot); - } - - //************ AssociationOverride2_0Annotation implementation **************** - - // ***** joinTable - public JoinTableAnnotation getJoinTable() { - return this.joinTable; - } - - public NestableJoinTableAnnotation addJoinTable() { - NestableJoinTableAnnotation table = buildJoinTableAnnotation(this, this.member, this.daa); - table.newAnnotation(); - this.setJoinTable(table); - return table; - } - - public JoinColumnAnnotation addJoinTable(AnnotationInitializer initializer) { - NestableJoinTableAnnotation table = buildJoinTableAnnotation(this, this.member, this.daa); - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) initializer.initializeAnnotation(table); - table.newAnnotation(); - this.setJoinTable(table); - return joinColumn; - } - - public void removeJoinTable() { - this.joinTable.removeAnnotation(); - setJoinTable(null); - } - - private void setJoinTable(NestableJoinTableAnnotation joinTable) { - JoinTableAnnotation old = this.joinTable; - this.joinTable = joinTable; - this.firePropertyChanged(JOIN_TABLE_PROPERTY, old, joinTable); - } - - public JoinTableAnnotation getNonNullJoinTable() { - return (this.joinTable != null) ? this.joinTable : new NullAssociationOverrideJoinTableAnnotation(this); - } - - private void updateJoinTable(CompilationUnit astRoot) { - if (this.joinTableAdapter.getAnnotation(astRoot) == null) { - this.setJoinTable(null); - } else { - if (this.joinTable == null) { - NestableJoinTableAnnotation table = buildJoinTableAnnotation(this, this.member, this.daa); - table.initialize(astRoot); - this.setJoinTable(table); - } else { - this.joinTable.update(astRoot); - } - } - } - - - // ********** static methods ********** - - public static SourceAssociationOverride2_0Annotation buildAssociationOverride(JavaResourceNode parent, Member member) { - return new SourceAssociationOverride2_0Annotation(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - static NestableJoinTableAnnotation buildJoinTableAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter associationOverrideAnnotationAdapter) { - return new SourceJoinTableAnnotation(parent, member, buildJoinTableAnnotationAdapter(associationOverrideAnnotationAdapter)); - } - - static DeclarationAnnotationAdapter buildJoinTableAnnotationAdapter(DeclarationAnnotationAdapter associationOverrideAnnotationAdapter) { - return new NestedDeclarationAnnotationAdapter(associationOverrideAnnotationAdapter, JPA2_0.ASSOCIATION_OVERRIDE__JOIN_TABLE, org.eclipse.jpt.core.resource.java.JPA.JOIN_TABLE); - } - - - static SourceAssociationOverrideAnnotation buildNestedAssociationOverride(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new SourceAssociationOverride2_0Annotation(parent, member, idaa, annotationAdapter); - } - - protected static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(attributeOverridesAdapter, index, org.eclipse.jpt.core.resource.java.JPA.ASSOCIATION_OVERRIDE); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverrides2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverrides2_0Annotation.java deleted file mode 100644 index 62dead13dc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverrides2_0Annotation.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.source; - -import org.eclipse.jpt.core.internal.resource.java.source.SourceAssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AssociationOverrides - */ -public final class SourceAssociationOverrides2_0Annotation - extends SourceAssociationOverridesAnnotation -{ - - public SourceAssociationOverrides2_0Annotation(JavaResourceNode parent, Member member) { - super(parent, member); - } - - @Override - protected NestableAssociationOverrideAnnotation buildAssociationOverride(int index) { - return SourceAssociationOverride2_0Annotation.buildNestedAssociationOverride(this, this.member, index, this.daa); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceSequenceGenerator2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceSequenceGenerator2_0Annotation.java deleted file mode 100644 index f1c09d3aa0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceSequenceGenerator2_0Annotation.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.source.SourceSequenceGeneratorAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.SequenceGenerator2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * SourceSequenceGenerator2_0Annotation - */ -public final class SourceSequenceGenerator2_0Annotation - extends SourceSequenceGeneratorAnnotation - implements SequenceGenerator2_0Annotation -{ - private static final DeclarationAnnotationElementAdapter<String> CATALOG_ADAPTER = buildAdapter(JPA2_0.SEQUENCE_GENERATOR__CATALOG); - private final AnnotationElementAdapter<String> catalogAdapter; - private String catalog; - - private static final DeclarationAnnotationElementAdapter<String> SCHEMA_ADAPTER = buildAdapter(JPA2_0.SEQUENCE_GENERATOR__SCHEMA); - private final AnnotationElementAdapter<String> schemaAdapter; - private String schema; - - - // ********** constructor ********** - public SourceSequenceGenerator2_0Annotation(JavaResourceNode parent, Member member) { - super(parent, member); - - this.catalogAdapter = this.buildAdapter(CATALOG_ADAPTER); - this.schemaAdapter = this.buildAdapter(SCHEMA_ADAPTER); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - - this.catalog = this.buildCatalog(astRoot); - this.schema = this.buildSchema(astRoot); - - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - - this.setCatalog(this.buildCatalog(astRoot)); - this.setSchema(this.buildSchema(astRoot)); - } - - // ********** catalog ********** - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String catalog) { - if (this.attributeValueHasNotChanged(this.catalog, catalog)) { - return; - } - String old = this.catalog; - this.catalog = catalog; - this.catalogAdapter.setValue(catalog); - this.firePropertyChanged(CATALOG_PROPERTY, old, catalog); - } - - private String buildCatalog(CompilationUnit astRoot) { - return this.catalogAdapter.getValue(astRoot); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(CATALOG_ADAPTER, astRoot); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(CATALOG_ADAPTER, pos, astRoot); - } - - // ********** schema ********** - public String getSchema() { - return this.schema; - } - - public void setSchema(String schema) { - if (this.attributeValueHasNotChanged(this.schema, schema)) { - return; - } - String old = this.schema; - this.schema = schema; - this.schemaAdapter.setValue(schema); - this.firePropertyChanged(SCHEMA_PROPERTY, old, schema); - } - - private String buildSchema(CompilationUnit astRoot) { - return this.schemaAdapter.getValue(astRoot); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(SCHEMA_ADAPTER, astRoot); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(SCHEMA_ADAPTER, pos, astRoot); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/orm/Orm2_0XmlResourceProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/orm/Orm2_0XmlResourceProvider.java deleted file mode 100644 index 4e18d4de6e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/orm/Orm2_0XmlResourceProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.orm; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.jpa2.resource.orm.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.orm.Orm2_0Factory; -import org.eclipse.jpt.core.jpa2.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider; - -public class Orm2_0XmlResourceProvider - extends AbstractXmlResourceProvider -{ - /** - * (Convenience method) Returns an ORM resource model provider for - * the given file. - */ - public static Orm2_0XmlResourceProvider getXmlResourceProvider(IFile file) { - return getXmlResourceProvider_(file.getProject(), file.getFullPath().toString()); - } - - /** - * (Convenience method) Returns an ORM resource model provider for - * the given project in the specified deploy location - */ - public static Orm2_0XmlResourceProvider getXmlResourceProvider(IProject project, String deployLocation) { - return getXmlResourceProvider_(project, JptCorePlugin.getDeploymentURI(project, deployLocation)); - } - - /** - * (Convenience method) Returns an ORM resource model provider for - * the given project in the default deploy location - */ - public static Orm2_0XmlResourceProvider getDefaultXmlResourceProvider(IProject project) { - return getXmlResourceProvider(project, JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - } - - private static Orm2_0XmlResourceProvider getXmlResourceProvider_(IProject project, String location) { - return new Orm2_0XmlResourceProvider(project, new Path(location)); - } - - - public Orm2_0XmlResourceProvider(IProject project) { - this(project, new Path(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH)); - } - - public Orm2_0XmlResourceProvider(IProject project, IPath filePath) { - super(project, filePath, JptCorePlugin.ORM2_0_XML_CONTENT_TYPE); - } - - @Override - protected void populateRoot() { - XmlEntityMappings entityMappings = Orm2_0Factory.eINSTANCE.createXmlEntityMappings(); - entityMappings.setVersion(JPA2_0.SCHEMA_VERSION); - getResourceContents().add(entityMappings); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/persistence/Persistence2_0XmlResourceProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/persistence/Persistence2_0XmlResourceProvider.java deleted file mode 100644 index 8c0ed2577d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/persistence/Persistence2_0XmlResourceProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.jpa2.resource.persistence; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.jpa2.resource.persistence.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.persistence.Persistence2_0Factory; -import org.eclipse.jpt.core.jpa2.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.jpa2.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider; - -public class Persistence2_0XmlResourceProvider - extends AbstractXmlResourceProvider -{ - /** - * (Convenience method) Returns a persistence resource model provider for - * the given file. - */ - public static Persistence2_0XmlResourceProvider getXmlResourceProvider(IFile file) { - return getXmlResourceProvider_(file.getProject(), file.getFullPath().toString()); - } - - /** - * (Convenience method) Returns an persistence resource model provider for - * the given project in the specified deploy location - */ - public static Persistence2_0XmlResourceProvider getXmlResourceProvider(IProject project, String deployLocation) { - return getXmlResourceProvider_(project, JptCorePlugin.getDeploymentURI(project, deployLocation)); - } - - /** - * (Convenience method) Returns a persistence resource model provider for - * the given project in the default deploy location - */ - public static Persistence2_0XmlResourceProvider getDefaultXmlResourceProvider(IProject project) { - return getXmlResourceProvider(project, JptCorePlugin.DEFAULT_PERSISTENCE_XML_FILE_PATH); - } - - private static Persistence2_0XmlResourceProvider getXmlResourceProvider_(IProject project, String location) { - return new Persistence2_0XmlResourceProvider(project, new Path(location)); - } - - - public Persistence2_0XmlResourceProvider(IProject project) { - this(project, new Path(JptCorePlugin.DEFAULT_PERSISTENCE_XML_FILE_PATH)); - } - - public Persistence2_0XmlResourceProvider(IProject project, IPath filePath) { - super(project, filePath, JptCorePlugin.PERSISTENCE2_0_XML_CONTENT_TYPE); - } - - @Override - protected void populateRoot() { - XmlPersistence persistence = Persistence2_0Factory.eINSTANCE.createXmlPersistence(); - persistence.setVersion(JPA2_0.SCHEMA_VERSION); - XmlPersistenceUnit persistenceUnit = Persistence2_0Factory.eINSTANCE.createXmlPersistenceUnit(); - persistenceUnit.setName(getProject().getName()); - persistence.getPersistenceUnits().add(persistenceUnit); - getResourceContents().add(persistence); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java deleted file mode 100644 index 908a3bb0d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java +++ /dev/null @@ -1,46 +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.operations; - -public interface OrmFileCreationDataModelProperties -{ - /** - * Required, type String, identifies the name of the project in which to create the file - */ - public static final String PROJECT_NAME = "OrmFileCreationDataModelProperties.PROJECT_NAME"; - - /** - * Required, type String, identifies the fully pathed source folder in which to create the file - */ - public static final String SOURCE_FOLDER = "OrmFileCreationDataModelProperties.SOURCE_FOLDER"; - - /** - * Required, type String, identifies the file path relative to the source folder - */ - public static final String FILE_PATH = "OrmFileCreationDataModelProperties.FILE_PATH"; - - /** - * Optional, type AccessType, specifies the default access type (or null) - */ - public static final String DEFAULT_ACCESS = "OrmFileCreationDataModelProperties.DEFAULT_ACCESS"; - - /** - * Required, type Boolean, specifies whether to add a reference to the file - * in the persistence unit - */ - public static final String ADD_TO_PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT"; - - /** - * Optional (unless ADD_TO_PERSISTENCE_UNIT property is true), type String, - * identifies the persistence unit to which to add a reference to the file - */ - public static final String PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.PERSISTENCE_UNIT"; -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java deleted file mode 100644 index 8f32742993..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java +++ /dev/null @@ -1,498 +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.operations; - -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -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.JptCoreMessages; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -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.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; -import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; - -public class OrmFileCreationDataModelProvider extends AbstractDataModelProvider - implements OrmFileCreationDataModelProperties -{ - /** - * required default constructor - */ - public OrmFileCreationDataModelProvider() { - super(); - } - - - @Override - public IDataModelOperation getDefaultOperation() { - return new OrmFileCreationOperation(getDataModel()); - } - - @Override - public Set<String> getPropertyNames() { - @SuppressWarnings("unchecked") - Set<String> propertyNames = super.getPropertyNames(); - propertyNames.add(PROJECT_NAME); - propertyNames.add(SOURCE_FOLDER); - propertyNames.add(FILE_PATH); - propertyNames.add(DEFAULT_ACCESS); - propertyNames.add(ADD_TO_PERSISTENCE_UNIT); - propertyNames.add(PERSISTENCE_UNIT); - return propertyNames; - } - - @Override - public boolean isPropertyEnabled(String propertyName) { - if (propertyName.equals(PERSISTENCE_UNIT)) { - return getBooleanProperty(ADD_TO_PERSISTENCE_UNIT); - } - return super.isPropertyEnabled(propertyName); - } - - @Override - public Object getDefaultProperty(String propertyName) { - if (propertyName.equals(SOURCE_FOLDER)) { - IFolder sourceFolder = getDefaultSourceFolder(); - if (sourceFolder != null && sourceFolder.exists()) { - return sourceFolder.getFullPath().toPortableString(); - } - } - else if (propertyName.equals(FILE_PATH)) { - return new Path(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH).toPortableString(); - } - else if (propertyName.equals(DEFAULT_ACCESS)) { - return null; - } - else if (propertyName.equals(ADD_TO_PERSISTENCE_UNIT)) { - return Boolean.FALSE; - } - else if (propertyName.equals(PERSISTENCE_UNIT)) { - PersistenceUnit pUnit = getDefaultPersistenceUnit(); - if (pUnit != null) { - return pUnit.getName(); - } - } - return super.getDefaultProperty(propertyName); - } - - @Override - public boolean propertySet(String propertyName, Object propertyValue) { - boolean ok = super.propertySet(propertyName, propertyValue); - if (propertyName.equals(PROJECT_NAME)) { - this.model.notifyPropertyChange(SOURCE_FOLDER, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(PERSISTENCE_UNIT, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(PERSISTENCE_UNIT, IDataModel.VALID_VALUES_CHG); - } - else if (propertyName.equals(ADD_TO_PERSISTENCE_UNIT)) { - this.model.notifyPropertyChange(PERSISTENCE_UNIT, IDataModel.ENABLE_CHG); - } - return ok; - } - - @Override - public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { - if (propertyName.equals(PROJECT_NAME)) { - return ArrayTools.array( - new TransformationIterator<IProject, DataModelPropertyDescriptor>(jpaIProjects()) { - @Override - protected DataModelPropertyDescriptor transform(IProject next) { - return new DataModelPropertyDescriptor(next.getName()); - } - }, - new DataModelPropertyDescriptor[0]); - } - else if (propertyName.equals(DEFAULT_ACCESS)) { - DataModelPropertyDescriptor[] accessTypes = new DataModelPropertyDescriptor[3]; - accessTypes[0] = accessPropertyDescriptor(null); - accessTypes[1] = accessPropertyDescriptor(AccessType.FIELD); - accessTypes[2] = accessPropertyDescriptor(AccessType.PROPERTY); - return accessTypes; - } - else if (propertyName.equals(PERSISTENCE_UNIT)) { - return ArrayTools.array( - new TransformationIterator<String, DataModelPropertyDescriptor>(new CompositeIterator<String>(null, persistenceUnitNames())) { - @Override - protected DataModelPropertyDescriptor transform(String next) { - return persistenceUnitPropertyDescriptor(next); - } - }, - new DataModelPropertyDescriptor[0]); - - } - return super.getValidPropertyDescriptors(propertyName); - } - - @Override - public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { - if (propertyName.equals(PROJECT_NAME)) { - return new DataModelPropertyDescriptor(getStringProperty(PROJECT_NAME)); - } - else if (propertyName.equals(DEFAULT_ACCESS)) { - return accessPropertyDescriptor((AccessType) getProperty(DEFAULT_ACCESS)); - } - else if (propertyName.equals(PERSISTENCE_UNIT)) { - return persistenceUnitPropertyDescriptor(getStringProperty(PERSISTENCE_UNIT)); - } - return super.getPropertyDescriptor(propertyName); - } - - protected DataModelPropertyDescriptor accessPropertyDescriptor(AccessType accessType) { - if (accessType == null) { - return new DataModelPropertyDescriptor(null, JptCoreMessages.NONE); - } - return new DataModelPropertyDescriptor(accessType, accessType.getName()); - } - - DataModelPropertyDescriptor persistenceUnitPropertyDescriptor(String persistenceUnitName) { - if (StringTools.stringIsEmpty(persistenceUnitName)) { - return new DataModelPropertyDescriptor(null, JptCoreMessages.NONE); - } - return new DataModelPropertyDescriptor(persistenceUnitName); - } - - - // **************** validation ********************************************* - - @Override - public IStatus validate(String propertyName) { - if (propertyName.equals(PROJECT_NAME) - || propertyName.equals(SOURCE_FOLDER) - || propertyName.equals(FILE_PATH)) { - return validateProjectSourceFolderAndFilePath(); - } - else if (propertyName.equals(ADD_TO_PERSISTENCE_UNIT) - || propertyName.equals(PERSISTENCE_UNIT)) { - return validatePersistenceUnit(); - } - return super.validate(propertyName); - } - - protected IStatus validateProjectSourceFolderAndFilePath() { - String projectName = (String) getProperty(PROJECT_NAME); - if (StringTools.stringIsEmpty(projectName)) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_PROJECT_NOT_SPECIFIED); - } - String sourceFolderPath = getStringProperty(SOURCE_FOLDER); - if (StringTools.stringIsEmpty(sourceFolderPath)) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_SOURCE_FOLDER_NOT_SPECIFIED); - } - if (sourceFolderIsIllegal(sourceFolderPath)) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_SOURCE_FOLDER_ILLEGAL); - } - if (sourceFolderNotInProject(sourceFolderPath)) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - NLS.bind( - JptCoreMessages.VALIDATE_SOURCE_FOLDER_NOT_IN_PROJECT, - sourceFolderPath, projectName)); - } - if (getVerifiedSourceFolder() == null) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - NLS.bind(JptCoreMessages.VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST, sourceFolderPath)); - } - if (getVerifiedJavaSourceFolder() == null) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - NLS.bind(JptCoreMessages.VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER, sourceFolderPath)); - } - String filePath = getStringProperty(FILE_PATH); - if (StringTools.stringIsEmpty(filePath)) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_FILE_PATH_NOT_SPECIFIED); - } - if (getExistingOrmFile() != null) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_ORM_FILE_ALREADY_EXISTS); - } - return Status.OK_STATUS; - } - - protected IStatus validatePersistenceUnit() { - boolean addToPUnit = getBooleanProperty(ADD_TO_PERSISTENCE_UNIT); - String projectName = getStringProperty(PROJECT_NAME); - String pUnitName = getStringProperty(PERSISTENCE_UNIT); - if (addToPUnit) { - if (StringTools.stringIsEmpty(pUnitName)) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - NLS.bind(JptCoreMessages.VALIDATE_PERSISTENCE_UNIT_DOES_NOT_SPECIFIED, pUnitName)); - } - if (getPersistenceUnit() == null) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - NLS.bind(JptCoreMessages.VALIDATE_PERSISTENCE_UNIT_NOT_IN_PROJECT, pUnitName, projectName)); - } - } - return Status.OK_STATUS; - } - - - // **************** helper methods ***************************************** - - // Copied from ArtifactEditOperationDataModelProvider - protected IProject getProject() { - String projectName = (String) model.getProperty(PROJECT_NAME); - if (StringTools.stringIsEmpty(projectName)) { - return null; - } - return ProjectUtilities.getProject(projectName); - } - - protected JpaProject getJpaProject() { - IProject project = getProject(); - if (project == null) { - return null; - } - return JptCorePlugin.getJpaProject(project); - } - - /** - * Return a best guess java source folder for the specified project - */ - // Copied from NewJavaClassDataModelProvider - protected IFolder getDefaultSourceFolder() { - IProject project = getProject(); - if (project == null) { - return null; - } - IPackageFragmentRoot[] sources = J2EEProjectUtilities.getSourceContainers(project); - // Try and return the first source folder - if (sources.length > 0) { - try { - return (IFolder) sources[0].getCorrespondingResource(); - } catch (Exception e) { - return null; - } - } - return null; - } - - /** - * Return whether the path provided can not be a valid IFolder path - */ - protected boolean sourceFolderIsIllegal(String folderPath) { - IProject project = getProject(); - if (project == null) { - return false; - } - try { - project.getWorkspace().getRoot().getFolder(new Path(folderPath)); - } - catch (IllegalArgumentException e) { - return true; - } - return false; - } - - /** - * Return whether the path provided is in the current project - */ - protected boolean sourceFolderNotInProject(String folderPath) { - IProject project = getProject(); - if (project == null) { - return false; - } - IFolder folder; - try { - folder = project.getWorkspace().getRoot().getFolder(new Path(folderPath)); - } - catch (IllegalArgumentException e) { - return false; - } - return ! project.equals(folder.getProject()); - } - - /** - * Return an IFolder represented by the SOURCE_FOLDER property, verified - * to exist - */ - protected IFolder getVerifiedSourceFolder() { - String folderPath = getStringProperty(SOURCE_FOLDER); - IProject project = getProject(); - if (project == null) { - return null; - } - IFolder folder; - try { - folder = project.getWorkspace().getRoot().getFolder(new Path(folderPath)); - } - catch (IllegalArgumentException e) { - return null; - } - if (folder == null || ! folder.exists()) { - return null; - } - return folder; - } - - /** - * Return the source folder, provided it is verified to be an actual java - * source folder - */ - protected IFolder getVerifiedJavaSourceFolder() { - IFolder folder = getVerifiedSourceFolder(); - if (folder == null) { - return null; - } - IJavaProject jProject = JavaCore.create(getProject()); - if (jProject == null) { - return null; - } - IPackageFragmentRoot packageFragmentRoot = jProject.getPackageFragmentRoot(folder); - if (packageFragmentRoot == null || ! packageFragmentRoot.exists()) { - return null; - } - return folder; - } - - protected IFile getExistingOrmFile() { - IFolder folder = getVerifiedSourceFolder(); - if (folder == null) { - return null; - } - String filePath = getStringProperty(FILE_PATH); - IFile existingFile = folder.getFile(new Path(filePath)); - if (! existingFile.exists()) { - return null; - } - return existingFile; - } - - protected PersistenceUnit getDefaultPersistenceUnit() { - JpaProject jpaProject = getJpaProject(); - if (jpaProject == null) { - return null; - } - PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml(); - if (persistenceXml == null) { - return null; - } - Persistence persistence = persistenceXml.getPersistence(); - if (persistence == null) { - return null; - } - if (persistence.persistenceUnitsSize() == 0) { - return null; - } - return persistence.persistenceUnits().next(); - } - - protected PersistenceUnit getPersistenceUnit() { - String pUnitName = getStringProperty(PERSISTENCE_UNIT); - JpaProject jpaProject = - (StringTools.stringIsEmpty(pUnitName)) ? null : getJpaProject(); - PersistenceXml persistenceXml = - (jpaProject == null) ? null : jpaProject.getRootContextNode().getPersistenceXml(); - Persistence persistence = - (persistenceXml == null) ? null : persistenceXml.getPersistence(); - if (persistence != null) { - for (Iterator<PersistenceUnit> stream = persistence.persistenceUnits(); stream.hasNext(); ) { - PersistenceUnit next = stream.next(); - if (pUnitName.equals(next.getName())) { - return next; - } - } - } - return null; - } - - protected Iterator<IProject> jpaIProjects() { - return new FilteringIterator<IProject, IProject>(this.allIProjects(), this.buildJpaIProjectsFilter()); - } - - protected Iterator<IProject> allIProjects() { - return CollectionTools.iterator(ProjectUtilities.getAllProjects()); - } - - protected Filter<IProject> buildJpaIProjectsFilter() { - return new JpaIProjectsFilter(); - } - - protected class JpaIProjectsFilter implements Filter<IProject> { - public boolean accept(IProject project) { - try { - return this.accept_(project); - } catch (CoreException ex) { - return false; - } - } - protected boolean accept_(IProject project) throws CoreException { - return hasJpaFacet(project) && hasSupportedPlatformId(project); - } - } - - protected boolean hasJpaFacet(IProject project) throws CoreException { - return FacetedProjectFramework.hasProjectFacet(project, JptCorePlugin.FACET_ID); - } - - protected boolean hasSupportedPlatformId(IProject project) { - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - return (jpaProject != null) && isSupportedPlatformId(jpaProject.getJpaPlatform().getId()); - } - - protected boolean isSupportedPlatformId(String id) { - return true; - } - - protected Iterator<PersistenceUnit> persistenceUnits() { - //only get the persistence units for the selected JpaProject, - //if no jpa project is selected, then no persistence units will be listed in the combo - JpaProject jpaProject = getJpaProject(); - PersistenceXml persistenceXml = (jpaProject == null) ? null : jpaProject.getRootContextNode().getPersistenceXml(); - Persistence persistence = (persistenceXml == null) ? null : persistenceXml.getPersistence(); - return (persistence == null) ? EmptyIterator.<PersistenceUnit>instance() : persistence.persistenceUnits(); - } - - protected Iterator<String> persistenceUnitNames() { - return new TransformationIterator<PersistenceUnit, String>(persistenceUnits()) { - @Override - protected String transform(PersistenceUnit next) { - return next.getName(); - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationOperation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationOperation.java deleted file mode 100644 index b60be017d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationOperation.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.operations; - -import java.util.Iterator; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -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.resource.orm.OrmXmlResourceProvider; -import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider; -import org.eclipse.jpt.core.resource.orm.AccessType; -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.resource.xml.JpaXmlResource; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public class OrmFileCreationOperation extends AbstractDataModelOperation - implements OrmFileCreationDataModelProperties -{ - public OrmFileCreationOperation(IDataModel dataModel) { - super(dataModel); - } - - - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // Create source folder if it does not exist - IFolder folder = createSourceFolder(); - // Create orm file - IFile file = createMappingFile(folder); - // Add orm file to persistence unit if specified - addMappingFileToPersistenceXml(file); - return OK_STATUS; - } - - protected IProject getProject() throws ExecutionException { - String projectName = (String) getDataModel().getProperty(PROJECT_NAME); - IProject project = ProjectUtilities.getProject(projectName); - if (project == null) { - throw new ExecutionException("No project name specified"); //$NON-NLS-1$ - } - return project; - } - - protected JpaProject getJpaProject() throws ExecutionException { - IProject project = getProject(); - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - if (jpaProject == null) { - throw new ExecutionException("Project does not have JPA content"); //$NON-NLS-1$ - } - return jpaProject; - } - - protected PersistenceUnit getPersistenceUnit() throws ExecutionException { - String pUnitName = getDataModel().getStringProperty(PERSISTENCE_UNIT); - JpaProject jpaProject = getJpaProject(); - PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml(); - if (persistenceXml == null) { - throw new ExecutionException("Project does not have a persistence.xml file"); //$NON-NLS-1$ - } - Persistence persistence = persistenceXml.getPersistence(); - if (persistence == null) { - throw new ExecutionException("persistence.xml does not have a persistence node."); //$NON-NLS-1$ - } - for (Iterator<PersistenceUnit> stream = persistence.persistenceUnits(); stream.hasNext(); ) { - PersistenceUnit pUnit = stream.next(); - if (pUnitName.equals(pUnit.getName())) { - return pUnit; - } - } - throw new ExecutionException("persistence.xml does not have persistence unit named \'" + pUnitName + "\'"); //$NON-NLS-1$ - } - - /** - * This method will return the source folder as specified in the data model. - * It will create the source folder if it does not exist. It will not add - * it as a source folder to the project build path if it is not already. - * This method may return null. - */ - // copied from NewJavaClassOperation - protected IFolder createSourceFolder() throws ExecutionException { - // Get the source folder name from the data model - String folderPath = model.getStringProperty(SOURCE_FOLDER); - IProject project = getProject(); - IFolder folder = project.getWorkspace().getRoot().getFolder(new Path(folderPath)); - // If folder does not exist, create the folder with the specified path - if (! folder.exists()) { - try { - folder.create(true, true, null); - } catch (CoreException e) { - throw new ExecutionException("Could not create folder", e); //$NON-NLS-1$ - } - } - // Return the source folder - return folder; - } - - protected IFile createMappingFile(IFolder folder) { - String filePath = getDataModel().getStringProperty(FILE_PATH); - IFile file = folder.getFile(new Path(filePath)); - final AbstractXmlResourceProvider resourceProvider = getXmlResourceProvider(file); - final JpaXmlResource xmlResource; - try { - xmlResource = resourceProvider.createFileAndResource(); - } - catch (CoreException e) { - JptCorePlugin.log(e); - return null; - } - xmlResource.modify(new Runnable() { - public void run() { - AccessType defaultAccess = (AccessType) getDataModel().getProperty(DEFAULT_ACCESS); - if (defaultAccess != null) { - XmlPersistenceUnitMetadata puMetadata = createXmlPersistenceUnitMetadata(); - ((XmlEntityMappings) xmlResource.getRootObject()).setPersistenceUnitMetadata(puMetadata); - XmlPersistenceUnitDefaults puDefaults = createXmlPersistenceUnitDefaults(); - puMetadata.setPersistenceUnitDefaults(puDefaults); - puDefaults.setAccess(defaultAccess); - } - } - }); - return file; - } - - protected XmlPersistenceUnitMetadata createXmlPersistenceUnitMetadata() { - return OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - } - - protected XmlPersistenceUnitDefaults createXmlPersistenceUnitDefaults() { - return OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - } - - protected AbstractXmlResourceProvider getXmlResourceProvider(IFile file) { - return OrmXmlResourceProvider.getXmlResourceProvider(file); - } - - protected void addMappingFileToPersistenceXml(IFile file) throws ExecutionException { - if (! getDataModel().getBooleanProperty(ADD_TO_PERSISTENCE_UNIT)) { - return; - } - JpaProject jpaProject = JptCorePlugin.getJpaProject(file.getProject()); - JpaXmlResource resource = jpaProject.getPersistenceXmlResource(); - - final PersistenceUnit pUnit = getPersistenceUnit(); - - resource.modify(new Runnable() { - public void run() { - String filePath = getDataModel().getStringProperty(FILE_PATH); - for (Iterator<MappingFileRef> stream = pUnit.specifiedMappingFileRefs(); stream.hasNext(); ) { - if (filePath.equals(stream.next().getFileName())) { - return; - } - } - MappingFileRef mfRef = pUnit.addSpecifiedMappingFileRef(); - mfRef.setFileName(new Path(filePath).toPortableString()); - } - }); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java deleted file mode 100644 index fda01b3469..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.prefs; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.jpt.core.JptCorePlugin; - -/** - * Class used to initialize default preference values. - * See <code>org.eclipse.core.runtime.preferences</code> extension point. - */ -public class JpaPreferenceInitializer - extends AbstractPreferenceInitializer -{ - @Override - public void initializeDefaultPreferences() { - JptCorePlugin.initializeDefaultPreferences(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/IndeterminateContentDescriber.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/IndeterminateContentDescriber.java deleted file mode 100644 index 6184852469..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/IndeterminateContentDescriber.java +++ /dev/null @@ -1,38 +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.resource; - -import java.io.InputStream; -import java.io.Reader; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.ITextContentDescriber; - -/** - * This class simply returns INDETERMINATE for any contents it receives. - * - * It is used currently for org.eclipse.jpt.core.content.baseJpaContent in order - * to make that content type act as an "abstract" content type. - */ -public class IndeterminateContentDescriber implements ITextContentDescriber -{ - public int describe(InputStream contents, IContentDescription description) { - return INDETERMINATE; - } - - public int describe(Reader contents, IContentDescription description) { - return INDETERMINATE; - } - - public QualifiedName[] getSupportedOptions() { - return new QualifiedName[0]; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.java deleted file mode 100644 index f047f4d8ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.CallbackChangeSupport; -import org.eclipse.jpt.utility.internal.model.ChangeSupport; - -/** - * Java resource containment hierarchy - */ -public abstract class AbstractJavaResourceNode - extends AbstractModel - implements JavaResourceNode -{ - protected final JavaResourceNode parent; - - - // ********** constructor ********** - - protected AbstractJavaResourceNode(JavaResourceNode parent) { - super(); - this.checkParent(parent); - this.parent = parent; - } - - - // ********** parent ********** - - protected void checkParent(JavaResourceNode p) { - if (p == null) { - if (this.requiresParent()) { - throw new IllegalArgumentException("'parent' cannot be null"); //$NON-NLS-1$ - } - } else { - if (this.forbidsParent()) { - throw new IllegalArgumentException("'parent' must be null"); //$NON-NLS-1$ - } - } - } - - protected boolean requiresParent() { - return true; - } - - protected boolean forbidsParent() { - return ! this.requiresParent(); // assume 'parent' is not optional - } - - - // ********** change support callback hook ********** - - @Override - protected final ChangeSupport buildChangeSupport() { - return new CallbackChangeSupport(this, this.buildChangeSupportListener()); - } - - private CallbackChangeSupport.Listener buildChangeSupportListener() { - return new CallbackChangeSupport.Listener() { - public void aspectChanged(String aspectName) { - AbstractJavaResourceNode.this.aspectChanged(aspectName); - } - }; - } - - /** - * ignore the aspect name, we notify listeners of *every* change - */ - protected void aspectChanged(@SuppressWarnings("unused") String aspectName) { - this.getRoot().resourceModelChanged(); - } - - - // ********** JavaResourceNode implementation ********** - - /** - * @see org.eclipse.jpt.core.internal.resource.java.source.SourceCompilationUnit#getRoot() - * @see org.eclipse.jpt.core.internal.resource.java.binary.BinaryPackageFragmentRoot#getRoot() - * @see org.eclipse.jpt.core.internal.resource.java.binary.BinaryPersistentTypeCache#getRoot() - */ - public Root getRoot() { - return this.parent.getRoot(); - } - - public IFile getFile() { - return this.getRoot().getFile(); - } - - - // ********** convenience methods ********** - - protected JpaAnnotationProvider getAnnotationProvider() { - return this.getRoot().getAnnotationProvider(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverrideAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverrideAnnotationDefinition.java deleted file mode 100644 index 9fc26e3348..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverrideAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.jpa1.resource.java.binary.BinaryAssociationOverride1_0Annotation; -import org.eclipse.jpt.core.internal.jpa1.resource.java.source.SourceAssociationOverride1_0Annotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AssociationOverride - */ -public final class AssociationOverrideAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new AssociationOverrideAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private AssociationOverrideAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourceAssociationOverride1_0Annotation.buildAssociationOverride(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryAssociationOverride1_0Annotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return AssociationOverrideAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverridesAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverridesAnnotationDefinition.java deleted file mode 100644 index 2fd18af99f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverridesAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.jpa1.resource.java.binary.BinaryAssociationOverrides1_0Annotation; -import org.eclipse.jpt.core.internal.jpa1.resource.java.source.SourceAssociationOverrides1_0Annotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AssociationOverrides - */ -public final class AssociationOverridesAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new AssociationOverridesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private AssociationOverridesAnnotationDefinition() { - super(); - } - - public AssociationOverridesAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceAssociationOverrides1_0Annotation(parent, member); - } - - public AssociationOverridesAnnotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryAssociationOverrides1_0Annotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return AssociationOverridesAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverrideAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverrideAnnotationDefinition.java deleted file mode 100644 index 03b83f682e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverrideAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAttributeOverrideAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceAttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AttributeOverride - */ -public final class AttributeOverrideAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new AttributeOverrideAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private AttributeOverrideAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourceAttributeOverrideAnnotation.buildAttributeOverride(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryAttributeOverrideAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return AttributeOverrideAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverridesAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverridesAnnotationDefinition.java deleted file mode 100644 index 27c8986fcb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverridesAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAttributeOverridesAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceAttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AttributeOverrides - */ -public final class AttributeOverridesAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new AttributeOverridesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private AttributeOverridesAnnotationDefinition() { - super(); - } - - public AttributeOverridesAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceAttributeOverridesAnnotation(parent, member); - } - - public AttributeOverridesAnnotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryAttributeOverridesAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return AttributeOverridesAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BasicAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BasicAnnotationDefinition.java deleted file mode 100644 index 989aa71ed0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BasicAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryBasicAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceBasicAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Basic - */ -public final class BasicAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new BasicAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private BasicAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceBasicAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullBasicAnnotation((JavaResourcePersistentAttribute) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryBasicAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return BasicAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnAnnotationDefinition.java deleted file mode 100644 index 219c98745c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryColumnAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceColumnAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Column - */ -public final class ColumnAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new ColumnAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private ColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceColumnAnnotation(parent, member, SourceColumnAnnotation.MAPPING_DECLARATION_ANNOTATION_ADAPTER); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullColumnAnnotation(parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryColumnAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ColumnAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorColumnAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorColumnAnnotationDefinition.java deleted file mode 100644 index ff4ec04c77..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorColumnAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryDiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceDiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.DiscriminatorColumn - */ -public final class DiscriminatorColumnAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new DiscriminatorColumnAnnotationDefinition(); - - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private DiscriminatorColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceDiscriminatorColumnAnnotation((JavaResourcePersistentType) parent, member, SourceDiscriminatorColumnAnnotation.DECLARATION_ANNOTATION_ADAPTER); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullDiscriminatorColumnAnnotation((JavaResourcePersistentType) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryDiscriminatorColumnAnnotation((JavaResourcePersistentType) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return DiscriminatorColumnAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorValueAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorValueAnnotationDefinition.java deleted file mode 100644 index ea12342ee1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorValueAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryDiscriminatorValueAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceDiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.DiscriminatorValue - */ -public final class DiscriminatorValueAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new DiscriminatorValueAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private DiscriminatorValueAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceDiscriminatorValueAnnotation(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullDiscriminatorValueAnnotation((JavaResourcePersistentType) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryDiscriminatorValueAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return DiscriminatorValueAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddableAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddableAnnotationDefinition.java deleted file mode 100644 index fd7dbfa3c7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddableAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryEmbeddableAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceEmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.Embeddable - */ -public final class EmbeddableAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new EmbeddableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private EmbeddableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceEmbeddableAnnotation((JavaResourcePersistentType) parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryEmbeddableAnnotation((JavaResourcePersistentType) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return EmbeddableAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedAnnotationDefinition.java deleted file mode 100644 index 1a3889fe3c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryEmbeddedAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceEmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Embedded - */ -public final class EmbeddedAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new EmbeddedAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private EmbeddedAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceEmbeddedAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullEmbeddedAnnotation((JavaResourcePersistentAttribute) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryEmbeddedAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return EmbeddedAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedIdAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedIdAnnotationDefinition.java deleted file mode 100644 index 741375240d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedIdAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryEmbeddedIdAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceEmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.EmbeddedId - */ -public final class EmbeddedIdAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new EmbeddedIdAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private EmbeddedIdAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceEmbeddedIdAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryEmbeddedIdAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return EmbeddedIdAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EntityAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EntityAnnotationDefinition.java deleted file mode 100644 index 7c4f432ffe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EntityAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryEntityAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceEntityAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.Entity - */ -public final class EntityAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new EntityAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private EntityAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceEntityAnnotation((JavaResourcePersistentType) parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryEntityAnnotation((JavaResourcePersistentType) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EnumeratedAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EnumeratedAnnotationDefinition.java deleted file mode 100644 index 5146a6d178..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EnumeratedAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryEnumeratedAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceEnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Enumerated - */ -public final class EnumeratedAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new EnumeratedAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private EnumeratedAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceEnumeratedAnnotation(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullEnumeratedAnnotation((JavaResourcePersistentAttribute) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryEnumeratedAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return EnumeratedAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueAnnotationDefinition.java deleted file mode 100644 index 7026476532..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryGeneratedValueAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceGeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.GeneratedValue - */ -public final class GeneratedValueAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new GeneratedValueAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private GeneratedValueAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceGeneratedValueAnnotation(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryGeneratedValueAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return GeneratedValueAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdAnnotationDefinition.java deleted file mode 100644 index 12ebf03b98..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryIdAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceIdAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Id - */ -public final class IdAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new IdAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private IdAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceIdAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryIdAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return IdAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdClassAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdClassAnnotationDefinition.java deleted file mode 100644 index 5e99e4c3e0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdClassAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryIdClassAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceIdClassAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.IdClass - */ -public final class IdClassAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new IdClassAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private IdClassAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceIdClassAnnotation(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryIdClassAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return IdClassAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/InheritanceAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/InheritanceAnnotationDefinition.java deleted file mode 100644 index 297ae12fa7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/InheritanceAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryInheritanceAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceInheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.Inheritance - */ -public final class InheritanceAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new InheritanceAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private InheritanceAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceInheritanceAnnotation((JavaResourcePersistentType) parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullInheritanceAnnotation((JavaResourcePersistentType) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryInheritanceAnnotation((JavaResourcePersistentType) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return InheritanceAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnAnnotationDefinition.java deleted file mode 100644 index c2c248a86c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryJoinColumnAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.JoinColumn - */ -public final class JoinColumnAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new JoinColumnAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private JoinColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourceJoinColumnAnnotation.createJoinColumn(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryJoinColumnAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return JoinColumnAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnsAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnsAnnotationDefinition.java deleted file mode 100644 index 1c00f40fde..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnsAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryJoinColumnsAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.JoinColumns - */ -public final class JoinColumnsAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new JoinColumnsAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private JoinColumnsAnnotationDefinition() { - super(); - } - - public JoinColumnsAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceJoinColumnsAnnotation(parent, member); - } - - public JoinColumnsAnnotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryJoinColumnsAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return JoinColumnsAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinTableAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinTableAnnotationDefinition.java deleted file mode 100644 index a58445ec6a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinTableAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryJoinTableAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceJoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.JoinTable - */ -public final class JoinTableAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new JoinTableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private JoinTableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceJoinTableAnnotation(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullJoinTableAnnotation(parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryJoinTableAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return JoinTableAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/LobAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/LobAnnotationDefinition.java deleted file mode 100644 index 29022f2c7a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/LobAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryLobAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceLobAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.LobAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Lob - */ -public final class LobAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new LobAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private LobAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceLobAnnotation(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryLobAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return LobAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToManyAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToManyAnnotationDefinition.java deleted file mode 100644 index a10d93fec5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToManyAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryManyToManyAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.ManyToMany - */ -public final class ManyToManyAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new ManyToManyAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private ManyToManyAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceManyToManyAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryManyToManyAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ManyToManyAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToOneAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToOneAnnotationDefinition.java deleted file mode 100644 index 140d7977b8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToOneAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryManyToOneAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.ManyToOne - */ -public final class ManyToOneAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new ManyToOneAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private ManyToOneAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceManyToOneAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryManyToOneAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ManyToOneAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MapKeyAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MapKeyAnnotationDefinition.java deleted file mode 100644 index 03c6ff8b36..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MapKeyAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryMapKeyAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceMapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.MapKey - */ -public final class MapKeyAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new MapKeyAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private MapKeyAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceMapKeyAnnotation(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryMapKeyAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return MapKeyAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MappedSuperclassAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MappedSuperclassAnnotationDefinition.java deleted file mode 100644 index c6452c9e68..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MappedSuperclassAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryMappedSuperclassAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceMappedSuperclassAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.MappedSuperclass - */ -public final class MappedSuperclassAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new MappedSuperclassAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private MappedSuperclassAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceMappedSuperclassAnnotation((JavaResourcePersistentType) parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryMappedSuperclassAnnotation((JavaResourcePersistentType) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return MappedSuperclassAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueriesAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueriesAnnotationDefinition.java deleted file mode 100644 index 21d55cb918..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueriesAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryNamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceNamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.NamedNativeQueries - */ -public final class NamedNativeQueriesAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new NamedNativeQueriesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NamedNativeQueriesAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceNamedNativeQueriesAnnotation(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryNamedNativeQueriesAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return NamedNativeQueriesAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueryAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueryAnnotationDefinition.java deleted file mode 100644 index db6d640c07..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueryAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryNamedNativeQueryAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceNamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.NamedNativeQuery - */ -public final class NamedNativeQueryAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new NamedNativeQueryAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NamedNativeQueryAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourceNamedNativeQueryAnnotation.createNamedNativeQuery(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryNamedNativeQueryAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return NamedNativeQueryAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueriesAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueriesAnnotationDefinition.java deleted file mode 100644 index 6220ca19d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueriesAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryNamedQueriesAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceNamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.NamedQueries - */ -public final class NamedQueriesAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new NamedQueriesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NamedQueriesAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceNamedQueriesAnnotation(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryNamedQueriesAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return NamedQueriesAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueryAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueryAnnotationDefinition.java deleted file mode 100644 index 2b40783b96..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueryAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryNamedQueryAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceNamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.NamedQuery - */ -public final class NamedQueryAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new NamedQueryAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NamedQueryAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourceNamedQueryAnnotation.createNamedQuery(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryNamedQueryAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return NamedQueryAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAnnotation.java deleted file mode 100644 index 3fc989ff90..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAnnotation.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * Simplify null annotation classes - */ -public abstract class NullAnnotation - extends AbstractJavaResourceNode - implements Annotation -{ - - protected NullAnnotation(JavaResourceNode parent) { - super(parent); - } - - public void initialize(CompilationUnit astRoot) { - // do nothing - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public JavaResourceCompilationUnit getJavaResourceCompilationUnit() { - throw new UnsupportedOperationException(); - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - /** - * Convenience method: Cast the annotation's parent to a - * persistent member. - */ - protected JavaResourcePersistentMember getMember() { - return (JavaResourcePersistentMember) this.parent; - } - - /** - * Convenience method: Add the type or attribute's annotation - * and return it. - * Pre-condition: The annotation's parent must be a persistent member - * (type or attribute). - */ - protected Annotation addAnnotation() { - return this.getMember().addAnnotation(this.getAnnotationName()); - } - - /** - * Convenience method: Add the type or attribute's annotation - * and return it. - * Pre-condition: The annotation's parent must be a persistent member - * (type or attribute). - */ - protected Annotation addAnnotation( - JavaResourcePersistentMember.AnnotationInitializer initializer) { - return this.getMember().addAnnotation(this.getAnnotationName(), initializer); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumnAnnotation.java deleted file mode 100644 index 85f0c6fe08..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumnAnnotation.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; - -/** - * javax.persistence.Column - */ -public class NullAttributeOverrideColumnAnnotation - extends NullColumnAnnotation -{ - public NullAttributeOverrideColumnAnnotation(AttributeOverrideAnnotation parent) { - super(parent); - } - - private AttributeOverrideAnnotation getAttributeOverrideAnnotation() { - return (AttributeOverrideAnnotation) this.parent; - } - - @Override - protected ColumnAnnotation addAnnotation() { - return this.getAttributeOverrideAnnotation().addColumn(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumnAnnotation.java deleted file mode 100644 index 477b7f8da0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumnAnnotation.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BaseColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Column - * javax.persistence.JoinColumn - */ -public abstract class NullBaseColumnAnnotation - extends NullNamedColumnAnnotation - implements BaseColumnAnnotation -{ - protected NullBaseColumnAnnotation(JavaResourceNode parent) { - super(parent); - } - - @Override - protected BaseColumnAnnotation addAnnotation() { - return (BaseColumnAnnotation) super.addAnnotation(); - } - - // ***** table - public String getTable() { - return null; - } - - public void setTable(String table) { - if (table != null) { - this.addAnnotation().setTable(table); - } - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - return false; - } - - // ***** unique - public Boolean getUnique() { - return null; - } - - public void setUnique(Boolean unique) { - if (unique != null) { - this.addAnnotation().setUnique(unique); - } - } - - public TextRange getUniqueTextRange(CompilationUnit astRoot) { - return null; - } - - // ***** updatable - public Boolean getUpdatable() { - return null; - } - - public void setUpdatable(Boolean updatable) { - if (updatable != null) { - this.addAnnotation().setUpdatable(updatable); - } - } - - public TextRange getUpdatableTextRange(CompilationUnit astRoot) { - return null; - } - - // ***** insertable - public Boolean getInsertable() { - return null; - } - - public void setInsertable(Boolean insertable) { - if (insertable != null) { - this.addAnnotation().setInsertable(insertable); - } - } - - public TextRange getInsertableTextRange(CompilationUnit astRoot) { - return null; - } - - // ***** nullable - public Boolean getNullable() { - return null; - } - - public void setNullable(Boolean nullable) { - if (nullable != null) { - this.addAnnotation().setNullable(nullable); - } - } - - public TextRange getNullableTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTableAnnotation.java deleted file mode 100644 index 93160b0452..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTableAnnotation.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BaseTableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -/** - * javax.persistence.Table - * javax.persistence.JoinTable - */ -public abstract class NullBaseTableAnnotation - extends NullAnnotation - implements BaseTableAnnotation -{ - protected NullBaseTableAnnotation(JavaResourceNode parent) { - super(parent); - } - - @Override - protected BaseTableAnnotation addAnnotation() { - return (BaseTableAnnotation) super.addAnnotation(); - } - - public boolean isSpecified() { - return false; - } - - // ***** name - public String getName() { - return null; - } - - public void setName(String name) { - if (name != null) { - this.addAnnotation().setName(name); - } - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return false; - } - - // ***** schema - public String getSchema() { - return null; - } - - public void setSchema(String schema) { - if (schema != null) { - this.addAnnotation().setSchema(schema); - } - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return false; - } - - // ***** catalog - public String getCatalog() { - return null; - } - - public void setCatalog(String catalog) { - if (catalog != null) { - this.addAnnotation().setCatalog(catalog); - } - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return false; - } - - // ***** unique constraints - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return EmptyListIterator.instance(); - } - - public int uniqueConstraintsSize() { - return 0; - } - - public UniqueConstraintAnnotation uniqueConstraintAt(int index) { - throw new UnsupportedOperationException(); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - throw new UnsupportedOperationException(); - } - - public UniqueConstraintAnnotation addUniqueConstraint(int index) { - return this.addAnnotation().addUniqueConstraint(index); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeUniqueConstraint(int index) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasicAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasicAnnotation.java deleted file mode 100644 index 0e16de1e07..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasicAnnotation.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * null javax.persistence.Basic - */ -public final class NullBasicAnnotation - extends NullAnnotation - implements BasicAnnotation -{ - protected NullBasicAnnotation(JavaResourcePersistentAttribute parent) { - super(parent); - } - - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected BasicAnnotation addAnnotation() { - return (BasicAnnotation) super.addAnnotation(); - } - - - // ***** fetch - - public FetchType getFetch() { - return null; - } - - public void setFetch(FetchType fetch) { - if (fetch != null) { - this.addAnnotation().setFetch(fetch); - } - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - return null; - } - - - // ***** optional - - public Boolean getOptional() { - return null; - } - - public void setOptional(Boolean optional) { - if (optional != null) { - this.addAnnotation().setOptional(optional); - } - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumnAnnotation.java deleted file mode 100644 index 3bf5452a0b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumnAnnotation.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Column - */ -public class NullColumnAnnotation - extends NullBaseColumnAnnotation - implements ColumnAnnotation -{ - public NullColumnAnnotation(JavaResourceNode parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected ColumnAnnotation addAnnotation() { - return (ColumnAnnotation) super.addAnnotation(); - } - - // ***** length - public Integer getLength() { - return null; - } - - public void setLength(Integer length) { - if (length != null) { - this.addAnnotation().setLength(length); - } - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - return null; - } - - // ***** scale - public Integer getScale() { - return null; - } - - public void setScale(Integer scale) { - if (scale != null) { - this.addAnnotation().setScale(scale); - } - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - return null; - } - - // ***** precision - public Integer getPrecision() { - return null; - } - - public void setPrecision(Integer precision) { - if (precision != null) { - this.addAnnotation().setPrecision(precision); - } - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumnAnnotation.java deleted file mode 100644 index 126ad60814..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumnAnnotation.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -/** - * javax.persistence.DiscriminatorColumn - */ -public final class NullDiscriminatorColumnAnnotation - extends NullNamedColumnAnnotation - implements DiscriminatorColumnAnnotation -{ - public NullDiscriminatorColumnAnnotation(JavaResourcePersistentType parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected DiscriminatorColumnAnnotation addAnnotation() { - return (DiscriminatorColumnAnnotation) super.addAnnotation(); - } - - // ***** discriminator type - public DiscriminatorType getDiscriminatorType() { - return null; - } - - public void setDiscriminatorType(DiscriminatorType discriminatorType) { - if (discriminatorType != null) { - this.addAnnotation().setDiscriminatorType(discriminatorType); - } - } - - // ***** length - public Integer getLength() { - return null; - } - - public void setLength(Integer length) { - if (length != null) { - this.addAnnotation().setLength(length); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValueAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValueAnnotation.java deleted file mode 100644 index 7a68d3d2dc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValueAnnotation.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.DiscriminatorValue - */ -public final class NullDiscriminatorValueAnnotation - extends NullAnnotation - implements DiscriminatorValueAnnotation -{ - - protected NullDiscriminatorValueAnnotation(JavaResourcePersistentType parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected DiscriminatorValueAnnotation addAnnotation() { - return (DiscriminatorValueAnnotation) super.addAnnotation(); - } - - // ***** value - public String getValue() { - return null; - } - - public void setValue(String value) { - if (value != null) { - this.addAnnotation().setValue(value); - } - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEmbeddedAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEmbeddedAnnotation.java deleted file mode 100644 index 029d2a6ffd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEmbeddedAnnotation.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; - -/** - * javax.persistence.Embedded - */ -public final class NullEmbeddedAnnotation - extends NullAnnotation - implements EmbeddedAnnotation -{ - protected NullEmbeddedAnnotation(JavaResourcePersistentAttribute parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumeratedAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumeratedAnnotation.java deleted file mode 100644 index 1e45dd51a9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumeratedAnnotation.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.EnumType; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Enumerated - */ -public final class NullEnumeratedAnnotation - extends NullAnnotation - implements EnumeratedAnnotation -{ - protected NullEnumeratedAnnotation(JavaResourcePersistentAttribute parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected EnumeratedAnnotation addAnnotation() { - return (EnumeratedAnnotation) super.addAnnotation(); - } - - // ***** value - public EnumType getValue() { - return null; - } - - public void setValue(EnumType value) { - if (value != null) { - this.addAnnotation().setValue(value); - } - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritanceAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritanceAnnotation.java deleted file mode 100644 index a4130b1b6e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritanceAnnotation.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Inheritance - */ -public final class NullInheritanceAnnotation - extends NullAnnotation - implements InheritanceAnnotation -{ - protected NullInheritanceAnnotation(JavaResourcePersistentType parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected InheritanceAnnotation addAnnotation() { - return (InheritanceAnnotation) super.addAnnotation(); - } - - // ***** strategy - public InheritanceType getStrategy() { - return null; - } - - public void setStrategy(InheritanceType strategy) { - if (strategy != null) { - this.addAnnotation().setStrategy(strategy); - } - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinColumnAnnotation.java deleted file mode 100644 index 32c74fa036..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinColumnAnnotation.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.JoinColumn - */ -public final class NullJoinColumnAnnotation - extends NullBaseColumnAnnotation - implements JoinColumnAnnotation -{ - public NullJoinColumnAnnotation(JavaResourceNode parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected JoinColumnAnnotation addAnnotation() { - throw new UnsupportedOperationException(); - } - - // ***** referenced column name - public String getReferencedColumnName() { - return null; - } - - public void setReferencedColumnName(String referencedColumnName) { - throw new UnsupportedOperationException(); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return false; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTableAnnotation.java deleted file mode 100644 index f54c7aac97..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTableAnnotation.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import java.util.ListIterator; - -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember.AnnotationInitializer; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -/** - * javax.persistence.JoinTable - */ -public class NullJoinTableAnnotation - extends NullBaseTableAnnotation - implements JoinTableAnnotation -{ - public NullJoinTableAnnotation(JavaResourceNode parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected JoinTableAnnotation addAnnotation() { - return (JoinTableAnnotation) super.addAnnotation(); - } - - @Override - protected JoinColumnAnnotation addAnnotation(AnnotationInitializer initializer) { - return (JoinColumnAnnotation) super.addAnnotation(initializer); - } - - // ***** join columns - public ListIterator<JoinColumnAnnotation> joinColumns() { - return EmptyListIterator.instance(); - } - - public int joinColumnsSize() { - return 0; - } - - public JoinColumnAnnotation joinColumnAt(int index) { - return null; - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation addJoinColumn(int index) { - // the JoinTable annotation is missing, add both it and a join column at the same time - return addAnnotation(buildJoinColumnInitializer()); - } - - protected AnnotationInitializer buildJoinColumnInitializer() { - return JOIN_COLUMN_INITIALIZER; - } - - protected static final AnnotationInitializer JOIN_COLUMN_INITIALIZER = - new AnnotationInitializer() { - public Annotation initializeAnnotation(Annotation supportingAnnotation) { - return ((JoinTableAnnotation) supportingAnnotation).initializeJoinColumns(); - } - }; - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation initializeJoinColumns() { - throw new UnsupportedOperationException(); - } - - // ***** inverse join columns - public ListIterator<JoinColumnAnnotation> inverseJoinColumns() { - return EmptyListIterator.instance(); - } - - public int inverseJoinColumnsSize() { - return 0; - } - - public JoinColumnAnnotation inverseJoinColumnAt(int index) { - return null; - } - - public int indexOfInverseJoinColumn(JoinColumnAnnotation joinColumn) { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation addInverseJoinColumn(int index) { - // the JoinTable annotation is missing, add both it and a join column at the same time - return addAnnotation(buildInverseJoinColumnInitializer()); - } - - protected AnnotationInitializer buildInverseJoinColumnInitializer() { - return INVERSE_JOIN_COLUMN_INITIALIZER; - } - - protected static final AnnotationInitializer INVERSE_JOIN_COLUMN_INITIALIZER = - new AnnotationInitializer() { - public Annotation initializeAnnotation(Annotation supportingAnnotation) { - return ((JoinTableAnnotation) supportingAnnotation).initializeInverseJoinColumns(); - } - }; - - - public void moveInverseJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeInverseJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation initializeInverseJoinColumns() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumnAnnotation.java deleted file mode 100644 index 0ae2b8cf38..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumnAnnotation.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Column - * javax.persistence.JoinColumn - * javax.persistence.DiscriminatorColumn - * javax.persistence.PrimaryKeyJoinColumn. - */ -public abstract class NullNamedColumnAnnotation - extends NullAnnotation - implements NamedColumnAnnotation -{ - protected NullNamedColumnAnnotation(JavaResourceNode parent) { - super(parent); - } - - public boolean isSpecified() { - return false; - } - - @Override - protected NamedColumnAnnotation addAnnotation() { - return (NamedColumnAnnotation) super.addAnnotation(); - } - - // ***** name - public String getName() { - return null; - } - - public void setName(String name) { - if (name != null) { - this.addAnnotation().setName(name); - } - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return false; - } - - // ***** column definition - public String getColumnDefinition() { - return null; - } - - public void setColumnDefinition(String columnDefinition) { - if (columnDefinition != null) { - this.addAnnotation().setColumnDefinition(columnDefinition); - } - } - - public TextRange getColumnDefinitionTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToManyAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToManyAnnotation.java deleted file mode 100644 index 4d92110c51..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToManyAnnotation.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; - -/** - * javax.persistence.OneToMany - */ -public final class NullOneToManyAnnotation - extends NullOwnableRelationshipMappingAnnotation - implements OneToManyAnnotation -{ - public NullOneToManyAnnotation(JavaResourcePersistentAttribute parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToOneAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToOneAnnotation.java deleted file mode 100644 index ce6374c71b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToOneAnnotation.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.OneToOne - */ -public final class NullOneToOneAnnotation - extends NullOwnableRelationshipMappingAnnotation - implements OneToOneAnnotation -{ - protected NullOneToOneAnnotation(JavaResourcePersistentAttribute parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected OneToOneAnnotation addAnnotation() { - return (OneToOneAnnotation) super.addAnnotation(); - } - - // ***** optional - public Boolean getOptional() { - return null; - } - - public void setOptional(Boolean optional) { - if (optional != null) { - this.addAnnotation().setOptional(optional); - } - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOwnableRelationshipMappingAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOwnableRelationshipMappingAnnotation.java deleted file mode 100644 index dd29a044d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOwnableRelationshipMappingAnnotation.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OwnableRelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.OneToMany - * javax.persistence.OneToOne - */ -public abstract class NullOwnableRelationshipMappingAnnotation - extends NullAnnotation - implements OwnableRelationshipMappingAnnotation -{ - protected NullOwnableRelationshipMappingAnnotation(JavaResourcePersistentAttribute parent) { - super(parent); - } - - - @Override - protected OwnableRelationshipMappingAnnotation addAnnotation() { - return (OwnableRelationshipMappingAnnotation) super.addAnnotation(); - } - - - // ***** target entity - - public String getTargetEntity() { - return null; - } - - public void setTargetEntity(String targetEntity) { - if (targetEntity != null) { - this.addAnnotation().setTargetEntity(targetEntity); - } - } - - public TextRange getTargetEntityTextRange(CompilationUnit astRoot) { - return null; - } - - - // ***** fully-qualified target entity class name - - public String getFullyQualifiedTargetEntityClassName() { - return null; - } - - - // ***** mapped by - - public String getMappedBy() { - return null; - } - - public void setMappedBy(String mappedBy) { - if (mappedBy != null) { - this.addAnnotation().setMappedBy(mappedBy); - } - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return false; - } - - - // ***** fetch - - public FetchType getFetch() { - return null; - } - - public void setFetch(FetchType fetch) { - if (fetch != null) { - this.addAnnotation().setFetch(fetch); - } - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - return null; - } - - - // ***** cascade all - - public boolean isCascadeAll() { - return false; - } - - public void setCascadeAll(boolean all) { - this.addAnnotation().setCascadeAll(all); - } - - - // ***** cascade merge - - public boolean isCascadeMerge() { - return false; - } - - public void setCascadeMerge(boolean merge) { - this.addAnnotation().setCascadeMerge(merge); - } - - - // ***** cascade persist - - public boolean isCascadePersist() { - return false; - } - - public void setCascadePersist(boolean persist) { - this.addAnnotation().setCascadePersist(persist); - } - - - // ***** cascade refresh - - public boolean isCascadeRefresh() { - return false; - } - - public void setCascadeRefresh(boolean refresh) { - this.addAnnotation().setCascadeRefresh(refresh); - } - - - // ***** cascade remove - - public boolean isCascadeRemove() { - return false; - } - - public void setCascadeRemove(boolean remove) { - this.addAnnotation().setCascadeRemove(remove); - } - - public TextRange getCascadeTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullPrimaryKeyJoinColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullPrimaryKeyJoinColumnAnnotation.java deleted file mode 100644 index a2ff594c03..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullPrimaryKeyJoinColumnAnnotation.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.PrimaryKeyJoinColumn - */ -public final class NullPrimaryKeyJoinColumnAnnotation - extends NullNamedColumnAnnotation - implements PrimaryKeyJoinColumnAnnotation -{ - public NullPrimaryKeyJoinColumnAnnotation(JavaResourceNode parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected NamedColumnAnnotation addAnnotation() { - throw new UnsupportedOperationException(); - } - - // ***** referenced column name - public String getReferencedColumnName() { - return null; - } - - public void setReferencedColumnName(String referencedColumnName) { - throw new UnsupportedOperationException(); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return false; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTableAnnotation.java deleted file mode 100644 index bc831e7093..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTableAnnotation.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember.AnnotationInitializer; - -/** - * javax.persistence.Table - */ -public final class NullTableAnnotation - extends NullBaseTableAnnotation - implements TableAnnotation -{ - protected NullTableAnnotation(JavaResourcePersistentType parent) { - super(parent); - } - - @Override - protected TableAnnotation addAnnotation() { - return (TableAnnotation) super.addAnnotation(); - } - - @Override - protected TableAnnotation addAnnotation(AnnotationInitializer initializer) { - return (TableAnnotation) super.addAnnotation(initializer); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporalAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporalAnnotation.java deleted file mode 100644 index ec38b00a84..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporalAnnotation.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalType; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Temporal - */ -public final class NullTemporalAnnotation - extends NullAnnotation - implements TemporalAnnotation -{ - protected NullTemporalAnnotation(JavaResourcePersistentAttribute parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - protected TemporalAnnotation addAnnotation() { - return (TemporalAnnotation) super.addAnnotation(); - } - - - // ********** TemporalAnnotation implementation ********** - - // ***** value - public TemporalType getValue() { - return null; - } - - public void setValue(TemporalType value) { - if (value != null) { - this.addAnnotation().setValue(value); - } - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToManyAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToManyAnnotationDefinition.java deleted file mode 100644 index 29c3efe9f0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToManyAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryOneToManyAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceOneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.OneToMany - */ -public final class OneToManyAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new OneToManyAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private OneToManyAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceOneToManyAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullOneToManyAnnotation((JavaResourcePersistentAttribute) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryOneToManyAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return OneToManyAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToOneAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToOneAnnotationDefinition.java deleted file mode 100644 index 93ecc8e615..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToOneAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryOneToOneAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceOneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.OneToOne - */ -public final class OneToOneAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new OneToOneAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private OneToOneAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceOneToOneAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullOneToOneAnnotation((JavaResourcePersistentAttribute) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryOneToOneAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return OneToOneAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OrderByAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OrderByAnnotationDefinition.java deleted file mode 100644 index 271aa8a070..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OrderByAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryOrderByAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceOrderByAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.OrderBy - */ -public final class OrderByAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new OrderByAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private OrderByAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceOrderByAnnotation(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryOrderByAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return OrderByAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnAnnotationDefinition.java deleted file mode 100644 index 77499381c1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryPrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourcePrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.PrimaryKeyJoinColumn - */ -public final class PrimaryKeyJoinColumnAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new PrimaryKeyJoinColumnAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private PrimaryKeyJoinColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourcePrimaryKeyJoinColumnAnnotation.createPrimaryKeyJoinColumn(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryPrimaryKeyJoinColumnAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnsAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnsAnnotationDefinition.java deleted file mode 100644 index 0c67aba310..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnsAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryPrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourcePrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.PrimaryKeyJoinColumns - */ -public final class PrimaryKeyJoinColumnsAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new PrimaryKeyJoinColumnsAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private PrimaryKeyJoinColumnsAnnotationDefinition() { - super(); - } - - public PrimaryKeyJoinColumnsAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourcePrimaryKeyJoinColumnsAnnotation(parent, member); - } - - public PrimaryKeyJoinColumnsAnnotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryPrimaryKeyJoinColumnsAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTableAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTableAnnotationDefinition.java deleted file mode 100644 index cca983ff52..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTableAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinarySecondaryTableAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceSecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.SecondaryTable - */ -public final class SecondaryTableAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new SecondaryTableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SecondaryTableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SourceSecondaryTableAnnotation.createSecondaryTable(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinarySecondaryTableAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTablesAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTablesAnnotationDefinition.java deleted file mode 100644 index 037c96894c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTablesAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinarySecondaryTablesAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceSecondaryTablesAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.SecondaryTables - */ -public final class SecondaryTablesAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new SecondaryTablesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SecondaryTablesAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceSecondaryTablesAnnotation((JavaResourcePersistentType) parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinarySecondaryTablesAnnotation((JavaResourcePersistentType) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return SecondaryTablesAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SequenceGeneratorAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SequenceGeneratorAnnotationDefinition.java deleted file mode 100644 index 884b36bb1a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SequenceGeneratorAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.jpa1.resource.java.binary.BinarySequenceGenerator1_0Annotation; -import org.eclipse.jpt.core.internal.jpa1.resource.java.source.SourceSequenceGenerator1_0Annotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.SequenceGenerator - */ -public final class SequenceGeneratorAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new SequenceGeneratorAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - protected SequenceGeneratorAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceSequenceGenerator1_0Annotation(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinarySequenceGenerator1_0Annotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return SequenceGeneratorAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableAnnotationDefinition.java deleted file mode 100644 index 6de211ef15..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableAnnotationDefinition.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryTableAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceTableAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Table - */ -public final class TableAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new TableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private TableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceTableAnnotation(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullTableAnnotation((JavaResourcePersistentType) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryTableAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return TableAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableGeneratorAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableGeneratorAnnotationDefinition.java deleted file mode 100644 index 428e818d4c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableGeneratorAnnotationDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryTableGeneratorAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceTableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.TableGenerator - */ -public final class TableGeneratorAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new TableGeneratorAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private TableGeneratorAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceTableGeneratorAnnotation(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryTableGeneratorAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return TableGeneratorAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TemporalAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TemporalAnnotationDefinition.java deleted file mode 100644 index eb433e17f2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TemporalAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryTemporalAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceTemporalAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Temporal - */ -public final class TemporalAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new TemporalAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private TemporalAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceTemporalAnnotation(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - return new NullTemporalAnnotation((JavaResourcePersistentAttribute) parent); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryTemporalAnnotation(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return TemporalAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TransientAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TransientAnnotationDefinition.java deleted file mode 100644 index 4d84704c0f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TransientAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryTransientAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceTransientAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Transient - */ -public final class TransientAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new TransientAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private TransientAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceTransientAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryTransientAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return TransientAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/VersionAnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/VersionAnnotationDefinition.java deleted file mode 100644 index 3b11cce142..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/VersionAnnotationDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.binary.BinaryVersionAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceVersionAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Version - */ -public final class VersionAnnotationDefinition - implements AnnotationDefinition -{ - // singleton - private static final AnnotationDefinition INSTANCE = new VersionAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private VersionAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SourceVersionAnnotation((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { - throw new UnsupportedOperationException(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { - return new BinaryVersionAnnotation((JavaResourcePersistentAttribute) parent, jdtAnnotation); - } - - public String getAnnotationName() { - return VersionAnnotation.ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAnnotation.java deleted file mode 100644 index 7d5b6bf1ec..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAnnotation.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IMemberValuePair; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -/** - * JAR annotation - */ -public abstract class BinaryAnnotation - extends BinaryNode - implements Annotation -{ - final IAnnotation jdtAnnotation; - - protected BinaryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent); - this.jdtAnnotation = jdtAnnotation; - } - - - // ********** convenience methods ********** - - /** - * Return the values of the JDT annotation's member with the specified name. - */ - protected Object[] getJdtMemberValues(String memberName) { - Object[] values = (Object[]) this.getJdtMemberValue(memberName); - return (values != null) ? values : EMPTY_OBJECT_ARRAY; - } - private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - - /** - * Return the value of the JDT annotation's member with the specified name. - */ - protected Object getJdtMemberValue(String memberName) { - IMemberValuePair pair = this.getJdtMemberValuePair(memberName); - return (pair == null) ? null : pair.getValue(); - } - - /** - * Return the JDT annotation's member-value pair with the specified name. - */ - private IMemberValuePair getJdtMemberValuePair(String memberName) { - for (IMemberValuePair pair : this.getJdtMemberValuePairs()) { - if (pair.getMemberName().equals(memberName)) { - return pair; - } - } - return null; - } - - private IMemberValuePair[] getJdtMemberValuePairs() { - try { - return this.jdtAnnotation.getMemberValuePairs(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return EMPTY_MEMBER_VALUE_PAIR_ARRAY; - } - } - private static final IMemberValuePair[] EMPTY_MEMBER_VALUE_PAIR_ARRAY = new IMemberValuePair[0]; - - - // ********** Annotation implementation ********** - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - // ********** NestableAnnotation implementation ********** - public void moveAnnotation(@SuppressWarnings("unused") int index) { - throw new UnsupportedOperationException(); - } - public void initializeFrom(@SuppressWarnings("unused") NestableAnnotation oldAnnotation) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAssociationOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAssociationOverrideAnnotation.java deleted file mode 100644 index 439b0442b3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAssociationOverrideAnnotation.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.AssociationOverride - */ -public abstract class BinaryAssociationOverrideAnnotation - extends BinaryOverrideAnnotation - implements NestableAssociationOverrideAnnotation -{ - private final Vector<JoinColumnAnnotation> joinColumns; - - - protected BinaryAssociationOverrideAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.joinColumns = this.buildJoinColumns(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.updateJoinColumns(); - } - - - // ********** BinaryOverrideAnnotation implementation ********** - - @Override - protected String getNameElementName() { - return JPA.ASSOCIATION_OVERRIDE__NAME; - } - - - // ********** AssociationOverrideAnnotation implementation ********** - - // ***** join columns - public ListIterator<JoinColumnAnnotation> joinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.joinColumns); - } - - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - public JoinColumnAnnotation joinColumnAt(int index) { - return this.joinColumns.get(index); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public JoinColumnAnnotation addJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - private Vector<JoinColumnAnnotation> buildJoinColumns() { - Object[] jdtJoinColumns = this.getJdtMemberValues(JPA.ASSOCIATION_OVERRIDE__JOIN_COLUMNS); - Vector<JoinColumnAnnotation> result = new Vector<JoinColumnAnnotation>(jdtJoinColumns.length); - for (Object jdtJoinColumn : jdtJoinColumns) { - result.add(new BinaryJoinColumnAnnotation(this, (IAnnotation) jdtJoinColumn)); - } - return result; - } - - // TODO - private void updateJoinColumns() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAssociationOverridesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAssociationOverridesAnnotation.java deleted file mode 100644 index 22a782a291..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAssociationOverridesAnnotation.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.AssociationOverrides - */ -public abstract class BinaryAssociationOverridesAnnotation - extends BinaryContainerAnnotation<NestableAssociationOverrideAnnotation> - implements AssociationOverridesAnnotation -{ - private final Vector<NestableAssociationOverrideAnnotation> associationOverrides; - - - protected BinaryAssociationOverridesAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.associationOverrides = this.buildAssociationOverrides(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public ListIterator<NestableAssociationOverrideAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableAssociationOverrideAnnotation>(this.associationOverrides); - } - - public int nestedAnnotationsSize() { - return this.associationOverrides.size(); - } - - private Vector<NestableAssociationOverrideAnnotation> buildAssociationOverrides() { - Object[] jdtAssociationOverrides = this.getJdtMemberValues(JPA.ASSOCIATION_OVERRIDES__VALUE); - Vector<NestableAssociationOverrideAnnotation> result = new Vector<NestableAssociationOverrideAnnotation>(jdtAssociationOverrides.length); - for (Object jdtAssociationOverride : jdtAssociationOverrides) { - result.add(buildAssociationOverride(jdtAssociationOverride)); - } - return result; - } - - protected abstract NestableAssociationOverrideAnnotation buildAssociationOverride(Object jdtAssociationOverride); - - @Override - public void update() { - super.update(); - this.updateAssociationOverrides(); - } - - // TODO - private void updateAssociationOverrides() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAttributeOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAttributeOverrideAnnotation.java deleted file mode 100644 index 37add8b4d8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAttributeOverrideAnnotation.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.internal.resource.java.NullAttributeOverrideColumnAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAttributeOverrideAnnotation; - -/** - * javax.persistence.AttributeOverride - */ -public final class BinaryAttributeOverrideAnnotation - extends BinaryOverrideAnnotation - implements NestableAttributeOverrideAnnotation -{ - private ColumnAnnotation column; - - - public BinaryAttributeOverrideAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.column = this.buildColumn(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.updateColumn(); - } - - - //************ BinaryOverrideAnnotation implementation **************** - - @Override - protected String getNameElementName() { - return JPA.ATTRIBUTE_OVERRIDE__NAME; - } - - - //************ AttributeOverride implementation **************** - - // ***** column - public ColumnAnnotation getColumn() { - return this.column; - } - - public ColumnAnnotation getNonNullColumn() { - return (this.column != null) ? this.column : new NullAttributeOverrideColumnAnnotation(this); - } - - public ColumnAnnotation addColumn() { - throw new UnsupportedOperationException(); - } - - public void removeColumn() { - throw new UnsupportedOperationException(); - } - - private ColumnAnnotation buildColumn() { - IAnnotation jdtColumn = this.getJdtColumn(); - return (jdtColumn == null) ? null : this.buildColumn(jdtColumn); - } - - private ColumnAnnotation buildColumn(IAnnotation jdtColumn) { - return new BinaryColumnAnnotation(this, jdtColumn); - } - - private IAnnotation getJdtColumn() { - return (IAnnotation) this.getJdtMemberValue(JPA.ATTRIBUTE_OVERRIDE__COLUMN); - } - - private void setColumn(ColumnAnnotation column) { - ColumnAnnotation old = this.column; - this.column = column; - this.firePropertyChanged(COLUMN_PROPERTY, old, column); - } - - // TODO - private void updateColumn() { - throw new UnsupportedOperationException(); -// IAnnotation jdtColumn = this.getJdtColumn(); -// if (jdtColumn == null) { -// this.setColumn(null); -// } else { -// if (this.column == null) { -// this.setColumn(this.buildColumn(jdtColumn)); -// } else { -// this.column.update(jdtColumn); -// } -// } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAttributeOverridesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAttributeOverridesAnnotation.java deleted file mode 100644 index 2af0df8e18..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryAttributeOverridesAnnotation.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -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.NestableAttributeOverrideAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.AttributeOverrides - */ -public final class BinaryAttributeOverridesAnnotation - extends BinaryContainerAnnotation<NestableAttributeOverrideAnnotation> - implements AttributeOverridesAnnotation -{ - private final Vector<NestableAttributeOverrideAnnotation> attributeOverrides; - - - public BinaryAttributeOverridesAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.attributeOverrides = this.buildAttributeOverrides(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public ListIterator<NestableAttributeOverrideAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableAttributeOverrideAnnotation>(this.attributeOverrides); - } - - public int nestedAnnotationsSize() { - return this.attributeOverrides.size(); - } - - private Vector<NestableAttributeOverrideAnnotation> buildAttributeOverrides() { - Object[] jdtAttributeOverrides = this.getJdtMemberValues(JPA.ATTRIBUTE_OVERRIDES__VALUE); - Vector<NestableAttributeOverrideAnnotation> result = new Vector<NestableAttributeOverrideAnnotation>(jdtAttributeOverrides.length); - for (Object jdtAttributeOverride : jdtAttributeOverrides) { - result.add(new BinaryAttributeOverrideAnnotation(this, (IAnnotation) jdtAttributeOverride)); - } - return result; - } - - @Override - public void update() { - super.update(); - this.updateAttributeOverrides(); - } - - // TODO - private void updateAttributeOverrides() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseColumnAnnotation.java deleted file mode 100644 index 7e7d4f32e9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseColumnAnnotation.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BaseColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Column - * javax.persistence.JoinColumn - */ -abstract class BinaryBaseColumnAnnotation - extends BinaryNamedColumnAnnotation - implements BaseColumnAnnotation -{ - private String table; - private Boolean unique; - private Boolean nullable; - private Boolean insertable; - private Boolean updatable; - - - BinaryBaseColumnAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.table = this.buildTable(); - this.unique = this.buildUnique(); - this.nullable = this.buildNullable(); - this.insertable = this.buildInsertable(); - this.updatable = this.buildUpdatable(); - } - - @Override - public void update() { - super.update(); - this.setTable_(this.buildTable()); - this.setUnique_(this.buildUnique()); - this.setNullable_(this.buildNullable()); - this.setInsertable_(this.buildInsertable()); - this.setUpdatable_(this.buildUpdatable()); - } - - - //************* BaseColumnAnnotation implementation ************* - - // ***** table - public String getTable() { - return this.table; - } - - public void setTable(String table) { - throw new UnsupportedOperationException(); - } - - private void setTable_(String table) { - String old = this.table; - this.table = table; - this.firePropertyChanged(TABLE_PROPERTY, old, table); - } - - private String buildTable() { - return (String) this.getJdtMemberValue(this.getTableElementName()); - } - - abstract String getTableElementName(); - - public TextRange getTableTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** unique - public Boolean getUnique() { - return this.unique; - } - - public void setUnique(Boolean unique) { - throw new UnsupportedOperationException(); - } - - private void setUnique_(Boolean unique) { - Boolean old = this.unique; - this.unique = unique; - this.firePropertyChanged(UNIQUE_PROPERTY, old, unique); - } - - private Boolean buildUnique() { - return (Boolean) this.getJdtMemberValue(this.getUniqueElementName()); - } - - abstract String getUniqueElementName(); - - public TextRange getUniqueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** nullable - public Boolean getNullable() { - return this.nullable; - } - - public void setNullable(Boolean nullable) { - throw new UnsupportedOperationException(); - } - - private void setNullable_(Boolean nullable) { - Boolean old = this.nullable; - this.nullable = nullable; - this.firePropertyChanged(NULLABLE_PROPERTY, old, nullable); - } - - private Boolean buildNullable() { - return (Boolean) this.getJdtMemberValue(this.getNullableElementName()); - } - - abstract String getNullableElementName(); - - public TextRange getNullableTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** insertable - public Boolean getInsertable() { - return this.insertable; - } - - public void setInsertable(Boolean insertable) { - throw new UnsupportedOperationException(); - } - - private void setInsertable_(Boolean insertable) { - Boolean old = this.insertable; - this.insertable = insertable; - this.firePropertyChanged(INSERTABLE_PROPERTY, old, insertable); - } - - private Boolean buildInsertable() { - return (Boolean) this.getJdtMemberValue(this.getInsertableElementName()); - } - - abstract String getInsertableElementName(); - - public TextRange getInsertableTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** updatable - public Boolean getUpdatable() { - return this.updatable; - } - - public void setUpdatable(Boolean updatable) { - throw new UnsupportedOperationException(); - } - - private void setUpdatable_(Boolean updatable) { - Boolean old = this.updatable; - this.updatable = updatable; - this.firePropertyChanged(UPDATABLE_PROPERTY, old, updatable); - } - - private Boolean buildUpdatable() { - return (Boolean) this.getJdtMemberValue(this.getUpdatableElementName()); - } - - abstract String getUpdatableElementName(); - - public TextRange getUpdatableTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseNamedQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseNamedQueryAnnotation.java deleted file mode 100644 index cb7745ef78..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseNamedQueryAnnotation.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BaseNamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.NamedQuery - * javax.persistence.NamedNativeQuery - */ -abstract class BinaryBaseNamedQueryAnnotation - extends BinaryAnnotation - implements BaseNamedQueryAnnotation -{ - String name; - String query; - final Vector<QueryHintAnnotation> hints; - - - BinaryBaseNamedQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - this.query = this.buildQuery(); - this.hints = this.buildHints(); - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - this.setQuery_(this.buildQuery()); - this.updateHints(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** BaseNamedQueryAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(this.getNameElementName()); - } - - abstract String getNameElementName(); - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** query - public String getQuery() { - return this.query; - } - - public void setQuery(String query) { - throw new UnsupportedOperationException(); - } - - private void setQuery_(String query) { - String old = this.query; - this.query = query; - this.firePropertyChanged(QUERY_PROPERTY, old, query); - } - - private String buildQuery() { - return (String) this.getJdtMemberValue(this.getQueryElementName()); - } - - abstract String getQueryElementName(); - - public TextRange getQueryTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** hints - public ListIterator<QueryHintAnnotation> hints() { - return new CloneListIterator<QueryHintAnnotation>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public QueryHintAnnotation hintAt(int index) { - return this.hints.get(index); - } - - public int indexOfHint(QueryHintAnnotation queryHint) { - return this.hints.indexOf(queryHint); - } - - public QueryHintAnnotation addHint(int index) { - throw new UnsupportedOperationException(); - } - - public void moveHint(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeHint(int index) { - throw new UnsupportedOperationException(); - } - - private Vector<QueryHintAnnotation> buildHints() { - Object[] jdtHints = this.getJdtMemberValues(this.getHintsElementName()); - Vector<QueryHintAnnotation> result = new Vector<QueryHintAnnotation>(jdtHints.length); - for (Object jdtHint : jdtHints) { - result.add(new BinaryQueryHintAnnotation(this, (IAnnotation) jdtHint)); - } - return result; - } - - abstract String getHintsElementName(); - - // TODO - private void updateHints() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseTableAnnotation.java deleted file mode 100644 index ca8c3d4ed4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBaseTableAnnotation.java +++ /dev/null @@ -1,199 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BaseTableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.Table - * javax.persistence.JoinTable - * javax.persistence.SecondaryTable - */ -abstract class BinaryBaseTableAnnotation - extends BinaryAnnotation - implements BaseTableAnnotation -{ - String name; - String schema; - String catalog; - final Vector<UniqueConstraintAnnotation> uniqueConstraints; - - - BinaryBaseTableAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - this.schema = this.buildSchema(); - this.catalog = this.buildCatalog(); - this.uniqueConstraints = this.buildUniqueConstraints(); - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - this.setSchema_(this.buildSchema()); - this.setCatalog_(this.buildCatalog()); - this.updateUniqueConstraints(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** BaseTableAnnotation implementation ********** - - public boolean isSpecified() { - return true; - } - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(this.getNameElementName()); - } - - abstract String getNameElementName(); - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** schema - public String getSchema() { - return this.schema; - } - - public void setSchema(String schema) { - throw new UnsupportedOperationException(); - } - - private void setSchema_(String schema) { - String old = this.schema; - this.schema = schema; - this.firePropertyChanged(SCHEMA_PROPERTY, old, schema); - } - - private String buildSchema() { - return (String) this.getJdtMemberValue(this.getSchemaElementName()); - } - - abstract String getSchemaElementName(); - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** catalog - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String catalog) { - throw new UnsupportedOperationException(); - } - - private void setCatalog_(String catalog) { - String old = this.catalog; - this.catalog = catalog; - this.firePropertyChanged(CATALOG_PROPERTY, old, catalog); - } - - private String buildCatalog() { - return (String) this.getJdtMemberValue(this.getCatalogElementName()); - } - - abstract String getCatalogElementName(); - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** unique constraints - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return new CloneListIterator<UniqueConstraintAnnotation>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public UniqueConstraintAnnotation uniqueConstraintAt(int index) { - return this.uniqueConstraints.get(index); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - return this.uniqueConstraints.indexOf(uniqueConstraint); - } - - public UniqueConstraintAnnotation addUniqueConstraint(int index) { - throw new UnsupportedOperationException(); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeUniqueConstraint(int index) { - throw new UnsupportedOperationException(); - } - - private Vector<UniqueConstraintAnnotation> buildUniqueConstraints() { - Object[] jdtUniqueConstraints = this.getJdtMemberValues(this.getUniqueConstraintElementName()); - Vector<UniqueConstraintAnnotation> result = new Vector<UniqueConstraintAnnotation>(jdtUniqueConstraints.length); - for (Object jdtUniqueConstraint : jdtUniqueConstraints) { - result.add(new BinaryUniqueConstraintAnnotation(this, (IAnnotation) jdtUniqueConstraint)); - } - return result; - } - - abstract String getUniqueConstraintElementName(); - - // TODO - private void updateUniqueConstraints() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBasicAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBasicAnnotation.java deleted file mode 100644 index 9db25330ce..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryBasicAnnotation.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Basic - */ -public final class BinaryBasicAnnotation - extends BinaryAnnotation - implements BasicAnnotation -{ - private Boolean optional; - private FetchType fetch; - - - public BinaryBasicAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.optional = this.buildOptional(); - this.fetch = this.buildFetch(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setOptional_(this.buildOptional()); - this.setFetch_(this.buildFetch()); - } - - - //*************** Basic implementation **************** - - // ***** optional - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean optional) { - throw new UnsupportedOperationException(); - } - - private void setOptional_(Boolean optional) { - Boolean old = this.optional; - this.optional = optional; - this.firePropertyChanged(OPTIONAL_PROPERTY, old, optional); - } - - private Boolean buildOptional() { - return (Boolean) this.getJdtMemberValue(JPA.BASIC__OPTIONAL); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** fetch - public FetchType getFetch() { - return this.fetch; - } - - public void setFetch(FetchType fetch) { - throw new UnsupportedOperationException(); - } - - private void setFetch_(FetchType fetch) { - FetchType old = this.fetch; - this.fetch = fetch; - this.firePropertyChanged(FETCH_PROPERTY, old, fetch); - } - - private FetchType buildFetch() { - return FetchType.fromJavaAnnotationValue(this.getJdtMemberValue(JPA.BASIC__FETCH)); - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryClassFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryClassFile.java deleted file mode 100644 index 037eda1ea4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryClassFile.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IClassFile; -import org.eclipse.jdt.core.IType; -import org.eclipse.jpt.core.resource.java.JavaResourceClassFile; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragment; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -/** - * binary class file - */ -final class BinaryClassFile - extends BinaryNode - implements JavaResourceClassFile -{ - /** JDT class file */ - private final IClassFile classFile; - - /** class file's persistent type */ - private final JavaResourcePersistentType persistentType; - - - // ********** construction/initialization ********** - - /** - * The JDT type gets passed in because the package fragment inspects it - * beforehand to determine whether it is "persistable". (We only build - * class files for "persistable" types.) - */ - BinaryClassFile(JavaResourcePackageFragment parent, IClassFile classFile, IType jdtType) { - super(parent); - this.classFile = classFile; - this.persistentType = this.buildPersistentType(jdtType); - } - - private JavaResourcePersistentType buildPersistentType(IType jdtType) { - return new BinaryPersistentType(this, jdtType); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.classFile.getElementName()); - } - - - // ********** JavaResourceClassFile implementation ********** - - public JavaResourcePersistentType getPersistentType() { - return this.persistentType; - } - - // TODO - @Override - public void update() { - super.update(); -// this.persistentType.update(this.classFile.getType()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryColumnAnnotation.java deleted file mode 100644 index 3290815860..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryColumnAnnotation.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Column - */ -public final class BinaryColumnAnnotation - extends BinaryBaseColumnAnnotation - implements ColumnAnnotation -{ - private Integer length; - private Integer precision; - private Integer scale; - - - public BinaryColumnAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.length = this.buildLength(); - this.precision = this.buildPrecision(); - this.scale = this.buildScale(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setLength_(this.buildLength()); - this.setPrecision_(this.buildPrecision()); - this.setScale_(this.buildScale()); - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.COLUMN__COLUMN_DEFINITION; - } - - - // ********** JavaSourceBaseColumnAnnotation implementation ********** - - @Override - String getTableElementName() { - return JPA.COLUMN__TABLE; - } - - @Override - String getUniqueElementName() { - return JPA.COLUMN__UNIQUE; - } - - @Override - String getNullableElementName() { - return JPA.COLUMN__NULLABLE; - } - - @Override - String getInsertableElementName() { - return JPA.COLUMN__INSERTABLE; - } - - @Override - String getUpdatableElementName() { - return JPA.COLUMN__UPDATABLE; - } - - - // ********** Column implementation ********** - - // ***** length - public Integer getLength() { - return this.length; - } - - public void setLength(Integer length) { - throw new UnsupportedOperationException(); - } - - private void setLength_(Integer length) { - Integer old = this.length; - this.length = length; - this.firePropertyChanged(LENGTH_PROPERTY, old, length); - } - - private Integer buildLength() { - return (Integer) this.getJdtMemberValue(JPA.COLUMN__LENGTH); - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** precision - public Integer getPrecision() { - return this.precision; - } - - public void setPrecision(Integer precision) { - throw new UnsupportedOperationException(); - } - - private void setPrecision_(Integer precision) { - Integer old = this.precision; - this.precision = precision; - this.firePropertyChanged(PRECISION_PROPERTY, old, precision); - } - - private Integer buildPrecision() { - return (Integer) this.getJdtMemberValue(JPA.COLUMN__PRECISION); - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** scale - public Integer getScale() { - return this.scale; - } - - public void setScale(Integer scale) { - throw new UnsupportedOperationException(); - } - - private void setScale_(Integer scale) { - Integer old = this.scale; - this.scale = scale; - this.firePropertyChanged(SCALE_PROPERTY, old, scale); - } - - private Integer buildScale() { - return (Integer) this.getJdtMemberValue(JPA.COLUMN__SCALE); - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryContainerAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryContainerAnnotation.java deleted file mode 100644 index 871b9b54f1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryContainerAnnotation.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -/** - * JAR annotations do not support most of the container annotation protocol. - */ -abstract class BinaryContainerAnnotation<T extends NestableAnnotation> - extends BinaryAnnotation - implements ContainerAnnotation<T> -{ - - public BinaryContainerAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getContainerAnnotationName() { - throw new UnsupportedOperationException(); - } - - public Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public String getElementName() { - throw new UnsupportedOperationException(); - } - - public String getNestableAnnotationName() { - throw new UnsupportedOperationException(); - } - - public T addNestedAnnotationInternal() { - throw new UnsupportedOperationException(); - } - - public void nestedAnnotationAdded(int index, T nestedAnnotation) { - throw new UnsupportedOperationException(); - } - - public T moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public T removeNestedAnnotationInternal(int index) { - throw new UnsupportedOperationException(); - } - - public void nestedAnnotationRemoved(int index, T nestedAnnotation) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryDiscriminatorColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryDiscriminatorColumnAnnotation.java deleted file mode 100644 index 779578ff56..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryDiscriminatorColumnAnnotation.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -/** - * javax.persistence.DiscriminatorColumn - */ -public final class BinaryDiscriminatorColumnAnnotation - extends BinaryNamedColumnAnnotation - implements DiscriminatorColumnAnnotation -{ - private DiscriminatorType discriminatorType; - private Integer length; - - - public BinaryDiscriminatorColumnAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.discriminatorType = this.buildDiscriminatorType(); - this.length = this.buildLength(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setDiscriminatorType_(this.buildDiscriminatorType()); - this.setLength_(this.buildLength()); - } - - - // ********** AbstractNamedColumn implementation ********** - - @Override - String getNameElementName() { - return JPA.DISCRIMINATOR_COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.DISCRIMINATOR_COLUMN__COLUMN_DEFINITION; - } - - - // ********** DiscriminatorColumn implementation ********** - - // ***** discriminator type - public DiscriminatorType getDiscriminatorType() { - return null; - } - - public void setDiscriminatorType(DiscriminatorType discriminatorType) { - throw new UnsupportedOperationException(); - } - - private void setDiscriminatorType_(DiscriminatorType discriminatorType) { - DiscriminatorType old = this.discriminatorType; - this.discriminatorType = discriminatorType; - this.firePropertyChanged(DISCRIMINATOR_TYPE_PROPERTY, old, discriminatorType); - } - - private DiscriminatorType buildDiscriminatorType() { - return DiscriminatorType.fromJavaAnnotationValue(this.getJdtMemberValue(JPA.DISCRIMINATOR_COLUMN__DISCRIMINATOR_TYPE)); - } - - // ***** length - public Integer getLength() { - return null; - } - - public void setLength(Integer length) { - throw new UnsupportedOperationException(); - } - - private void setLength_(Integer length) { - Integer old = this.length; - this.length = length; - this.firePropertyChanged(LENGTH_PROPERTY, old, length); - } - - private Integer buildLength() { - return (Integer) this.getJdtMemberValue(JPA.DISCRIMINATOR_COLUMN__LENGTH); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryDiscriminatorValueAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryDiscriminatorValueAnnotation.java deleted file mode 100644 index 883f99695f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryDiscriminatorValueAnnotation.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.DiscriminatorValue - */ -public final class BinaryDiscriminatorValueAnnotation - extends BinaryAnnotation - implements DiscriminatorValueAnnotation -{ - private String value; - - - public BinaryDiscriminatorValueAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.value = this.buildValue(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setValue_(this.buildValue()); - } - - - // ********** DiscriminatorValueAnnotation implementation ********** - - // ***** value - public String getValue() { - return this.value; - } - - public void setValue(String value) { - throw new UnsupportedOperationException(); - } - - private void setValue_(String value) { - String old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private String buildValue() { - return (String) this.getJdtMemberValue(JPA.DISCRIMINATOR_VALUE__VALUE); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddableAnnotation.java deleted file mode 100644 index 91db09f2a2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddableAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -/** - * javax.persistence.Embeddable - */ -public final class BinaryEmbeddableAnnotation - extends BinaryAnnotation - implements EmbeddableAnnotation -{ - - public BinaryEmbeddableAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddedAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddedAnnotation.java deleted file mode 100644 index 2fd143485d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddedAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; - -/** - * javax.persistence.Embedded - */ -public final class BinaryEmbeddedAnnotation - extends BinaryAnnotation - implements EmbeddedAnnotation -{ - - public BinaryEmbeddedAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddedIdAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddedIdAnnotation.java deleted file mode 100644 index 604f5be572..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEmbeddedIdAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; - -/** - * javax.persistence.EmbeddedId - */ -public final class BinaryEmbeddedIdAnnotation - extends BinaryAnnotation - implements EmbeddedIdAnnotation -{ - - public BinaryEmbeddedIdAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEntityAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEntityAnnotation.java deleted file mode 100644 index bd4acb47b9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEntityAnnotation.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Entity - */ -public final class BinaryEntityAnnotation - extends BinaryAnnotation - implements EntityAnnotation -{ - private String name; - - - public BinaryEntityAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** EntityAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(JPA.ENTITY__NAME); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEnumeratedAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEnumeratedAnnotation.java deleted file mode 100644 index 0263fb7765..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryEnumeratedAnnotation.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.EnumType; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Enumerated - */ -public final class BinaryEnumeratedAnnotation - extends BinaryAnnotation - implements EnumeratedAnnotation -{ - private EnumType value; - - - public BinaryEnumeratedAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.value = this.buildValue(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setValue_(this.buildValue()); - } - - - // ********** EnumeratedAnnotation implementation ********** - - // ***** value - public EnumType getValue() { - return this.value; - } - - public void setValue(EnumType value) { - throw new UnsupportedOperationException(); - } - - private void setValue_(EnumType value) { - EnumType old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private EnumType buildValue() { - return EnumType.fromJavaAnnotationValue(this.getJdtMemberValue(JPA.ENUMERATED__VALUE)); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryGeneratedValueAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryGeneratedValueAnnotation.java deleted file mode 100644 index a6b26366a0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryGeneratedValueAnnotation.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.GenerationType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.GeneratedValue - */ -public final class BinaryGeneratedValueAnnotation - extends BinaryAnnotation - implements GeneratedValueAnnotation -{ - private GenerationType strategy; - private String generator; - - - public BinaryGeneratedValueAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.strategy = this.buildStrategy(); - this.generator = this.buildGenerator(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setStrategy_(this.buildStrategy()); - this.setGenerator_(this.buildGenerator()); - } - - - // ********** GeneratedValueAnnotation implementation ********** - - // ***** strategy - public GenerationType getStrategy() { - return this.strategy; - } - - public void setStrategy(GenerationType strategy) { - throw new UnsupportedOperationException(); - } - - private void setStrategy_(GenerationType strategy) { - GenerationType old = this.strategy; - this.strategy = strategy; - this.firePropertyChanged(STRATEGY_PROPERTY, old, strategy); - } - - private GenerationType buildStrategy() { - return GenerationType.fromJavaAnnotationValue(this.getJdtMemberValue(JPA.GENERATED_VALUE__STRATEGY)); - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** generator - public String getGenerator() { - return this.generator; - } - - public void setGenerator(String generator) { - throw new UnsupportedOperationException(); - } - - private void setGenerator_(String generator) { - String old = this.generator; - this.generator = generator; - this.firePropertyChanged(GENERATOR_PROPERTY, old, generator); - } - - private String buildGenerator() { - return (String) this.getJdtMemberValue(JPA.GENERATED_VALUE__GENERATOR); - } - - public TextRange getGeneratorTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean generatorTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryGeneratorAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryGeneratorAnnotation.java deleted file mode 100644 index d89cff9ec8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryGeneratorAnnotation.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.GeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.SequenceGenerator - * javax.persistence.TableGenerator - */ -abstract class BinaryGeneratorAnnotation - extends BinaryAnnotation - implements GeneratorAnnotation -{ - String name; - Integer initialValue; - Integer allocationSize; - - - BinaryGeneratorAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - this.initialValue = this.buildInitialValue(); - this.allocationSize = this.buildAllocationSize(); - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - this.setInitialValue_(this.buildInitialValue()); - this.setAllocationSize_(this.buildAllocationSize()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** GeneratorAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(this.getNameElementName()); - } - - abstract String getNameElementName(); - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** initial value - public Integer getInitialValue() { - return this.initialValue; - } - - public void setInitialValue(Integer initialValue) { - throw new UnsupportedOperationException(); - } - - private void setInitialValue_(Integer initialValue) { - Integer old = this.initialValue; - this.initialValue = initialValue; - this.firePropertyChanged(INITIAL_VALUE_PROPERTY, old, initialValue); - } - - private Integer buildInitialValue() { - return (Integer) this.getJdtMemberValue(this.getInitialValueElementName()); - } - - abstract String getInitialValueElementName(); - - public TextRange getInitialValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** name - public Integer getAllocationSize() { - return this.allocationSize; - } - - public void setAllocationSize(Integer allocationSize) { - throw new UnsupportedOperationException(); - } - - private void setAllocationSize_(Integer allocationSize) { - Integer old = this.allocationSize; - this.allocationSize = allocationSize; - this.firePropertyChanged(NAME_PROPERTY, old, allocationSize); - } - - private Integer buildAllocationSize() { - return (Integer) this.getJdtMemberValue(this.getAllocationSizeElementName()); - } - - abstract String getAllocationSizeElementName(); - - public TextRange getAllocationSizeTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryIdAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryIdAnnotation.java deleted file mode 100644 index 95946b447e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryIdAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; - -/** - * javax.persistence.Id - */ -public final class BinaryIdAnnotation - extends BinaryAnnotation - implements IdAnnotation -{ - - public BinaryIdAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryIdClassAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryIdClassAnnotation.java deleted file mode 100644 index 74ff351246..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryIdClassAnnotation.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.IdClass - */ -public final class BinaryIdClassAnnotation - extends BinaryAnnotation - implements IdClassAnnotation -{ - private String value; - - - public BinaryIdClassAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.value = this.buildValue(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setValue_(this.buildValue()); - } - - - // ********** IdClassAnnotation implementation ********** - - // ***** value - public String getValue() { - return this.value; - } - - public void setValue(String value) { - throw new UnsupportedOperationException(); - } - - private void setValue_(String value) { - String old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - this.firePropertyChanged(FULLY_QUALIFIED_CLASS_NAME_PROPERTY, old, value); - } - - private String buildValue() { - return (String) this.getJdtMemberValue(JPA.ID_CLASS__VALUE); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** fully-qualified class name - /** - * binary is already fully-qualified - */ - public String getFullyQualifiedClassName() { - return this.value; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryInheritanceAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryInheritanceAnnotation.java deleted file mode 100644 index 81711643ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryInheritanceAnnotation.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Inheritance - */ -public final class BinaryInheritanceAnnotation - extends BinaryAnnotation - implements InheritanceAnnotation -{ - private InheritanceType strategy; - - - public BinaryInheritanceAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.strategy = this.buildStrategy(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setStrategy_(this.buildStrategy()); - } - - - // ********** InheritanceAnnotation implementation ********** - - // ***** strategy - public InheritanceType getStrategy() { - return this.strategy; - } - - public void setStrategy(InheritanceType strategy) { - throw new UnsupportedOperationException(); - } - - private void setStrategy_(InheritanceType strategy) { - InheritanceType old = this.strategy; - this.strategy = strategy; - this.firePropertyChanged(STRATEGY_PROPERTY, old, strategy); - } - - private InheritanceType buildStrategy() { - return InheritanceType.fromJavaAnnotationValue(this.getJdtMemberValue(JPA.INHERITANCE__STRATEGY)); - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinColumnAnnotation.java deleted file mode 100644 index 5c15fcefac..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinColumnAnnotation.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.JoinColumn - */ -public final class BinaryJoinColumnAnnotation - extends BinaryBaseColumnAnnotation - implements NestableJoinColumnAnnotation -{ - private String referencedColumnName; - - - public BinaryJoinColumnAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.referencedColumnName = this.buildReferencedColumnName(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setReferencedColumnName_(this.buildReferencedColumnName()); - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.JOIN_COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.JOIN_COLUMN__COLUMN_DEFINITION; - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getTableElementName() { - return JPA.JOIN_COLUMN__TABLE; - } - - @Override - String getUniqueElementName() { - return JPA.JOIN_COLUMN__UNIQUE; - } - - @Override - String getNullableElementName() { - return JPA.JOIN_COLUMN__NULLABLE; - } - - @Override - String getInsertableElementName() { - return JPA.JOIN_COLUMN__INSERTABLE; - } - - @Override - String getUpdatableElementName() { - return JPA.JOIN_COLUMN__UPDATABLE; - } - - - //************ JoinColumn implementation *************** - - // referenced column name - public String getReferencedColumnName() { - return this.referencedColumnName; - } - - public void setReferencedColumnName(String referencedColumnName) { - throw new UnsupportedOperationException(); - } - - private void setReferencedColumnName_(String referencedColumnName) { - String old = this.referencedColumnName; - this.referencedColumnName = referencedColumnName; - this.firePropertyChanged(REFERENCED_COLUMN_NAME_PROPERTY, old, referencedColumnName); - } - - private String buildReferencedColumnName() { - return (String) this.getJdtMemberValue(JPA.JOIN_COLUMN__REFERENCED_COLUMN_NAME); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinColumnsAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinColumnsAnnotation.java deleted file mode 100644 index 196dd994d1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinColumnsAnnotation.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinColumnAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.JoinColumns - */ -public final class BinaryJoinColumnsAnnotation - extends BinaryContainerAnnotation<NestableJoinColumnAnnotation> - implements JoinColumnsAnnotation -{ - private final Vector<NestableJoinColumnAnnotation> joinColumns; - - - public BinaryJoinColumnsAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.joinColumns = this.buildJoinColumns(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public ListIterator<NestableJoinColumnAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableJoinColumnAnnotation>(this.joinColumns); - } - - public int nestedAnnotationsSize() { - return this.joinColumns.size(); - } - - private Vector<NestableJoinColumnAnnotation> buildJoinColumns() { - Object[] jdtJoinColumns = this.getJdtMemberValues(JPA.JOIN_COLUMNS__VALUE); - Vector<NestableJoinColumnAnnotation> result = new Vector<NestableJoinColumnAnnotation>(jdtJoinColumns.length); - for (Object jdtJoinColumn : jdtJoinColumns) { - result.add(new BinaryJoinColumnAnnotation(this, (IAnnotation) jdtJoinColumn)); - } - return result; - } - - @Override - public void update() { - super.update(); - this.updateJoinColumns(); - } - - // TODO - private void updateJoinColumns() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinTableAnnotation.java deleted file mode 100644 index 615b84b17e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryJoinTableAnnotation.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.JoinTable - */ -public final class BinaryJoinTableAnnotation - extends BinaryBaseTableAnnotation - implements JoinTableAnnotation -{ - private final Vector<JoinColumnAnnotation> joinColumns; - private final Vector<JoinColumnAnnotation> inverseJoinColumns; - - - public BinaryJoinTableAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.joinColumns = this.buildJoinColumns(); - this.inverseJoinColumns = this.buildInverseJoinColumns(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.updateJoinColumns(); - this.updateInverseJoinColumns(); - } - - - // ********** AbstractBaseTableAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.JOIN_TABLE__NAME; - } - - @Override - String getSchemaElementName() { - return JPA.JOIN_TABLE__SCHEMA; - } - - @Override - String getCatalogElementName() { - return JPA.JOIN_TABLE__CATALOG; - } - - @Override - String getUniqueConstraintElementName() { - return JPA.JOIN_TABLE__UNIQUE_CONSTRAINTS; - } - - - // ********** JoinTableAnnotation implementation ********** - - // ***** join columns - public ListIterator<JoinColumnAnnotation> joinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.joinColumns); - } - - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - public JoinColumnAnnotation joinColumnAt(int index) { - return this.joinColumns.get(index); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public JoinColumnAnnotation addJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - private Vector<JoinColumnAnnotation> buildJoinColumns() { - Object[] jdtJoinColumns = this.getJdtMemberValues(JPA.JOIN_TABLE__JOIN_COLUMNS); - Vector<JoinColumnAnnotation> result = new Vector<JoinColumnAnnotation>(jdtJoinColumns.length); - for (Object jdtJoinColumn : jdtJoinColumns) { - result.add(new BinaryJoinColumnAnnotation(this, (IAnnotation) jdtJoinColumn)); - } - return result; - } - - // TODO - private void updateJoinColumns() { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation initializeJoinColumns() { - throw new UnsupportedOperationException(); - } - - // ***** inverse join columns - public ListIterator<JoinColumnAnnotation> inverseJoinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.inverseJoinColumns); - } - - public int inverseJoinColumnsSize() { - return this.inverseJoinColumns.size(); - } - - public JoinColumnAnnotation inverseJoinColumnAt(int index) { - return this.inverseJoinColumns.get(index); - } - - public int indexOfInverseJoinColumn(JoinColumnAnnotation joinColumn) { - return this.inverseJoinColumns.indexOf(joinColumn); - } - - public JoinColumnAnnotation addInverseJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public void moveInverseJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeInverseJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - private Vector<JoinColumnAnnotation> buildInverseJoinColumns() { - Object[] jdtJoinColumns = this.getJdtMemberValues(JPA.JOIN_TABLE__INVERSE_JOIN_COLUMNS); - Vector<JoinColumnAnnotation> result = new Vector<JoinColumnAnnotation>(jdtJoinColumns.length); - for (Object jdtJoinColumn : jdtJoinColumns) { - result.add(new BinaryJoinColumnAnnotation(this, (IAnnotation) jdtJoinColumn)); - } - return result; - } - - // TODO - private void updateInverseJoinColumns() { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation initializeInverseJoinColumns() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryLobAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryLobAnnotation.java deleted file mode 100644 index 2d5dc244cd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryLobAnnotation.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.LobAnnotation; - -/** - * javax.persistence.Lob - */ -public final class BinaryLobAnnotation - extends BinaryAnnotation - implements LobAnnotation -{ - public BinaryLobAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryManyToManyAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryManyToManyAnnotation.java deleted file mode 100644 index 5428fce84a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryManyToManyAnnotation.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.ManyToMany - */ -public final class BinaryManyToManyAnnotation - extends BinaryRelationshipMappingAnnotation - implements ManyToManyAnnotation -{ - private String mappedBy; - - - public BinaryManyToManyAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.mappedBy = this.buildMappedBy(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setMappedBy_(this.buildMappedBy()); - } - - - // ********** BinaryRelationshipMappingAnnotation implementation ********** - - @Override - String getTargetEntityElementName() { - return JPA.MANY_TO_MANY__TARGET_ENTITY; - } - - @Override - String getFetchElementName() { - return JPA.MANY_TO_MANY__FETCH; - } - - @Override - String getCascadeElementName() { - return JPA.MANY_TO_MANY__CASCADE; - } - - - //**************** OwnableRelationshipMappingAnnotation implementation ************** - - // ***** mapped by - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String mappedBy) { - throw new UnsupportedOperationException(); - } - - private void setMappedBy_(String mappedBy) { - String old = this.mappedBy; - this.mappedBy = mappedBy; - this.firePropertyChanged(MAPPED_BY_PROPERTY, old, mappedBy); - } - - private String buildMappedBy() { - return (String) this.getJdtMemberValue(JPA.MANY_TO_MANY__MAPPED_BY); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryManyToOneAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryManyToOneAnnotation.java deleted file mode 100644 index 77ad757c4f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryManyToOneAnnotation.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.ManyToOne - */ -public final class BinaryManyToOneAnnotation - extends BinaryRelationshipMappingAnnotation - implements ManyToOneAnnotation -{ - private Boolean optional; - - - public BinaryManyToOneAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.optional = this.buildOptional(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setOptional_(this.buildOptional()); - } - - - // ********** BinaryRelationshipMappingAnnotation implementation ********** - - @Override - String getTargetEntityElementName() { - return JPA.MANY_TO_ONE__TARGET_ENTITY; - } - - @Override - String getFetchElementName() { - return JPA.MANY_TO_ONE__FETCH; - } - - @Override - String getCascadeElementName() { - return JPA.MANY_TO_ONE__CASCADE; - } - - - // ********** ManyToOneMappingAnnotation implementation ********** - - // ***** optional - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean optional) { - throw new UnsupportedOperationException(); - } - - private void setOptional_(Boolean optional) { - Boolean old = this.optional; - this.optional = optional; - this.firePropertyChanged(OPTIONAL_PROPERTY, old, optional); - } - - private Boolean buildOptional() { - return (Boolean) this.getJdtMemberValue(JPA.MANY_TO_ONE__OPTIONAL); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryMapKeyAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryMapKeyAnnotation.java deleted file mode 100644 index 73b09dbed1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryMapKeyAnnotation.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.MapKey - */ -public final class BinaryMapKeyAnnotation - extends BinaryAnnotation - implements MapKeyAnnotation -{ - private String name; - - - public BinaryMapKeyAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** MapKeyAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(JPA.MAP_KEY__NAME); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryMappedSuperclassAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryMappedSuperclassAnnotation.java deleted file mode 100644 index 419bfaaa06..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryMappedSuperclassAnnotation.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; - -public final class BinaryMappedSuperclassAnnotation - extends BinaryAnnotation - implements MappedSuperclassAnnotation -{ - public BinaryMappedSuperclassAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedColumnAnnotation.java deleted file mode 100644 index fb9168e6e5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedColumnAnnotation.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Column - * javax.persistence.JoinColumn - * javax.persistence.DiscriminatorColumn - * javax.persistence.PrimaryKeyJoinColumn. - */ -abstract class BinaryNamedColumnAnnotation - extends BinaryAnnotation - implements NamedColumnAnnotation -{ - private String name; - private String columnDefinition; - - - BinaryNamedColumnAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - this.columnDefinition = this.buildColumnDefinition(); - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - this.setColumnDefinition_(this.buildColumnDefinition()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** NamedColumn implementation ********** - - public boolean isSpecified() { - return true; - } - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(this.getNameElementName()); - } - - abstract String getNameElementName(); - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** column definition - public String getColumnDefinition() { - return null; - } - - public void setColumnDefinition(String columnDefinition) { - throw new UnsupportedOperationException(); - } - - private void setColumnDefinition_(String columnDefinition) { - String old = this.columnDefinition; - this.columnDefinition = columnDefinition; - this.firePropertyChanged(COLUMN_DEFINITION_PROPERTY, old, columnDefinition); - } - - private String buildColumnDefinition() { - return (String) this.getJdtMemberValue(this.getColumnDefinitionElementName()); - } - - abstract String getColumnDefinitionElementName(); - - public TextRange getColumnDefinitionTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedNativeQueriesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedNativeQueriesAnnotation.java deleted file mode 100644 index bc0ebc51e0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedNativeQueriesAnnotation.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NestableNamedNativeQueryAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.NamedNativeQueries - */ -public final class BinaryNamedNativeQueriesAnnotation - extends BinaryContainerAnnotation<NestableNamedNativeQueryAnnotation> - implements NamedNativeQueriesAnnotation -{ - private final Vector<NestableNamedNativeQueryAnnotation> namedNativeQueries; - - - public BinaryNamedNativeQueriesAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.namedNativeQueries = this.buildNamedNativeQueries(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public ListIterator<NestableNamedNativeQueryAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableNamedNativeQueryAnnotation>(this.namedNativeQueries); - } - - public int nestedAnnotationsSize() { - return this.namedNativeQueries.size(); - } - - private Vector<NestableNamedNativeQueryAnnotation> buildNamedNativeQueries() { - Object[] jdtQueries = this.getJdtMemberValues(JPA.NAMED_NATIVE_QUERIES__VALUE); - Vector<NestableNamedNativeQueryAnnotation> result = new Vector<NestableNamedNativeQueryAnnotation>(jdtQueries.length); - for (Object jdtQuery : jdtQueries) { - result.add(new BinaryNamedNativeQueryAnnotation(this, (IAnnotation) jdtQuery)); - } - return result; - } - - @Override - public void update() { - super.update(); - this.updateNamedNativeQueries(); - } - - // TODO - private void updateNamedNativeQueries() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java deleted file mode 100644 index 7b96cfc170..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedNativeQueryAnnotation.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableNamedNativeQueryAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.NamedNativeQuery - */ -public final class BinaryNamedNativeQueryAnnotation - extends BinaryBaseNamedQueryAnnotation - implements NestableNamedNativeQueryAnnotation -{ - private String resultClass; - private String resultSetMapping; - - - public BinaryNamedNativeQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.resultClass = this.buildResultClass(); - this.resultSetMapping = this.buildResultSetMapping(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setResultClass_(this.buildResultClass()); - this.setResultSetMapping_(this.buildResultSetMapping()); - } - - - // ********** BinaryBaseNamedQueryAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.NAMED_NATIVE_QUERY__NAME; - } - - @Override - String getQueryElementName() { - return JPA.NAMED_NATIVE_QUERY__QUERY; - } - - @Override - String getHintsElementName() { - return JPA.NAMED_NATIVE_QUERY__HINTS; - } - - - // ********** NamedNativeQueryAnnotation implementation ********** - - // ***** result class - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String resultClass) { - throw new UnsupportedOperationException(); - } - - private void setResultClass_(String resultClass) { - String old = this.resultClass; - this.resultClass = resultClass; - this.firePropertyChanged(RESULT_CLASS_PROPERTY, old, resultClass); - } - - private String buildResultClass() { - return (String) this.getJdtMemberValue(JPA.NAMED_NATIVE_QUERY__RESULT_CLASS); - } - - public TextRange getResultClassTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** fully-qualified result class name - public String getFullyQualifiedResultClassName() { - return this.resultClass; - } - - // ***** result set mapping - public String getResultSetMapping() { - return this.resultSetMapping; - } - - public void setResultSetMapping(String resultSetMapping) { - throw new UnsupportedOperationException(); - } - - private void setResultSetMapping_(String resultSetMapping) { - String old = this.resultSetMapping; - this.resultSetMapping = resultSetMapping; - this.firePropertyChanged(RESULT_SET_MAPPING_PROPERTY, old, resultSetMapping); - } - - private String buildResultSetMapping() { - return (String) this.getJdtMemberValue(JPA.NAMED_NATIVE_QUERY__RESULT_CLASS); - } - - public TextRange getResultSetMappingTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedQueriesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedQueriesAnnotation.java deleted file mode 100644 index f671570332..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedQueriesAnnotation.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NestableNamedQueryAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.NamedQueries - */ -public final class BinaryNamedQueriesAnnotation - extends BinaryContainerAnnotation<NestableNamedQueryAnnotation> - implements NamedQueriesAnnotation -{ - private final Vector<NestableNamedQueryAnnotation> namedQueries; - - - public BinaryNamedQueriesAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.namedQueries = this.buildNamedQueries(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public ListIterator<NestableNamedQueryAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableNamedQueryAnnotation>(this.namedQueries); - } - - public int nestedAnnotationsSize() { - return this.namedQueries.size(); - } - - private Vector<NestableNamedQueryAnnotation> buildNamedQueries() { - Object[] jdtQueries = this.getJdtMemberValues(JPA.NAMED_QUERIES__VALUE); - Vector<NestableNamedQueryAnnotation> result = new Vector<NestableNamedQueryAnnotation>(jdtQueries.length); - for (Object jdtQuery : jdtQueries) { - result.add(new BinaryNamedQueryAnnotation(this, (IAnnotation) jdtQuery)); - } - return result; - } - - @Override - public void update() { - super.update(); - this.updateNamedQueries(); - } - - // TODO - private void updateNamedQueries() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java deleted file mode 100644 index 95b7b0e2a0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNamedQueryAnnotation.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableNamedQueryAnnotation; - -/** - * javax.persistence.NamedQuery - */ -public final class BinaryNamedQueryAnnotation - extends BinaryBaseNamedQueryAnnotation - implements NestableNamedQueryAnnotation -{ - public BinaryNamedQueryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - // ********** BinaryBaseNamedQueryAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.NAMED_QUERY__NAME; - } - - @Override - String getQueryElementName() { - return JPA.NAMED_QUERY__QUERY; - } - - @Override - String getHintsElementName() { - return JPA.NAMED_QUERY__HINTS; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNode.java deleted file mode 100644 index 07a15f79a1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryNode.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.AbstractJavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * Binary convenience methods - */ -// TODO hopefully this class can go away with some sort of refactoring of the -// source and binary hierarchies... -public abstract class BinaryNode - extends AbstractJavaResourceNode -{ - - // ********** construction ********** - - protected BinaryNode(JavaResourceNode parent) { - super(parent); - } - - - // ********** JavaResourceNode implementation ********** - - @Override - public IFile getFile() { - return null; // only BinaryPackageFragmentRoot has a file... - } - - public void update() { - // nothing by default - } - - public JavaResourceCompilationUnit getJavaResourceCompilationUnit() { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public void initialize(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOneToManyAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOneToManyAnnotation.java deleted file mode 100644 index fcd1c05da2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOneToManyAnnotation.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.OneToMany - */ -public final class BinaryOneToManyAnnotation - extends BinaryRelationshipMappingAnnotation - implements OneToManyAnnotation -{ - private String mappedBy; - - - public BinaryOneToManyAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.mappedBy = this.buildMappedBy(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setMappedBy_(this.buildMappedBy()); - } - - - // ********** BinaryRelationshipMappingAnnotation implementation ********** - - @Override - String getTargetEntityElementName() { - return JPA.ONE_TO_MANY__TARGET_ENTITY; - } - - @Override - String getFetchElementName() { - return JPA.ONE_TO_MANY__FETCH; - } - - @Override - String getCascadeElementName() { - return JPA.ONE_TO_MANY__CASCADE; - } - - - //**************** OwnableRelationshipMappingAnnotation implementation ************** - - // ***** mapped by - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String mappedBy) { - throw new UnsupportedOperationException(); - } - - private void setMappedBy_(String mappedBy) { - String old = this.mappedBy; - this.mappedBy = mappedBy; - this.firePropertyChanged(MAPPED_BY_PROPERTY, old, mappedBy); - } - - private String buildMappedBy() { - return (String) this.getJdtMemberValue(JPA.ONE_TO_MANY__MAPPED_BY); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOneToOneAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOneToOneAnnotation.java deleted file mode 100644 index a36c7bf1d8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOneToOneAnnotation.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.OneToOne - */ -public final class BinaryOneToOneAnnotation - extends BinaryRelationshipMappingAnnotation - implements OneToOneAnnotation -{ - private Boolean optional; - private String mappedBy; - - public BinaryOneToOneAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.optional = this.buildOptional(); - this.mappedBy = this.buildMappedBy(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setOptional_(this.buildOptional()); - this.setMappedBy_(this.buildMappedBy()); - } - - - // ********** BinaryRelationshipMappingAnnotation implementation ********** - - @Override - String getTargetEntityElementName() { - return JPA.ONE_TO_ONE__TARGET_ENTITY; - } - - @Override - String getFetchElementName() { - return JPA.ONE_TO_ONE__FETCH; - } - - @Override - String getCascadeElementName() { - return JPA.ONE_TO_ONE__CASCADE; - } - - - //**************** OwnableRelationshipMappingAnnotation implementation ************** - - // ***** mapped by - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String mappedBy) { - throw new UnsupportedOperationException(); - } - - private void setMappedBy_(String mappedBy) { - String old = this.mappedBy; - this.mappedBy = mappedBy; - this.firePropertyChanged(MAPPED_BY_PROPERTY, old, mappedBy); - } - - private String buildMappedBy() { - return (String) this.getJdtMemberValue(JPA.ONE_TO_ONE__MAPPED_BY); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - - //**************** OneToOneAnnotation implementation ************** - - // ***** optional - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean optional) { - throw new UnsupportedOperationException(); - } - - private void setOptional_(Boolean optional) { - Boolean old = this.optional; - this.optional = optional; - this.firePropertyChanged(OPTIONAL_PROPERTY, old, optional); - } - - private Boolean buildOptional() { - return (Boolean) this.getJdtMemberValue(JPA.MANY_TO_ONE__OPTIONAL); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOrderByAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOrderByAnnotation.java deleted file mode 100644 index 690fdc3263..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOrderByAnnotation.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.OrderBy - */ -public final class BinaryOrderByAnnotation - extends BinaryAnnotation - implements OrderByAnnotation -{ - private String value; - - - public BinaryOrderByAnnotation(JavaResourceNode parent, IAnnotation annotation) { - super(parent, annotation); - this.value = this.buildValue(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - // ********** OrderByAnnotation implementation ********** - - // ***** value - public String getValue() { - return this.value; - } - - public void setValue(String value) { - throw new UnsupportedOperationException(); - } - - private void setValue_(String value) { - String old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private String buildValue() { - return (String) this.getJdtMemberValue(JPA.ORDER_BY__VALUE); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOverrideAnnotation.java deleted file mode 100644 index 4e129f6372..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryOverrideAnnotation.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.OverrideAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * Common behavior for - * javax.persistence.AttributeOverride - * javax.persistence.AssociationOverride - */ -public abstract class BinaryOverrideAnnotation - extends BinaryAnnotation - implements OverrideAnnotation -{ - private String name; - - - public BinaryOverrideAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** OverrideAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(OverrideAnnotation.NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(this.getNameElementName()); - } - - protected abstract String getNameElementName(); - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragment.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragment.java deleted file mode 100644 index 734439b56d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragment.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.jdt.core.IClassFile; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.resource.java.JavaResourceClassFile; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragment; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * binary package fragment - */ -final class BinaryPackageFragment - extends BinaryNode - implements JavaResourcePackageFragment -{ - /** JDT package fragment */ - private final IPackageFragment packageFragment; - - /** - * class files in the package fragment; - * we only hold class files/types that are actually annotated; - * if the unannotated types are needed (e.g. for orm.xml or an - * inheritance tree) they can be discovered on the classpath as needed - */ - private final Vector<JavaResourceClassFile> classFiles = new Vector<JavaResourceClassFile>(); - - - // ********** construction/initialization ********** - - BinaryPackageFragment(JavaResourcePackageFragmentRoot parent, IPackageFragment packageFragment) { - super(parent); - this.packageFragment = packageFragment; - this.classFiles.addAll(this.buildClassFiles()); - } - - private Collection<JavaResourceClassFile> buildClassFiles() { - IJavaElement[] children = this.getJDTChildren(); - ArrayList<JavaResourceClassFile> result = new ArrayList<JavaResourceClassFile>(children.length); - for (IJavaElement child : children) { - IClassFile jdtClassFile = (IClassFile) child; - IType jdtType = jdtClassFile.getType(); - if (BinaryPersistentType.typeIsPersistable(jdtType)) { - JavaResourceClassFile classFile = new BinaryClassFile(this, jdtClassFile, jdtType); - if (classFile.getPersistentType().isAnnotated()) { // we only hold annotated types - result.add(classFile); - } - } - } - return result; - } - - - // ********** JarResourceNode implementation ********** - - @Override - public void update() { - super.update(); - this.updateClassFiles(); - } - - // TODO - private void updateClassFiles() { - throw new UnsupportedOperationException(); - } - - - // ********** JavaResourcePackageFragment implementation ********** - - public ListIterator<JavaResourceClassFile> classFiles() { - return new CloneListIterator<JavaResourceClassFile>(this.classFiles); - } - - public int classFilesSize() { - return this.classFiles.size(); - } - - public Iterator<JavaResourcePersistentType> persistedTypes() { - return new TransformationIterator<JavaResourceClassFile, JavaResourcePersistentType>(this.classFiles()) { - @Override - protected JavaResourcePersistentType transform(JavaResourceClassFile classFile) { - return classFile.getPersistentType(); // we only hold annotated types - } - }; - } - - - // ********** misc ********** - - private IJavaElement[] getJDTChildren() { - try { - return this.packageFragment.getChildren(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return EMPTY_JAVA_ELEMENT_ARRAY; - } - } - protected static final IJavaElement[] EMPTY_JAVA_ELEMENT_ARRAY = new IJavaElement[0]; - - @Override - public void toString(StringBuilder sb) { - sb.append(this.packageFragment.getElementName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragmentRoot.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragmentRoot.java deleted file mode 100644 index 52276c41a0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragmentRoot.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Vector; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragment; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * binary package fragment root - */ -public final class BinaryPackageFragmentRoot - extends RootBinaryNode - implements JavaResourcePackageFragmentRoot -{ - /** JDT package fragment root */ - private final IPackageFragmentRoot packageFragmentRoot; - - /** package fragments in the JAR */ - private final Vector<JavaResourcePackageFragment> packageFragments = new Vector<JavaResourcePackageFragment>(); - - - // ********** construction/initialization ********** - - public BinaryPackageFragmentRoot(IPackageFragmentRoot packageFragmentRoot, JpaAnnotationProvider annotationProvider) { - super(null, annotationProvider); // the package fragment root is the root of its sub-tree - this.packageFragmentRoot = packageFragmentRoot; - this.packageFragments.addAll(this.buildPackageFragments()); - } - - private Collection<JavaResourcePackageFragment> buildPackageFragments() { - IJavaElement[] jdtChildren = this.getJDTChildren(); - ArrayList<JavaResourcePackageFragment> result = new ArrayList<JavaResourcePackageFragment>(jdtChildren.length); - for (IJavaElement child : jdtChildren) { - result.add(new BinaryPackageFragment(this, (IPackageFragment) child)); - } - return result; - } - - - // ********** overrides ********** - - @Override - public IFile getFile() { - return (IFile) this.packageFragmentRoot.getResource(); - } - - @Override - public void update() { - super.update(); - this.updatePackageFragments(); - } - - // TODO - private void updatePackageFragments() { - throw new UnsupportedOperationException(); - } - - - // ********** JavaResourceNode.Root implementation ********** - - /** - * NB: we hold only annotated types - */ - public Iterator<JavaResourcePersistentType> persistentTypes() { - return new CompositeIterator<JavaResourcePersistentType>(this.persistedTypeIterators()); - } - - private Iterator<Iterator<JavaResourcePersistentType>> persistedTypeIterators() { - return new TransformationIterator<JavaResourcePackageFragment, Iterator<JavaResourcePersistentType>>(this.packageFragments()) { - @Override - protected Iterator<JavaResourcePersistentType> transform(JavaResourcePackageFragment fragment) { - return fragment.persistedTypes(); - } - }; - } - - - // ********** JavaResourcePackageFragmentRoot implementation ********** - - public Iterator<JavaResourcePackageFragment> packageFragments() { - return new CloneIterator<JavaResourcePackageFragment>(this.packageFragments); - } - - public int packageFragmentsSize() { - return this.packageFragments.size(); - } - - - // ********** misc ********** - - private IJavaElement[] getJDTChildren() { - try { - return this.packageFragmentRoot.getChildren(); - } catch (JavaModelException ex) { - // ignore FNFE - which can happen when the workspace is out of synch with O/S file system - if ( ! (ex.getCause() instanceof FileNotFoundException)) { - JptCorePlugin.log(ex); - } - return EMPTY_JAVA_ELEMENT_ARRAY; - } - } - private static final IJavaElement[] EMPTY_JAVA_ELEMENT_ARRAY = new IJavaElement[0]; - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getFile().getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java deleted file mode 100644 index 392396901d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java +++ /dev/null @@ -1,648 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.utility.jdt.JPTTools; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.resource.java.AccessType; -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.utility.MethodSignature; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * binary persistent attribute (field or property) - */ -final class BinaryPersistentAttribute - extends BinaryPersistentMember - implements JavaResourcePersistentAttribute -{ - private int modifiers; - - private String typeName; - - private boolean typeIsInterface; - - private boolean typeIsEnum; - - private final Vector<String> typeSuperclassNames = new Vector<String>(); - - private final Vector<String> typeInterfaceNames = new Vector<String>(); - - private final Vector<String> typeTypeArgumentNames = new Vector<String>(); - - - BinaryPersistentAttribute(JavaResourcePersistentType parent, IField field) { - this(parent, new FieldAdapter(field)); - } - - BinaryPersistentAttribute(JavaResourcePersistentType parent, IMethod method) { - this(parent, new MethodAdapter(method)); - } - - private BinaryPersistentAttribute(JavaResourcePersistentType parent, Adapter adapter) { - super(parent, adapter); - this.modifiers = this.buildModifiers(); - this.typeName = this.buildTypeName(); - - IType type = this.getType(); // shouldn't be an array... - this.typeIsInterface = this.buildTypeIsInterface(type); - this.typeIsEnum = this.buildTypeIsEnum(type); - this.typeSuperclassNames.addAll(this.buildTypeSuperclassNames(type)); - this.typeInterfaceNames.addAll(this.buildTypeInterfaceNames(type)); - - this.typeTypeArgumentNames.addAll(this.buildTypeTypeArgumentNames()); - } - - - // ******** overrides ******** - - @Override - public void update() { - super.update(); - this.setModifiers(this.buildModifiers()); - this.setTypeName(this.buildTypeName()); - - IType type = this.getType(); // shouldn't be an array... - this.setTypeIsInterface(this.buildTypeIsInterface(type)); - this.setTypeIsEnum(this.buildTypeIsEnum(type)); - this.setTypeSuperclassNames(this.buildTypeSuperclassNames(type)); - this.setTypeInterfaceNames(this.buildTypeInterfaceNames(type)); - - this.setTypeTypeArgumentNames(this.buildTypeTypeArgumentNames()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ********** BinaryPersistentMember implementation ********** - - private Adapter getAdapter() { - return (Adapter) this.adapter; - } - - @Override - Iterator<String> validAnnotationNames() { - return this.getAnnotationProvider().attributeAnnotationNames(); - } - - @Override - Annotation buildAnnotation(IAnnotation jdtAnnotation) { - return this.getAnnotationProvider().buildAttributeAnnotation(this, jdtAnnotation); - } - - Annotation buildNullAnnotation_(String annotationName) { - return this.getAnnotationProvider().buildNullAttributeAnnotation(this, annotationName); - } - - - // ********** JavaResourcePersistentAttribute implementation ********** - - public String getName() { - return this.getAdapter().getAttributeName(); - } - - @Override - public Annotation buildNullAnnotation(String annotationName) { - return (annotationName == null) ? null : this.buildNullAnnotation_(annotationName); - } - - public boolean isField() { - return this.getAdapter().isField(); - } - - public boolean isProperty() { - return ! this.isField(); - } - - public boolean isFor(MethodSignature methodSignature, int occurrence) { - throw new UnsupportedOperationException(); - } - - public AccessType getSpecifiedAccess() { - Access2_0Annotation accessAnnotation = (Access2_0Annotation) this.getAnnotation(Access2_0Annotation.ANNOTATION_NAME); - return accessAnnotation == null ? null : accessAnnotation.getValue(); - } - - public boolean typeIsSubTypeOf(String tn) { - return ((this.typeName != null) && this.typeName.equals(tn)) - || this.typeInterfaceNames.contains(tn) - || this.typeSuperclassNames.contains(tn); - } - - public boolean typeIsVariablePrimitive() { - return (this.typeName != null) && ClassTools.classNamedIsVariablePrimitive(this.typeName); - } - - // ***** modifiers - public int getModifiers() { - return this.modifiers; - } - - private void setModifiers(int modifiers) { - int old = this.modifiers; - this.modifiers = modifiers; - this.firePropertyChanged(MODIFIERS_PROPERTY, old, modifiers); - } - - /** - * zero seems like a reasonable default... - */ - private int buildModifiers() { - try { - return this.getMember().getFlags(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return 0; - } - } - - // ***** type name - public String getTypeName() { - return this.typeName; - } - - private void setTypeName(String typeName) { - String old = this.typeName; - this.typeName = typeName; - this.firePropertyChanged(TYPE_NAME_PROPERTY, old, typeName); - } - - /** - * JARs don't have array types; - * also, no generic type parameters - */ - private String buildTypeName() { - return convertTypeSignatureToTypeName(this.getTypeSignature()); - } - - // ***** type is interface - public boolean typeIsInterface() { - return this.typeIsInterface; - } - - private void setTypeIsInterface(boolean typeIsInterface) { - boolean old = this.typeIsInterface; - this.typeIsInterface = typeIsInterface; - this.firePropertyChanged(TYPE_IS_INTERFACE_PROPERTY, old, typeIsInterface); - } - - private boolean buildTypeIsInterface(IType type) { - try { - return (type != null) && type.isInterface(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - // ***** type is enum - public boolean typeIsEnum() { - return this.typeIsEnum; - } - - private void setTypeIsEnum(boolean typeIsEnum) { - boolean old = this.typeIsEnum; - this.typeIsEnum = typeIsEnum; - this.firePropertyChanged(TYPE_IS_ENUM_PROPERTY, old, typeIsEnum); - } - - private boolean buildTypeIsEnum(IType type) { - try { - return (type != null) && type.isEnum(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - // ***** type superclass hierarchy - public ListIterator<String> typeSuperclassNames() { - return new CloneListIterator<String>(this.typeSuperclassNames); - } - - public boolean typeSuperclassNamesContains(String superclassName) { - return this.typeSuperclassNames.contains(superclassName); - } - - private void setTypeSuperclassNames(List<String> typeSuperclassNames) { - this.synchronizeList(typeSuperclassNames, this.typeSuperclassNames, TYPE_SUPERCLASS_NAMES_LIST); - } - - private List<String> buildTypeSuperclassNames(IType type) { - if (type == null) { - return Collections.emptyList(); - } - - ArrayList<String> names = new ArrayList<String>(); - type = this.findSuperclass(type); - while (type != null) { - names.add(type.getFullyQualifiedName('.')); // no parameters are included here - type = this.findSuperclass(type); - } - return names; - } - - // ***** type interface hierarchy - public Iterator<String> typeInterfaceNames() { - return new CloneIterator<String>(this.typeInterfaceNames); - } - - public boolean typeInterfaceNamesContains(String interfaceName) { - return this.typeInterfaceNames.contains(interfaceName); - } - - private void setTypeInterfaceNames(Collection<String> typeInterfaceNames) { - this.synchronizeCollection(typeInterfaceNames, this.typeInterfaceNames, TYPE_INTERFACE_NAMES_COLLECTION); - } - - private Collection<String> buildTypeInterfaceNames(IType type) { - if (type == null) { - return Collections.emptySet(); - } - - HashSet<String> names = new HashSet<String>(); - while (type != null) { - this.addInterfaceNamesTo(type, names); - type = this.findSuperclass(type); - } - return names; - } - - private void addInterfaceNamesTo(IType type, HashSet<String> names) { - for (String interfaceSignature : this.getSuperInterfaceTypeSignatures(type)) { - String interfaceName = convertTypeSignatureToTypeName(interfaceSignature); - names.add(interfaceName); - IType interfaceType = this.findType(interfaceName); - if (interfaceType != null) { - this.addInterfaceNamesTo(interfaceType, names); // recurse - } - } - } - - // ***** type type argument names - public ListIterator<String> typeTypeArgumentNames() { - return new CloneListIterator<String>(this.typeTypeArgumentNames); - } - - public int typeTypeArgumentNamesSize() { - return this.typeTypeArgumentNames.size(); - } - - public String getTypeTypeArgumentName(int index) { - return this.typeTypeArgumentNames.get(index); - } - - private void setTypeTypeArgumentNames(List<String> typeTypeArgumentNames) { - this.synchronizeList(typeTypeArgumentNames, this.typeTypeArgumentNames, TYPE_TYPE_ARGUMENT_NAMES_LIST); - } - - /** - * these types can be arrays (e.g. "java.lang.String[]"); - * but they won't have any further nested generic type arguments - * (e.g. "java.util.Collection<java.lang.String>") - */ - private List<String> buildTypeTypeArgumentNames() { - String typeSignature = this.getTypeSignature(); - if (typeSignature == null) { - return Collections.emptyList(); - } - - String[] typeArgumentSignatures = Signature.getTypeArguments(typeSignature); - if (typeArgumentSignatures.length == 0) { - return Collections.emptyList(); - } - - ArrayList<String> names = new ArrayList<String>(typeArgumentSignatures.length); - for (String typeArgumentSignature : typeArgumentSignatures) { - names.add(convertTypeSignatureToTypeName(typeArgumentSignature)); - } - return names; - } - - - // ********** convenience methods ********** - - private String getTypeSignature() { - try { - return this.getAdapter().getTypeSignature(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return null; - } - } - - private IType findSuperclass(IType type) { - return this.findTypeBySignature(this.getSuperclassSignature(type)); - } - - private String getSuperclassSignature(IType type) { - try { - return type.getSuperclassTypeSignature(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return null; - } - } - - private String[] getSuperInterfaceTypeSignatures(IType type) { - try { - return type.getSuperInterfaceTypeSignatures(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return EMPTY_STRING_ARRAY; - } - } - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - private IType findTypeBySignature(String typeSignature) { - return (typeSignature == null) ? null : this.findType(convertTypeSignatureToTypeName_(typeSignature)); - } - - private IType getType() { - return (this.typeName == null) ? null : this.findType(this.typeName); - } - - private IType findType(String fullyQualifiedName) { - try { - return this.getJavaProject().findType(fullyQualifiedName); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return null; - } - } - - private IJavaProject getJavaProject() { - return this.getMember().getJavaProject(); - } - - - - // ********** adapters ********** - - /** - * Adapt an IField or IMethod. - */ - interface Adapter - extends BinaryPersistentMember.Adapter - { - /** - * Return the field or getter method's "attribute" name - * (e.g. field "foo" -> "foo"; method "getFoo" -> "foo"). - */ - String getAttributeName(); - - /** - * Return whether the attribute is a Java field (as opposed to a method). - */ - boolean isField(); - - /** - * Return the attribute's type signature. - */ - String getTypeSignature() throws JavaModelException; - } - - /** - * IField adapter - */ - static class FieldAdapter - implements Adapter - { - final IField field; - - FieldAdapter(IField field) { - super(); - this.field = field; - } - - public IField getMember() { - return this.field; - } - - public boolean isPersistable() { - return this.field.exists() && JPTTools.fieldIsPersistable(new JPTToolsAdapter()); - } - - public IAnnotation[] getAnnotations() throws JavaModelException { - return this.field.getAnnotations(); - } - - public String getAttributeName() { - return this.field.getElementName(); - } - - public boolean isField() { - return true; - } - - public String getTypeSignature() throws JavaModelException { - return this.field.getTypeSignature(); - } - - /** - * JPTTools needs an adapter so it can work with either an IField - * or an IVariableBinding etc. - */ - class JPTToolsAdapter implements JPTTools.FieldAdapter { - public int getModifiers() { - try { - return FieldAdapter.this.field.getFlags(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return 0; - } - } - - } - - } - - /** - * IMethod adapter - */ - static class MethodAdapter - implements Adapter - { - final IMethod method; - static final IMethod[] EMPTY_METHOD_ARRAY = new IMethod[0]; - - MethodAdapter(IMethod method) { - super(); - this.method = method; - } - - public IMethod getMember() { - return this.method; - } - - public boolean isPersistable() { - return JPTTools.methodIsPersistablePropertyGetter(new JPTToolsAdapter()); - } - - public IAnnotation[] getAnnotations() throws JavaModelException { - return this.method.getAnnotations(); - } - - public String getAttributeName() { - return NameTools.convertGetterMethodNameToPropertyName(this.method.getElementName()); - } - - public boolean isField() { - return false; - } - - public String getTypeSignature() throws JavaModelException { - return this.method.getReturnType(); - } - - /** - * JPTTools needs an adapter so it can work with either an IMethod - * or an IMethodBinding etc. - */ - abstract static class AbstractJPTToolsAdapter - implements JPTTools.SimpleMethodAdapter - { - AbstractJPTToolsAdapter() { - super(); - } - - abstract IMethod getMethod(); - - public int getModifiers() { - try { - return this.getMethod().getFlags(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return 0; - } - } - - public String getReturnTypeErasureName() { - return convertTypeSignatureToTypeName(this.getReturnTypeSignature()); - } - - private String getReturnTypeSignature() { - try { - return this.getMethod().getReturnType(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return null; - } - } - - public boolean isConstructor() { - try { - return this.getMethod().isConstructor(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - } - - static class SimpleJPTToolsAdapter - extends AbstractJPTToolsAdapter - { - private final IMethod method; - - SimpleJPTToolsAdapter(IMethod method) { - super(); - this.method = method; - } - - @Override - IMethod getMethod() { - return this.method; - } - - } - - class JPTToolsAdapter - extends AbstractJPTToolsAdapter - implements JPTTools.MethodAdapter - { - JPTToolsAdapter() { - super(); - } - - @Override - IMethod getMethod() { - return MethodAdapter.this.method; - } - - public String getName() { - return this.getMethod().getElementName(); - } - - public int getParametersLength() { - return this.getMethod().getParameterTypes().length; - } - - public JPTTools.SimpleMethodAdapter getSibling(String name) { - for (IMethod sibling : this.getSiblings()) { - if ((sibling.getParameterTypes().length == 0) - && sibling.getElementName().equals(name)) { - return new SimpleJPTToolsAdapter(sibling); - } - } - return null; - } - - public JPTTools.SimpleMethodAdapter getSibling(String name, String parameterTypeErasureName) { - for (IMethod sibling : this.getSiblings()) { - String[] parmTypes = sibling.getParameterTypes(); - if ((parmTypes.length == 1) - && sibling.getElementName().equals(name) - && convertTypeSignatureToTypeName(parmTypes[0]).equals(parameterTypeErasureName)) { - return new SimpleJPTToolsAdapter(sibling); - } - } - return null; - } - - private IMethod[] getSiblings() { - try { - return this.getMethod().getDeclaringType().getMethods(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return EMPTY_METHOD_ARRAY; - } - } - - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java deleted file mode 100644 index c8676f67c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java +++ /dev/null @@ -1,283 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.Iterator; -import java.util.Vector; -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IMember; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; - -/** - * binary persistent member - */ -abstract class BinaryPersistentMember - extends BinaryNode - implements JavaResourcePersistentMember -{ - /** JDT member adapter */ - final Adapter adapter; - - /** annotations */ - final Vector<Annotation> annotations = new Vector<Annotation>(); - - boolean persistable; - - - // ********** construction/initialization ********** - - public BinaryPersistentMember(JavaResourceNode parent, Adapter adapter) { - super(parent); - this.adapter = adapter; - this.initializeAnnotations(); - this.persistable = this.buildPersistable(); - } - - private void initializeAnnotations() { - for (IAnnotation annotation : this.getJdtAnnotations()) { - this.addAnnotation(annotation); - } - } - - private void addAnnotation(IAnnotation jdtAnnotation) { - if (this.annotationIsValid(jdtAnnotation)) { - this.annotations.add(this.buildAnnotation(jdtAnnotation)); - } - } - - - // ********** updating ********** - - @Override - public void update() { - super.update(); - this.updateAnnotations(); - this.setPersistable(this.buildPersistable()); - } - - // TODO - private void updateAnnotations() { - throw new UnsupportedOperationException(); - } - - - // ********** annotations ********** - - public Iterator<Annotation> annotations() { - return this.getAnnotations().iterator(); - } - - private Iterable<Annotation> getAnnotations() { - return new LiveCloneIterable<Annotation>(this.annotations); - } - - public int annotationsSize() { - return this.annotations.size(); - } - - public Annotation getAnnotation(String annotationName) { - return this.selectAnnotationNamed(this.getAnnotations(), annotationName); - } - - public Annotation getNonNullAnnotation(String annotationName) { - Annotation annotation = this.getAnnotation(annotationName); - return (annotation != null) ? annotation : this.buildNullAnnotation(annotationName); - } - - public Iterator<NestableAnnotation> annotations( - String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = - getContainerAnnotation(containerAnnotationName); - if (containerAnnotation != null) { - return containerAnnotation.nestedAnnotations(); - } - NestableAnnotation nestableAnnotation = - getNestableAnnotation(nestableAnnotationName); - return (nestableAnnotation == null) ? - EmptyListIterator.<NestableAnnotation>instance() : - new SingleElementIterator<NestableAnnotation>(nestableAnnotation); - } - - private NestableAnnotation getNestableAnnotation(String annotationName) { - return (NestableAnnotation) this.getAnnotation(annotationName); - } - - @SuppressWarnings("unchecked") - private ContainerAnnotation<NestableAnnotation> getContainerAnnotation(String annotationName) { - return (ContainerAnnotation<NestableAnnotation>) this.getAnnotation(annotationName); - } - - private boolean annotationIsValid(IAnnotation jdtAnnotation) { - return CollectionTools.contains( - this.validAnnotationNames(), jdtAnnotation.getElementName()); - } - - abstract Iterator<String> validAnnotationNames(); - - abstract Annotation buildAnnotation(IAnnotation jdtAnnotation); - - abstract Annotation buildNullAnnotation(String annotationName); - - - // ********** simple state ********** - - public boolean isPersistable() { - return this.persistable; - } - - private void setPersistable(boolean persistable) { - boolean old = this.persistable; - this.persistable = persistable; - this.firePropertyChanged(PERSISTABLE_PROPERTY, old, persistable); - } - - private boolean buildPersistable() { - return this.adapter.isPersistable(); - } - - public boolean isAnnotated() { - return ! this.annotations.isEmpty(); - } - - - // ********** miscellaneous ********** - - IMember getMember() { - return this.adapter.getMember(); - } - - private Annotation selectAnnotationNamed(Iterable<Annotation> annotations, String annotationName) { - for (Annotation annotation : annotations) { - if (annotation.getAnnotationName().equals(annotationName)) { - return annotation; - } - } - return null; - } - - /** - * convenience method - */ - <T extends JavaResourcePersistentMember> Iterator<T> persistableMembers(Iterator<T> members) { - return new FilteringIterator<T, T>(members) { - @Override - protected boolean accept(T m) { - return m.isPersistable(); - } - }; - } - - /** - * Strip off the type signature's parameters if present. - * Convert to a readable string. - */ - static String convertTypeSignatureToTypeName(String typeSignature) { - return (typeSignature == null) ? null : convertTypeSignatureToTypeName_(typeSignature); - } - - /** - * no null check - */ - static String convertTypeSignatureToTypeName_(String typeSignature) { - return Signature.toString(Signature.getTypeErasure(typeSignature)); - } - - private IAnnotation[] getJdtAnnotations() { - try { - return this.adapter.getAnnotations(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return EMPTY_JDT_ANNOTATION_ARRAY; - } - } - private static final IAnnotation[] EMPTY_JDT_ANNOTATION_ARRAY = new IAnnotation[0]; - - - // ********** IMember adapter ********** - - interface Adapter { - /** - * Return the adapter's JDT member (IType, IField, IMethod). - */ - IMember getMember(); - - /** - * Return whether the adapter's member is "persistable" - * (i.e. according to the JPA spec the member can be mapped) - */ - boolean isPersistable(); - - /** - * Return the adapter's member's JDT annotations. - */ - IAnnotation[] getAnnotations() throws JavaModelException; - } - - - // ********** unsupported JavaResourcePersistentMember implementation ********** - - public Annotation addAnnotation(String annotationName) { - throw new UnsupportedOperationException(); - } - - public Annotation addAnnotation(String annotationName, AnnotationInitializer foo) { - throw new UnsupportedOperationException(); - } - - public NestableAnnotation addAnnotation( - int index, String nestableAnnotationName, String containerAnnotationName) { - throw new UnsupportedOperationException(); - } - - public void moveAnnotation( - int targetIndex, int sourceIndex, String containerAnnotationName) { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation(String annotationName) { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation( - int index, String nestableAnnotationName, String containerAnnotationName) { - throw new UnsupportedOperationException(); - } - - public Annotation setPrimaryAnnotation( - String primaryAnnotationName, String[] supportingAnnotationNames) { - throw new UnsupportedOperationException(); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public void resolveTypes(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean isFor(String memberName, int occurrence) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java deleted file mode 100644 index 0ad5c16718..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java +++ /dev/null @@ -1,543 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Vector; -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.utility.jdt.JPTTools; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.MethodSignature; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -/** - * binary persistent type - */ -final class BinaryPersistentType - extends BinaryPersistentMember - implements JavaResourcePersistentType -{ - private String name; - - private String qualifiedName; - - private String superclassQualifiedName; - - private boolean abstract_; // 'abstract' is a reserved word - - private final Vector<JavaResourcePersistentAttribute> fields; - - private final Vector<JavaResourcePersistentAttribute> methods; - - private AccessType access; - - - // ********** construction/initialization ********** - - BinaryPersistentType(JavaResourceNode parent, IType type) { - super(parent, new TypeAdapter(type)); - this.name = this.buildName(); - this.qualifiedName = this.buildQualifiedName(); - this.superclassQualifiedName = this.buildSuperclassQualifiedName(); - this.abstract_ = this.buildAbstract(); - this.fields = this.buildFields(); - this.methods = this.buildMethods(); - // need to wait until everything is built to calculate 'access' - this.access = this.buildAccess(); - } - - - // ********** overrides ********** - - @Override - public void update() { - super.update(); - this.setName(this.buildName()); - this.setQualifiedName(this.buildQualifiedName()); - this.setSuperclassQualifiedName(this.buildSuperclassQualifiedName()); - this.setAbstract(this.buildAbstract()); - this.updateFields(); - this.updateMethods(); - // need to wait until everything is updated to calculate 'access' - this.setAccess(this.buildAccess()); - } - - // TODO - private void updateFields() { - throw new UnsupportedOperationException(); - } - - // TODO - private void updateMethods() { - throw new UnsupportedOperationException(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** BinaryPersistentMember implementation ********** - - @Override - Annotation buildAnnotation(IAnnotation jdtAnnotation) { - return this.getAnnotationProvider().buildTypeAnnotation(this, jdtAnnotation); - } - - @Override - Annotation buildNullAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullTypeAnnotation(this, annotationName); - } - - @Override - Iterator<String> validAnnotationNames() { - return this.getAnnotationProvider().typeAnnotationNames(); - } - - - // ********** JavaResourcePersistentType implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - private void setName(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return this.getMember().getElementName(); - } - - // ***** qualified name - public String getQualifiedName() { - return this.qualifiedName; - } - - private void setQualifiedName(String qualifiedName) { - String old = this.qualifiedName; - this.qualifiedName = qualifiedName; - this.firePropertyChanged(QUALIFIED_NAME_PROPERTY, old, qualifiedName); - } - - private String buildQualifiedName() { - return this.getMember().getFullyQualifiedName('.'); // no parameters are included here - } - - // ***** superclass qualified name - public String getSuperclassQualifiedName() { - return this.superclassQualifiedName; - } - - private void setSuperclassQualifiedName(String superclassQualifiedName) { - String old = this.superclassQualifiedName; - this.superclassQualifiedName = superclassQualifiedName; - this.firePropertyChanged(SUPERCLASS_QUALIFIED_NAME_PROPERTY, old, superclassQualifiedName); - } - - private String buildSuperclassQualifiedName() { - return convertTypeSignatureToTypeName(this.getSuperclassTypeSignature()); - } - - private String getSuperclassTypeSignature() { - try { - return this.getMember().getSuperclassTypeSignature(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return null; - } - } - - // ***** abstract - public boolean isAbstract() { - return this.abstract_; - } - - private void setAbstract(boolean abstract_) { - boolean old = this.abstract_; - this.abstract_ = abstract_; - this.firePropertyChanged(ABSTRACT_PROPERTY, old, abstract_); - } - - private boolean buildAbstract() { - try { - return Flags.isAbstract(this.getMember().getFlags()); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - // ***** access - public AccessType getAccess() { - return this.access; - } - - private void setAccess(AccessType access) { - AccessType old = this.access; - this.access = access; - this.firePropertyChanged(ACCESS_PROPERTY, old, access); - } - - private AccessType buildAccess() { - return JPTTools.buildAccess(this); - } - - public boolean isMapped() { - for (Annotation each : CollectionTools.iterable(annotations())) { - if (CollectionTools.contains( - getAnnotationProvider().typeMappingAnnotationNames(), - each.getAnnotationName())) { - return true; - } - } - return false; - } - - /** - * check only persistable attributes - */ - public boolean hasAnyAnnotatedAttributes() { - for (Iterator<JavaResourcePersistentAttribute> stream = this.persistableAttributes(); stream.hasNext(); ) { - if (stream.next().isAnnotated()) { - return true; - } - } - return false; - } - - @Override - public IType getMember() { - return (IType) super.getMember(); - } - - - // ********** fields ********** - - public Iterator<JavaResourcePersistentAttribute> fields() { - return this.getFields().iterator(); - } - - private Iterable<JavaResourcePersistentAttribute> getFields() { - return new LiveCloneIterable<JavaResourcePersistentAttribute>(this.fields); - } - - public Iterator<JavaResourcePersistentAttribute> persistableFields() { - return this.persistableMembers(this.fields()); - } - - public Iterator<JavaResourcePersistentAttribute> persistableFieldsWithSpecifiedFieldAccess() { - return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableFields()) { - @Override - protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) { - return resourceAttribute.getSpecifiedAccess() == AccessType.FIELD; - } - }; - } - - private void addField(JavaResourcePersistentAttribute field) { - this.addItemToCollection(field, this.fields, FIELDS_COLLECTION); - } - - private JavaResourcePersistentAttribute getField(String fieldName, int occurrence) { - for (JavaResourcePersistentAttribute field : this.getFields()) { - if (field.isFor(fieldName, occurrence)) { - return field; - } - } - return null; - } - - private void removeFields(Collection<JavaResourcePersistentAttribute> remove) { - this.removeItemsFromCollection(remove, this.fields, FIELDS_COLLECTION); - } - - private Vector<JavaResourcePersistentAttribute> buildFields() { - IField[] jdtFields = this.getFields(this.getMember()); - Vector<JavaResourcePersistentAttribute> result = new Vector<JavaResourcePersistentAttribute>(jdtFields.length); - for (IField jdtField : jdtFields) { - result.add(this.buildField(jdtField)); - } - return result; - } - - private IField[] getFields(IType type) { - try { - return type.getFields(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return EMPTY_FIELD_ARRAY; - } - } - private static final IField[] EMPTY_FIELD_ARRAY = new IField[0]; - - private JavaResourcePersistentAttribute buildField(IField jdtField) { - return new BinaryPersistentAttribute(this, jdtField); - } - - - // ********** methods ********** - - public Iterator<JavaResourcePersistentAttribute> methods() { - return this.getMethods().iterator(); - } - - private Iterable<JavaResourcePersistentAttribute> getMethods() { - return new LiveCloneIterable<JavaResourcePersistentAttribute>(this.methods); - } - - public Iterator<JavaResourcePersistentAttribute> persistableProperties() { - return persistableMembers(this.methods()); - } - - public Iterator<JavaResourcePersistentAttribute> persistablePropertiesWithSpecifiedPropertyAccess() { - return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableProperties()) { - @Override - protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) { - return resourceAttribute.getSpecifiedAccess() == AccessType.PROPERTY; - } - }; - } - - private JavaResourcePersistentAttribute getMethod(MethodSignature signature, int occurrence) { - for (JavaResourcePersistentAttribute method : this.getMethods()) { - if (method.isFor(signature, occurrence)) { - return method; - } - } - return null; - } - - private void addMethod(JavaResourcePersistentAttribute method) { - this.addItemToCollection(method, this.methods, METHODS_COLLECTION); - } - - private void removeMethods(Collection<JavaResourcePersistentAttribute> remove) { - this.removeItemsFromCollection(remove, this.methods, METHODS_COLLECTION); - } - - private Vector<JavaResourcePersistentAttribute> buildMethods() { - IMethod[] jdtMethods = this.getMethods(this.getMember()); - Vector<JavaResourcePersistentAttribute> result = new Vector<JavaResourcePersistentAttribute>(jdtMethods.length); - for (IMethod jdtMethod : jdtMethods) { - result.add(this.buildMethod(jdtMethod)); - } - return result; - } - - private IMethod[] getMethods(IType type) { - try { - return type.getMethods(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return EMPTY_METHOD_ARRAY; - } - } - private static final IMethod[] EMPTY_METHOD_ARRAY = new IMethod[0]; - - private JavaResourcePersistentAttribute buildMethod(IMethod jdtMethod) { - return new BinaryPersistentAttribute(this, jdtMethod); - } - - - // ********** attributes ********** - - @SuppressWarnings("unchecked") - public Iterator<JavaResourcePersistentAttribute> persistableAttributes() { - return new CompositeIterator<JavaResourcePersistentAttribute>( - this.persistableFields(), - this.persistableProperties() - ); - } - - public Iterator<JavaResourcePersistentAttribute> persistableAttributes(AccessType specifiedAccess) { - if (specifiedAccess == null) { - throw new IllegalArgumentException("specified access is null"); //$NON-NLS-1$ - } - return (specifiedAccess == AccessType.FIELD) ? - this.persistableAttributesForFieldAccessType() : - this.persistableAttributesForPropertyAccessType(); - } - - @SuppressWarnings("unchecked") - private Iterator<JavaResourcePersistentAttribute> persistableAttributesForFieldAccessType() { - return new CompositeIterator<JavaResourcePersistentAttribute>( - this.persistableFields(), - this.persistablePropertiesWithSpecifiedPropertyAccess() - ); - } - - @SuppressWarnings("unchecked") - private Iterator<JavaResourcePersistentAttribute> persistableAttributesForPropertyAccessType() { - return new CompositeIterator<JavaResourcePersistentAttribute>( - this.persistableProperties(), - this.persistableFieldsWithSpecifiedFieldAccess() - ); - } - - - // ********** IType adapter ********** - - static class TypeAdapter implements Adapter { - private final IType type; - - TypeAdapter(IType type) { - super(); - this.type = type; - } - - public IType getMember() { - return this.type; - } - - public boolean isPersistable() { - return true; // we only build a JAR type if it is "persistable" - } - - public IAnnotation[] getAnnotations() throws JavaModelException { - return this.type.getAnnotations(); - } - - } - - - // ********** "persistable" check ********** - - static boolean typeIsPersistable(IType type) { - return (type != null) - && type.exists() - && JPTTools.typeIsPersistable(new JPTToolsAdapter(type)); - } - - - // ********** JPT tools adapter ********** - - /** - * JPTTools needs an adapter so it can work with either an IType - * or an ITypeBinding etc. - */ - static class JPTToolsAdapter implements JPTTools.TypeAdapter { - private final IType type; - - protected JPTToolsAdapter(IType type) { - super(); - if (type == null) { - throw new NullPointerException(); - } - this.type = type; - } - - public int getModifiers() { - try { - return this.type.getFlags(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return 0; - } - } - - public boolean isAnnotation() { - try { - return this.type.isAnnotation(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - public boolean isAnonymous() { - try { - return this.type.isAnonymous(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - public boolean isArray() { - return false; // ??? - } - - public boolean isEnum() { - try { - return this.type.isEnum(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - public boolean isInterface() { - try { - return this.type.isInterface(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - public boolean isLocal() { - try { - return this.type.isLocal(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - public boolean isMember() { - try { - return this.type.isMember(); - } catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return false; - } - } - - public boolean isPrimitive() { - return false; // ??? - } - - } - - - // ********** unsupported JavaResourcePersistentType implementation ********** - - public Iterator<JavaResourcePersistentType> types() { - throw new UnsupportedOperationException(); - } - - public Iterator<JavaResourcePersistentType> allTypes() { - throw new UnsupportedOperationException(); - } - - public Iterator<JavaResourcePersistentType> persistableTypes() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentTypeCache.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentTypeCache.java deleted file mode 100644 index bc1b8a1225..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentTypeCache.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.Iterator; -import java.util.Vector; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.jdt.core.IType; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentTypeCache; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * cache used to hold binary "external" Java resource persistent types - * (typically derived from JARs on the project's build path) - */ -public final class BinaryPersistentTypeCache - extends RootBinaryNode - implements JavaResourcePersistentTypeCache -{ - /** populated on-demand */ - private final Vector<Entry> entries = new Vector<Entry>(); - - - // ********** construction ********** - - public BinaryPersistentTypeCache(JpaAnnotationProvider annotationProvider) { - super(null, annotationProvider); - } - - - // ********** JavaResourceNode.Root implementation ********** - - public Iterator<JavaResourcePersistentType> persistentTypes() { - return this.getPersistentTypes().iterator(); - } - - private Iterable<JavaResourcePersistentType> getPersistentTypes() { - return new TransformationIterable<Entry, JavaResourcePersistentType>(this.getEntries()) { - @Override - protected JavaResourcePersistentType transform(Entry entry) { - return entry.persistentType; - } - }; - } - - private Iterable<Entry> getEntries() { - return new LiveCloneIterable<Entry>(this.entries); - } - - - // ********** JavaResourcePersistentTypeCache implementation ********** - - public int persistentTypesSize() { - return this.entries.size(); - } - - public JavaResourcePersistentType addPersistentType(IType jdtType) { - Entry entry = this.buildEntry(jdtType); - this.entries.add(entry); - this.fireItemAdded(PERSISTENT_TYPES_COLLECTION, entry.persistentType); - return entry.persistentType; - } - - private Entry buildEntry(IType jdtType) { - return new Entry(this.buildPersistentType(jdtType), jdtType.getResource()); - } - - private JavaResourcePersistentType buildPersistentType(IType jdtType) { - return new BinaryPersistentType(this, jdtType); - } - - public boolean removePersistentTypes(IFile jarFile) { - boolean modified = false; - for (Entry entry : this.getEntries()) { - IResource resource = entry.resource; - if ((resource != null) && resource.equals(jarFile)) { - this.removeEntry(entry); - modified = true; - } - } - return modified; - } - - private void removeEntry(Entry entry) { - this.entries.remove(entry); - this.fireItemRemoved(PERSISTENT_TYPES_COLLECTION, entry.persistentType); - } - - - // ********** overrides ********** - - /** - * Ignore changes to this collection. Adds can be ignored since they are triggered - * by requests that will, themselves, trigger updates (typically during the - * update of an object that calls a setter with the newly-created resource - * type). Deletes will be accompanied by manual updates. - */ - @Override - protected void aspectChanged(String aspectName) { - if ((aspectName != null) && ! aspectName.equals(PERSISTENT_TYPES_COLLECTION)) { - super.aspectChanged(aspectName); - } - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.entries); - } - - - // ********** cache entry ********** - - /** - * Associate a persistent type with its resource. - * This will be a JAR in the case of a type loaded from a JAR that is in - * the Eclipse workspace. The resource will be null for a type loaded - * from a JAR or class directory outside of the workspace. - */ - static class Entry { - final JavaResourcePersistentType persistentType; - final IResource resource; - - Entry(JavaResourcePersistentType persistentType, IResource resource) { - super(); - this.persistentType = persistentType; - this.resource = resource; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.persistentType); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPrimaryKeyJoinColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPrimaryKeyJoinColumnAnnotation.java deleted file mode 100644 index 35a6401ce0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPrimaryKeyJoinColumnAnnotation.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestablePrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.PrimaryKeyJoinColumn - */ -public final class BinaryPrimaryKeyJoinColumnAnnotation - extends BinaryNamedColumnAnnotation - implements NestablePrimaryKeyJoinColumnAnnotation -{ - private String referencedColumnName; - - - public BinaryPrimaryKeyJoinColumnAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.referencedColumnName = this.buildReferencedColumnName(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setReferencedColumnName_(this.buildReferencedColumnName()); - } - - - // ********** AbstractNamedColumn implementation ********** - - @Override - String getNameElementName() { - return JPA.PRIMARY_KEY_JOIN_COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.PRIMARY_KEY_JOIN_COLUMN__COLUMN_DEFINITION; - } - - - // ********** PrimaryKeyJoinColumn implementation ********** - - // ***** referenced column name - public String getReferencedColumnName() { - return this.referencedColumnName; - } - - public void setReferencedColumnName(String referencedColumnName) { - throw new UnsupportedOperationException(); - } - - private void setReferencedColumnName_(String referencedColumnName) { - String old = this.referencedColumnName; - this.referencedColumnName = referencedColumnName; - this.firePropertyChanged(REFERENCED_COLUMN_NAME_PROPERTY, old, referencedColumnName); - } - - private String buildReferencedColumnName() { - return (String) this.getJdtMemberValue(JPA.PRIMARY_KEY_JOIN_COLUMN__REFERENCED_COLUMN_NAME); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPrimaryKeyJoinColumnsAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPrimaryKeyJoinColumnsAnnotation.java deleted file mode 100644 index 0951dbc459..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPrimaryKeyJoinColumnsAnnotation.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestablePrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.PrimaryKeyJoinColumns - */ -public final class BinaryPrimaryKeyJoinColumnsAnnotation - extends BinaryContainerAnnotation<NestablePrimaryKeyJoinColumnAnnotation> - implements PrimaryKeyJoinColumnsAnnotation -{ - private final Vector<NestablePrimaryKeyJoinColumnAnnotation> pkJoinColumns; - - - public BinaryPrimaryKeyJoinColumnsAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.pkJoinColumns = this.buildPkJoinColumns(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public ListIterator<NestablePrimaryKeyJoinColumnAnnotation> nestedAnnotations() { - return new CloneListIterator<NestablePrimaryKeyJoinColumnAnnotation>(this.pkJoinColumns); - } - - public int nestedAnnotationsSize() { - return this.pkJoinColumns.size(); - } - - private Vector<NestablePrimaryKeyJoinColumnAnnotation> buildPkJoinColumns() { - Object[] jdtJoinColumns = this.getJdtMemberValues(JPA.PRIMARY_KEY_JOIN_COLUMNS__VALUE); - Vector<NestablePrimaryKeyJoinColumnAnnotation> result = new Vector<NestablePrimaryKeyJoinColumnAnnotation>(jdtJoinColumns.length); - for (Object jdtJoinColumn : jdtJoinColumns) { - result.add(new BinaryPrimaryKeyJoinColumnAnnotation(this, (IAnnotation) jdtJoinColumn)); - } - return result; - } - - @Override - public void update() { - super.update(); - this.updatePkJoinColumns(); - } - - // TODO - private void updatePkJoinColumns() { - throw new UnsupportedOperationException(); - } - -} - diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryQueryHintAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryQueryHintAnnotation.java deleted file mode 100644 index c3f76581e6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryQueryHintAnnotation.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.QueryHint - */ -class BinaryQueryHintAnnotation - extends BinaryAnnotation - implements QueryHintAnnotation -{ - private String name; - private String value; - - - BinaryQueryHintAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.name = this.buildName(); - this.value = this.buildValue(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setName_(this.buildName()); - this.setValue_(this.buildValue()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** QueryHintAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - throw new UnsupportedOperationException(); - } - - private void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return (String) this.getJdtMemberValue(JPA.QUERY_HINT__NAME); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** value - public String getValue() { - return this.value; - } - - public void setValue(String value) { - throw new UnsupportedOperationException(); - } - - private void setValue_(String value) { - String old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private String buildValue() { - return (String) this.getJdtMemberValue(JPA.QUERY_HINT__VALUE); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryRelationshipMappingAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryRelationshipMappingAnnotation.java deleted file mode 100644 index 1ba6e11ed3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryRelationshipMappingAnnotation.java +++ /dev/null @@ -1,212 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.CascadeType; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.ArrayTools; - -/** - * javax.persistence.ManyToMany - * javax.persistence.ManyToOne - * javax.persistence.OneToMany - * javax.persistence.OneToOne - */ -abstract class BinaryRelationshipMappingAnnotation - extends BinaryAnnotation - implements RelationshipMappingAnnotation -{ - String targetEntity; - FetchType fetch; - boolean cascadeAll; - boolean cascadeMerge; - boolean cascadePersist; - boolean cascadeRefresh; - boolean cascadeRemove; - - - BinaryRelationshipMappingAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.targetEntity = this.buildTargetEntity(); - this.fetch = this.buildFetch(); - - CascadeType[] cascadeTypes = this.buildCascadeTypes(); - this.cascadeAll = ArrayTools.contains(cascadeTypes, CascadeType.ALL); - this.cascadeMerge = ArrayTools.contains(cascadeTypes, CascadeType.MERGE); - this.cascadePersist = ArrayTools.contains(cascadeTypes, CascadeType.PERSIST); - this.cascadeRefresh = ArrayTools.contains(cascadeTypes, CascadeType.REFRESH); - this.cascadeRemove = ArrayTools.contains(cascadeTypes, CascadeType.REMOVE); - } - - @Override - public void update() { - super.update(); - this.setTargetEntity_(this.buildTargetEntity()); - this.setFetch_(this.buildFetch()); - - CascadeType[] cascadeTypes = this.buildCascadeTypes(); - this.setCascadeAll_(ArrayTools.contains(cascadeTypes, CascadeType.ALL)); - this.setCascadeMerge_(ArrayTools.contains(cascadeTypes, CascadeType.MERGE)); - this.setCascadePersist_(ArrayTools.contains(cascadeTypes, CascadeType.PERSIST)); - this.setCascadeRefresh_(ArrayTools.contains(cascadeTypes, CascadeType.REFRESH)); - this.setCascadeRemove_(ArrayTools.contains(cascadeTypes, CascadeType.REMOVE)); - } - - - // ********** RelationshipMappingAnnotation implementation ********** - - // ***** target entity - public String getTargetEntity() { - return this.targetEntity; - } - - public void setTargetEntity(String targetEntity) { - throw new UnsupportedOperationException(); - } - - private void setTargetEntity_(String targetEntity) { - String old = this.targetEntity; - this.targetEntity = targetEntity; - this.firePropertyChanged(TARGET_ENTITY_PROPERTY, old, targetEntity); - this.firePropertyChanged(FULLY_QUALIFIED_TARGET_ENTITY_CLASS_NAME_PROPERTY, old, targetEntity); - } - - private String buildTargetEntity() { - return (String) this.getJdtMemberValue(this.getTargetEntityElementName()); - } - - abstract String getTargetEntityElementName(); - - public TextRange getTargetEntityTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** fully-qualified target entity class name - public String getFullyQualifiedTargetEntityClassName() { - return this.targetEntity; - } - - // ***** fetch - public FetchType getFetch() { - return this.fetch; - } - - public void setFetch(FetchType fetch) { - throw new UnsupportedOperationException(); - } - - private void setFetch_(FetchType fetch) { - FetchType old = this.fetch; - this.fetch = fetch; - this.firePropertyChanged(FETCH_PROPERTY, old, fetch); - } - - private FetchType buildFetch() { - return FetchType.fromJavaAnnotationValue(this.getJdtMemberValue(this.getFetchElementName())); - } - - abstract String getFetchElementName(); - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** cascade - private CascadeType[] buildCascadeTypes() { - return CascadeType.fromJavaAnnotationValues(this.getJdtMemberValues(this.getCascadeElementName())); - } - - abstract String getCascadeElementName(); - - public TextRange getCascadeTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** cascade all - public boolean isCascadeAll() { - return this.cascadeAll; - } - - public void setCascadeAll(boolean cascadeAll) { - throw new UnsupportedOperationException(); - } - - private void setCascadeAll_(boolean cascadeAll) { - boolean old = this.cascadeAll; - this.cascadeAll = cascadeAll; - this.firePropertyChanged(CASCADE_ALL_PROPERTY, old, cascadeAll); - } - - // ***** cascade merge - public boolean isCascadeMerge() { - return this.cascadeMerge; - } - - public void setCascadeMerge(boolean cascadeMerge) { - throw new UnsupportedOperationException(); - } - - private void setCascadeMerge_(boolean cascadeMerge) { - boolean old = this.cascadeMerge; - this.cascadeMerge = cascadeMerge; - this.firePropertyChanged(CASCADE_MERGE_PROPERTY, old, cascadeMerge); - } - - // ***** cascade persist - public boolean isCascadePersist() { - return this.cascadePersist; - } - - public void setCascadePersist(boolean cascadePersist) { - throw new UnsupportedOperationException(); - } - - private void setCascadePersist_(boolean cascadePersist) { - boolean old = this.cascadePersist; - this.cascadePersist = cascadePersist; - this.firePropertyChanged(CASCADE_PERSIST_PROPERTY, old, cascadePersist); - } - - // ***** cascade refresh - public boolean isCascadeRefresh() { - return this.cascadeRefresh; - } - - public void setCascadeRefresh(boolean cascadeRefresh) { - throw new UnsupportedOperationException(); - } - - private void setCascadeRefresh_(boolean cascadeRefresh) { - boolean old = this.cascadeRefresh; - this.cascadeRefresh = cascadeRefresh; - this.firePropertyChanged(CASCADE_REFRESH_PROPERTY, old, cascadeRefresh); - } - - // ***** cascade remove - public boolean isCascadeRemove() { - return this.cascadeRemove; - } - - public void setCascadeRemove(boolean cascadeRemove) { - throw new UnsupportedOperationException(); - } - - private void setCascadeRemove_(boolean cascadeRemove) { - boolean old = this.cascadeRemove; - this.cascadeRemove = cascadeRemove; - this.firePropertyChanged(CASCADE_REMOVE_PROPERTY, old, cascadeRemove); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySecondaryTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySecondaryTableAnnotation.java deleted file mode 100644 index dd8eaa1a7e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySecondaryTableAnnotation.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableSecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.SecondaryTable - */ -public final class BinarySecondaryTableAnnotation - extends BinaryBaseTableAnnotation - implements NestableSecondaryTableAnnotation -{ - private final Vector<PrimaryKeyJoinColumnAnnotation> pkJoinColumns; - - public BinarySecondaryTableAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.pkJoinColumns = this.buildPkJoinColumns(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.updatePkJoinColumns(); - } - - - // ********** BinaryBaseTableAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.SECONDARY_TABLE__NAME; - } - - @Override - String getSchemaElementName() { - return JPA.SECONDARY_TABLE__SCHEMA; - } - - @Override - String getCatalogElementName() { - return JPA.SECONDARY_TABLE__CATALOG; - } - - @Override - String getUniqueConstraintElementName() { - return JPA.SECONDARY_TABLE__UNIQUE_CONSTRAINTS; - } - - - // ************* SecondaryTable implementation ******************* - - // ***** pk join columns - public ListIterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns() { - return new CloneListIterator<PrimaryKeyJoinColumnAnnotation>(this.pkJoinColumns); - } - - public int pkJoinColumnsSize() { - return this.pkJoinColumns.size(); - } - - public PrimaryKeyJoinColumnAnnotation pkJoinColumnAt(int index) { - return this.pkJoinColumns.get(index); - } - - public int indexOfPkJoinColumn(PrimaryKeyJoinColumnAnnotation pkJoinColumn) { - return this.pkJoinColumns.indexOf(pkJoinColumn); - } - - public PrimaryKeyJoinColumnAnnotation addPkJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public void movePkJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removePkJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - private Vector<PrimaryKeyJoinColumnAnnotation> buildPkJoinColumns() { - Object[] jdtJoinColumns = this.getJdtMemberValues(JPA.SECONDARY_TABLE__PK_JOIN_COLUMNS); - Vector<PrimaryKeyJoinColumnAnnotation> result = new Vector<PrimaryKeyJoinColumnAnnotation>(jdtJoinColumns.length); - for (Object jdtJoinColumn : jdtJoinColumns) { - result.add(new BinaryPrimaryKeyJoinColumnAnnotation(this, (IAnnotation) jdtJoinColumn)); - } - return result; - } - - // TODO - private void updatePkJoinColumns() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySecondaryTablesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySecondaryTablesAnnotation.java deleted file mode 100644 index 01edfe1e8c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySecondaryTablesAnnotation.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableSecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.SecondaryTables - */ -public final class BinarySecondaryTablesAnnotation - extends BinaryContainerAnnotation<NestableSecondaryTableAnnotation> - implements SecondaryTablesAnnotation -{ - private final Vector<NestableSecondaryTableAnnotation> secondaryTables; - - - public BinarySecondaryTablesAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.secondaryTables = this.buildSecondaryTables(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public ListIterator<NestableSecondaryTableAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableSecondaryTableAnnotation>(this.secondaryTables); - } - - public int nestedAnnotationsSize() { - return this.secondaryTables.size(); - } - - private Vector<NestableSecondaryTableAnnotation> buildSecondaryTables() { - Object[] jdtSecondaryTables = this.getJdtMemberValues(JPA.SECONDARY_TABLES__VALUE); - Vector<NestableSecondaryTableAnnotation> result = new Vector<NestableSecondaryTableAnnotation>(jdtSecondaryTables.length); - for (Object jdtSecondaryTable : jdtSecondaryTables) { - result.add(new BinarySecondaryTableAnnotation(this, (IAnnotation) jdtSecondaryTable)); - } - return result; - } - - @Override - public void update() { - super.update(); - this.updateSecondaryTables(); - } - - // TODO - private void updateSecondaryTables() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySequenceGeneratorAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySequenceGeneratorAnnotation.java deleted file mode 100644 index cfe2c821ba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinarySequenceGeneratorAnnotation.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.SequenceGenerator - */ -public abstract class BinarySequenceGeneratorAnnotation - extends BinaryGeneratorAnnotation - implements SequenceGeneratorAnnotation -{ - private String sequenceName; - - - protected BinarySequenceGeneratorAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.sequenceName = this.buildSequenceName(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setSequenceName_(this.buildSequenceName()); - } - - - // ********** BinaryGeneratorAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.SEQUENCE_GENERATOR__NAME; - } - - @Override - String getInitialValueElementName() { - return JPA.SEQUENCE_GENERATOR__INITIAL_VALUE; - } - - @Override - String getAllocationSizeElementName() { - return JPA.SEQUENCE_GENERATOR__ALLOCATION_SIZE; - } - - - // ********** SequenceGeneratorAnnotation implementation ********** - - // ***** sequence name - public String getSequenceName() { - return this.sequenceName; - } - - public void setSequenceName(String sequenceName) { - throw new UnsupportedOperationException(); - } - - private void setSequenceName_(String sequenceName) { - String old = this.sequenceName; - this.sequenceName = sequenceName; - this.firePropertyChanged(SEQUENCE_NAME_PROPERTY, old, sequenceName); - } - - private String buildSequenceName() { - return (String) this.getJdtMemberValue(JPA.SEQUENCE_GENERATOR__SEQUENCE_NAME); - } - - public TextRange getSequenceNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean sequenceNameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTableAnnotation.java deleted file mode 100644 index bc456e6b8f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTableAnnotation.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.TableAnnotation; - -/** - * javax.persistence.Table - */ -public final class BinaryTableAnnotation - extends BinaryBaseTableAnnotation - implements TableAnnotation -{ - public BinaryTableAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - // ********** BinaryBaseTableAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.TABLE__NAME; - } - - @Override - String getSchemaElementName() { - return JPA.TABLE__SCHEMA; - } - - @Override - String getCatalogElementName() { - return JPA.TABLE__CATALOG; - } - - @Override - String getUniqueConstraintElementName() { - return JPA.TABLE__UNIQUE_CONSTRAINTS; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTableGeneratorAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTableGeneratorAnnotation.java deleted file mode 100644 index 0ecdebbb42..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTableGeneratorAnnotation.java +++ /dev/null @@ -1,293 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.TableGenerator - */ -public final class BinaryTableGeneratorAnnotation - extends BinaryGeneratorAnnotation - implements TableGeneratorAnnotation -{ - private String table; - private String schema; - private String catalog; - private String pkColumnName; - private String valueColumnName; - private String pkColumnValue; - private final Vector<UniqueConstraintAnnotation> uniqueConstraints; - - - public BinaryTableGeneratorAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.table = this.buildTable(); - this.schema = this.buildSchema(); - this.catalog = this.buildCatalog(); - this.pkColumnName = this.buildPkColumnName(); - this.valueColumnName = this.buildValueColumnName(); - this.pkColumnValue = this.buildPkColumnValue(); - this.uniqueConstraints = this.buildUniqueConstraints(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setTable_(this.buildTable()); - this.setSchema_(this.buildSchema()); - this.setCatalog_(this.buildCatalog()); - this.setPkColumnName_(this.buildPkColumnName()); - this.setValueColumnName_(this.buildValueColumnName()); - this.setPkColumnValue_(this.buildPkColumnValue()); - this.updateUniqueConstraints(); - } - - - // ********** AbstractGeneratorAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.TABLE_GENERATOR__NAME; - } - - @Override - String getInitialValueElementName() { - return JPA.TABLE_GENERATOR__INITIAL_VALUE; - } - - @Override - String getAllocationSizeElementName() { - return JPA.TABLE_GENERATOR__ALLOCATION_SIZE; - } - - - // ********** TableGeneratorAnnotation implementation ********** - - // ***** table - public String getTable() { - return this.table; - } - - public void setTable(String table) { - throw new UnsupportedOperationException(); - } - - private void setTable_(String table) { - String old = this.table; - this.table = table; - this.firePropertyChanged(TABLE_PROPERTY, old, table); - } - - private String buildTable() { - return (String) this.getJdtMemberValue(JPA.TABLE_GENERATOR__TABLE); - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** schema - public String getSchema() { - return this.schema; - } - - public void setSchema(String schema) { - throw new UnsupportedOperationException(); - } - - private void setSchema_(String schema) { - String old = this.schema; - this.schema = schema; - this.firePropertyChanged(SCHEMA_PROPERTY, old, schema); - } - - private String buildSchema() { - return (String) this.getJdtMemberValue(JPA.TABLE_GENERATOR__SCHEMA); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** catalog - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String catalog) { - throw new UnsupportedOperationException(); - } - - private void setCatalog_(String catalog) { - String old = this.catalog; - this.catalog = catalog; - this.firePropertyChanged(CATALOG_PROPERTY, old, catalog); - } - - private String buildCatalog() { - return (String) this.getJdtMemberValue(JPA.TABLE_GENERATOR__CATALOG); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** pk column name - public String getPkColumnName() { - return this.pkColumnName; - } - - public void setPkColumnName(String pkColumnName) { - throw new UnsupportedOperationException(); - } - - private void setPkColumnName_(String pkColumnName) { - String old = this.pkColumnName; - this.pkColumnName = pkColumnName; - this.firePropertyChanged(PK_COLUMN_NAME_PROPERTY, old, pkColumnName); - } - - private String buildPkColumnName() { - return (String) this.getJdtMemberValue(JPA.TABLE_GENERATOR__PK_COLUMN_NAME); - } - - public TextRange getPkColumnNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean pkColumnNameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** value column name - public String getValueColumnName() { - return this.valueColumnName; - } - - public void setValueColumnName(String valueColumnName) { - throw new UnsupportedOperationException(); - } - - private void setValueColumnName_(String valueColumnName) { - String old = this.valueColumnName; - this.valueColumnName = valueColumnName; - this.firePropertyChanged(VALUE_COLUMN_NAME_PROPERTY, old, valueColumnName); - } - - private String buildValueColumnName() { - return (String) this.getJdtMemberValue(JPA.TABLE_GENERATOR__VALUE_COLUMN_NAME); - } - - public TextRange getValueColumnNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean valueColumnNameTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** pk column value - public String getPkColumnValue() { - return this.pkColumnValue; - } - - public void setPkColumnValue(String pkColumnValue) { - throw new UnsupportedOperationException(); - } - - private void setPkColumnValue_(String pkColumnValue) { - String old = this.pkColumnValue; - this.pkColumnValue = pkColumnValue; - this.firePropertyChanged(PK_COLUMN_VALUE_PROPERTY, old, pkColumnValue); - } - - private String buildPkColumnValue() { - return (String) this.getJdtMemberValue(JPA.TABLE_GENERATOR__PK_COLUMN_VALUE); - } - - public TextRange getPkColumnValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean pkColumnValueTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - // ***** unique constraints - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return new CloneListIterator<UniqueConstraintAnnotation>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public UniqueConstraintAnnotation uniqueConstraintAt(int index) { - return this.uniqueConstraints.get(index); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - return this.uniqueConstraints.indexOf(uniqueConstraint); - } - - public UniqueConstraintAnnotation addUniqueConstraint(int index) { - throw new UnsupportedOperationException(); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeUniqueConstraint(int index) { - throw new UnsupportedOperationException(); - } - - private Vector<UniqueConstraintAnnotation> buildUniqueConstraints() { - Object[] jdtUniqueConstraints = this.getJdtMemberValues(JPA.TABLE_GENERATOR__UNIQUE_CONSTRAINTS); - Vector<UniqueConstraintAnnotation> result = new Vector<UniqueConstraintAnnotation>(jdtUniqueConstraints.length); - for (Object jdtUniqueConstraint : jdtUniqueConstraints) { - result.add(new BinaryUniqueConstraintAnnotation(this, (IAnnotation) jdtUniqueConstraint)); - } - return result; - } - - // TODO - private void updateUniqueConstraints() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTemporalAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTemporalAnnotation.java deleted file mode 100644 index d2945aa198..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTemporalAnnotation.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalType; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * javax.persistence.Temporal - */ -public final class BinaryTemporalAnnotation - extends BinaryAnnotation - implements TemporalAnnotation -{ - private TemporalType value; - - - public BinaryTemporalAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.value = this.buildValue(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.setValue_(this.buildValue()); - } - - - // ********** TemporalAnnotation implementation ********** - - // ***** value - public TemporalType getValue() { - return this.value; - } - - public void setValue(TemporalType value) { - throw new UnsupportedOperationException(); - } - - private void setValue_(TemporalType value) { - TemporalType old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private TemporalType buildValue() { - return TemporalType.fromJavaAnnotationValue(this.getJdtMemberValue(JPA.TEMPORAL__VALUE)); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTransientAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTransientAnnotation.java deleted file mode 100644 index 92e643fd4b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryTransientAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; - -/** - * javax.persistence.Transient - */ -public final class BinaryTransientAnnotation - extends BinaryAnnotation - implements TransientAnnotation -{ - - public BinaryTransientAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryUniqueConstraintAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryUniqueConstraintAnnotation.java deleted file mode 100644 index 2d8af3aec7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryUniqueConstraintAnnotation.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.UniqueConstraint - */ -final class BinaryUniqueConstraintAnnotation - extends BinaryAnnotation - implements UniqueConstraintAnnotation -{ - private final Vector<String> columnNames; - - - BinaryUniqueConstraintAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - this.columnNames = this.buildColumnNames(); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void update() { - super.update(); - this.updateColumnNames(); - } - - // TODO - private void updateColumnNames() { - throw new UnsupportedOperationException(); - } - - - // ********** UniqueConstraintAnnotation implementation ********** - - // ***** column names - public ListIterator<String> columnNames() { - return new CloneListIterator<String>(this.columnNames); - } - - public int columnNamesSize() { - return this.columnNames.size(); - } - - private Vector<String> buildColumnNames() { - Object[] jdtColumnNames = this.getJdtMemberValues(JPA.UNIQUE_CONSTRAINT__COLUMN_NAMES); - Vector<String> result = new Vector<String>(jdtColumnNames.length); - for (Object jdtColumnName : jdtColumnNames) { - result.add((String) jdtColumnName); - } - return result; - } - - public void addColumnName(String columnName) { - throw new UnsupportedOperationException(); - } - - public void addColumnName(int index, String columnName) { - throw new UnsupportedOperationException(); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public boolean columnNamesTouches(int pos, CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public void removeColumnName(String columnName) { - throw new UnsupportedOperationException(); - } - - public void removeColumnName(int index) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryVersionAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryVersionAnnotation.java deleted file mode 100644 index 37f3256a19..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryVersionAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; - -/** - * javax.persistence.Version - */ -public final class BinaryVersionAnnotation - extends BinaryAnnotation - implements VersionAnnotation -{ - - public BinaryVersionAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - super(parent, jdtAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/RootBinaryNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/RootBinaryNode.java deleted file mode 100644 index be9981c144..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/RootBinaryNode.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.binary; - -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.JpaResourceModelListener; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.utility.internal.ListenerList; - -/** - * JAR and external types - */ -abstract class RootBinaryNode - extends BinaryNode - implements JavaResourceNode.Root -{ - /** pluggable annotation provider */ - private final JpaAnnotationProvider annotationProvider; - - /** listeners notified whenever the resource model changes */ - private final ListenerList<JpaResourceModelListener> resourceModelListenerList = new ListenerList<JpaResourceModelListener>(JpaResourceModelListener.class); - - - // ********** construction ********** - - RootBinaryNode(JavaResourceNode parent, JpaAnnotationProvider annotationProvider) { - super(parent); - this.annotationProvider = annotationProvider; - } - - - // ********** overrides ********** - - @Override - protected boolean requiresParent() { - return false; - } - - @Override - public Root getRoot() { - return this; - } - - @Override - public JpaAnnotationProvider getAnnotationProvider() { - return this.annotationProvider; - } - - - // ********** JavaResourceNode.Root implementation ********** - - public void resourceModelChanged() { - for (JpaResourceModelListener listener : this.resourceModelListenerList.getListeners()) { - listener.resourceModelChanged(); - } - } - - - // ********** JpaResourceModel implementation ********** - - public void addResourceModelListener(JpaResourceModelListener listener) { - this.resourceModelListenerList.add(listener); - } - - public void removeResourceModelListener(JpaResourceModelListener listener) { - this.resourceModelListenerList.remove(listener); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/AnnotationContainerTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/AnnotationContainerTools.java deleted file mode 100644 index 97446b9da0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/AnnotationContainerTools.java +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.ArrayInitializer; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.resource.java.AnnotationContainer; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * Utility methods for manipulating annotation containers. - */ -public final class AnnotationContainerTools { - - /** - * Add a nested annotation to the specified annotation container - * at the specified index. - * This method modifies both the model annotation container and the - * AST; with the appropriate change notification occurring afterwards. - */ - public static <T extends NestableAnnotation> NestableAnnotation addNestedAnnotation(int index, AnnotationContainer<T> annotationContainer) { - // add a new annotation to the end of the list... - int sourceIndex = annotationContainer.nestedAnnotationsSize(); - T nestedAnnotation = annotationContainer.addNestedAnnotationInternal(); - nestedAnnotation.newAnnotation(); - // ...then move it to the specified index... - annotationContainer.moveNestedAnnotationInternal(index, sourceIndex); - synchJavaAnnotationsAfterMove(index, sourceIndex, annotationContainer, nestedAnnotation); - // ...then, when all is settled, tell the container to fire change notification - annotationContainer.nestedAnnotationAdded(index, nestedAnnotation); - return nestedAnnotation; - } - - /** - * Move the nested annotation at the specified source index in the - * specified annotation container to the specified target index. - * This method modifies both the model annotation container and the - * AST; with the appropriate change notification occurring afterwards. - */ - public static <T extends NestableAnnotation> void moveNestedAnnotation(int targetIndex, int sourceIndex, AnnotationContainer<T> annotationContainer) { - NestableAnnotation nestedAnnotation = annotationContainer.moveNestedAnnotationInternal(targetIndex, sourceIndex); - synchJavaAnnotationsAfterMove(targetIndex, sourceIndex, annotationContainer, nestedAnnotation); - annotationContainer.nestedAnnotationMoved(targetIndex, sourceIndex); - } - - /** - * An annotation was moved within the specified annotation container from - * the specified source index to the specified target index. - * Synchronize the AST annotations with the model annotation container, - * starting with the lower index to prevent overlap. - */ - private static <T extends NestableAnnotation> void synchJavaAnnotationsAfterMove(int targetIndex, int sourceIndex, AnnotationContainer<T> annotationContainer, NestableAnnotation nestedAnnotationAnnotation) { - // move the Java annotation to the end of the list... - nestedAnnotationAnnotation.moveAnnotation(annotationContainer.nestedAnnotationsSize()); - // ...then shift the other Java annotations over one slot... - List<T> nestableAnnotations = CollectionTools.list(annotationContainer.nestedAnnotations()); - if (sourceIndex < targetIndex) { - for (int i = sourceIndex; i < targetIndex; i++) { - nestableAnnotations.get(i).moveAnnotation(i); - } - } else { - for (int i = sourceIndex; i > targetIndex; i-- ) { - nestableAnnotations.get(i).moveAnnotation(i); - } - } - // ...then move the Java annotation to the now empty slot at the target index - nestedAnnotationAnnotation.moveAnnotation(targetIndex); - } - - /** - * Remove the nested annotation at the specified index in the - * specified annotation container. - * This method modifies both the model annotation container and the - * AST; with the appropriate change notification occurring afterwards. - */ - public static <T extends NestableAnnotation> void removeNestedAnnotation(int index, AnnotationContainer<T> annotationContainer) { - T nestedAnnotation = annotationContainer.removeNestedAnnotationInternal(index); - nestedAnnotation.removeAnnotation(); - synchJavaAnnotationsAfterRemove(index, annotationContainer); - annotationContainer.nestedAnnotationRemoved(index, nestedAnnotation); - } - - /** - * An annotation was removed from the specified annotation container at the - * specified index. - * Synchronize the AST annotations with the model annotation container, - * starting at the specified index to prevent overlap. - */ - private static <T extends NestableAnnotation> void synchJavaAnnotationsAfterRemove(int index, AnnotationContainer<T> annotationContainer) { - List<T> nestableAnnotations = CollectionTools.list(annotationContainer.nestedAnnotations()); - for (int i = index; i < nestableAnnotations.size(); i++) { - // the indices are the same because the model annotations are - // already in the proper locations - it's the Java annotations that - // need to be moved to the same location - nestableAnnotations.get(i).moveAnnotation(i); - } - } - - /** - * Initialize the specified annotation container to be in synch with the - * specified AST. No change notification will occur. - */ - public static <T extends NestableAnnotation> void initialize(AnnotationContainer<T> annotationContainer, CompilationUnit astRoot) { - // ignore the nested AST annotations themselves - // (maybe someday we can use them during initialization...) - int size = getNestedAstAnnotations(astRoot, annotationContainer).size(); - for (int i = 0; i < size; i++) { - T nestedAnnotation = annotationContainer.addNestedAnnotationInternal(); - nestedAnnotation.initialize(astRoot); - } - } - - /** - * Return a list of the nested AST annotations. - */ - private static <T extends NestableAnnotation> ArrayList<Annotation> getNestedAstAnnotations(CompilationUnit astRoot, AnnotationContainer<T> annotationContainer) { - ArrayList<Annotation> result = new ArrayList<Annotation>(); - Annotation containerAstAnnotation = annotationContainer.getContainerJdtAnnotation(astRoot); - if (containerAstAnnotation.isMarkerAnnotation()) { - // no nested annotations - } - else if (containerAstAnnotation.isSingleMemberAnnotation()) { - if (annotationContainer.getElementName().equals("value")) { //$NON-NLS-1$ - Expression ex = ((SingleMemberAnnotation) containerAstAnnotation).getValue(); - addAstAnnotationsTo(ex, annotationContainer.getNestableAnnotationName(), result); - } else { - // no nested annotations - } - } - else if (containerAstAnnotation.isNormalAnnotation()) { - MemberValuePair pair = getMemberValuePair((NormalAnnotation) containerAstAnnotation, annotationContainer.getElementName()); - if (pair == null) { - // no nested annotations - } else { - addAstAnnotationsTo(pair.getValue(), annotationContainer.getNestableAnnotationName(), result); - } - } - return result; - } - - /** - * Add whatever annotations are represented by the specified expression to - * the specified bag. Add null to the bag for any non-annotation expression. - */ - private static void addAstAnnotationsTo(Expression expression, String annotationName, ArrayList<Annotation> astAnnotations) { - if (expression == null) { - astAnnotations.add(null); // not sure how we would get here... - } - else if (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) { - addAstAnnotationsTo((ArrayInitializer) expression, annotationName, astAnnotations); - } - else { - astAnnotations.add(getAstAnnotation_(expression, annotationName)); - } - } - - private static void addAstAnnotationsTo(ArrayInitializer arrayInitializer, String annotationName, ArrayList<Annotation> astAnnotations) { - @SuppressWarnings("unchecked") - List<Expression> expressions = arrayInitializer.expressions(); - for (Expression expression : expressions) { - astAnnotations.add(getAstAnnotation(expression, annotationName)); - } - } - - /** - * If the specified expression is an annotation with the specified name, return it; - * otherwise return null. - */ - private static Annotation getAstAnnotation(Expression expression, String annotationName) { - // not sure how the expression could be null... - return (expression == null) ? null : getAstAnnotation_(expression, annotationName); - } - - /** - * pre-condition: expression is not null - */ - private static Annotation getAstAnnotation_(Expression expression, String annotationName) { - switch (expression.getNodeType()) { - case ASTNode.NORMAL_ANNOTATION: - case ASTNode.SINGLE_MEMBER_ANNOTATION: - case ASTNode.MARKER_ANNOTATION: - Annotation astAnnotation = (Annotation) expression; - if (getQualifiedName(astAnnotation).equals(annotationName)) { - return astAnnotation; - } - return null; - default: - return null; - } - } - - private static String getQualifiedName(Annotation astAnnotation) { - ITypeBinding typeBinding = astAnnotation.resolveTypeBinding(); - if (typeBinding != null) { - String resolvedName = typeBinding.getQualifiedName(); - if (resolvedName != null) { - return resolvedName; - } - } - return astAnnotation.getTypeName().getFullyQualifiedName(); - } - - private static MemberValuePair getMemberValuePair(NormalAnnotation annotation, String elementName) { - @SuppressWarnings("unchecked") - List<MemberValuePair> pairs = annotation.values(); - for (MemberValuePair pair : pairs) { - if (pair.getName().getFullyQualifiedName().equals(elementName)) { - return pair; - } - } - return null; - } - - /** - * Update the annotations in the specified annotation container to be in - * synch with those in the specified AST. The appropriate change - * notification will occur. - */ - public static <T extends NestableAnnotation> void update(AnnotationContainer<T> annotationContainer, CompilationUnit astRoot) { - ListIterator<Annotation> astAnnotations = getNestedAstAnnotations(astRoot, annotationContainer).listIterator(); - - for (ListIterator<T> nestedAnnotations = annotationContainer.nestedAnnotations(); nestedAnnotations.hasNext(); ) { - T nestedAnnotation = nestedAnnotations.next(); - if (astAnnotations.hasNext()) { - // matching AST annotation is present - update the nested annotation - astAnnotations.next(); // maybe someday we can pass this to the update - nestedAnnotation.update(astRoot); - } else { - // no more AST annotations - remove the nested annotation at the end of the container's list - int last = annotationContainer.nestedAnnotationsSize() - 1; - T remove = annotationContainer.removeNestedAnnotationInternal(last); - annotationContainer.nestedAnnotationRemoved(last, remove); - } - } - - // add nested annotations for the remaining AST annotations - int i = annotationContainer.nestedAnnotationsSize(); - while (astAnnotations.hasNext()) { - astAnnotations.next(); // maybe someday we can pass this to the initialize - T nestedAnnotation = annotationContainer.addNestedAnnotationInternal(); - nestedAnnotation.initialize(astRoot); - annotationContainer.nestedAnnotationAdded(i++, nestedAnnotation); - } - } - - private AnnotationContainerTools() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAnnotation.java deleted file mode 100644 index 78e6e5ba82..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAnnotation.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.internal.utility.jdt.ASTNodeTextRange; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * some common state and behavior for Java source annotations; - * and lots of convenience methods - */ -public abstract class SourceAnnotation<M extends Member> - extends SourceNode - implements Annotation -{ - protected final M member; - - protected final DeclarationAnnotationAdapter daa; - - protected final AnnotationAdapter annotationAdapter; - - - /** - * constructor for straight member annotation - */ - protected SourceAnnotation(JavaResourceNode parent, M member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - /** - * constructor for nested annotation (typically) - */ - protected SourceAnnotation(JavaResourceNode parent, M member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent); - this.member = member; - this.daa = daa; - this.annotationAdapter = annotationAdapter; - } - - - // ********** JavaResourceNode implementation ********** - - public TextRange getTextRange(CompilationUnit astRoot) { - return this.getAnnotationTextRange(astRoot); - } - - - // ********** Annotation implementation ********** - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return this.annotationAdapter.getAnnotation(astRoot); - } - - public void newAnnotation() { - this.annotationAdapter.newMarkerAnnotation(); - } - - public void removeAnnotation() { - this.annotationAdapter.removeAnnotation(); - } - - - // ********** convenience methods ********** - - /** - * Return the text range corresponding to the annotation. - * If the annotation is missing, return null. - */ - protected TextRange getAnnotationTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.getJdtAnnotation(astRoot)); - } - - /** - * Convenience method. - * Return the text range corresponding to the specified element. - * If the specified element is missing, return the annotation's text range instead. - */ - protected TextRange getElementTextRange(DeclarationAnnotationElementAdapter<?> elementAdapter, CompilationUnit astRoot) { - return this.getElementTextRange(this.getAnnotationElementTextRange(elementAdapter, astRoot), astRoot); - } - - /** - * Convenience method. If the specified element text range is null - * return the member's text range instead. - */ - protected TextRange getElementTextRange(TextRange elementTextRange, CompilationUnit astRoot) { - return (elementTextRange != null) ? elementTextRange : this.getAnnotationTextRange(astRoot); - } - - /** - * Convenience method. Return whether the specified position exists and - * touches the specified element. - */ - protected boolean elementTouches(DeclarationAnnotationElementAdapter<?> elementAdapter, int pos, CompilationUnit astRoot) { - return this.textRangeTouches(this.getAnnotationElementTextRange(elementAdapter, astRoot), pos); - } - - /** - * Convenience method. Return whether the specified text range is not - * null (meaning the corresponding AST node exists) and the specified position touches it. - */ - protected boolean textRangeTouches(TextRange textRange, int pos) { - return (textRange != null) && textRange.touches(pos); - } - - /** - * Return the text range corresponding to the specified element. - * If the element is missing, return null. - */ - protected TextRange getAnnotationElementTextRange(DeclarationAnnotationElementAdapter<?> adapter, CompilationUnit astRoot) { - return this.getTextRange(this.getAnnotationElementExpression(adapter, astRoot)); - } - - /** - * Return the specified AST DOM element. - */ - protected Expression getAnnotationElementExpression(DeclarationAnnotationElementAdapter<?> adapter, CompilationUnit astRoot) { - return adapter.getExpression(this.member.getModifiedDeclaration(astRoot)); - } - - /** - * Return the text range corresponding to the specified AST node. - * If the AST node is null, return null. - */ - protected TextRange getTextRange(ASTNode astNode) { - return (astNode == null) ? null : new ASTNodeTextRange(astNode); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAssociationOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAssociationOverrideAnnotation.java deleted file mode 100644 index 9f2ccc4032..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAssociationOverrideAnnotation.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationContainer; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.AssociationOverride - */ -public abstract class SourceAssociationOverrideAnnotation - extends SourceOverrideAnnotation - implements NestableAssociationOverrideAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestableJoinColumnAnnotation> joinColumns = new Vector<NestableJoinColumnAnnotation>(); - private final JoinColumnsAnnotationContainer joinColumnsContainer = new JoinColumnsAnnotationContainer(); - - - // ********** construction/initialization ********** - - protected SourceAssociationOverrideAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - AnnotationContainerTools.initialize(this.joinColumnsContainer, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - AnnotationContainerTools.update(this.joinColumnsContainer, astRoot); - } - - - // ********** SourceOverrideAnnotation implementation ********** - - @Override - protected String getNameElementName() { - return JPA.ASSOCIATION_OVERRIDE__NAME; - } - - - // ********** AssociationOverrideAnnotation implementation ********** - - // ***** join columns - public ListIterator<JoinColumnAnnotation> joinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.joinColumns); - } - - ListIterator<NestableJoinColumnAnnotation> nestableJoinColumns() { - return new CloneListIterator<NestableJoinColumnAnnotation>(this.joinColumns); - } - - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - public NestableJoinColumnAnnotation joinColumnAt(int index) { - return this.joinColumns.get(index); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public NestableJoinColumnAnnotation addJoinColumn(int index) { - return (NestableJoinColumnAnnotation) AnnotationContainerTools.addNestedAnnotation(index, this.joinColumnsContainer); - } - - NestableJoinColumnAnnotation addJoinColumnInternal() { - NestableJoinColumnAnnotation joinColumn = this.buildJoinColumn(this.joinColumns.size()); - this.joinColumns.add(joinColumn); - return joinColumn; - } - - private NestableJoinColumnAnnotation buildJoinColumn(int index) { - return SourceJoinColumnAnnotation.createAssociationOverrideJoinColumn(this.daa, this, this.member, index); - } - - void joinColumnAdded(int index, NestableJoinColumnAnnotation joinColumn) { - this.fireItemAdded(JOIN_COLUMNS_LIST, index, joinColumn); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, this.joinColumnsContainer); - } - - NestableJoinColumnAnnotation moveJoinColumnInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.joinColumns, targetIndex, sourceIndex).get(targetIndex); - } - - void joinColumnMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void removeJoinColumn(int index) { - AnnotationContainerTools.removeNestedAnnotation(index, this.joinColumnsContainer); - } - - NestableJoinColumnAnnotation removeJoinColumnInternal(int index) { - return this.joinColumns.remove(index); - } - - void joinColumnRemoved(int index, NestableJoinColumnAnnotation joinColumn) { - this.fireItemRemoved(JOIN_COLUMNS_LIST, index, joinColumn); - } - - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - AssociationOverrideAnnotation oldOverride = (AssociationOverrideAnnotation) oldAnnotation; - for (JoinColumnAnnotation oldJoinColumn : CollectionTools.iterable(oldOverride.joinColumns())) { - NestableJoinColumnAnnotation newJoinColumn = this.addJoinColumn(oldOverride.indexOfJoinColumn(oldJoinColumn)); - newJoinColumn.initializeFrom((NestableAnnotation) oldJoinColumn); - } - } - - // ********** join column container ********** - - /** - * adapt the AnnotationContainer interface to the override's join columns - */ - class JoinColumnsAnnotationContainer - implements AnnotationContainer<NestableJoinColumnAnnotation> - { - public String getContainerAnnotationName() { - return SourceAssociationOverrideAnnotation.this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return SourceAssociationOverrideAnnotation.this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.ASSOCIATION_OVERRIDE__JOIN_COLUMNS; - } - - public String getNestableAnnotationName() { - return JoinColumnAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableJoinColumnAnnotation> nestedAnnotations() { - return SourceAssociationOverrideAnnotation.this.nestableJoinColumns(); - } - - public int nestedAnnotationsSize() { - return SourceAssociationOverrideAnnotation.this.joinColumnsSize(); - } - - public NestableJoinColumnAnnotation addNestedAnnotationInternal() { - return SourceAssociationOverrideAnnotation.this.addJoinColumnInternal(); - } - - public void nestedAnnotationAdded(int index, NestableJoinColumnAnnotation nestedAnnotation) { - SourceAssociationOverrideAnnotation.this.joinColumnAdded(index, nestedAnnotation); - } - - public NestableJoinColumnAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return SourceAssociationOverrideAnnotation.this.moveJoinColumnInternal(targetIndex, sourceIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - SourceAssociationOverrideAnnotation.this.joinColumnMoved(targetIndex, sourceIndex); - } - - public NestableJoinColumnAnnotation removeNestedAnnotationInternal(int index) { - return SourceAssociationOverrideAnnotation.this.removeJoinColumnInternal(index); - } - - public void nestedAnnotationRemoved(int index, NestableJoinColumnAnnotation nestedAnnotation) { - SourceAssociationOverrideAnnotation.this.joinColumnRemoved(index, nestedAnnotation); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAssociationOverridesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAssociationOverridesAnnotation.java deleted file mode 100644 index 65acf31d66..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAssociationOverridesAnnotation.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverrideAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.AssociationOverrides - */ -public abstract class SourceAssociationOverridesAnnotation - extends SourceAnnotation<Member> - implements AssociationOverridesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestableAssociationOverrideAnnotation> associationOverrides = new Vector<NestableAssociationOverrideAnnotation>(); - - - protected SourceAssociationOverridesAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - AnnotationContainerTools.initialize(this, astRoot); - } - - public void update(CompilationUnit astRoot) { - AnnotationContainerTools.update(this, astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.associationOverrides); - } - - - // ********** AnnotationContainer implementation ********** - - public String getContainerAnnotationName() { - return this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.ASSOCIATION_OVERRIDES__VALUE; - } - - public String getNestableAnnotationName() { - return AssociationOverrideAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableAssociationOverrideAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableAssociationOverrideAnnotation>(this.associationOverrides); - } - - public int nestedAnnotationsSize() { - return this.associationOverrides.size(); - } - - public NestableAssociationOverrideAnnotation addNestedAnnotationInternal() { - NestableAssociationOverrideAnnotation associationOverride = this.buildAssociationOverride(this.associationOverrides.size()); - this.associationOverrides.add(associationOverride); - return associationOverride; - } - - protected abstract NestableAssociationOverrideAnnotation buildAssociationOverride(int index); - - public void nestedAnnotationAdded(int index, NestableAssociationOverrideAnnotation nestedAnnotation) { - this.fireItemAdded(ASSOCIATION_OVERRIDES_LIST, index, nestedAnnotation); - } - - public NestableAssociationOverrideAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.associationOverrides, targetIndex, sourceIndex).get(targetIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(ASSOCIATION_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - public NestableAssociationOverrideAnnotation removeNestedAnnotationInternal(int index) { - return this.associationOverrides.remove(index); - } - - public void nestedAnnotationRemoved(int index, NestableAssociationOverrideAnnotation nestedAnnotation) { - this.fireItemRemoved(ASSOCIATION_OVERRIDES_LIST, index, nestedAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAttributeOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAttributeOverrideAnnotation.java deleted file mode 100644 index 5f7fdb2d8e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAttributeOverrideAnnotation.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.NullAttributeOverrideColumnAnnotation; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.NestableColumnAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.AttributeOverride - */ -public final class SourceAttributeOverrideAnnotation - extends SourceOverrideAnnotation - implements NestableAttributeOverrideAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final MemberAnnotationAdapter columnAdapter; - private NestableColumnAnnotation column; - - - // ********** construction/initialization ********** - - public SourceAttributeOverrideAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.columnAdapter = new MemberAnnotationAdapter(this.member, SourceColumnAnnotation.buildAttributeOverrideAnnotationAdapter(this.daa)); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - if (this.columnAdapter.getAnnotation(astRoot) != null) { - this.column = SourceColumnAnnotation.createAttributeOverrideColumn(this, this.member, this.daa); - this.column.initialize(astRoot); - } - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.updateColumn(astRoot); - } - - - // ********** SourceOverrideAnnotation implementation ********** - - @Override - protected String getNameElementName() { - return JPA.ATTRIBUTE_OVERRIDE__NAME; - } - - - //************ AttributeOverride implementation **************** - - // ***** column - public ColumnAnnotation getColumn() { - return this.column; - } - - public NestableColumnAnnotation addColumn() { - NestableColumnAnnotation col = SourceColumnAnnotation.createAttributeOverrideColumn(this, this.member, this.daa); - col.newAnnotation(); - this.setColumn(col); - return col; - } - - public void removeColumn() { - this.column.removeAnnotation(); - setColumn(null); - } - - private void setColumn(NestableColumnAnnotation column) { - ColumnAnnotation old = this.column; - this.column = column; - this.firePropertyChanged(COLUMN_PROPERTY, old, column); - } - - public ColumnAnnotation getNonNullColumn() { - return (this.column != null) ? this.column : new NullAttributeOverrideColumnAnnotation(this); - } - - private void updateColumn(CompilationUnit astRoot) { - if (this.columnAdapter.getAnnotation(astRoot) == null) { - this.setColumn(null); - } else { - if (this.column == null) { - NestableColumnAnnotation col = SourceColumnAnnotation.createAttributeOverrideColumn(this, this.member, this.daa); - col.initialize(astRoot); - this.setColumn(col); - } else { - this.column.update(astRoot); - } - } - } - - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - AttributeOverrideAnnotation oldOverride = (AttributeOverrideAnnotation) oldAnnotation; - ColumnAnnotation oldColumn = oldOverride.getColumn(); - if (oldColumn != null) { - NestableColumnAnnotation newColumn = this.addColumn(); - newColumn.initializeFrom((NestableAnnotation) oldColumn); - } - } - - - // ********** static methods ********** - - public static SourceAttributeOverrideAnnotation buildAttributeOverride(JavaResourceNode parent, Member member) { - return new SourceAttributeOverrideAnnotation(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - static SourceAttributeOverrideAnnotation buildNestedAttributeOverride(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new SourceAttributeOverrideAnnotation(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(attributeOverridesAdapter, index, JPA.ATTRIBUTE_OVERRIDE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAttributeOverridesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAttributeOverridesAnnotation.java deleted file mode 100644 index 8d41766fe8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceAttributeOverridesAnnotation.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.NestableAttributeOverrideAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.AttributeOverrides - */ -public final class SourceAttributeOverridesAnnotation - extends SourceAnnotation<Member> - implements AttributeOverridesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestableAttributeOverrideAnnotation> attributesOverrides = new Vector<NestableAttributeOverrideAnnotation>(); - - - public SourceAttributeOverridesAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - AnnotationContainerTools.initialize(this, astRoot); - } - - public void update(CompilationUnit astRoot) { - AnnotationContainerTools.update(this, astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.attributesOverrides); - } - - - // ********** AnnotationContainer implementation ********** - - public String getContainerAnnotationName() { - return this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.ATTRIBUTE_OVERRIDES__VALUE; - } - - public String getNestableAnnotationName() { - return AttributeOverrideAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableAttributeOverrideAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableAttributeOverrideAnnotation>(this.attributesOverrides); - } - - public int nestedAnnotationsSize() { - return this.attributesOverrides.size(); - } - - public NestableAttributeOverrideAnnotation addNestedAnnotationInternal() { - NestableAttributeOverrideAnnotation attributeOverride = this.buildAttributeOverride(this.attributesOverrides.size()); - this.attributesOverrides.add(attributeOverride); - return attributeOverride; - } - - private NestableAttributeOverrideAnnotation buildAttributeOverride(int index) { - return SourceAttributeOverrideAnnotation.buildNestedAttributeOverride(this, this.member, index, this.daa); - } - - public void nestedAnnotationAdded(int index, NestableAttributeOverrideAnnotation nestedAnnotation) { - this.fireItemAdded(ATTRIBUTE_OVERRIDES_LIST, index, nestedAnnotation); - } - - public NestableAttributeOverrideAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.attributesOverrides, targetIndex, sourceIndex).get(targetIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - public NestableAttributeOverrideAnnotation removeNestedAnnotationInternal(int index) { - return this.attributesOverrides.remove(index); - } - - public void nestedAnnotationRemoved(int index, NestableAttributeOverrideAnnotation nestedAnnotation) { - this.fireItemRemoved(ATTRIBUTE_OVERRIDES_LIST, index, nestedAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseColumnAnnotation.java deleted file mode 100644 index 2fac36bf04..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseColumnAnnotation.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.BaseColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Column - * javax.persistence.JoinColumn - */ -abstract class SourceBaseColumnAnnotation - extends SourceNamedColumnAnnotation - implements BaseColumnAnnotation -{ - final DeclarationAnnotationElementAdapter<String> tableDeclarationAdapter; - final AnnotationElementAdapter<String> tableAdapter; - String table; - - final DeclarationAnnotationElementAdapter<Boolean> uniqueDeclarationAdapter; - final AnnotationElementAdapter<Boolean> uniqueAdapter; - Boolean unique; - - final DeclarationAnnotationElementAdapter<Boolean> nullableDeclarationAdapter; - final AnnotationElementAdapter<Boolean> nullableAdapter; - Boolean nullable; - - final DeclarationAnnotationElementAdapter<Boolean> insertableDeclarationAdapter; - final AnnotationElementAdapter<Boolean> insertableAdapter; - Boolean insertable; - - final DeclarationAnnotationElementAdapter<Boolean> updatableDeclarationAdapter; - final AnnotationElementAdapter<Boolean> updatableAdapter; - Boolean updatable; - - - SourceBaseColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - SourceBaseColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.tableDeclarationAdapter = this.buildStringElementAdapter(this.getTableElementName()); - this.tableAdapter = this.buildShortCircuitElementAdapter(this.tableDeclarationAdapter); - this.uniqueDeclarationAdapter = this.buildBooleanElementAdapter(this.getUniqueElementName()); - this.uniqueAdapter = this.buildShortCircuitBooleanElementAdapter(this.uniqueDeclarationAdapter); - this.nullableDeclarationAdapter = this.buildBooleanElementAdapter(this.getNullableElementName()); - this.nullableAdapter = this.buildShortCircuitBooleanElementAdapter(this.nullableDeclarationAdapter); - this.insertableDeclarationAdapter = this.buildBooleanElementAdapter(this.getInsertableElementName()); - this.insertableAdapter = this.buildShortCircuitBooleanElementAdapter(this.insertableDeclarationAdapter); - this.updatableDeclarationAdapter = this.buildBooleanElementAdapter(this.getUpdatableElementName()); - this.updatableAdapter = this.buildShortCircuitBooleanElementAdapter(this.updatableDeclarationAdapter); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.table = this.buildTable(astRoot); - this.unique = this.buildUnique(astRoot); - this.nullable = this.buildNullable(astRoot); - this.insertable = this.buildInsertable(astRoot); - this.updatable = this.buildUpdatable(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setTable(this.buildTable(astRoot)); - this.setUnique(this.buildUnique(astRoot)); - this.setNullable(this.buildNullable(astRoot)); - this.setInsertable(this.buildInsertable(astRoot)); - this.setUpdatable(this.buildUpdatable(astRoot)); - } - - - //************* BaseColumnAnnotation implementation ************* - - // ***** table - public String getTable() { - return this.table; - } - - public void setTable(String table) { - if (this.attributeValueHasNotChanged(this.table, table)) { - return; - } - String old = this.table; - this.table = table; - this.tableAdapter.setValue(table); - this.firePropertyChanged(TABLE_PROPERTY, old, table); - } - - private String buildTable(CompilationUnit astRoot) { - return this.tableAdapter.getValue(astRoot); - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.tableDeclarationAdapter, astRoot); - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.tableDeclarationAdapter, pos, astRoot); - } - - abstract String getTableElementName(); - - // ***** unique - public Boolean getUnique() { - return this.unique; - } - - public void setUnique(Boolean unique) { - if (this.attributeValueHasNotChanged(this.unique, unique)) { - return; - } - Boolean old = this.unique; - this.unique = unique; - this.uniqueAdapter.setValue(unique); - this.firePropertyChanged(UNIQUE_PROPERTY, old, unique); - } - - private Boolean buildUnique(CompilationUnit astRoot) { - return this.uniqueAdapter.getValue(astRoot); - } - - public TextRange getUniqueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.uniqueDeclarationAdapter, astRoot); - } - - abstract String getUniqueElementName(); - - // ***** nullable - public Boolean getNullable() { - return this.nullable; - } - - public void setNullable(Boolean nullable) { - if (this.attributeValueHasNotChanged(this.nullable, nullable)) { - return; - } - Boolean old = this.nullable; - this.nullable = nullable; - this.nullableAdapter.setValue(nullable); - this.firePropertyChanged(NULLABLE_PROPERTY, old, nullable); - } - - private Boolean buildNullable(CompilationUnit astRoot) { - return this.nullableAdapter.getValue(astRoot); - } - - public TextRange getNullableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nullableDeclarationAdapter, astRoot); - } - - abstract String getNullableElementName(); - - // ***** insertable - public Boolean getInsertable() { - return this.insertable; - } - - public void setInsertable(Boolean insertable) { - if (this.attributeValueHasNotChanged(this.insertable, insertable)) { - return; - } - Boolean old = this.insertable; - this.insertable = insertable; - this.insertableAdapter.setValue(insertable); - this.firePropertyChanged(INSERTABLE_PROPERTY, old, insertable); - } - - private Boolean buildInsertable(CompilationUnit astRoot) { - return this.insertableAdapter.getValue(astRoot); - } - - public TextRange getInsertableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.insertableDeclarationAdapter, astRoot); - } - - abstract String getInsertableElementName(); - - // ***** updatable - public Boolean getUpdatable() { - return this.updatable; - } - - public void setUpdatable(Boolean updatable) { - if (this.attributeValueHasNotChanged(this.updatable, updatable)) { - return; - } - Boolean old = this.updatable; - this.updatable = updatable; - this.updatableAdapter.setValue(updatable); - this.firePropertyChanged(UPDATABLE_PROPERTY, old, updatable); - } - - private Boolean buildUpdatable(CompilationUnit astRoot) { - return this.updatableAdapter.getValue(astRoot); - } - - public TextRange getUpdatableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.updatableDeclarationAdapter, astRoot); - } - - abstract String getUpdatableElementName(); - - - //************* NestableAnnotation implementation ************* - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - BaseColumnAnnotation oldColumn = (BaseColumnAnnotation) oldAnnotation; - this.setTable(oldColumn.getTable()); - this.setUnique(oldColumn.getUnique()); - this.setNullable(oldColumn.getNullable()); - this.setInsertable(oldColumn.getInsertable()); - this.setUpdatable(oldColumn.getUpdatable()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseNamedQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseNamedQueryAnnotation.java deleted file mode 100644 index 20e69a94f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseNamedQueryAnnotation.java +++ /dev/null @@ -1,305 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationContainer; -import org.eclipse.jpt.core.resource.java.BaseNamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableQueryHintAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.NamedQuery - * javax.persistence.NamedNativeQuery - */ -abstract class SourceBaseNamedQueryAnnotation - extends SourceAnnotation<Type> - implements BaseNamedQueryAnnotation -{ - final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - final AnnotationElementAdapter<String> nameAdapter; - String name; - - final DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter; - final AnnotationElementAdapter<String> queryAdapter; - String query; - - final Vector<NestableQueryHintAnnotation> hints = new Vector<NestableQueryHintAnnotation>(); - final HintsAnnotationContainer hintsContainer = new HintsAnnotationContainer(); - - - SourceBaseNamedQueryAnnotation(JavaResourceNode parent, Type type,DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, type, daa, annotationAdapter); - this.nameDeclarationAdapter = this.buildNameAdapter(daa); - this.queryDeclarationAdapter = this.buildQueryAdapter(daa); - this.nameAdapter = this.buildAdapter(this.nameDeclarationAdapter); - this.queryAdapter = this.buildAdapter(this.queryDeclarationAdapter); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - this.query = this.buildQuery(astRoot); - AnnotationContainerTools.initialize(this.hintsContainer, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - this.setQuery(this.buildQuery(astRoot)); - AnnotationContainerTools.update(this.hintsContainer, astRoot); - } - - /** - * convenience method - */ - AnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** BaseNamedQueryAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - private DeclarationAnnotationElementAdapter<String> buildNameAdapter(DeclarationAnnotationAdapter daAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daAdapter, this.getNameElementName()); - } - - abstract String getNameElementName(); - - // ***** query - public String getQuery() { - return this.query; - } - - public void setQuery(String query) { - if (this.attributeValueHasNotChanged(this.query, query)) { - return; - } - String old = this.query; - this.query = query; - this.queryAdapter.setValue(query); - this.firePropertyChanged(QUERY_PROPERTY, old, query); - } - - private String buildQuery(CompilationUnit astRoot) { - return this.queryAdapter.getValue(astRoot); - } - - public TextRange getQueryTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.queryDeclarationAdapter, astRoot); - } - - private DeclarationAnnotationElementAdapter<String> buildQueryAdapter(DeclarationAnnotationAdapter daAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daAdapter, this.getQueryElementName()); - } - - abstract String getQueryElementName(); - - // ***** hints - public ListIterator<QueryHintAnnotation> hints() { - return new CloneListIterator<QueryHintAnnotation>(this.hints); - } - - ListIterator<NestableQueryHintAnnotation> nestableHints() { - return new CloneListIterator<NestableQueryHintAnnotation>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public NestableQueryHintAnnotation hintAt(int index) { - return this.hints.get(index); - } - - public int indexOfHint(QueryHintAnnotation queryHint) { - return this.hints.indexOf(queryHint); - } - - public NestableQueryHintAnnotation addHint(int index) { - return (NestableQueryHintAnnotation) AnnotationContainerTools.addNestedAnnotation(index, this.hintsContainer); - } - - NestableQueryHintAnnotation addHintInternal() { - NestableQueryHintAnnotation hint = this.buildQueryHint(this.hints.size()); - this.hints.add(hint); - return hint; - } - - abstract NestableQueryHintAnnotation buildQueryHint(int index); - - void hintAdded(int index, NestableQueryHintAnnotation hint) { - this.fireItemAdded(HINTS_LIST, index, hint); - } - - public void moveHint(int targetIndex, int sourceIndex) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, this.hintsContainer); - } - - NestableQueryHintAnnotation moveHintInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.hints, targetIndex, sourceIndex).get(targetIndex); - } - - void hintMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(HINTS_LIST, targetIndex, sourceIndex); - } - - public void removeHint(int index) { - AnnotationContainerTools.removeNestedAnnotation(index, this.hintsContainer); - } - - NestableQueryHintAnnotation removeHintInternal(int index) { - return this.hints.remove(index); - } - - void hintRemoved(int index, NestableQueryHintAnnotation hint) { - this.fireItemRemoved(HINTS_LIST, index, hint); - } - - abstract String getHintsElementName(); - - - // ********** NestableAnnotation implementation ********** - - /** - * convenience implementation of method from NestableAnnotation interface - * for subclasses - */ - public void initializeFrom(NestableAnnotation oldAnnotation) { - BaseNamedQueryAnnotation oldQuery = (BaseNamedQueryAnnotation) oldAnnotation; - this.setName(oldQuery.getName()); - this.setQuery(oldQuery.getQuery()); - for (QueryHintAnnotation oldQueryHint : CollectionTools.iterable(oldQuery.hints())) { - NestableQueryHintAnnotation newQueryHint = this.addHint(oldQuery.indexOfHint(oldQueryHint)); - newQueryHint.initializeFrom((NestableQueryHintAnnotation) oldQueryHint); - } - } - - /** - * convenience implementation of method from NestableAnnotation interface - * for subclasses - */ - public void moveAnnotation(int newIndex) { - this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - private IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - - - // ********** hint container ********** - - /** - * adapt the AnnotationContainer interface to the override's join columns - */ - class HintsAnnotationContainer - implements AnnotationContainer<NestableQueryHintAnnotation> - { - public String getContainerAnnotationName() { - return SourceBaseNamedQueryAnnotation.this.getAnnotationName(); - } - - public Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return SourceBaseNamedQueryAnnotation.this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return SourceBaseNamedQueryAnnotation.this.getHintsElementName(); - } - - public String getNestableAnnotationName() { - return QueryHintAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableQueryHintAnnotation> nestedAnnotations() { - return SourceBaseNamedQueryAnnotation.this.nestableHints(); - } - - public int nestedAnnotationsSize() { - return SourceBaseNamedQueryAnnotation.this.hintsSize(); - } - - public NestableQueryHintAnnotation addNestedAnnotationInternal() { - return SourceBaseNamedQueryAnnotation.this.addHintInternal(); - } - - public void nestedAnnotationAdded(int index, NestableQueryHintAnnotation nestedAnnotation) { - SourceBaseNamedQueryAnnotation.this.hintAdded(index, nestedAnnotation); - } - - public NestableQueryHintAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return SourceBaseNamedQueryAnnotation.this.moveHintInternal(targetIndex, sourceIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - SourceBaseNamedQueryAnnotation.this.hintMoved(targetIndex, sourceIndex); - } - - public NestableQueryHintAnnotation removeNestedAnnotationInternal(int index) { - return SourceBaseNamedQueryAnnotation.this.removeHintInternal(index); - } - - public void nestedAnnotationRemoved(int index, NestableQueryHintAnnotation nestedAnnotation) { - SourceBaseNamedQueryAnnotation.this.hintRemoved(index, nestedAnnotation); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseTableAnnotation.java deleted file mode 100644 index 608f9c5cdb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBaseTableAnnotation.java +++ /dev/null @@ -1,352 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationContainer; -import org.eclipse.jpt.core.resource.java.BaseTableAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraintAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.Table - * javax.persistence.JoinTable - * javax.persistence.SecondaryTable - */ -abstract class SourceBaseTableAnnotation - extends SourceAnnotation<Member> - implements BaseTableAnnotation -{ - final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - final AnnotationElementAdapter<String> nameAdapter; - String name; - - final DeclarationAnnotationElementAdapter<String> schemaDeclarationAdapter; - final AnnotationElementAdapter<String> schemaAdapter; - String schema; - - final DeclarationAnnotationElementAdapter<String> catalogDeclarationAdapter; - final AnnotationElementAdapter<String> catalogAdapter; - String catalog; - - final Vector<NestableUniqueConstraintAnnotation> uniqueConstraints = new Vector<NestableUniqueConstraintAnnotation>(); - final UniqueConstraintsAnnotationContainer uniqueConstraintsContainer = new UniqueConstraintsAnnotationContainer(); - - - SourceBaseTableAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - SourceBaseTableAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.nameDeclarationAdapter = this.getNameAdapter(daa); - this.schemaDeclarationAdapter = this.getSchemaAdapter(daa); - this.catalogDeclarationAdapter = this.getCatalogAdapter(daa); - this.nameAdapter = this.buildAnnotationElementAdapter(this.nameDeclarationAdapter); - this.schemaAdapter = this.buildAnnotationElementAdapter(this.schemaDeclarationAdapter); - this.catalogAdapter = this.buildAnnotationElementAdapter(this.catalogDeclarationAdapter); - } - - private AnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - this.schema = this.buildSchema(astRoot); - this.catalog = this.buildCatalog(astRoot); - AnnotationContainerTools.initialize(this.uniqueConstraintsContainer, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - this.setSchema(this.buildSchema(astRoot)); - this.setCatalog(this.buildCatalog(astRoot)); - AnnotationContainerTools.update(this.uniqueConstraintsContainer, astRoot); - } - - /** - * Return the uniqueConstraints element name - */ - abstract String getUniqueConstraintsElementName(); - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** BaseTableAnnotation implementation ********** - - public boolean isSpecified() { - return true; - } - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.nameDeclarationAdapter, pos, astRoot); - } - - /** - * Build and return a declaration element adapter for the table's 'name' element - */ - abstract DeclarationAnnotationElementAdapter<String> getNameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter); - - // ***** schema - public String getSchema() { - return this.schema; - } - - public void setSchema(String schema) { - if (this.attributeValueHasNotChanged(this.schema, schema)) { - return; - } - String old = this.schema; - this.schema = schema; - this.schemaAdapter.setValue(schema); - this.firePropertyChanged(SCHEMA_PROPERTY, old, schema); - } - - private String buildSchema(CompilationUnit astRoot) { - return this.schemaAdapter.getValue(astRoot); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.schemaDeclarationAdapter, astRoot); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.schemaDeclarationAdapter, pos, astRoot); - } - - /** - * Build and return a declaration element adapter for the table's 'schema' element - */ - abstract DeclarationAnnotationElementAdapter<String> getSchemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter); - - // ***** catalog - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String catalog) { - if (this.attributeValueHasNotChanged(this.catalog, catalog)) { - return; - } - String old = this.catalog; - this.catalog = catalog; - this.catalogAdapter.setValue(catalog); - this.firePropertyChanged(CATALOG_PROPERTY, old, catalog); - } - - private String buildCatalog(CompilationUnit astRoot) { - return this.catalogAdapter.getValue(astRoot); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.catalogDeclarationAdapter, astRoot); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.catalogDeclarationAdapter, pos, astRoot); - } - - /** - * Build and return a declaration element adapter for the table's 'catalog' element - */ - abstract DeclarationAnnotationElementAdapter<String> getCatalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter); - - // ***** unique constraints - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return new CloneListIterator<UniqueConstraintAnnotation>(this.uniqueConstraints); - } - - ListIterator<NestableUniqueConstraintAnnotation> nestableUniqueConstraints() { - return new CloneListIterator<NestableUniqueConstraintAnnotation>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public NestableUniqueConstraintAnnotation uniqueConstraintAt(int index) { - return this.uniqueConstraints.get(index); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - return this.uniqueConstraints.indexOf(uniqueConstraint); - } - - public NestableUniqueConstraintAnnotation addUniqueConstraint(int index) { - return (NestableUniqueConstraintAnnotation) AnnotationContainerTools.addNestedAnnotation(index, this.uniqueConstraintsContainer); - } - - NestableUniqueConstraintAnnotation addUniqueConstraintInternal() { - NestableUniqueConstraintAnnotation uniqueConstraint = this.buildUniqueConstraint(this.uniqueConstraints.size()); - this.uniqueConstraints.add(uniqueConstraint); - return uniqueConstraint; - } - - NestableUniqueConstraintAnnotation buildUniqueConstraint(int index) { - return new SourceUniqueConstraintAnnotation(this, this.member, buildUniqueConstraintAnnotationAdapter(index)); - } - - IndexedDeclarationAnnotationAdapter buildUniqueConstraintAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(this.daa, getUniqueConstraintsElementName(), index, JPA.UNIQUE_CONSTRAINT); - } - - void uniqueConstraintAdded(int index, NestableUniqueConstraintAnnotation constraint) { - this.fireItemAdded(UNIQUE_CONSTRAINTS_LIST, index, constraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, this.uniqueConstraintsContainer); - } - - NestableUniqueConstraintAnnotation moveUniqueConstraintInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex).get(targetIndex); - } - - void uniqueConstraintMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - public void removeUniqueConstraint(int index) { - AnnotationContainerTools.removeNestedAnnotation(index, this.uniqueConstraintsContainer); - } - - NestableUniqueConstraintAnnotation removeUniqueConstraintInternal(int index) { - return this.uniqueConstraints.remove(index); - } - - void uniqueConstraintRemoved(int index, NestableUniqueConstraintAnnotation constraint) { - this.fireItemRemoved(UNIQUE_CONSTRAINTS_LIST, index, constraint); - } - - - // ********** NestableAnnotation implementation ********** - - protected void initializeFrom(NestableAnnotation oldAnnotation) { - BaseTableAnnotation oldTable = (BaseTableAnnotation) oldAnnotation; - this.setName(oldTable.getName()); - this.setSchema(oldTable.getSchema()); - this.setCatalog(oldTable.getCatalog()); - for (UniqueConstraintAnnotation oldUniqueConstraint : CollectionTools.iterable(oldTable.uniqueConstraints())) { - NestableUniqueConstraintAnnotation newUniqueConstraint = this.addUniqueConstraint(oldTable.indexOfUniqueConstraint(oldUniqueConstraint)); - newUniqueConstraint.initializeFrom((NestableAnnotation) oldUniqueConstraint); - } - } - - // ********** unique constraint container ********** - - /** - * adapt the AnnotationContainer interface to the table's unique constraints - */ - class UniqueConstraintsAnnotationContainer - implements AnnotationContainer<NestableUniqueConstraintAnnotation> - { - public String getContainerAnnotationName() { - return SourceBaseTableAnnotation.this.getAnnotationName(); - } - - public Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return SourceBaseTableAnnotation.this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return SourceBaseTableAnnotation.this.getUniqueConstraintsElementName(); - } - - public String getNestableAnnotationName() { - return UniqueConstraintAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableUniqueConstraintAnnotation> nestedAnnotations() { - return SourceBaseTableAnnotation.this.nestableUniqueConstraints(); - } - - public int nestedAnnotationsSize() { - return SourceBaseTableAnnotation.this.uniqueConstraintsSize(); - } - - public NestableUniqueConstraintAnnotation addNestedAnnotationInternal() { - return SourceBaseTableAnnotation.this.addUniqueConstraintInternal(); - } - - public void nestedAnnotationAdded(int index, NestableUniqueConstraintAnnotation nestedAnnotation) { - SourceBaseTableAnnotation.this.uniqueConstraintAdded(index, nestedAnnotation); - } - - public NestableUniqueConstraintAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return SourceBaseTableAnnotation.this.moveUniqueConstraintInternal(targetIndex, sourceIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - SourceBaseTableAnnotation.this.uniqueConstraintMoved(targetIndex, sourceIndex); - } - - public NestableUniqueConstraintAnnotation removeNestedAnnotationInternal(int index) { - return SourceBaseTableAnnotation.this.removeUniqueConstraintInternal(index); - } - - public void nestedAnnotationRemoved(int index, NestableUniqueConstraintAnnotation nestedAnnotation) { - SourceBaseTableAnnotation.this.uniqueConstraintRemoved(index, nestedAnnotation); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBasicAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBasicAnnotation.java deleted file mode 100644 index c9d4466863..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceBasicAnnotation.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.BooleanExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.Basic - */ -public final class SourceBasicAnnotation - extends SourceAnnotation<Attribute> - implements BasicAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<Boolean> OPTIONAL_ADAPTER = buildOptionalAdapter(); - private final AnnotationElementAdapter<Boolean> optionalAdapter; - private Boolean optional; - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - private final AnnotationElementAdapter<String> fetchAdapter; - private FetchType fetch; - - - public SourceBasicAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.optionalAdapter = new ShortCircuitAnnotationElementAdapter<Boolean>(attribute, OPTIONAL_ADAPTER); - this.fetchAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, FETCH_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.optional = this.buildOptional(astRoot); - this.fetch = this.buildFetch(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setOptional(this.buildOptional(astRoot)); - this.setFetch(this.buildFetch(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.fetch); - } - - - //*************** Basic implementation **************** - - // ***** optional - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean optional) { - if (this.attributeValueHasNotChanged(this.optional, optional)) { - return; - } - Boolean old = this.optional; - this.optional = optional; - this.optionalAdapter.setValue(optional); - this.firePropertyChanged(OPTIONAL_PROPERTY, old, optional); - } - - protected Boolean buildOptional(CompilationUnit astRoot) { - return this.optionalAdapter.getValue(astRoot); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(OPTIONAL_ADAPTER, astRoot); - } - - // ***** fetch - public FetchType getFetch() { - return this.fetch; - } - - public void setFetch(FetchType fetch) { - if (this.attributeValueHasNotChanged(this.fetch, fetch)) { - return; - } - FetchType old = this.fetch; - this.fetch = fetch; - this.fetchAdapter.setValue(FetchType.toJavaAnnotationValue(fetch)); - this.firePropertyChanged(FETCH_PROPERTY, old, fetch); - } - - protected FetchType buildFetch(CompilationUnit astRoot) { - return FetchType.fromJavaAnnotationValue(this.fetchAdapter.getValue(astRoot)); - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(FETCH_ADAPTER, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<Boolean> buildOptionalAdapter() { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(DECLARATION_ANNOTATION_ADAPTER, JPA.BASIC__OPTIONAL, false, BooleanExpressionConverter.instance()); - } - - private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.BASIC__FETCH, false); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceColumnAnnotation.java deleted file mode 100644 index d04fb8b97c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceColumnAnnotation.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Column - */ -public final class SourceColumnAnnotation - extends SourceBaseColumnAnnotation - implements NestableColumnAnnotation -{ - // this adapter is only used by a Column annotation associated with a mapping annotation (e.g. Basic) - public static final DeclarationAnnotationAdapter MAPPING_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final DeclarationAnnotationElementAdapter<Integer> lengthDeclarationAdapter; - private final AnnotationElementAdapter<Integer> lengthAdapter; - private Integer length; - - private final DeclarationAnnotationElementAdapter<Integer> precisionDeclarationAdapter; - private final AnnotationElementAdapter<Integer> precisionAdapter; - private Integer precision; - - private final DeclarationAnnotationElementAdapter<Integer> scaleDeclarationAdapter; - private final AnnotationElementAdapter<Integer> scaleAdapter; - private Integer scale; - - - public SourceColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - super(parent, member, daa); - this.lengthDeclarationAdapter = this.buildIntegerElementAdapter(JPA.COLUMN__LENGTH); - this.lengthAdapter = this.buildShortCircuitIntegerElementAdapter(this.lengthDeclarationAdapter); - this.precisionDeclarationAdapter = this.buildIntegerElementAdapter(JPA.COLUMN__PRECISION); - this.precisionAdapter = this.buildShortCircuitIntegerElementAdapter(this.precisionDeclarationAdapter); - this.scaleDeclarationAdapter = this.buildIntegerElementAdapter(JPA.COLUMN__SCALE); - this.scaleAdapter = this.buildShortCircuitIntegerElementAdapter(this.scaleDeclarationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.length = this.buildLength(astRoot); - this.precision = this.buildPrecision(astRoot); - this.scale = this.buildScale(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setLength(this.buildLength(astRoot)); - this.setPrecision(this.buildPrecision(astRoot)); - this.setScale(this.buildScale(astRoot)); - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.COLUMN__COLUMN_DEFINITION; - } - - - // ********** JavaSourceBaseColumnAnnotation implementation ********** - - @Override - String getTableElementName() { - return JPA.COLUMN__TABLE; - } - - @Override - String getUniqueElementName() { - return JPA.COLUMN__UNIQUE; - } - - @Override - String getNullableElementName() { - return JPA.COLUMN__NULLABLE; - } - - @Override - String getInsertableElementName() { - return JPA.COLUMN__INSERTABLE; - } - - @Override - String getUpdatableElementName() { - return JPA.COLUMN__UPDATABLE; - } - - - // ********** Column implementation ********** - - // ***** length - public Integer getLength() { - return this.length; - } - - public void setLength(Integer length) { - if (this.attributeValueHasNotChanged(this.length, length)) { - return; - } - Integer old = this.length; - this.length = length; - this.lengthAdapter.setValue(length); - this.firePropertyChanged(LENGTH_PROPERTY, old, length); - } - - private Integer buildLength(CompilationUnit astRoot) { - return this.lengthAdapter.getValue(astRoot); - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.lengthDeclarationAdapter, astRoot); - } - - // ***** precision - public Integer getPrecision() { - return this.precision; - } - - public void setPrecision(Integer precision) { - if (this.attributeValueHasNotChanged(this.precision, precision)) { - return; - } - Integer old = this.precision; - this.precision = precision; - this.precisionAdapter.setValue(precision); - this.firePropertyChanged(PRECISION_PROPERTY, old, precision); - } - - private Integer buildPrecision(CompilationUnit astRoot) { - return this.precisionAdapter.getValue(astRoot); - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.precisionDeclarationAdapter, astRoot); - } - - // ***** scale - public Integer getScale() { - return this.scale; - } - - public void setScale(Integer scale) { - if (this.attributeValueHasNotChanged(this.scale, scale)) { - return; - } - Integer old = this.scale; - this.scale = scale; - this.scaleAdapter.setValue(scale); - this.firePropertyChanged(SCALE_PROPERTY, old, scale); - } - - private Integer buildScale(CompilationUnit astRoot) { - return this.scaleAdapter.getValue(astRoot); - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.scaleDeclarationAdapter, astRoot); - } - - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - ColumnAnnotation oldColumn = (ColumnAnnotation) oldAnnotation; - this.setLength(oldColumn.getLength()); - this.setPrecision(oldColumn.getPrecision()); - this.setScale(oldColumn.getScale()); - } - - public void moveAnnotation(int newIndex) { - // the only place where a column annotation is nested is in an - // attribute override; and that only nests a single column, not an array - // of columns; so #moveAnnotation(int) is never called - // TODO maybe NestableAnnotation should be split up; - // moving this method to something like IndexableAnnotation - throw new UnsupportedOperationException(); - } - - - // ********** static methods ********** - - static NestableColumnAnnotation createAttributeOverrideColumn(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter attributeOverrideAnnotationAdapter) { - return new SourceColumnAnnotation(parent, member, buildAttributeOverrideAnnotationAdapter(attributeOverrideAnnotationAdapter)); - } - - static DeclarationAnnotationAdapter buildAttributeOverrideAnnotationAdapter(DeclarationAnnotationAdapter attributeOverrideAnnotationAdapter) { - return new NestedDeclarationAnnotationAdapter(attributeOverrideAnnotationAdapter, JPA.ATTRIBUTE_OVERRIDE__COLUMN, JPA.COLUMN); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java deleted file mode 100644 index 05b908a909..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.JpaResourceModelListener; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - -/** - * Java compilation unit (source file) - */ -public final class SourceCompilationUnit - extends SourceNode - implements JavaResourceCompilationUnit -{ - /** JDT compilation unit */ - private final ICompilationUnit compilationUnit; - - /** pluggable annotation provider */ - private final JpaAnnotationProvider annotationProvider; - - /** improved annotation formatting */ - private final AnnotationEditFormatter annotationEditFormatter; - - /** pluggable executor that allows the document to be modified on another thread */ - private final CommandExecutor modifySharedDocumentCommandExecutor; - - /** listeners notified whenever the resource model changes */ - private final ListenerList<JpaResourceModelListener> resourceModelListenerList; - - /** - * The primary type of the AST compilation unit. We are not going to handle - * multiple types defined in a single compilation unit. Entities must have - * a public/protected no-arg constructor, and there is no way to access - * the constructor in a package class (which is what all top-level, - * non-primary classes must be). - */ - protected JavaResourcePersistentType persistentType; - - - // ********** construction ********** - - public SourceCompilationUnit( - ICompilationUnit compilationUnit, - JpaAnnotationProvider annotationProvider, - AnnotationEditFormatter annotationEditFormatter, - CommandExecutor modifySharedDocumentCommandExecutor) { - super(null); // the JPA compilation unit is the root of its sub-tree - this.compilationUnit = compilationUnit; - this.annotationProvider = annotationProvider; - this.annotationEditFormatter = annotationEditFormatter; - this.modifySharedDocumentCommandExecutor = modifySharedDocumentCommandExecutor; - this.resourceModelListenerList = new ListenerList<JpaResourceModelListener>(JpaResourceModelListener.class); - this.persistentType = this.buildPersistentType(); - } - - protected JavaResourcePersistentType buildPersistentType() { - this.openCompilationUnit(); - CompilationUnit astRoot = this.buildASTRoot(); - this.closeCompilationUnit(); - return this.buildPersistentType(astRoot); - } - - protected void openCompilationUnit() { - try { - this.compilationUnit.open(null); - } catch (JavaModelException ex) { - // do nothing - we just won't have a primary type in this case - } - } - - protected void closeCompilationUnit() { - try { - this.compilationUnit.close(); - } catch (JavaModelException ex) { - // hmmm - } - } - - protected JavaResourcePersistentType buildPersistentType(CompilationUnit astRoot) { - TypeDeclaration td = this.getPrimaryType(astRoot); - return (td == null) ? null : this.buildPersistentType(astRoot, td); - } - - @Override - protected boolean requiresParent() { - return false; - } - - public void initialize(CompilationUnit astRoot) { - // never called? - } - - - // ********** AbstractJavaResourceNode overrides ********** - - @Override - public JavaResourceCompilationUnit getRoot() { - return this; - } - - @Override - public IFile getFile() { - return (IFile) this.compilationUnit.getResource(); - } - - @Override - public JpaAnnotationProvider getAnnotationProvider() { - return this.annotationProvider; - } - - - // ********** JavaResourceNode implementation ********** - - public void update(CompilationUnit astRoot) { - TypeDeclaration td = this.getPrimaryType(astRoot); - if (td == null) { - this.persistentType = null; - } else { - if (this.persistentType == null) { - this.persistentType = this.buildPersistentType(astRoot, td); - } else { - this.persistentType.update(astRoot); - } - } - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - - // ********** JavaResourceNode.Root implementation ********** - - /** - * NB: return *all* the persistent types since we build them all - */ - public Iterator<JavaResourcePersistentType> persistentTypes() { - return (this.persistentType == null) ? - EmptyIterator.<JavaResourcePersistentType>instance() : - this.persistentType.allTypes(); - } - - public void resourceModelChanged() { - for (JpaResourceModelListener listener : this.resourceModelListenerList.getListeners()) { - listener.resourceModelChanged(); - } - } - - - // ********** JavaResourceCompilationUnit implementation ********** - - public ICompilationUnit getCompilationUnit() { - return this.compilationUnit; - } - - public void resolveTypes() { - if (this.persistentType != null) { - this.persistentType.resolveTypes(this.buildASTRoot()); - } - } - - public CommandExecutor getModifySharedDocumentCommandExecutor() { - return this.modifySharedDocumentCommandExecutor; - } - - public AnnotationEditFormatter getAnnotationEditFormatter() { - return this.annotationEditFormatter; - } - - public CompilationUnit buildASTRoot() { - return JDTTools.buildASTRoot(this.compilationUnit); - } - - - // ********** JpaResourceModel implementation ********** - - public void addResourceModelListener(JpaResourceModelListener listener) { - this.resourceModelListenerList.add(listener); - } - - public void removeResourceModelListener(JpaResourceModelListener listener) { - this.resourceModelListenerList.remove(listener); - } - - - // ********** Java changes ********** - - public void update() { - this.update(this.buildASTRoot()); - } - - - // ********** internal ********** - - protected JavaResourcePersistentType buildPersistentType(CompilationUnit astRoot, TypeDeclaration typeDeclaration) { - return SourcePersistentType.newInstance(this, typeDeclaration, astRoot); - } - - /** - * i.e. the type with the same name as the compilation unit; - * return the first class or interface (ignore annotations and enums) with - * the same name as the compilation unit (file); - * NB: this type could be in error if there is an annotation or enum - * with the same name preceding it in the compilation unit - * - * Return null if the parser did not resolve the type declaration's binding. - * This can occur if the project JRE is removed (bug 225332). - */ - protected TypeDeclaration getPrimaryType(CompilationUnit astRoot) { - String primaryTypeName = this.getPrimaryTypeName(); - for (AbstractTypeDeclaration atd : types(astRoot)) { - if ((atd.getNodeType() == ASTNode.TYPE_DECLARATION) - && atd.getName().getFullyQualifiedName().equals(primaryTypeName)) { - return (atd.resolveBinding() == null) ? null : (TypeDeclaration) atd; - } - } - return null; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - protected static List<AbstractTypeDeclaration> types(CompilationUnit astRoot) { - return astRoot.types(); - } - - /** - * i.e. the name of the compilation unit - */ - protected String getPrimaryTypeName() { - return removeJavaExtension(this.compilationUnit.getElementName()); - } - - protected static String removeJavaExtension(String fileName) { - int index = fileName.lastIndexOf(".java"); //$NON-NLS-1$ - return (index == -1) ? fileName : fileName.substring(0, index); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getPrimaryTypeName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceDiscriminatorColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceDiscriminatorColumnAnnotation.java deleted file mode 100644 index 0239d3f048..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceDiscriminatorColumnAnnotation.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.DiscriminatorColumn - */ -public final class SourceDiscriminatorColumnAnnotation - extends SourceNamedColumnAnnotation - implements DiscriminatorColumnAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> DISCRIMINATOR_TYPE_ADAPTER = buildDiscriminatorTypeAdapter(); - private final AnnotationElementAdapter<String> discriminatorTypeAdapter; - private DiscriminatorType discriminatorType; - - private final DeclarationAnnotationElementAdapter<Integer> lengthDeclarationAdapter; - private final AnnotationElementAdapter<Integer> lengthAdapter; - private Integer length; - - - public SourceDiscriminatorColumnAnnotation(JavaResourcePersistentType parent, Member member, DeclarationAnnotationAdapter daa) { - super(parent, member, daa); - this.discriminatorTypeAdapter = new ShortCircuitAnnotationElementAdapter<String>(member, DISCRIMINATOR_TYPE_ADAPTER); - this.lengthDeclarationAdapter = this.buildIntegerElementAdapter(JPA.DISCRIMINATOR_COLUMN__LENGTH); - this.lengthAdapter = this.buildShortCircuitIntegerElementAdapter(this.lengthDeclarationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.discriminatorType = this.buildDiscriminatorType(astRoot); - this.length = this.buildLength(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setLength(this.buildLength(astRoot)); - this.setDiscriminatorType(this.buildDiscriminatorType(astRoot)); - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.DISCRIMINATOR_COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.DISCRIMINATOR_COLUMN__COLUMN_DEFINITION; - } - - - // ********** DiscriminatorColumn implementation ********** - - // ***** discriminator type - public DiscriminatorType getDiscriminatorType() { - return this.discriminatorType; - } - - public void setDiscriminatorType(DiscriminatorType discriminatorType) { - if (this.attributeValueHasNotChanged(this.discriminatorType, discriminatorType)) { - return; - } - DiscriminatorType old = this.discriminatorType; - this.discriminatorType = discriminatorType; - this.discriminatorTypeAdapter.setValue(DiscriminatorType.toJavaAnnotationValue(discriminatorType)); - this.firePropertyChanged(DISCRIMINATOR_TYPE_PROPERTY, old, discriminatorType); - } - - private DiscriminatorType buildDiscriminatorType(CompilationUnit astRoot) { - return DiscriminatorType.fromJavaAnnotationValue(this.discriminatorTypeAdapter.getValue(astRoot)); - } - - // ***** length - public Integer getLength() { - return this.length; - } - - public void setLength(Integer length) { - if (this.attributeValueHasNotChanged(this.length, length)) { - return; - } - Integer old = this.length; - this.length = length; - this.lengthAdapter.setValue(length); - this.firePropertyChanged(LENGTH_PROPERTY, old, length); - } - - private Integer buildLength(CompilationUnit astRoot) { - return this.lengthAdapter.getValue(astRoot); - } - - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - throw new UnsupportedOperationException("DiscriminatorColumn is not a nestable annotation"); //$NON-NLS-1$ - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildDiscriminatorTypeAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.DISCRIMINATOR_COLUMN__DISCRIMINATOR_TYPE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceDiscriminatorValueAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceDiscriminatorValueAnnotation.java deleted file mode 100644 index 33dac08ce5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceDiscriminatorValueAnnotation.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.DiscriminatorValue - */ -public final class SourceDiscriminatorValueAnnotation - extends SourceAnnotation<Type> - implements DiscriminatorValueAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); - private final AnnotationElementAdapter<String> valueAdapter; - private String value; - - - public SourceDiscriminatorValueAnnotation(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(type, VALUE_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.buildValue(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.buildValue(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** DiscriminatorValueAnnotation implementation ********** - - // ***** value - public String getValue() { - return this.value; - } - - public void setValue(String value) { - if (this.attributeValueHasNotChanged(this.value, value)) { - return; - } - String old = this.value; - this.value = value; - this.valueAdapter.setValue(value); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private String buildValue(CompilationUnit astRoot) { - return this.valueAdapter.getValue(astRoot); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.DISCRIMINATOR_VALUE__VALUE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddableAnnotation.java deleted file mode 100644 index 787e136a18..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddableAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.Embeddable - */ -public final class SourceEmbeddableAnnotation - extends SourceAnnotation<Type> - implements EmbeddableAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceEmbeddableAnnotation(JavaResourcePersistentType parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddedAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddedAnnotation.java deleted file mode 100644 index 723086ad8a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddedAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; - -/** - * javax.persistence.Embedded - */ -public final class SourceEmbeddedAnnotation - extends SourceAnnotation<Attribute> - implements EmbeddedAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceEmbeddedAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddedIdAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddedIdAnnotation.java deleted file mode 100644 index c35382bb7d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEmbeddedIdAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; - -/** - * javax.persistence.EmbeddedId - */ -public final class SourceEmbeddedIdAnnotation - extends SourceAnnotation<Attribute> - implements EmbeddedIdAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceEmbeddedIdAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEntityAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEntityAnnotation.java deleted file mode 100644 index 55662448e9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEntityAnnotation.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.Entity - */ -public final class SourceEntityAnnotation - extends SourceAnnotation<Type> - implements EntityAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildNameAdapter(); - private final AnnotationElementAdapter<String> nameAdapter; - private String name; - - - public SourceEntityAnnotation(JavaResourcePersistentType parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(this.member, NAME_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** EntityAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(NAME_ADAPTER, astRoot); - } - - - //*********** static methods **************** - - private static DeclarationAnnotationElementAdapter<String> buildNameAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.ENTITY__NAME, false); // false = do not remove annotation when empty - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEnumeratedAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEnumeratedAnnotation.java deleted file mode 100644 index 9ba3ff5f65..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceEnumeratedAnnotation.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.EnumType; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.Enumerated - */ -public final class SourceEnumeratedAnnotation - extends SourceAnnotation<Attribute> - implements EnumeratedAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); - private final AnnotationElementAdapter<String> valueAdapter; - private EnumType value; - - - public SourceEnumeratedAnnotation(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, VALUE_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.buildValue(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.buildValue(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** EnumeratedAnnotation implementation ********** - - // ***** value - public EnumType getValue() { - return this.value; - } - - public void setValue(EnumType value) { - if (this.attributeValueHasNotChanged(this.value, value)) { - return; - } - EnumType old = this.value; - this.value = value; - this.valueAdapter.setValue(EnumType.toJavaAnnotationValue(value)); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private EnumType buildValue(CompilationUnit astRoot) { - return EnumType.fromJavaAnnotationValue(this.valueAdapter.getValue(astRoot)); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ENUMERATED__VALUE, false); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceGeneratedValueAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceGeneratedValueAnnotation.java deleted file mode 100644 index 8461845e88..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceGeneratedValueAnnotation.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.GenerationType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.GeneratedValue - */ -public final class SourceGeneratedValueAnnotation - extends SourceAnnotation<Member> - implements GeneratedValueAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> STRATEGY_ADAPTER = buildStrategyAdapter(); - private final AnnotationElementAdapter<String> strategyAdapter; - private GenerationType strategy; - - private static final DeclarationAnnotationElementAdapter<String> GENERATOR_ADAPTER = buildGeneratorAdapter(); - private final AnnotationElementAdapter<String> generatorAdapter; - private String generator; - - - public SourceGeneratedValueAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.strategyAdapter = new ShortCircuitAnnotationElementAdapter<String>(member, STRATEGY_ADAPTER); - this.generatorAdapter = new ShortCircuitAnnotationElementAdapter<String>(member, GENERATOR_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.strategy = this.buildStrategy(astRoot); - this.generator = this.buildGenerator(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setStrategy(this.buildStrategy(astRoot)); - this.setGenerator(this.buildGenerator(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.strategy); - } - - - // ********** GeneratedValueAnnotation implementation ********** - - // ***** strategy - public GenerationType getStrategy() { - return this.strategy; - } - - public void setStrategy(GenerationType strategy) { - if (this.attributeValueHasNotChanged(this.strategy, strategy)) { - return; - } - GenerationType old = this.strategy; - this.strategy = strategy; - this.strategyAdapter.setValue(GenerationType.toJavaAnnotationValue(strategy)); - this.firePropertyChanged(STRATEGY_PROPERTY, old, strategy); - } - - private GenerationType buildStrategy(CompilationUnit astRoot) { - return GenerationType.fromJavaAnnotationValue(this.strategyAdapter.getValue(astRoot)); - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(STRATEGY_ADAPTER, astRoot); - } - - // ***** generator - public String getGenerator() { - return this.generator; - } - - public void setGenerator(String generator) { - if (this.attributeValueHasNotChanged(this.generator, generator)) { - return; - } - String old = this.generator; - this.generator = generator; - this.generatorAdapter.setValue(generator); - this.firePropertyChanged(GENERATOR_PROPERTY, old, generator); - } - - private String buildGenerator(CompilationUnit astRoot) { - return this.generatorAdapter.getValue(astRoot); - } - - public TextRange getGeneratorTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(GENERATOR_ADAPTER, astRoot); - } - - public boolean generatorTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(GENERATOR_ADAPTER, pos, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildStrategyAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.GENERATED_VALUE__STRATEGY, false); - } - - private static DeclarationAnnotationElementAdapter<String> buildGeneratorAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.GENERATED_VALUE__GENERATOR, false); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceGeneratorAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceGeneratorAnnotation.java deleted file mode 100644 index fd6d68a5ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceGeneratorAnnotation.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NumberIntegerExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.resource.java.GeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.SequenceGenerator - * javax.persistence.TableGenerator - */ -abstract class SourceGeneratorAnnotation - extends SourceAnnotation<Member> - implements GeneratorAnnotation -{ - final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - final AnnotationElementAdapter<String> nameAdapter; - String name; - - final DeclarationAnnotationElementAdapter<Integer> initialValueDeclarationAdapter; - final AnnotationElementAdapter<Integer> initialValueAdapter; - Integer initialValue; - - final DeclarationAnnotationElementAdapter<Integer> allocationSizeDeclarationAdapter; - final AnnotationElementAdapter<Integer> allocationSizeAdapter; - Integer allocationSize; - - - SourceGeneratorAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - super(parent, member, daa); - this.nameDeclarationAdapter = this.getNameAdapter(); - this.nameAdapter = this.buildAdapter(this.nameDeclarationAdapter); - this.initialValueDeclarationAdapter = this.getInitialValueAdapter(); - this.initialValueAdapter = this.buildIntegerAdapter(this.initialValueDeclarationAdapter); - this.allocationSizeDeclarationAdapter = this.getAllocationSizeAdapter(); - this.allocationSizeAdapter = this.buildIntegerAdapter(this.allocationSizeDeclarationAdapter); - } - - protected AnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea); - } - - protected AnnotationElementAdapter<Integer> buildIntegerAdapter(DeclarationAnnotationElementAdapter<Integer> daea) { - return new ShortCircuitAnnotationElementAdapter<Integer>(this.member, daea); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - this.initialValue = this.buildInitialValue(astRoot); - this.allocationSize = this.buildAllocationSize(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - this.setInitialValue(this.buildInitialValue(astRoot)); - this.setAllocationSize(this.buildAllocationSize(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** GeneratorAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - abstract DeclarationAnnotationElementAdapter<String> getNameAdapter(); - - // ***** initial value - public Integer getInitialValue() { - return this.initialValue; - } - - public void setInitialValue(Integer initialValue) { - if (this.attributeValueHasNotChanged(this.initialValue, initialValue)) { - return; - } - Integer old = this.initialValue; - this.initialValue = initialValue; - this.initialValueAdapter.setValue(initialValue); - this.firePropertyChanged(INITIAL_VALUE_PROPERTY, old, initialValue); - } - - private Integer buildInitialValue(CompilationUnit astRoot) { - return this.initialValueAdapter.getValue(astRoot); - } - - public TextRange getInitialValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.initialValueDeclarationAdapter, astRoot); - } - - abstract DeclarationAnnotationElementAdapter<Integer> getInitialValueAdapter(); - - // ***** allocation size - public Integer getAllocationSize() { - return this.allocationSize; - } - - public void setAllocationSize(Integer allocationSize) { - if (this.attributeValueHasNotChanged(this.allocationSize, allocationSize)) { - return; - } - Integer old = this.allocationSize; - this.allocationSize = allocationSize; - this.allocationSizeAdapter.setValue(allocationSize); - this.firePropertyChanged(ALLOCATION_SIZE_PROPERTY, old, allocationSize); - } - - private Integer buildAllocationSize(CompilationUnit astRoot) { - return this.allocationSizeAdapter.getValue(astRoot); - } - - public TextRange getAllocationSizeTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.allocationSizeDeclarationAdapter, astRoot); - } - - abstract DeclarationAnnotationElementAdapter<Integer> getAllocationSizeAdapter(); - - - // ********** static methods ********** - - static DeclarationAnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(annotationAdapter, elementName); - } - - static DeclarationAnnotationElementAdapter<Integer> buildIntegerAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Integer>(annotationAdapter, elementName, NumberIntegerExpressionConverter.instance()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceIdAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceIdAnnotation.java deleted file mode 100644 index 224785258d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceIdAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; - -/** - * javax.persistence.Id - */ -public final class SourceIdAnnotation - extends SourceAnnotation<Attribute> - implements IdAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceIdAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceIdClassAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceIdClassAnnotation.java deleted file mode 100644 index 96712da0a5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceIdClassAnnotation.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.IdClass - */ -public final class SourceIdClassAnnotation - extends SourceAnnotation<Type> - implements IdClassAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); - private final AnnotationElementAdapter<String> valueAdapter; - private String value; - - private String fullyQualifiedClassName; - - - public SourceIdClassAnnotation(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(type, VALUE_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.buildValue(astRoot); - this.fullyQualifiedClassName = this.buildFullyQualifiedClassName(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.buildValue(astRoot)); - this.setFullyQualifiedClassName(this.buildFullyQualifiedClassName(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** IdClassAnnotation implementation ********** - - // ***** value - public String getValue() { - return this.value; - } - - public void setValue(String value) { - if (this.attributeValueHasNotChanged(this.value, value)) { - return; - } - String old = this.value; - this.value = value; - this.valueAdapter.setValue(value); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private String buildValue(CompilationUnit astRoot) { - return this.valueAdapter.getValue(astRoot); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - // ***** fully-qualified class name - public String getFullyQualifiedClassName() { - return this.fullyQualifiedClassName; - } - - private void setFullyQualifiedClassName(String fullyQualifiedClassName) { - String old = this.fullyQualifiedClassName; - this.fullyQualifiedClassName = fullyQualifiedClassName; - this.firePropertyChanged(FULLY_QUALIFIED_CLASS_NAME_PROPERTY, old, fullyQualifiedClassName); - } - - private String buildFullyQualifiedClassName(CompilationUnit astRoot) { - return (this.value == null) ? null : JDTTools.resolveFullyQualifiedName(this.valueAdapter.getExpression(astRoot)); - } - - - // ********** static methods ********** - - protected static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, JPA.ID_CLASS__VALUE, SimpleTypeStringExpressionConverter.instance()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceInheritanceAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceInheritanceAnnotation.java deleted file mode 100644 index 12957ce4b5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceInheritanceAnnotation.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.Inheritance - */ -public final class SourceInheritanceAnnotation - extends SourceAnnotation<Type> - implements InheritanceAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> STRATEGY_ADAPTER = buildStrategyAdapter(); - private final AnnotationElementAdapter<String> strategyAdapter; - private InheritanceType strategy; - - - public SourceInheritanceAnnotation(JavaResourcePersistentType parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.strategyAdapter = new ShortCircuitAnnotationElementAdapter<String>(type, STRATEGY_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.strategy = this.buildStrategy(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setStrategy(this.buildStrategy(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.strategy); - } - - - // ********** InheritanceAnnotation implementation ********** - - // ***** strategy - public InheritanceType getStrategy() { - return this.strategy; - } - - public void setStrategy(InheritanceType strategy) { - if (this.attributeValueHasNotChanged(this.strategy, strategy)) { - return; - } - InheritanceType old = this.strategy; - this.strategy = strategy; - this.strategyAdapter.setValue(InheritanceType.toJavaAnnotationValue(strategy)); - this.firePropertyChanged(STRATEGY_PROPERTY, old, strategy); - } - - private InheritanceType buildStrategy(CompilationUnit astRoot) { - return InheritanceType.fromJavaAnnotationValue(this.strategyAdapter.getValue(astRoot)); - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(STRATEGY_ADAPTER, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildStrategyAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.INHERITANCE__STRATEGY); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinColumnAnnotation.java deleted file mode 100644 index cf9f24a3a6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinColumnAnnotation.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.JoinColumn - */ -public final class SourceJoinColumnAnnotation - extends SourceBaseColumnAnnotation - implements NestableJoinColumnAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final DeclarationAnnotationElementAdapter<String> referencedColumnNameDeclarationAdapter; - private final AnnotationElementAdapter<String> referencedColumnNameAdapter; - private String referencedColumnName; - - - public SourceJoinColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.referencedColumnNameDeclarationAdapter = this.buildStringElementAdapter(JPA.JOIN_COLUMN__REFERENCED_COLUMN_NAME); - this.referencedColumnNameAdapter = this.buildShortCircuitElementAdapter(this.referencedColumnNameDeclarationAdapter); - } - - public SourceJoinColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - public SourceJoinColumnAnnotation(JavaResourceNode parent, Member member, IndexedDeclarationAnnotationAdapter idaa) { - this(parent, member, idaa, new MemberIndexedAnnotationAdapter(member, idaa)); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.referencedColumnName = this.buildReferencedColumnName(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setReferencedColumnName(this.buildReferencedColumnName(astRoot)); - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.JOIN_COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.JOIN_COLUMN__COLUMN_DEFINITION; - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getTableElementName() { - return JPA.JOIN_COLUMN__TABLE; - } - - @Override - String getUniqueElementName() { - return JPA.JOIN_COLUMN__UNIQUE; - } - - @Override - String getNullableElementName() { - return JPA.JOIN_COLUMN__NULLABLE; - } - - @Override - String getInsertableElementName() { - return JPA.JOIN_COLUMN__INSERTABLE; - } - - @Override - String getUpdatableElementName() { - return JPA.JOIN_COLUMN__UPDATABLE; - } - - - //************ JoinColumn implementation *************** - - // referenced column name - public String getReferencedColumnName() { - return this.referencedColumnName; - } - - public void setReferencedColumnName(String referencedColumnName) { - if (this.attributeValueHasNotChanged(this.referencedColumnName, referencedColumnName)) { - return; - } - String old = this.referencedColumnName; - this.referencedColumnName = referencedColumnName; - this.referencedColumnNameAdapter.setValue(referencedColumnName); - this.firePropertyChanged(REFERENCED_COLUMN_NAME_PROPERTY, old, referencedColumnName); - } - - private String buildReferencedColumnName(CompilationUnit astRoot) { - return this.referencedColumnNameAdapter.getValue(astRoot); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.referencedColumnNameDeclarationAdapter, astRoot); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.referencedColumnNameDeclarationAdapter, pos, astRoot); - } - - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - JoinColumnAnnotation oldJoinColumn = (JoinColumnAnnotation) oldAnnotation; - this.setReferencedColumnName(oldJoinColumn.getReferencedColumnName()); - } - - public void moveAnnotation(int newIndex) { - this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - protected IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - - - // ********** static methods ********** - - public static SourceJoinColumnAnnotation createJoinColumn(JavaResourceNode parent, Member member) { - return new SourceJoinColumnAnnotation(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - static SourceJoinColumnAnnotation createNestedJoinColumn(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter joinColumnsAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, joinColumnsAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new SourceJoinColumnAnnotation(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter joinColumnsAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(joinColumnsAdapter, index, JPA.JOIN_COLUMN); - } - - static NestableJoinColumnAnnotation createAssociationOverrideJoinColumn(DeclarationAnnotationAdapter associationOverrideAdapter, JavaResourceNode parent, Member member, int index) { - return new SourceJoinColumnAnnotation(parent, member, buildAssociationOverrideAnnotationAdapter(associationOverrideAdapter, index)); - } - - private static IndexedDeclarationAnnotationAdapter buildAssociationOverrideAnnotationAdapter(DeclarationAnnotationAdapter associationOverrideAdapter, int index) { - return new NestedIndexedDeclarationAnnotationAdapter(associationOverrideAdapter, JPA.ASSOCIATION_OVERRIDE__JOIN_COLUMNS, index, JPA.JOIN_COLUMN); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinColumnsAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinColumnsAnnotation.java deleted file mode 100644 index 30f633fd88..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinColumnsAnnotation.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.JoinColumns - */ -public final class SourceJoinColumnsAnnotation - extends SourceAnnotation<Member> - implements JoinColumnsAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestableJoinColumnAnnotation> joinColumns = new Vector<NestableJoinColumnAnnotation>(); - - - public SourceJoinColumnsAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - AnnotationContainerTools.initialize(this, astRoot); - } - - public void update(CompilationUnit astRoot) { - AnnotationContainerTools.update(this, astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.joinColumns); - } - - - // ********** AnnotationContainer implementation ********** - - public String getContainerAnnotationName() { - return this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.JOIN_COLUMNS__VALUE; - } - - public String getNestableAnnotationName() { - return JoinColumnAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableJoinColumnAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableJoinColumnAnnotation>(this.joinColumns); - } - - public int nestedAnnotationsSize() { - return this.joinColumns.size(); - } - - public NestableJoinColumnAnnotation addNestedAnnotationInternal() { - NestableJoinColumnAnnotation joinColumn = this.buildJoinColumn(this.joinColumns.size()); - this.joinColumns.add(joinColumn); - return joinColumn; - } - - private NestableJoinColumnAnnotation buildJoinColumn(int index) { - return SourceJoinColumnAnnotation.createNestedJoinColumn(this, this.member, index, this.daa); - } - - public void nestedAnnotationAdded(int index, NestableJoinColumnAnnotation nestedAnnotation) { - this.fireItemAdded(JOIN_COLUMNS_LIST, index, nestedAnnotation); - } - - public NestableJoinColumnAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.joinColumns, targetIndex, sourceIndex).get(targetIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public NestableJoinColumnAnnotation removeNestedAnnotationInternal(int index) { - return this.joinColumns.remove(index); - } - - public void nestedAnnotationRemoved(int index, NestableJoinColumnAnnotation nestedAnnotation) { - this.fireItemRemoved(JOIN_COLUMNS_LIST, index, nestedAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinTableAnnotation.java deleted file mode 100644 index 56822b9f22..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceJoinTableAnnotation.java +++ /dev/null @@ -1,381 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationContainer; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinTableAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.JoinTable - */ -public class SourceJoinTableAnnotation - extends SourceBaseTableAnnotation - implements NestableJoinTableAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JoinTableAnnotation.ANNOTATION_NAME); - - - private final Vector<NestableJoinColumnAnnotation> joinColumns = new Vector<NestableJoinColumnAnnotation>(); - private final JoinColumnsAnnotationContainer joinColumnsContainer = new JoinColumnsAnnotationContainer(); - - private final Vector<NestableJoinColumnAnnotation> inverseJoinColumns = new Vector<NestableJoinColumnAnnotation>(); - private final InverseJoinColumnsContainerAnnotation inverseJoinColumnsContainer = new InverseJoinColumnsContainerAnnotation(); - - - public SourceJoinTableAnnotation(JavaResourceNode parent, Member member) { - this(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - public SourceJoinTableAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - super(parent, member, daa); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - AnnotationContainerTools.initialize(this.joinColumnsContainer, astRoot); - AnnotationContainerTools.initialize(this.inverseJoinColumnsContainer, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - AnnotationContainerTools.update(this.joinColumnsContainer, astRoot); - AnnotationContainerTools.update(this.inverseJoinColumnsContainer, astRoot); - } - - - // ********** AbstractBaseTableAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getNameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.JOIN_TABLE__NAME); - } - - @Override - DeclarationAnnotationElementAdapter<String> getSchemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.JOIN_TABLE__SCHEMA); - } - - @Override - DeclarationAnnotationElementAdapter<String> getCatalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.JOIN_TABLE__CATALOG); - } - - @Override - String getUniqueConstraintsElementName() { - return JPA.JOIN_TABLE__UNIQUE_CONSTRAINTS; - } - - // ********** JoinTableAnnotation implementation ********** - - // ***** join columns - public ListIterator<JoinColumnAnnotation> joinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.joinColumns); - } - - ListIterator<NestableJoinColumnAnnotation> nestableJoinColumns() { - return new CloneListIterator<NestableJoinColumnAnnotation>(this.joinColumns); - } - - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - public NestableJoinColumnAnnotation joinColumnAt(int index) { - return this.joinColumns.get(index); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public NestableJoinColumnAnnotation addJoinColumn(int index) { - return (NestableJoinColumnAnnotation) AnnotationContainerTools.addNestedAnnotation(index, this.joinColumnsContainer); - } - - NestableJoinColumnAnnotation addJoinColumnInternal() { - NestableJoinColumnAnnotation joinColumn = this.buildJoinColumn(this.joinColumns.size()); - this.joinColumns.add(joinColumn); - return joinColumn; - } - - private NestableJoinColumnAnnotation buildJoinColumn(int index) { - return new SourceJoinColumnAnnotation(this, this.member, buildJoinColumnAnnotationAdapter(index)); - } - - private IndexedDeclarationAnnotationAdapter buildJoinColumnAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(this.daa, JPA.JOIN_TABLE__JOIN_COLUMNS, index, JPA.JOIN_COLUMN); - } - - void joinColumnAdded(int index, NestableJoinColumnAnnotation joinColumn) { - this.fireItemAdded(JOIN_COLUMNS_LIST, index, joinColumn); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, this.joinColumnsContainer); - } - - NestableJoinColumnAnnotation moveJoinColumnInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.joinColumns, targetIndex, sourceIndex).get(targetIndex); - } - - void joinColumnMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void removeJoinColumn(int index) { - AnnotationContainerTools.removeNestedAnnotation(index, this.joinColumnsContainer); - } - - NestableJoinColumnAnnotation removeJoinColumnInternal(int index) { - return this.joinColumns.remove(index); - } - - void joinColumnRemoved(int index, NestableJoinColumnAnnotation joinColumn) { - this.fireItemRemoved(JOIN_COLUMNS_LIST, index, joinColumn); - } - - public JoinColumnAnnotation initializeJoinColumns() { - return this.addJoinColumnInternal(); - } - - // ***** inverse join columns - public ListIterator<JoinColumnAnnotation> inverseJoinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.inverseJoinColumns); - } - - ListIterator<NestableJoinColumnAnnotation> nestableInverseJoinColumns() { - return new CloneListIterator<NestableJoinColumnAnnotation>(this.inverseJoinColumns); - } - - public int inverseJoinColumnsSize() { - return this.inverseJoinColumns.size(); - } - - public NestableJoinColumnAnnotation inverseJoinColumnAt(int index) { - return this.inverseJoinColumns.get(index); - } - - public int indexOfInverseJoinColumn(JoinColumnAnnotation joinColumn) { - return this.inverseJoinColumns.indexOf(joinColumn); - } - - public NestableJoinColumnAnnotation addInverseJoinColumn(int index) { - return (NestableJoinColumnAnnotation) AnnotationContainerTools.addNestedAnnotation(index, this.inverseJoinColumnsContainer); - } - - NestableJoinColumnAnnotation addInverseJoinColumnInternal() { - NestableJoinColumnAnnotation joinColumn = this.buildInverseJoinColumn(this.inverseJoinColumns.size()); - this.inverseJoinColumns.add(joinColumn); - return joinColumn; - } - - private NestableJoinColumnAnnotation buildInverseJoinColumn(int index) { - return new SourceJoinColumnAnnotation(this, this.member, buildInverseJoinColumnAnnotationAdapter(index)); - } - - private IndexedDeclarationAnnotationAdapter buildInverseJoinColumnAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(this.daa, JPA.JOIN_TABLE__INVERSE_JOIN_COLUMNS, index, JPA.JOIN_COLUMN); - } - - void inverseJoinColumnAdded(int index, NestableJoinColumnAnnotation joinColumn) { - this.fireItemAdded(INVERSE_JOIN_COLUMNS_LIST, index, joinColumn); - } - - public void moveInverseJoinColumn(int targetIndex, int sourceIndex) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, this.inverseJoinColumnsContainer); - } - - NestableJoinColumnAnnotation moveInverseJoinColumnInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.inverseJoinColumns, targetIndex, sourceIndex).get(targetIndex); - } - - void inverseJoinColumnMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void removeInverseJoinColumn(int index) { - AnnotationContainerTools.removeNestedAnnotation(index, this.inverseJoinColumnsContainer); - } - - NestableJoinColumnAnnotation removeInverseJoinColumnInternal(int index) { - return this.inverseJoinColumns.remove(index); - } - - void inverseJoinColumnRemoved(int index, NestableJoinColumnAnnotation joinColumn) { - this.fireItemRemoved(INVERSE_JOIN_COLUMNS_LIST, index, joinColumn); - } - - public JoinColumnAnnotation initializeInverseJoinColumns() { - return this.addInverseJoinColumnInternal(); - } - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - JoinTableAnnotation oldJoinTable = (JoinTableAnnotation) oldAnnotation; - for (JoinColumnAnnotation oldJoinColumn : CollectionTools.iterable(oldJoinTable.joinColumns())) { - NestableJoinColumnAnnotation newJoinColumn = this.addJoinColumn(oldJoinTable.indexOfJoinColumn(oldJoinColumn)); - newJoinColumn.initializeFrom((NestableAnnotation) oldJoinColumn); - } - for (JoinColumnAnnotation oldInverseJoinColumn : CollectionTools.iterable(oldJoinTable.inverseJoinColumns())) { - NestableJoinColumnAnnotation newInverseJoinColumn = this.addInverseJoinColumn(oldJoinTable.indexOfInverseJoinColumn(oldInverseJoinColumn)); - newInverseJoinColumn.initializeFrom((NestableAnnotation) oldInverseJoinColumn); - } - } - - public void moveAnnotation(int newIndex) { - // the only place where a join table annotation is nested is in an - // association override; and that only nests a single join table, not an array - // of join tables; so #moveAnnotation(int) is never called - // TODO maybe NestableAnnotation should be split up; - // moving this method to something like IndexableAnnotation - throw new UnsupportedOperationException(); - } - - // ********** annotation containers ********** - - abstract class AbstractJoinColumnAnnotationContainer - implements AnnotationContainer<NestableJoinColumnAnnotation> - { - public String getContainerAnnotationName() { - return SourceJoinTableAnnotation.this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return SourceJoinTableAnnotation.this.getJdtAnnotation(astRoot); - } - - public String getNestableAnnotationName() { - return JoinColumnAnnotation.ANNOTATION_NAME; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - /** - * adapt the AnnotationContainer interface to the join table's join columns - */ - class JoinColumnsAnnotationContainer - extends AbstractJoinColumnAnnotationContainer - { - public String getElementName() { - return JPA.JOIN_TABLE__JOIN_COLUMNS; - } - - public ListIterator<NestableJoinColumnAnnotation> nestedAnnotations() { - return SourceJoinTableAnnotation.this.nestableJoinColumns(); - } - - public int nestedAnnotationsSize() { - return SourceJoinTableAnnotation.this.joinColumnsSize(); - } - - public NestableJoinColumnAnnotation addNestedAnnotationInternal() { - return SourceJoinTableAnnotation.this.addJoinColumnInternal(); - } - - public void nestedAnnotationAdded(int index, NestableJoinColumnAnnotation nestedAnnotation) { - SourceJoinTableAnnotation.this.joinColumnAdded(index, nestedAnnotation); - } - - public NestableJoinColumnAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return SourceJoinTableAnnotation.this.moveJoinColumnInternal(targetIndex, sourceIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - SourceJoinTableAnnotation.this.joinColumnMoved(targetIndex, sourceIndex); - } - - public NestableJoinColumnAnnotation removeNestedAnnotationInternal(int index) { - return SourceJoinTableAnnotation.this.removeJoinColumnInternal(index); - } - - public void nestedAnnotationRemoved(int index, NestableJoinColumnAnnotation nestedAnnotation) { - SourceJoinTableAnnotation.this.joinColumnRemoved(index, nestedAnnotation); - } - } - - - /** - * adapt the AnnotationContainer interface to the join table's inverse join columns - */ - class InverseJoinColumnsContainerAnnotation - extends AbstractJoinColumnAnnotationContainer - { - public String getElementName() { - return JPA.JOIN_TABLE__INVERSE_JOIN_COLUMNS; - } - - public ListIterator<NestableJoinColumnAnnotation> nestedAnnotations() { - return SourceJoinTableAnnotation.this.nestableInverseJoinColumns(); - } - - public int nestedAnnotationsSize() { - return SourceJoinTableAnnotation.this.inverseJoinColumnsSize(); - } - - public NestableJoinColumnAnnotation addNestedAnnotationInternal() { - return SourceJoinTableAnnotation.this.addInverseJoinColumnInternal(); - } - - public void nestedAnnotationAdded(int index, NestableJoinColumnAnnotation nestedAnnotation) { - SourceJoinTableAnnotation.this.inverseJoinColumnAdded(index, nestedAnnotation); - } - - public NestableJoinColumnAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return SourceJoinTableAnnotation.this.moveInverseJoinColumnInternal(targetIndex, sourceIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - SourceJoinTableAnnotation.this.inverseJoinColumnMoved(targetIndex, sourceIndex); - } - - public NestableJoinColumnAnnotation removeNestedAnnotationInternal(int index) { - return SourceJoinTableAnnotation.this.removeInverseJoinColumnInternal(index); - } - - public void nestedAnnotationRemoved(int index, NestableJoinColumnAnnotation nestedAnnotation) { - SourceJoinTableAnnotation.this.inverseJoinColumnRemoved(index, nestedAnnotation); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceLobAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceLobAnnotation.java deleted file mode 100644 index 05228b8d51..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceLobAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.LobAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; - -/** - * javax.persistence.Lob - */ -public final class SourceLobAnnotation - extends SourceAnnotation<Attribute> - implements LobAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceLobAnnotation(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceManyToManyAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceManyToManyAnnotation.java deleted file mode 100644 index 73d8ef8db2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceManyToManyAnnotation.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.ManyToMany - */ -public final class SourceManyToManyAnnotation - extends SourceRelationshipMappingAnnotation - implements ManyToManyAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> TARGET_ENTITY_ADAPTER = buildTargetEntityAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<String[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> MAPPED_BY_ADAPTER = buildMappedByAdapter(); - private final AnnotationElementAdapter<String> mappedByAdapter; - private String mappedBy; - - - public SourceManyToManyAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.mappedByAdapter = this.buildAnnotationElementAdapter(MAPPED_BY_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.mappedBy = this.buildMappedBy(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setMappedBy(this.buildMappedBy(astRoot)); - } - - - // ********** SourceRelationshipMappingAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getTargetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String> getFetchAdapter() { - return FETCH_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String[]> getCascadeAdapter() { - return CASCADE_ADAPTER; - } - - - //**************** OwnableRelationshipMappingAnnotation implementation ************** - - // ***** mapped by - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String mappedBy) { - if (this.attributeValueHasNotChanged(this.mappedBy, mappedBy)) { - return; - } - String old = this.mappedBy; - this.mappedBy = mappedBy; - this.mappedByAdapter.setValue(mappedBy); - this.firePropertyChanged(MAPPED_BY_PROPERTY, old, mappedBy); - } - - private String buildMappedBy(CompilationUnit astRoot) { - return this.mappedByAdapter.getValue(astRoot); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(MAPPED_BY_ADAPTER, astRoot); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(MAPPED_BY_ADAPTER, pos, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter() { - return buildTargetEntityAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_MANY__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String> buildMappedByAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_MANY__MAPPED_BY, false); // false = do not remove annotation when empty - } - - private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() { - return buildFetchAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_MANY__FETCH); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_MANY__CASCADE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceManyToOneAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceManyToOneAnnotation.java deleted file mode 100644 index 6883f3d1c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceManyToOneAnnotation.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.BooleanExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.ManyToOne - */ -public final class SourceManyToOneAnnotation - extends SourceRelationshipMappingAnnotation - implements ManyToOneAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> TARGET_ENTITY_ADAPTER = buildTargetEntityAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<String[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<Boolean> OPTIONAL_ADAPTER = buildOptionalAdapter(); - private final AnnotationElementAdapter<Boolean> optionalAdapter; - private Boolean optional; - - - public SourceManyToOneAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.optionalAdapter = this.buildBooleanAnnotationElementAdapter(OPTIONAL_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.optional = this.buildOptional(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setOptional(this.buildOptional(astRoot)); - } - - - // ********** SourceRelationshipMappingAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getTargetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String> getFetchAdapter() { - return FETCH_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String[]> getCascadeAdapter() { - return CASCADE_ADAPTER; - } - - - // ********** ManyToOneMappingAnnotation implementation ********** - - // ***** optional - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean optional) { - if (this.attributeValueHasNotChanged(this.optional, optional)) { - return; - } - Boolean old = this.optional; - this.optional = optional; - this.optionalAdapter.setValue(optional); - this.firePropertyChanged(OPTIONAL_PROPERTY, old, optional); - } - - private Boolean buildOptional(CompilationUnit astRoot) { - return this.optionalAdapter.getValue(astRoot); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(OPTIONAL_ADAPTER, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter() { - return buildTargetEntityAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_ONE__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() { - return buildFetchAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_ONE__FETCH); - } - - private static DeclarationAnnotationElementAdapter<Boolean> buildOptionalAdapter() { - return buildOptionalAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_ONE__OPTIONAL); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_ONE__CASCADE); - } - - private static DeclarationAnnotationElementAdapter<Boolean> buildOptionalAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(annotationAdapter, elementName, false, BooleanExpressionConverter.instance()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceMapKeyAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceMapKeyAnnotation.java deleted file mode 100644 index 34f409fe27..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceMapKeyAnnotation.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.MapKey - */ -public final class SourceMapKeyAnnotation - extends SourceAnnotation<Attribute> - implements MapKeyAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildNameAdapter(); - private final AnnotationElementAdapter<String> nameAdapter; - private String name; - - - public SourceMapKeyAnnotation(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, NAME_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** MapKeyAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(NAME_ADAPTER, astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(NAME_ADAPTER, pos, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildNameAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.MAP_KEY__NAME, false); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceMappedSuperclassAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceMappedSuperclassAnnotation.java deleted file mode 100644 index 3703e3ab2e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceMappedSuperclassAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.MappedSuperclass - */ -public final class SourceMappedSuperclassAnnotation - extends SourceAnnotation<Type> - implements MappedSuperclassAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceMappedSuperclassAnnotation(JavaResourcePersistentType parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedColumnAnnotation.java deleted file mode 100644 index 3f6048f7e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedColumnAnnotation.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.BooleanExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NumberIntegerExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Column - * javax.persistence.JoinColumn - * javax.persistence.DiscriminatorColumn - * javax.persistence.PrimaryKeyJoinColumn. - */ -abstract class SourceNamedColumnAnnotation - extends SourceAnnotation<Member> - implements NamedColumnAnnotation -{ - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - private final AnnotationElementAdapter<String> nameAdapter; - private String name; - - private final DeclarationAnnotationElementAdapter<String> columnDefinitionDeclarationAdapter; - private final AnnotationElementAdapter<String> columnDefinitionAdapter; - private String columnDefinition; - - - SourceNamedColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - SourceNamedColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.nameDeclarationAdapter = this.buildStringElementAdapter(this.getNameElementName()); - this.nameAdapter = this.buildShortCircuitElementAdapter(this.nameDeclarationAdapter); - this.columnDefinitionDeclarationAdapter = this.buildStringElementAdapter(this.getColumnDefinitionElementName()); - this.columnDefinitionAdapter = this.buildShortCircuitElementAdapter(this.columnDefinitionDeclarationAdapter); - } - - DeclarationAnnotationElementAdapter<String> buildStringElementAdapter(String elementName) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, elementName); - } - - DeclarationAnnotationElementAdapter<Boolean> buildBooleanElementAdapter(String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(this.daa, elementName, BooleanExpressionConverter.instance()); - } - - DeclarationAnnotationElementAdapter<Integer> buildIntegerElementAdapter(String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Integer>(this.daa, elementName, NumberIntegerExpressionConverter.instance()); - } - - AnnotationElementAdapter<String> buildShortCircuitElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea); - } - - AnnotationElementAdapter<Boolean> buildShortCircuitBooleanElementAdapter(DeclarationAnnotationElementAdapter<Boolean> daea) { - return new ShortCircuitAnnotationElementAdapter<Boolean>(this.member, daea); - } - - AnnotationElementAdapter<Integer> buildShortCircuitIntegerElementAdapter(DeclarationAnnotationElementAdapter<Integer> daea) { - return new ShortCircuitAnnotationElementAdapter<Integer>(this.member, daea); - } - - AnnotationElementAdapter<String> buildShortCircuitStringElementAdapter(String elementName) { - return this.buildShortCircuitElementAdapter(this.buildStringElementAdapter(elementName)); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - this.columnDefinition = this.buildColumnDefinition(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - this.setColumnDefinition(this.buildColumnDefinition(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** NamedColumn implementation ********** - - public boolean isSpecified() { - return true; - } - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.nameDeclarationAdapter, pos, astRoot); - } - - abstract String getNameElementName(); - - // ***** column definition - public String getColumnDefinition() { - return this.columnDefinition; - } - - public void setColumnDefinition(String columnDefinition) { - if (this.attributeValueHasNotChanged(this.columnDefinition, columnDefinition)) { - return; - } - String old = this.columnDefinition; - this.columnDefinition = columnDefinition; - this.columnDefinitionAdapter.setValue(columnDefinition); - this.firePropertyChanged(COLUMN_DEFINITION_PROPERTY, old, columnDefinition); - } - - private String buildColumnDefinition(CompilationUnit astRoot) { - return this.columnDefinitionAdapter.getValue(astRoot); - } - - public TextRange getColumnDefinitionTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.columnDefinitionDeclarationAdapter, astRoot); - } - - abstract String getColumnDefinitionElementName(); - - - // ********** NestableAnnotation implementation ********** - - public void initializeFrom(NestableAnnotation oldAnnotation) { - NamedColumnAnnotation oldColumn = (NamedColumnAnnotation) oldAnnotation; - this.setName(oldColumn.getName()); - this.setColumnDefinition(oldColumn.getColumnDefinition()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedNativeQueriesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedNativeQueriesAnnotation.java deleted file mode 100644 index 966e3506d3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedNativeQueriesAnnotation.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableNamedNativeQueryAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.NamedNativeQueries - */ -public final class SourceNamedNativeQueriesAnnotation - extends SourceAnnotation<Type> - implements NamedNativeQueriesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestableNamedNativeQueryAnnotation> namedNativeQueries = new Vector<NestableNamedNativeQueryAnnotation>(); - - - public SourceNamedNativeQueriesAnnotation(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - AnnotationContainerTools.initialize(this, astRoot); - } - - public void update(CompilationUnit astRoot) { - AnnotationContainerTools.update(this, astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.namedNativeQueries); - } - - - // ********** AnnotationContainer implementation ********** - - public String getContainerAnnotationName() { - return this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.NAMED_NATIVE_QUERIES__VALUE; - } - - public String getNestableAnnotationName() { - return NamedNativeQueryAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableNamedNativeQueryAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableNamedNativeQueryAnnotation>(this.namedNativeQueries); - } - - public int nestedAnnotationsSize() { - return this.namedNativeQueries.size(); - } - - public NestableNamedNativeQueryAnnotation addNestedAnnotationInternal() { - NestableNamedNativeQueryAnnotation namedNativeQuery = this.buildNamedNativeQuery(this.namedNativeQueries.size()); - this.namedNativeQueries.add(namedNativeQuery); - return namedNativeQuery; - } - - private NestableNamedNativeQueryAnnotation buildNamedNativeQuery(int index) { - return SourceNamedNativeQueryAnnotation.createNestedNamedNativeQuery(this, this.member, index, this.daa); - } - - public void nestedAnnotationAdded(int index, NestableNamedNativeQueryAnnotation nestedAnnotation) { - this.fireItemAdded(NAMED_NATIVE_QUERIES_LIST, index, nestedAnnotation); - } - - public NestableNamedNativeQueryAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex).get(targetIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); - } - - public NestableNamedNativeQueryAnnotation removeNestedAnnotationInternal(int index) { - return this.namedNativeQueries.remove(index); - } - - public void nestedAnnotationRemoved(int index, NestableNamedNativeQueryAnnotation nestedAnnotation) { - this.fireItemRemoved(NAMED_NATIVE_QUERIES_LIST, index, nestedAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java deleted file mode 100644 index 0c5cadde71..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedNativeQueryAnnotation.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableNamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableQueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.NamedNativeQuery - */ -public final class SourceNamedNativeQueryAnnotation - extends SourceBaseNamedQueryAnnotation - implements NestableNamedNativeQueryAnnotation -{ - public static final SimpleDeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final DeclarationAnnotationElementAdapter<String> resultClassDeclarationAdapter; - private final AnnotationElementAdapter<String> resultClassAdapter; - private String resultClass; - - private String fullyQualifiedResultClassName; - - private final DeclarationAnnotationElementAdapter<String> resultSetMappingDeclarationAdapter; - private final AnnotationElementAdapter<String> resultSetMappingAdapter; - private String resultSetMapping; - - - public SourceNamedNativeQueryAnnotation(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, type, daa, annotationAdapter); - this.resultClassDeclarationAdapter = this.buildResultClassAdapter(daa); - this.resultClassAdapter = this.buildAdapter(this.resultClassDeclarationAdapter); - this.resultSetMappingDeclarationAdapter = this.buildResultSetMappingAdapter(daa); - this.resultSetMappingAdapter = this.buildAdapter(this.resultSetMappingDeclarationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.resultClass = this.buildResultClass(astRoot); - this.fullyQualifiedResultClassName = this.buildFullyQualifiedResultClassName(astRoot); - this.resultSetMapping = this.buildResultSetMapping(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setResultClass(this.buildResultClass(astRoot)); - this.setFullyQualifiedResultClassName(this.buildFullyQualifiedResultClassName(astRoot)); - this.setResultSetMapping(this.buildResultSetMapping(astRoot)); - } - - - // ********** AbstractBaseNamedQueryAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.NAMED_NATIVE_QUERY__NAME; - } - - @Override - String getQueryElementName() { - return JPA.NAMED_NATIVE_QUERY__QUERY; - } - - @Override - String getHintsElementName() { - return JPA.NAMED_NATIVE_QUERY__HINTS; - } - - @Override - NestableQueryHintAnnotation buildQueryHint(int index) { - return SourceQueryHintAnnotation.createNamedNativeQueryQueryHint(this, this.member, this.daa, index); - } - - - // ********** NamedNativeQueryAnnotation implementation ********** - - // ***** result class - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String resultClass) { - if (this.attributeValueHasNotChanged(this.resultClass, resultClass)) { - return; - } - String old = this.resultClass; - this.resultClass = resultClass; - this.resultClassAdapter.setValue(resultClass); - this.firePropertyChanged(RESULT_CLASS_PROPERTY, old, resultClass); - } - - private String buildResultClass(CompilationUnit astRoot) { - return this.resultClassAdapter.getValue(astRoot); - } - - public TextRange getResultClassTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.resultClassDeclarationAdapter, astRoot); - } - - private DeclarationAnnotationElementAdapter<String> buildResultClassAdapter(DeclarationAnnotationAdapter daAdapter) { - return new ConversionDeclarationAnnotationElementAdapter<String>(daAdapter, JPA.NAMED_NATIVE_QUERY__RESULT_CLASS, SimpleTypeStringExpressionConverter.instance()); - } - - // ***** fully-qualified result class name - public String getFullyQualifiedResultClassName() { - return this.fullyQualifiedResultClassName; - } - - private void setFullyQualifiedResultClassName(String name) { - String old = this.fullyQualifiedResultClassName; - this.fullyQualifiedResultClassName = name; - this.firePropertyChanged(FULLY_QUALIFIED_RESULT_CLASS_NAME_PROPERTY, old, name); - } - - private String buildFullyQualifiedResultClassName(CompilationUnit astRoot) { - return (this.resultClass == null) ? null : JDTTools.resolveFullyQualifiedName(this.resultClassAdapter.getExpression(astRoot)); - } - - // ***** result set mapping - public String getResultSetMapping() { - return this.resultSetMapping; - } - - public void setResultSetMapping(String resultSetMapping) { - if (this.attributeValueHasNotChanged(this.resultSetMapping, resultSetMapping)) { - return; - } - String old = this.resultSetMapping; - this.resultSetMapping = resultSetMapping; - this.resultSetMappingAdapter.setValue(resultSetMapping); - this.firePropertyChanged(RESULT_SET_MAPPING_PROPERTY, old, resultSetMapping); - } - - private String buildResultSetMapping(CompilationUnit astRoot) { - return this.resultSetMappingAdapter.getValue(astRoot); - } - - public TextRange getResultSetMappingTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.resultSetMappingDeclarationAdapter, astRoot); - } - - private DeclarationAnnotationElementAdapter<String> buildResultSetMappingAdapter(DeclarationAnnotationAdapter daAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daAdapter, JPA.NAMED_NATIVE_QUERY__RESULT_SET_MAPPING); - } - - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - NamedNativeQueryAnnotation oldQuery = (NamedNativeQueryAnnotation) oldAnnotation; - this.setResultClass(oldQuery.getResultClass()); - this.setResultSetMapping(oldQuery.getResultSetMapping()); - } - - - // ********** static methods ********** - - public static SourceNamedNativeQueryAnnotation createNamedNativeQuery(JavaResourceNode parent, Type type) { - return new SourceNamedNativeQueryAnnotation(parent, type, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(type, DECLARATION_ANNOTATION_ADAPTER)); - } - - static SourceNamedNativeQueryAnnotation createNestedNamedNativeQuery(JavaResourceNode parent, Type type, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(type, idaa); - return new SourceNamedNativeQueryAnnotation(parent, type, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter namedQueriesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(namedQueriesAdapter, index, JPA.NAMED_NATIVE_QUERY); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedQueriesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedQueriesAnnotation.java deleted file mode 100644 index 25734c6cc4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedQueriesAnnotation.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableNamedQueryAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.NamedQueries - */ -public final class SourceNamedQueriesAnnotation - extends SourceAnnotation<Type> - implements NamedQueriesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestableNamedQueryAnnotation> namedQueries = new Vector<NestableNamedQueryAnnotation>(); - - - public SourceNamedQueriesAnnotation(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - AnnotationContainerTools.initialize(this, astRoot); - } - - public void update(CompilationUnit astRoot) { - AnnotationContainerTools.update(this, astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.namedQueries); - } - - - // ********** AnnotationContainer implementation ********** - - public String getContainerAnnotationName() { - return this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.NAMED_QUERIES__VALUE; - } - - public String getNestableAnnotationName() { - return NamedQueryAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableNamedQueryAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableNamedQueryAnnotation>(this.namedQueries); - } - - public int nestedAnnotationsSize() { - return this.namedQueries.size(); - } - - public NestableNamedQueryAnnotation addNestedAnnotationInternal() { - NestableNamedQueryAnnotation namedQuery = this.buildNamedQuery(this.namedQueries.size()); - this.namedQueries.add(namedQuery); - return namedQuery; - } - - private NestableNamedQueryAnnotation buildNamedQuery(int index) { - return SourceNamedQueryAnnotation.createNestedNamedQuery(this, member, index, this.daa); - } - - public void nestedAnnotationAdded(int index, NestableNamedQueryAnnotation nestedAnnotation) { - this.fireItemAdded(NAMED_QUERIES_LIST, index, nestedAnnotation); - } - - public NestableNamedQueryAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.namedQueries, targetIndex, sourceIndex).get(targetIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(NAMED_QUERIES_LIST, targetIndex, sourceIndex); - } - - public NestableNamedQueryAnnotation removeNestedAnnotationInternal(int index) { - return this.namedQueries.remove(index); - } - - public void nestedAnnotationRemoved(int index, NestableNamedQueryAnnotation nestedAnnotation) { - this.fireItemRemoved(NAMED_QUERIES_LIST, index, nestedAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedQueryAnnotation.java deleted file mode 100644 index 3408082826..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNamedQueryAnnotation.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableNamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableQueryHintAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.NamedQuery - */ -public final class SourceNamedQueryAnnotation - extends SourceBaseNamedQueryAnnotation - implements NestableNamedQueryAnnotation -{ - public static final SimpleDeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceNamedQueryAnnotation(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, type, daa, annotationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - // ********** AbstractBaseNamedQueryAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.NAMED_QUERY__NAME; - } - - @Override - String getQueryElementName() { - return JPA.NAMED_QUERY__QUERY; - } - - @Override - String getHintsElementName() { - return JPA.NAMED_QUERY__HINTS; - } - - @Override - NestableQueryHintAnnotation buildQueryHint(int index) { - return SourceQueryHintAnnotation.createNamedQueryQueryHint(this, this.member, this.daa, index); - } - - - // ********** static methods ********** - - public static SourceNamedQueryAnnotation createNamedQuery(JavaResourceNode parent, Type type) { - return new SourceNamedQueryAnnotation(parent, type, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(type, DECLARATION_ANNOTATION_ADAPTER)); - } - - static SourceNamedQueryAnnotation createNestedNamedQuery(JavaResourceNode parent, Type type, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(type, idaa); - return new SourceNamedQueryAnnotation(parent, type, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter namedQueriesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(namedQueriesAdapter, index, JPA.NAMED_QUERY); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNode.java deleted file mode 100644 index 354ba9d633..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceNode.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jpt.core.internal.resource.java.AbstractJavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; - -/** - * Source convenience methods - */ -public abstract class SourceNode - extends AbstractJavaResourceNode -{ - - public SourceNode(JavaResourceNode parent) { - super(parent); - } - - public JavaResourceCompilationUnit getJavaResourceCompilationUnit() { - return (JavaResourceCompilationUnit) this.getRoot(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOneToManyAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOneToManyAnnotation.java deleted file mode 100644 index 388c22f842..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOneToManyAnnotation.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.OneToMany - */ -public final class SourceOneToManyAnnotation - extends SourceRelationshipMappingAnnotation - implements OneToManyAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> TARGET_ENTITY_ADAPTER = buildTargetEntityAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<String[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> MAPPED_BY_ADAPTER = buildMappedByAdapter(); - private final AnnotationElementAdapter<String> mappedByAdapter; - private String mappedBy; - - - public SourceOneToManyAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.mappedByAdapter = this.buildAnnotationElementAdapter(MAPPED_BY_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.mappedBy = this.buildMappedBy(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setMappedBy(this.buildMappedBy(astRoot)); - } - - - // ********** SourceRelationshipMappingAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getTargetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String> getFetchAdapter() { - return FETCH_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String[]> getCascadeAdapter() { - return CASCADE_ADAPTER; - } - - - // ********** OwnableRelationshipMappingAnnotation implementation ********** - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String mappedBy) { - if (this.attributeValueHasNotChanged(this.mappedBy, mappedBy)) { - return; - } - String old = this.mappedBy; - this.mappedBy = mappedBy; - this.mappedByAdapter.setValue(mappedBy); - this.firePropertyChanged(MAPPED_BY_PROPERTY, old, mappedBy); - } - - private String buildMappedBy(CompilationUnit astRoot) { - return this.mappedByAdapter.getValue(astRoot); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return getElementTextRange(MAPPED_BY_ADAPTER, astRoot); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(MAPPED_BY_ADAPTER, pos, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter() { - return buildTargetEntityAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_MANY__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String> buildMappedByAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_MANY__MAPPED_BY, false); // false = do not remove annotation when empty - } - - private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() { - return buildFetchAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_MANY__FETCH); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_MANY__CASCADE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOneToOneAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOneToOneAnnotation.java deleted file mode 100644 index 0beac3af1b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOneToOneAnnotation.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.BooleanExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.OneToOne - */ -public final class SourceOneToOneAnnotation - extends SourceRelationshipMappingAnnotation - implements OneToOneAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - static final DeclarationAnnotationElementAdapter<String> TARGET_ENTITY_ADAPTER = buildTargetEntityAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<String[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<Boolean> OPTIONAL_ADAPTER = buildOptionalAdapter(); - private final AnnotationElementAdapter<Boolean> optionalAdapter; - private Boolean optional; - - private static final DeclarationAnnotationElementAdapter<String> MAPPED_BY_ADAPTER = buildMappedByAdapter(); - private final AnnotationElementAdapter<String> mappedByAdapter; - private String mappedBy; - - - public SourceOneToOneAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.mappedByAdapter = this.buildAnnotationElementAdapter(MAPPED_BY_ADAPTER); - this.optionalAdapter = this.buildBooleanAnnotationElementAdapter(OPTIONAL_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.mappedBy = this.buildMappedBy(astRoot); - this.optional = this.buildOptional(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setMappedBy(this.buildMappedBy(astRoot)); - this.setOptional(this.buildOptional(astRoot)); - } - - - // ********** SourceRelationshipMappingAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getTargetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String> getFetchAdapter() { - return FETCH_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String[]> getCascadeAdapter() { - return CASCADE_ADAPTER; - } - - - // ********** OneToOneAnnotation implementation ********** - - // ***** mapped by - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String mappedBy) { - if (this.attributeValueHasNotChanged(this.mappedBy, mappedBy)) { - return; - } - String old = this.mappedBy; - this.mappedBy = mappedBy; - this.mappedByAdapter.setValue(mappedBy); - this.firePropertyChanged(MAPPED_BY_PROPERTY, old, mappedBy); - } - - private String buildMappedBy(CompilationUnit astRoot) { - return this.mappedByAdapter.getValue(astRoot); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(MAPPED_BY_ADAPTER, astRoot); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(MAPPED_BY_ADAPTER, pos, astRoot); - } - - // ***** optional - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean optional) { - if (this.attributeValueHasNotChanged(this.optional, optional)) { - return; - } - Boolean old = this.optional; - this.optional = optional; - this.optionalAdapter.setValue(optional); - this.firePropertyChanged(OPTIONAL_PROPERTY, old, optional); - } - - private Boolean buildOptional(CompilationUnit astRoot) { - return this.optionalAdapter.getValue(astRoot); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(OPTIONAL_ADAPTER, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter() { - return buildTargetEntityAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String> buildMappedByAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__MAPPED_BY, false); // false = do not remove annotation when empty - } - - private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() { - return buildFetchAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__FETCH); - } - - private static DeclarationAnnotationElementAdapter<Boolean> buildOptionalAdapter() { - return buildOptionalAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__OPTIONAL); - } - - private static DeclarationAnnotationElementAdapter<Boolean> buildOptionalAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(annotationAdapter, elementName, false, BooleanExpressionConverter.instance()); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__CASCADE); - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOrderByAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOrderByAnnotation.java deleted file mode 100644 index 6aeb27ca59..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOrderByAnnotation.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.OrderBy - */ -public final class SourceOrderByAnnotation - extends SourceAnnotation<Attribute> - implements OrderByAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); - private final AnnotationElementAdapter<String> valueAdapter; - private String value; - - - public SourceOrderByAnnotation(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, VALUE_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.buildValue(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.buildValue(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** OrderByAnnotation implementation ********** - - public String getValue() { - return this.value; - } - - public void setValue(String value) { - if (this.attributeValueHasNotChanged(this.value, value)) { - return; - } - String old = this.value; - this.value = value; - this.valueAdapter.setValue(value); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - private String buildValue(CompilationUnit astRoot) { - return this.valueAdapter.getValue(astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.ORDER_BY__VALUE, false); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOverrideAnnotation.java deleted file mode 100644 index 8d0758b647..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceOverrideAnnotation.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OverrideAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * Common behavior for - * javax.persistence.AttributeOverride - * javax.persistence.AssociationOverride - */ -abstract class SourceOverrideAnnotation - extends SourceAnnotation<Member> - implements OverrideAnnotation -{ - final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - final AnnotationElementAdapter<String> nameAdapter; - String name; - - - // ********** construction/initialization ********** - - SourceOverrideAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.nameDeclarationAdapter = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, this.getNameElementName(), false); // false = do not remove annotation when empty - this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(this.member, this.nameDeclarationAdapter); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** OverrideAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(OverrideAnnotation.NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.nameDeclarationAdapter, pos, astRoot); - } - - protected abstract String getNameElementName(); - - - // ********** NestableAnnotation implementation ********** - - void initializeFrom(NestableAnnotation oldAnnotation) { - OverrideAnnotation oldOverride = (OverrideAnnotation) oldAnnotation; - this.setName(oldOverride.getName()); - } - - /** - * convenience implementation of method from NestableAnnotation interface - * for subclasses - */ - public void moveAnnotation(int index) { - this.getIndexedAnnotationAdapter().moveAnnotation(index); - } - - private IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java deleted file mode 100644 index c2d79684ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java +++ /dev/null @@ -1,388 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jpt.core.internal.utility.jdt.JDTFieldAttribute; -import org.eclipse.jpt.core.internal.utility.jdt.JDTMethodAttribute; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.MethodAttribute; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.MethodSignature; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * Java source persistent attribute (field or property) - */ -final class SourcePersistentAttribute - extends SourcePersistentMember<Attribute> - implements JavaResourcePersistentAttribute -{ - private int modifiers; - - private String typeName; - - private boolean typeIsInterface; - - private boolean typeIsEnum; - - private final Vector<String> typeSuperclassNames = new Vector<String>(); - - private final Vector<String> typeInterfaceNames = new Vector<String>(); - - private final Vector<String> typeTypeArgumentNames = new Vector<String>(); - - - /** - * construct field attribute - */ - static JavaResourcePersistentAttribute newInstance( - JavaResourcePersistentType parent, - Type declaringType, - String name, - int occurrence, - JavaResourceCompilationUnit javaResourceCompilationUnit, - CompilationUnit astRoot) { - Attribute attribute = new JDTFieldAttribute( - declaringType, - name, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentAttribute jrpa = new SourcePersistentAttribute(parent, attribute); - jrpa.initialize(astRoot); - return jrpa; - } - - /** - * construct property attribute - */ - static JavaResourcePersistentAttribute newInstance( - JavaResourcePersistentType parent, - Type declaringType, - MethodSignature signature, - int occurrence, - JavaResourceCompilationUnit javaResourceCompilationUnit, - CompilationUnit astRoot) { - Attribute attribute = JDTMethodAttribute.newInstance( - declaringType, - signature, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentAttribute jrpa = new SourcePersistentAttribute(parent, attribute); - jrpa.initialize(astRoot); - return jrpa; - } - - private SourcePersistentAttribute(JavaResourcePersistentType parent, Attribute attribute){ - super(parent, attribute); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.modifiers = this.buildModifiers(astRoot); - this.typeName = this.buildTypeName(astRoot); - this.typeIsInterface = this.buildTypeIsInterface(astRoot); - this.typeIsEnum = this.buildTypeIsEnum(astRoot); - this.typeSuperclassNames.addAll(this.buildTypeSuperclassNames(astRoot)); - this.typeInterfaceNames.addAll(this.buildTypeInterfaceNames(astRoot)); - this.typeTypeArgumentNames.addAll(this.buildTypeTypeArgumentNames(astRoot)); - } - - - // ******** overrides ******** - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - this.setTypeName(this.buildTypeName(astRoot)); - this.setTypeSuperclassNames(this.buildTypeSuperclassNames(astRoot)); - this.setTypeInterfaceNames(this.buildTypeInterfaceNames(astRoot)); - this.setTypeTypeArgumentNames(this.buildTypeTypeArgumentNames(astRoot)); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setModifiers(this.buildModifiers(astRoot)); - this.setTypeName(this.buildTypeName(astRoot)); - this.setTypeIsInterface(this.buildTypeIsInterface(astRoot)); - this.setTypeIsEnum(this.buildTypeIsEnum(astRoot)); - this.setTypeSuperclassNames(this.buildTypeSuperclassNames(astRoot)); - this.setTypeInterfaceNames(this.buildTypeInterfaceNames(astRoot)); - this.setTypeTypeArgumentNames(this.buildTypeTypeArgumentNames(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ******** AbstractJavaResourcePersistentMember implementation ******** - - @Override - Iterator<String> validAnnotationNames() { - return this.getAnnotationProvider().attributeAnnotationNames(); - } - - @Override - Annotation buildAnnotation(String annotationName) { - return this.getAnnotationProvider(). - buildAttributeAnnotation(this, this.member, annotationName); - } - - Annotation buildNullAnnotation_(String annotationName) { - return this.getAnnotationProvider(). - buildNullAttributeAnnotation(this, annotationName); - } - - public boolean isFor(MethodSignature signature, int occurrence) { - return ((MethodAttribute) this.member).matches(signature, occurrence); - } - - - // ******** JavaResourcePersistentAttribute implementation ******** - - public String getName() { - return this.member.getAttributeName(); - } - - @Override - public Annotation buildNullAnnotation(String annotationName) { - return (annotationName == null) ? null : this.buildNullAnnotation_(annotationName); - } - - public boolean isField() { - return this.member.isField(); - } - - public boolean isProperty() { - return ! this.isField(); - } - - public AccessType getSpecifiedAccess() { - Access2_0Annotation accessAnnotation = - (Access2_0Annotation) getAnnotation(Access2_0Annotation.ANNOTATION_NAME); - return (accessAnnotation == null) ? null : accessAnnotation.getValue(); - } - - public boolean typeIsSubTypeOf(String tn) { - if (this.typeName == null) { - return false; - } - return this.typeName.equals(tn) - || this.typeInterfaceNames.contains(tn) - || this.typeSuperclassNames.contains(tn); - } - - public boolean typeIsVariablePrimitive() { - return (this.typeName != null) && ClassTools.classNamedIsVariablePrimitive(this.typeName); - } - - private ITypeBinding getTypeBinding(CompilationUnit astRoot) { - return this.member.getTypeBinding(astRoot); - } - - - // ***** modifiers - public int getModifiers() { - return this.modifiers; - } - - private void setModifiers(int modifiers) { - int old = this.modifiers; - this.modifiers = modifiers; - this.firePropertyChanged(MODIFIERS_PROPERTY, old, modifiers); - } - - /** - * zero seems like a reasonable default... - */ - private int buildModifiers(CompilationUnit astRoot) { - IBinding binding = this.member.getBinding(astRoot); - return (binding == null) ? 0 : binding.getModifiers(); - } - - // ***** type name - public String getTypeName() { - return this.typeName; - } - - private void setTypeName(String typeName) { - String old = this.typeName; - this.typeName = typeName; - this.firePropertyChanged(TYPE_NAME_PROPERTY, old, typeName); - } - - /** - * this can be an array (e.g. "java.lang.String[]"); - * but no generic type arguments - */ - private String buildTypeName(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getTypeBinding(astRoot); - return (typeBinding == null) ? null : typeBinding.getTypeDeclaration().getQualifiedName(); - } - - // ***** type is interface - public boolean typeIsInterface() { - return this.typeIsInterface; - } - - private void setTypeIsInterface(boolean typeIsInterface) { - boolean old = this.typeIsInterface; - this.typeIsInterface = typeIsInterface; - this.firePropertyChanged(TYPE_IS_INTERFACE_PROPERTY, old, typeIsInterface); - } - - private boolean buildTypeIsInterface(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getTypeBinding(astRoot); - return (typeBinding != null) && ( ! typeBinding.isArray()) && typeBinding.isInterface(); - } - - // ***** type is enum - public boolean typeIsEnum() { - return this.typeIsEnum; - } - - private void setTypeIsEnum(boolean typeIsEnum) { - boolean old = this.typeIsEnum; - this.typeIsEnum = typeIsEnum; - this.firePropertyChanged(TYPE_IS_ENUM_PROPERTY, old, typeIsEnum); - } - - private boolean buildTypeIsEnum(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getTypeBinding(astRoot); - return (typeBinding != null) && ( ! typeBinding.isArray()) && typeBinding.isEnum(); - } - - // ***** type superclass hierarchy - public ListIterator<String> typeSuperclassNames() { - return new CloneListIterator<String>(this.typeSuperclassNames); - } - - private void setTypeSuperclassNames(List<String> typeSuperclassNames) { - this.synchronizeList(typeSuperclassNames, this.typeSuperclassNames, TYPE_SUPERCLASS_NAMES_LIST); - } - - private List<String> buildTypeSuperclassNames(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getTypeBinding(astRoot); - if (typeBinding == null) { - return Collections.emptyList(); - } - ArrayList<String> names = new ArrayList<String>(); - typeBinding = typeBinding.getSuperclass(); - while (typeBinding != null) { - names.add(typeBinding.getQualifiedName()); - typeBinding = typeBinding.getSuperclass(); - } - return names; - } - - // ***** type interface hierarchy - public Iterator<String> typeInterfaceNames() { - return new CloneIterator<String>(this.typeInterfaceNames); - } - -// private boolean typeInterfaceNamesContains(String interfaceName) { -// return this.typeInterfaceNames.contains(interfaceName); -// } -// - private void setTypeInterfaceNames(Collection<String> typeInterfaceNames) { - this.synchronizeCollection(typeInterfaceNames, this.typeInterfaceNames, TYPE_INTERFACE_NAMES_COLLECTION); - } - - private Collection<String> buildTypeInterfaceNames(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getTypeBinding(astRoot); - if (typeBinding == null) { - return Collections.emptySet(); - } - HashSet<String> names = new HashSet<String>(); - while (typeBinding != null) { - this.addInterfaceNamesTo(typeBinding, names); - typeBinding = typeBinding.getSuperclass(); - } - return names; - } - - private void addInterfaceNamesTo(ITypeBinding typeBinding, HashSet<String> names) { - for (ITypeBinding interfaceBinding : typeBinding.getInterfaces()) { - names.add(interfaceBinding.getQualifiedName()); - this.addInterfaceNamesTo(interfaceBinding, names); // recurse - } - } - - // ***** type type argument names - public ListIterator<String> typeTypeArgumentNames() { - return new CloneListIterator<String>(this.typeTypeArgumentNames); - } - - public int typeTypeArgumentNamesSize() { - return this.typeTypeArgumentNames.size(); - } - - public String getTypeTypeArgumentName(int index) { - return this.typeTypeArgumentNames.get(index); - } - - private void setTypeTypeArgumentNames(List<String> typeTypeArgumentNames) { - this.synchronizeList(typeTypeArgumentNames, this.typeTypeArgumentNames, TYPE_TYPE_ARGUMENT_NAMES_LIST); - } - - /** - * these types can be arrays (e.g. "java.lang.String[]"); - * but they won't have any further nested generic type arguments - * (e.g. "java.util.Collection<java.lang.String>") - */ - private List<String> buildTypeTypeArgumentNames(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getTypeBinding(astRoot); - if (typeBinding == null) { - return Collections.emptyList(); - } - - ITypeBinding[] typeArguments = typeBinding.getTypeArguments(); - if (typeArguments.length == 0) { - return Collections.emptyList(); - } - - ArrayList<String> names = new ArrayList<String>(typeArguments.length); - for (ITypeBinding typeArgument : typeArguments) { - if (typeArgument == null) { - names.add(null); - } else { - names.add(typeArgument.getTypeDeclaration().getQualifiedName()); - } - } - return names; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java deleted file mode 100644 index a0ea958697..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java +++ /dev/null @@ -1,549 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ASTVisitor; -import org.eclipse.jdt.core.dom.BodyDeclaration; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.internal.utility.jdt.ASTNodeTextRange; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; - -/** - * Java source persistent member (annotations, "persistable") - */ -abstract class SourcePersistentMember<E extends Member> - extends SourceNode - implements JavaResourcePersistentMember -{ - final E member; - - /** - * annotations; no duplicates (java compiler has an error for duplicates) - */ - final Vector<Annotation> annotations = new Vector<Annotation>(); - - boolean persistable; - - - // ********** construction/initialization ********** - - SourcePersistentMember(JavaResourceNode parent, E member) { - super(parent); - this.member = member; - } - - public void initialize(CompilationUnit astRoot) { - this.member.getBodyDeclaration(astRoot).accept(this.buildInitialAnnotationVisitor(astRoot)); - this.persistable = this.buildPersistable(astRoot); - } - - private ASTVisitor buildInitialAnnotationVisitor(CompilationUnit astRoot) { - return new InitialAnnotationVisitor(astRoot, this.member.getBodyDeclaration(astRoot)); - } - - /** - * called from InitialAnnotationVisitor - */ - void addInitialAnnotation(org.eclipse.jdt.core.dom.Annotation node, CompilationUnit astRoot) { - String jdtAnnotationName = JDTTools.resolveAnnotation(node); - if (jdtAnnotationName == null) { - return; - } - if (this.annotationIsValid(jdtAnnotationName)) { - if (this.selectAnnotationNamed(this.annotations, jdtAnnotationName) == null) { // ignore duplicates - Annotation annotation = this.buildAnnotation(jdtAnnotationName); - annotation.initialize(astRoot); - this.annotations.add(annotation); - } - } - } - - - // ********** annotations ********** - - public Iterator<Annotation> annotations() { - return this.getAnnotations().iterator(); - } - - private Iterable<Annotation> getAnnotations() { - return new LiveCloneIterable<Annotation>(this.annotations); - } - - public int annotationsSize() { - return this.annotations.size(); - } - - public Annotation getAnnotation(String annotationName) { - return this.selectAnnotationNamed(this.getAnnotations(), annotationName); - } - - public Annotation getNonNullAnnotation(String annotationName) { - Annotation annotation = this.getAnnotation(annotationName); - return (annotation != null) ? annotation : this.buildNullAnnotation(annotationName); - } - - public Iterator<NestableAnnotation> annotations( - String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = - this.getContainerAnnotation(containerAnnotationName); - if (containerAnnotation != null) { - return containerAnnotation.nestedAnnotations(); - } - NestableAnnotation nestableAnnotation = - getNestableAnnotation(nestableAnnotationName); - if (nestableAnnotation != null) { - return new SingleElementIterator<NestableAnnotation>(nestableAnnotation); - } - return EmptyIterator.instance(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private ContainerAnnotation<NestableAnnotation> getContainerAnnotation(String annotationName) { - return (ContainerAnnotation<NestableAnnotation>) getAnnotation(annotationName); - } - - private NestableAnnotation getNestableAnnotation(String annotationName) { - return (NestableAnnotation) this.getAnnotation(annotationName); - } - - public Annotation addAnnotation(String annotationName) { - Annotation annotation = this.buildAnnotation(annotationName); - this.annotations.add(annotation); - annotation.newAnnotation(); - this.fireItemAdded(ANNOTATIONS_COLLECTION, annotation); - return annotation; - } - - public Annotation addAnnotation(String annotationName, AnnotationInitializer annotationInitializer) { - Annotation annotation = this.buildAnnotation(annotationName); - this.annotations.add(annotation); - annotation.newAnnotation(); - Annotation nestedAnnotation = annotationInitializer.initializeAnnotation(annotation); - nestedAnnotation.newAnnotation(); - this.fireItemAdded(ANNOTATIONS_COLLECTION, annotation); - return nestedAnnotation; - } - - /** - * 1. check for a container annotation; - * if it is present, add a nested annotation to it - * 2. check for a stand-alone nested annotation; - * if it is missing, add a stand-alone nested annotation - * 3. if there is an existing stand-alone nested annotation, - * add a container annotation and move the stand-alone nested annotation to it - * and add a new nested annotation to it also - */ - public NestableAnnotation addAnnotation( - int index, String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = - getContainerAnnotation(containerAnnotationName); - if (containerAnnotation != null) { - // ignore any stand-alone nestable annotations and just add to the container annotation - return AnnotationContainerTools.addNestedAnnotation(index, containerAnnotation); - } - NestableAnnotation standAloneAnnotation = - getNestableAnnotation(nestableAnnotationName); - if (standAloneAnnotation == null) { - // add a stand-alone nestable annotation since neither the nestable nor the container exist - return (NestableAnnotation) this.addAnnotation(nestableAnnotationName); - } - // move the stand-alone nestable annotation to a container and add another nestable - return this.addSecondNestedAnnotation(index, containerAnnotationName, standAloneAnnotation); - } - - /** - * "move" the existing nestable annotation to a new container annotation and - * add a new nestable annotation at the specified index (which should be 0 or 1) - * - * NB: we make all the necessary changes to the resource model and the - * Java source code *before* we fire any events; so that everything is in - * place when the context model gets an "update" and looks at the resource - * model to determine what has changed - */ - private NestableAnnotation addSecondNestedAnnotation( - int index, String containerAnnotationName, NestableAnnotation standAloneAnnotation) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = - buildContainerAnnotation(containerAnnotationName); - this.annotations.add(containerAnnotation); - containerAnnotation.newAnnotation(); - - NestableAnnotation nestedAnnotation0 = containerAnnotation.addNestedAnnotationInternal(); - nestedAnnotation0.newAnnotation(); - NestableAnnotation nestedAnnotation1 = containerAnnotation.addNestedAnnotationInternal(); - nestedAnnotation1.newAnnotation(); - this.removeAnnotation(standAloneAnnotation); - this.fireItemAdded(ANNOTATIONS_COLLECTION, containerAnnotation); - - if (index == 0) { - // adding new annotation at 0, so stand-alone is "copied" to slot 1 - nestedAnnotation1.initializeFrom(standAloneAnnotation); - } else { - // adding new annotation at 1, so stand-alone is "copied" to slot 0 - nestedAnnotation0.initializeFrom(standAloneAnnotation); - } - - return (index == 0) ? nestedAnnotation0 : nestedAnnotation1; - } - - public void moveAnnotation( - int targetIndex, int sourceIndex, String containerAnnotationName) { - moveAnnotation(targetIndex, sourceIndex, getContainerAnnotation(containerAnnotationName)); - } - - private void moveAnnotation( - int targetIndex, int sourceIndex, - ContainerAnnotation<NestableAnnotation> containerAnnotation) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, containerAnnotation); - } - - public void removeAnnotation(String annotationName) { - Annotation annotation = getAnnotation(annotationName); - if (annotation != null) { - this.removeAnnotation(annotation); - } - } - - private void removeAnnotation(Annotation annotation) { - this.annotations.remove(annotation); - annotation.removeAnnotation(); - this.fireItemRemoved(ANNOTATIONS_COLLECTION, annotation); - } - - public void removeAnnotation( - int index, String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = - getContainerAnnotation(containerAnnotationName); - if (containerAnnotation == null) { // assume the index is 0 - removeAnnotation(getAnnotation(nestableAnnotationName)); - } - else { - removeAnnotation(index, containerAnnotation); - } - } - - /** - * after we remove the nested annotation, check to see whether we need to - * either remove the container (if it is empty) or convert the last nested - * annotation to a stand-alone annotation - */ - private void removeAnnotation( - int index, ContainerAnnotation<NestableAnnotation> containerAnnotation) { - AnnotationContainerTools.removeNestedAnnotation(index, containerAnnotation); - switch (containerAnnotation.nestedAnnotationsSize()) { - case 0: - this.removeAnnotation(containerAnnotation); - break; - case 1: - this.convertLastNestedAnnotation(containerAnnotation); - break; - default: - break; - } - } - - /** - * convert the last nested annotation in the container to a stand-alone - * annotation - * - * NB: we make all the necessary changes to the resource model and the - * Java source code *before* we fire any events; so that everything is in - * place when the context model gets an "update" and looks at the resource - * model to determine what has changed - */ - private void convertLastNestedAnnotation( - ContainerAnnotation<NestableAnnotation> containerAnnotation) { - NestableAnnotation lastNestedAnnotation = containerAnnotation.nestedAnnotations().next(); - annotations.remove(containerAnnotation); - containerAnnotation.removeAnnotation(); - - NestableAnnotation standAloneAnnotation = - buildNestableAnnotation(lastNestedAnnotation.getAnnotationName()); - this.annotations.add(standAloneAnnotation); - standAloneAnnotation.newAnnotation(); - this.fireItemRemoved(ANNOTATIONS_COLLECTION, containerAnnotation); - this.fireItemAdded(ANNOTATIONS_COLLECTION, standAloneAnnotation); - standAloneAnnotation.initializeFrom(lastNestedAnnotation); - } - - public Annotation setPrimaryAnnotation( - String primaryAnnotationName, String[] supportingAnnotationNames) { - Annotation newPrimaryAnnotation = null; - String[] annotationNamesToKeep = supportingAnnotationNames; - if (primaryAnnotationName != null) { - annotationNamesToKeep = ArrayTools.add(supportingAnnotationNames, primaryAnnotationName); - } - for (Annotation existingAnnotation : getAnnotations()) { - if (! ArrayTools.contains(annotationNamesToKeep, existingAnnotation.getAnnotationName())) { - this.annotations.remove(existingAnnotation); - existingAnnotation.removeAnnotation(); - } - } - if (primaryAnnotationName != null && getAnnotation(primaryAnnotationName) == null) { - newPrimaryAnnotation = buildAnnotation(primaryAnnotationName); - this.annotations.add(newPrimaryAnnotation); - newPrimaryAnnotation.newAnnotation(); - } - // fire collection change event after all annotation changes are done - fireCollectionChanged(ANNOTATIONS_COLLECTION, Collections.unmodifiableCollection(this.annotations)); - return newPrimaryAnnotation; - } - - private boolean annotationIsValid(String annotationName) { - return CollectionTools.contains(this.validAnnotationNames(), annotationName); - } - - abstract Iterator<String> validAnnotationNames(); - - abstract Annotation buildAnnotation(String mappingAnnotationName); - - abstract Annotation buildNullAnnotation(String annotationName); - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private ContainerAnnotation<NestableAnnotation> buildContainerAnnotation(String annotationName) { - return (ContainerAnnotation<NestableAnnotation>) buildAnnotation(annotationName); - } - - @SuppressWarnings("unchecked") - private NestableAnnotation buildNestableAnnotation(String annotationName) { - return (NestableAnnotation) buildAnnotation(annotationName); - } - - - // ********** simple state ********** - - public boolean isPersistable() { - return this.persistable; - } - - private void setPersistable(boolean persistable) { - boolean old = this.persistable; - this.persistable = persistable; - this.firePropertyChanged(PERSISTABLE_PROPERTY, old, persistable); - } - - private boolean buildPersistable(CompilationUnit astRoot) { - return this.member.isPersistable(astRoot); - } - - public boolean isAnnotated() { - return ! this.annotations.isEmpty(); - } - - public boolean isFor(String memberName, int occurrence) { - return this.member.matches(memberName, occurrence); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return this.fullTextRange(astRoot); - } - - private TextRange fullTextRange(CompilationUnit astRoot) { - return this.buildTextRange(this.member.getBodyDeclaration(astRoot)); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.member.getNameTextRange(astRoot); - } - - - // ********** update ********** - - public void update(CompilationUnit astRoot) { - this.updateAnnotations(astRoot); - this.setPersistable(this.buildPersistable(astRoot)); - } - - private void updateAnnotations(CompilationUnit astRoot) { - HashSet<Annotation> annotationsToRemove = - new HashSet<Annotation>(this.annotations); - - this.member.getBodyDeclaration(astRoot).accept( - this.buildUpdateAnnotationVisitor(astRoot, annotationsToRemove)); - - for (Annotation annotation : annotationsToRemove) { - this.removeItemFromCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); - } - } - - private ASTVisitor buildUpdateAnnotationVisitor( - CompilationUnit astRoot, Set<Annotation> annotationsToRemove) { - return new UpdateAnnotationVisitor( - astRoot, this.member.getBodyDeclaration(astRoot), annotationsToRemove); - } - - void addOrUpdateAnnotation( - org.eclipse.jdt.core.dom.Annotation node, CompilationUnit astRoot, - Set<Annotation> annotationsToRemove) { - String jdtAnnotationName = JDTTools.resolveAnnotation(node); - if (jdtAnnotationName == null) { - return; - } - if (this.annotationIsValid(jdtAnnotationName)) { - this.addOrUpdateAnnotation(jdtAnnotationName, astRoot, annotationsToRemove); - return; - } - } - - private void addOrUpdateAnnotation( - String jdtAnnotationName, CompilationUnit astRoot, - Set<Annotation> annotationsToRemove) { - Annotation annotation = this.selectAnnotationNamed(annotationsToRemove, jdtAnnotationName); - if (annotation != null) { - annotation.update(astRoot); - annotationsToRemove.remove(annotation); - } - else { - annotation = this.buildAnnotation(jdtAnnotationName); - annotation.initialize(astRoot); - this.addItemToCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); - } - } - - - // ********** miscellaneous ********** - - public void resolveTypes(CompilationUnit astRoot) { - this.setPersistable(this.buildPersistable(astRoot)); - } - - private Annotation selectAnnotationNamed(Iterable<Annotation> annotations, String annotationName) { - for (Annotation annotation : annotations) { - if (annotation.getAnnotationName().equals(annotationName)) { - return annotation; - } - } - return null; - } - - private TextRange buildTextRange(ASTNode astNode) { - return (astNode == null) ? null : new ASTNodeTextRange(astNode); - } - - /** - * convenience method - */ - <T extends JavaResourcePersistentMember> Iterator<T> persistableMembers(Iterator<T> members) { - return new FilteringIterator<T, T>(members) { - @Override - protected boolean accept(T m) { - return m.isPersistable(); - } - }; - } - - - // ********** AST visitors ********** - - /** - * annotation visitor - */ - protected static abstract class AnnotationVisitor - extends ASTVisitor - { - protected final CompilationUnit astRoot; - protected final BodyDeclaration bodyDeclaration; - - protected AnnotationVisitor(CompilationUnit astRoot, BodyDeclaration bodyDeclaration) { - super(); - this.astRoot = astRoot; - this.bodyDeclaration = bodyDeclaration; - } - - @Override - public boolean visit(SingleMemberAnnotation node) { - return visit_(node); - } - - @Override - public boolean visit(NormalAnnotation node) { - return visit_(node); - } - - @Override - public boolean visit(MarkerAnnotation node) { - return visit_(node); - } - - protected boolean visit_(org.eclipse.jdt.core.dom.Annotation node) { - // ignore annotations for child members, only this member - if (node.getParent() == this.bodyDeclaration) { - this.visitChildAnnotation(node); - } - return false; - } - - protected abstract void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node); - } - - - /** - * initial annotation visitor - */ - protected class InitialAnnotationVisitor - extends AnnotationVisitor - { - protected InitialAnnotationVisitor(CompilationUnit astRoot, BodyDeclaration bodyDeclaration) { - super(astRoot, bodyDeclaration); - } - - @Override - protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - SourcePersistentMember.this.addInitialAnnotation(node, this.astRoot); - } - } - - - /** - * update annotation visitor - */ - protected class UpdateAnnotationVisitor - extends AnnotationVisitor - { - protected final Set<Annotation> annotationsToRemove; - - protected UpdateAnnotationVisitor( - CompilationUnit astRoot, BodyDeclaration bodyDeclaration, - Set<Annotation> annotationsToRemove) { - super(astRoot, bodyDeclaration); - this.annotationsToRemove = annotationsToRemove; - } - - @Override - protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - SourcePersistentMember.this.addOrUpdateAnnotation( - node, this.astRoot, this.annotationsToRemove); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java deleted file mode 100644 index 67c306b809..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java +++ /dev/null @@ -1,606 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.FieldDeclaration; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jdt.core.dom.VariableDeclarationFragment; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.JDTType; -import org.eclipse.jpt.core.internal.utility.jdt.JPTTools; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.MethodSignature; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Counter; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TreeIterator; - -/** - * Java source persistent type - */ -final class SourcePersistentType - extends SourcePersistentMember<Type> - implements JavaResourcePersistentType -{ - private String name; - - private String qualifiedName; - - private String superclassQualifiedName; - - private boolean abstract_; // 'abstract' is a reserved word - - private final Vector<JavaResourcePersistentType> types; - - private final Vector<JavaResourcePersistentAttribute> fields; - - private final Vector<JavaResourcePersistentAttribute> methods; - - private AccessType access; - - - // ********** construction/initialization ********** - - /** - * build top-level persistent type - */ - static JavaResourcePersistentType newInstance( - JavaResourceCompilationUnit javaResourceCompilationUnit, - TypeDeclaration typeDeclaration, - CompilationUnit astRoot) { - Type type = new JDTType( - typeDeclaration, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentType jrpt = new SourcePersistentType(javaResourceCompilationUnit, type); - jrpt.initialize(astRoot); - return jrpt; - } - - /** - * build nested persistent type - */ - private static JavaResourcePersistentType newInstance( - JavaResourceCompilationUnit javaResourceCompilationUnit, - Type declaringType, - TypeDeclaration typeDeclaration, - int occurrence, - CompilationUnit astRoot) { - Type type = new JDTType( - declaringType, - typeDeclaration, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentType jrpt = new SourcePersistentType(javaResourceCompilationUnit, type); - jrpt.initialize(astRoot); - return jrpt; - } - - private SourcePersistentType(JavaResourceCompilationUnit javaResourceCompilationUnit, Type type) { - super(javaResourceCompilationUnit, type); - this.types = new Vector<JavaResourcePersistentType>(); - this.fields = new Vector<JavaResourcePersistentAttribute>(); - this.methods = new Vector<JavaResourcePersistentAttribute>(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.name = this.buildName(astRoot); - this.qualifiedName = this.buildQualifiedName(astRoot); - this.superclassQualifiedName = this.buildSuperclassQualifiedName(astRoot); - this.abstract_ = this.buildAbstract(astRoot); - this.initializeTypes(astRoot); - this.initializeFields(astRoot); - this.initializeMethods(astRoot); - // need to wait until everything is built to calculate 'access' - this.access = this.buildAccess(); - } - - private void initializeTypes(CompilationUnit astRoot) { - TypeDeclaration[] typeDeclarations = this.member.getTypes(astRoot); - CounterMap counters = new CounterMap(typeDeclarations.length); - for (TypeDeclaration td : typeDeclarations) { - String tdName = td.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - this.types.add(this.buildType(td, occurrence, astRoot)); - } - } - - private void initializeFields(CompilationUnit astRoot) { - FieldDeclaration[] fieldDeclarations = this.member.getFields(astRoot); - CounterMap counters = new CounterMap(fieldDeclarations.length); - for (FieldDeclaration fieldDeclaration : fieldDeclarations) { - for (VariableDeclarationFragment fragment : fragments(fieldDeclaration)) { - String fieldName = fragment.getName().getFullyQualifiedName(); - int occurrence = counters.increment(fieldName); - this.fields.add(this.buildField(fieldName, occurrence, astRoot)); - } - } - } - - private void initializeMethods(CompilationUnit astRoot) { - MethodDeclaration[] methodDeclarations = this.member.getMethods(astRoot); - CounterMap counters = new CounterMap(methodDeclarations.length); - for (MethodDeclaration methodDeclaration : methodDeclarations) { - MethodSignature signature = JDTTools.buildMethodSignature(methodDeclaration); - int occurrence = counters.increment(signature); - this.methods.add(this.buildMethod(signature, occurrence, astRoot)); - } - } - - - // ********** AbstractJavaResourcePersistentMember implementation ********** - - @Override - Iterator<String> validAnnotationNames() { - return this.getAnnotationProvider().typeAnnotationNames(); - } - - @Override - Annotation buildAnnotation(String mappingAnnotationName) { - return this.getAnnotationProvider(). - buildTypeAnnotation(this, this.member, mappingAnnotationName); - } - - @Override - Annotation buildNullAnnotation(String annotationName) { - return this.getAnnotationProvider(). - buildNullTypeAnnotation(this, annotationName); - } - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - - this.setSuperclassQualifiedName(this.buildSuperclassQualifiedName(astRoot)); - - for (JavaResourcePersistentAttribute field : this.getFields()) { - field.resolveTypes(astRoot); - } - - // a new type can trigger a method parameter type to be a resolved, - // fully-qualified name, so we need to rebuild our list of methods: - // "setFoo(Foo)" is not the same as "setFoo(com.bar.Foo)" - // and, vice-versa, a removed type can "unresolve" a parameter type - this.updateMethods(astRoot); - - for (JavaResourcePersistentAttribute method : this.getMethods()) { - method.resolveTypes(astRoot); - } - for (JavaResourcePersistentType type : this.getTypes()) { - type.resolveTypes(astRoot); - } - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ******** JavaResourcePersistentType implementation ******** - - // ***** name - public String getName() { - return this.name; - } - - private void setName(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); - return (binding == null) ? null : binding.getName(); - } - - // ***** qualified name - public String getQualifiedName() { - return this.qualifiedName; - } - - private void setQualifiedName(String qualifiedName) { - String old = this.qualifiedName; - this.qualifiedName = qualifiedName; - this.firePropertyChanged(QUALIFIED_NAME_PROPERTY, old, qualifiedName); - } - - private String buildQualifiedName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); - return (binding == null) ? null : binding.getQualifiedName(); - } - - // ***** superclass qualified name - public String getSuperclassQualifiedName() { - return this.superclassQualifiedName; - } - - private void setSuperclassQualifiedName(String superclassQualifiedName) { - String old = this.superclassQualifiedName; - this.superclassQualifiedName = superclassQualifiedName; - this.firePropertyChanged(SUPERCLASS_QUALIFIED_NAME_PROPERTY, old, superclassQualifiedName); - } - - private String buildSuperclassQualifiedName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); - if (binding == null) { - return null; - } - ITypeBinding superclass = binding.getSuperclass(); - return (superclass == null) ? null : superclass.getTypeDeclaration().getQualifiedName(); - } - - // ***** abstract - public boolean isAbstract() { - return this.abstract_; - } - - private void setAbstract(boolean abstract_) { - boolean old = this.abstract_; - this.abstract_ = abstract_; - this.firePropertyChanged(ABSTRACT_PROPERTY, old, abstract_); - } - - private boolean buildAbstract(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); - return (binding == null) ? false : Modifier.isAbstract(binding.getModifiers()); - } - - // ***** access - public AccessType getAccess() { - return this.access; - } - - // TODO - //seems we could have a public changeAccess() api which would - //move all annotations from fields to their corresponding methods or vice versa - //though of course it's more complicated than that since what if the - //corresponding field/method does not exist? - //making this internal since it should only be set based on changes in the source, the - //context model should not need to set this - private void setAccess(AccessType access) { - AccessType old = this.access; - this.access = access; - this.firePropertyChanged(ACCESS_PROPERTY, old, access); - } - - private AccessType buildAccess() { - return JPTTools.buildAccess(this); - } - - public boolean isMapped() { - for (Annotation each : CollectionTools.iterable(annotations())) { - if (CollectionTools.contains( - getAnnotationProvider().typeMappingAnnotationNames(), - each.getAnnotationName())) { - return true; - } - } - return false; - } - - /** - * check only persistable attributes - */ - public boolean hasAnyAnnotatedAttributes() { - for (Iterator<JavaResourcePersistentAttribute> stream = - this.persistableAttributes(); stream.hasNext(); ) { - if (stream.next().isAnnotated()) { - return true; - } - } - return false; - } - - - // ********** types ********** - - public Iterator<JavaResourcePersistentType> types() { - return this.getTypes().iterator(); - } - - private Iterable<JavaResourcePersistentType> getTypes() { - return new LiveCloneIterable<JavaResourcePersistentType>(this.types); // read-only - } - - public Iterator<JavaResourcePersistentType> allTypes() { - return new TreeIterator<JavaResourcePersistentType>(this) { - @Override - protected Iterator<? extends JavaResourcePersistentType> children(JavaResourcePersistentType type) { - return type.types(); - } - }; - } - - public Iterator<JavaResourcePersistentType> persistableTypes() { - return this.persistableMembers(this.types()); - } - - private JavaResourcePersistentType getType(String typeName, int occurrence) { - for (JavaResourcePersistentType type : this.getTypes()) { - if (type.isFor(typeName, occurrence)) { - return type; - } - } - return null; - } - - private void addType(JavaResourcePersistentType type) { - this.addItemToCollection(type, this.types, TYPES_COLLECTION); - } - - private void removeTypes(Collection<JavaResourcePersistentType> remove) { - this.removeItemsFromCollection(remove, this.types, TYPES_COLLECTION); - } - - - // ********** fields ********** - - public Iterator<JavaResourcePersistentAttribute> fields() { - return this.getFields().iterator(); - } - - private Iterable<JavaResourcePersistentAttribute> getFields() { - return new LiveCloneIterable<JavaResourcePersistentAttribute>(this.fields); - } - - public Iterator<JavaResourcePersistentAttribute> persistableFields() { - return this.persistableMembers(this.fields()); - } - - public Iterator<JavaResourcePersistentAttribute> persistableFieldsWithSpecifiedFieldAccess() { - return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableFields()) { - @Override - protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) { - return resourceAttribute.getSpecifiedAccess() == AccessType.FIELD; - } - }; - } - - private void addField(JavaResourcePersistentAttribute field) { - this.addItemToCollection(field, this.fields, FIELDS_COLLECTION); - } - - private JavaResourcePersistentAttribute getField(String fieldName, int occurrence) { - for (JavaResourcePersistentAttribute field : this.getFields()) { - if (field.isFor(fieldName, occurrence)) { - return field; - } - } - return null; - } - - private void removeFields(Collection<JavaResourcePersistentAttribute> remove) { - this.removeItemsFromCollection(remove, this.fields, FIELDS_COLLECTION); - } - - - // ********** methods ********** - - public Iterator<JavaResourcePersistentAttribute> methods() { - return this.getMethods().iterator(); - } - - private Iterable<JavaResourcePersistentAttribute> getMethods() { - return new LiveCloneIterable<JavaResourcePersistentAttribute>(this.methods); - } - - public Iterator<JavaResourcePersistentAttribute> persistableProperties() { - return this.persistableMembers(this.methods()); - } - - public Iterator<JavaResourcePersistentAttribute> persistablePropertiesWithSpecifiedPropertyAccess() { - return new FilteringIterator<JavaResourcePersistentAttribute, JavaResourcePersistentAttribute>(this.persistableProperties()) { - @Override - protected boolean accept(JavaResourcePersistentAttribute resourceAttribute) { - return resourceAttribute.getSpecifiedAccess() == AccessType.PROPERTY; - } - }; - } - - private JavaResourcePersistentAttribute getMethod(MethodSignature signature, int occurrence) { - for (JavaResourcePersistentAttribute method : this.getMethods()) { - if (method.isFor(signature, occurrence)) { - return method; - } - } - return null; - } - - private void addMethod(JavaResourcePersistentAttribute method) { - this.addItemToCollection(method, this.methods, METHODS_COLLECTION); - } - - private void removeMethods(Collection<JavaResourcePersistentAttribute> remove) { - this.removeItemsFromCollection(remove, this.methods, METHODS_COLLECTION); - } - - - // ********** attributes ********** - - @SuppressWarnings("unchecked") - public Iterator<JavaResourcePersistentAttribute> persistableAttributes() { - return new CompositeIterator<JavaResourcePersistentAttribute>( - this.persistableFields(), - this.persistableProperties() - ); - } - - public Iterator<JavaResourcePersistentAttribute> persistableAttributes(AccessType specifiedAccess) { - if (specifiedAccess == null) { - throw new IllegalArgumentException("specified access is null"); //$NON-NLS-1$ - } - return (specifiedAccess == AccessType.FIELD) ? - this.persistableAttributesForFieldAccessType() : - this.persistableAttributesForPropertyAccessType(); - } - - @SuppressWarnings("unchecked") - private Iterator<JavaResourcePersistentAttribute> persistableAttributesForFieldAccessType() { - return new CompositeIterator<JavaResourcePersistentAttribute>( - this.persistableFields(), - this.persistablePropertiesWithSpecifiedPropertyAccess() - ); - } - - @SuppressWarnings("unchecked") - private Iterator<JavaResourcePersistentAttribute> persistableAttributesForPropertyAccessType() { - return new CompositeIterator<JavaResourcePersistentAttribute>( - this.persistableProperties(), - this.persistableFieldsWithSpecifiedFieldAccess() - ); - } - - - // ********** update from Java ********** - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setName(this.buildName(astRoot)); - this.setQualifiedName(this.buildQualifiedName(astRoot)); - this.setSuperclassQualifiedName(this.buildSuperclassQualifiedName(astRoot)); - this.setAbstract(this.buildAbstract(astRoot)); - this.updateTypes(astRoot); - this.updateFields(astRoot); - this.updateMethods(astRoot); - // need to wait until everything is built to calculate 'access' - this.setAccess(this.buildAccess()); - } - - private void updateTypes(CompilationUnit astRoot) { - TypeDeclaration[] typeDeclarations = this.member.getTypes(astRoot); - CounterMap counters = new CounterMap(typeDeclarations.length); - HashSet<JavaResourcePersistentType> typesToRemove = new HashSet<JavaResourcePersistentType>(this.types); - for (TypeDeclaration typeDeclaration : typeDeclarations) { - String tdName = typeDeclaration.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - - JavaResourcePersistentType type = this.getType(tdName, occurrence); - if (type == null) { - this.addType(this.buildType(typeDeclaration, occurrence, astRoot)); - } else { - typesToRemove.remove(type); - type.update(astRoot); - } - } - this.removeTypes(typesToRemove); - } - - private JavaResourcePersistentType buildType(TypeDeclaration nestedTypeDeclaration, int occurrence, CompilationUnit astRoot) { - return newInstance(this.getJavaResourceCompilationUnit(), this.member, nestedTypeDeclaration, occurrence, astRoot); - } - - private void updateFields(CompilationUnit astRoot) { - FieldDeclaration[] fieldDeclarations = this.member.getFields(astRoot); - CounterMap counters = new CounterMap(fieldDeclarations.length); - HashSet<JavaResourcePersistentAttribute> fieldsToRemove = new HashSet<JavaResourcePersistentAttribute>(this.fields); - for (FieldDeclaration fieldDeclaration : fieldDeclarations) { - for (VariableDeclarationFragment fragment : fragments(fieldDeclaration)) { - String fieldName = fragment.getName().getFullyQualifiedName(); - int occurrence = counters.increment(fieldName); - - JavaResourcePersistentAttribute field = this.getField(fieldName, occurrence); - if (field == null) { - this.addField(this.buildField(fieldName, occurrence, astRoot)); - } else { - fieldsToRemove.remove(field); - field.update(astRoot); - } - } - } - this.removeFields(fieldsToRemove); - } - - private JavaResourcePersistentAttribute buildField(String fieldName, int occurrence, CompilationUnit astRoot) { - return SourcePersistentAttribute.newInstance(this, this.member, fieldName, occurrence, this.getJavaResourceCompilationUnit(), astRoot); - } - - private void updateMethods(CompilationUnit astRoot) { - MethodDeclaration[] methodDeclarations = this.member.getMethods(astRoot); - CounterMap counters = new CounterMap(methodDeclarations.length); - HashSet<JavaResourcePersistentAttribute> methodsToRemove = new HashSet<JavaResourcePersistentAttribute>(this.methods); - for (MethodDeclaration methodDeclaration : methodDeclarations) { - MethodSignature signature = JDTTools.buildMethodSignature(methodDeclaration); - int occurrence = counters.increment(signature); - - JavaResourcePersistentAttribute method = this.getMethod(signature, occurrence); - if (method == null) { - this.addMethod(this.buildMethod(signature, occurrence, astRoot)); - } else { - methodsToRemove.remove(method); - method.update(astRoot); - } - } - this.removeMethods(methodsToRemove); - } - - private JavaResourcePersistentAttribute buildMethod(MethodSignature signature, int occurrence, CompilationUnit astRoot) { - return SourcePersistentAttribute.newInstance(this, this.member, signature, occurrence, this.getJavaResourceCompilationUnit(), astRoot); - } - - - // ********** static methods ********** - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private static List<VariableDeclarationFragment> fragments(FieldDeclaration fd) { - return fd.fragments(); - } - - - // ********** CounterMap ********** - - private static class CounterMap { - private final HashMap<Object, Counter> counters; - - protected CounterMap(int initialCapacity) { - super(); - this.counters = new HashMap<Object, Counter>(initialCapacity); - } - - /** - * Return the incremented count for the specified object. - */ - int increment(Object o) { - Counter counter = this.counters.get(o); - if (counter == null) { - counter = new Counter(); - this.counters.put(o, counter); - } - counter.increment(); - return counter.count(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePrimaryKeyJoinColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePrimaryKeyJoinColumnAnnotation.java deleted file mode 100644 index 7e7a3a2e21..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePrimaryKeyJoinColumnAnnotation.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestablePrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.PrimaryKeyJoinColumn - */ -public final class SourcePrimaryKeyJoinColumnAnnotation - extends SourceNamedColumnAnnotation - implements NestablePrimaryKeyJoinColumnAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final DeclarationAnnotationElementAdapter<String> referencedColumnNameDeclarationAdapter; - private final AnnotationElementAdapter<String> referencedColumnNameAdapter; - private String referencedColumnName; - - - public SourcePrimaryKeyJoinColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.referencedColumnNameDeclarationAdapter = this.buildStringElementAdapter(JPA.PRIMARY_KEY_JOIN_COLUMN__REFERENCED_COLUMN_NAME); - this.referencedColumnNameAdapter = this.buildShortCircuitElementAdapter(this.referencedColumnNameDeclarationAdapter); - } - - public SourcePrimaryKeyJoinColumnAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - public SourcePrimaryKeyJoinColumnAnnotation(JavaResourceNode parent, Member member, IndexedDeclarationAnnotationAdapter idaa) { - this(parent, member, idaa, new MemberIndexedAnnotationAdapter(member, idaa)); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.referencedColumnName = this.buildReferencedColumnName(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setReferencedColumnName(this.buildReferencedColumnName(astRoot)); - } - - - // ********** JavaSourceNamedColumnAnnotation implementation ********** - - @Override - String getNameElementName() { - return JPA.PRIMARY_KEY_JOIN_COLUMN__NAME; - } - - @Override - String getColumnDefinitionElementName() { - return JPA.PRIMARY_KEY_JOIN_COLUMN__COLUMN_DEFINITION; - } - - - // ********** PrimaryKeyJoinColumn implementation ********** - - // ***** referenced column name - public String getReferencedColumnName() { - return this.referencedColumnName; - } - - public void setReferencedColumnName(String referencedColumnName) { - if (this.attributeValueHasNotChanged(this.referencedColumnName, referencedColumnName)) { - return; - } - String old = this.referencedColumnName; - this.referencedColumnName = referencedColumnName; - this.referencedColumnNameAdapter.setValue(referencedColumnName); - this.firePropertyChanged(REFERENCED_COLUMN_NAME_PROPERTY, old, referencedColumnName); - } - - private String buildReferencedColumnName(CompilationUnit astRoot) { - return this.referencedColumnNameAdapter.getValue(astRoot); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.referencedColumnNameDeclarationAdapter, astRoot); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.referencedColumnNameDeclarationAdapter, pos, astRoot); - } - - - // ********** NestableAnnotation implementation ********** - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - PrimaryKeyJoinColumnAnnotation oldJoinColumn = (PrimaryKeyJoinColumnAnnotation) oldAnnotation; - this.setReferencedColumnName(oldJoinColumn.getReferencedColumnName()); - } - - public void moveAnnotation(int newIndex) { - this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - protected IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - - - // ********** static methods ********** - - public static SourcePrimaryKeyJoinColumnAnnotation createPrimaryKeyJoinColumn(JavaResourceNode parent, Member member) { - return new SourcePrimaryKeyJoinColumnAnnotation(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - static SourcePrimaryKeyJoinColumnAnnotation createNestedPrimaryKeyJoinColumn(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter pkJoinColumnsAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, pkJoinColumnsAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new SourcePrimaryKeyJoinColumnAnnotation(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter pkJoinColumnsAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(pkJoinColumnsAdapter, index, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - - static NestablePrimaryKeyJoinColumnAnnotation createSecondaryTablePrimaryKeyJoinColumn(DeclarationAnnotationAdapter secondaryTableAdapter, JavaResourceNode parent, Member member, int index) { - return new SourcePrimaryKeyJoinColumnAnnotation(parent, member, buildSecondaryTableAnnotationAdapter(secondaryTableAdapter, index)); - } - - private static IndexedDeclarationAnnotationAdapter buildSecondaryTableAnnotationAdapter(DeclarationAnnotationAdapter secondaryTableAdapter, int index) { - return new NestedIndexedDeclarationAnnotationAdapter(secondaryTableAdapter, JPA.SECONDARY_TABLE__PK_JOIN_COLUMNS, index, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePrimaryKeyJoinColumnsAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePrimaryKeyJoinColumnsAnnotation.java deleted file mode 100644 index 0a3ea82674..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePrimaryKeyJoinColumnsAnnotation.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestablePrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.PrimaryKeyJoinColumns - */ -public final class SourcePrimaryKeyJoinColumnsAnnotation - extends SourceAnnotation<Member> - implements PrimaryKeyJoinColumnsAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestablePrimaryKeyJoinColumnAnnotation> pkJoinColumns = new Vector<NestablePrimaryKeyJoinColumnAnnotation>(); - - - public SourcePrimaryKeyJoinColumnsAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - AnnotationContainerTools.initialize(this, astRoot); - } - - public void update(CompilationUnit astRoot) { - AnnotationContainerTools.update(this, astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.pkJoinColumns); - } - - - // ********** AnnotationContainer Implementation ********** - - public String getContainerAnnotationName() { - return this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.PRIMARY_KEY_JOIN_COLUMNS__VALUE; - } - - public String getNestableAnnotationName() { - return PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestablePrimaryKeyJoinColumnAnnotation> nestedAnnotations() { - return new CloneListIterator<NestablePrimaryKeyJoinColumnAnnotation>(this.pkJoinColumns); - } - - public int nestedAnnotationsSize() { - return this.pkJoinColumns.size(); - } - - public NestablePrimaryKeyJoinColumnAnnotation addNestedAnnotationInternal() { - NestablePrimaryKeyJoinColumnAnnotation pkJoinColumn = this.buildPrimaryKeyJoinColumn(this.pkJoinColumns.size()); - this.pkJoinColumns.add(pkJoinColumn); - return pkJoinColumn; - } - - private NestablePrimaryKeyJoinColumnAnnotation buildPrimaryKeyJoinColumn(int index) { - return SourcePrimaryKeyJoinColumnAnnotation.createNestedPrimaryKeyJoinColumn(this, this.member, index, this.daa); - } - - public void nestedAnnotationAdded(int index, NestablePrimaryKeyJoinColumnAnnotation nestedAnnotation) { - this.fireItemAdded(PK_JOIN_COLUMNS_LIST, index, nestedAnnotation); - } - - public NestablePrimaryKeyJoinColumnAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.pkJoinColumns, targetIndex, sourceIndex).get(targetIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(PK_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public NestablePrimaryKeyJoinColumnAnnotation removeNestedAnnotationInternal(int index) { - return this.pkJoinColumns.remove(index); - } - - public void nestedAnnotationRemoved(int index, NestablePrimaryKeyJoinColumnAnnotation nestedAnnotation) { - this.fireItemRemoved(PK_JOIN_COLUMNS_LIST, index, nestedAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceQueryHintAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceQueryHintAnnotation.java deleted file mode 100644 index 23484c15f1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceQueryHintAnnotation.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableQueryHintAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Type; - -/** - * javax.persistence.QueryHint - */ -public final class SourceQueryHintAnnotation - extends SourceAnnotation<Type> - implements NestableQueryHintAnnotation -{ - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - private final AnnotationElementAdapter<String> nameAdapter; - private String name; - - private final DeclarationAnnotationElementAdapter<String> valueDeclarationAdapter; - private final AnnotationElementAdapter<String> valueAdapter; - private String value; - - - public SourceQueryHintAnnotation(JavaResourceNode parent, Type type, IndexedDeclarationAnnotationAdapter idaa) { - super(parent, type, idaa, new MemberIndexedAnnotationAdapter(type, idaa)); - this.nameDeclarationAdapter = this.buildNameAdapter(idaa); - this.nameAdapter = this.buildAdapter(this.nameDeclarationAdapter); - this.valueDeclarationAdapter = this.buildValueAdapter(idaa); - this.valueAdapter = this.buildAdapter(this.valueDeclarationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - private AnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea); - } - - private DeclarationAnnotationElementAdapter<String> buildNameAdapter(DeclarationAnnotationAdapter adapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(adapter, JPA.QUERY_HINT__NAME); - } - - private DeclarationAnnotationElementAdapter<String> buildValueAdapter(DeclarationAnnotationAdapter adapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(adapter, JPA.QUERY_HINT__VALUE); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.buildName(astRoot); - this.value = this.buildValue(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.buildName(astRoot)); - this.setValue(this.buildValue(astRoot)); - } - - public IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** QueryHintAnnotation implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - public void setName(String name) { - if (this.attributeValueHasNotChanged(this.name, name)) { - return; - } - String old = this.name; - this.name = name; - this.nameAdapter.setValue(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - // ***** value - public String getValue() { - return this.value; - } - - public void setValue(String value) { - if (this.attributeValueHasNotChanged(this.value, value)) { - return; - } - String old = this.value; - this.value = value; - this.valueAdapter.setValue(value); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private String buildValue(CompilationUnit astRoot) { - return this.valueAdapter.getValue(astRoot); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.valueDeclarationAdapter, astRoot); - } - - - // ********** NestableAnnotation implementation ********** - - public void initializeFrom(NestableAnnotation oldAnnotation) { - QueryHintAnnotation oldHint = (QueryHintAnnotation) oldAnnotation; - this.setName(oldHint.getName()); - this.setValue(oldHint.getValue()); - } - - public void moveAnnotation(int newIndex) { - this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - - // ********** static methods ********** - - static SourceQueryHintAnnotation createNamedQueryQueryHint(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter namedQueryAdapter, int index) { - return new SourceQueryHintAnnotation(parent, type, buildNamedQueryQueryHintAnnotationAdapter(namedQueryAdapter, index)); - } - - private static IndexedDeclarationAnnotationAdapter buildNamedQueryQueryHintAnnotationAdapter(DeclarationAnnotationAdapter namedQueryAdapter, int index) { - return new NestedIndexedDeclarationAnnotationAdapter(namedQueryAdapter, JPA.NAMED_QUERY__HINTS, index, JPA.QUERY_HINT); - } - - static SourceQueryHintAnnotation createNamedNativeQueryQueryHint(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) { - return new SourceQueryHintAnnotation(parent, type, buildNamedNativeQueryQueryHintAnnotationAdapter(namedNativeQueryAdapter, index)); - } - - private static IndexedDeclarationAnnotationAdapter buildNamedNativeQueryQueryHintAnnotationAdapter(DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) { - return new NestedIndexedDeclarationAnnotationAdapter(namedNativeQueryAdapter, JPA.NAMED_NATIVE_QUERY__HINTS, index, JPA.QUERY_HINT); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceRelationshipMappingAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceRelationshipMappingAnnotation.java deleted file mode 100644 index 5cdc49f8f0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceRelationshipMappingAnnotation.java +++ /dev/null @@ -1,315 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.EnumArrayDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitArrayAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter; -import org.eclipse.jpt.core.resource.java.CascadeType; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; -import org.eclipse.jpt.utility.internal.ArrayTools; - -/** - * javax.persistence.ManyToMany - * javax.persistence.ManyToOne - * javax.persistence.OneToMany - * javax.persistence.OneToOne - */ -abstract class SourceRelationshipMappingAnnotation - extends SourceAnnotation<Attribute> - implements RelationshipMappingAnnotation -{ - final DeclarationAnnotationElementAdapter<String> targetEntityDeclarationAdapter; - final AnnotationElementAdapter<String> targetEntityAdapter; - String targetEntity; - - String fullyQualifiedTargetEntityClassName; - - final DeclarationAnnotationElementAdapter<String> fetchDeclarationAdapter; - final AnnotationElementAdapter<String> fetchAdapter; - FetchType fetch; - - final DeclarationAnnotationElementAdapter<String[]> cascadeDeclarationAdapter; - final AnnotationElementAdapter<String[]> cascadeAdapter; - boolean cascadeAll; - boolean cascadePersist; - boolean cascadeMerge; - boolean cascadeRemove; - boolean cascadeRefresh; - - - SourceRelationshipMappingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, DeclarationAnnotationAdapter daa) { - super(parent, attribute, daa); - this.targetEntityDeclarationAdapter = this.getTargetEntityAdapter(); - this.targetEntityAdapter = this.buildAnnotationElementAdapter(this.targetEntityDeclarationAdapter); - this.fetchDeclarationAdapter = this.getFetchAdapter(); - this.fetchAdapter = this.buildAnnotationElementAdapter(this.fetchDeclarationAdapter); - this.cascadeDeclarationAdapter = this.getCascadeAdapter(); - this.cascadeAdapter = new ShortCircuitArrayAnnotationElementAdapter<String>(attribute, this.cascadeDeclarationAdapter); - } - - AnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea); - } - - AnnotationElementAdapter<Boolean> buildBooleanAnnotationElementAdapter(DeclarationAnnotationElementAdapter<Boolean> daea) { - return new ShortCircuitAnnotationElementAdapter<Boolean>(this.member, daea); - } - - public void initialize(CompilationUnit astRoot) { - this.targetEntity = this.buildTargetEntity(astRoot); - this.fullyQualifiedTargetEntityClassName = this.buildFullyQualifiedTargetEntityClassName(astRoot); - this.fetch = this.buildFetch(astRoot); - this.initializeCascadeTypes(astRoot); - } - - private void initializeCascadeTypes(CompilationUnit astRoot) { - CascadeType[] cascadeTypes = CascadeType.fromJavaAnnotationValues(this.cascadeAdapter.getValue(astRoot)); - this.cascadeAll = ArrayTools.contains(cascadeTypes, CascadeType.ALL); - this.cascadeMerge = ArrayTools.contains(cascadeTypes, CascadeType.MERGE); - this.cascadePersist = ArrayTools.contains(cascadeTypes, CascadeType.PERSIST); - this.cascadeRefresh = ArrayTools.contains(cascadeTypes, CascadeType.REFRESH); - this.cascadeRemove = ArrayTools.contains(cascadeTypes, CascadeType.REMOVE); - } - - public void update(CompilationUnit astRoot) { - this.setFetch(this.buildFetch(astRoot)); - this.setTargetEntity(this.buildTargetEntity(astRoot)); - this.setFullyQualifiedTargetEntityClassName(this.buildFullyQualifiedTargetEntityClassName(astRoot)); - this.updateCascade(astRoot); - } - - private void updateCascade(CompilationUnit astRoot) { - CascadeType[] cascadeTypes = CascadeType.fromJavaAnnotationValues(this.cascadeAdapter.getValue(astRoot)); - this.setCascadeAll(ArrayTools.contains(cascadeTypes, CascadeType.ALL)); - this.setCascadeMerge(ArrayTools.contains(cascadeTypes, CascadeType.MERGE)); - this.setCascadePersist(ArrayTools.contains(cascadeTypes, CascadeType.PERSIST)); - this.setCascadeRefresh(ArrayTools.contains(cascadeTypes, CascadeType.REFRESH)); - this.setCascadeRemove(ArrayTools.contains(cascadeTypes, CascadeType.REMOVE)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.targetEntity); - } - - - // ********** RelationshipMappingAnnotation implementation ********** - - // ***** target entity - public String getTargetEntity() { - return this.targetEntity; - } - - public void setTargetEntity(String targetEntity) { - if (this.attributeValueHasNotChanged(this.targetEntity, targetEntity)) { - return; - } - String old = this.targetEntity; - this.targetEntity = targetEntity; - this.targetEntityAdapter.setValue(targetEntity); - this.firePropertyChanged(TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - private String buildTargetEntity(CompilationUnit astRoot) { - return this.targetEntityAdapter.getValue(astRoot); - } - - public TextRange getTargetEntityTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.targetEntityDeclarationAdapter, astRoot); - } - - /** - * return the Java adapter's 'targetEntity' element adapter config - */ - abstract DeclarationAnnotationElementAdapter<String> getTargetEntityAdapter(); - - // ***** fully-qualified target entity class name - public String getFullyQualifiedTargetEntityClassName() { - return this.fullyQualifiedTargetEntityClassName; - } - - private void setFullyQualifiedTargetEntityClassName(String name) { - String old = this.fullyQualifiedTargetEntityClassName; - this.fullyQualifiedTargetEntityClassName = name; - this.firePropertyChanged(FULLY_QUALIFIED_TARGET_ENTITY_CLASS_NAME_PROPERTY, old, name); - } - - private String buildFullyQualifiedTargetEntityClassName(CompilationUnit astRoot) { - return (this.targetEntity == null) ? null : JDTTools.resolveFullyQualifiedName(this.targetEntityAdapter.getExpression(astRoot)); - } - - // ***** fetch - public FetchType getFetch() { - return this.fetch; - } - - public void setFetch(FetchType fetch) { - if (this.attributeValueHasNotChanged(this.fetch, fetch)) { - return; - } - FetchType old = this.fetch; - this.fetch = fetch; - this.fetchAdapter.setValue(FetchType.toJavaAnnotationValue(fetch)); - this.firePropertyChanged(FETCH_PROPERTY, old, fetch); - } - - private FetchType buildFetch(CompilationUnit astRoot) { - return FetchType.fromJavaAnnotationValue(this.fetchAdapter.getValue(astRoot)); - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.fetchDeclarationAdapter, astRoot); - } - - /** - * return the Java adapter's 'fetch' element adapter config - */ - abstract DeclarationAnnotationElementAdapter<String> getFetchAdapter(); - - // ***** cascade - private void setCascadeTypes(CascadeType[] cascadeTypes) { - this.cascadeAdapter.setValue(CascadeType.toJavaAnnotationValues(cascadeTypes)); - } - - private void setCascade(CascadeType cascadeType, boolean set) { - String[] javaValues = this.cascadeAdapter.getValue(); - CascadeType[] cascadeTypes = CascadeType.fromJavaAnnotationValues(javaValues); - - boolean present = ArrayTools.contains(cascadeTypes, cascadeType); - if (set) { - if ( ! present) { - this.setCascadeTypes(ArrayTools.add(cascadeTypes, cascadeType)); - } - } else { - if (present) { - this.setCascadeTypes(ArrayTools.remove(cascadeTypes, cascadeType)); - } - } - } - - public TextRange getCascadeTextRange(CompilationUnit astRoot) { - return getElementTextRange(this.cascadeDeclarationAdapter, astRoot); - } - - /** - * return the Java adapter's 'cascade' element adapter config - */ - abstract DeclarationAnnotationElementAdapter<String[]> getCascadeAdapter(); - - // ***** cascade all - public boolean isCascadeAll() { - return this.cascadeAll; - } - - public void setCascadeAll(boolean cascadeAll) { - if (this.cascadeAll == cascadeAll) { - return; - } - boolean old = this.cascadeAll; - this.cascadeAll = cascadeAll; - this.setCascade(CascadeType.ALL, cascadeAll); - this.firePropertyChanged(CASCADE_ALL_PROPERTY, old, cascadeAll); - } - - // ***** cascade persist - public boolean isCascadePersist() { - return this.cascadePersist; - } - - public void setCascadePersist(boolean cascadePersist) { - if (this.cascadePersist == cascadePersist) { - return; - } - boolean old = this.cascadePersist; - this.cascadePersist = cascadePersist; - this.setCascade(CascadeType.PERSIST, cascadePersist); - this.firePropertyChanged(CASCADE_PERSIST_PROPERTY, old, cascadePersist); - } - - // ***** cascade merge - public boolean isCascadeMerge() { - return this.cascadeMerge; - } - - public void setCascadeMerge(boolean cascadeMerge) { - if (this.cascadeMerge == cascadeMerge) { - return; - } - boolean old = this.cascadeMerge; - this.cascadeMerge = cascadeMerge; - this.setCascade(CascadeType.MERGE, cascadeMerge); - this.firePropertyChanged(CASCADE_MERGE_PROPERTY, old, cascadeMerge); - } - - // ***** cascade remove - public boolean isCascadeRemove() { - return this.cascadeRemove; - } - - public void setCascadeRemove(boolean cascadeRemove) { - if (this.cascadeRemove == cascadeRemove) { - return; - } - boolean old = this.cascadeRemove; - this.cascadeRemove = cascadeRemove; - this.setCascade(CascadeType.REMOVE, cascadeRemove); - this.firePropertyChanged(CASCADE_REMOVE_PROPERTY, old, cascadeRemove); - } - - // ***** cascade refresh - public boolean isCascadeRefresh() { - return this.cascadeRefresh; - } - - public void setCascadeRefresh(boolean cascadeRefresh) { - if (this.cascadeRefresh == cascadeRefresh) { - return; - } - boolean old = this.cascadeRefresh; - this.cascadeRefresh = cascadeRefresh; - this.setCascade(CascadeType.REFRESH, cascadeRefresh); - this.firePropertyChanged(CASCADE_REFRESH_PROPERTY, old, cascadeRefresh); - } - - - // ********** static methods ********** - - static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - // TODO what about QualifiedType? - return buildAnnotationElementAdapter(annotationAdapter, elementName, SimpleTypeStringExpressionConverter.instance()); - } - - static DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String> converter) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, false, converter); - } - - static DeclarationAnnotationElementAdapter<String> buildFetchAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new EnumDeclarationAnnotationElementAdapter(annotationAdapter, elementName, false); - } - - static DeclarationAnnotationElementAdapter<String[]> buildEnumArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new EnumArrayDeclarationAnnotationElementAdapter(annotationAdapter, elementName, false); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSecondaryTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSecondaryTableAnnotation.java deleted file mode 100644 index ada1107dc3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSecondaryTableAnnotation.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationContainer; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestablePrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableSecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.SecondaryTable - */ -public final class SourceSecondaryTableAnnotation - extends SourceBaseTableAnnotation - implements NestableSecondaryTableAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(SecondaryTableAnnotation.ANNOTATION_NAME); - - private final Vector<NestablePrimaryKeyJoinColumnAnnotation> pkJoinColumns = new Vector<NestablePrimaryKeyJoinColumnAnnotation>(); - private final PkJoinColumnsAnnotationContainer pkJoinColumnsContainer = new PkJoinColumnsAnnotationContainer(); - - - public SourceSecondaryTableAnnotation(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - AnnotationContainerTools.initialize(this.pkJoinColumnsContainer, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - AnnotationContainerTools.update(this.pkJoinColumnsContainer, astRoot); - } - - - // ********** AbstractBaseTableAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getNameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.SECONDARY_TABLE__NAME); - } - - @Override - DeclarationAnnotationElementAdapter<String> getSchemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.SECONDARY_TABLE__SCHEMA); - } - - @Override - DeclarationAnnotationElementAdapter<String> getCatalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.SECONDARY_TABLE__CATALOG); - } - - @Override - String getUniqueConstraintsElementName() { - return JPA.SECONDARY_TABLE__UNIQUE_CONSTRAINTS; - } - - - // ************* SecondaryTable implementation ******************* - - // ***** pk join columns - public ListIterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns() { - return new CloneListIterator<PrimaryKeyJoinColumnAnnotation>(this.pkJoinColumns); - } - - ListIterator<NestablePrimaryKeyJoinColumnAnnotation> nestablePkJoinColumns() { - return new CloneListIterator<NestablePrimaryKeyJoinColumnAnnotation>(this.pkJoinColumns); - } - - public int pkJoinColumnsSize() { - return this.pkJoinColumns.size(); - } - - public NestablePrimaryKeyJoinColumnAnnotation pkJoinColumnAt(int index) { - return this.pkJoinColumns.get(index); - } - - public int indexOfPkJoinColumn(PrimaryKeyJoinColumnAnnotation joinColumn) { - return this.pkJoinColumns.indexOf(joinColumn); - } - - public NestablePrimaryKeyJoinColumnAnnotation addPkJoinColumn(int index) { - return (NestablePrimaryKeyJoinColumnAnnotation) AnnotationContainerTools.addNestedAnnotation(index, this.pkJoinColumnsContainer); - } - - NestablePrimaryKeyJoinColumnAnnotation addPkJoinColumnInternal() { - NestablePrimaryKeyJoinColumnAnnotation pkJoinColumn = this.buildPrimaryKeyJoinColumn(this.pkJoinColumns.size()); - this.pkJoinColumns.add(pkJoinColumn); - return pkJoinColumn; - } - - private NestablePrimaryKeyJoinColumnAnnotation buildPrimaryKeyJoinColumn(int index) { - return SourcePrimaryKeyJoinColumnAnnotation.createSecondaryTablePrimaryKeyJoinColumn(this.daa, this, this.member, index); - } - - void pkJoinColumnAdded(int index, NestablePrimaryKeyJoinColumnAnnotation joinColumn) { - this.fireItemAdded(PK_JOIN_COLUMNS_LIST, index, joinColumn); - } - - public void movePkJoinColumn(int targetIndex, int sourceIndex) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, this.pkJoinColumnsContainer); - } - - NestablePrimaryKeyJoinColumnAnnotation movePkJoinColumnInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.pkJoinColumns, targetIndex, sourceIndex).get(targetIndex); - } - - void pkJoinColumnMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(PK_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public void removePkJoinColumn(int index) { - AnnotationContainerTools.removeNestedAnnotation(index, this.pkJoinColumnsContainer); - } - - NestablePrimaryKeyJoinColumnAnnotation removePkJoinColumnInternal(int index) { - return this.pkJoinColumns.remove(index); - } - - void pkJoinColumnRemoved(int index, NestablePrimaryKeyJoinColumnAnnotation joinColumn) { - this.fireItemRemoved(PK_JOIN_COLUMNS_LIST, index, joinColumn); - } - - - // ********** NestableAnnotation implementation ********** - - public void moveAnnotation(int newIndex) { - this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - protected IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - SecondaryTableAnnotation oldTable = (SecondaryTableAnnotation) oldAnnotation; - for (PrimaryKeyJoinColumnAnnotation oldPkJoinColumn : CollectionTools.iterable(oldTable.pkJoinColumns())) { - NestablePrimaryKeyJoinColumnAnnotation newPkJoinColumn = this.addPkJoinColumn(oldTable.indexOfPkJoinColumn(oldPkJoinColumn)); - newPkJoinColumn.initializeFrom((NestableAnnotation) oldPkJoinColumn); - } - } - - - // ********** static methods ********** - - public static SourceSecondaryTableAnnotation createSecondaryTable(JavaResourceNode parent, Member member) { - return new SourceSecondaryTableAnnotation(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - static SourceSecondaryTableAnnotation createNestedSecondaryTable(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter secondaryTablesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, secondaryTablesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new SourceSecondaryTableAnnotation(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter secondaryTablesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(secondaryTablesAdapter, index, JPA.SECONDARY_TABLE); - } - - - // ********** pk join column container ********** - - /** - * adapt the AnnotationContainer interface to the secondary table's - * primary key join columns - */ - class PkJoinColumnsAnnotationContainer - implements AnnotationContainer<NestablePrimaryKeyJoinColumnAnnotation> - { - public String getContainerAnnotationName() { - return SourceSecondaryTableAnnotation.this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return SourceSecondaryTableAnnotation.this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.SECONDARY_TABLE__PK_JOIN_COLUMNS; - } - - public String getNestableAnnotationName() { - return PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestablePrimaryKeyJoinColumnAnnotation> nestedAnnotations() { - return SourceSecondaryTableAnnotation.this.nestablePkJoinColumns(); - } - - public int nestedAnnotationsSize() { - return SourceSecondaryTableAnnotation.this.pkJoinColumnsSize(); - } - - public NestablePrimaryKeyJoinColumnAnnotation addNestedAnnotationInternal() { - return SourceSecondaryTableAnnotation.this.addPkJoinColumnInternal(); - } - - public void nestedAnnotationAdded(int index, NestablePrimaryKeyJoinColumnAnnotation nestedAnnotation) { - SourceSecondaryTableAnnotation.this.pkJoinColumnAdded(index, nestedAnnotation); - } - - public NestablePrimaryKeyJoinColumnAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return SourceSecondaryTableAnnotation.this.movePkJoinColumnInternal(targetIndex, sourceIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - SourceSecondaryTableAnnotation.this.pkJoinColumnMoved(targetIndex, sourceIndex); - } - - public NestablePrimaryKeyJoinColumnAnnotation removeNestedAnnotationInternal(int index) { - return SourceSecondaryTableAnnotation.this.removePkJoinColumnInternal(index); - } - - public void nestedAnnotationRemoved(int index, NestablePrimaryKeyJoinColumnAnnotation nestedAnnotation) { - SourceSecondaryTableAnnotation.this.pkJoinColumnRemoved(index, nestedAnnotation); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSecondaryTablesAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSecondaryTablesAnnotation.java deleted file mode 100644 index bf37125772..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSecondaryTablesAnnotation.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableSecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.SecondaryTables - */ -public final class SourceSecondaryTablesAnnotation - extends SourceAnnotation<Member> - implements SecondaryTablesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final Vector<NestableSecondaryTableAnnotation> secondaryTables = new Vector<NestableSecondaryTableAnnotation>(); - - - public SourceSecondaryTablesAnnotation(JavaResourcePersistentType parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - AnnotationContainerTools.initialize(this, astRoot); - } - - public void update(CompilationUnit astRoot) { - AnnotationContainerTools.update(this, astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.secondaryTables); - } - - - // ********** AnnotationContainer implementation ********** - - public String getContainerAnnotationName() { - return this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.SECONDARY_TABLES__VALUE; - } - - public String getNestableAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableSecondaryTableAnnotation> nestedAnnotations() { - return new CloneListIterator<NestableSecondaryTableAnnotation>(this.secondaryTables); - } - - public int nestedAnnotationsSize() { - return this.secondaryTables.size(); - } - - public NestableSecondaryTableAnnotation addNestedAnnotationInternal() { - NestableSecondaryTableAnnotation secondaryTable = this.buildSecondaryTable(this.secondaryTables.size()); - this.secondaryTables.add(secondaryTable); - return secondaryTable; - } - - private NestableSecondaryTableAnnotation buildSecondaryTable(int index) { - return SourceSecondaryTableAnnotation.createNestedSecondaryTable(this, this.member, index, this.daa); - } - - public void nestedAnnotationAdded(int index, NestableSecondaryTableAnnotation nestedAnnotation) { - this.fireItemAdded(SECONDARY_TABLES_LIST, index, nestedAnnotation); - } - - public NestableSecondaryTableAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.secondaryTables, targetIndex, sourceIndex).get(targetIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(SECONDARY_TABLES_LIST, targetIndex, sourceIndex); - } - - public NestableSecondaryTableAnnotation removeNestedAnnotationInternal(int index) { - return this.secondaryTables.remove(index); - } - - public void nestedAnnotationRemoved(int index, NestableSecondaryTableAnnotation nestedAnnotation) { - this.fireItemRemoved(SECONDARY_TABLES_LIST, index, nestedAnnotation); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSequenceGeneratorAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSequenceGeneratorAnnotation.java deleted file mode 100644 index 90387e4bf8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceSequenceGeneratorAnnotation.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.SequenceGenerator - */ -public abstract class SourceSequenceGeneratorAnnotation - extends SourceGeneratorAnnotation - implements SequenceGeneratorAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildAdapter(JPA.SEQUENCE_GENERATOR__NAME); - - private static final DeclarationAnnotationElementAdapter<Integer> INITIAL_VALUE_ADAPTER = buildIntegerAdapter(JPA.SEQUENCE_GENERATOR__INITIAL_VALUE); - - private static final DeclarationAnnotationElementAdapter<Integer> ALLOCATION_SIZE_ADAPTER = buildIntegerAdapter(JPA.SEQUENCE_GENERATOR__ALLOCATION_SIZE); - - private static final DeclarationAnnotationElementAdapter<String> SEQUENCE_NAME_ADAPTER = buildAdapter(JPA.SEQUENCE_GENERATOR__SEQUENCE_NAME); - private final AnnotationElementAdapter<String> sequenceNameAdapter; - private String sequenceName; - - - protected SourceSequenceGeneratorAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.sequenceNameAdapter = this.buildAdapter(SEQUENCE_NAME_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.sequenceName = this.buildSequenceName(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setSequenceName(this.buildSequenceName(astRoot)); - } - - - // ********** AbstractGeneratorAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getNameAdapter() { - return NAME_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<Integer> getInitialValueAdapter() { - return INITIAL_VALUE_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<Integer> getAllocationSizeAdapter() { - return ALLOCATION_SIZE_ADAPTER; - } - - - // ********** SequenceGeneratorAnnotation implementation ********** - - // ***** sequence name - public String getSequenceName() { - return this.sequenceName; - } - - public void setSequenceName(String sequenceName) { - if (this.attributeValueHasNotChanged(this.sequenceName, sequenceName)) { - return; - } - String old = this.sequenceName; - this.sequenceName = sequenceName; - this.sequenceNameAdapter.setValue(sequenceName); - this.firePropertyChanged(SEQUENCE_NAME_PROPERTY, old, sequenceName); - } - - private String buildSequenceName(CompilationUnit astRoot) { - return this.sequenceNameAdapter.getValue(astRoot); - } - - public TextRange getSequenceNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(SEQUENCE_NAME_ADAPTER, astRoot); - } - - public boolean sequenceNameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(SEQUENCE_NAME_ADAPTER, pos, astRoot); - } - - - // ********** static methods ********** - - protected static DeclarationAnnotationElementAdapter<String> buildAdapter(String elementName) { - return buildAdapter(DECLARATION_ANNOTATION_ADAPTER, elementName); - } - - protected static DeclarationAnnotationElementAdapter<Integer> buildIntegerAdapter(String elementName) { - return buildIntegerAdapter(DECLARATION_ANNOTATION_ADAPTER, elementName); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTableAnnotation.java deleted file mode 100644 index 546ebe3e49..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTableAnnotation.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * javax.persistence.Table - */ -public final class SourceTableAnnotation - extends SourceBaseTableAnnotation - implements TableAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.TABLE__NAME); - - private static final DeclarationAnnotationElementAdapter<String> SCHEMA_ADAPTER = ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.TABLE__SCHEMA); - - private static final DeclarationAnnotationElementAdapter<String> CATALOG_ADAPTER = ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.TABLE__CATALOG); - - - public SourceTableAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - // ********** AbstractBaseTableAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getNameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @Table is never nested - return NAME_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String> getSchemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @Table is never nested - return SCHEMA_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<String> getCatalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @Table is never nested - return CATALOG_ADAPTER; - } - - @Override - String getUniqueConstraintsElementName() { - return JPA.TABLE__UNIQUE_CONSTRAINTS; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTableGeneratorAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTableGeneratorAnnotation.java deleted file mode 100644 index 328cdf6727..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTableGeneratorAnnotation.java +++ /dev/null @@ -1,440 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationContainer; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraintAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.TableGenerator - */ -public final class SourceTableGeneratorAnnotation - extends SourceGeneratorAnnotation - implements TableGeneratorAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__NAME); - - private static final DeclarationAnnotationElementAdapter<Integer> INITIAL_VALUE_ADAPTER = buildIntegerAdapter(JPA.TABLE_GENERATOR__INITIAL_VALUE); - - private static final DeclarationAnnotationElementAdapter<Integer> ALLOCATION_SIZE_ADAPTER = buildIntegerAdapter(JPA.TABLE_GENERATOR__ALLOCATION_SIZE); - - private static final DeclarationAnnotationElementAdapter<String> TABLE_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__TABLE); - private final AnnotationElementAdapter<String> tableAdapter; - private String table; - - private static final DeclarationAnnotationElementAdapter<String> SCHEMA_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__SCHEMA); - private final AnnotationElementAdapter<String> schemaAdapter; - private String schema; - - private static final DeclarationAnnotationElementAdapter<String> CATALOG_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__CATALOG); - private final AnnotationElementAdapter<String> catalogAdapter; - private String catalog; - - private static final DeclarationAnnotationElementAdapter<String> PK_COLUMN_NAME_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__PK_COLUMN_NAME); - private final AnnotationElementAdapter<String> pkColumnNameAdapter; - private String pkColumnName; - - private static final DeclarationAnnotationElementAdapter<String> VALUE_COLUMN_NAME_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__VALUE_COLUMN_NAME); - private final AnnotationElementAdapter<String> valueColumnNameAdapter; - private String valueColumnName; - - private static final DeclarationAnnotationElementAdapter<String> PK_COLUMN_VALUE_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__PK_COLUMN_VALUE); - private final AnnotationElementAdapter<String> pkColumnValueAdapter; - private String pkColumnValue; - - private final Vector<NestableUniqueConstraintAnnotation> uniqueConstraints = new Vector<NestableUniqueConstraintAnnotation>(); - private final UniqueConstraintsAnnotationContainer uniqueConstraintsContainer = new UniqueConstraintsAnnotationContainer(); - - - public SourceTableGeneratorAnnotation(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.tableAdapter = this.buildAdapter(TABLE_ADAPTER); - this.catalogAdapter = this.buildAdapter(CATALOG_ADAPTER); - this.schemaAdapter = this.buildAdapter(SCHEMA_ADAPTER); - this.pkColumnNameAdapter = this.buildAdapter(PK_COLUMN_NAME_ADAPTER); - this.valueColumnNameAdapter = this.buildAdapter(VALUE_COLUMN_NAME_ADAPTER); - this.pkColumnValueAdapter = this.buildAdapter(PK_COLUMN_VALUE_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.table = this.buildTable(astRoot); - this.schema = this.buildSchema(astRoot); - this.catalog = this.buildCatalog(astRoot); - this.pkColumnName = this.buildPkColumnName(astRoot); - this.valueColumnName = this.buildValueColumnName(astRoot); - this.pkColumnValue = this.buildPkColumnValue(astRoot); - AnnotationContainerTools.initialize(this.uniqueConstraintsContainer, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setTable(this.buildTable(astRoot)); - this.setSchema(this.buildSchema(astRoot)); - this.setCatalog(this.buildCatalog(astRoot)); - this.setPkColumnName(this.buildPkColumnName(astRoot)); - this.setValueColumnName(this.buildValueColumnName(astRoot)); - this.setPkColumnValue(this.buildPkColumnValue(astRoot)); - AnnotationContainerTools.update(this.uniqueConstraintsContainer, astRoot); - } - - - // ********** AbstractGeneratorAnnotation implementation ********** - - @Override - DeclarationAnnotationElementAdapter<String> getNameAdapter() { - return NAME_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<Integer> getInitialValueAdapter() { - return INITIAL_VALUE_ADAPTER; - } - - @Override - DeclarationAnnotationElementAdapter<Integer> getAllocationSizeAdapter() { - return ALLOCATION_SIZE_ADAPTER; - } - - - // ********** TableGeneratorAnnotation implementation ********** - - // ***** table - public String getTable() { - return this.table; - } - - public void setTable(String table) { - if (this.attributeValueHasNotChanged(this.table, table)) { - return; - } - String old = this.table; - this.table = table; - this.tableAdapter.setValue(table); - this.firePropertyChanged(TABLE_PROPERTY, old, table); - } - - private String buildTable(CompilationUnit astRoot) { - return this.tableAdapter.getValue(astRoot); - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(TABLE_ADAPTER, astRoot); - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(TABLE_ADAPTER, pos, astRoot); - } - - // ***** schema - public String getSchema() { - return this.schema; - } - - public void setSchema(String schema) { - if (this.attributeValueHasNotChanged(this.schema, schema)) { - return; - } - String old = this.schema; - this.schema = schema; - this.schemaAdapter.setValue(schema); - this.firePropertyChanged(SCHEMA_PROPERTY, old, schema); - } - - private String buildSchema(CompilationUnit astRoot) { - return this.schemaAdapter.getValue(astRoot); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(SCHEMA_ADAPTER, astRoot); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(SCHEMA_ADAPTER, pos, astRoot); - } - - // ***** catalog - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String catalog) { - if (this.attributeValueHasNotChanged(this.catalog, catalog)) { - return; - } - String old = this.catalog; - this.catalog = catalog; - this.catalogAdapter.setValue(catalog); - this.firePropertyChanged(CATALOG_PROPERTY, old, catalog); - } - - private String buildCatalog(CompilationUnit astRoot) { - return this.catalogAdapter.getValue(astRoot); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(CATALOG_ADAPTER, astRoot); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(CATALOG_ADAPTER, pos, astRoot); - } - - // ***** pk column name - public String getPkColumnName() { - return this.pkColumnName; - } - - public void setPkColumnName(String pkColumnName) { - if (this.attributeValueHasNotChanged(this.pkColumnName, pkColumnName)) { - return; - } - String old = this.pkColumnName; - this.pkColumnName = pkColumnName; - this.pkColumnNameAdapter.setValue(pkColumnName); - this.firePropertyChanged(PK_COLUMN_NAME_PROPERTY, old, pkColumnName); - } - - private String buildPkColumnName(CompilationUnit astRoot) { - return this.pkColumnNameAdapter.getValue(astRoot); - } - - public TextRange getPkColumnNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(PK_COLUMN_NAME_ADAPTER, astRoot); - } - - public boolean pkColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(PK_COLUMN_NAME_ADAPTER, pos, astRoot); - } - - // ***** value column name - public String getValueColumnName() { - return this.valueColumnName; - } - - public void setValueColumnName(String valueColumnName) { - if (this.attributeValueHasNotChanged(this.valueColumnName, valueColumnName)) { - return; - } - String old = this.valueColumnName; - this.valueColumnName = valueColumnName; - this.valueColumnNameAdapter.setValue(valueColumnName); - this.firePropertyChanged(VALUE_COLUMN_NAME_PROPERTY, old, valueColumnName); - } - - private String buildValueColumnName(CompilationUnit astRoot) { - return this.valueColumnNameAdapter.getValue(astRoot); - } - - public TextRange getValueColumnNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_COLUMN_NAME_ADAPTER, astRoot); - } - - public boolean valueColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(VALUE_COLUMN_NAME_ADAPTER, pos, astRoot); - } - - // ***** pk column value - public String getPkColumnValue() { - return this.pkColumnValue; - } - - public void setPkColumnValue(String pkColumnValue) { - if (this.attributeValueHasNotChanged(this.pkColumnValue, pkColumnValue)) { - return; - } - String old = this.pkColumnValue; - this.pkColumnValue = pkColumnValue; - this.pkColumnValueAdapter.setValue(pkColumnValue); - this.firePropertyChanged(PK_COLUMN_VALUE_PROPERTY, old, pkColumnValue); - } - - private String buildPkColumnValue(CompilationUnit astRoot) { - return this.pkColumnValueAdapter.getValue(astRoot); - } - - public TextRange getPkColumnValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(PK_COLUMN_VALUE_ADAPTER, astRoot); - } - - public boolean pkColumnValueTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(PK_COLUMN_VALUE_ADAPTER, pos, astRoot); - } - - // ***** unique constraints - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return new CloneListIterator<UniqueConstraintAnnotation>(this.uniqueConstraints); - } - - ListIterator<NestableUniqueConstraintAnnotation> nestableUniqueConstraints() { - return new CloneListIterator<NestableUniqueConstraintAnnotation>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public NestableUniqueConstraintAnnotation uniqueConstraintAt(int index) { - return this.uniqueConstraints.get(index); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - return this.uniqueConstraints.indexOf(uniqueConstraint); - } - - public NestableUniqueConstraintAnnotation addUniqueConstraint(int index) { - return (NestableUniqueConstraintAnnotation) AnnotationContainerTools.addNestedAnnotation(index, this.uniqueConstraintsContainer); - } - - NestableUniqueConstraintAnnotation addUniqueConstraintInternal() { - NestableUniqueConstraintAnnotation uniqueConstraint = this.buildUniqueConstraint(this.uniqueConstraints.size()); - this.uniqueConstraints.add(uniqueConstraint); - return uniqueConstraint; - } - - NestableUniqueConstraintAnnotation buildUniqueConstraint(int index) { - return new SourceUniqueConstraintAnnotation(this, this.member, buildUniqueConstraintAnnotationAdapter(index)); - } - - IndexedDeclarationAnnotationAdapter buildUniqueConstraintAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(this.daa, JPA.TABLE_GENERATOR__UNIQUE_CONSTRAINTS, index, JPA.UNIQUE_CONSTRAINT); - } - - void uniqueConstraintAdded(int index, NestableUniqueConstraintAnnotation constraint) { - this.fireItemAdded(UNIQUE_CONSTRAINTS_LIST, index, constraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, this.uniqueConstraintsContainer); - } - - NestableUniqueConstraintAnnotation moveUniqueConstraintInternal(int targetIndex, int sourceIndex) { - return CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex).get(targetIndex); - } - - void uniqueConstraintMoved(int targetIndex, int sourceIndex) { - this.fireItemMoved(UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - public void removeUniqueConstraint(int index) { - AnnotationContainerTools.removeNestedAnnotation(index, this.uniqueConstraintsContainer); - } - - NestableUniqueConstraintAnnotation removeUniqueConstraintInternal(int index) { - return this.uniqueConstraints.remove(index); - } - - void uniqueConstraintRemoved(int index, NestableUniqueConstraintAnnotation constraint) { - this.fireItemRemoved(UNIQUE_CONSTRAINTS_LIST, index, constraint); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildAdapter(String elementName) { - return buildAdapter(DECLARATION_ANNOTATION_ADAPTER, elementName); - } - - private static DeclarationAnnotationElementAdapter<Integer> buildIntegerAdapter(String elementName) { - return buildIntegerAdapter(DECLARATION_ANNOTATION_ADAPTER, elementName); - } - - - // ********** unique constraint container ********** - - /** - * adapt the AnnotationContainer interface to the table generator's unique constraints - */ - class UniqueConstraintsAnnotationContainer - implements AnnotationContainer<NestableUniqueConstraintAnnotation> - { - public String getContainerAnnotationName() { - return SourceTableGeneratorAnnotation.this.getAnnotationName(); - } - - public org.eclipse.jdt.core.dom.Annotation getContainerJdtAnnotation(CompilationUnit astRoot) { - return SourceTableGeneratorAnnotation.this.getJdtAnnotation(astRoot); - } - - public String getElementName() { - return JPA.TABLE_GENERATOR__UNIQUE_CONSTRAINTS; - } - - public String getNestableAnnotationName() { - return UniqueConstraintAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableUniqueConstraintAnnotation> nestedAnnotations() { - return SourceTableGeneratorAnnotation.this.nestableUniqueConstraints(); - } - - public int nestedAnnotationsSize() { - return SourceTableGeneratorAnnotation.this.uniqueConstraintsSize(); - } - - public NestableUniqueConstraintAnnotation addNestedAnnotationInternal() { - return SourceTableGeneratorAnnotation.this.addUniqueConstraintInternal(); - } - - public void nestedAnnotationAdded(int index, NestableUniqueConstraintAnnotation nestedAnnotation) { - SourceTableGeneratorAnnotation.this.uniqueConstraintAdded(index, nestedAnnotation); - } - - public NestableUniqueConstraintAnnotation moveNestedAnnotationInternal(int targetIndex, int sourceIndex) { - return SourceTableGeneratorAnnotation.this.moveUniqueConstraintInternal(targetIndex, sourceIndex); - } - - public void nestedAnnotationMoved(int targetIndex, int sourceIndex) { - SourceTableGeneratorAnnotation.this.uniqueConstraintMoved(targetIndex, sourceIndex); - } - - public NestableUniqueConstraintAnnotation removeNestedAnnotationInternal(int index) { - return SourceTableGeneratorAnnotation.this.removeUniqueConstraintInternal(index); - } - - public void nestedAnnotationRemoved(int index, NestableUniqueConstraintAnnotation nestedAnnotation) { - SourceTableGeneratorAnnotation.this.uniqueConstraintRemoved(index, nestedAnnotation); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTemporalAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTemporalAnnotation.java deleted file mode 100644 index e2811269a1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTemporalAnnotation.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -/** - * javax.persistence.Temporal - */ -public final class SourceTemporalAnnotation - extends SourceAnnotation<Attribute> - implements TemporalAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); - private final AnnotationElementAdapter<String> valueAdapter; - private TemporalType value; - - - public SourceTemporalAnnotation(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, VALUE_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.buildValue(astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.buildValue(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.value); - } - - - // ********** TemporalAnnotation implementation ********** - - // ***** value - public TemporalType getValue() { - return this.value; - } - - public void setValue(TemporalType value) { - if (this.attributeValueHasNotChanged(this.value, value)) { - return; - } - TemporalType old = this.value; - this.value = value; - this.valueAdapter.setValue(TemporalType.toJavaAnnotationValue(value)); - this.firePropertyChanged(VALUE_PROPERTY, old, value); - } - - private TemporalType buildValue(CompilationUnit astRoot) { - return TemporalType.fromJavaAnnotationValue(this.valueAdapter.getValue(astRoot)); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.TEMPORAL__VALUE); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTransientAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTransientAnnotation.java deleted file mode 100644 index b41ff19a6e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTransientAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; - -/** - * javax.persistence.Transient - */ -public final class SourceTransientAnnotation - extends SourceAnnotation<Attribute> - implements TransientAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceTransientAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceUniqueConstraintAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceUniqueConstraintAnnotation.java deleted file mode 100644 index 334eb0b608..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceUniqueConstraintAnnotation.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import java.util.Arrays; -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitArrayAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraintAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -/** - * javax.persistence.UniqueConstraint - */ -public final class SourceUniqueConstraintAnnotation - extends SourceAnnotation<Member> - implements NestableUniqueConstraintAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.UNIQUE_CONSTRAINT); - - private final DeclarationAnnotationElementAdapter<String[]> columnNamesDeclarationAdapter; - private final AnnotationElementAdapter<String[]> columnNamesAdapter; - private final Vector<String> columnNames = new Vector<String>(); - - - public SourceUniqueConstraintAnnotation(JavaResourceNode parent, Member member, IndexedDeclarationAnnotationAdapter idaa) { - super(parent, member, idaa, new MemberIndexedAnnotationAdapter(member, idaa)); - this.columnNamesDeclarationAdapter = buildArrayAnnotationElementAdapter(idaa, JPA.UNIQUE_CONSTRAINT__COLUMN_NAMES); - this.columnNamesAdapter = this.buildAnnotationElementAdapter(this.columnNamesDeclarationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - private AnnotationElementAdapter<String[]> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String[]> daea) { - return new ShortCircuitArrayAnnotationElementAdapter<String>(this.member, daea); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return buildArrayAnnotationElementAdapter(annotationAdapter, elementName, AnnotationStringArrayExpressionConverter.forStrings()); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String[]> converter) { - return new ConversionDeclarationAnnotationElementAdapter<String[]>(annotationAdapter, elementName, false, converter); - } - - public void initialize(CompilationUnit astRoot) { - String[] javaColumnNames = this.columnNamesAdapter.getValue(astRoot); - for (int i = 0; i < javaColumnNames.length; i++) { - this.columnNames.add(javaColumnNames[i]); - } - } - - public void update(CompilationUnit astRoot) { - this.updateColumnNames(astRoot); - } - - private void updateColumnNames(CompilationUnit astRoot) { - String[] javaColumnNames = this.columnNamesAdapter.getValue(astRoot); - this.synchronizeList(Arrays.asList(javaColumnNames), this.columnNames, COLUMN_NAMES_LIST); - } - - public IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.columnNames); - } - - - // ********** UniqueConstraintAnnotation implementation ********** - - // ***** column names - public ListIterator<String> columnNames() { - return new CloneListIterator<String>(this.columnNames); - } - - public int columnNamesSize() { - return this.columnNames.size(); - } - - public void addColumnName(String columnName) { - this.addColumnName(this.columnNames.size(), columnName); - } - - public void addColumnName(int index, String columnName) { - this.addColumnName_(index, columnName); - this.columnNamesAdapter.setValue(this.columnNames.toArray(new String[this.columnNames.size()])); - } - - private void addColumnName_(int index, String columnName) { - this.addItemToList(index, columnName, this.columnNames, COLUMN_NAMES_LIST); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - this.moveItemInList(targetIndex, sourceIndex, this.columnNames, COLUMN_NAMES_LIST); - this.columnNamesAdapter.setValue(this.columnNames.toArray(new String[this.columnNames.size()])); - } - - public boolean columnNamesTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.columnNamesDeclarationAdapter, pos, astRoot); - } - - public void removeColumnName(String columnName) { - this.removeItemFromList(columnName, this.columnNames, COLUMN_NAMES_LIST); - this.columnNamesAdapter.setValue(this.columnNames.toArray(new String[this.columnNames.size()])); - } - - public void removeColumnName(int index) { - this.removeItemFromList(index, this.columnNames, COLUMN_NAMES_LIST); - this.columnNamesAdapter.setValue(this.columnNames.toArray(new String[this.columnNames.size()])); - } - - - // ********** NestableAnnotation implementation ********** - - public void initializeFrom(NestableAnnotation oldAnnotation) { - UniqueConstraintAnnotation oldConstraint = (UniqueConstraintAnnotation) oldAnnotation; - for (String columnName : CollectionTools.iterable(oldConstraint.columnNames())) { - this.addColumnName(columnName); - } - } - - public void moveAnnotation(int newIndex) { - this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceVersionAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceVersionAnnotation.java deleted file mode 100644 index 2b27d2c6c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceVersionAnnotation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; - -/** - * javax.persistence.Version - */ -public final class SourceVersionAnnotation - extends SourceAnnotation<Attribute> - implements VersionAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - - public SourceVersionAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public void update(CompilationUnit astRoot) { - // nothing to update - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/OrmXmlResourceProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/OrmXmlResourceProvider.java deleted file mode 100644 index a7d8735eac..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/OrmXmlResourceProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider; -import org.eclipse.jpt.core.resource.orm.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; - -public class OrmXmlResourceProvider - extends AbstractXmlResourceProvider -{ - /** - * (Convenience method) Returns an ORM resource model provider for - * the given file. - */ - public static OrmXmlResourceProvider getXmlResourceProvider(IFile file) { - return getXmlResourceProvider_(file.getProject(), file.getFullPath().toString()); - } - - /** - * (Convenience method) Returns an ORM resource model provider for - * the given project in the specified deploy location - */ - public static OrmXmlResourceProvider getXmlResourceProvider(IProject project, String deployLocation) { - return getXmlResourceProvider_(project, JptCorePlugin.getDeploymentURI(project, deployLocation)); - } - - /** - * (Convenience method) Returns an ORM resource model provider for - * the given project in the default deploy location - */ - public static OrmXmlResourceProvider getDefaultXmlResourceProvider(IProject project) { - return getXmlResourceProvider(project, JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - } - - private static OrmXmlResourceProvider getXmlResourceProvider_(IProject project, String location) { - return new OrmXmlResourceProvider(project, new Path(location)); - } - - - public OrmXmlResourceProvider(IProject project) { - this(project, new Path(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH)); - } - - public OrmXmlResourceProvider(IProject project, IPath filePath) { - super(project, filePath, JptCorePlugin.ORM_XML_CONTENT_TYPE); - } - - @Override - protected void populateRoot() { - XmlEntityMappings entityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - entityMappings.setVersion(JPA.SCHEMA_VERSION); - getResourceContents().add(entityMappings); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/PersistenceXmlResourceProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/PersistenceXmlResourceProvider.java deleted file mode 100644 index e4000d950a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/PersistenceXmlResourceProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.persistence; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider; -import org.eclipse.jpt.core.resource.persistence.JPA; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; - -public class PersistenceXmlResourceProvider - extends AbstractXmlResourceProvider -{ - /** - * (Convenience method) Returns a persistence resource model provider for - * the given file. - */ - public static PersistenceXmlResourceProvider getXmlResourceProvider(IFile file) { - return getXmlResourceProvider_(file.getProject(), file.getFullPath().toString()); - } - - /** - * (Convenience method) Returns an persistence resource model provider for - * the given project in the specified deploy location - */ - public static PersistenceXmlResourceProvider getXmlResourceProvider(IProject project, String deployLocation) { - return getXmlResourceProvider_(project, JptCorePlugin.getDeploymentURI(project, deployLocation)); - } - - /** - * (Convenience method) Returns a persistence resource model provider for - * the given project in the default deploy location - */ - public static PersistenceXmlResourceProvider getDefaultXmlResourceProvider(IProject project) { - return getXmlResourceProvider(project, JptCorePlugin.DEFAULT_PERSISTENCE_XML_FILE_PATH); - } - - private static PersistenceXmlResourceProvider getXmlResourceProvider_(IProject project, String location) { - return new PersistenceXmlResourceProvider(project, new Path(location)); - } - - - public PersistenceXmlResourceProvider(IProject project) { - this(project, new Path(JptCorePlugin.DEFAULT_PERSISTENCE_XML_FILE_PATH)); - } - - public PersistenceXmlResourceProvider(IProject project, IPath filePath) { - super(project, filePath, JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE); - } - - @Override - protected void populateRoot() { - XmlPersistence persistence = PersistenceFactory.eINSTANCE.createXmlPersistence(); - persistence.setVersion(JPA.SCHEMA_VERSION); - XmlPersistenceUnit persistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - persistenceUnit.setName(getProject().getName()); - persistence.getPersistenceUnits().add(persistenceUnit); - getResourceContents().add(persistence); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/XMLRootElementVersionContentDescriber.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/XMLRootElementVersionContentDescriber.java deleted file mode 100644 index daca1e1ac9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/XMLRootElementVersionContentDescriber.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the 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: - * IBM Corporation - initial API and implementation - * Jesper Steen Moeller - added namespace support - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.xml; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import javax.xml.parsers.ParserConfigurationException; -import org.eclipse.core.internal.content.ContentMessages; -import org.eclipse.core.internal.runtime.RuntimeLog; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.XMLContentDescriber; -import org.eclipse.osgi.util.NLS; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -//TODO bug 263976 - copied from org.eclipse.core.runtime.content.XMLRootElementContentDescriber2 -/** - * A content describer for detecting the name of the top-level element, - * its namespace and the DTD system identifier in an XML file. - * <p> - * This executable extension supports "element" parameter, that - * can be specified more than once. If the - * <code>":-"</code> method is used, then the value is treated as - * "element" (always just one) - * </p> - * <p> - * The value of "element" is specified using such a format - * <code>{namespace}name/dtd:version</code>. The namespace or dtd part - * can be omitted and accepted are values like <code>name/dtd</code>, - * <code>{ns}name</code> and <code>name</code>. - * </p> - * <p> - * The describer will detect a document, if it matches at least one "element" - * what means, that dtd, namespace (if specified) and name in "element" - * match those in the document. - * </p> - * <p> - * If the "element" name part is "*", e.g. <code>{namespace}*</code>, - * it denotes a wildcard match. If the "element" namespace part is empty, - * e.g. <code>{}name</code>, only these documents with the root element - * that belong to the unnamed namespace <code><elem xmlns=""></code> - * will be detected. - * </p> - * <p> - * This class should be used instead of {@link XMLRootElementVersionContentDescriber} - * which doesn't detect namespaces and doesn't allow to specify - * more than one set of dtds, root element names and namespaces which - * should be detected. - * </p> - * <p> - * This class is not intended to be subclassed or instantiated by clients, - * only to be referenced by the "describer" configuration element in - * extensions to the <code>org.eclipse.core.runtime.contentTypes</code> - * extension point. - * </p> - * - * @since org.eclipse.core.contenttype 3.3 - */ -public final class XMLRootElementVersionContentDescriber extends XMLContentDescriber implements IExecutableExtension { - private static final String ELEMENT_TO_FIND = "element"; //$NON-NLS-1$ - - /* (Intentionally not included in javadoc) - * The top-level elements we are looking for. This value will be initialized - * by the <code>setInitializationData</code> method. If no value is - * provided, then this means that we don't care what the top-level element - * will be. The list is a collection of <code>QualifiedElement</code>. - */ - private QualifiedElement[] elementsToFind = null; - - /* (Intentionally not included in javadoc) - * Simple value holder for root element name, its namespace and dtd. - */ - static class QualifiedElement { - private String namespace; - private String element; - private String dtd; - private String version; - - QualifiedElement(String namespace, String element, String dtd, String version) { - this.namespace = namespace; - this.element = element; - this.dtd = dtd; - this.version = version; - } - - QualifiedElement(String qualifiedElement) { - // Extract namespace part - int openBrace = qualifiedElement.indexOf('{'); - int closeBrace = qualifiedElement.indexOf('}'); - if (openBrace == 0 && closeBrace >=1 ) { - namespace = qualifiedElement.substring(1, closeBrace); - qualifiedElement = qualifiedElement.substring(closeBrace+1); - } - // Extract dtd part - int dtdSlash = qualifiedElement.indexOf('/'); - if (dtdSlash > 0) { - dtd = qualifiedElement.substring(dtdSlash+1); - qualifiedElement = qualifiedElement.substring(0, dtdSlash); - } - // Extract version part - int versionSlash = qualifiedElement.indexOf(':'); - if (versionSlash > 0) { - version = qualifiedElement.substring(versionSlash + 1); - qualifiedElement = qualifiedElement.substring(0, versionSlash); - } - - // Check if the name is a wildcard - element = ("*".equals(qualifiedElement) ? null : qualifiedElement); - } - - public String getNamespace() { - return namespace; - } - - public String getElement() { - return element; - } - public String getDTD() { - return dtd; - } - - public String getVersion() { - return version; - } - - public boolean matches(String someNamespace, String someElement, String someDtd, String someVersion) { - boolean nsMatch = this.namespace != null ? this.namespace.equals(someNamespace) : true; - boolean elementEquals = this.element != null ? this.element.equals(someElement) : true; - boolean dtdEquals = this.dtd != null ? this.dtd.equals(someDtd) : true; - boolean versionEquals = this.version != null ? this.version.equals(someVersion) : true; - return nsMatch && elementEquals && dtdEquals && versionEquals; - } - } - - /* (Intentionally not included in javadoc) - * Determines the validation status for the given contents. - * - * @param contents the contents to be evaluated - * @return one of the following:<ul> - * <li><code>VALID</code></li>, - * <li><code>INVALID</code></li>, - * <li><code>INDETERMINATE</code></li> - * </ul> - * @throws IOException - */ - private int checkCriteria(InputSource contents) throws IOException { - XMLRootHandler xmlHandler = new XMLRootHandler(elementsToFind != null); - try { - if (!xmlHandler.parseContents(contents)) - return INDETERMINATE; - } catch (SAXException e) { - // we may be handed any kind of contents... it is normal we fail to parse - return INDETERMINATE; - } catch (ParserConfigurationException e) { - // some bad thing happened - force this describer to be disabled - String message = ContentMessages.content_parserConfiguration; - RuntimeLog.log(new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, e)); - throw new RuntimeException(message); - } - // Check to see if we matched our criteria. - if (elementsToFind != null) { - boolean foundOne = false; - for (int i = 0; i < elementsToFind.length && !foundOne; ++i) { - foundOne |= elementsToFind[i].matches(xmlHandler.getRootNamespace(), xmlHandler.getRootName(), xmlHandler.getDTD(), xmlHandler.getVersion()); - } - if (!foundOne) - return INDETERMINATE; - } - // We must be okay then. - return VALID; - } - - /* (Intentionally not included in javadoc) - * @see IContentDescriber#describe(InputStream, IContentDescription) - */ - @Override - public int describe(InputStream contents, IContentDescription description) throws IOException { - // call the basic XML describer to do basic recognition - if (super.describe(contents, description) == INVALID) - return INVALID; - // super.describe will have consumed some chars, need to rewind - contents.reset(); - // Check to see if we matched our criteria. - return checkCriteria(new InputSource(contents)); - } - - /* (Intentionally not included in javadoc) - * @see IContentDescriber#describe(Reader, IContentDescription) - */ - @Override - public int describe(Reader contents, IContentDescription description) throws IOException { - // call the basic XML describer to do basic recognition - if (super.describe(contents, description) == INVALID) - return INVALID; - // super.describe will have consumed some chars, need to rewind - contents.reset(); - // Check to see if we matched our criteria. - return checkCriteria(new InputSource(contents)); - } - - /* (Intentionally not included in javadoc) - * @see IExecutableExtension#setInitializationData - */ - public void setInitializationData(final IConfigurationElement config, final String propertyName, final Object data) throws CoreException { - if (data instanceof String) - elementsToFind = new QualifiedElement[] {new QualifiedElement((String) data)}; - else if (data instanceof Hashtable) { - List elements = null; - - // the describer parameters have to be read again, because "element" parameter can be specified multiple times - // and the given hashtable carries only one of them - IConfigurationElement describerElement = config.getChildren("describer")[0]; //$NON-NLS-1$ - IConfigurationElement[] params = describerElement.getChildren("parameter"); //$NON-NLS-1$ - String pname = null; - for (int i = 0; i < params.length; i++) { - pname = params[i].getAttribute("name"); //$NON-NLS-1$ - if (ELEMENT_TO_FIND.equals(pname)) { - if (elements == null) - elements = new LinkedList(); - elements.add(new QualifiedElement(params[i].getAttribute("value"))); //$NON-NLS-1$ - } - } - - List qualifiedElements = new ArrayList(); - - // create list of qualified elements - if (elements != null) { - for (Iterator it = elements.iterator(); it.hasNext();) { - qualifiedElements.add(it.next()); - } - } - elementsToFind = (QualifiedElement[]) qualifiedElements.toArray(new QualifiedElement[qualifiedElements.size()]); - } - - if (elementsToFind.length == 0) { - String message = NLS.bind(ContentMessages.content_badInitializationData, XMLRootElementVersionContentDescriber.class.getName()); - throw new CoreException(new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, null)); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/XMLRootHandler.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/XMLRootHandler.java deleted file mode 100644 index f2acd33948..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/XMLRootHandler.java +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.xml; - -import java.io.IOException; -import java.io.StringReader; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.eclipse.jpt.core.JptCorePlugin; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.XMLReader; -import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.DefaultHandler; - -//TODO bug 263976 - copied from org.eclipse.core.internal.content.XMLRootHandler -/** - * A content describer for detecting the name of the top-level element of the - * DTD system identifier in an XML file. This supports two parameters: - * <code>DTD_TO_FIND</code> and <code>ELEMENT_TO_FIND</code>. This is done - * using the <code>IExecutableExtension</code> mechanism. If the - * <code>":-"</code> method is used, then the value is treated as the - * <code>ELEMENT_TO_FIND</code>. - * - * @since 3.0 - */ -public final class XMLRootHandler extends DefaultHandler implements LexicalHandler { - /** - * An exception indicating that the parsing should stop. This is usually - * triggered when the top-level element has been found. - * - * @since 3.0 - */ - static class StopParsingException extends SAXException { - /** - * All serializable objects should have a stable serialVersionUID - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs an instance of <code>StopParsingException</code> with a - * <code>null</code> detail message. - */ - public StopParsingException() { - super((String) null); - } - } - - - /** - * Should we check the root element? - */ - private boolean checkRoot; - /** - * The system identifier for the DTD that was found while parsing the XML. - * This member variable is <code>null</code> unless the file has been - * parsed successful to the point of finding the DTD's system identifier. - */ - private String dtdFound = null; - /** - * This is the name of the top-level element found in the XML file. This - * member variable is <code>null</code> unless the file has been parsed - * successful to the point of finding the top-level element. - */ - private String elementFound = null; - - /** - * This is the namespace of the top-level element found in the XML file. This - * member variable is <code>null</code> unless the file has been parsed - * successful to the point of finding the top-level element. - */ - private String namespaceFound = null; - - private String versionFound = null; - - public XMLRootHandler(boolean checkRoot) { - this.checkRoot = checkRoot; - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int) - */ - public final void comment(final char[] ch, final int start, final int length) { - // Not interested. - } - - /** - * Creates a new SAX parser for use within this instance. - * - * @return The newly created parser. - * - * @throws ParserConfigurationException - * If a parser of the given configuration cannot be created. - * @throws SAXException - * If something in general goes wrong when creating the parser. - * @throws SAXNotRecognizedException - * If the <code>XMLReader</code> does not recognize the - * lexical handler configuration option. - * @throws SAXNotSupportedException - * If the <code>XMLReader</code> does not support the lexical - * handler configuration option. - */ - private final SAXParser createParser(SAXParserFactory parserFactory) throws ParserConfigurationException, SAXException, SAXNotRecognizedException, SAXNotSupportedException { - // Initialize the parser. - final SAXParser parser = parserFactory.newSAXParser(); - final XMLReader reader = parser.getXMLReader(); - reader.setProperty("http://xml.org/sax/properties/lexical-handler", this); //$NON-NLS-1$ - // disable DTD validation (bug 63625) - try { - // be sure validation is "off" or the feature to ignore DTD's will not apply - reader.setFeature("http://xml.org/sax/features/validation", false); //$NON-NLS-1$ - reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); //$NON-NLS-1$ - } catch (SAXNotRecognizedException e) { - // not a big deal if the parser does not recognize the features - } catch (SAXNotSupportedException e) { - // not a big deal if the parser does not support the features - } - return parser; - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ext.LexicalHandler#endCDATA() - */ - public final void endCDATA() { - // Not interested. - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ext.LexicalHandler#endDTD() - */ - public final void endDTD() { - // Not interested. - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String) - */ - public final void endEntity(final String name) { - // Not interested. - } - - public String getDTD() { - return dtdFound; - } - - public String getRootName() { - return elementFound; - } - - /** - * @since org.eclipse.core.contenttype 3.3 - */ - public String getRootNamespace() { - return namespaceFound; - } - - public String getVersion() { - return this.versionFound; - } - - - public boolean parseContents(InputSource contents) throws IOException, - ParserConfigurationException, SAXException { - // Parse the file into we have what we need (or an error occurs). - SAXParser parser = null; - - /* - * set context class loader while factories instantiate classes (for - * minimal time) so proper classes, and classloaders, are used in IBM - * JRE, with Xerces on the classpath. See bug 283721. - * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=283721) - */ - ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - SAXParserFactory factory = JptCorePlugin.instance().getSAXParserFactory(); - if (factory == null) - return false; - parser = createParser(factory); - } finally { - Thread.currentThread().setContextClassLoader(savedClassLoader); - } - // to support external entities specified as relative URIs (see - // bug 63298) - contents.setSystemId("/"); //$NON-NLS-1$ - try { - parser.parse(contents, this); - } catch (StopParsingException e) { - // Abort the parsing normally. Fall through... - } - - return true; - } - - /* - * Resolve external entity definitions to an empty string. This is to speed - * up processing of files with external DTDs. Not resolving the contents - * of the DTD is ok, as only the System ID of the DTD declaration is used. - * @see org.xml.sax.helpers.DefaultHandler#resolveEntity(java.lang.String, java.lang.String) - */ - @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException { - return new InputSource(new StringReader("")); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ext.LexicalHandler#startCDATA() - */ - public final void startCDATA() { - // Not interested. - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, - * java.lang.String, java.lang.String) - */ - public final void startDTD(final String name, final String publicId, final String systemId) throws SAXException { - dtdFound = systemId; - // If we don't care about the top-level element, we can stop here. - if (!checkRoot) - throw new StopParsingException(); - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ContentHandler#startElement(java.lang.String, - * java.lang.String, java.lang.String, org.xml.sax.Attributes) - */ - @Override - public final void startElement(final String uri, final String elementName, final String qualifiedName, final Attributes attributes) throws SAXException { - elementFound = elementName; - namespaceFound = uri; - versionFound = attributes.getValue("version"); - throw new StopParsingException(); - } - - /* - * (non-Javadoc) - * - * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String) - */ - public final void startEntity(final String name) { - // Not interested. - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/BooleanTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/BooleanTranslator.java deleted file mode 100644 index bd843f0a1b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/BooleanTranslator.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.xml.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class BooleanTranslator - extends Translator -{ - public BooleanTranslator(String domPathAndNames, EStructuralFeature structuralFeature) { - super(domPathAndNames, structuralFeature, BOOLEAN_FEATURE | BOOLEAN_LOWERCASE); - } - - public BooleanTranslator(String domPathAndNames, EStructuralFeature structuralFeature, int style) { - super(domPathAndNames, structuralFeature, BOOLEAN_FEATURE | BOOLEAN_LOWERCASE | style); - } - - @Override - public Object convertStringToValue(String string, EObject owner) { - return Boolean.valueOf(string); - } - - @Override - public String convertValueToString(Object value, EObject owner) { - return ((Boolean) value).toString(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/EmptyTagBooleanTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/EmptyTagBooleanTranslator.java deleted file mode 100644 index 18e56ca0eb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/EmptyTagBooleanTranslator.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.xml.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -/** - * This translator is to be used for empty xml tags that correspond - * to a boolean attribute in the emf model. - * cascade-persist is an example from the orm.xsd: - * - * <persistence-unit-defaults> - * <cascade-persist/> - * </persistence-unit-defaults> ==> cascadePersist == true - * - * vs. - * - * <persistence-unit-defaults> - * </persistence-unit-defaults> ==> cascadePersist == false - * - */ -public class EmptyTagBooleanTranslator - extends Translator -{ - public EmptyTagBooleanTranslator(String domPathAndNames, EStructuralFeature structuralFeature) { - super(domPathAndNames, structuralFeature, EMPTY_TAG | BOOLEAN_FEATURE); - } - - public EmptyTagBooleanTranslator(String domPathAndNames, EStructuralFeature structuralFeature, int style) { - super(domPathAndNames, structuralFeature, style | EMPTY_TAG | BOOLEAN_FEATURE); - } - - @Override - public Object getMOFValue(EObject mofObject) { - // I am overriding this method. This is so the tag will be removed when - // the value is false. - // I'm not sure if this is a bug in the ecore or maybe in the translators, - // but I really don't think that we should have to depend on the boolean - // being "unset" to remove the tag. - Boolean value = (Boolean) super.getMOFValue(mofObject); - return (value == null) ? null : value.booleanValue() ? value : null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/SimpleRootTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/SimpleRootTranslator.java deleted file mode 100644 index 5e29735fff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/SimpleRootTranslator.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.xml.translators; - -import org.eclipse.emf.ecore.EClass; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.wst.common.internal.emf.resource.RootTranslator; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -/** - * Root translator that contains a list of child translators and no special - * behavior. - */ -public class SimpleRootTranslator - extends RootTranslator -{ - protected Translator[] children; - - public SimpleRootTranslator(String domPathAndNames, EClass eClass) { - super(domPathAndNames, eClass); - } - - public SimpleRootTranslator(String domPathAndNames, EClass eClass, Translator[] children) { - super(domPathAndNames, eClass); - this.children = children; - } - - /** - * Widen method access to 'public'. - */ - @Override - public Translator[] getChildren() { - return this.children; - } - - protected Translator[] getChildren_() { - return (this.children == null) ? EMPTY_TRANSLATOR_ARRAY : this.children; - } - protected static final Translator[] EMPTY_TRANSLATOR_ARRAY = new Translator[0]; - - /** - * Set the translator's children. - * Return the translator. - */ - public void setChildren(Translator[] children) { - this.children = children; - } - - /** - * Add the specified translator to the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleRootTranslator addChild(Translator translator) { - this.children = ArrayTools.add(this.getChildren_(), translator); - return this; - } - - /** - * Add the specified translators to the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleRootTranslator addChildren(Translator[] translators) { - this.children = ArrayTools.addAll(this.getChildren_(), translators); - return this; - } - - /** - * Remove the specified translator from the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleRootTranslator removeChild(Translator translator) { - this.children = ArrayTools.remove(this.children, translator); - return this; - } - - /** - * Remove the specified translators from the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleRootTranslator removeChildren(Translator[] translators) { - this.children = ArrayTools.removeAll(this.children, (Object[]) translators); - return this; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/SimpleTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/SimpleTranslator.java deleted file mode 100644 index 6132344e1e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/xml/translators/SimpleTranslator.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.xml.translators; - -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.wst.common.internal.emf.resource.Translator; -import org.eclipse.wst.common.internal.emf.resource.TranslatorPath; - -/** - * Translator that contains a list of child translators and no special - * behavior. - */ -public class SimpleTranslator - extends Translator -{ - protected Translator[] children; - - - // ********** constructors ********** - - public SimpleTranslator(String domPathAndNames, EClass eClass) { - super(domPathAndNames, eClass); - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature) { - super(domPathAndNames, eStructuralFeature); - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature, Translator[] children) { - super(domPathAndNames, eStructuralFeature); - this.children = children; - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature, EClass eClass) { - super(domPathAndNames, eStructuralFeature, eClass); - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature, EClass eClass, Translator[] children) { - super(domPathAndNames, eStructuralFeature, eClass); - this.children = children; - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature, TranslatorPath translatorPath) { - super(domPathAndNames, eStructuralFeature, translatorPath); - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature, TranslatorPath[] translatorPaths) { - super(domPathAndNames, eStructuralFeature, translatorPaths); - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature, int style) { - super(domPathAndNames, eStructuralFeature, style); - } - - public SimpleTranslator(String domPathAndNames, EStructuralFeature eStructuralFeature, int style, Translator[] children) { - super(domPathAndNames, eStructuralFeature, style); - this.children = children; - } - - - // ********** children ********** - - /** - * Widen method access to 'public'. - */ - @Override - public Translator[] getChildren() { - return this.children; - } - - protected Translator[] getChildren_() { - return (this.children == null) ? EMPTY_TRANSLATOR_ARRAY : this.children; - } - protected static final Translator[] EMPTY_TRANSLATOR_ARRAY = new Translator[0]; - - /** - * Set the translator's children. - * Return the translator. - */ - public void setChildren(Translator[] children) { - this.children = children; - } - - /** - * Add the specified translator to the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleTranslator addChild(Translator translator) { - this.children = ArrayTools.add(this.getChildren_(), translator); - return this; - } - - /** - * Add the specified translators to the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleTranslator addChildren(Translator[] translators) { - this.children = ArrayTools.addAll(this.getChildren_(), translators); - return this; - } - - /** - * Remove the specified translator from the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleTranslator removeChild(Translator translator) { - this.children = ArrayTools.remove(this.children, translator); - return this; - } - - /** - * Remove the specified translators from the translator's list of children. - * Return the translator for method chaining. - */ - public SimpleTranslator removeChildren(Translator[] translators) { - this.children = ArrayTools.removeAll(this.children, (Object[]) translators); - return this; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java deleted file mode 100644 index 83611f0f35..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.synch; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -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.JptCoreMessages; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * Synchronizes the lists of persistent classes in a persistence unit and a - * persistence project. - */ -public class SynchronizeClassesJob extends WorkspaceJob -{ - private IFile persistenceXmlFile; - - - public SynchronizeClassesJob(IFile file) { - super(JptCoreMessages.SYNCHRONIZE_CLASSES_JOB); - setRule(file.getProject()); - this.persistenceXmlFile = file; - } - - @Override - public IStatus runInWorkspace(final IProgressMonitor monitor) { - monitor.beginTask(JptCoreMessages.SYNCHRONIZING_CLASSES_TASK, 200); - - if (monitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - - final JpaProject jpaProject = JptCorePlugin.getJpaProject(this.persistenceXmlFile.getProject()); - final JpaXmlResource resource = jpaProject.getPersistenceXmlResource(); - if (resource == null) { - //the resource would only be null if the persistence.xml file had an invalid content type - return Status.OK_STATUS; - } - - monitor.worked(25); - - resource.modify(new Runnable() { - public void run() { - XmlPersistence persistence = (XmlPersistence) resource.getRootObject(); - XmlPersistenceUnit persistenceUnit; - - if (persistence.getPersistenceUnits().size() > 0) { - persistenceUnit = persistence.getPersistenceUnits().get(0); - } - else { - persistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - persistenceUnit.setName(jpaProject.getName()); - persistence.getPersistenceUnits().add(persistenceUnit); - } - - persistenceUnit.getClasses().clear(); - - monitor.worked(25); - - for (Iterator<String> stream = mappedClassNames(jpaProject, '$'); stream.hasNext(); ) { - String fullyQualifiedTypeName = stream.next(); - if ( ! mappingFileContains(jpaProject, fullyQualifiedTypeName)) { - XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - classRef.setJavaClass(fullyQualifiedTypeName); - persistenceUnit.getClasses().add(classRef); - } - } - - monitor.worked(100); - } - }); - - monitor.done(); - - return Status.OK_STATUS; - } - - protected Iterator<String> mappedClassNames(final JpaProject jpaProject, final char enclosingTypeSeparator) { - return new TransformationIterator<String, String>(jpaProject.mappedJavaSourceClassNames()) { - @Override - protected String transform(String fullyQualifiedName) { - IType jdtType = SynchronizeClassesJob.this.findType(jpaProject, fullyQualifiedName); - return jdtType.getFullyQualifiedName(enclosingTypeSeparator); - } - }; - } - - protected IType findType(JpaProject jpaProject, String typeName) { - try { - return getJavaProject(jpaProject).findType(typeName); - } catch (JavaModelException ex) { - return null; // ignore exception? - } - } - - public IJavaProject getJavaProject(JpaProject jpaProject) { - return JavaCore.create(jpaProject.getProject()); - } - - boolean mappingFileContains(JpaProject jpaProject, String fullyQualifiedTypeName) { - PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml(); - if (persistenceXml == null) { - return false; - } - Persistence persistence = persistenceXml.getPersistence(); - if (persistence == null) { - return false; - } - if (persistence.persistenceUnitsSize() == 0) { - return false; - } - PersistenceUnit persistenceUnit = persistence.persistenceUnits().next(); - for (MappingFileRef mappingFileRef : CollectionTools.iterable(persistenceUnit.mappingFileRefs())) { - if (mappingFileRef.getPersistentType(fullyQualifiedTypeName) != null) { - return true; - } - } - return false; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/CallbackJobSynchronizer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/CallbackJobSynchronizer.java deleted file mode 100644 index 7ddb587da5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/CallbackJobSynchronizer.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.synchronizers.CallbackSynchronizer; - -/** - * Extend the job synchronizer to notify listeners - * when a synchronization "cycle" is complete; i.e. the synchronization has, - * for the moment, handled every "synchronize" request and quiesced. - * This notification is <em>not</em> guaranteed to occur with <em>every</em> - * synchronization "cycle"; - * since other, unrelated, synchronizations can be triggered concurrently. - */ -public class CallbackJobSynchronizer - extends JobSynchronizer - implements CallbackSynchronizer -{ - private final ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class); - - - // ********** construction ********** - - /** - * Construct a callback job synchronizer that uses the specified job command to - * perform the synchronization. Assign the generated Eclipse job the - * specified name. - */ - public CallbackJobSynchronizer(String jobName, JobCommand command) { - super(jobName, command); - } - - /** - * Construct a callback job synchronizer that uses the specified job command to - * perform the synchronization. Assign the generated Eclipse job the - * specified name and scheduling rule. - */ - public CallbackJobSynchronizer(String jobName, JobCommand command, ISchedulingRule schedulingRule) { - super(jobName, command, schedulingRule); - } - - /** - * Build a job that will let us know when the synchronization has - * quiesced. - */ - @Override - SynchronizationJob buildJob(String jobName, JobCommand command, ISchedulingRule schedulingRule) { - return new CallbackSynchronizationJob(jobName, command, schedulingRule); - } - - - // ********** CallbackSynchronizer implementation ********** - - public void addListener(Listener listener) { - this.listenerList.add(listener); - } - - public void removeListener(Listener listener) { - this.listenerList.remove(listener); - } - - /** - * Notify our listeners. - */ - void synchronizationQuiesced() { - for (Listener listener : this.listenerList.getListeners()) { - listener.synchronizationQuiesced(this); - } - } - - - // ********** synchronization job ********** - - /** - * Extend {@link JobSynchronizer.SynchronizationJob} - * to notify the synchronizer when the synchronization has quiesced - * (i.e. the command has finished executing and there are no further - * requests for synchronization). - * Because synchronization occurs during the job's execution, - * no other thread will be able to - * initiate another synchronization until the synchronizer's listeners have been - * notified. Note also, the synchronizer's listeners can, themselves, - * trigger another synchronization (by directly or indirectly calling - * {@link org.eclipse.jpt.utility.internal.synchronizers.Synchronizer#synchronize()); - * but this synchronization will not occur until <em>after</em> all the - * listeners have been notified. - */ - class CallbackSynchronizationJob - extends SynchronizationJob - { - /** - * When this flag is set to true, the job has been scheduled to run. - * We need this because {@link org.eclipse.core.runtime.jobs.Job Job} - * has no public API for discovering whether a job is "scheduled". - */ - // use 'volatile' because synchronization isn't really required - private volatile boolean scheduled; - - - CallbackSynchronizationJob(String jobName, JobCommand command, ISchedulingRule schedulingRule) { - super(jobName, command, schedulingRule); - this.scheduled = false; - } - - /** - * If we are allowing the job to be scheduled (i.e. {@link #start()} - * was called), set the "scheduled" flag. - */ - @Override - void synchronize() { - if (this.shouldSchedule) { - this.scheduled = true; - } - super.synchronize(); - } - - /** - * Clear the "scheduled" flag; perform the synchronization; and, - * if the "scheduled" flag is still clear (i.e. there have been no - * further calls to {@link #synchronize()}), notify our listeners. - */ - @Override - protected IStatus run(IProgressMonitor monitor) { - this.scheduled = false; - IStatus status = super.run(monitor); - // hmmm - we will notify listeners even when we our job is "stopped"; - // that seems ok... ~bjv - if ( ! this.scheduled) { - CallbackJobSynchronizer.this.synchronizationQuiesced(); - } - return status; - } - - @Override - void stop() { - this.scheduled = false; - super.stop(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/JobCommand.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/JobCommand.java deleted file mode 100644 index f4b1a0d7d0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/JobCommand.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility; - -import java.io.Serializable; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Simple interface for implementing the GOF Command design pattern in an - * Eclipse job. - * <p> - * Provisional API: This interface is part of an interim API that is still - * under development and expected to change significantly before reaching - * stability. It is available at this early stage to solicit feedback from - * pioneering adopters on the understanding that any code that uses this API - * will almost certainly be broken (repeatedly) as the API evolves. - */ -public interface JobCommand { - - /** - * Execute the command. The semantics of the command - * is determined by the contract between the client and server. - * The command should check, as appropriate, whether the specified progress - * monitor is {@link IProgressMonitor#isCanceled() "canceled"}; if it is, - * the command should throw an - * {@link org.eclipse.core.runtime.OperationCanceledException OperationCanceledException}. - * @see IProgressMonitor#isCanceled() - */ - IStatus execute(IProgressMonitor monitor); - - /** - * Singleton implementation of the job command interface that will do - * nothing when executed. - */ - final class Null implements JobCommand, Serializable { - public static final JobCommand INSTANCE = new Null(); - public static JobCommand instance() { - return INSTANCE; - } - // ensure single instance - private Null() { - super(); - } - public IStatus execute(IProgressMonitor arg0) { - return Status.OK_STATUS; - } - @Override - public String toString() { - return "JobCommand.Null"; //$NON-NLS-1$ - } - private static final long serialVersionUID = 1L; - private Object readResolve() { - // replace this object with the singleton - return INSTANCE; - } - } - - /** - * Singleton implementation of the job command interface that will throw an - * exception when executed. - */ - final class Disabled implements JobCommand, Serializable { - public static final JobCommand INSTANCE = new Disabled(); - public static JobCommand instance() { - return INSTANCE; - } - // ensure single instance - private Disabled() { - super(); - } - // throw an exception - public IStatus execute(IProgressMonitor arg0) { - throw new UnsupportedOperationException(); - } - @Override - public String toString() { - return "JobCommand.Disabled"; //$NON-NLS-1$ - } - private static final long serialVersionUID = 1L; - private Object readResolve() { - // replace this object with the singleton - return INSTANCE; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/JobSynchronizer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/JobSynchronizer.java deleted file mode 100644 index ece0020a41..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/JobSynchronizer.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.synchronizers.Synchronizer; - -/** - * This synchronizer will perform synchronizations in an Eclipse job on a - * separate thread, allowing calls to {@link Synchronizer#synchronize()} - * to return immediately. - * <p> - * If necessary, the client-supplied job command should handle any - * exceptions appropriately. Although, the default exception-handling provided - * by the Eclipse Job Framework is probably adequate in most cases:<ul> - * <li>An {@link org.eclipse.core.runtime.OperationCanceledException OperationCanceledException} - * results in a {@link org.eclipse.core.runtime.Status#CANCEL_STATUS CANCEL_STATUS}. - * <li>Any non-{@link ThreadDeath} {@link Throwable} - * results in a {@link org.eclipse.core.runtime.IStatus#ERROR ERROR} - * {@link org.eclipse.core.runtime.IStatus IStatus} - * </ul> - * @see org.eclipse.core.internal.jobs.Worker#run() - */ -public class JobSynchronizer - implements Synchronizer -{ - /** - * The synchronization is performed by this job. The same job is used - * for every start/stop cycle (since a job can be re-started). - */ - private final SynchronizationJob job; - - - // ********** construction ********** - - /** - * Construct a job synchronizer that uses the specified job command to - * perform the synchronization. Assign the generated Eclipse job the - * specified name. - */ - public JobSynchronizer(String jobName, JobCommand command) { - this(jobName, command, null); - } - - /** - * Construct a job synchronizer that uses the specified job command to - * perform the synchronization. Assign the generated Eclipse job the - * specified name and scheduling rule. - */ - public JobSynchronizer(String jobName, JobCommand command, ISchedulingRule schedulingRule) { - super(); - this.job = this.buildJob(jobName, command, schedulingRule); - } - - SynchronizationJob buildJob(String jobName, JobCommand command, ISchedulingRule schedulingRule) { - return new SynchronizationJob(jobName, command, schedulingRule); - } - - - // ********** Synchronizer implementation ********** - - /** - * Allow the job to be scheduled, but postpone the first synchronization - * until requested, via {@link #synchronize()}. - */ - public void start() { - this.job.start(); - } - - /** - * "Schedule" the job. - */ - public void synchronize() { - this.job.synchronize(); - } - - /** - * Wait for the current job execution to complete. - */ - public void stop() { - this.job.stop(); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.job); - } - - - // ********** synchronization job ********** - - /** - * This is the job that gets scheduled by the job synchronizer. - * When the job is run it executes the client-supplied job command. - */ - static class SynchronizationJob extends Job { - /** - * The client-supplied job command that executes every time the job - * runs. - */ - private final JobCommand command; - - /** - * When this flag is set to false, the job does not stop immediately; - * but it will not be scheduled to run again. - */ - // use 'volatile' because synchronization isn't really required - volatile boolean shouldSchedule; - - - SynchronizationJob(String jobName, JobCommand command, ISchedulingRule schedulingRule) { - super(jobName); - if (command == null) { - throw new NullPointerException(); - } - this.command = command; - this.shouldSchedule = false; - this.setRule(schedulingRule); - } - - /** - * Just set the "should schedule" flag so the job <em>can</em> be - * scheduled; but don't actually schedule it. - */ - void start() { - if (this.shouldSchedule) { - throw new IllegalStateException("The Synchronizer was not stopped."); //$NON-NLS-1$ - } - this.shouldSchedule = true; - } - - /** - * Simply re-schedule the job, allowing the current execution - * to run to completion (i.e. do not try to cancel it prematurely). - * This should minimize the number of times the job is re-executed - * (recursively and otherwise). - */ - void synchronize() { - this.schedule(); - } - - @Override - protected IStatus run(IProgressMonitor monitor) { - return this.command.execute(monitor); - } - - /** - * Prevent the job from running again and wait for the current - * execution, if there is any, to end before returning. - */ - void stop() { - if ( ! this.shouldSchedule) { - throw new IllegalStateException("The Synchronizer was not started."); //$NON-NLS-1$ - } - // this will prevent the job from being scheduled to run again - this.shouldSchedule = false; - // this will cancel the job if it has already been scheduled, but is currently WAITING - this.cancel(); - try { - // if the job is currently RUNNING, wait until it is done before returning - this.join(); - } catch (InterruptedException ex) { - // the thread that called #stop() was interrupted while waiting to - // join the synchronization job - ignore; - // 'shouldSchedule' is still set to 'false', so the job loop will still stop - we - // just won't wait around for it... - } - } - - /** - * This is part of the normal {@link Job} behavior. By default, it is - * not used (i.e. it always returns <code>true</code>). - * We implement it here. - */ - @Override - public boolean shouldSchedule() { - return this.shouldSchedule; - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java deleted file mode 100644 index 48bdb82f02..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.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.utility; - -import java.io.IOException; -import java.io.InputStream; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.jpt.core.JptCorePlugin; - -/** - * A collection of utilities for dealing with the Eclipse platform API. - */ -public class PlatformTools { - - /** - * Return the specified file's content type, - * using the Eclipse platform's content type manager. - */ - public static IContentType getContentType(IFile file) { - String fileName = file.getName(); - InputStream fileContents = null; - try { - fileContents = file.getContents(); - } catch (CoreException ex) { - // seems like we can ignore any exception that might occur here; - // e.g. we get a FNFE if the workspace is out of synch with the O/S file system - // JptCorePlugin.log(ex); - - // look for content type based on the file name only(?) - return findContentTypeFor(fileName); - } - - IContentType contentType = null; - try { - contentType = findContentTypeFor(fileContents, fileName); - } catch (IOException ex) { - JptCorePlugin.log(ex); - } finally { - try { - fileContents.close(); - } catch (IOException ex) { - JptCorePlugin.log(ex); - } - } - return contentType; - } - - private static IContentType findContentTypeFor(InputStream fileContents, String fileName) throws IOException { - return getContentTypeManager().findContentTypeFor(fileContents, fileName); - } - - private static IContentType findContentTypeFor(String fileName) { - return getContentTypeManager().findContentTypeFor(fileName); - } - - private static IContentTypeManager getContentTypeManager() { - return Platform.getContentTypeManager(); - } - - private PlatformTools() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleSchedulingRule.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleSchedulingRule.java deleted file mode 100644 index a77b0c03aa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleSchedulingRule.java +++ /dev/null @@ -1,46 +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.utility; - -import org.eclipse.core.runtime.jobs.ISchedulingRule; - -/** - * A job scheduling rule that conflicts only with itself. - */ -public final class SimpleSchedulingRule - implements ISchedulingRule -{ - - // singleton - private static final SimpleSchedulingRule INSTANCE = new SimpleSchedulingRule(); - - /** - * Return the singleton. - */ - public static ISchedulingRule instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SimpleSchedulingRule() { - super(); - } - - public boolean contains(ISchedulingRule rule) { - return rule == this; - } - - public boolean isConflicting(ISchedulingRule rule) { - return rule == this; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleTextRange.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleTextRange.java deleted file mode 100644 index bbb398fc84..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/SimpleTextRange.java +++ /dev/null @@ -1,41 +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.utility; - -import org.eclipse.jpt.core.utility.AbstractTextRange; - -/** - * Straightforward implementation of TextRange. - */ -public class SimpleTextRange extends AbstractTextRange { - private final int offset; - private final int length; - private final int lineNumber; - - public SimpleTextRange(int offset, int length, int lineNumber) { - super(); - this.offset = offset; - this.length = length; - this.lineNumber = lineNumber; - } - - public int getOffset() { - return this.offset; - } - - public int getLength() { - return this.length; - } - - public int getLineNumber() { - return this.lineNumber; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ASTNodeTextRange.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ASTNodeTextRange.java deleted file mode 100644 index 1cb404987c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ASTNodeTextRange.java +++ /dev/null @@ -1,39 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.utility.AbstractTextRange; - -/** - * Adapt an ASTNode to the TextRange interface. - */ -public class ASTNodeTextRange extends AbstractTextRange { - private final ASTNode astNode; - - public ASTNodeTextRange(ASTNode astNode) { - super(); - this.astNode = astNode; - } - - public int getOffset() { - return this.astNode.getStartPosition(); - } - - public int getLength() { - return this.astNode.getLength(); - } - - public int getLineNumber() { - return ((CompilationUnit) this.astNode.getRoot()).getLineNumber(this.getOffset()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractAnnotationAdapter.java deleted file mode 100644 index 09631dee2e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractAnnotationAdapter.java +++ /dev/null @@ -1,165 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Adapt a member and a declaration annotation adapter. - */ -public abstract class AbstractAnnotationAdapter implements AnnotationAdapter { - private final Member member; - private final DeclarationAnnotationAdapter daa; - - - // ********** constructor ********** - - public AbstractAnnotationAdapter(Member member, DeclarationAnnotationAdapter daa) { - super(); - this.member = member; - this.daa = daa; - } - - - // ********** AnnotationAdapter implementation ********** - - public Annotation getAnnotation(CompilationUnit astRoot) { - return this.daa.getAnnotation(this.member.getModifiedDeclaration(astRoot)); - } - - public void newMarkerAnnotation() { - this.edit(this.buildNewMarkerAnnotationEditor()); - } - - public void newSingleMemberAnnotation() { - this.edit(this.buildNewSingleMemberAnnotationEditor()); - } - - public void newNormalAnnotation() { - this.edit(this.buildNewNormalAnnotationEditor()); - } - - public void removeAnnotation() { - this.edit(this.buildRemoveAnnotationEditor()); - } - - public ASTNode getAstNode(CompilationUnit astRoot) { - return this.daa.getAstNode(this.member.getModifiedDeclaration(astRoot)); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.daa); - } - - - // ********** internal methods ********** - - protected void edit(Member.Editor editor) { - this.member.edit(editor); - } - - - // ********** factory methods ********** - - protected Member.Editor buildNewMarkerAnnotationEditor() { - return new NewMarkerAnnotationEditor(this.daa); - } - - protected Member.Editor buildNewSingleMemberAnnotationEditor() { - return new NewSingleMemberAnnotationEditor(this.daa); - } - - protected Member.Editor buildNewNormalAnnotationEditor() { - return new NewNormalAnnotationEditor(this.daa); - } - - protected Member.Editor buildRemoveAnnotationEditor() { - return new RemoveAnnotationEditor(this.daa); - } - - - // ********** member classes ********** - - protected static class NewMarkerAnnotationEditor implements Member.Editor { - private final DeclarationAnnotationAdapter daa; - - NewMarkerAnnotationEditor(DeclarationAnnotationAdapter daa) { - super(); - this.daa = daa; - } - public void edit(ModifiedDeclaration declaration) { - this.daa.newMarkerAnnotation(declaration); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - protected static class NewSingleMemberAnnotationEditor implements Member.Editor { - private final DeclarationAnnotationAdapter daa; - - NewSingleMemberAnnotationEditor(DeclarationAnnotationAdapter daa) { - super(); - this.daa = daa; - } - public void edit(ModifiedDeclaration declaration) { - this.daa.newSingleMemberAnnotation(declaration); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - protected static class NewNormalAnnotationEditor implements Member.Editor { - private final DeclarationAnnotationAdapter daa; - - NewNormalAnnotationEditor(DeclarationAnnotationAdapter daa) { - super(); - this.daa = daa; - } - public void edit(ModifiedDeclaration declaration) { - this.daa.newNormalAnnotation(declaration); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - protected static class RemoveAnnotationEditor implements Member.Editor { - private final DeclarationAnnotationAdapter daa; - - RemoveAnnotationEditor(DeclarationAnnotationAdapter daa) { - super(); - this.daa = daa; - } - public void edit(ModifiedDeclaration declaration) { - this.daa.removeAnnotation(declaration); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractDeclarationAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractDeclarationAnnotationAdapter.java deleted file mode 100644 index 85c4983f16..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,153 +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.utility.jdt; - -import java.util.List; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * - */ -public abstract class AbstractDeclarationAnnotationAdapter implements DeclarationAnnotationAdapter { - private final String annotationName; - - - // ********** constructors ********** - - protected AbstractDeclarationAnnotationAdapter(String annotationName) { - super(); - this.annotationName = annotationName; - } - - - // ********** DeclarationAnnotationAdapter implementation ********** - - public MarkerAnnotation newMarkerAnnotation(ModifiedDeclaration declaration) { - MarkerAnnotation annotation = this.newMarkerAnnotation(declaration.getAst()); - this.addAnnotationAndImport(declaration, annotation); - return annotation; - } - - public SingleMemberAnnotation newSingleMemberAnnotation(ModifiedDeclaration declaration) { - SingleMemberAnnotation annotation = this.newSingleMemberAnnotation(declaration.getAst()); - this.addAnnotationAndImport(declaration, annotation); - return annotation; - } - - public NormalAnnotation newNormalAnnotation(ModifiedDeclaration declaration) { - NormalAnnotation annotation = this.newNormalAnnotation(declaration.getAst()); - this.addAnnotationAndImport(declaration, annotation); - return annotation; - } - - /** - * Add the appropriate import statement, then shorten the annotation's - * name before adding it to the declaration. - */ - protected void addAnnotationAndImport(ModifiedDeclaration declaration, Annotation annotation) { - annotation.setTypeName(declaration.getAst().newName(this.getSourceCodeAnnotationName(declaration))); - this.addAnnotation(declaration, annotation); - } - - /** - * Return the annotation's name as it can be used in source code; - * i.e. if we can add it to the compilation unit's imports, return the short - * name; if we can't (because of a collision), return the fully-qualified name. - * NB: an import may be added as a side-effect :-( - */ - protected String getSourceCodeAnnotationName(ModifiedDeclaration declaration) { - return declaration.addImport(this.annotationName) ? this.getShortAnnotationName() : this.annotationName; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.annotationName); - } - - /** - * Add the specified annotation to the specified declaration, - * replacing the original annotation if present. - */ - protected abstract void addAnnotation(ModifiedDeclaration declaration, Annotation annotation); - - - // ********** public methods ********** - - /** - * This is 'public' because we use it in CombinationIndexedDeclarationAnnotationAdapter - * to get the annotation name from a NestedIndexedDeclarationAnnotationAdapter. - */ - public String getAnnotationName() { - return this.annotationName; - } - - - // ********** helper methods ********** - - protected boolean nameMatches(ModifiedDeclaration declaration, Annotation annotation) { - return this.nameMatches(declaration, annotation, this.annotationName); - } - - protected boolean nameMatches(ModifiedDeclaration declaration, Annotation annotation, String name) { - return declaration.annotationIsNamed(annotation, name); - } - - protected MarkerAnnotation newMarkerAnnotation(AST ast) { - return this.newMarkerAnnotation(ast, this.annotationName); - } - - protected MarkerAnnotation newMarkerAnnotation(AST ast, String name) { - MarkerAnnotation annotation = ast.newMarkerAnnotation(); - annotation.setTypeName(ast.newName(name)); - return annotation; - } - - protected SingleMemberAnnotation newSingleMemberAnnotation(AST ast) { - return this.newSingleMemberAnnotation(ast, this.annotationName); - } - - protected SingleMemberAnnotation newSingleMemberAnnotation(AST ast, String name) { - SingleMemberAnnotation annotation = ast.newSingleMemberAnnotation(); - annotation.setTypeName(ast.newName(name)); - return annotation; - } - - protected NormalAnnotation newNormalAnnotation(AST ast) { - return this.newNormalAnnotation(ast, this.annotationName); - } - - protected NormalAnnotation newNormalAnnotation(AST ast, String name) { - NormalAnnotation annotation = ast.newNormalAnnotation(); - annotation.setTypeName(ast.newName(name)); - return annotation; - } - - protected String getShortAnnotationName() { - return convertToShortName(this.annotationName); - } - - protected static String convertToShortName(String name) { - return name.substring(name.lastIndexOf('.') + 1); - } - - @SuppressWarnings("unchecked") - protected List<MemberValuePair> values(NormalAnnotation na) { - return na.values(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractExpressionConverter.java deleted file mode 100644 index a4bde672a8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractExpressionConverter.java +++ /dev/null @@ -1,82 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Gather together the common implementation behavior. - * T is the type of the object to be converted to and from an expression. - * - * We're still figuring out Java Generics here.... The methods in this abstract - * class work fine with any subclass of Expression E; but a ClassCastException - * will occur as soon as we call any method implemented by a subclass - * (e.g. StringExpressionConverter) that expects a particular subclass of - * Expression (e.g. StringLiteral). - */ -public abstract class AbstractExpressionConverter<T> - implements ExpressionConverter<T> -{ - - protected AbstractExpressionConverter() { - super(); - } - - - // ********** object -> expression ********** - - public Expression convert(T object, AST ast) { - return (object == null) ? this.convertNull(ast) : this.convertObject(object, ast); - } - - /** - * Return the expression for a null object. By default, a null object will - * be converted into a null expression. - */ - protected Expression convertNull(@SuppressWarnings("unused") AST ast) { - return null; - } - - /** - * The specified object is not null. - * @see #convert(T, AST) - */ - protected abstract Expression convertObject(T object, AST ast); - - - // ********** expression -> object ********** - - public T convert(Expression expression) { - return (expression == null) ? this.convertNull() : this.convertExpression(expression); - } - - /** - * Return the object for a null expression. By default, a null expression will - * be converted into a null object. - */ - protected T convertNull() { - return null; - } - - /** - * The specified expression is not null. - * @see #convert(Expression) - */ - protected abstract T convertExpression(Expression expression); - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractNestedDeclarationAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractNestedDeclarationAnnotationAdapter.java deleted file mode 100644 index 9606e65926..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractNestedDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,422 +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.utility.jdt; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Pull together some of the behavior common to NestedDeclarationAnnotationAdapter - * and IndexedNestedDeclarationAnnotationAdapter - */ -public abstract class AbstractNestedDeclarationAnnotationAdapter extends AbstractDeclarationAnnotationAdapter { - private final DeclarationAnnotationAdapter outerAnnotationAdapter; - private final String elementName; - private final boolean removeOuterAnnotationWhenEmpty; - - // reduce NLS checks - protected static final String VALUE = "value"; //$NON-NLS-1$ - - - // ********** constructors ********** - - /** - * default element name is "value"; - * default behavior is to remove the outer annotation when it is empty - */ - protected AbstractNestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String annotationName) { - this(outerAnnotationAdapter, VALUE, annotationName); - } - - /** - * default behavior is to remove the outer annotation when it is empty - */ - protected AbstractNestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String elementName, String annotationName) { - this(outerAnnotationAdapter, elementName, annotationName, true); - } - - protected AbstractNestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String elementName, String annotationName, boolean removeOuterAnnotationWhenEmpty) { - super(annotationName); - this.outerAnnotationAdapter = outerAnnotationAdapter; - this.elementName = elementName; - this.removeOuterAnnotationWhenEmpty = removeOuterAnnotationWhenEmpty; - } - - - // ********** DeclarationAnnotationAdapter implementation ********** - - public Annotation getAnnotation(ModifiedDeclaration declaration) { - Annotation outer = this.outerAnnotationAdapter.getAnnotation(declaration); - if (outer == null) { - return null; - } - Expression value = this.elementValue(outer); - if (value == null) { - return null; - } - Annotation inner = this.getAnnotation(value); - if (inner == null) { - return null; - } - // return the annotation only if it has a matching name(?) - return this.nameMatches(declaration, inner) ? inner : null; - } - - public void removeAnnotation(ModifiedDeclaration declaration) { - Annotation outer = this.outerAnnotationAdapter.getAnnotation(declaration); - if (outer == null) { - return; - } - Expression value = this.elementValue(outer); - if (value == null) { - return; - } - // hack to allow short-circuit when the value is an array initializer - if (this.removeAnnotation(declaration, outer, value)) { - return; - } - Annotation inner = this.annotationValue(value); - if (inner == null) { - return; - } - // remove the annotation only if it has a matching name(?) - if (this.nameMatches(declaration, inner)) { - this.removeElementAndNormalize(declaration, outer); - } - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - // if the annotation is missing, return the outer annotation's node - Annotation annotation = this.getAnnotation(declaration); - return (annotation != null) ? annotation : this.outerAnnotationAdapter.getAstNode(declaration); - } - - @Override - protected void addAnnotation(ModifiedDeclaration declaration, Annotation inner) { - Annotation outer = this.outerAnnotationAdapter.getAnnotation(declaration); - if (outer == null) { - this.buildNewOuterAnnotation(declaration, inner); - } else if (outer.isMarkerAnnotation()) { - this.modifyAnnotation(declaration, (MarkerAnnotation) outer, inner); - } else if (outer.isSingleMemberAnnotation()) { - this.modifyAnnotation(declaration, (SingleMemberAnnotation) outer, inner); - } else if (outer.isNormalAnnotation()) { - this.modifyAnnotation(declaration, (NormalAnnotation) outer, inner); - } else { - throw new IllegalStateException("unknown annotation type: " + outer); //$NON-NLS-1$ - } - } - - - // ********** abstract methods ********** - - /** - * Return an annotation extracted from the specified expression, - * which is the value of the adapter's element. - */ - protected abstract Annotation getAnnotation(Expression value); - - /** - * Remove the annotation from the specified expression, - * which is the value of the adapter's element. - * Return whether the removal was successful. - */ - protected abstract boolean removeAnnotation(ModifiedDeclaration declaration, Annotation outer, Expression value); - - /** - * Set the value of the specified outer annotation to the - * specified inner annotation. - */ - protected abstract void modifyAnnotationValue(SingleMemberAnnotation outer, Annotation inner); - - /** - * Set the value of the specified member value pair to the - * specified inner annotation. - */ - protected abstract void modifyMemberValuePair(MemberValuePair pair, Annotation inner); - - - // ********** public methods ********** - - public DeclarationAnnotationAdapter getOuterAnnotationAdapter() { - return this.outerAnnotationAdapter; - } - - public String getElementName() { - return this.elementName; - } - - - // ********** internal methods ********** - - /** - * If the specified expression is an annotation, cast it to an annotation; - * otherwise return null. - */ - protected Annotation annotationValue(Expression expression) { - switch (expression.getNodeType()) { - case ASTNode.NORMAL_ANNOTATION: - case ASTNode.SINGLE_MEMBER_ANNOTATION: - case ASTNode.MARKER_ANNOTATION: - return (Annotation) expression; - default: - return null; - } - } - - /** - * Remove the *first* annotation element with the specified name - * from the specified annotation, converting the annotation as appropriate. - */ - protected void removeElementAndNormalize(ModifiedDeclaration declaration, Annotation outer) { - if (outer.isNormalAnnotation()) { - this.removeElementAndNormalize(declaration, (NormalAnnotation) outer); - } else if (outer.isSingleMemberAnnotation()) { - this.removeElementAndNormalize(declaration, (SingleMemberAnnotation) outer); - } else if (outer.isMarkerAnnotation()) { - this.removeElementAndNormalize(declaration, (MarkerAnnotation) outer); - } else { - throw new IllegalArgumentException("unknown annotation type: " + outer); //$NON-NLS-1$ - } - } - - /** - * Remove the *first* annotation element with the adapter's element name - * from the specified annotation. Convert the annotation to - * a marker annotation or single member annotation if appropriate. - * <pre> - * @Outer(name="Fred", foo=@Inner) => @Outer(name="Fred") - * @Outer(foo=@Inner) => @Outer - * </pre> - */ - protected void removeElementAndNormalize(ModifiedDeclaration declaration, NormalAnnotation outer) { - this.removeElement(outer); - this.normalizeAnnotation(declaration, outer); - } - - /** - * Remove from the specified annotation the element with - * the adapter's element name. - */ - protected void removeElement(NormalAnnotation annotation) { - for (Iterator<MemberValuePair> stream = this.values(annotation).iterator(); stream.hasNext(); ) { - MemberValuePair pair = stream.next(); - if (pair.getName().getFullyQualifiedName().equals(this.elementName)) { - stream.remove(); - break; - } - } - } - - /** - * Convert the specified normal annotation to a marker annotation or - * single member annotation if appropriate. - */ - protected void normalizeAnnotation(ModifiedDeclaration declaration, NormalAnnotation outer) { - List<MemberValuePair> values = this.values(outer); - switch (values.size()) { - case 0: - // if the elements are all gone, remove the annotation or convert it to a marker annotation - if (this.removeOuterAnnotationWhenEmpty) { - this.outerAnnotationAdapter.removeAnnotation(declaration); - } else { - // convert the annotation to a marker annotation - this.outerAnnotationAdapter.newMarkerAnnotation(declaration); - } - break; - case 1: - MemberValuePair pair = values.get(0); - if (pair.getName().getFullyQualifiedName().equals(VALUE)) { - // if the last remaining element is 'value', convert the annotation to a single member annotation - Expression vv = pair.getValue(); - vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); - this.outerAnnotationAdapter.newSingleMemberAnnotation(declaration).setValue(vv); - } - break; - default: - // do nothing - break; - } - } - - /** - * Convert the specified single member annotation to a marker annotation - * if the adapter's element name is "value". - */ - protected void removeElementAndNormalize(ModifiedDeclaration declaration, @SuppressWarnings("unused") SingleMemberAnnotation outer) { - if (this.elementName.equals(VALUE)) { - if (this.removeOuterAnnotationWhenEmpty) { - this.outerAnnotationAdapter.removeAnnotation(declaration); - } else { - // convert the annotation to a marker annotation - this.outerAnnotationAdapter.newMarkerAnnotation(declaration); - } - } - } - - protected void removeElementAndNormalize(ModifiedDeclaration declaration, @SuppressWarnings("unused") MarkerAnnotation outer) { - if (this.removeOuterAnnotationWhenEmpty) { - this.outerAnnotationAdapter.removeAnnotation(declaration); - } - } - - /** - * Return the value of the *first* annotation element - * with the adapter's element name. - * Return null if the annotation has no such element. - * (An element name of "value" will return the value of a single - * member annotation.) - */ - protected Expression elementValue(Annotation annotation) { - if (annotation.isNormalAnnotation()) { - return this.elementValue((NormalAnnotation) annotation); - } - if (annotation.isSingleMemberAnnotation()) { - return this.elementValue((SingleMemberAnnotation) annotation); - } - return null; - } - - protected Expression elementValue(NormalAnnotation annotation) { - MemberValuePair pair = this.memberValuePair(annotation); - return (pair == null) ? null : pair.getValue(); - } - - /** - * If the adapter's element name is "value", return the value of the - * annotation, otherwise return null. - */ - protected Expression elementValue(SingleMemberAnnotation annotation) { - return this.elementName.equals(VALUE) ? annotation.getValue() : null; - } - - /** - * Return the *first* member value pair for the adapter's element name. - * Return null if the specified annotation has no such element. - */ - protected MemberValuePair memberValuePair(NormalAnnotation annotation) { - for (MemberValuePair pair : this.values(annotation)) { - if (pair.getName().getFullyQualifiedName().equals(this.elementName)) { - return pair; - } - } - return null; - } - - /** - * Build a new outer annotation and add the specified - * inner annotation to it: - * <pre> - * @Outer(@Inner) - * </pre> - * or - * <pre> - * @Outer(foo=@Inner) - * </pre> - */ - protected void buildNewOuterAnnotation(ModifiedDeclaration declaration, Annotation inner) { - if (this.elementName.equals(VALUE)) { - this.outerAnnotationAdapter.newSingleMemberAnnotation(declaration).setValue(this.buildNewInnerExpression(inner)); - } else { - List<MemberValuePair> values = this.values(this.outerAnnotationAdapter.newNormalAnnotation(declaration)); - values.add(this.newMemberValuePair(this.buildNewInnerExpression(inner))); - } - } - - /** - * Build an expression to be added to a new outer annotation - * for the specified inner annotation. - */ - protected abstract Expression buildNewInnerExpression(Annotation inner); - - /** - * Build a new member value pair with the specified name and value. - */ - protected MemberValuePair newMemberValuePair(String name, Expression value) { - AST ast = value.getAST(); - MemberValuePair pair = ast.newMemberValuePair(); - pair.setName(ast.newSimpleName(name)); - pair.setValue(value); - return pair; - } - - /** - * Build a new member value pair with the adapter's element name - * and the specified inner annotation. - */ - protected MemberValuePair newMemberValuePair(Expression value) { - return this.newMemberValuePair(this.elementName, value); - } - - /** - * Add the specified inner annotation to the marker annotation. - */ - protected void modifyAnnotation(ModifiedDeclaration declaration, @SuppressWarnings("unused") MarkerAnnotation outer, Annotation inner) { - this.buildNewOuterAnnotation(declaration, inner); - } - - /** - * Add the specified inner annotation to the single member annotation. - */ - protected void modifyAnnotation(ModifiedDeclaration declaration, SingleMemberAnnotation outer, Annotation inner) { - if (this.elementName.equals(VALUE)) { - this.modifyAnnotationValue(outer, inner); - } else { - this.modifyAnnotationNonValue(declaration, outer, inner); - } - } - - /** - * Add the specified inner annotation to the single member annotation, - * converting it to a normal annotation: - * <pre> - * @Outer("lorem ipsum") => @Outer(value="lorem ipsum", foo=@Inner) - * </pre> - */ - protected void modifyAnnotationNonValue(ModifiedDeclaration declaration, SingleMemberAnnotation outer, Annotation inner) { - Expression vv = outer.getValue(); - vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); - NormalAnnotation newOuter = this.outerAnnotationAdapter.newNormalAnnotation(declaration); - List<MemberValuePair> values = this.values(newOuter); - values.add(this.newMemberValuePair(VALUE, vv)); - values.add(this.newMemberValuePair(this.buildNewInnerExpression(inner))); - } - - /** - * Add the specified inner annotation to the normal annotation: - * <pre> - * @Outer(bar="lorem ipsum") => @Outer(bar="lorem ipsum", foo=@Inner) - * </pre> - * or - * <pre> - * @Outer(foo=@Inner("lorem ipsum")) => @Outer(foo=@Inner) - * </pre> - */ - protected void modifyAnnotation(@SuppressWarnings("unused") ModifiedDeclaration declaration, NormalAnnotation outer, Annotation inner) { - MemberValuePair pair = this.memberValuePair(outer); - if (pair == null) { - List<MemberValuePair> values = this.values(outer); - values.add(this.newMemberValuePair(inner)); - } else { - this.modifyMemberValuePair(pair, inner); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AnnotationStringArrayExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AnnotationStringArrayExpressionConverter.java deleted file mode 100644 index 889b59ea63..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AnnotationStringArrayExpressionConverter.java +++ /dev/null @@ -1,96 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ArrayInitializer; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert an array initializer or single expression to/from an array of - * strings (e.g. {"text0", "text1"}). - * E is the type of the expressions to be found either standalone or - * as elements in the array initializer. - */ -public class AnnotationStringArrayExpressionConverter - extends AbstractExpressionConverter<String[]> -{ - private final ExpressionConverter<String> elementConverter; - private final StringArrayExpressionConverter arrayConverter; - - - /** - * The default behavior is to remove the array initializer if it is empty. - */ - public AnnotationStringArrayExpressionConverter(ExpressionConverter<String> elementConverter) { - this(elementConverter, true); - } - - public AnnotationStringArrayExpressionConverter(ExpressionConverter<String> elementConverter, boolean removeArrayInitializerWhenEmpty) { - super(); - this.elementConverter = elementConverter; - this.arrayConverter = new StringArrayExpressionConverter(elementConverter, removeArrayInitializerWhenEmpty); - } - - /** - * if we only have a single string in the array return the single expression, - * without braces, instead of an array initializer - */ - @Override - protected Expression convertObject(String[] strings, AST ast) { - return (strings.length == 1) ? - this.elementConverter.convert(strings[0], ast) - : - this.arrayConverter.convertObject(strings, ast); - } - - @Override - protected String[] convertNull() { - return this.arrayConverter.convertNull(); - } - - /** - * check for a single expression with no surrounding braces, implying a - * single-entry array - */ - @Override - protected String[] convertExpression(Expression expression) { - return (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) ? - this.arrayConverter.convertArrayInitializer((ArrayInitializer) expression) - : - new String[] {this.elementConverter.convert(expression)}; - } - - - // ********** factory methods ********** - - /** - * Build an expression converter for an annotation element of type String[]. - * @Foo(bar={"text0", "text1"}) - * or - * @Foo(bar="text0") - */ - public static AnnotationStringArrayExpressionConverter forStrings() { - return new AnnotationStringArrayExpressionConverter(StringExpressionConverter.instance()); - } - - /** - * Build an expression converter for an annotation element of type <enum>[]. - * @Foo(bar={BAZ, BAT}) - * or - * @Foo(bar=BAZ) - */ - public static AnnotationStringArrayExpressionConverter forNames() { - return new AnnotationStringArrayExpressionConverter(NameStringExpressionConverter.instance()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/BooleanExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/BooleanExpressionConverter.java deleted file mode 100644 index d6fc40d886..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/BooleanExpressionConverter.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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.BooleanLiteral; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a boolean literal to/from a Boolean - * (e.g. Boolean.TRUE). - */ -public final class BooleanExpressionConverter - extends AbstractExpressionConverter<Boolean> -{ - private static final ExpressionConverter<Boolean> INSTANCE = new BooleanExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<Boolean> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private BooleanExpressionConverter() { - super(); - } - - @Override - protected BooleanLiteral convertObject(Boolean booleanObject, AST ast) { - return ast.newBooleanLiteral(booleanObject.booleanValue()); - } - - @Override - protected Boolean convertExpression(Expression expression) { - Object value = expression.resolveConstantExpressionValue(); - return (value instanceof Boolean) ? ((Boolean) value) : null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/CharacterStringExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/CharacterStringExpressionConverter.java deleted file mode 100644 index 1da206b188..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/CharacterStringExpressionConverter.java +++ /dev/null @@ -1,53 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.CharacterLiteral; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a character literal to/from a string representation of a character - * (e.g. "A"). - */ -public final class CharacterStringExpressionConverter - extends AbstractExpressionConverter<String> -{ - private static final ExpressionConverter<String> INSTANCE = new CharacterStringExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<String> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private CharacterStringExpressionConverter() { - super(); - } - - @Override - protected CharacterLiteral convertObject(String string, AST ast) { - CharacterLiteral characterLiteral = ast.newCharacterLiteral(); - characterLiteral.setCharValue(string.charAt(0)); - return characterLiteral; - } - - @Override - protected String convertExpression(Expression expression) { - Object value = expression.resolveConstantExpressionValue(); - return (value instanceof Character) ? ((Character) value).toString() : null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapter.java deleted file mode 100644 index e43a30e97c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,496 +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.utility.jdt; - -import java.util.List; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Manipulate an annotation that either occurs stand-alone, e.g. - * <pre> - * @Inner("zero") - * private int id; - * </pre> - * - * or is embedded in an element array within another annotation, e.g. - * <pre> - * @Outer(foo={@Inner("zero"), @Inner("one"), @Inner("two")}) - * private int id; - * - * annotationName = "Inner" - * containerAnnotationName = "Outer" - * elementName = "foo" - * index = 0-2 - * </pre> - * - * This is a useful pattern because a declaration cannot have more - * than one annotation of the same type, and allowing the stand-alone - * configuration reduces clutter. - * <br> - * NB: This configuration only makes sense for "top-level" annotations, as - * opposed to "nested" annotations. This is because annotation elements - * can only be declared with a type of a single annotation and annotations - * cannot be part of an inheritance hierarchy. - * For example, the following configurations cannot *both* be supported: - * <pre> - * @Foo(bar=@Outer(...)) - * private int id; - * - * @Foo(bar=@Inner(...)) // not allowed - * private int id; - * </pre> - * - * NB: Behavior is undefined when both the stand-alone and the nested - * configurations annotate the same declaration, e.g. - * <pre> - * // undefined behavior - * @Inner("zero") - * @Outer(foo={@Inner("zero"), @Inner("one"), @Inner("two")}) - * private int id; - * </pre> - */ -public class CombinationIndexedDeclarationAnnotationAdapter - implements IndexedDeclarationAnnotationAdapter -{ - - /** - * this adapter is used when the annotation is "stand-alone": - * <pre> - * @Inner("zero") - * </pre> - * and is only used when the index is 0 or 1 - */ - private final SimpleDeclarationAnnotationAdapter standAloneAnnotationAdapter; - - /** - * this adapter is used when the annotation is "nested": - * <pre> - * @Outer(foo={@Inner("zero"), @Inner("one")}) - * </pre> - */ - private final NestedIndexedDeclarationAnnotationAdapter nestedAnnotationAdapter; - - /** - * this adapter is for the "nested" annotation at the zero index; - * and is only used when the index is 1 - */ - private final NestedIndexedDeclarationAnnotationAdapter zeroNestedAnnotationAdapter; - - // reduce NLS checks - protected static final String VALUE = "value"; //$NON-NLS-1$ - - - // ********** constructors ********** - - /** - * default element name is "value" - * <pre> - * @Inner("zero") - * @Outer({@Inner("zero"), @Inner("one")}) - * </pre> - */ - public CombinationIndexedDeclarationAnnotationAdapter(String annotationName, String containerAnnotationName, int index) { - this(annotationName, containerAnnotationName, VALUE, index); - } - - public CombinationIndexedDeclarationAnnotationAdapter(String annotationName, String containerAnnotationName, String elementName, int index) { - this(new SimpleDeclarationAnnotationAdapter(annotationName), new SimpleDeclarationAnnotationAdapter(containerAnnotationName), elementName, index, annotationName); - } - - /** - * default element name is "value" - */ - public CombinationIndexedDeclarationAnnotationAdapter( - SimpleDeclarationAnnotationAdapter standAloneAnnotationAdapter, - SimpleDeclarationAnnotationAdapter containerAnnotationAdapter, - int index, - String nestedAnnotationName - ) { - this(standAloneAnnotationAdapter, containerAnnotationAdapter, VALUE, index, nestedAnnotationName); - } - - public CombinationIndexedDeclarationAnnotationAdapter( - SimpleDeclarationAnnotationAdapter standAloneAnnotationAdapter, - SimpleDeclarationAnnotationAdapter containerAnnotationAdapter, - String elementName, - int index, - String nestedAnnotationName - ) { - super(); - this.standAloneAnnotationAdapter = standAloneAnnotationAdapter; - this.nestedAnnotationAdapter = new NestedIndexedDeclarationAnnotationAdapter(containerAnnotationAdapter, elementName, index, nestedAnnotationName); - this.zeroNestedAnnotationAdapter = new NestedIndexedDeclarationAnnotationAdapter(containerAnnotationAdapter, elementName, 0, nestedAnnotationName); - } - - - // ********** DeclarationAnnotationAdapter implementation ********** - - public Annotation getAnnotation(ModifiedDeclaration declaration) { - if (this.getIndex() == 0) { - // check for the stand-alone annotation - Annotation standAloneAnnotation = this.getStandAloneAnnotation(declaration); - if (standAloneAnnotation != null) { - return standAloneAnnotation; - } - } - return this.getNestedAnnotation(declaration); - } - - /** - * <pre> - * [none] => @Inner - * or - * @Inner("lorem ipsum") => @Inner - * or - * @Inner(text="lorem ipsum") => @Inner - * or - * @Outer(foo={@Inner, @Inner}) => @Outer(foo={@Inner, @Inner, @Inner}) - * or - * @Outer(foo=@Inner) => @Outer(foo={@Inner, @Inner}) - * or - * @Inner => @Outer(foo={@Inner, @Inner}) - * etc. - * </pre> - */ - public MarkerAnnotation newMarkerAnnotation(ModifiedDeclaration declaration) { - return (MarkerAnnotation) this.newAnnotation(MARKER_ANNOTATION_FACTORY, declaration); - } - - public SingleMemberAnnotation newSingleMemberAnnotation(ModifiedDeclaration declaration) { - return (SingleMemberAnnotation) this.newAnnotation(SINGLE_MEMBER_ANNOTATION_FACTORY, declaration); - } - - public NormalAnnotation newNormalAnnotation(ModifiedDeclaration declaration) { - return (NormalAnnotation) this.newAnnotation(NORMAL_ANNOTATION_FACTORY, declaration); - } - - public void removeAnnotation(ModifiedDeclaration declaration) { - if (this.getIndex() == 0) { - // check for the stand-alone annotation - if (this.standAloneAnnotationIsPresent(declaration)) { - this.removeStandAloneAnnotation(declaration); - return; - } - } - this.removeNestedAnnotation(declaration); - if (this.nestedElementCanBeConvertedToStandAlone(declaration)) { - this.convertLastElementAnnotationToStandAloneAnnotation(declaration); - } - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - // if the annotation is missing, delegate to the nested annotation adapter - Annotation annotation = this.getAnnotation(declaration); - return (annotation != null) ? annotation : this.nestedAnnotationAdapter.getAstNode(declaration); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getAnnotationName()); - } - - - // ********** IndexedDeclarationAnnotationAdapter implementation ********** - - public int getIndex() { - return this.nestedAnnotationAdapter.getIndex(); - } - - public void moveAnnotation(int newIndex, ModifiedDeclaration declaration) { - int oldIndex = this.getIndex(); - if (newIndex == oldIndex) { - return; - } - - Annotation standAloneAnnotation = this.getStandAloneAnnotation(declaration); - if (standAloneAnnotation == null) { - this.moveNestedAnnotation(newIndex, declaration); - if (this.nestedElementCanBeConvertedToStandAlone(declaration)) { - this.convertLastElementAnnotationToStandAloneAnnotation(declaration); - } - } else { - if ((oldIndex == 0) && (newIndex == 1)) { - // this is one of two situations where we transition from standalone to container - this.moveStandAloneAnnotationToContainerAnnotation(standAloneAnnotation, declaration); - this.moveNestedAnnotation(newIndex, declaration); - } else if (newIndex == 0) { - // we are moving a 'null' entry on top of the standalone, so remove it - this.removeStandAloneAnnotation(declaration); - } else { - throw new IllegalStateException("old index = " + oldIndex + "; new index = " + newIndex); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - - - // ********** internal methods ********** - - /** - * build the appropriate new annotation, - * which may require moving the 0th annotation from "stand-alone" to "nested" - */ - private Annotation newAnnotation(AnnotationFactory annotationFactory, ModifiedDeclaration declaration) { - if (this.getIndex() == 0) { - return this.newZeroAnnotation(annotationFactory, declaration); - } - if (this.zeroNestedAnnotationIsPresent(declaration)) { - // manipulate the container annotation - ignore the stand-alone annotation(?) - // @Outer(foo=@Inner("zero")) => @Outer(foo={@Inner("zero"), @Inner}) - // or - // @Outer(foo={@Inner("zero"), @Inner("one")}) => @Outer(foo={@Inner("zero"), @Inner}) - return annotationFactory.newAnnotation(this.nestedAnnotationAdapter, declaration); - } - - // this is one of two situations where we transition from standalone to container - this.moveStandAloneAnnotationToContainerAnnotation(declaration); - // once the stand-alone annotation is moved to index=0, build the new annotation at index=1 - return annotationFactory.newAnnotation(this.nestedAnnotationAdapter, declaration); - } - - /** - * the index is 0 - build the appropriate new annotation, - * which may be either "stand-alone" or "nested" - */ - private Annotation newZeroAnnotation(AnnotationFactory annotationFactory, ModifiedDeclaration declaration) { - if (this.standAloneAnnotationIsPresent(declaration)) { - // replace the stand-alone annotation - ignore the container annotation(?) - // @Inner(text="lorem ipsum") => @Inner - return annotationFactory.newAnnotation(this.standAloneAnnotationAdapter, declaration); - } - if (this.containerAnnotationIsPresent(declaration)) { - // manipulate the container annotation - // @Outer(foo=@Inner(text="lorem ipsum")) => @Outer(foo=@Inner) - return annotationFactory.newAnnotation(this.nestedAnnotationAdapter, declaration); - } - // neither annotation is present - add a new stand-alone annotation - return annotationFactory.newAnnotation(this.standAloneAnnotationAdapter, declaration); - } - - /** - * move the stand-alone annotation to the container annotation at index=0 - */ - private void moveStandAloneAnnotationToContainerAnnotation(ModifiedDeclaration declaration) { - Annotation standAloneAnnotation = this.getStandAloneAnnotation(declaration); - if (standAloneAnnotation == null) { - throw new IllegalStateException("the stand-alone annotation is missing"); //$NON-NLS-1$ - } - this.moveStandAloneAnnotationToContainerAnnotation(standAloneAnnotation, declaration); - } - - /** - * move the specified, non-null, stand-alone annotation to - * the container annotation at index=0 - */ - private void moveStandAloneAnnotationToContainerAnnotation(Annotation standAloneAnnotation, ModifiedDeclaration declaration) { - if (standAloneAnnotation.isMarkerAnnotation()) { - this.zeroNestedAnnotationAdapter.newMarkerAnnotation(declaration); - } else if (standAloneAnnotation.isSingleMemberAnnotation()) { - Expression vv = ((SingleMemberAnnotation) standAloneAnnotation).getValue(); - vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); - this.zeroNestedAnnotationAdapter.newSingleMemberAnnotation(declaration).setValue(vv); - } else if (standAloneAnnotation.isNormalAnnotation()) { - NormalAnnotation newNA = this.zeroNestedAnnotationAdapter.newNormalAnnotation(declaration); - List<MemberValuePair> values = this.values(newNA); - for (MemberValuePair pair : this.values((NormalAnnotation) standAloneAnnotation)) { - values.add((MemberValuePair) ASTNode.copySubtree(pair.getAST(), pair)); - } - } else { - throw new IllegalStateException("unknown annotation type: " + standAloneAnnotation); //$NON-NLS-1$ - } - this.removeStandAloneAnnotation(declaration); - } - - /** - * return whether the "nested" annotation container has been reduced to - * a single element (and the array initializer is converted to just - * the single remaining element) and can be further converted to the - * "stand-alone" annotation: - * <pre> - * @Outer(foo={@Inner("zero"), @Inner("one")}) => - * @Outer(foo=@Inner("zero")) => - * @Inner("zero") - * </pre> - */ - private boolean nestedElementCanBeConvertedToStandAlone(ModifiedDeclaration declaration) { - Annotation containerAnnotation = this.getContainerAnnotation(declaration); - if (containerAnnotation == null) { - return false; - } - if (containerAnnotation.isMarkerAnnotation()) { - return false; - } - if (containerAnnotation.isSingleMemberAnnotation()) { - if (this.getElementName().equals(VALUE)) { - return (((SingleMemberAnnotation) containerAnnotation).getValue().getNodeType() != ASTNode.ARRAY_INITIALIZER) - && (this.zeroNestedAnnotationAdapter.getAnnotation(declaration) != null); - } - return false; - } - if (containerAnnotation.isNormalAnnotation()) { - NormalAnnotation na = (NormalAnnotation) containerAnnotation; - if (na.values().size() == 0) { - return false; // there are no elements present - } - if (na.values().size() != 1) { - return false; // there are other elements present - leave them all alone - } - MemberValuePair pair = (MemberValuePair) na.values().get(0); - if (this.getElementName().equals(pair.getName().getFullyQualifiedName())) { - return (pair.getValue().getNodeType() != ASTNode.ARRAY_INITIALIZER) - && (this.zeroNestedAnnotationAdapter.getAnnotation(declaration) != null); - } - return false; - } - throw new IllegalStateException("unknown annotation type: " + containerAnnotation); //$NON-NLS-1$ - } - - /** - * move the annotation in the container annotation at index=0 - * to the stand-alone annotation - */ - private void convertLastElementAnnotationToStandAloneAnnotation(ModifiedDeclaration declaration) { - Annotation last = this.zeroNestedAnnotationAdapter.getAnnotation(declaration); - if (last == null) { - throw new IllegalStateException("the last nested annotation is missing"); //$NON-NLS-1$ - } else if (last.isMarkerAnnotation()) { - this.newStandAloneMarkerAnnotation(declaration); - } else if (last.isSingleMemberAnnotation()) { - Expression vv = ((SingleMemberAnnotation) last).getValue(); - vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); - this.newStandAloneSingleMemberAnnotation(declaration).setValue(vv); - } else if (last.isNormalAnnotation()) { - NormalAnnotation newNA = this.newStandAloneNormalAnnotation(declaration); - List<MemberValuePair> values = this.values(newNA); - for (MemberValuePair pair : this.values((NormalAnnotation) last)) { - values.add((MemberValuePair) ASTNode.copySubtree(pair.getAST(), pair)); - } - } else { - throw new IllegalStateException("unknown annotation type: " + last); //$NON-NLS-1$ - } - this.zeroNestedAnnotationAdapter.removeAnnotation(declaration); - } - - private boolean standAloneAnnotationIsPresent(ModifiedDeclaration declaration) { - return this.getStandAloneAnnotation(declaration) != null; - } - - private Annotation getStandAloneAnnotation(ModifiedDeclaration declaration) { - return this.standAloneAnnotationAdapter.getAnnotation(declaration); - } - - private MarkerAnnotation newStandAloneMarkerAnnotation(ModifiedDeclaration declaration) { - return this.standAloneAnnotationAdapter.newMarkerAnnotation(declaration); - } - - private SingleMemberAnnotation newStandAloneSingleMemberAnnotation(ModifiedDeclaration declaration) { - return this.standAloneAnnotationAdapter.newSingleMemberAnnotation(declaration); - } - - private NormalAnnotation newStandAloneNormalAnnotation(ModifiedDeclaration declaration) { - return this.standAloneAnnotationAdapter.newNormalAnnotation(declaration); - } - - private void removeStandAloneAnnotation(ModifiedDeclaration declaration) { - this.standAloneAnnotationAdapter.removeAnnotation(declaration); - } - - private Annotation getNestedAnnotation(ModifiedDeclaration declaration) { - return this.nestedAnnotationAdapter.getAnnotation(declaration); - } - - private void moveNestedAnnotation(int newIndex, ModifiedDeclaration declaration) { - this.nestedAnnotationAdapter.moveAnnotation(newIndex, declaration); - } - - private void removeNestedAnnotation(ModifiedDeclaration declaration) { - this.nestedAnnotationAdapter.removeAnnotation(declaration); - } - - private boolean containerAnnotationIsPresent(ModifiedDeclaration declaration) { - return this.getContainerAnnotation(declaration) != null; - } - - private Annotation getContainerAnnotation(ModifiedDeclaration declaration) { - return this.nestedAnnotationAdapter.getOuterAnnotationAdapter().getAnnotation(declaration); - } - - private boolean zeroNestedAnnotationIsPresent(ModifiedDeclaration declaration) { - return this.getZeroNestedAnnotation(declaration) != null; - } - - private Annotation getZeroNestedAnnotation(ModifiedDeclaration declaration) { - return this.zeroNestedAnnotationAdapter.getAnnotation(declaration); - } - - private String getAnnotationName() { - return this.nestedAnnotationAdapter.getAnnotationName(); - } - - private String getElementName() { - return this.nestedAnnotationAdapter.getElementName(); - } - - @SuppressWarnings("unchecked") - protected List<MemberValuePair> values(NormalAnnotation na) { - return na.values(); - } - - - // ********** annotation factories ********** - - /** - * define interface that allows us to "re-use" the nasty code in - * #newAnnotation(AnnotationFactory, ModifiedDeclaration) - */ - private interface AnnotationFactory { - Annotation newAnnotation(DeclarationAnnotationAdapter adapter, ModifiedDeclaration declaration); - } - - private static final AnnotationFactory MARKER_ANNOTATION_FACTORY = new AnnotationFactory() { - public Annotation newAnnotation(DeclarationAnnotationAdapter adapter, ModifiedDeclaration declaration) { - return adapter.newMarkerAnnotation(declaration); - } - @Override - public String toString() { - return "MarkerAnnotationFactory"; //$NON-NLS-1$ - } - }; - - private static final AnnotationFactory SINGLE_MEMBER_ANNOTATION_FACTORY = new AnnotationFactory() { - public Annotation newAnnotation(DeclarationAnnotationAdapter adapter, ModifiedDeclaration declaration) { - return adapter.newSingleMemberAnnotation(declaration); - } - @Override - public String toString() { - return "SingleMemberAnnotationFactory"; //$NON-NLS-1$ - } - }; - - private static final AnnotationFactory NORMAL_ANNOTATION_FACTORY = new AnnotationFactory() { - public Annotation newAnnotation(DeclarationAnnotationAdapter adapter, ModifiedDeclaration declaration) { - return adapter.newNormalAnnotation(declaration); - } - @Override - public String toString() { - return "NormalAnnotationFactory"; //$NON-NLS-1$ - } - }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ConversionDeclarationAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ConversionDeclarationAnnotationElementAdapter.java deleted file mode 100644 index 8a70c2230c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ConversionDeclarationAnnotationElementAdapter.java +++ /dev/null @@ -1,203 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Wrap a declaration annotation element adapter that deals with AST - * expressions, converting them to/from various other objects. - * T is the type of the object to be passed to and returned by the adapter. - */ -public class ConversionDeclarationAnnotationElementAdapter<T> - implements DeclarationAnnotationElementAdapter<T> -{ - /** - * The wrapped adapter that returns and takes AST expressions. - */ - private final DeclarationAnnotationElementAdapter<Expression> adapter; - - /** - * The converter that converts AST expressions to other objects - * (e.g. Strings). - */ - private final ExpressionConverter<T> converter; - - - // ********** constructors ********** - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed. - */ - public ConversionDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, ExpressionConverter<T> converter) { - this(new ExpressionDeclarationAnnotationElementAdapter<Expression>(annotationAdapter), converter); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed. - */ - public ConversionDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<T> converter) { - this(new ExpressionDeclarationAnnotationElementAdapter<Expression>(annotationAdapter, elementName), converter); - } - - public ConversionDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty, ExpressionConverter<T> converter) { - this(new ExpressionDeclarationAnnotationElementAdapter<Expression>(annotationAdapter, elementName, removeAnnotationWhenEmpty), converter); - } - - public ConversionDeclarationAnnotationElementAdapter(DeclarationAnnotationElementAdapter<Expression> adapter, ExpressionConverter<T> converter) { - super(); - this.adapter = adapter; - this.converter = converter; - } - - - // ********** DeclarationAnnotationElementAdapter implementation ********** - - public T getValue(ModifiedDeclaration declaration) { - Expression expression = this.adapter.getValue(declaration); - return this.converter.convert(expression); - } - - public void setValue(T value, ModifiedDeclaration declaration) { - Expression expression; - try { - expression = this.converter.convert(value, declaration.getAst()); - } catch (IllegalArgumentException ex) { - // if there is a problem converting the 'value' to an Expression we get this exception - return; // don't set the value if it is "illegal" - } - this.adapter.setValue(expression, declaration); - } - - public Expression getExpression(ModifiedDeclaration declaration) { - return this.adapter.getExpression(declaration); - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - return this.adapter.getAstNode(declaration); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.adapter); - } - - - // ********** factory static methods ********** - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed; - * the default expression converter expects string constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<String> forStrings(DeclarationAnnotationAdapter annotationAdapter) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, StringExpressionConverter.instance()); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed; the default expression converter expects - * string constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<String> forStrings(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, StringExpressionConverter.instance()); - } - - /** - * The default expression converter expects string constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<String> forStrings(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, removeAnnotationWhenEmpty, StringExpressionConverter.instance()); - } - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed; - * the default expression converter expects number constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<Integer> forNumbers(DeclarationAnnotationAdapter annotationAdapter) { - return new ConversionDeclarationAnnotationElementAdapter<Integer>(annotationAdapter, NumberIntegerExpressionConverter.instance()); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed; the default expression converter expects - * number constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<Integer> forNumbers(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Integer>(annotationAdapter, elementName, NumberIntegerExpressionConverter.instance()); - } - - /** - * The default expression converter expects number constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<Integer> forNumbers(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty) { - return new ConversionDeclarationAnnotationElementAdapter<Integer>(annotationAdapter, elementName, removeAnnotationWhenEmpty, NumberIntegerExpressionConverter.instance()); - } - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed; - * the default expression converter expects boolean constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<Boolean> forBooleans(DeclarationAnnotationAdapter annotationAdapter) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(annotationAdapter, BooleanExpressionConverter.instance()); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed; the default expression converter expects - * boolean constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<Boolean> forBooleans(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(annotationAdapter, elementName, BooleanExpressionConverter.instance()); - } - - /** - * The default expression converter expects boolean constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<Boolean> forBooleans(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(annotationAdapter, elementName, removeAnnotationWhenEmpty, BooleanExpressionConverter.instance()); - } - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed; - * the default expression converter expects character constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<String> forCharacters(DeclarationAnnotationAdapter annotationAdapter) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, CharacterStringExpressionConverter.instance()); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed; the default expression converter expects - * character constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<String> forCharacters(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, CharacterStringExpressionConverter.instance()); - } - - /** - * The default expression converter expects character constant expressions. - */ - public static ConversionDeclarationAnnotationElementAdapter<String> forCharacters(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, removeAnnotationWhenEmpty, CharacterStringExpressionConverter.instance()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/DefaultAnnotationEditFormatter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/DefaultAnnotationEditFormatter.java deleted file mode 100644 index 0f6cfd917d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/DefaultAnnotationEditFormatter.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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.utility.jdt; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.text.edits.InsertEdit; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.text.edits.TextEdit; - -/** - * This implementation will clean up some of the nasty Eclipse annotation - * formatting (or lack thereof); e.g. arrays of annotations. - */ -public final class DefaultAnnotationEditFormatter - implements AnnotationEditFormatter -{ - private static final DefaultAnnotationEditFormatter INSTANCE = new DefaultAnnotationEditFormatter(); - - /** - * Return the singleton. - */ - public static DefaultAnnotationEditFormatter instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private DefaultAnnotationEditFormatter() { - super(); - } - - /** - * TODO - */ - public void format(IDocument doc, TextEdit editTree) throws MalformedTreeException, BadLocationException { - TextEdit[] edits = editTree.getChildren(); - int len = edits.length; - if (len == 0) { - return; - } - - MultiTextEdit extraEdits = new MultiTextEdit(); - for (int i = 0; i < len; i++) { - TextEdit edit1 = edits[i]; - if ( ! (edit1 instanceof InsertEdit)) { - continue; // if the edit is not an insert, skip to the next edit - } - InsertEdit insert1 = (InsertEdit) edit1; - int j = i + 1; - if (j < len) { - TextEdit edit2 = edits[j]; - if (edit2 instanceof InsertEdit) { - InsertEdit insert2 = (InsertEdit) edit2; - String text1 = insert1.getText(); - String text2 = insert2.getText(); - int offset1 = insert1.getOffset(); - int offset2 = insert2.getOffset(); - if (this.stringIsAnnotation(text1) && text2.equals(" ")) { - // an annotation was inserted before something on the same line; - // replace the trailing space with a newline and appropriate indent - extraEdits.addChild(new ReplaceEdit(offset2, 1, this.buildCR(doc, offset2))); - i++; // jump the index past 'edit2' - continue; // go to the next edit - } - int comma1Length = this.commaLength(text1); - if ((comma1Length != 0) && this.stringIsAnnotation(text2)) { - // an annotation was inserted in an array initializer on the - // same line as the previous array element; - // replace the preceding space with a newline and appropriate indent - extraEdits.addChild(new ReplaceEdit(offset1 + comma1Length, text1.length() - comma1Length, this.buildCR(doc, offset1))); - i++; // jump the index past 'edit2' - continue; // go to the next edit - } - } - } - this.formatArrayInitializer(doc, insert1, extraEdits); - } - extraEdits.apply(doc, TextEdit.NONE); - } - - /** - * If the insert edit is inserting an annotation containing an array of annotations as - * its value then format them nicely. - */ - private void formatArrayInitializer(IDocument doc, InsertEdit insertEdit, MultiTextEdit extraEdits) throws BadLocationException { - String s = insertEdit.getText(); - if ( ! this.stringIsAnnotation(s)) { - return; - } - int len = s.length(); - int pos = 1; // skip '@' - while (pos < len) { - char c = s.charAt(pos); - pos++; // bump to just past first '(' - if (c == '(') { - break; - } - } - if (pos == len) { - return; // reached end of string - } - while (pos < len) { - char c = s.charAt(pos); - pos++; // bump to just past first '{' - if (c == '{') { - break; - } - if (c != ' ') { - return; - } - } - if (pos == len) { - return; // reached end of string - } - // now look for '@' not inside parentheses and put in - // line delimeter and indent string before each - int offset = insertEdit.getOffset(); - String indent = null; - int parenDepth = 0; - while (pos < len) { - switch (s.charAt(pos)) { - case '(' : - parenDepth++; - break; - case ')' : - parenDepth--; - break; - case '@' : - if (parenDepth == 0) { - if (indent == null) { - indent = this.buildCR(doc, offset, "\t"); // TODO use tab preference? - } - extraEdits.addChild(new InsertEdit(offset + pos, indent)); - } - break; - case '}' : - if (parenDepth == 0) { - extraEdits.addChild(new InsertEdit(offset + pos, this.buildCR(doc, offset))); - } - break; - } - pos++; - } - } - - /** - * Build a string containing a line delimeter and indenting characters - * matching the indent level of the line containing the character offset - * (i.e. the new line's indent matches the current line). - */ - private String buildCR(IDocument doc, int offset) throws BadLocationException { - return this.buildCR(doc, offset, ""); - } - - private String buildCR(IDocument doc, int offset, String suffix) throws BadLocationException { - int line = doc.getLineOfOffset(offset); - StringBuilder sb = new StringBuilder(); - sb.append(doc.getLineDelimiter(line)); // use same CR as current line - - int o = doc.getLineOffset(line); // match the whitespace of the current line - char c = doc.getChar(o++); - while ((c == ' ') || (c == '\t')) { - sb.append(c); - c = doc.getChar(o++); - } - sb.append(suffix); - return sb.toString(); - } - - /** - * Return whether the specified string is an annotation. - */ - private boolean stringIsAnnotation(String string) { - return (string.length() > 1) && string.charAt(0) == '@'; - } - - /** - * If the specified string is a single comma, possibly surrounded by - * spaces, return the length of the substring containing the - * initial spaces and the comma. - */ - private int commaLength(String string) { - boolean comma = false; - int len = string.length(); - int result = 0; - for (int i = 0; i < len; i++) { - switch (string.charAt(i)) { - case ' ' : - if ( ! comma) { - result++; // space preceding comma - } - break; - case ',' : - if (comma) { - return 0; // second comma! - } - comma = true; - result++; - break; - default: - return 0; // non-comma, non-space char - } - } - return result; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumArrayDeclarationAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumArrayDeclarationAnnotationElementAdapter.java deleted file mode 100644 index 31ffe65292..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumArrayDeclarationAnnotationElementAdapter.java +++ /dev/null @@ -1,159 +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.utility.jdt; - -import java.util.List; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ArrayInitializer; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Wrap a declaration annotation element adapter and simply - * add an import for the enums when necessary. - */ -public class EnumArrayDeclarationAnnotationElementAdapter - implements DeclarationAnnotationElementAdapter<String[]> -{ - /** - * The wrapped adapter that returns and takes name strings (enums). - */ - private final ConversionDeclarationAnnotationElementAdapter<String[]> adapter; - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - - // ********** constructors ********** - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed. - */ - public EnumArrayDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter) { - this(annotationAdapter, VALUE); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed and remove the array initializer if it is empty. - */ - public EnumArrayDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - this(annotationAdapter, elementName, true); - } - - /** - * The default behavior is to remove the array initializer if it is empty. - */ - public EnumArrayDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty) { - this(annotationAdapter, elementName, removeAnnotationWhenEmpty, true); - } - - public EnumArrayDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty, boolean removeArrayInitializerWhenEmpty) { - this(new ConversionDeclarationAnnotationElementAdapter<String[]>(annotationAdapter, elementName, removeAnnotationWhenEmpty, buildExpressionConverter(removeArrayInitializerWhenEmpty))); - } - - private static ExpressionConverter<String[]> buildExpressionConverter(boolean removeArrayInitializerWhenEmpty) { - return new AnnotationStringArrayExpressionConverter(NameStringExpressionConverter.instance(), removeArrayInitializerWhenEmpty); - } - - protected EnumArrayDeclarationAnnotationElementAdapter(ConversionDeclarationAnnotationElementAdapter<String[]> adapter) { - super(); - this.adapter = adapter; - } - - - // ********** DeclarationAnnotationElementAdapter implementation ********** - - public String[] getValue(ModifiedDeclaration declaration) { - // ignore the adapter's getValue() - we want the expression - return this.resolve(this.adapter.getExpression(declaration), declaration); - } - - public void setValue(String[] value, ModifiedDeclaration declaration) { - this.adapter.setValue(this.convertToSourceCodeNames(value, declaration), declaration); - } - - public Expression getExpression(ModifiedDeclaration declaration) { - return this.adapter.getExpression(declaration); - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - return this.adapter.getAstNode(declaration); - } - - - // ********** internal methods ********** - - /** - * resolve the enums, which can be - * null - * or - * {FOO, BAR, BAZ} - * or - * FOO - */ - protected String[] resolve(Expression expression, ModifiedDeclaration declaration) { - if (expression == null) { - return EMPTY_STRING_ARRAY; - } else if (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) { - return this.resolveArray((ArrayInitializer) expression, declaration); - } else { - return this.resolveSingleElement(expression, declaration); - } - } - - protected String[] resolveArray(ArrayInitializer ai, @SuppressWarnings("unused") ModifiedDeclaration declaration) { - List<Expression> expressions = this.expressions(ai); - int len = expressions.size(); - String[] enums = new String[len]; - for (int i = len; i-- > 0; ) { - enums[i] = this.resolveEnum(expressions.get(i)); - } - return enums; - } - - protected String[] resolveSingleElement(Expression enumExpression, @SuppressWarnings("unused") ModifiedDeclaration declaration) { - return new String[] {this.resolveEnum(enumExpression)}; - } - - protected String resolveEnum(Expression expression) { - return JDTTools.resolveEnum(expression); - } - - // minimize scope of suppressd warnings - @SuppressWarnings("unchecked") - private List<Expression> expressions(ArrayInitializer arrayInitializer) { - return arrayInitializer.expressions(); - } - - /** - * convert the fully-qualified enums to names that can be inserted in source code - * NB: imports may be added as a side-effect :-( - */ - protected String[] convertToSourceCodeNames(String[] enums, ModifiedDeclaration declaration) { - if (enums == null) { - return null; - } - int len = enums.length; - String[] sourceCodeNames = new String[len]; - for (int i = 0; i < len; i++) { - sourceCodeNames[i] = this.convertToSourceCodeName(enums[i], declaration); - } - return sourceCodeNames; - } - - protected String convertToSourceCodeName(String enum_, ModifiedDeclaration declaration) { - return EnumDeclarationAnnotationElementAdapter.convertToSourceCodeName(enum_, declaration); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumDeclarationAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumDeclarationAnnotationElementAdapter.java deleted file mode 100644 index 4fe7f9c115..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumDeclarationAnnotationElementAdapter.java +++ /dev/null @@ -1,128 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Wrap a declaration annotation element adapter and simply - * add an import for the enum when necessary. - */ -public class EnumDeclarationAnnotationElementAdapter - implements DeclarationAnnotationElementAdapter<String> -{ - /** - * The wrapped adapter that returns and takes name strings (enums). - */ - private final ConversionDeclarationAnnotationElementAdapter<String> adapter; - - - // ********** constructors ********** - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed. - */ - public EnumDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter) { - this(annotationAdapter, VALUE); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed. - */ - public EnumDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - this(annotationAdapter, elementName, true); - } - - public EnumDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty) { - this(new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, removeAnnotationWhenEmpty, NameStringExpressionConverter.instance())); - } - - protected EnumDeclarationAnnotationElementAdapter(ConversionDeclarationAnnotationElementAdapter<String> adapter) { - super(); - this.adapter = adapter; - } - - - // ********** DeclarationAnnotationElementAdapter implementation ********** - - public String getValue(ModifiedDeclaration declaration) { - return this.resolve(this.adapter.getExpression(declaration)); - } - - public void setValue(String value, ModifiedDeclaration declaration) { - this.adapter.setValue(convertToSourceCodeName(value, declaration), declaration); - } - - public Expression getExpression(ModifiedDeclaration declaration) { - return this.adapter.getExpression(declaration); - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - return this.adapter.getAstNode(declaration); - } - - - // ********** internal methods ********** - - /** - * resolve the enum - */ - protected String resolve(Expression expression) { - return JDTTools.resolveEnum(expression); - } - - /** - * convert the fully-qualified enum constant to a static import and the constant's short name, e.g. - * static import javax.persistence.FetchType.EAGER; - * return "EAGER" - * if that doesn't work, convert to a normal import and the constant's partially-qualified name, e.g. - * import javax.persistence.FetchType; - * return "FetchType.EAGER" - * if that doesn't work, simply return the constant's fully-qualified name, e.g. - * return "javax.persistence.FetchType.EAGER" - * NB: an import may be added as a side-effect :-( - */ - protected static String convertToSourceCodeName(String enumConstantName, ModifiedDeclaration declaration) { - return (enumConstantName == null) ? null : convertToSourceCodeName_(enumConstantName, declaration); - } - - /** - * pre-condition: enum constant name is non-null; - * convert it to its short version if we can add a static import etc. - */ - protected static String convertToSourceCodeName_(String enumConstantName, ModifiedDeclaration declaration) { - if (declaration.addStaticImport(enumConstantName)) { - return convertToShortName(enumConstantName); - } - if (declaration.addImport(convertToTypeName(enumConstantName))) { - return convertToPartiallyQualifiedName(enumConstantName); - } - return enumConstantName; - } - - protected static String convertToShortName(String name) { - return name.substring(name.lastIndexOf('.') + 1); - } - - protected static String convertToTypeName(String name) { - return name.substring(0, name.lastIndexOf('.')); - } - - protected static String convertToPartiallyQualifiedName(String name) { - return name.substring(name.lastIndexOf('.', name.lastIndexOf('.') - 1) + 1); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ExpressionDeclarationAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ExpressionDeclarationAnnotationElementAdapter.java deleted file mode 100644 index b96a7de027..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ExpressionDeclarationAnnotationElementAdapter.java +++ /dev/null @@ -1,362 +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.utility.jdt; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Most obvious implementation of the interface. - * Assume the element's value is an Expression. - */ -public class ExpressionDeclarationAnnotationElementAdapter<E extends Expression> - implements DeclarationAnnotationElementAdapter<E> -{ - /** - * Adapter used to manipulate the element's annotation. - */ - private final DeclarationAnnotationAdapter annotationAdapter; - - /** - * The name of the relevant annotation element. - */ - private final String elementName; - - /** - * Flag to indicate whether the element's annotation is to be - * completely removed if, when the element itself is removed, - * the annotation has no remaining elements. - */ - private final boolean removeAnnotationWhenEmpty; - - - // ********** constructors ********** - - /** - * The default element name is "value"; the default behavior is to - * remove the annotation when the last element is removed. - */ - public ExpressionDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter) { - this(annotationAdapter, VALUE); - } - - /** - * The default element name is "value". - */ - public ExpressionDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, boolean removeAnnotationWhenEmpty) { - this(annotationAdapter, VALUE, removeAnnotationWhenEmpty); - } - - /** - * The default behavior is to remove the annotation when the last - * element is removed. - */ - public ExpressionDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - this(annotationAdapter, elementName, true); - } - - public ExpressionDeclarationAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, boolean removeAnnotationWhenEmpty) { - super(); - this.annotationAdapter = annotationAdapter; - this.elementName = elementName; - this.removeAnnotationWhenEmpty = removeAnnotationWhenEmpty; - } - - - // ********** DeclarationAnnotationElementAdapter implementation ********** - - public E getValue(ModifiedDeclaration declaration) { - // return the expression unmodified - return this.getExpression(declaration); - } - - public void setValue(E value, ModifiedDeclaration declaration) { - this.setValue(value, this.annotationAdapter.getAnnotation(declaration), declaration); - } - - public E getExpression(ModifiedDeclaration declaration) { - return this.expression(this.annotationAdapter.getAnnotation(declaration)); - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - Expression exp = this.getExpression(declaration); - return (exp != null) ? exp : this.annotationAdapter.getAstNode(declaration); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.elementName); - } - - - // ********** expression ********** - - /** - * Return the expression value of the *first* annotation element - * with the adapter's element name. - * Return null if the annotation has no such element. - * (An element name of "value" will return the value of a single - * member annotation.) - */ - protected E expression(Annotation annotation) { - if (annotation == null) { - return this.expressionNoAnnotation(); - } - if (annotation.isMarkerAnnotation()) { - return this.expressionMarkerAnnotation((MarkerAnnotation) annotation); - } - if (annotation.isSingleMemberAnnotation()) { - return this.expressionSingleMemberAnnotation((SingleMemberAnnotation) annotation); - } - if (annotation.isNormalAnnotation()) { - return this.expressionNormalAnnotation((NormalAnnotation) annotation); - } - throw new IllegalArgumentException("unknown annotation type: " + annotation); //$NON-NLS-1$ - } - - protected E expressionNoAnnotation() { - return null; - } - - /** - * Return the expression value of the *first* annotation element - * with the adapter's element name. - * Return null if the annotation has no such element. - */ - protected E expressionMarkerAnnotation(@SuppressWarnings("unused") MarkerAnnotation annotation) { - return null; - } - - /** - * Return the expression value of the *first* annotation element - * with the adapter's element name. - * Return null if the annotation has no such element. - */ - protected E expressionSingleMemberAnnotation(SingleMemberAnnotation annotation) { - return this.downcast(this.elementName.equals(VALUE) ? annotation.getValue() : null); - } - - @SuppressWarnings("unchecked") - private E downcast(Expression e) { - return (E) e; - } - - /** - * Return the expression value of the *first* annotation element - * with the adapter's element name. - * Return null if the annotation has no such element. - */ - protected E expressionNormalAnnotation(NormalAnnotation annotation) { - MemberValuePair pair = this.memberValuePair(annotation); - return this.downcast((pair == null) ? null : pair.getValue()); - } - - - // ********** set value ********** - - /** - * set non-null, non-empty value - */ - protected void setValue(Expression value, Annotation annotation, ModifiedDeclaration declaration) { - if (value == null) { - this.removeElement(annotation, declaration); - } - else if (annotation == null) { - this.setValueNoAnnotation(value, declaration); - } - else if (annotation.isMarkerAnnotation()) { - this.setValueMarkerAnnotation(value, (MarkerAnnotation) annotation, declaration); - } - else if (annotation.isSingleMemberAnnotation()) { - this.setValueSingleMemberAnnotation(value, (SingleMemberAnnotation) annotation, declaration); - } - else if (annotation.isNormalAnnotation()) { - this.setValueNormalAnnotation(value, (NormalAnnotation) annotation, declaration); - } - else { - throw new IllegalArgumentException("unknown annotation type: " + annotation); //$NON-NLS-1$ - } - } - - /** - * add non-null, non-empty value - */ - protected void setValueNoAnnotation(Expression value, ModifiedDeclaration declaration) { - if (this.elementName.equals(VALUE)) { - // @Foo("xxx") - this.annotationAdapter.newSingleMemberAnnotation(declaration).setValue(value); - } else { - // @Foo(bar="xxx") - this.addValue(value, this.annotationAdapter.newNormalAnnotation(declaration)); - } - } - - protected void addValue(Expression value, NormalAnnotation annotation) { - this.addValue(value, annotation, this.elementName); - } - - protected void addValue(Expression value, NormalAnnotation annotation, String annotationElementName) { - AST ast = annotation.getAST(); - MemberValuePair pair = ast.newMemberValuePair(); - pair.setName(ast.newSimpleName(annotationElementName)); - pair.setValue(value); - List<MemberValuePair> values = this.values(annotation); - values.add(pair); - } - - protected void setValueMarkerAnnotation(Expression value, @SuppressWarnings("unused") MarkerAnnotation annotation, ModifiedDeclaration declaration) { - // @Foo => @Foo("xxx") - // or - // @Foo => @Foo(bar="xxx") - this.setValueNoAnnotation(value, declaration); - } - - protected void setValueSingleMemberAnnotation(Expression value, SingleMemberAnnotation annotation, ModifiedDeclaration declaration) { - if (this.elementName.equals(VALUE)) { - // @Foo("yyy") => @Foo("xxx") - annotation.setValue(value); - } else { - // @Foo("yyy") => @Foo(value="yyy", bar="xxx") - Expression vv = annotation.getValue(); - vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); - NormalAnnotation normalAnnotation = this.annotationAdapter.newNormalAnnotation(declaration); - this.addValue(vv, normalAnnotation, VALUE); - this.addValue(value, normalAnnotation); - } - } - - protected void setValueNormalAnnotation(Expression value, NormalAnnotation annotation, @SuppressWarnings("unused") ModifiedDeclaration declaration) { - MemberValuePair pair = this.memberValuePair(annotation); - if (pair == null) { - this.addValue(value, annotation); - } else { - pair.setValue(value); - } - } - - - // ********** remove element ********** - - protected void removeElement(Annotation annotation, ModifiedDeclaration declaration) { - if (annotation == null) { - this.removeElementNoAnnotation(declaration); - } - else if (annotation.isMarkerAnnotation()) { - this.removeElementMarkerAnnotation((MarkerAnnotation) annotation, declaration); - } - else if (annotation.isSingleMemberAnnotation()) { - this.removeElementSingleMemberAnnotation((SingleMemberAnnotation) annotation, declaration); - } - else if (annotation.isNormalAnnotation()) { - this.removeElementNormalAnnotation((NormalAnnotation) annotation, declaration); - } - else { - throw new IllegalArgumentException("unknown annotation type: " + annotation); //$NON-NLS-1$ - } - } - - protected void removeElementNoAnnotation(@SuppressWarnings("unused") ModifiedDeclaration declaration) { - // the element is already gone (?) - } - - protected void removeElementMarkerAnnotation(@SuppressWarnings("unused") MarkerAnnotation annotation, @SuppressWarnings("unused") ModifiedDeclaration declaration) { - // the element is already gone (?) - } - - protected void removeElementSingleMemberAnnotation(@SuppressWarnings("unused") SingleMemberAnnotation annotation, ModifiedDeclaration declaration) { - if (this.elementName.equals(VALUE)) { - if (this.removeAnnotationWhenEmpty) { - // @Foo("xxx") => - this.annotationAdapter.removeAnnotation(declaration); - } else { - // @Foo("xxx") => @Foo - this.annotationAdapter.newMarkerAnnotation(declaration); - } - } else { - // the [non-'value'] element is already gone (?) - } - } - - protected void removeElementNormalAnnotation(NormalAnnotation annotation, ModifiedDeclaration declaration) { - List<MemberValuePair> values = this.values(annotation); - if ((values.size() == 1) && values.get(0).getName().getFullyQualifiedName().equals(this.elementName)) { - if (this.removeAnnotationWhenEmpty) { - // @Foo(bar="xxx") => - this.annotationAdapter.removeAnnotation(declaration); - } else { - // @Foo(bar="xxx") => @Foo - this.annotationAdapter.newMarkerAnnotation(declaration); - } - } else { - this.removeElement(annotation); - if (values.size() == 1) { - MemberValuePair pair = values.get(0); - if (pair.getName().getFullyQualifiedName().equals(VALUE)) { - // @Foo(bar="xxx", value="yyy") => @Foo("yyy") - Expression vv = pair.getValue(); - vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); - this.annotationAdapter.newSingleMemberAnnotation(declaration).setValue(vv); - } else { - // @Foo(bar="xxx", baz="yyy") => @Foo(baz="yyy") - } - } else { - // @Foo(bar="xxx", baz="yyy", joo="xxx") => @Foo(baz="yyy", joo="xxx") - } - } - } - - /** - * Remove the *first* member value pair from the specified annotation element - * with the adapter's element name. - */ - protected void removeElement(NormalAnnotation annotation) { - for (Iterator<MemberValuePair> stream = this.values(annotation).iterator(); stream.hasNext(); ) { - MemberValuePair pair = stream.next(); - if (pair.getName().getFullyQualifiedName().equals(this.elementName)) { - stream.remove(); - } - } - } - - - // ********** convenience methods ********** - - /** - * Return the *first* member value pair for the specified annotation element - * with the adapter's element name. - * Return null if the annotation has no such element. - */ - protected MemberValuePair memberValuePair(NormalAnnotation annotation) { - for (MemberValuePair pair : this.values(annotation)) { - if (pair.getName().getFullyQualifiedName().equals(this.elementName)) { - return pair; - } - } - return null; - } - - @SuppressWarnings("unchecked") - protected List<MemberValuePair> values(NormalAnnotation na) { - return na.values(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/GenericVisitor.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/GenericVisitor.java deleted file mode 100644 index 284d615e26..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/GenericVisitor.java +++ /dev/null @@ -1,791 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ASTVisitor; -import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; -import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; -import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; -import org.eclipse.jdt.core.dom.ArrayAccess; -import org.eclipse.jdt.core.dom.ArrayCreation; -import org.eclipse.jdt.core.dom.ArrayInitializer; -import org.eclipse.jdt.core.dom.ArrayType; -import org.eclipse.jdt.core.dom.AssertStatement; -import org.eclipse.jdt.core.dom.Assignment; -import org.eclipse.jdt.core.dom.Block; -import org.eclipse.jdt.core.dom.BlockComment; -import org.eclipse.jdt.core.dom.BooleanLiteral; -import org.eclipse.jdt.core.dom.BreakStatement; -import org.eclipse.jdt.core.dom.CastExpression; -import org.eclipse.jdt.core.dom.CatchClause; -import org.eclipse.jdt.core.dom.CharacterLiteral; -import org.eclipse.jdt.core.dom.ClassInstanceCreation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.ConditionalExpression; -import org.eclipse.jdt.core.dom.ConstructorInvocation; -import org.eclipse.jdt.core.dom.ContinueStatement; -import org.eclipse.jdt.core.dom.DoStatement; -import org.eclipse.jdt.core.dom.EmptyStatement; -import org.eclipse.jdt.core.dom.EnhancedForStatement; -import org.eclipse.jdt.core.dom.EnumConstantDeclaration; -import org.eclipse.jdt.core.dom.EnumDeclaration; -import org.eclipse.jdt.core.dom.ExpressionStatement; -import org.eclipse.jdt.core.dom.FieldAccess; -import org.eclipse.jdt.core.dom.FieldDeclaration; -import org.eclipse.jdt.core.dom.ForStatement; -import org.eclipse.jdt.core.dom.IfStatement; -import org.eclipse.jdt.core.dom.ImportDeclaration; -import org.eclipse.jdt.core.dom.InfixExpression; -import org.eclipse.jdt.core.dom.Initializer; -import org.eclipse.jdt.core.dom.InstanceofExpression; -import org.eclipse.jdt.core.dom.Javadoc; -import org.eclipse.jdt.core.dom.LabeledStatement; -import org.eclipse.jdt.core.dom.LineComment; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.MemberRef; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.MethodInvocation; -import org.eclipse.jdt.core.dom.MethodRef; -import org.eclipse.jdt.core.dom.MethodRefParameter; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.NullLiteral; -import org.eclipse.jdt.core.dom.NumberLiteral; -import org.eclipse.jdt.core.dom.PackageDeclaration; -import org.eclipse.jdt.core.dom.ParameterizedType; -import org.eclipse.jdt.core.dom.ParenthesizedExpression; -import org.eclipse.jdt.core.dom.PostfixExpression; -import org.eclipse.jdt.core.dom.PrefixExpression; -import org.eclipse.jdt.core.dom.PrimitiveType; -import org.eclipse.jdt.core.dom.QualifiedName; -import org.eclipse.jdt.core.dom.QualifiedType; -import org.eclipse.jdt.core.dom.ReturnStatement; -import org.eclipse.jdt.core.dom.SimpleName; -import org.eclipse.jdt.core.dom.SimpleType; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jdt.core.dom.SingleVariableDeclaration; -import org.eclipse.jdt.core.dom.StringLiteral; -import org.eclipse.jdt.core.dom.SuperConstructorInvocation; -import org.eclipse.jdt.core.dom.SuperFieldAccess; -import org.eclipse.jdt.core.dom.SuperMethodInvocation; -import org.eclipse.jdt.core.dom.SwitchCase; -import org.eclipse.jdt.core.dom.SwitchStatement; -import org.eclipse.jdt.core.dom.SynchronizedStatement; -import org.eclipse.jdt.core.dom.TagElement; -import org.eclipse.jdt.core.dom.TextElement; -import org.eclipse.jdt.core.dom.ThisExpression; -import org.eclipse.jdt.core.dom.ThrowStatement; -import org.eclipse.jdt.core.dom.TryStatement; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jdt.core.dom.TypeDeclarationStatement; -import org.eclipse.jdt.core.dom.TypeLiteral; -import org.eclipse.jdt.core.dom.TypeParameter; -import org.eclipse.jdt.core.dom.VariableDeclarationExpression; -import org.eclipse.jdt.core.dom.VariableDeclarationFragment; -import org.eclipse.jdt.core.dom.VariableDeclarationStatement; -import org.eclipse.jdt.core.dom.WhileStatement; -import org.eclipse.jdt.core.dom.WildcardType; - -/** - * copied from org.eclipse.jdt.internal.corext.dom.GenericVisitor - */ -public class GenericVisitor extends ASTVisitor { - - public GenericVisitor() { - super(); - } - - public GenericVisitor(boolean visitJavadocTags) { - super(visitJavadocTags); - } - - // ********** hooks for subclasses ********** - - protected boolean visit_(@SuppressWarnings("unused") ASTNode node) { - return true; - } - - protected void endVisit_(@SuppressWarnings("unused") ASTNode node) { - // do nothing - } - - // ********** overrides ********** - - @Override - public boolean visit(AnonymousClassDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(ArrayAccess node) { - return visit_(node); - } - @Override - public boolean visit(ArrayCreation node) { - return visit_(node); - } - @Override - public boolean visit(ArrayInitializer node) { - return visit_(node); - } - @Override - public boolean visit(ArrayType node) { - return visit_(node); - } - @Override - public boolean visit(AssertStatement node) { - return visit_(node); - } - @Override - public boolean visit(Assignment node) { - return visit_(node); - } - @Override - public boolean visit(Block node) { - return visit_(node); - } - @Override - public boolean visit(BooleanLiteral node) { - return visit_(node); - } - @Override - public boolean visit(BreakStatement node) { - return visit_(node); - } - @Override - public boolean visit(CastExpression node) { - return visit_(node); - } - @Override - public boolean visit(CatchClause node) { - return visit_(node); - } - @Override - public boolean visit(CharacterLiteral node) { - return visit_(node); - } - @Override - public boolean visit(ClassInstanceCreation node) { - return visit_(node); - } - @Override - public boolean visit(CompilationUnit node) { - return visit_(node); - } - @Override - public boolean visit(ConditionalExpression node) { - return visit_(node); - } - @Override - public boolean visit(ConstructorInvocation node) { - return visit_(node); - } - @Override - public boolean visit(ContinueStatement node) { - return visit_(node); - } - @Override - public boolean visit(DoStatement node) { - return visit_(node); - } - @Override - public boolean visit(EmptyStatement node) { - return visit_(node); - } - @Override - public boolean visit(ExpressionStatement node) { - return visit_(node); - } - @Override - public boolean visit(FieldAccess node) { - return visit_(node); - } - @Override - public boolean visit(FieldDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(ForStatement node) { - return visit_(node); - } - @Override - public boolean visit(IfStatement node) { - return visit_(node); - } - @Override - public boolean visit(ImportDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(InfixExpression node) { - return visit_(node); - } - @Override - public boolean visit(InstanceofExpression node) { - return visit_(node); - } - @Override - public boolean visit(Initializer node) { - return visit_(node); - } - @Override - public boolean visit(Javadoc node) { - return (super.visit(node)) ? visit_(node) : false; - } - @Override - public boolean visit(LabeledStatement node) { - return visit_(node); - } - @Override - public boolean visit(MethodDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(MethodInvocation node) { - return visit_(node); - } - @Override - public boolean visit(NullLiteral node) { - return visit_(node); - } - @Override - public boolean visit(NumberLiteral node) { - return visit_(node); - } - @Override - public boolean visit(PackageDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(ParenthesizedExpression node) { - return visit_(node); - } - @Override - public boolean visit(PostfixExpression node) { - return visit_(node); - } - @Override - public boolean visit(PrefixExpression node) { - return visit_(node); - } - @Override - public boolean visit(PrimitiveType node) { - return visit_(node); - } - @Override - public boolean visit(QualifiedName node) { - return visit_(node); - } - @Override - public boolean visit(ReturnStatement node) { - return visit_(node); - } - @Override - public boolean visit(SimpleName node) { - return visit_(node); - } - @Override - public boolean visit(SimpleType node) { - return visit_(node); - } - @Override - public boolean visit(StringLiteral node) { - return visit_(node); - } - @Override - public boolean visit(SuperConstructorInvocation node) { - return visit_(node); - } - @Override - public boolean visit(SuperFieldAccess node) { - return visit_(node); - } - @Override - public boolean visit(SuperMethodInvocation node) { - return visit_(node); - } - @Override - public boolean visit(SwitchCase node) { - return visit_(node); - } - @Override - public boolean visit(SwitchStatement node) { - return visit_(node); - } - @Override - public boolean visit(SynchronizedStatement node) { - return visit_(node); - } - @Override - public boolean visit(ThisExpression node) { - return visit_(node); - } - @Override - public boolean visit(ThrowStatement node) { - return visit_(node); - } - @Override - public boolean visit(TryStatement node) { - return visit_(node); - } - @Override - public boolean visit(TypeDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(TypeDeclarationStatement node) { - return visit_(node); - } - @Override - public boolean visit(TypeLiteral node) { - return visit_(node); - } - @Override - public boolean visit(SingleVariableDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(VariableDeclarationExpression node) { - return visit_(node); - } - @Override - public boolean visit(VariableDeclarationStatement node) { - return visit_(node); - } - @Override - public boolean visit(VariableDeclarationFragment node) { - return visit_(node); - } - @Override - public boolean visit(WhileStatement node) { - return visit_(node); - } - @Override - public boolean visit(AnnotationTypeDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(AnnotationTypeMemberDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(BlockComment node) { - return visit_(node); - } - @Override - public boolean visit(EnhancedForStatement node) { - return visit_(node); - } - @Override - public boolean visit(EnumConstantDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(EnumDeclaration node) { - return visit_(node); - } - @Override - public boolean visit(LineComment node) { - return visit_(node); - } - @Override - public boolean visit(MarkerAnnotation node) { - return visit_(node); - } - @Override - public boolean visit(MemberRef node) { - return visit_(node); - } - @Override - public boolean visit(MemberValuePair node) { - return visit_(node); - } - @Override - public boolean visit(MethodRef node) { - return visit_(node); - } - @Override - public boolean visit(MethodRefParameter node) { - return visit_(node); - } - @Override - public boolean visit(Modifier node) { - return visit_(node); - } - @Override - public boolean visit(NormalAnnotation node) { - return visit_(node); - } - @Override - public boolean visit(ParameterizedType node) { - return visit_(node); - } - @Override - public boolean visit(QualifiedType node) { - return visit_(node); - } - @Override - public boolean visit(SingleMemberAnnotation node) { - return visit_(node); - } - @Override - public boolean visit(TagElement node) { - return visit_(node); - } - @Override - public boolean visit(TextElement node) { - return visit_(node); - } - @Override - public boolean visit(TypeParameter node) { - return visit_(node); - } - @Override - public boolean visit(WildcardType node) { - return visit_(node); - } - - @Override - public void endVisit(AnonymousClassDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(ArrayAccess node) { - endVisit_(node); - } - @Override - public void endVisit(ArrayCreation node) { - endVisit_(node); - } - @Override - public void endVisit(ArrayInitializer node) { - endVisit_(node); - } - @Override - public void endVisit(ArrayType node) { - endVisit_(node); - } - @Override - public void endVisit(AssertStatement node) { - endVisit_(node); - } - @Override - public void endVisit(Assignment node) { - endVisit_(node); - } - @Override - public void endVisit(Block node) { - endVisit_(node); - } - @Override - public void endVisit(BooleanLiteral node) { - endVisit_(node); - } - @Override - public void endVisit(BreakStatement node) { - endVisit_(node); - } - @Override - public void endVisit(CastExpression node) { - endVisit_(node); - } - @Override - public void endVisit(CatchClause node) { - endVisit_(node); - } - @Override - public void endVisit(CharacterLiteral node) { - endVisit_(node); - } - @Override - public void endVisit(ClassInstanceCreation node) { - endVisit_(node); - } - @Override - public void endVisit(CompilationUnit node) { - endVisit_(node); - } - @Override - public void endVisit(ConditionalExpression node) { - endVisit_(node); - } - @Override - public void endVisit(ConstructorInvocation node) { - endVisit_(node); - } - @Override - public void endVisit(ContinueStatement node) { - endVisit_(node); - } - @Override - public void endVisit(DoStatement node) { - endVisit_(node); - } - @Override - public void endVisit(EmptyStatement node) { - endVisit_(node); - } - @Override - public void endVisit(ExpressionStatement node) { - endVisit_(node); - } - @Override - public void endVisit(FieldAccess node) { - endVisit_(node); - } - @Override - public void endVisit(FieldDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(ForStatement node) { - endVisit_(node); - } - @Override - public void endVisit(IfStatement node) { - endVisit_(node); - } - @Override - public void endVisit(ImportDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(InfixExpression node) { - endVisit_(node); - } - @Override - public void endVisit(InstanceofExpression node) { - endVisit_(node); - } - @Override - public void endVisit(Initializer node) { - endVisit_(node); - } - @Override - public void endVisit(Javadoc node) { - endVisit_(node); - } - @Override - public void endVisit(LabeledStatement node) { - endVisit_(node); - } - @Override - public void endVisit(MethodDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(MethodInvocation node) { - endVisit_(node); - } - @Override - public void endVisit(NullLiteral node) { - endVisit_(node); - } - @Override - public void endVisit(NumberLiteral node) { - endVisit_(node); - } - @Override - public void endVisit(PackageDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(ParenthesizedExpression node) { - endVisit_(node); - } - @Override - public void endVisit(PostfixExpression node) { - endVisit_(node); - } - @Override - public void endVisit(PrefixExpression node) { - endVisit_(node); - } - @Override - public void endVisit(PrimitiveType node) { - endVisit_(node); - } - @Override - public void endVisit(QualifiedName node) { - endVisit_(node); - } - @Override - public void endVisit(ReturnStatement node) { - endVisit_(node); - } - @Override - public void endVisit(SimpleName node) { - endVisit_(node); - } - @Override - public void endVisit(SimpleType node) { - endVisit_(node); - } - @Override - public void endVisit(StringLiteral node) { - endVisit_(node); - } - @Override - public void endVisit(SuperConstructorInvocation node) { - endVisit_(node); - } - @Override - public void endVisit(SuperFieldAccess node) { - endVisit_(node); - } - @Override - public void endVisit(SuperMethodInvocation node) { - endVisit_(node); - } - @Override - public void endVisit(SwitchCase node) { - endVisit_(node); - } - @Override - public void endVisit(SwitchStatement node) { - endVisit_(node); - } - @Override - public void endVisit(SynchronizedStatement node) { - endVisit_(node); - } - @Override - public void endVisit(ThisExpression node) { - endVisit_(node); - } - @Override - public void endVisit(ThrowStatement node) { - endVisit_(node); - } - @Override - public void endVisit(TryStatement node) { - endVisit_(node); - } - @Override - public void endVisit(TypeDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(TypeDeclarationStatement node) { - endVisit_(node); - } - @Override - public void endVisit(TypeLiteral node) { - endVisit_(node); - } - @Override - public void endVisit(SingleVariableDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(VariableDeclarationExpression node) { - endVisit_(node); - } - @Override - public void endVisit(VariableDeclarationStatement node) { - endVisit_(node); - } - @Override - public void endVisit(VariableDeclarationFragment node) { - endVisit_(node); - } - @Override - public void endVisit(WhileStatement node) { - endVisit_(node); - } - @Override - public void endVisit(AnnotationTypeDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(AnnotationTypeMemberDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(BlockComment node) { - endVisit_(node); - } - @Override - public void endVisit(EnhancedForStatement node) { - endVisit_(node); - } - @Override - public void endVisit(EnumConstantDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(EnumDeclaration node) { - endVisit_(node); - } - @Override - public void endVisit(LineComment node) { - endVisit_(node); - } - @Override - public void endVisit(MarkerAnnotation node) { - endVisit_(node); - } - @Override - public void endVisit(MemberRef node) { - endVisit_(node); - } - @Override - public void endVisit(MemberValuePair node) { - endVisit_(node); - } - @Override - public void endVisit(MethodRef node) { - endVisit_(node); - } - @Override - public void endVisit(MethodRefParameter node) { - endVisit_(node); - } - @Override - public void endVisit(Modifier node) { - endVisit_(node); - } - @Override - public void endVisit(NormalAnnotation node) { - endVisit_(node); - } - @Override - public void endVisit(ParameterizedType node) { - endVisit_(node); - } - @Override - public void endVisit(QualifiedType node) { - endVisit_(node); - } - @Override - public void endVisit(SingleMemberAnnotation node) { - endVisit_(node); - } - @Override - public void endVisit(TagElement node) { - endVisit_(node); - } - @Override - public void endVisit(TextElement node) { - endVisit_(node); - } - @Override - public void endVisit(TypeParameter node) { - endVisit_(node); - } - @Override - public void endVisit(WildcardType node) { - endVisit_(node); - } - -} - diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTAttribute.java deleted file mode 100644 index 86551588da..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTAttribute.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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.utility.jdt; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.core.utility.jdt.Attribute; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.CommandExecutor; - -/** - * Combine behavior common to JDTFieldAttribute and JDTMethodAttribute. - * Not so sure this is useful.... - */ -public abstract class JDTAttribute - extends JDTMember - implements Attribute -{ - - // ********** constructors ********** - - protected JDTAttribute( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor) { - super(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutor); - } - - protected JDTAttribute( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter); - } - - - // ********** Member/Attribute implementation ********** - - public boolean isField() { - return false; - } - - - // ********** internal ********** - - protected TypeDeclaration getDeclaringTypeDeclaration(CompilationUnit astRoot) { - // assume the declaring type is not an enum or annotation - // since they do not have field or method declarations - return this.getDeclaringType().getBodyDeclaration(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTFieldAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTFieldAttribute.java deleted file mode 100644 index 1c18f297cb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTFieldAttribute.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility.jdt; - -import java.util.List; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.FieldDeclaration; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.IVariableBinding; -import org.eclipse.jdt.core.dom.VariableDeclarationFragment; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.core.utility.jdt.FieldAttribute; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.CommandExecutor; - -/** - * Adapt and extend a JDT field. - * Attribute based on a Java field, e.g. - * private int foo; - */ -public class JDTFieldAttribute - extends JDTAttribute - implements FieldAttribute -{ - - // ********** constructors ********** - - public JDTFieldAttribute( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor) { - this(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, DefaultAnnotationEditFormatter.instance()); - } - - public JDTFieldAttribute( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter); - } - - /** - * constructor for testing - */ - public JDTFieldAttribute(Type declaringType, String name, int occurrence, ICompilationUnit compilationUnit) { - this(declaringType, name, occurrence, compilationUnit, CommandExecutor.Default.instance(), DefaultAnnotationEditFormatter.instance()); - } - - - // ********** Member/Attribute/FieldAttribute implementation ********** - - public IVariableBinding getBinding(CompilationUnit astRoot) { - return this.getFragment(astRoot).resolveBinding(); - } - - public FieldDeclaration getBodyDeclaration(CompilationUnit astRoot) { - return this.getSelectedDeclaration(astRoot, FIELD_DECLARATION_SELECTOR); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return new ASTNodeTextRange(this.getFragment(astRoot).getName()); - } - - public String getAttributeName() { - return this.getName_(); - } - - public ITypeBinding getTypeBinding(CompilationUnit astRoot) { - return this.getBodyDeclaration(astRoot).getType().resolveBinding(); - } - - @Override - public boolean isField() { - return true; - } - - public boolean isPersistable(CompilationUnit astRoot) { - IVariableBinding binding = this.getBinding(astRoot); - return (binding == null) ? false : JPTTools.fieldIsPersistable(new JPTToolsAdapter(binding)); - } - - - // ********** internal ********** - - protected VariableDeclarationFragment getFragment(CompilationUnit astRoot) { - return this.getSelectedDeclaration(astRoot, VARIABLE_DECLARATION_FRAGMENT_SELECTOR); - } - - /** - * return either a FieldDeclaration or a VariableDeclarationFragment, - * depending on the specified selector; - * - * handle multiple fields declared in a single statement: - * private int foo, bar; - */ - protected <T extends ASTNode> T getSelectedDeclaration(CompilationUnit astRoot, Selector<T> selector) { - String name = this.getName_(); - int occurrence = this.getOccurrence(); - int count = 0; - for (FieldDeclaration fieldDeclaration : this.getDeclaringTypeFieldDeclarations(astRoot)) { - for (VariableDeclarationFragment fragment : fragments(fieldDeclaration)) { - if (fragment.getName().getFullyQualifiedName().equals(name)) { - count++; - if (count == occurrence) { - return selector.select(fieldDeclaration, fragment); - } - } - } - } - // return null if the field is no longer in the source code; - // this can happen when the context model has not yet - // been synchronized with the resource model but is still - // asking for an ASTNode (e.g. during a selection event) - return null; - } - - protected FieldDeclaration[] getDeclaringTypeFieldDeclarations(CompilationUnit astRoot) { - return this.getDeclaringTypeDeclaration(astRoot).getFields(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - protected static List<VariableDeclarationFragment> fragments(FieldDeclaration fd) { - return fd.fragments(); - } - - - // ********** Selector ********** - - // I'm not quite sure this interface is worth the resulting obfuscation, - // but, then, I kept changing both methods, so... ~bjv - protected interface Selector<T extends ASTNode> { - T select(FieldDeclaration fieldDeclaration, VariableDeclarationFragment variableDeclarationFragment); - String getDescription(); - } - - protected static final Selector<FieldDeclaration> FIELD_DECLARATION_SELECTOR = - new Selector<FieldDeclaration>() { - public FieldDeclaration select(FieldDeclaration fieldDeclaration, VariableDeclarationFragment variableDeclarationFragment) { - return fieldDeclaration; - } - public String getDescription() { - return "field declaration"; //$NON-NLS-1$ - } - @Override - public String toString() { - return "FIELD_DECLARATION_SELECTOR"; //$NON-NLS-1$ - } - }; - - protected static final Selector<VariableDeclarationFragment> VARIABLE_DECLARATION_FRAGMENT_SELECTOR = - new Selector<VariableDeclarationFragment>() { - public VariableDeclarationFragment select(FieldDeclaration fieldDeclaration, VariableDeclarationFragment variableDeclarationFragment) { - return variableDeclarationFragment; - } - public String getDescription() { - return "variable declaration fragment"; //$NON-NLS-1$ - } - @Override - public String toString() { - return "VARIABLE_DECLARATION_FRAGMENT_SELECTOR"; //$NON-NLS-1$ - } - }; - - - // ********** JPTTools adapter ********** - - /** - * JPTTools needs an adapter so it can work with either an IField - * or an IVariableBinding etc. - */ - protected static class JPTToolsAdapter implements JPTTools.FieldAdapter { - private final IVariableBinding fieldBinding; - - protected JPTToolsAdapter(IVariableBinding fieldBinding) { - super(); - if (fieldBinding == null) { - throw new NullPointerException(); - } - this.fieldBinding = fieldBinding; - } - - public int getModifiers() { - return this.fieldBinding.getModifiers(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMember.java deleted file mode 100644 index b0ecf61004..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMember.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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.utility.jdt; - -import org.eclipse.core.filebuffers.FileBuffers; -import org.eclipse.core.filebuffers.ITextFileBuffer; -import org.eclipse.core.filebuffers.LocationKind; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.Command; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.TextEdit; - -/** - * Adapt and extend a JDT member with simplified annotation handling. - */ -public abstract class JDTMember - implements Member -{ - /** this will be null for the primary type */ - private final Type declaringType; - - /** the member's name (duh) */ - private final String name; - - /** - * members can occur more than once in non-compiling source; - * count starts at 1; the primary type will have occurrence 1 - */ - private final int occurrence; - - /** - * the compilation unit (file) containing the member; - * used for building an AST when we modify the member - */ - private final ICompilationUnit compilationUnit; - - /** - * this allows clients to provide a way to modify the compilation unit - * (file) when it is open in an editor and should be modified on the UI - * thread - */ - private final CommandExecutor modifySharedDocumentCommandExecutor; - - /** this will format the member's annotations a bit */ - private final AnnotationEditFormatter annotationEditFormatter; - - - // ********** constructors ********** - - protected JDTMember( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor) { - this(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, DefaultAnnotationEditFormatter.instance()); - } - - protected JDTMember( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor, - AnnotationEditFormatter annotationEditFormatter) { - super(); - this.declaringType = declaringType; - this.name = name; - this.occurrence = occurrence; - this.compilationUnit = compilationUnit; - this.modifySharedDocumentCommandExecutor = modifySharedDocumentCommandExecutor; - this.annotationEditFormatter = annotationEditFormatter; - } - - - // ********** Member implementation ********** - - public ModifiedDeclaration getModifiedDeclaration(CompilationUnit astRoot) { - return new JDTModifiedDeclaration(this.getBodyDeclaration(astRoot)); - } - - public ModifiedDeclaration getModifiedDeclaration() { - return this.getModifiedDeclaration(this.buildASTRoot()); - } - - public boolean matches(String memberName, int occur) { - return memberName.equals(this.name) && (occur == this.occurrence); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.name); - } - - - // ********** internal ********** - - protected String getName_() { - return this.name; - } - - protected int getOccurrence() { - return this.occurrence; - } - - /** - * this will return null for a top-level type - */ - protected Type getDeclaringType() { - return this.declaringType; - } - - - // ********** editing ********** - - /** - * Edit the member with the specified editor. - * The editor will be invoked once the member's compilation unit - * is in an editable state. - */ - public void edit(Editor editor) { - try { - this.edit_(editor); - } catch (JavaModelException ex) { - throw new RuntimeException(ex); - } catch (BadLocationException ex) { - throw new RuntimeException(ex); - } - } - - /** - * NB: Be careful changing this method. - * Things to look out for: - * - when editing via the JavaEditor there is no need to create a working copy - * - when editing without an editor or via a simple text editor, a "working copy" must be created. - * (at least as far as I can tell ~kfm) - * - sharedDocument is only ever false in tests (headless mode). In the UI, even if the file - * is not open in an editor, sharedDocument is still true (buffer is not null) - * - if a working copy is created, then we must discard it - */ - protected void edit_(Editor editor) throws JavaModelException, BadLocationException { - boolean createWorkingCopy = ! this.compilationUnit.isWorkingCopy(); - if (createWorkingCopy) { - this.compilationUnit.becomeWorkingCopy(null); - } - - ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(this.compilationUnit.getResource().getFullPath(), LocationKind.NORMALIZE); - boolean sharedDocument = (buffer != null); // documents are typically shared when they are already open in an editor - IDocument doc = sharedDocument ? - buffer.getDocument() - : - new Document(this.compilationUnit.getBuffer().getContents()); - - try { - CompilationUnit astRoot = this.buildASTRoot(); - astRoot.recordModifications(); - - editor.edit(this.getModifiedDeclaration(astRoot)); - - TextEdit edits = astRoot.rewrite(doc, this.compilationUnit.getJavaProject().getOptions(true)); - if (sharedDocument) { - this.modifySharedDocumentCommandExecutor.execute(new ModifySharedDocumentCommand(edits, doc)); - } else { - this.applyEdits(edits, doc); - } - } - finally { - if (createWorkingCopy) { - //discardWorkingCopy must be called every time becomeWorkingCopy is called. - this.compilationUnit.getBuffer().setContents(doc.get()); - this.compilationUnit.commitWorkingCopy(true, null); // true="force" - this.compilationUnit.discardWorkingCopy(); - } - } - } - - /** - * apply the specified edits to the specified document, - * reformatting the document if necessary - */ - protected void applyEdits(TextEdit edits, IDocument doc) throws MalformedTreeException, BadLocationException { - edits.apply(doc, TextEdit.UPDATE_REGIONS); - this.annotationEditFormatter.format(doc, edits); - } - - protected CompilationUnit buildASTRoot() { - return JDTTools.buildASTRoot(this.compilationUnit); - } - - - // ********** modify shared document command class ********** - - /** - * simple command that calls back to the member to apply the edits - * in the same way as if the document were not shared - */ - protected class ModifySharedDocumentCommand implements Command { - private final TextEdit edits; - private final IDocument doc; - - protected ModifySharedDocumentCommand(TextEdit edits, IDocument doc) { - super(); - this.edits = edits; - this.doc = doc; - } - - public void execute() { - try { - JDTMember.this.applyEdits(this.edits, this.doc); - } catch (MalformedTreeException ex) { - throw new RuntimeException(ex); - } catch (BadLocationException ex) { - throw new RuntimeException(ex); - } - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMethodAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMethodAttribute.java deleted file mode 100644 index b233a2a803..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMethodAttribute.java +++ /dev/null @@ -1,256 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility.jdt; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IMethodBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.SingleVariableDeclaration; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.core.utility.jdt.MethodAttribute; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.jpt.utility.JavaType; -import org.eclipse.jpt.utility.MethodSignature; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.SimpleMethodSignature; - -/** - * Adapt and extend a JDT method. - * Attribute based on a Java property, e.g. - * private int getFoo() { - * return foo; - * } - * private void setFoo(int foo) { - * this.foo = foo; - * } - */ -public class JDTMethodAttribute - extends JDTAttribute - implements MethodAttribute -{ - /** we need the parameter types to build the method signature */ - private final JavaType[] parameterTypes; - - - // ********** constructors ********** - - public static JDTMethodAttribute newInstance( - Type declaringType, - MethodSignature signature, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor) { - return newInstance(declaringType, signature, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, DefaultAnnotationEditFormatter.instance()); - } - - public static JDTMethodAttribute newInstance( - Type declaringType, - MethodSignature signature, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor, - AnnotationEditFormatter annotationEditFormatter) { - return new JDTMethodAttribute(declaringType, signature, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter); - } - - public JDTMethodAttribute( - Type declaringType, - MethodSignature methodSignature, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor) { - this(declaringType, methodSignature, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, DefaultAnnotationEditFormatter.instance()); - } - - public JDTMethodAttribute( - Type declaringType, - MethodSignature methodSignature, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, methodSignature.getName(), occurrence, compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter); - this.parameterTypes = methodSignature.getParameterTypes(); - } - - /** - * constructor for testing - */ - public JDTMethodAttribute(Type declaringType, String name, String[] parameterTypeNames, int occurrence, ICompilationUnit compilationUnit) { - this(declaringType, new SimpleMethodSignature(name, parameterTypeNames), occurrence, compilationUnit, CommandExecutor.Default.instance(), DefaultAnnotationEditFormatter.instance()); - } - - - // ********** Member/Attribute/MethodAttribute implementation ********** - - public IMethodBinding getBinding(CompilationUnit astRoot) { - return this.getBodyDeclaration(astRoot).resolveBinding(); - } - - public MethodDeclaration getBodyDeclaration(CompilationUnit astRoot) { - int count = 0; - for (MethodDeclaration methodDeclaration : this.getDeclaringTypeMethodDeclarations(astRoot)) { - if (this.matches(methodDeclaration)) { - count++; - if (count == this.getOccurrence()) { - return methodDeclaration; - } - } - } - // return null if the method is no longer in the source code; - // this can happen when the context model has not yet - // been synchronized with the resource model but is still - // asking for an ASTNode (e.g. during a selection event) - return null; - } - - public boolean matches(MethodSignature signature, int occurrence) { - return this.matches(signature) && (occurrence == this.getOccurrence()); - } - - protected boolean matches(MethodSignature signature) { - return signature.getName().equals(this.getName_()) - && Arrays.equals(this.parameterTypes, signature.getParameterTypes()); - } - - protected boolean matches(MethodDeclaration methodDeclaration) { - return this.matches(JDTTools.buildMethodSignature(methodDeclaration)); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - protected static List<SingleVariableDeclaration> parameters(MethodDeclaration methodDeclaration) { - return methodDeclaration.parameters(); - } - - @Override - public boolean matches(String memberName, int occurrence) { - throw new UnsupportedOperationException("Use #matches(MethodSignature, int)."); //$NON-NLS-1$ - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName()); - } - - /** - * return "foo" for a method named "getFoo" or "isFoo" - */ - public String getAttributeName() { - return NameTools.convertGetterMethodNameToPropertyName(this.getName_()); - } - - public ITypeBinding getTypeBinding(CompilationUnit astRoot) { - IMethodBinding methodBinding = getBodyDeclaration(astRoot).resolveBinding(); - return (methodBinding == null) ? null : methodBinding.getReturnType(); - } - - public boolean isPersistable(CompilationUnit astRoot) { - IMethodBinding binding = this.getBinding(astRoot); - return (binding == null) ? false : JPTTools.methodIsPersistablePropertyGetter(new JPTToolsAdapter(binding)); - } - - - // ********** internal ********** - - protected MethodDeclaration[] getDeclaringTypeMethodDeclarations(CompilationUnit astRoot) { - return this.getDeclaringTypeDeclaration(astRoot).getMethods(); - } - - - // ********** JPTTools adapter ********** - - /** - * JPTTools needs an adapter so it can work with either an IMethod - * or an IMethodBinding etc. - */ - protected static class SimpleJPTToolsAdapter - implements JPTTools.SimpleMethodAdapter - { - protected final IMethodBinding methodBinding; - - protected SimpleJPTToolsAdapter(IMethodBinding methodBinding) { - super(); - if (methodBinding == null) { - throw new NullPointerException(); - } - this.methodBinding = methodBinding; - } - - public int getModifiers() { - return this.methodBinding.getModifiers(); - } - - public String getReturnTypeErasureName() { - ITypeBinding returnType = this.methodBinding.getReturnType(); - return (returnType == null) ? null : returnType.getTypeDeclaration().getErasure().getQualifiedName(); - } - - public boolean isConstructor() { - return this.methodBinding.isConstructor(); - } - - } - - protected static class JPTToolsAdapter - extends SimpleJPTToolsAdapter - implements JPTTools.MethodAdapter - { - protected JPTToolsAdapter(IMethodBinding methodBinding) { - super(methodBinding); - } - - public String getName() { - return this.methodBinding.getName(); - } - - public int getParametersLength() { - return this.methodBinding.getParameterTypes().length; - } - - public JPTTools.SimpleMethodAdapter getSibling(String name) { - ITypeBinding typeBinding = this.methodBinding.getDeclaringClass(); - if (typeBinding == null) { - return null; - } - for (IMethodBinding sibling : typeBinding.getDeclaredMethods()) { - if ((sibling.getParameterTypes().length == 0) - && sibling.getName().equals(name)) { - return new SimpleJPTToolsAdapter(sibling); - } - } - return null; - } - - public JPTTools.SimpleMethodAdapter getSibling(String name, String parameterTypeErasureName) { - ITypeBinding typeBinding = this.methodBinding.getDeclaringClass(); - if (typeBinding == null) { - return null; - } - for (IMethodBinding sibling : typeBinding.getDeclaredMethods()) { - ITypeBinding[] siblingParmTypes = sibling.getParameterTypes(); - if ((siblingParmTypes.length == 1) - && sibling.getName().equals(name) - && siblingParmTypes[0].getTypeDeclaration().getErasure().getQualifiedName().equals(parameterTypeErasureName)) { - return new SimpleJPTToolsAdapter(sibling); - } - } - return null; - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java deleted file mode 100644 index 2f6f82dab1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java +++ /dev/null @@ -1,532 +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.utility.jdt; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.BodyDeclaration; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IExtendedModifier; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.ImportDeclaration; -import org.eclipse.jdt.core.dom.SingleVariableDeclaration; -import org.eclipse.jdt.core.dom.VariableDeclarationExpression; -import org.eclipse.jdt.core.dom.VariableDeclarationStatement; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -/** - * Wrap any of the AST nodes that have modifiers (specifically, annotations); - * i.e. BodyDeclaration, SingleVariableDeclaration, VariableDeclarationExpression, - * and VariableDeclarationStatement. - */ -public class JDTModifiedDeclaration - implements ModifiedDeclaration -{ - private final Adapter adapter; - - - // ********** constructors ********** - - public JDTModifiedDeclaration(Adapter adapter) { - super(); - this.adapter = adapter; - } - - public JDTModifiedDeclaration(BodyDeclaration declaration) { - this(new BodyDeclarationAdapter(declaration)); - } - - public JDTModifiedDeclaration(SingleVariableDeclaration declaration) { - this(new SingleVariableDeclarationAdapter(declaration)); - } - - public JDTModifiedDeclaration(VariableDeclarationExpression declaration) { - this(new VariableDeclarationExpressionAdapter(declaration)); - } - - public JDTModifiedDeclaration(VariableDeclarationStatement declaration) { - this(new VariableDeclarationStatementAdapter(declaration)); - } - - - // ********** annotations ********** - - public Annotation getAnnotationNamed(String annotationName) { - for (Iterator<Annotation> stream = this.annotations(); stream.hasNext(); ) { - Annotation annotation = stream.next(); - if (this.annotationIsNamed(annotation, annotationName)) { - return annotation; - } - } - return null; - } - - public void removeAnnotationNamed(String annotationName) { - for (Iterator<IExtendedModifier> stream = this.getModifiers().iterator(); stream.hasNext(); ) { - IExtendedModifier modifier = stream.next(); - if (modifier.isAnnotation()) { - if (this.annotationIsNamed((Annotation) modifier, annotationName)) { - stream.remove(); - break; - } - } - } - } - - public void replaceAnnotationNamed(String oldAnnotationName, Annotation newAnnotation) { - List<IExtendedModifier> modifiers = this.getModifiers(); - for (ListIterator<IExtendedModifier> stream = modifiers.listIterator(); stream.hasNext(); ) { - IExtendedModifier modifier = stream.next(); - if (modifier.isAnnotation()) { - if (this.annotationIsNamed((Annotation) modifier, oldAnnotationName)) { - stream.set(newAnnotation); - return; - } - } - } - this.addAnnotation(newAnnotation); - } - - /** - * Add the specified annotation to the declaration. - * By convention annotations precede the "standard" (JLS2) modifiers; - * though, technically, they can be interspersed. - */ - protected void addAnnotation(Annotation annotation) { - List<IExtendedModifier> modifiers = this.getModifiers(); - for (ListIterator<IExtendedModifier> stream = modifiers.listIterator(); stream.hasNext(); ) { - if (stream.next().isModifier()) { - stream.previous(); // put the annotation *before* the first "standard" (JLS2) modifier - stream.add(annotation); - return; - } - } - modifiers.add(annotation); // just tack it on to the end - } - - /** - * Return the declaration's annotations. - */ - protected Iterator<Annotation> annotations() { - return new FilteringIterator<IExtendedModifier, Annotation>(this.getModifiers().iterator()) { - @Override - protected boolean accept(IExtendedModifier next) { - return next.isAnnotation(); - } - }; - } - - - // ********** add import ********** - - public boolean addImport(String className) { - if (className.indexOf('.') == -1) { - return true; // the class is in the default package - no need for import - } - return this.addImport(className, false); - } - - public boolean addStaticImport(String enumConstantName) { - int index1 = enumConstantName.indexOf('.'); - if (index1 == -1) { - throw new IllegalArgumentException(enumConstantName); // shouldn't happen? - } - int index2 = enumConstantName.indexOf('.', index1 + 1); - if (index2 == -1) { - return true; // the enum is in the default package - no need for import - } - return this.addImport(enumConstantName, true); - } - - public boolean addImport(String importName, boolean staticImport) { - Boolean include = this.importsInclude(importName, staticImport); - if (include != null) { - return include.booleanValue(); - } - - ImportDeclaration importDeclaration = this.getAst().newImportDeclaration(); - importDeclaration.setName(this.getAst().newName(importName)); - importDeclaration.setStatic(staticImport); - this.getImports().add(importDeclaration); - return true; - } - - /** - * Just a bit hacky: - * Return Boolean.TRUE if the import is already present. - * Return Boolean.FALSE if a colliding import is already present. - * Return null if a new import may be added. - * This hackery allows us to loop through the imports only once - * (and compose our methods). - * Pre-condition: 'importName' is not in the "default" package (i.e. it *is* qualified) - */ - protected Boolean importsInclude(String importName, boolean staticImport) { - int period = importName.lastIndexOf('.'); // should not be -1 - String importNameQualifier = importName.substring(0, period); - String shortImportName = importName.substring(period + 1); - return this.importsInclude(importName, importNameQualifier, shortImportName, staticImport); - } - - /** - * pre-calculate the qualifier and short name - */ - protected Boolean importsInclude(String importName, String importNameQualifier, String shortImportName, boolean staticImport) { - for (ImportDeclaration importDeclaration : this.getImports()) { - if (importDeclaration.isStatic() == staticImport) { - Boolean match = this.importMatches(importDeclaration, importName, importNameQualifier, shortImportName); - if (match != null) { - return match; - } - } - } - return null; - } - - /** - * we should be able to rely on the JDT model here, since we are looking - * at objects that should not be changing underneath us... - */ - protected Boolean importMatches(ImportDeclaration importDeclaration, String importName, String importNameQualifier, String shortImportName) { - // examples: - // 'importName' is "java.util.Date" - // or - // 'importName' is "java.lang.annotation.ElementType.TYPE" - String idn = importDeclaration.getName().getFullyQualifiedName(); - if (importName.equals(idn)) { - // import java.util.Date; => "Date" will resolve to "java.util.Date" - // import static java.lang.annotation.ElementType.TYPE; => "TYPE" will resolve to "java.lang.annotation.ElementType.TYPE" - return Boolean.TRUE; - } - - String shortIDN = idn.substring(idn.lastIndexOf('.') + 1); - if (shortImportName.equals(shortIDN)) { - // import java.sql.Date; => ambiguous resolution of "Date" - // import static org.foo.Bar.TYPE; => ambiguous resolution of "TYPE" - return Boolean.FALSE; - } - - if (importDeclaration.isOnDemand()) { - if (importNameQualifier.equals(idn)) { - // import java.util.*; => "Date" will resolve to "java.util.Date" - // import static java.lang.annotation.ElementType.*; => "TYPE" will resolve to "java.lang.annotation.ElementType.TYPE" - return Boolean.TRUE; - } - if (importDeclaration.isStatic()) { - if (this.enumResolves(idn, shortImportName)) { - // import static org.foo.Bar.*; => ambiguous resolution of "TYPE" - return Boolean.FALSE; - } - } else { - if (this.typeResolves(idn + '.' + shortImportName)) { - // import java.sql.*; => ambiguous resolution of "Date" - return Boolean.FALSE; - } - } - } - // no matches - OK to add explicit import - return null; - } - - protected boolean enumResolves(String enumTypeName, String enumConstantName) { - try { - return this.enumResolves_(enumTypeName, enumConstantName); - } catch (JavaModelException ex) { - throw new RuntimeException(ex); - } - } - - protected boolean enumResolves_(String enumTypeName, String enumConstantName) throws JavaModelException { - IType jdtType = this.findType_(enumTypeName); - if (jdtType == null) { - return false; - } - if ( ! jdtType.isEnum()) { - return false; - } - for (IField jdtField : jdtType.getFields()) { - if (jdtField.isEnumConstant() && jdtField.getElementName().equals(enumConstantName)) { - return true; - } - } - return false; - } - - protected boolean typeResolves(String name) { - return this.findType(name) != null; - } - - protected IType findType(String name) { - try { - return this.findType_(name); - } catch (JavaModelException ex) { - throw new RuntimeException(ex); - } - } - - protected IType findType_(String name) throws JavaModelException { - return this.getCompilationUnit().getJavaElement().getJavaProject().findType(name); - } - - protected List<ImportDeclaration> getImports() { - return this.imports(this.getCompilationUnit()); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - protected List<ImportDeclaration> imports(CompilationUnit astRoot) { - return astRoot.imports(); - } - - - // ********** annotation name resolution ********** - - public boolean annotationIsNamed(Annotation annotation, String name) { - return this.getQualifiedName(annotation).equals(name); - } - - /** - * Simply return the annotation's unqualified name if we can't "resolve" it. - */ - protected String getQualifiedName(Annotation annotation) { - ITypeBinding typeBinding = annotation.resolveTypeBinding(); - if (typeBinding != null) { - String resolvedName = typeBinding.getQualifiedName(); - if (resolvedName != null) { - return resolvedName; - } - } - // hack(?): check for a matching import because when moving a stand-alone - // annotation to its container in CombinationIndexedDeclarationAnnotationAdapter - // the container's import is added but then it won't "resolve" upon - // subsequent lookups (because the parser hasn't had time to run?)... :-( - return this.convertToFullClassName(annotation.getTypeName().getFullyQualifiedName()); - } - - /** - * If necessary, use the declaration's imports to calculate a guess as to - * the specified name's fully-qualified form. - * Simply return the unqualified name if we can't "resolve" it. - */ - protected String convertToFullClassName(String name) { - // check for fully-qualified name - return (name.lastIndexOf('.') != -1) ? name : this.resolveAgainstImports(name, false); - } - - /** - * If necessary, use the declaration's imports to calculate a guess as to - * the specified name's fully-qualified form. - * Simply return the unqualified name if we can't "resolve" it. - */ - protected String convertToFullEnumConstantName(String name) { - int index1 = name.indexOf('.'); - if (index1 == -1) { - // short name, e.g. "TYPE" - // true = look for static import of enum constant - return this.resolveAgainstImports(name, true); - } - - int index2 = name.indexOf('.', index1 + 1); - if (index2 == -1) { - // partially-qualified name, e.g. "ElementType.TYPE" - // false = look regular import of enum class, not static import of enum constant - return this.resolveAgainstImports(name, false); - } - - // fully-qualified name, e.g. "java.lang.annotation.ElementType.TYPE" - return name; - } - - /** - * Attempt to resolve the specified "short" name against the declaration's - * imports. Return the name unchanged if we can't resolve it (perhaps it is - * in the "default" package). - */ - protected String resolveAgainstImports(String shortName, boolean static_) { - for (ImportDeclaration importDeclaration : this.getImports()) { - if (importDeclaration.isStatic() == static_) { - String resolvedName = this.resolveAgainstImport(importDeclaration, shortName); - if (resolvedName != null) { - return resolvedName; - } - } - } - return shortName; // "default" package or unknown - } - - /** - * Attempt to resolve the specified "short" name against the specified - * import. Return the resolved name if the import resolves it; otherwise - * return null. - */ - protected String resolveAgainstImport(ImportDeclaration importDeclaration, String shortName) { - String idn = importDeclaration.getName().getFullyQualifiedName(); - if (importDeclaration.isOnDemand()) { - String candidate = idn + '.' + shortName; - if (importDeclaration.isStatic()) { - if (this.enumResolves(idn, shortName)) { - return candidate; - } - } else { - if (this.typeResolves(candidate)) { - return candidate; - } - } - // no match - return null; - } - - // explicit import - see whether its end matches 'shortName' - int period = idn.length() - shortName.length() - 1; - if (period < 1) { - // something must precede period - return null; - } - if ((idn.charAt(period) == '.') && idn.endsWith(shortName)) { - return idn; // probable exact match - } - return null; - } - - - // ********** miscellaneous methods ********** - - public ASTNode getDeclaration() { - return this.adapter.getDeclaration(); - } - - /** - * Return the declaration's list of modifiers. - * Element type: org.eclipse.jdt.core.dom.IExtendedModifier - */ - protected List<IExtendedModifier> getModifiers() { - return this.adapter.getModifiers(); - } - - public AST getAst() { - return this.getDeclaration().getAST(); - } - - protected CompilationUnit getCompilationUnit() { - return (CompilationUnit) this.getDeclaration().getRoot(); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.adapter.toString()); - } - - - // ********** declaration adapter interface and implementations ********** - - /** - * Define common protocol among the various "declarations". - */ - public interface Adapter { - - /** - * Return the adapted "declaration". - */ - ASTNode getDeclaration(); - - /** - * Return the "declaration"'s list of modifiers. - * Element type: org.eclipse.jdt.core.dom.IExtendedModifier - */ - List<IExtendedModifier> getModifiers(); - - } - - public static class BodyDeclarationAdapter implements Adapter { - private final BodyDeclaration declaration; - public BodyDeclarationAdapter(BodyDeclaration declaration) { - super(); - this.declaration = declaration; - } - public ASTNode getDeclaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> getModifiers() { - return this.declaration.modifiers(); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.declaration.toString()); - } - } - - public static class SingleVariableDeclarationAdapter implements Adapter { - private final SingleVariableDeclaration declaration; - public SingleVariableDeclarationAdapter(SingleVariableDeclaration declaration) { - super(); - this.declaration = declaration; - } - public ASTNode getDeclaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> getModifiers() { - return this.declaration.modifiers(); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.declaration.toString()); - } - } - - public static class VariableDeclarationExpressionAdapter implements Adapter { - private final VariableDeclarationExpression declaration; - public VariableDeclarationExpressionAdapter(VariableDeclarationExpression declaration) { - super(); - this.declaration = declaration; - } - public ASTNode getDeclaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> getModifiers() { - return this.declaration.modifiers(); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.declaration.toString()); - } - } - - public static class VariableDeclarationStatementAdapter implements Adapter { - private final VariableDeclarationStatement declaration; - public VariableDeclarationStatementAdapter(VariableDeclarationStatement declaration) { - super(); - this.declaration = declaration; - } - public ASTNode getDeclaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> getModifiers() { - return this.declaration.modifiers(); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.declaration.toString()); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTTools.java deleted file mode 100644 index a7f93390f9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTTools.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility.jdt; - -import java.util.HashSet; -import java.util.List; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ASTParser; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.IAnnotationBinding; -import org.eclipse.jdt.core.dom.IBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.IVariableBinding; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.Name; -import org.eclipse.jdt.core.dom.SingleVariableDeclaration; -import org.eclipse.jdt.core.dom.TypeLiteral; -import org.eclipse.jpt.utility.JavaType; -import org.eclipse.jpt.utility.MethodSignature; -import org.eclipse.jpt.utility.internal.SimpleJavaType; -import org.eclipse.jpt.utility.internal.SimpleMethodSignature; - -/** - * Convenience methods for dealing with JDT objects. - */ -public class JDTTools { - - /** - * Build an AST for the specified compilation unit with its bindings - * resolved (and the resultant performance hit). - */ - public static CompilationUnit buildASTRoot(ICompilationUnit compilationUnit) { - ASTParser parser = ASTParser.newParser(AST.JLS3); - parser.setSource(compilationUnit); -// TODO -// parser.setFocalPosition(0); - parser.setResolveBindings(true); - parser.setBindingsRecovery(true); // see bugs 196200, 222735 - return (CompilationUnit) parser.createAST(null); - } - - - // ********** JDT DOM ********** - - public static String resolveEnum(Expression expression) { - if (expression == null) { - return null; - } - switch (expression.getNodeType()) { - case ASTNode.QUALIFIED_NAME: - case ASTNode.SIMPLE_NAME: - return resolveEnum((Name) expression); - default: - return null; - } - } - - public static String resolveEnum(Name enumExpression) { - IBinding binding = enumExpression.resolveBinding(); - if (binding == null) { - return null; // TODO figure out why this is null sometimes - } - if (binding.getKind() != IBinding.VARIABLE) { - return null; - } - IVariableBinding variableBinding = (IVariableBinding) binding; - return variableBinding.getType().getQualifiedName() + '.' + variableBinding.getName(); - } - - /** - * Return the fully-qualified name of the specified node's annotation - * class. - */ - public static String resolveAnnotation(Annotation node) { - IAnnotationBinding annotationBinding = node.resolveAnnotationBinding(); - if (annotationBinding == null) { - return null; - } - ITypeBinding annotationTypeBinding = annotationBinding.getAnnotationType(); - return (annotationTypeBinding == null) ? null : annotationTypeBinding.getQualifiedName(); - } - - /** - * If the specified expression is a type literal, return the type's fully- - * qualified name. Return null otherwise. - */ - public static String resolveFullyQualifiedName(Expression expression) { - ITypeBinding resolvedTypeBinding = resolveTypeBinding(expression); - return (resolvedTypeBinding == null) ? null : resolvedTypeBinding.getQualifiedName(); - } - - /** - * If the specified expression is a type literal, return the corresponding - * type binding. - */ - public static ITypeBinding resolveTypeBinding(Expression expression) { - if (expression.getNodeType() == ASTNode.TYPE_LITERAL) { - return ((TypeLiteral) expression).getType().resolveBinding(); - } - return null; - } - - public static MethodSignature buildMethodSignature(MethodDeclaration methodDeclaration) { - return new SimpleMethodSignature( - methodDeclaration.getName().getFullyQualifiedName(), - buildParameterTypes(methodDeclaration) - ); - } - - public static JavaType[] buildParameterTypes(MethodDeclaration methodDeclaration) { - List<SingleVariableDeclaration> parameters = parameters(methodDeclaration); - int len = parameters.size(); - JavaType[] parameterTypes = new JavaType[len]; - for (int i = 0; i < len; i++) { - ITypeBinding type = parameters.get(i).getType().resolveBinding(); - parameterTypes[i] = new SimpleJavaType(type.getQualifiedName(), type.getDimensions()); - } - return parameterTypes; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private static List<SingleVariableDeclaration> parameters(MethodDeclaration methodDeclaration) { - return methodDeclaration.parameters(); - } - - /** - * Return whether the specified expression is a type literal and the type binding - * corresponding to the specified type name exists in the type - * literal's inheritance hierarchy (superclasses and interfaces). - * Return null otherwise. - */ - public static boolean typeIsSubTypeOf(Expression expression, String searchTypeName) { - return findTypeInHierarchy(expression, searchTypeName) != null; - } - - /** - * If the specified expression is a type literal, return the type binding - * corresponding to the specified type name if it exists in the type - * literal's inheritance hierarchy (superclasses and interfaces). - * Return null otherwise. - */ - public static ITypeBinding findTypeInHierarchy(Expression expression, String searchTypeName) { - ITypeBinding typeBinding = resolveTypeBinding(expression); - return (typeBinding == null) ? null : findTypeInHierarchy(typeBinding, searchTypeName); - } - - /** - * Return whether a type binding with the specified type name exists in - * the specified type binding's inheritance hierarchy (superclasses - * and interfaces). - */ - public static boolean typeIsSubTypeOf(ITypeBinding typeBinding, String searchTypeName) { - return findTypeInHierarchy(typeBinding, searchTypeName) != null; - } - - /** - * Return the type binding corresponding to the specified type name if it - * exists in the specified type binding's inheritance hierarchy (superclasses - * and interfaces). Return null otherwise. - */ - public static ITypeBinding findTypeInHierarchy(ITypeBinding typeBinding, String searchTypeName) { - return findTypeInHierarchy(typeBinding, searchTypeName, new HashSet<String>()); - } - - private static ITypeBinding findTypeInHierarchy(ITypeBinding typeBinding, String searchTypeName, HashSet<String> visited) { - String typeName = typeBinding.getQualifiedName(); - if (visited.contains(typeName)) { - return null; - } - if (typeName.equals(searchTypeName)) { - return typeBinding; - } - visited.add(typeName); - - ITypeBinding[] interfaceBindings = typeBinding.getInterfaces(); - for (ITypeBinding interfaceBinding : interfaceBindings) { // recurse up interfaces - ITypeBinding result = findTypeInHierarchy(interfaceBinding, searchTypeName, visited); - if (result != null) { - return result; - } - } - - ITypeBinding superBinding = typeBinding.getSuperclass(); - if (superBinding != null) { // recurse up superclasses - ITypeBinding result = findTypeInHierarchy(superBinding, searchTypeName, visited); - if (result != null) { - return result; - } - } - - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTType.java deleted file mode 100644 index 26de333d42..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTType.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility.jdt; - -import java.util.List; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.FieldDeclaration; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.CommandExecutor; - -/** - * Adapt and extend a JDT type. - */ -public class JDTType - extends JDTMember - implements Type -{ - - /** - * constructor for the compilation unit's primary type - */ - public JDTType( - TypeDeclaration typeDeclaration, // exclude annotations and enums - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor) { - this(typeDeclaration, compilationUnit, modifySharedDocumentCommandExecutor, DefaultAnnotationEditFormatter.instance()); - } - - /** - * constructor for the compilation unit's primary type - */ - public JDTType( - TypeDeclaration typeDeclaration, // exclude annotations and enums - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor, - AnnotationEditFormatter annotationEditFormatter) { - this(null, typeDeclaration, 1, compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter); - } - - /** - * constructor for nested types - */ - public JDTType( - Type declaringType, - TypeDeclaration typeDeclaration, // exclude annotations and enums - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor) { - this(declaringType, typeDeclaration, occurrence, compilationUnit, modifySharedDocumentCommandExecutor, DefaultAnnotationEditFormatter.instance()); - } - - /** - * constructor for nested types - */ - public JDTType( - Type declaringType, - TypeDeclaration typeDeclaration, // exclude annotations and enums - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutor modifySharedDocumentCommandExecutor, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, typeDeclaration.getName().getFullyQualifiedName(), occurrence, compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter); - } - - /** - * constructor for testing - */ - public JDTType(Type declaringType, String name, int occurrence, ICompilationUnit compilationUnit) { - super(declaringType, name, occurrence, compilationUnit, CommandExecutor.Default.instance(), DefaultAnnotationEditFormatter.instance()); - } - - - // ********** Member/Type implementation ********** - - public ITypeBinding getBinding(CompilationUnit astRoot) { - TypeDeclaration td = this.getBodyDeclaration(astRoot); - return (td == null) ? null : td.resolveBinding(); - } - - /** - * find the type's body declaration in the specified AST - */ - public TypeDeclaration getBodyDeclaration(CompilationUnit astRoot) { - Type declaringType = this.getDeclaringType(); - return (declaringType == null) ? - this.getTopLevelTypeDeclaration(astRoot) - : - this.getNestedTypeDeclaration(declaringType.getBodyDeclaration(astRoot)); - } - - public boolean isPersistable(CompilationUnit astRoot) { - ITypeBinding binding = this.getBinding(astRoot); - return (binding == null) ? false : JPTTools.typeIsPersistable(new JPTToolsAdapter(binding)); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName()); - } - - public TypeDeclaration[] getTypes(CompilationUnit astRoot) { - return this.getBodyDeclaration(astRoot).getTypes(); - } - - public FieldDeclaration[] getFields(CompilationUnit astRoot) { - return this.getBodyDeclaration(astRoot).getFields(); - } - - public MethodDeclaration[] getMethods(CompilationUnit astRoot) { - return this.getBodyDeclaration(astRoot).getMethods(); - } - - - // ********** internal ********** - - /** - * return the first top-level type in the specified AST with a matching name - */ - protected TypeDeclaration getTopLevelTypeDeclaration(CompilationUnit astRoot) { - return this.getTypeDeclaration(types(astRoot)); - } - - protected TypeDeclaration getTypeDeclaration(List<AbstractTypeDeclaration> typeDeclarations) { - return this.getTypeDeclaration(typeDeclarations.toArray(new AbstractTypeDeclaration[typeDeclarations.size()])); - } - - /** - * return the nested type with a matching name and occurrence - */ - protected TypeDeclaration getNestedTypeDeclaration(TypeDeclaration declaringTypeDeclaration) { - return this.getTypeDeclaration(declaringTypeDeclaration.getTypes()); - } - - /** - * return the type declaration corresponding to the type from the specified - * set of type declarations (match name and occurrence) - */ - protected TypeDeclaration getTypeDeclaration(AbstractTypeDeclaration[] typeDeclarations) { - String name = this.getName_(); - int occurrence = this.getOccurrence(); - int count = 0; - for (AbstractTypeDeclaration typeDeclaration : typeDeclarations) { - if (typeDeclaration.getName().getFullyQualifiedName().equals(name)) { - count++; - if (count == occurrence) { - return (typeDeclaration.getNodeType() == ASTNode.TYPE_DECLARATION) ? (TypeDeclaration) typeDeclaration : null; - } - } - } - // return null if the type is no longer in the source code; - // this can happen when the context model has not yet - // been synchronized with the resource model but is still - // asking for an ASTNode (e.g. during a selection event) - return null; - } - - /** - * we only instantiate a single top-level, non-enum, non-annotation - * type per compilation unit (i.e. a class or interface); and, since - * enums and annotations can only be top-level types (i.e. they cannot - * be nested within another type) we will always have TypeDeclarations - * in the CompilationUnit - */ - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - protected static List<AbstractTypeDeclaration> types(CompilationUnit astRoot) { - return astRoot.types(); - } - - - // ********** JPT tools adapter ********** - - protected static class JPTToolsAdapter implements JPTTools.TypeAdapter { - private final ITypeBinding typeBinding; - protected JPTToolsAdapter(ITypeBinding typeBinding) { - super(); - if (typeBinding == null) { - throw new NullPointerException(); - } - this.typeBinding = typeBinding; - } - - public int getModifiers() { - return this.typeBinding.getModifiers(); - } - - public boolean isAnnotation() { - return this.typeBinding.isAnnotation(); - } - - public boolean isAnonymous() { - return this.typeBinding.isAnonymous(); - } - - public boolean isArray() { - return this.typeBinding.isArray(); - } - - public boolean isEnum() { - return this.typeBinding.isEnum(); - } - - public boolean isInterface() { - return this.typeBinding.isInterface(); - } - - public boolean isLocal() { - return this.typeBinding.isLocal(); - } - - public boolean isMember() { - return this.typeBinding.isMember(); - } - - public boolean isPrimitive() { - return this.typeBinding.isPrimitive(); - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java deleted file mode 100644 index 4ab0e88d3d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility.jdt; - -import java.lang.reflect.Modifier; -import java.util.Iterator; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -/** - * Convenience methods for JPA-related queries concerning JDT objects. - */ -public class JPTTools { - - // ********** type ********** - - /** - * Return whether the specified type can be "persisted", i.e. marked as - * Entity, MappedSuperclass, Embeddable - */ - // TODO check for no-arg constructor (or should that just be validation?) - // TODO move other checks to validation (e.g. 'final', 'static')? - public static boolean typeIsPersistable(TypeAdapter typeAdapter) { - if (typeAdapter.isInterface()) { - return false; - } - if (typeAdapter.isAnnotation()) { - return false; - } - if (typeAdapter.isEnum()) { - return false; - } - if (typeAdapter.isLocal()) { - return false; - } - if (typeAdapter.isAnonymous()) { - return false; - } - if (typeAdapter.isPrimitive()) { - return false; // should never get here(?) - } - if (typeAdapter.isArray()) { - return false; // should never get here(?) - } - int modifiers = typeAdapter.getModifiers(); - if (Modifier.isFinal(modifiers)) { - return false; - } - if (typeAdapter.isMember()) { - if ( ! Modifier.isStatic(modifiers)) { - return false; - } - } - return true; - } - - /** - * Queries needed to calculate whether a type is "persistable". - * Adapted to ITypeBinding and IType. - */ - public interface TypeAdapter { - int getModifiers(); - boolean isAnnotation(); - boolean isAnonymous(); - boolean isArray(); - boolean isEnum(); - boolean isInterface(); - boolean isLocal(); - boolean isMember(); - boolean isPrimitive(); - } - - - // ********** field ********** - - /** - * Return whether the specified field may be "persisted". - * According to the spec, "All non-transient instance variables that are not - * annotated with the Transient annotation are persistent." - */ - public static boolean fieldIsPersistable(FieldAdapter fieldAdapter) { - int modifiers = fieldAdapter.getModifiers(); - if (Modifier.isStatic(modifiers)) { - return false; - } - if (Modifier.isTransient(modifiers)) { - return false; - } - return true; - } - - /** - * Queries needed to calculate whether a field is "persistable". - * Adapted to IVariableBinding and IField. - */ - public interface FieldAdapter { - /** - * Return the field's modifiers. We use these to check whether the - * field is static or transient. - */ - int getModifiers(); - } - - - // ********** method ********** - - /** - * Return whether the specified method is a "getter" method that - * represents a property that may be "persisted". - */ - public static boolean methodIsPersistablePropertyGetter(MethodAdapter methodAdapter) { - if (methodHasInvalidModifiers(methodAdapter)) { - return false; - } - if (methodAdapter.isConstructor()) { - return false; - } - - String returnTypeName = methodAdapter.getReturnTypeErasureName(); - if (returnTypeName == null) { - return false; // DOM method bindings can have a null name - } - if (returnTypeName.equals("void")) { //$NON-NLS-1$ - return false; - } - if (methodHasParameters(methodAdapter)) { - return false; - } - - String name = methodAdapter.getName(); - int beginIndex = 0; - boolean booleanGetter = false; - if (name.startsWith("is")) { //$NON-NLS-1$ - if (returnTypeName.equals("boolean")) { //$NON-NLS-1$ - beginIndex = 2; - } else { - return false; - } - } else if (name.startsWith("get")) { //$NON-NLS-1$ - beginIndex = 3; - if (returnTypeName.equals("boolean")) { //$NON-NLS-1$ - booleanGetter = true; - } - } else { - return false; - } - - String capitalizedAttributeName = name.substring(beginIndex); - // if the type has both methods: - // boolean isProperty() - // boolean getProperty() - // then #isProperty() takes precedence and we ignore #getProperty(); - // but only having #getProperty() is OK too - // (see the JavaBeans spec 1.01) - if (booleanGetter && methodHasValidSiblingIsMethod(methodAdapter, capitalizedAttributeName)) { - return false; // since the type also defines #isProperty(), ignore #getProperty() - } - return methodHasValidSiblingSetMethod(methodAdapter, capitalizedAttributeName, returnTypeName); - } - - /** - * Return whether the method's modifiers prevent it - * from being a getter or setter for a "persistent" property. - */ - private static boolean methodHasInvalidModifiers(SimpleMethodAdapter methodAdapter) { - int modifiers = methodAdapter.getModifiers(); - if (Modifier.isStatic(modifiers)) { - return true; - } - if (Modifier.isFinal(modifiers)) { - return true; - } - if ( ! (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers))) { - return true; - } - return false; - } - - private static boolean methodHasParameters(MethodAdapter methodAdapter) { - return methodAdapter.getParametersLength() != 0; - } - - /** - * Return whether the method has a sibling "is" method for the specified - * property and that method is valid for a "persistable" property. - * Pre-condition: the method is a "boolean getter" (e.g. 'public boolean getProperty()'); - * this prevents us from returning true when the method itself is an - * "is" method. - */ - private static boolean methodHasValidSiblingIsMethod(MethodAdapter methodAdapter, String capitalizedAttributeName) { - SimpleMethodAdapter isMethodAdapter = methodAdapter.getSibling("is" + capitalizedAttributeName); //$NON-NLS-1$ - return methodIsValidSibling(isMethodAdapter, "boolean"); //$NON-NLS-1$ - } - - /** - * Return whether the method has a sibling "set" method - * and that method is valid for a "persistable" property. - */ - private static boolean methodHasValidSiblingSetMethod(MethodAdapter methodAdapter, String capitalizedAttributeName, String parameterTypeErasureName) { - SimpleMethodAdapter setMethodAdapter = methodAdapter.getSibling("set" + capitalizedAttributeName, parameterTypeErasureName); //$NON-NLS-1$ - return methodIsValidSibling(setMethodAdapter, "void"); //$NON-NLS-1$ - } - - /** - * Return whether the specified method is a valid sibling with the - * specified return type. - */ - private static boolean methodIsValidSibling(SimpleMethodAdapter methodAdapter, String returnTypeName) { - if (methodAdapter == null) { - return false; - } - if (methodHasInvalidModifiers(methodAdapter)) { - return false; - } - if (methodAdapter.isConstructor()) { - return false; - } - String rtName = methodAdapter.getReturnTypeErasureName(); - if (rtName == null) { - return false; // DOM method bindings can have a null name - } - return rtName.equals(returnTypeName); - } - - /** - * Queries needed to calculate whether a method is "persistable". - * Adapted to IMethodBinding and IMethod. - */ - public interface SimpleMethodAdapter { - /** - * Return the method's modifiers. - * We use these to check whether the method is static, final, etc. - */ - int getModifiers(); - - /** - * Return the name of the method's return type erasure. - * We use this to check for - * - boolean getters - * - void return types - * - matching getters and setters - */ - String getReturnTypeErasureName(); - - /** - * Return whether the method is a constructor. - */ - boolean isConstructor(); - } - - /** - * Queries needed to calculate whether a method is "persistable". - * Adapted to IMethodBinding and IMethod. - */ - public interface MethodAdapter extends SimpleMethodAdapter { - /** - * Return the method's name. - * We use this to determine - * - whether the method is a "getter" - * - the property name implied by the getter's name - */ - String getName(); - - /** - * Return the number of paramters declared by the method. - * We use this to determine whether the method is a "getter". - */ - int getParametersLength(); - - /** - * Return the method's "sibling" with the specified name and no parameters. - * We use this to find an "is" boolean getter that would take precedence - * over a "get" boolean getter. - */ - SimpleMethodAdapter getSibling(String name); - - /** - * Return the method's "sibling" with the specified name and single parameter. - * We use this to find a matching "setter" for a possible "getter". - */ - SimpleMethodAdapter getSibling(String name, String parameterTypeErasureName); - } - - - // ********** Access type ********** - - /** - * Return the AccessType currently implied by the Java source code - * or class file: - * - if only Fields are annotated => FIELD - * - if only Properties are annotated => PROPERTY - * - if both Fields and Properties are annotated => FIELD - * - if nothing is annotated - * - and fields exist => FIELD - * - and properties exist, but no fields exist => PROPERTY - * - and neither fields nor properties exist => null at this level (FIELD in the context model) - */ - public static AccessType buildAccess(JavaResourcePersistentType jrpType) { - boolean hasPersistableFields = false; - for (Iterator<JavaResourcePersistentAttribute> stream = jrpType.persistableFields(); stream.hasNext(); ) { - hasPersistableFields = true; - if (stream.next().isAnnotated()) { - // any field is annotated => FIELD - return AccessType.FIELD; - } - } - - boolean hasPersistableProperties = false; - for (Iterator<JavaResourcePersistentAttribute> stream = jrpType.persistableProperties(); stream.hasNext(); ) { - hasPersistableProperties = true; - if (stream.next().isAnnotated()) { - // none of the fields are annotated and a getter is annotated => PROPERTY - return AccessType.PROPERTY; - } - } - - if (hasPersistableProperties && ! hasPersistableFields) { - return AccessType.PROPERTY; - } - - // if no annotations exist, access is null at the resource model level - return null; - } - - - // ********** suppressed constructor ********** - - /** - * Suppress default constructor, ensuring non-instantiability. - */ - private JPTTools() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberAnnotationAdapter.java deleted file mode 100644 index 5b92fa57d8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberAnnotationAdapter.java +++ /dev/null @@ -1,27 +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.utility.jdt; - -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * Adapt a member and a declaration annotation adapter. - */ -public class MemberAnnotationAdapter extends AbstractAnnotationAdapter { - - - // ********** constructor ********** - - public MemberAnnotationAdapter(Member member, DeclarationAnnotationAdapter daa) { - super(member, daa); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberAnnotationElementAdapter.java deleted file mode 100644 index 89f854f2e5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberAnnotationElementAdapter.java +++ /dev/null @@ -1,99 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; - - /** - * Adapt a member and a declaration annotation element adapter. - */ -public class MemberAnnotationElementAdapter<T> - implements AnnotationElementAdapter<T> -{ - private final Member member; - private final DeclarationAnnotationElementAdapter<T> daea; - - - // ********** constructor ********** - - public MemberAnnotationElementAdapter(Member member, DeclarationAnnotationElementAdapter<T> daea) { - super(); - this.member = member; - this.daea = daea; - } - - - // ********** AnnotationElementAdapter implementation ********** - - public T getValue() { - return this.daea.getValue(this.member.getModifiedDeclaration()); - } - - public T getValue(CompilationUnit astRoot) { - return this.daea.getValue(this.member.getModifiedDeclaration(astRoot)); - } - - public void setValue(T value) { - this.edit(this.buildSetValueEditor(value)); - } - - public Expression getExpression(CompilationUnit astRoot) { - return this.daea.getExpression(this.member.getModifiedDeclaration(astRoot)); - } - - public ASTNode getAstNode(CompilationUnit astRoot) { - return this.daea.getAstNode(this.member.getModifiedDeclaration(astRoot)); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.daea); - } - - - // ********** internal methods ********** - - protected void edit(Member.Editor editor) { - this.member.edit(editor); - } - - protected Member.Editor buildSetValueEditor(T value) { - return new SetValueEditor<T>(value, this.daea); - } - - - // ********** member classes ********** - - protected static class SetValueEditor<T> implements Member.Editor { - private final DeclarationAnnotationElementAdapter<T> daea; - private final T value; - - SetValueEditor(T value, DeclarationAnnotationElementAdapter<T> daea) { - super(); - this.value = value; - this.daea = daea; - } - public void edit(ModifiedDeclaration declaration) { - this.daea.setValue(this.value, declaration); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberIndexedAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberIndexedAnnotationAdapter.java deleted file mode 100644 index aceeb48616..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/MemberIndexedAnnotationAdapter.java +++ /dev/null @@ -1,74 +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.utility.jdt; - -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Adapt a member and an indexed declaration annotation adapter. - */ -public class MemberIndexedAnnotationAdapter - extends AbstractAnnotationAdapter - implements IndexedAnnotationAdapter -{ - private final IndexedDeclarationAnnotationAdapter idaa; - - - // ********** constructor ********** - - public MemberIndexedAnnotationAdapter(Member member, IndexedDeclarationAnnotationAdapter idaa) { - super(member, idaa); - this.idaa = idaa; - } - - - // ********** IndexedAnnotationAdapter implementation ********** - - public int getIndex() { - return this.idaa.getIndex(); - } - - public void moveAnnotation(int newIndex) { - this.edit(this.buildMoveAnnotationEditor(newIndex)); - } - - - // ********** factory methods ********** - - protected Member.Editor buildMoveAnnotationEditor(int newIndex) { - return new MoveAnnotationEditor(this.idaa, newIndex); - } - - - // ********** member classes ********** - - protected static class MoveAnnotationEditor implements Member.Editor { - private final IndexedDeclarationAnnotationAdapter idaa; - private int index; - - MoveAnnotationEditor(IndexedDeclarationAnnotationAdapter idaa, int index) { - super(); - this.idaa = idaa; - this.index = index; - } - public void edit(ModifiedDeclaration declaration) { - this.idaa.moveAnnotation(this.index, declaration); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NameStringExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NameStringExpressionConverter.java deleted file mode 100644 index 56fd65a386..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NameStringExpressionConverter.java +++ /dev/null @@ -1,57 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.Name; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a name to/from a string representation of a name/identifier - * (e.g. "com.xxx.Foo.VALUE1" or "value"). - */ -public final class NameStringExpressionConverter - extends AbstractExpressionConverter<String> -{ - private static final ExpressionConverter<String> INSTANCE = new NameStringExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<String> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NameStringExpressionConverter() { - super(); - } - - @Override - protected Name convertObject(String string, AST ast) { - return ast.newName(string); - } - - @Override - protected String convertExpression(Expression expression) { - switch (expression.getNodeType()) { - case ASTNode.QUALIFIED_NAME: - case ASTNode.SIMPLE_NAME: - return ((Name) expression).getFullyQualifiedName(); - default: - return null; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NestedDeclarationAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NestedDeclarationAnnotationAdapter.java deleted file mode 100644 index 2b991a7c2e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NestedDeclarationAnnotationAdapter.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.utility.jdt; - -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Manipulate an annotation that is embedded as an element within - * another annotation, e.g. - * <pre> - * @Outer(foo=@Inner) - * private int id; - * outerAnnotationAdapter = AnnotationAdapter<@Outer> - * elementName = "foo" - * annotationName = "Inner" - * </pre> - */ -public class NestedDeclarationAnnotationAdapter extends AbstractNestedDeclarationAnnotationAdapter { - - - // ********** constructors ********** - - /** - * default element name is "value"; - * default behavior is to remove the outer annotation when it is empty - */ - public NestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String annotationName) { - super(outerAnnotationAdapter, annotationName); - } - - /** - * default behavior is to remove the outer annotation when it is empty - */ - public NestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String elementName, String annotationName) { - super(outerAnnotationAdapter, elementName, annotationName); - } - - public NestedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter outerAnnotationAdapter, String elementName, String annotationName, boolean removeOuterAnnotationWhenEmpty) { - super(outerAnnotationAdapter, elementName, annotationName, removeOuterAnnotationWhenEmpty); - } - - - // ********** AbstractNestedDeclarationAnnotationAdapter implementation ********** - - @Override - protected Annotation getAnnotation(Expression value) { - return this.annotationValue(value); - } - - @Override - protected Expression buildNewInnerExpression(Annotation inner) { - return inner; - } - - /** - * the annotation is the expression itself, so the annotation cannot be - * "removed" from itself - return 'false' - */ - @Override - protected boolean removeAnnotation(ModifiedDeclaration declaration, Annotation outer, Expression value) { - return false; - } - - /** - * <pre> - * @Outer("lorem ipsum") => @Outer(@Inner) - * </pre> - */ - @Override - protected void modifyAnnotationValue(SingleMemberAnnotation outer, Annotation inner) { - // replace(?) the current element value - outer.setValue(inner); - } - - /** - * Simply set the pair's value. - */ - @Override - protected void modifyMemberValuePair(MemberValuePair pair, Annotation inner) { - pair.setValue(inner); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapter.java deleted file mode 100644 index 8f39485e0e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,334 +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.utility.jdt; - -import java.util.List; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.ArrayInitializer; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Manipulate an annotation that is embedded in an element array within - * another annotation, e.g. - * <pre> - * @Outer(foo={@Inner("zero"), @Inner("one"), @Inner("two")}) - * private int id; - * outerAnnotationAdapter = AnnotationAdapter<@Outer> - * elementName = "foo" - * index = 0-2 - * annotationName = "Inner" - * </pre> - */ -public class NestedIndexedDeclarationAnnotationAdapter - extends AbstractNestedDeclarationAnnotationAdapter - implements IndexedDeclarationAnnotationAdapter -{ - private int index; - - - // ********** constructors ********** - - /** - * default element name is "value"; - * default behavior is to remove the outer annotation when it is empty - */ - public NestedIndexedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter annotationAdapter, int index, String annotationName) { - super(annotationAdapter, annotationName); - this.index = index; - } - - /** - * default behavior is to remove the outer annotation when it is empty - */ - public NestedIndexedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, int index, String annotationName) { - super(annotationAdapter, elementName, annotationName); - this.index = index; - } - - public NestedIndexedDeclarationAnnotationAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, int index, String annotationName, boolean removeOuterAnnotationWhenEmpty) { - super(annotationAdapter, elementName, annotationName, removeOuterAnnotationWhenEmpty); - this.index = index; - } - - - // ********** AbstractNestedDeclarationAnnotationAdapter implementation ********** - - @Override - protected Annotation getAnnotation(Expression value) { - if (value.getNodeType() == ASTNode.ARRAY_INITIALIZER) { - return this.annotation((ArrayInitializer) value); - } - return (this.index == 0) ? this.annotationValue(value) : null; - } - - @Override - protected Expression buildNewInnerExpression(Annotation inner) { - return (this.index == 0) ? inner : (Expression) this.buildNewInnerArrayInitializer(inner); - } - - @Override - protected boolean removeAnnotation(ModifiedDeclaration declaration, Annotation outer, Expression value) { - if (value.getNodeType() == ASTNode.ARRAY_INITIALIZER) { - this.removeAnnotation(declaration, outer, (ArrayInitializer) value); - return true; - } - // if our index is greater than zero, but we don't have an array, - // then the annotation must already be gone - return (this.index != 0); - } - - /** - * <pre> - * @Outer({@Inner(0), @Inner(1)}) => @Outer({@Inner(0), @Inner(1), @Inner(2)}) - * or - * @Outer("lorem ipsum") => @Outer(@Inner(0)) - * or - * @Outer(@Inner(0)) => @Outer({@Inner(0), @Inner(1)}) - * </pre> - */ - @Override - protected void modifyAnnotationValue(SingleMemberAnnotation outer, Annotation inner) { - this.modifyExpression(outer, SINGLE_MEMBER_ANNOTATION_EXPRESSION_PROVIDER, inner); - } - - /** - * <pre> - * @Outer(text="lorem ipsum") => @Outer(text="lorem ipsum", foo=@Inner(0)) - * or - * @Outer(foo={@Inner(0), @Inner(1)}) => @Outer(foo={@Inner(0), @Inner(1), @Inner(2)}) - * or - * @Outer(foo="lorem ipsum") => @Outer(foo=@Inner(0)) - * or - * @Outer(foo=@NotInner) => @Outer(foo=@Inner(0)) - * or - * @Outer(foo=@Inner(0)) => @Outer(foo={@Inner(0), @Inner(1)}) - * </pre> - */ - @Override - protected void modifyMemberValuePair(MemberValuePair pair, Annotation inner) { - this.modifyExpression(pair, MEMBER_VALUE_PAIR_EXPRESSION_PROVIDER, inner); - } - - - // ********** IndexedDeclarationAnnotationAdapter implementation ********** - - public int getIndex() { - return this.index; - } - - /** - * Move the annotation to the specified index, leaving its original - * position cleared out. - */ - public void moveAnnotation(int newIndex, ModifiedDeclaration declaration) { - int oldIndex = this.index; - if (newIndex == oldIndex) { - return; - } - - Annotation original = this.getAnnotation(declaration); - if (original == null) { - this.index = newIndex; - this.removeAnnotation(declaration); // clear out the new location (?) - } else { - Annotation copy = (Annotation) ASTNode.copySubtree(original.getAST(), original); - this.index = newIndex; - this.addAnnotation(declaration, copy); // install the copy in the new location - this.index = oldIndex; - this.removeAnnotation(declaration); // go back and clear out the original location (AFTER the move) - this.index = newIndex; - } - } - - - // ********** internal methods ********** - - /** - * Return the adapter's annotation from the specified array initializer. - */ - private Annotation annotation(ArrayInitializer value) { - List<Expression> expressions = this.expressions(value); - return (this.index >= expressions.size()) ? null : this.annotationValue(expressions.get(this.index)); - } - - /** - * Build a new array initializer to hold the specified annotation, - * padding it with 'null' literals as necessary - */ - private ArrayInitializer buildNewInnerArrayInitializer(Annotation inner) { - ArrayInitializer ai = inner.getAST().newArrayInitializer(); - this.addInnerToExpressions(inner, this.expressions(ai)); - return ai; - } - - /** - * Add the specified annotation to the specified array initializer, - * padding it with 'null' literals as necessary - */ - private void addInnerToExpressions(Annotation inner, List<Expression> expressions) { - if (expressions.size() > this.index) { - throw new IllegalStateException("expressions size is greater than index - size: " + expressions.size() + " - index: " + this.index); //$NON-NLS-1$ //$NON-NLS-2$ - } - while (expressions.size() < this.index) { - expressions.add(inner.getAST().newNullLiteral()); - } - expressions.add(inner); - } - - /** - * Remove the adapter's annotation from the specified array initializer. - */ - private void removeAnnotation(ModifiedDeclaration declaration, Annotation outer, ArrayInitializer value) { - List<Expression> expressions = this.expressions(value); - if (this.index >= expressions.size()) { - return; // avoid IndexOutOfBoundsException(?) - } - Annotation inner = this.annotationValue(expressions.get(this.index)); - if (inner == null) { - return; - } - if ( ! this.nameMatches(declaration, inner)) { - return; - } - if (this.index == (expressions.size() - 1)) { - expressions.remove(this.index); - } else { - expressions.set(this.index, value.getAST().newNullLiteral()); - } - this.trimExpressions(declaration, outer, expressions); - } - - /** - * Strip all the null literals off the end of the specified list of expressions - * and normalize the specified outer annotation. - */ - private void trimExpressions(ModifiedDeclaration declaration, Annotation outer, List<Expression> expressions) { - // start at the end of the list - for (int i = expressions.size(); i-- > 0; ) { - if (expressions.get(i).getNodeType() == ASTNode.NULL_LITERAL) { - expressions.remove(i); - } else { - break; // stop with the first non-null literal encountered - } - } - switch (expressions.size()) { - case 0: - this.removeElementAndNormalize(declaration, outer); - break; - case 1: - this.convertArrayToLastRemainingExpression(outer, expressions.get(0)); - break; - default: - break; - } - } - - /** - * When there is only a single element in an array initializer, convert the - * expression to be just the single element; e.g. - * <pre> - * @Foo(xxx={"abc"}) => @Foo(xxx="abc") - * or - * @Foo({"abc"}) => @Foo("abc") - * </pre> - */ - private void convertArrayToLastRemainingExpression(Annotation outer, Expression lastValue) { - lastValue = (Expression) ASTNode.copySubtree(lastValue.getAST(), lastValue); - if (outer.isNormalAnnotation()) { - this.memberValuePair((NormalAnnotation) outer).setValue(lastValue); - } else if (outer.isSingleMemberAnnotation()) { - ((SingleMemberAnnotation) outer).setValue(lastValue); - } else { - throw new IllegalArgumentException("unexpected annotation type: " + outer); //$NON-NLS-1$ - } - } - - /** - * Manipulate the specified expression appropriately. - * If it is an array initializer, add the specified annotation to it. - * If it is not, replace the expression or convert it into an array - * initializer. - */ - private void modifyExpression(ASTNode node, ExpressionProvider expProvider, Annotation inner) { - Expression value = expProvider.getExpression(node); - if (value.getNodeType() == ASTNode.ARRAY_INITIALIZER) { - // ignore the other entries in the array initializer(?) - they may not be matching Annotations... - List<Expression> expressions = this.expressions((ArrayInitializer) value); - if (this.index >= expressions.size()) { - this.addInnerToExpressions(inner, expressions); - } else { - expressions.set(this.index, inner); - } - } else { - if (this.index == 0) { - // replace whatever was there before - expProvider.setExpression(node, inner); - } else { - // convert to an array - ArrayInitializer ai = inner.getAST().newArrayInitializer(); - List<Expression> expressions = this.expressions(ai); - expressions.add((Expression) ASTNode.copySubtree(value.getAST(), value)); - this.addInnerToExpressions(inner, expressions); - expProvider.setExpression(node, ai); - } - } - } - - @SuppressWarnings("unchecked") - protected List<Expression> expressions(ArrayInitializer ai) { - return ai.expressions(); - } - - - // ********** expression providers ********** - - /** - * define interface that allows us to "re-use" the code in - * #modifyExpression(ASTNode, ExpressionProvider, Annotation) - */ - private interface ExpressionProvider { - Expression getExpression(ASTNode node); - void setExpression(ASTNode node, Expression expression); - } - - private static final ExpressionProvider MEMBER_VALUE_PAIR_EXPRESSION_PROVIDER = new ExpressionProvider() { - public Expression getExpression(ASTNode node) { - return ((MemberValuePair) node).getValue(); - } - public void setExpression(ASTNode node, Expression expression) { - ((MemberValuePair) node).setValue(expression); - } - @Override - public String toString() { - return "MemberValuePairExpressionProvider"; //$NON-NLS-1$ - } - }; - - private static final ExpressionProvider SINGLE_MEMBER_ANNOTATION_EXPRESSION_PROVIDER = new ExpressionProvider() { - public Expression getExpression(ASTNode node) { - return ((SingleMemberAnnotation) node).getValue(); - } - public void setExpression(ASTNode node, Expression expression) { - ((SingleMemberAnnotation) node).setValue(expression); - } - @Override - public String toString() { - return "SingleMemberAnnotationExpressionProvider"; //$NON-NLS-1$ - } - }; - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullAnnotationEditFormatter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullAnnotationEditFormatter.java deleted file mode 100644 index 3c632f36c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullAnnotationEditFormatter.java +++ /dev/null @@ -1,42 +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.utility.jdt; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.TextEdit; - -public final class NullAnnotationEditFormatter - implements AnnotationEditFormatter -{ - - private static final NullAnnotationEditFormatter INSTANCE = new NullAnnotationEditFormatter(); - - /** - * Return the singleton. - */ - public static AnnotationEditFormatter instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NullAnnotationEditFormatter() { - super(); - } - - public void format(IDocument doc, TextEdit editTree) throws MalformedTreeException, BadLocationException { - // no formatting - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullDeclarationAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullDeclarationAnnotationAdapter.java deleted file mode 100644 index d81448ce1b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,82 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Behaviorless implementation. - */ -public final class NullDeclarationAnnotationAdapter - implements IndexedDeclarationAnnotationAdapter -{ - - // singleton - private static final NullDeclarationAnnotationAdapter INSTANCE = new NullDeclarationAnnotationAdapter(); - - /** - * Return the singleton. - */ - public static IndexedDeclarationAnnotationAdapter instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NullDeclarationAnnotationAdapter() { - super(); - } - - - // ********** DeclarationAnnotationAdapter implementation ********** - - public Annotation getAnnotation(ModifiedDeclaration declaration) { - return null; - } - - public MarkerAnnotation newMarkerAnnotation(ModifiedDeclaration declaration) { - return null; - } - - public SingleMemberAnnotation newSingleMemberAnnotation(ModifiedDeclaration declaration) { - return null; - } - - public NormalAnnotation newNormalAnnotation(ModifiedDeclaration declaration) { - return null; - } - - public void removeAnnotation(ModifiedDeclaration declaration) { - // do nothing - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - return declaration.getDeclaration(); - } - - - // ********** IndexedDeclarationAnnotationAdapter implementation ********** - - public int getIndex() { - return -1; - } - - public void moveAnnotation(int newIndex, ModifiedDeclaration declaration) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullDeclarationAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullDeclarationAnnotationElementAdapter.java deleted file mode 100644 index c53a69546a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullDeclarationAnnotationElementAdapter.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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Behaviorless implementation. - */ -public class NullDeclarationAnnotationElementAdapter<T> - implements DeclarationAnnotationElementAdapter<T> -{ - - // singleton - @SuppressWarnings("unchecked") - private static final DeclarationAnnotationElementAdapter INSTANCE - = new NullDeclarationAnnotationElementAdapter(); - - /** - * Return the singleton. - */ - @SuppressWarnings("unchecked") - public static <S> DeclarationAnnotationElementAdapter<S> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NullDeclarationAnnotationElementAdapter() { - super(); - } - - public T getValue(ModifiedDeclaration declaration) { - return null; - } - - public void setValue(T value, ModifiedDeclaration declaration) { - // do nothing - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - return declaration.getDeclaration(); - } - - public Expression getExpression(ModifiedDeclaration declaration) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullExpressionConverter.java deleted file mode 100644 index 803b983910..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NullExpressionConverter.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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * No conversion. - */ -public final class NullExpressionConverter - implements ExpressionConverter<Expression> -{ - - // singleton - private static final ExpressionConverter<Expression> INSTANCE = new NullExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<Expression> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NullExpressionConverter() { - super(); - } - - public Expression convert(Expression expression, AST ast) { - return expression; - } - - public Expression convert(Expression expression) { - return expression; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NumberIntegerExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NumberIntegerExpressionConverter.java deleted file mode 100644 index 526e1fe4aa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/NumberIntegerExpressionConverter.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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.NumberLiteral; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a number literal to/from an Integer - * (e.g. 5). - */ -public final class NumberIntegerExpressionConverter - extends AbstractExpressionConverter<Integer> -{ - private static final ExpressionConverter<Integer> INSTANCE = new NumberIntegerExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<Integer> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private NumberIntegerExpressionConverter() { - super(); - } - - @Override - protected NumberLiteral convertObject(Integer integer, AST ast) { - return ast.newNumberLiteral(integer.toString()); - } - - @Override - protected Integer convertExpression(Expression expression) { - Object value = expression.resolveConstantExpressionValue(); - return (value instanceof Integer) ? ((Integer) value) : null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/PrimitiveTypeStringExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/PrimitiveTypeStringExpressionConverter.java deleted file mode 100644 index 3f9990680f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/PrimitiveTypeStringExpressionConverter.java +++ /dev/null @@ -1,61 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.PrimitiveType; -import org.eclipse.jdt.core.dom.TypeLiteral; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a type literal to/from a string representation of a primitive type - * (e.g. "int"). - */ -public final class PrimitiveTypeStringExpressionConverter - extends AbstractExpressionConverter<String> -{ - private static final ExpressionConverter<String> INSTANCE = new PrimitiveTypeStringExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<String> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private PrimitiveTypeStringExpressionConverter() { - super(); - } - - @Override - protected TypeLiteral convertObject(String string, AST ast) { - org.eclipse.jdt.core.dom.Type type = ast.newPrimitiveType(PrimitiveType.toCode(string)); - TypeLiteral typeLiteral = ast.newTypeLiteral(); - typeLiteral.setType(type); - return typeLiteral; - } - - @Override - protected String convertExpression(Expression expression) { - if (expression.getNodeType() == ASTNode.TYPE_LITERAL) { - org.eclipse.jdt.core.dom.Type type = ((TypeLiteral) expression).getType(); - if (type.getNodeType() == ASTNode.PRIMITIVE_TYPE) { - return ((PrimitiveType) type).getPrimitiveTypeCode().toString(); - } - } - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ShortCircuitAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ShortCircuitAnnotationElementAdapter.java deleted file mode 100644 index c0a1dca304..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ShortCircuitAnnotationElementAdapter.java +++ /dev/null @@ -1,104 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Wrap another annotation element adapter and short-circuit the - * #setValue method if the value has not changed. - */ -public class ShortCircuitAnnotationElementAdapter<T> - implements AnnotationElementAdapter<T> -{ - /** the wrapped adapter */ - private final AnnotationElementAdapter<T> adapter; - - - // ********** constructor ********** - - public ShortCircuitAnnotationElementAdapter(Member member, DeclarationAnnotationElementAdapter<T> daea) { - this(new MemberAnnotationElementAdapter<T>(member, daea)); - } - - public ShortCircuitAnnotationElementAdapter(AnnotationElementAdapter<T> adapter) { - super(); - this.adapter = adapter; - } - - - // ********** AnnotationElementAdapter implementation ********** - - public T getValue() { - return this.adapter.getValue(); - } - - public T getValue(CompilationUnit astRoot) { - return this.adapter.getValue(astRoot); - } - - public void setValue(T value) { - this.setValue(this.adapter.getValue(), value); - } - - public Expression getExpression(CompilationUnit astRoot) { - return this.adapter.getExpression(astRoot); - } - - public ASTNode getAstNode(CompilationUnit astRoot) { - return this.adapter.getAstNode(astRoot); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.adapter); - } - - - // ********** internal methods ********** - - /** - * set the adapter's value to the specified new value if it - * is different from the specified old value - */ - protected void setValue(T oldValue, T newValue) { - if (oldValue == null) { - if (newValue == null) { // null => null - // do nothing - } else { // null => object - this.adapter.setValue(newValue); - } - } else { - if (newValue == null) { // object => null - this.adapter.setValue(null); - } else { // object => object - if (this.valuesAreEqual(oldValue, newValue)) { - // do nothing - } else { - this.adapter.setValue(newValue); - } - } - } - } - - /** - * both values are non-null when this method is called - */ - protected boolean valuesAreEqual(T oldValue, T newValue) { - return newValue.equals(oldValue); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ShortCircuitArrayAnnotationElementAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ShortCircuitArrayAnnotationElementAdapter.java deleted file mode 100644 index 01952fe059..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ShortCircuitArrayAnnotationElementAdapter.java +++ /dev/null @@ -1,43 +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.utility.jdt; - -import java.util.Arrays; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -/** - * Wrap another annotation element adapter and short-circuit the - * #setValue method if the value has not changed. Overrides #valuesAreEqual() - * to check equality on arrays - */ -public class ShortCircuitArrayAnnotationElementAdapter<T> - extends ShortCircuitAnnotationElementAdapter<T[]> -{ - // ********** constructor ********** - - public ShortCircuitArrayAnnotationElementAdapter(Member member, DeclarationAnnotationElementAdapter<T[]> daea) { - super(member, daea); - } - - public ShortCircuitArrayAnnotationElementAdapter(AnnotationElementAdapter<T[]> adapter) { - super(adapter); - } - - - // ********** AnnotationElementAdapter implementation ********** - - @Override - protected boolean valuesAreEqual(T[] oldValue, T[] newValue) { - return Arrays.equals(newValue, oldValue); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/SimpleDeclarationAnnotationAdapter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/SimpleDeclarationAnnotationAdapter.java deleted file mode 100644 index 16a657437b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/SimpleDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,62 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -/** - * Manipulate an annotation with a specific name, e.g. - * <pre> - * @Foo - * private int id; - * </pre> - * - * NB: - * If the declaration contains more than one annotation with the same - * name, the adapter will correspond to the first annotation with the specified - * name. (Also note that the compiler will not allow a declaration to be - * modified by multiple annotations with the same name, i.e. of the same type; - * so if there *are* multiple annotations of the same type, there are bigger - * problems to worry about than which annotation the adapter manipulates.) - */ -public class SimpleDeclarationAnnotationAdapter extends AbstractDeclarationAnnotationAdapter { - - - // ********** constructors ********** - - public SimpleDeclarationAnnotationAdapter(String annotationName) { - super(annotationName); - } - - - // ********** DeclarationAnnotationAdapter implementation ********** - - public Annotation getAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(this.getAnnotationName()); - } - - public void removeAnnotation(ModifiedDeclaration declaration) { - declaration.removeAnnotationNamed(this.getAnnotationName()); - } - - @Override - protected void addAnnotation(ModifiedDeclaration declaration, Annotation annotation) { - declaration.replaceAnnotationNamed(this.getAnnotationName(), annotation); - } - - public ASTNode getAstNode(ModifiedDeclaration declaration) { - // if the annotation is missing, return the declaration - Annotation annotation = this.getAnnotation(declaration); - return (annotation != null) ? annotation : declaration.getDeclaration(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/SimpleTypeStringExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/SimpleTypeStringExpressionConverter.java deleted file mode 100644 index f622562554..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/SimpleTypeStringExpressionConverter.java +++ /dev/null @@ -1,63 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.Name; -import org.eclipse.jdt.core.dom.SimpleType; -import org.eclipse.jdt.core.dom.TypeLiteral; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a type literal to/from a string representation of a simple type - * (e.g. "java.lang.Object"). - */ -public final class SimpleTypeStringExpressionConverter - extends AbstractExpressionConverter<String> -{ - private static final ExpressionConverter<String> INSTANCE = new SimpleTypeStringExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<String> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private SimpleTypeStringExpressionConverter() { - super(); - } - - @Override - protected TypeLiteral convertObject(String string, AST ast) { - Name name = ast.newName(string); - org.eclipse.jdt.core.dom.Type type = ast.newSimpleType(name); - TypeLiteral typeLiteral = ast.newTypeLiteral(); - typeLiteral.setType(type); - return typeLiteral; - } - - @Override - protected String convertExpression(Expression expression) { - if (expression.getNodeType() == ASTNode.TYPE_LITERAL) { - org.eclipse.jdt.core.dom.Type type = ((TypeLiteral) expression).getType(); - if (type.getNodeType() == ASTNode.SIMPLE_TYPE) { - return ((SimpleType) type).getName().getFullyQualifiedName(); - } - } - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/StringArrayExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/StringArrayExpressionConverter.java deleted file mode 100644 index 35751f6e52..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/StringArrayExpressionConverter.java +++ /dev/null @@ -1,111 +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.utility.jdt; - -import java.util.List; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ArrayInitializer; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert an array initializer to/from an array of strings (e.g. {"text0", "text1"}). - * - * Do NOT use this class for converting array initializers in annotation elements. - * Java5 has a bit of syntactic sugar that allows a single-element array - * initializer to not have curly braces. This converter will return null if it encounters - * anything other than an array initializer. - * - * Invalid entries in the array initializer will result in null elements in the - * resulting string array. This allows clients to manipulate elements at - * the appropriate index. - */ -public class StringArrayExpressionConverter - extends AbstractExpressionConverter<String[]> -{ - private final ExpressionConverter<String> elementConverter; - private final boolean removeArrayInitializerWhenEmpty; - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - - /** - * The default behavior is to remove the array initializer if it is empty. - */ - public StringArrayExpressionConverter(ExpressionConverter<String> elementConverter) { - this(elementConverter, true); - } - - public StringArrayExpressionConverter(ExpressionConverter<String> elementConverter, boolean removeArrayInitializerWhenEmpty) { - super(); - this.elementConverter = elementConverter; - this.removeArrayInitializerWhenEmpty = removeArrayInitializerWhenEmpty; - } - - @Override - /* - * this method is 'public' so it can be called by - * AnnotationStringArrayExpressionConverter - */ - public ArrayInitializer convertObject(String[] strings, AST ast) { - if ((strings.length == 0) && this.removeArrayInitializerWhenEmpty) { - return null; - } - ArrayInitializer arrayInitializer = ast.newArrayInitializer(); - List<Expression> expressions = this.expressions(arrayInitializer); - for (String string : strings) { - expressions.add(this.elementConverter.convert(string, ast)); - } - return arrayInitializer; - } - - @SuppressWarnings("unchecked") - private List<Expression> expressions(ArrayInitializer arrayInitializer) { - return arrayInitializer.expressions(); - } - - /* - * this method is 'public' so it can be called by - * AnnotationStringArrayExpressionConverter - */ - @Override - public String[] convertNull() { - return EMPTY_STRING_ARRAY; - } - - @Override - protected String[] convertExpression(Expression expression) { - return (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) ? - this.convertArrayInitializer((ArrayInitializer) expression) - : - EMPTY_STRING_ARRAY; - } - - /* - * this method is 'public' so it can be called by - * AnnotationStringArrayExpressionConverter - */ - public String[] convertArrayInitializer(ArrayInitializer arrayInitializer) { - List<Expression> expressions = this.downcastExpressions(arrayInitializer); - int len = expressions.size(); - String[] strings = new String[len]; - for (int i = len; i-- > 0; ) { - strings[i] = this.elementConverter.convert(expressions.get(i)); - } - return strings; - } - - @SuppressWarnings("unchecked") - private List<Expression> downcastExpressions(ArrayInitializer arrayInitializer) { - return arrayInitializer.expressions(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/StringExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/StringExpressionConverter.java deleted file mode 100644 index b5fee1e52d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/StringExpressionConverter.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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.StringLiteral; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a string literal to/from a string (e.g. "text"). - */ -public final class StringExpressionConverter - extends AbstractExpressionConverter<String> -{ - private static final ExpressionConverter<String> INSTANCE = new StringExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<String> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private StringExpressionConverter() { - super(); - } - - @Override - protected StringLiteral convertObject(String string, AST ast) { - StringLiteral stringLiteral = ast.newStringLiteral(); - stringLiteral.setLiteralValue(string); - return stringLiteral; - } - - @Override - protected String convertExpression(Expression expression) { - Object value = expression.resolveConstantExpressionValue(); - return (value instanceof String) ? (String) value : null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/TypeStringExpressionConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/TypeStringExpressionConverter.java deleted file mode 100644 index 4ca6248449..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/TypeStringExpressionConverter.java +++ /dev/null @@ -1,55 +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.utility.jdt; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.PrimitiveType; -import org.eclipse.jdt.core.dom.TypeLiteral; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -/** - * Convert a type literal to/from a string representation of a - * simple type (e.g. "java.lang.Object") or primitive type (e.g. "int"). - */ -public final class TypeStringExpressionConverter - extends AbstractExpressionConverter<String> -{ - private static final ExpressionConverter<String> INSTANCE = new TypeStringExpressionConverter(); - - /** - * Return the singleton. - */ - public static ExpressionConverter<String> instance() { - return INSTANCE; - } - - /** - * Ensure single instance. - */ - private TypeStringExpressionConverter() { - super(); - } - - @Override - protected TypeLiteral convertObject(String string, AST ast) { - if (PrimitiveType.toCode(string) != null) { - return (TypeLiteral) PrimitiveTypeStringExpressionConverter.instance().convert(string, ast); - } - return (TypeLiteral) SimpleTypeStringExpressionConverter.instance().convert(string, ast); - } - - @Override - protected String convertExpression(Expression expression) { - String name = SimpleTypeStringExpressionConverter.instance().convert(expression); - return name != null ? name : PrimitiveTypeStringExpressionConverter.instance().convert(expression); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java deleted file mode 100644 index ae30b69460..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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.validation; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.core.Message; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class DefaultJpaValidationMessages { - - private static String[] DEFAULT_PARMS = new String[0]; - private static TextRange DEFAULT_TEXT_RANGE = TextRange.Empty.instance(); - - public static IMessage buildMessage( - int severity, String messageId, Object targetObject) { - return buildMessage(severity, messageId, DEFAULT_PARMS, targetObject); - } - - public static IMessage buildMessage( - int severity, String messageId, String[] parms, Object targetObject) { - return buildMessage(severity, messageId, parms, targetObject, DEFAULT_TEXT_RANGE); - } - - public static IMessage buildMessage( - int severity, String messageId, Object targetObject, TextRange textRange) { - return buildMessage(severity, messageId, DEFAULT_PARMS, targetObject, textRange); - } - - public static IMessage buildMessage( - int severity, String messageId, String[] parms, Object targetObject, TextRange textRange) { - IMessage message = new Message(JpaValidationMessages.BUNDLE_NAME, severity, messageId, parms, targetObject); - if (textRange == null) { - //log an exception and then continue without setting location information - //At least the user will still get the validation message and will - //be able to see other validation messages with valid textRanges - JptCorePlugin.log(new IllegalArgumentException("Null text range for message ID: " + messageId)); //$NON-NLS-1$ - } - else { - message.setLineNo(textRange.getLineNumber()); - message.setOffset(textRange.getOffset()); - message.setLength(textRange.getLength()); - } - return message; - } - - - private DefaultJpaValidationMessages() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java deleted file mode 100644 index 7789238c30..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaHelper.java +++ /dev/null @@ -1,32 +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.validation; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jpt.core.JpaNode; - -public class JpaHelper extends org.eclipse.wst.validation.internal.operations.WorkbenchContext { - - @Override - public IResource getResource(Object obj) { - return ((JpaNode) obj).getResource(); - } - - /* - * This is used when no line number is set. We generally use line numbers. - * Therefore, when this is called, we will use the default location, i.e. - * null. - */ - @Override - public String getLocation(Object object) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java deleted file mode 100644 index 704a1d60ff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.validation; - -@SuppressWarnings("nls") -public interface JpaValidationMessages { - - public static final String BUNDLE_NAME = "jpa_validation"; - - public static final String PROJECT_NO_CONNECTION = "PROJECT_NO_CONNECTION"; - public static final String PROJECT_INVALID_CONNECTION = "PROJECT_INVALID_CONNECTION"; - public static final String PROJECT_INACTIVE_CONNECTION = "PROJECT_INACTIVE_CONNECTION"; - public static final String PROJECT_NO_PERSISTENCE_XML = "PROJECT_NO_PERSISTENCE_XML"; - public static final String PROJECT_MULTIPLE_PERSISTENCE_XML = "PROJECT_MULTIPLE_PERSISTENCE_XML"; - public static final String PERSISTENCE_XML_INVALID_CONTENT = "PERSISTENCE_XML_INVALID_CONTENT"; - public static final String PERSISTENCE_NO_PERSISTENCE_UNIT = "PERSISTENCE_NO_PERSISTENCE_UNIT"; - public static final String PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS = "PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS"; - public static final String PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE = "PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE"; - public static final String PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT = "PERSISTENCE_UNIT_UNSUPPORTED_MAPPING_FILE_CONTENT"; - public static final String PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE = "PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE"; - public static final String PERSISTENCE_UNIT_INVALID_MAPPING_FILE = "PERSISTENCE_UNIT_INVALID_MAPPING_FILE"; - public static final String PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE = "PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE"; - public static final String PERSISTENCE_UNIT_UNSPECIFIED_CLASS = "PERSISTENCE_UNIT_UNSPECIFIED_CLASS"; - public static final String PERSISTENCE_UNIT_NONEXISTENT_CLASS = "PERSISTENCE_UNIT_NONEXISTENT_CLASS"; - public static final String PERSISTENCE_UNIT_INVALID_CLASS = "PERSISTENCE_UNIT_INVALID_CLASS"; - public static final String PERSISTENCE_UNIT_DUPLICATE_CLASS = "PERSISTENCE_UNIT_DUPLICATE_CLASS"; - public static final String PERSISTENCE_UNIT_REDUNDANT_CLASS = "PERSISTENCE_UNIT_REDUNDANT_CLASS"; - public static final String PERSISTENCE_UNIT_DUPLICATE_JAR_FILE = "PERSISTENCE_UNIT_DUPLICATE_JAR_FILE"; - public static final String PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE = "PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE"; - public static final String PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING = "PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING"; - public static final String PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE = "PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE"; - public static final String GENERATOR_DUPLICATE_NAME = "GENERATOR_DUPLICATE_NAME"; - public static final String QUERY_DUPLICATE_NAME = "QUERY_DUPLICATE_NAME"; - public static final String MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_DEFAULTS = "MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_DEFAULTS"; - public static final String PERSISTENT_TYPE_MAPPED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT = "PERSISTENT_TYPE_MAPPED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT"; - public static final String PERSISTENT_TYPE_ANNOTATED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT = "PERSISTENT_TYPE_ANNOTATED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT"; - public static final String PERSISTENT_TYPE_UNSPECIFIED_CLASS = "PERSISTENT_TYPE_UNSPECIFIED_CLASS"; - public static final String PERSISTENT_TYPE_UNRESOLVED_CLASS = "PERSISTENT_TYPE_UNRESOLVED_CLASS"; - public static final String ENTITY_NO_ID = "ENTITY_NO_ID"; - public static final String ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE = "ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE"; - public static final String ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE = "ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE"; - public static final String ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED = "ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED"; - public static final String ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED = "ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED"; - public static final String ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED = "ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED"; - public static final String ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED = "ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED"; - public static final String PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME = "PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME"; - public static final String PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME = "PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME"; - public static final String PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED = "PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED"; - public static final String PERSISTENT_ATTRIBUTE_FINAL_FIELD = "PERSISTENT_ATTRIBUTE_FINAL_FIELD"; - public static final String PERSISTENT_ATTRIBUTE_PUBLIC_FIELD = "PERSISTENT_ATTRIBUTE_PUBLIC_FIELD"; - public static final String PERSISTENT_ATTRIBUTE_INVALID_MAPPING = "PERSISTENT_ATTRIBUTE_INVALID_MAPPING"; - public static final String MAPPING_UNRESOLVED_MAPPED_BY = "MAPPING_UNRESOLVED_MAPPED_BY"; - public static final String MAPPING_INVALID_MAPPED_BY = "MAPPING_INVALID_MAPPED_BY"; - public static final String MAPPING_MAPPED_BY_WITH_JOIN_TABLE = "MAPPING_MAPPED_BY_WITH_JOIN_TABLE"; - public static final String MAPPING_MAPPED_BY_ON_BOTH_SIDES = "MAPPING_MAPPED_BY_ON_BOTH_SIDES"; - public static final String ID_MAPPING_UNRESOLVED_GENERATOR_NAME = "ID_MAPPING_UNRESOLVED_GENERATOR_NAME"; - public static final String TABLE_UNRESOLVED_CATALOG = "TABLE_UNRESOLVED_CATALOG"; - public static final String TABLE_UNRESOLVED_SCHEMA = "TABLE_UNRESOLVED_SCHEMA"; - public static final String TABLE_UNRESOLVED_NAME = "TABLE_UNRESOLVED_NAME"; - public static final String SECONDARY_TABLE_UNRESOLVED_CATALOG = "SECONDARY_TABLE_UNRESOLVED_CATALOG"; - public static final String SECONDARY_TABLE_UNRESOLVED_SCHEMA = "SECONDARY_TABLE_UNRESOLVED_SCHEMA"; - public static final String SECONDARY_TABLE_UNRESOLVED_NAME = "SECONDARY_TABLE_UNRESOLVED_NAME"; - public static final String JOIN_TABLE_UNRESOLVED_CATALOG = "JOIN_TABLE_UNRESOLVED_CATALOG"; - public static final String JOIN_TABLE_UNRESOLVED_SCHEMA = "JOIN_TABLE_UNRESOLVED_SCHEMA"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_CATALOG = "VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_CATALOG"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA = "VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA"; - public static final String JOIN_TABLE_UNRESOLVED_NAME = "JOIN_TABLE_UNRESOLVED_NAME"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_NAME = "VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_NAME"; - public static final String COLUMN_UNRESOLVED_TABLE = "COLUMN_UNRESOLVED_TABLE"; - public static final String VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE = "VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE"; - public static final String VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE = "VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE"; - public static final String COLUMN_UNRESOLVED_NAME = "COLUMN_UNRESOLVED_NAME"; - public static final String VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME"; - public static final String VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME"; - public static final String JOIN_COLUMN_UNRESOLVED_TABLE = "JOIN_COLUMN_UNRESOLVED_TABLE"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_TABLE = "VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_TABLE"; - public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_TABLE = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_TABLE"; - public static final String JOIN_COLUMN_UNRESOLVED_NAME = "JOIN_COLUMN_UNRESOLVED_NAME"; - public static final String JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS = "JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS = "VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS"; - public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_NAME"; - public static final String JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME = "JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME"; - public static final String JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS = "JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME"; - public static final String VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS = "VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME_MULTIPLE_JOIN_COLUMNS"; - public static final String VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME"; - public static final String GENERATED_VALUE_UNRESOLVED_GENERATOR = "GENERATED_VALUE_UNRESOLVED_GENERATOR"; - public static final String PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME = "PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_NAME"; - public static final String PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME = "PRIMARY_KEY_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME"; - public static final String NO_JPA_PROJECT = "NO_JPA_PROJECT"; - public static final String TARGET_ENTITY_NOT_DEFINED = "TARGET_ENTITY_NOT_DEFINED"; - public static final String VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED = "VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED"; - public static final String TARGET_ENTITY_IS_NOT_AN_ENTITY = "TARGET_ENTITY_IS_NOT_AN_ENTITY"; - public static final String VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY = "VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY"; - public static final String DISCRIMINATOR_COLUMN_UNRESOLVED_NAME = "DISCRIMINATOR_COLUMN_UNRESOLVED_NAME"; - public static final String ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM = "ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM"; - public static final String ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM = "ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM"; -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java deleted file mode 100644 index 68f3fac1c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.validation; - -import java.util.Iterator; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jpt.core.IResourcePart; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.wst.validation.AbstractValidator; -import org.eclipse.wst.validation.ValidationResult; -import org.eclipse.wst.validation.ValidationState; -import org.eclipse.wst.validation.ValidatorMessage; -import org.eclipse.wst.validation.internal.ValConstants; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IProjectValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; -import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IValidator; - -/** - * This class is referenced in the JPA extension for the - * WTP validator extension point. - */ -public class JpaValidator extends AbstractValidator implements IValidator { - - - // ********** IValidator implementation ********** - - public void validate(IValidationContext context, IReporter reporter) { - validate(reporter, project(context)); - } - - public void cleanup(IReporter reporter) { - // nothing to do - } - - - // **************** AbstractValidator impl ********************************* - - @Override - public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { - if (resource.getType() != IResource.FILE) - return null; - ValidationResult result = new ValidationResult(); - IReporter reporter = result.getReporter(monitor); - IProject project = resource.getProject(); - try { - clearMarkers(project); - } - catch (CoreException ce) { - JptCorePlugin.log(ce); - } - result.setSuspendValidation(project); - validate(reporter, project); - return result; - } - - - // **************** internal conv. ***************************************** - - private void clearMarkers(IProject project) throws CoreException { - IMarker[] markers = project.findMarkers(ValConstants.ProblemMarker, true, IResource.DEPTH_INFINITE); - String valId = JptCorePlugin.VALIDATOR_ID; - for (IMarker marker : markers) { - String id = marker.getAttribute(ValidatorMessage.ValidationId, null); - if (valId.equals(id)) marker.delete(); - } - } - - private void validate(IReporter reporter, IProject project) { - reporter.removeAllMessages(this); - - for (Iterator<IMessage> stream = this.validationMessages(reporter, project); stream.hasNext(); ) { - reporter.addMessage(this, adjustMessage(stream.next())); - } - } - - private IProject project(IValidationContext context) { - return ((IProjectValidationContext) context).getProject(); - } - - private Iterator<IMessage> validationMessages(IReporter reporter, IProject project) { - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - if (jpaProject != null) { - return jpaProject.validationMessages(reporter); - } - return new SingleElementIterator<IMessage>( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.NO_JPA_PROJECT, - project - )); - } - - private IMessage adjustMessage(IMessage message) { - IAdaptable targetObject = (IAdaptable) message.getTargetObject(); - IResource targetResource = ((IResourcePart) targetObject.getAdapter(IResourcePart.class)).getResource(); - message.setTargetObject(targetResource); - if (message.getLineNumber() == IMessage.LINENO_UNSET) { - message.setAttribute(IMarker.LOCATION, " "); - } - return message; - } -} |