diff options
author | nhauge | 2008-08-18 15:46:07 +0000 |
---|---|---|
committer | nhauge | 2008-08-18 15:46:07 +0000 |
commit | 0fc02d4b54e725f832b00bef0b47e3d905e9ae13 (patch) | |
tree | 3fc92f27d04dc063e777a93422af4a24bb7aef36 /jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal | |
parent | 51f3e2bf3dfc6d4a7ffc01c0b2dd830a4fedb964 (diff) | |
parent | 6a7ab73ae0d63dfafc02bb15f5d115a8d6f75e86 (diff) | |
download | webtools.dali-200808170000.tar.gz webtools.dali-200808170000.tar.xz webtools.dali-200808170000.zip |
This commit was manufactured by cvs2svn to create tag 'v200808170000'.v200808170000
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal')
368 files changed, 0 insertions, 60903 deletions
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 31aede7d77..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaNode.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; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -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.ResourceModel; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.CallbackChangeSupport; -import org.eclipse.jpt.utility.internal.model.ChangeSupport; - -/** - * - */ -public abstract class AbstractJpaNode - extends AbstractModel - implements JpaNode, CallbackChangeSupport.Source -{ - private final JpaNode parent; - - - // ********** constructor ********** - - 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); - } - - - // ********** IAdaptable implementation ********** - - @SuppressWarnings("unchecked") - public Object getAdapter(Class adapter) { - return Platform.getAdapterManager().getAdapter(this, adapter); - } - - - // ********** IJpaNode implementation ********** - - public JpaNode getParent() { - return this.parent; - } - - public IResource getResource() { - return this.parent.getResource(); - } - - public JpaProject getJpaProject() { - return this.parent.getJpaProject(); - } - - public String displayString() { - return this.toString(); - } - - - // ********** convenience methods ********** - - protected JpaPlatform getJpaPlatform() { - return this.getJpaProject().getJpaPlatform(); - } - - protected JpaFactory getJpaFactory() { - return this.getJpaPlatform().getJpaFactory(); - } - - protected JpaFile getJpaFile(ResourceModel resourceModel) { - return this.getJpaProject().getJpaFile(resourceModel.getFile()); - } - - protected JpaDataSource getDataSource() { - return this.getJpaProject().getDataSource(); - } - - public boolean connectionProfileIsActive() { - return this.getDataSource().connectionProfileIsActive(); - } - - - // ********** update model ********** - - private static final HashMap<Class<? extends AbstractJpaNode>, HashSet<String>> nonUpdateAspectNameSets = new HashMap<Class<? extends AbstractJpaNode>, HashSet<String>>(); - - public 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; - } - } - - 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/AbstractResourceModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractResourceModel.java deleted file mode 100644 index 4b67456ff2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractResourceModel.java +++ /dev/null @@ -1,35 +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.resources.IFile; -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.utility.internal.model.AbstractModel; - -public abstract class AbstractResourceModel - extends AbstractModel - implements ResourceModel -{ - protected final IFile file; - - protected AbstractResourceModel(IFile file) { - super(); - this.file = file; - } - - public IFile getFile() { - return this.file; - } - - public void dispose() { - // do nothing by default - } - -} 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 aa1f5c8f73..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java +++ /dev/null @@ -1,116 +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.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * This updater will "update" the project in a job that executes in a separate - * thread and allows calls to #update() to return immediately. - */ -public class AsynchronousJpaProjectUpdater implements JpaProject.Updater { - protected final JpaProject jpaProject; - protected final UpdateJob job; - - public AsynchronousJpaProjectUpdater(JpaProject jpaProject) { - super(); - this.jpaProject = jpaProject; - this.job = this.buildJob(); - } - - protected UpdateJob buildJob() { - return new UpdateJob(); - } - - /** - * Allow the job to be scheduled and execute an "update". - */ - public void start() { - this.job.start(); - this.update(); - } - - /** - * Let the job run to completion (i.e. do not cancel it). - * This should reduce the number of times the job is re-scheduled. - */ - public void update() { - this.job.schedule(); - } - - public void dispose() { - this.job.dispose(); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.jpaProject); - } - - - /** - * This is the job that gets scheduled by the asynchronous updater. - * When the job is run it tells the JPA project to "update". - * Only a single instance of this job per project can run at a time. - */ - protected class UpdateJob extends Job { - /** - * When this flag is set to false, the job does not stop immediately; - * but it cannot be scheduled to run again. - */ - protected boolean shouldSchedule; - - protected UpdateJob() { - super("Update JPA project: " + AsynchronousJpaProjectUpdater.this.jpaProject.getName()); // TODO i18n - this.shouldSchedule = false; - this.setRule(AsynchronousJpaProjectUpdater.this.jpaProject.getProject()); - } - - @Override - protected IStatus run(IProgressMonitor monitor) { - return AsynchronousJpaProjectUpdater.this.jpaProject.update(monitor); - } - - @Override - public boolean shouldSchedule() { - return this.shouldSchedule; - } - - protected void start() { - if (this.shouldSchedule) { - throw new IllegalStateException("The Updater was not stopped."); - } - this.shouldSchedule = true; - } - - /** - * Prevent the job from running again and wait for the current - * execution, if there is any, to end before returning. - */ - protected void dispose() { - // 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 job thread was interrupted while waiting - ignore - } - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaDataSource.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaDataSource.java deleted file mode 100644 index 9b2d896545..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaDataSource.java +++ /dev/null @@ -1,243 +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; - -import java.util.Iterator; - -import org.eclipse.jpt.core.JpaDataSource; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.db.Catalog; -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; -import org.eclipse.jpt.db.Schema; - -/** - * 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); - - this.connectionProfileListener = this.buildConnectionProfileListener(); - this.getConnectionProfileFactory().addConnectionProfileListener(this.connectionProfileListener); - - this.connectionListener = this.buildConnectionListener(); - this.connectionProfileName = connectionProfileName; - this.connectionProfile = this.buildConnectionProfile(connectionProfileName); - 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; - this.firePropertyChanged(CONNECTION_PROFILE_NAME_PROPERTY, old, connectionProfileName); - // synch the connection profile when the name changes - this.setConnectionProfile(this.buildConnectionProfile(connectionProfileName)); - } - - public ConnectionProfile getConnectionProfile() { - return this.connectionProfile; - } - - @Override - public boolean connectionProfileIsActive() { - ConnectionProfile cp = this.connectionProfile; - return (cp != null) && cp.isActive(); - } - - public Database getDatabase() { - ConnectionProfile cp = this.connectionProfile; - return (cp == null) ? null : cp.getDatabase(); - } - - public Iterator<String> catalogNames() { - Database db = this.getDatabase(); - return (db == null) ? null : db.catalogNames(); - } - - public Catalog getCatalogNamed(String name) { - Database db = this.getDatabase(); - return (db == null) ? null : db.getCatalogNamed(name); - } - - public Catalog getDefaultCatalog() { - Database db = this.getDatabase(); - return (db == null) ? null : db.getDefaultCatalog(); - } - - public Iterator<String> schemaNames() { - Database db = this.getDatabase(); - return (db == null) ? null : db.schemaNames(); - } - - public Schema getSchemaNamed(String name) { - Database db = this.getDatabase(); - return (db == null) ? null : db.getSchemaNamed(name); - } - - public Schema getDefaultSchema() { - Database db = this.getDatabase(); - return (db == null) ? null : db.getDefaultSchema(); - } - - public <T extends DatabaseObject> T getDatabaseObjectNamed(T[] databaseObjects, String name) { - Database db = this.getDatabase(); - return (db == null) ? null : db.getDatabaseObjectNamed(databaseObjects, name); - } - - 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) { - 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); - } - } - - } - - - /** - * 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/GenericJpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaFile.java deleted file mode 100644 index 80ae72945f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaFile.java +++ /dev/null @@ -1,139 +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 java.util.Hashtable; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; - -public class GenericJpaFile extends AbstractJpaNode implements JpaFile -{ - /** - * The IFile associated with this JPA file - */ - protected final IFile file; - - /** - * The resource model represented by this JPA file - */ - protected final ResourceModel resourceModel; - - /** - * The context model root nodes represented by this JPA file - */ - protected final Hashtable<Object, JpaStructureNode> rootStructureNodes; - - public GenericJpaFile(JpaProject jpaProject, IFile file, ResourceModel resourceModel) { - super(jpaProject); - this.file = file; - this.resourceModel = resourceModel; - this.rootStructureNodes = new Hashtable<Object, JpaStructureNode>(); - } - - @Override - protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) { - super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - //JpaFile.ROOT_STRUCTURE_NODES_COLLECTION does not need to trigger a project update, - //only the UI cares about the rootStructureNode. - //If you do a project update on this you get in an infinite loop if you - //specify a java class in more than one location in your persistence unit. - nonUpdateAspectNames.add(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION); - } - - public IFile getFile() { - return this.file; - } - - public ResourceModel getResourceModel() { - return this.resourceModel; - } - - public Iterator<JpaStructureNode> rootStructureNodes() { - return new CloneIterator<JpaStructureNode>(this.rootStructureNodes.values()); - } - - public int rootStructureNodesSize() { - return this.rootStructureNodes.size(); - } - - // TODO move events outside of 'synchronized' block? - // need fireItemReplaced(String, Object, Object) for Collection? - public void addRootStructureNode(Object key, JpaStructureNode rootStructureNode) { - synchronized (this.rootStructureNodes) { - JpaStructureNode node = this.rootStructureNodes.get(key); - if (node == rootStructureNode) { - return; // no duplicates - } - if (node != null) { - this.rootStructureNodes.remove(key); - this.fireItemRemoved(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, node); - } - this.rootStructureNodes.put(key, rootStructureNode); - this.fireItemAdded(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, rootStructureNode); - } - } - - public void removeRootStructureNode(Object key) { - JpaStructureNode removedStructureNode = this.rootStructureNodes.remove(key); - fireItemRemoved(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, removedStructureNode); - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (JpaStructureNode rootNode : CollectionTools.iterable(rootStructureNodes())) { - JpaStructureNode node = rootNode.getStructureNode(textOffset); - if (node != null) { - return node; - } - } - return null; - } - - protected Iterator<Object> rootStructureNodeKeys() { - return new CloneIterator<Object>(this.rootStructureNodes.keySet()); - } - - public String getResourceType() { - return getResourceModel().getResourceType(); - } - - public void dispose() { - getResourceModel().dispose(); - - for (Iterator<Object> stream = this.rootStructureNodeKeys(); stream.hasNext(); ) { - this.removeRootStructureNode(stream.next()); - } - } - - public void javaElementChanged(ElementChangedEvent event) { - getResourceModel().javaElementChanged(event); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(getFile().toString()); - sb.append(" (resourceType: "); - sb.append(getResourceType()); - sb.append(")"); - } - - public void updateFromResource() { - this.resourceModel.updateFromResource(); - } - -} 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 90316ea2ce..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java +++ /dev/null @@ -1,553 +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 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.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jdt.core.ElementChangedEvent; -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.core.JpaProject.Config; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.persistence.PersistenceArtifactEdit; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -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.setUserOverrideDefaultSchemaName(JptCorePlugin.getUserOverrideDefaultSchemaName(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 the JPA project corresponding - * to the specified Eclipse project. - */ - synchronized void synchronizeFiles(IProject project, IResourceDelta delta) throws CoreException { - this.getJpaProjectHolder(project).synchronizeJpaFiles(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 ********** - - // create persistence.xml and orm.xml in jobs so we don't deadlock - // with the Resource Change Event that comes in from another - // thread after the Eclipse project is created by the project facet - // wizard (which happens before the wizard notifies us); the Artifact - // Edits will hang during #save(), waiting for the workspace lock held - // by the Resource Change Notification loop - synchronized void jpaFacetedProjectPostInstall(IProjectFacetActionEvent event) { - IProject project = event.getProject().getProject(); - IDataModel dataModel = (IDataModel) event.getActionConfig(); - - boolean buildOrmXml = dataModel.getBooleanProperty(JpaFacetDataModelProperties.CREATE_ORM_XML); - this.buildProjectXmlJob(project, buildOrmXml).schedule(); - - // assume(?) this is the first event to indicate we need to add the JPA project to the JPA model - this.addJpaProject(project); - } - - private Job buildProjectXmlJob(final IProject project, final boolean buildOrmXml) { - Job job = new Job("Create Project XML files") { - @Override - protected IStatus run(IProgressMonitor monitor) { - GenericJpaModel.this.createProjectXml(project, buildOrmXml); - return Status.OK_STATUS; - } - }; - job.setRule(ResourcesPlugin.getWorkspace().getRoot()); - return job; - } - - /* private */ void createProjectXml(IProject project, boolean buildOrmXml) { - this.createPersistenceXml(project); - - if (buildOrmXml) { - this.createOrmXml(project); - } - - } - - private void createPersistenceXml(IProject project) { - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(project); - - // 202811 - do not add content if it is already present - PersistenceResource resource = pae.getResource(); - if (! resource.getFile().exists()) { - pae.createDefaultResource(); - } - - pae.dispose(); - } - - private void createOrmXml(IProject project) { - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForWrite(project); - OrmResource resource = oae.getResource(JptCorePlugin.getDefaultOrmXmlDeploymentURI(project)); - - // 202811 - do not add content if it is already present - if (resource.getEntityMappings() == null) { - XmlEntityMappings entityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - entityMappings.setVersion("1.0"); - this.getResourceContents(resource).add(entityMappings); - oae.save(null); - } - - oae.dispose(); - } - - /** - * minimize the scope of the suppressed warnings - */ - @SuppressWarnings("unchecked") - private EList<EObject> getResourceContents(OrmResource resource) { - return resource.getContents(); - } - - // 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()); - } - - - // ********** 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 synchronizeJpaFiles(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 synchronizeJpaFiles(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 { - JpaProject jpaProject = this.config.getJpaPlatform().getJpaFactory().buildJpaProject(this.config); - jpaProject.setUpdater(new AsynchronousJpaProjectUpdater(jpaProject)); - return jpaProject; - } - - public void synchronizeJpaFiles(IResourceDelta delta) throws CoreException { - if (this.jpaProject != null) { - this.jpaProject.synchronizeJpaFiles(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")) { - break; // skip all elements outside of the JUnit test - } - System.out.println("\t" + element); - } - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaProject.java deleted file mode 100644 index 6f6727de0a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaProject.java +++ /dev/null @@ -1,710 +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 java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -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.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -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.JptCorePlugin; -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.core.ResourceModelListener; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.jpt.utility.CommandExecutorProvider; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -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.J2EEConstants; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -/** - * - */ -public class GenericJpaProject extends AbstractJpaNode implements JpaProject { - - /** - * 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 data source that wraps the DTP model. - */ - protected final JpaDataSource dataSource; - - /** - * A schema name used to override the connection's default schema - */ - protected String userOverrideDefaultSchemaName; - - /** - * 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; - - /** - * The JPA files associated with the JPA project. - */ - protected final Vector<JpaFile> jpaFiles; - - /** - * The root of the model representing the collated resources associated with - * the JPA project. - */ - protected JpaRootContextNode rootContextNode; - - /** - * Support for modifying documents shared with the UI. - */ - protected final ThreadLocal<CommandExecutor> threadLocalModifySharedDocumentCommandExecutor; - protected final CommandExecutorProvider modifySharedDocumentCommandExecutorProvider; - - /** - * A pluggable updater that can be used to "update" the project either - * synchronously or asynchronously (or not at all). An asynchronous - * updater is the default and is used when the project is being manipulated - * by the UI. A synchronous updater is used when the project is being - * manipulated by a "batch" (or non-UI) client (e.g. when testing the - * "update" behavior). A null updater is used during tests that - * do not care whether "updates" occur. Clients will need to explicitly - * configure the updater if they require something other than an - * asynchronous updater. - */ - protected Updater updater; - - /** - * Resource models notify this listener when they change. A project update - * should occur any time a resource model changes. - */ - protected ResourceModelListener resourceModelListener; - - - // ********** constructor/initialization ********** - - /** - * The project and JPA platform are required. - */ - public GenericJpaProject(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.userOverrideDefaultSchemaName = config.getUserOverrideDefaultSchemaName(); - this.discoversAnnotatedClasses = config.discoverAnnotatedClasses(); - this.jpaFiles = this.buildEmptyJpaFiles(); - - this.threadLocalModifySharedDocumentCommandExecutor = this.buildThreadLocalModifySharedDocumentCommandExecutor(); - this.modifySharedDocumentCommandExecutorProvider = this.buildModifySharedDocumentCommandExecutorProvider(); - - this.resourceModelListener = this.buildResourceModelListener(); - // build the JPA files corresponding to the Eclipse project's files - this.project.accept(this.buildInitialResourceProxyVisitor(), IResource.NONE); - - this.rootContextNode = this.buildRootContextNode(); - } - - @Override - protected boolean requiresParent() { - return false; - } - - @Override - public IResource getResource() { - return getProject(); - } - - protected Vector<JpaFile> buildEmptyJpaFiles() { - return new Vector<JpaFile>(); - } - - protected ResourceDeltaVisitor buildResourceDeltaVisitor() { - return new ResourceDeltaVisitor(); - } - - protected ThreadLocal<CommandExecutor> buildThreadLocalModifySharedDocumentCommandExecutor() { - return new ThreadLocal<CommandExecutor>(); - } - - protected CommandExecutorProvider buildModifySharedDocumentCommandExecutorProvider() { - return new ModifySharedDocumentCommandExecutorProvider(); - } - - protected ResourceModelListener buildResourceModelListener() { - return new DefaultResourceModelListener(); - } - - protected IResourceProxyVisitor buildInitialResourceProxyVisitor() { - return new InitialResourceProxyVisitor(); - } - - protected JpaRootContextNode buildRootContextNode() { - return this.getJpaFactory().buildRootContext(this); - } - - // ***** 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 - case IResource.PROJECT : - case IResource.FOLDER : - return true; // visit children - case IResource.FILE : - GenericJpaProject.this.addJpaFileInternal((IFile) resource.requestResource()); - return false; // no children - default : - return false; // no children - } - } - } - - - // ********** 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; - } - - @Override - public JpaDataSource getDataSource() { - return this.dataSource; - } - - public ConnectionProfile getConnectionProfile() { - return this.dataSource.getConnectionProfile(); - } - - public Schema getDefaultSchema() { - Schema schema = this.getUserOverrideDefaultSchema(); - return (schema != null) ? schema : this.getDataSource().getDefaultSchema(); - } - - public Schema getUserOverrideDefaultSchema() { - return (this.userOverrideDefaultSchemaName == null) ? null : this.getDataSource().getSchemaNamed(this.userOverrideDefaultSchemaName); - } - - - // **************** user override default schema name ********************** - - public String getUserOverrideDefaultSchemaName() { - return this.userOverrideDefaultSchemaName; - } - - public void setUserOverrideDefaultSchemaName(String newDefaultSchemaName) { - String oldDefaultSchemaName = this.userOverrideDefaultSchemaName; - this.userOverrideDefaultSchemaName = newDefaultSchemaName; - this.firePropertyChanged(USER_OVERRIDE_DEFAULT_SCHEMA_NAME_PROPERTY, - oldDefaultSchemaName, newDefaultSchemaName); - } - - - // **************** discover annotated classes ***************************** - - public boolean discoversAnnotatedClasses() { - return this.discoversAnnotatedClasses; - } - - public void setDiscoversAnnotatedClasses(boolean discoversAnnotatedClasses) { - boolean old = this.discoversAnnotatedClasses; - this.discoversAnnotatedClasses = discoversAnnotatedClasses; - this.firePropertyChanged(DISCOVERS_ANNOTATED_CLASSES_PROPERTY, old, discoversAnnotatedClasses); - } - - - // **************** JPA files ********************************************** - - public Iterator<JpaFile> jpaFiles() { - return new CloneIterator<JpaFile>(this.jpaFiles); // read-only - } - - public int jpaFilesSize() { - return this.jpaFiles.size(); - } - - public JpaFile getJpaFile(IFile file) { - synchronized (this.jpaFiles) { - for (JpaFile jpaFile : this.jpaFiles) { - if (jpaFile.getFile().equals(file)) { - return jpaFile; - } - } - } - return null; - } - - public Iterator<JpaFile> jpaFiles(final String resourceType) { - return new FilteringIterator<JpaFile, JpaFile>(this.jpaFiles()) { - @Override - protected boolean accept(JpaFile o) { - return o.getResourceType().equals(resourceType); - } - }; - } - - /** - * 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.addJpaFileInternal(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 addJpaFileInternal(IFile file) { - JpaFile jpaFile = this.jpaPlatform.buildJpaFile(this, file); - if (jpaFile == null) { - return null; - } - this.jpaFiles.add(jpaFile); - jpaFile.getResourceModel().addResourceModelChangeListener(this.resourceModelListener); - 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 - removeJpaFile(jpaFile); - return true; - } - return false; - } - - /** - * Remove the JPA file and dispose of it - */ - protected void removeJpaFile(JpaFile jpaFile) { - jpaFile.getResourceModel().removeResourceModelChangeListener(this.resourceModelListener); - jpaFile.dispose(); - if ( ! this.removeItemFromCollection(jpaFile, this.jpaFiles, JPA_FILES_COLLECTION)) { - throw new IllegalArgumentException("JPA file: " + jpaFile.getFile().getName()); //$NON-NLS-1$ - } - } - - protected boolean containsJpaFile(IFile file) { - return (this.getJpaFile(file) != null); - } - - - // ********** context model ********** - - public JpaRootContextNode getRootContext() { - return this.rootContextNode; - } - - - // ********** more queries ********** - - public Iterator<String> annotatedClassNames() { - return new TransformationIterator<JavaResourcePersistentType, String>(this.annotatedJavaPersistentTypes()) { - @Override - protected String transform(JavaResourcePersistentType next) { - return next.getQualifiedName(); - } - }; - } - - protected Iterator<JavaResourcePersistentType> annotatedJavaPersistentTypes() { - return new FilteringIterator<JavaResourcePersistentType, JavaResourcePersistentType>(this.javaResourcePersistentTypes()) { - @Override - protected boolean accept(JavaResourcePersistentType persistentType) { - return (persistentType == null) ? false : persistentType.isPersisted(); - } - }; - } - - protected Iterator<JavaResourcePersistentType> javaResourcePersistentTypes() { - return new CompositeIterator<JavaResourcePersistentType>( - new TransformationIterator<JpaCompilationUnit, Iterator<JavaResourcePersistentType>>(jpaCompilationUnitResources()) { - @Override - protected Iterator<JavaResourcePersistentType> transform(JpaCompilationUnit next) { - if (next.getPersistentType() == null) { - return EmptyIterator.instance(); - } - return new CompositeIterator<JavaResourcePersistentType>(next.getPersistentType(), next.getPersistentType().nestedTypes()); - } - }); - } - - public Iterator<JpaFile> javaJpaFiles() { - return this.jpaFiles(ResourceModel.JAVA_RESOURCE_TYPE); - } - - protected Iterator<JpaCompilationUnit> jpaCompilationUnitResources() { - return new TransformationIterator<JpaFile, JpaCompilationUnit>(this.javaJpaFiles()) { - @Override - protected JpaCompilationUnit transform(JpaFile jpaFile) { - return ((JavaResourceModel) jpaFile.getResourceModel()).getJpaCompilationUnit(); - } - }; - } - - // look for binary stuff here... - public JavaResourcePersistentType getJavaResourcePersistentType(String typeName) { - for (JpaCompilationUnit jpCompilationUnitResource : CollectionTools.iterable(this.jpaCompilationUnitResources())) { - JavaResourcePersistentType jptr = jpCompilationUnitResource.getJavaPersistentTypeResource(typeName); - if (jptr != null) { - return jptr; - } - } -// this.javaProject().findType(typeName); - return null; - } - - - // ********** Java change ********** - - public void javaElementChanged(ElementChangedEvent event) { - for (Iterator<JpaFile> stream = this.jpaFiles(); stream.hasNext(); ) { - stream.next().javaElementChanged(event); - } - } - - - // ********** validation ********** - - public Iterator<IMessage> validationMessages() { - List<IMessage> messages = new ArrayList<IMessage>(); - this.jpaPlatform.addToMessages(this, messages); - return messages.iterator(); - } - - /* If this is true, it may be assumed that all the requirements are valid - * for further validation. For example, if this is true at the point we - * are validating persistence units, it may be assumed that there is a - * single persistence.xml and that it has valid content down to the - * persistence unit level. */ - private boolean okToContinueValidation = true; - - public void addToMessages(List<IMessage> messages) { - //start with the project - then down - //project validation - addProjectLevelMessages(messages); - - //context model validation - getRootContext().addToMessages(messages); - } - - protected void addProjectLevelMessages(List<IMessage> messages) { - addConnectionMessages(messages); - addMultiplePersistenceXmlMessage(messages); - } - - protected void addConnectionMessages(List<IMessage> messages) { - addNoConnectionMessage(messages); - addInactiveConnectionMessage(messages); - } - - protected boolean okToProceedForConnectionValidation = true; - - protected void addNoConnectionMessage(List<IMessage> messages) { - if (this.getConnectionProfile() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PROJECT_NO_CONNECTION, - this) - ); - okToProceedForConnectionValidation = false; - } - } - - protected void addInactiveConnectionMessage(List<IMessage> messages) { - if (okToProceedForConnectionValidation && ! this.getDataSource().connectionProfileIsActive()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PROJECT_INACTIVE_CONNECTION, - new String[] {this.getDataSource().getConnectionProfileName()}, - this) - ); - } - okToProceedForConnectionValidation = true; - } - - protected void addMultiplePersistenceXmlMessage(@SuppressWarnings("unused") List<IMessage> messages) { -// if (validPersistenceXmlFiles.size() > 1) { -// messages.add( -// JpaValidationMessages.buildMessage( -// IMessage.HIGH_SEVERITY, -// IJpaValidationMessages.PROJECT_MULTIPLE_PERSISTENCE_XML, -// jpaProject) -// ); -// okToContinueValidation = false; -// } - } - - - // ********** root deploy location ********** - - protected static final String WEB_PROJECT_ROOT_DEPLOY_LOCATION = J2EEConstants.WEB_INF_CLASSES; - - public String getRootDeployLocation() { - return this.isWebProject() ? WEB_PROJECT_ROOT_DEPLOY_LOCATION : ""; //$NON-NLS-1$ - } - - protected static final String JST_WEB_MODULE = IModuleConstants.JST_WEB_MODULE; - - protected boolean isWebProject() { - return JptCorePlugin.projectHasWebFacet(this.project); - } - - - // ********** dispose ********** - - public void dispose() { - if (this.updater != null) { - this.updater.dispose(); - } - // use clone iterator while deleting JPA files - for (Iterator<JpaFile> stream = this.jpaFiles(); stream.hasNext(); ) { - this.removeJpaFile(stream.next()); - } - this.dataSource.dispose(); - } - - - // ********** resource model listener ********** - - protected class DefaultResourceModelListener implements ResourceModelListener { - protected DefaultResourceModelListener() { - super(); - } - public void resourceModelChanged() { - GenericJpaProject.this.update(); - } - } - - - // ********** handling resource deltas ********** - - public void synchronizeJpaFiles(IResourceDelta delta) throws CoreException { - ResourceDeltaVisitor resourceDeltaVisitor = this.buildResourceDeltaVisitor(); - delta.accept(resourceDeltaVisitor); - if (resourceDeltaVisitor.jpaFilesChanged()) { - for(JpaFile jpaFile : CollectionTools.iterable(jpaFiles())) { - jpaFile.getResourceModel().resolveTypes(); - } - } - } - - /** - * 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 : - case IResourceDelta.ADDED_PHANTOM : - case IResourceDelta.REMOVED_PHANTOM : - default : - break; // only worried about added and removed files - } - - return false; - } - - // ***** inner class - /** - * add a JPA file for every [appropriate] file encountered by the visitor - */ - protected class ResourceDeltaVisitor implements IResourceDeltaVisitor { - private boolean jpaFilesChanged = false; - - protected ResourceDeltaVisitor() { - super(); - } - public boolean visit(IResourceDelta delta) throws CoreException { - IResource res = delta.getResource(); - switch (res.getType()) { - case IResource.ROOT : - case IResource.PROJECT : - case IResource.FOLDER : - return true; // visit children - case IResource.FILE : - if (GenericJpaProject.this.synchronizeJpaFiles((IFile) res, delta.getKind())) { - this.jpaFilesChanged = true; - } - return false; // no children - default : - return false; // no children - } - } - /** - * Used to determine if the JPA files collection was modified while - * traversing the IResourceDelta. Return true if a JPA file was added/removed - */ - protected boolean jpaFilesChanged() { - return this.jpaFilesChanged; - } - } - - - // ********** support for modifying documents shared with the UI ********** - - /** - * If there is no thread-specific command executor, use the default - * implementation, which simply executes the command directly. - */ - protected CommandExecutor getThreadLocalModifySharedDocumentCommandExecutor() { - CommandExecutor ce = this.threadLocalModifySharedDocumentCommandExecutor.get(); - return (ce != null) ? ce : CommandExecutor.Default.instance(); - } - - public void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor) { - this.threadLocalModifySharedDocumentCommandExecutor.set(commandExecutor); - } - - public CommandExecutorProvider getModifySharedDocumentCommandExecutorProvider() { - return this.modifySharedDocumentCommandExecutorProvider; - } - - // ***** inner class - protected class ModifySharedDocumentCommandExecutorProvider implements CommandExecutorProvider { - protected ModifySharedDocumentCommandExecutorProvider() { - super(); - } - public CommandExecutor getCommandExecutor() { - return GenericJpaProject.this.getThreadLocalModifySharedDocumentCommandExecutor(); - } - } - - - // ********** project "update" ********** - - public Updater getUpdater() { - return this.updater; - } - - public void setUpdater(Updater updater) { - if (this.updater != null) { // first time through, the updater will be null - this.updater.dispose(); - } - this.updater = updater; - this.updater.start(); - } - - /** - * Delegate to the updater so clients can configure how updates occur. - */ - public void update() { - if (this.updater == null) { - throw new IllegalStateException("updater is null, use #setUpdater(Updater) after construction of GenericJpaProject"); //$NON-NLS-1$ - } - this.updater.update(); - } - - /** - * Called by the updater. - */ - public IStatus update(IProgressMonitor monitor) { - try { - this.getRootContext().update(monitor); - } catch (OperationCanceledException ex) { - return Status.CANCEL_STATUS; - } catch (Throwable ex) { - // Exceptions can occur when the update is running and changes are - // made concurrently to the Java source. When that happens, our - // model might be in an inconsistent state because it is not yet in - // sync with the changed Java source. - // Log these exceptions and assume they won't happen when the - // update runs again as a result of the concurrent Java source changes. - JptCorePlugin.log(ex); - } - return Status.OK_STATUS; - } - -} 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 1e21e392ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java +++ /dev/null @@ -1,564 +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.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; -import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; -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.jdt.core.JavaModelException; -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.core.internal.prefs.JpaPreferenceConstants; -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 (created and opened) - * resource POST_CHANGE -> PROJECT -> CHANGED -> 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; - - /** - * Listen for changes to the "Default JPA Lib" preference - * so we can update the corresponding classpath variable. - */ - private final IPropertyChangeListener preferencesListener; - - - // ********** 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.preferencesListener = new PreferencesListener(); - } - - - // ********** plug-in controlled life-cycle ********** - - /** - * internal - called by JptCorePlugin - */ - public synchronized void start() throws Exception { - debug("*** START JPA model manager ***"); - try { - this.jpaModel = new GenericJpaModel(); - ResourcesPlugin.getWorkspace().addResourceChangeListener(this.resourceChangeListener); - FacetedProjectFramework.addListener(this.facetedProjectListener, IFacetedProjectEvent.Type.values()); - JavaCore.addElementChangedListener(this.javaElementChangeListener); - JptCorePlugin.instance().getPluginPreferences().addPropertyChangeListener(this.preferencesListener); - } catch (RuntimeException ex) { - this.log(ex); - this.stop(); - } - } - - /** - * internal - called by JptCorePlugin - */ - public synchronized void stop() throws Exception { - debug("*** STOP JPA model manager ***"); - JptCorePlugin.instance().getPluginPreferences().removePropertyChangeListener(this.preferencesListener); - 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); - } - - /** - * 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 - */ - /* private */ void resourceChanged(IResourceChangeEvent event) { - 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; - case IResourceChangeEvent.PRE_CLOSE : // project-only event - case IResourceChangeEvent.PRE_BUILD : - case IResourceChangeEvent.POST_BUILD : - default : - break; - } - } - - /** - * A project is being deleted. Remove its corresponding - * JPA project if appropriate. - */ - private void resourcePreDelete(IResourceChangeEvent event) { - debug("Resource (Project) PRE_DELETE: " + event.getResource()); - this.jpaModel.projectPreDelete((IProject) event.getResource()); - } - - /** - * A resource has changed somehow. - * Check for files being added or removed. - * (The JPA project only handles added and removed files here, ignoring - * changed files.) - */ - private void resourcePostChange(IResourceChangeEvent event) { - debug("Resource POST_CHANGE"); - this.synchronizeFiles(event.getDelta()); - this.checkForOpenedProjects(event.getDelta()); - } - - private void synchronizeFiles(IResourceDelta delta) { - IResource resource = delta.getResource(); - switch (resource.getType()) { - case IResource.ROOT : - this.synchronizeFiles(delta.getAffectedChildren()); // recurse - break; - case IResource.PROJECT : - this.synchronizeFiles((IProject) resource, delta); - break; - case IResource.FILE : - case IResource.FOLDER : - default : - break; - } - } - - private void synchronizeFiles(IResourceDelta[] deltas) { - for (int i = 0; i < deltas.length; i++) { - this.synchronizeFiles(deltas[i]); // recurse - } - } - - /** - * Checked exceptions bite. - */ - private void synchronizeFiles(IProject project, IResourceDelta delta) { - try { - this.jpaModel.synchronizeFiles(project, 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 checkForOpenedProjects(IResourceDelta delta) { - IResource resource = delta.getResource(); - switch (resource.getType()) { - case IResource.ROOT : - this.checkForOpenedProjects(delta.getAffectedChildren()); // recurse - break; - case IResource.PROJECT : - this.checkForOpenedProject((IProject) resource, delta); - break; - case IResource.FILE : - case IResource.FOLDER : - default : - break; - } - } - - private void checkForOpenedProjects(IResourceDelta[] deltas) { - for (int i = 0; i < deltas.length; i++) { - this.checkForOpenedProjects(deltas[i]); // recurse - } - } - - private void checkForOpenedProject(IProject project, IResourceDelta delta) { - switch (delta.getKind()) { - case IResourceDelta.CHANGED : - this.checkDeltaFlagsForOpenedProject(project, delta); - break; - case IResourceDelta.REMOVED : // already handled with the PRE_DELETE event - case IResourceDelta.ADDED : // all but project rename handled with the facet POST_INSTALL event - this.checkDeltaFlagsForRenamedProject(project, delta); - break; - case IResourceDelta.ADDED_PHANTOM : // ignore - case IResourceDelta.REMOVED_PHANTOM : // ignore - 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()); - 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()); - this.jpaModel.checkForTransition(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()); - if (event.getProjectFacet().getId().equals(JptCorePlugin.FACET_ID)) { - this.jpaModel.jpaFacetedProjectPostInstall(event); - } - } - - private void facetedProjectPreUninstall(IProjectFacetActionEvent event) { - debug("Facet PRE_UNINSTALL: " + event.getProjectFacet()); - 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()); - this.jpaModel.checkForTransition(project); - } - - - // ********** Java element changed ********** - - /** - * Forward the event to the JPA model. - */ - /* private */ void javaElementChanged(ElementChangedEvent event) { - 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; - } - - // ********** preference changed ********** - - /** - * When the "Default JPA Lib" preference changes, - * update the appropriate JDT Core classpath variable. - */ - /* private */ void preferenceChanged(PropertyChangeEvent event) { - if (event.getProperty() == JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB) { - try { - JavaCore.setClasspathVariable("DEFAULT_JPA_LIB", new Path((String) event.getNewValue()), null); - } catch (JavaModelException ex) { - this.log(ex); // not sure what would cause this... - } - } - } - - - // ********** 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); - } - } - - - // ********** preferences listener ********** - - /** - * Forward the Preferences change event back to the JPA model manager. - */ - private class PreferencesListener implements IPropertyChangeListener { - PreferencesListener() { - super(); - } - public void propertyChange(PropertyChangeEvent event) { - JpaModelManager.this.preferenceChanged(event); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - - // ********** debug ********** - - // @see JpaModelTests#testDEBUG() - private static final boolean DEBUG = false; - - private static void debug(String message) { - if (DEBUG) { - System.out.println(Thread.currentThread().getName() + ": " + message); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java deleted file mode 100644 index 3244d67704..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaProjectAdapterFactory.java +++ /dev/null @@ -1,44 +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; - -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; - -public class JpaProjectAdapterFactory - implements IAdapterFactory -{ - private static Class[] PROPERTIES= new Class[] { - JpaProject.class - }; - - public Class[] getAdapterList() { - return PROPERTIES; - } - - public Object getAdapter(Object element, Class key) { - IProject project; - - if (element instanceof IProject) { - project = (IProject) element; - } - else if (element instanceof IJavaProject) { - project = ((IJavaProject) element).getProject(); - } - else { - return null; - } - - return JptCorePlugin.getJpaProject(project); - } -} 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 ecab723abe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.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; - -import org.eclipse.osgi.util.NLS; - -/** - * Localized messages used by Dali core. - */ -public class JptCoreMessages { - - public static String NONE; - 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_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_NOT_CONNECTED; - public static String VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED; - 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; - - 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/SimpleJpaProjectConfig.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java deleted file mode 100644 index f642ef3ae9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SimpleJpaProjectConfig.java +++ /dev/null @@ -1,76 +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; - -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 userOverrideDefaultSchemaName; - 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 getUserOverrideDefaultSchemaName() { - return this.userOverrideDefaultSchemaName; - } - - public void setUserOverrideDefaultSchemaName(String userOverrideDefaultSchemaName) { - this.userOverrideDefaultSchemaName = userOverrideDefaultSchemaName; - } - - 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 37a621f36b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.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; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.SynchronizedBoolean; - -/** - * 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 implements JpaProject.Updater { - protected final JpaProject jpaProject; - protected final SynchronizedFlags flags; - - protected static final IProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); - - public SynchronousJpaProjectUpdater(JpaProject jpaProject) { - super(); - this.jpaProject = jpaProject; - this.flags = new SynchronizedFlags(); - } - - /** - * Initialize the flags and execute an "update". - */ - public void start() { - this.flags.start(); - this.update(); - } - - // recursion: we come back here when IJpaProject#update() is called during the "update" - public void update() { - if (this.flags.updateCanStart()) { - do { - this.jpaProject.update(NULL_PROGRESS_MONITOR); - } while (this.flags.updateMustExecuteAgain()); - } - } - - public void dispose() { - this.flags.dispose(); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.jpaProject); - } - - - /** - * synchronize access to the pair of 'updating' and 'again' flags - */ - protected static class SynchronizedFlags { - protected SynchronizedBoolean updating = new SynchronizedBoolean(false, this); - protected boolean again = false; - protected boolean stop = true; - - protected synchronized void start() { - if ( ! this.stop) { - throw new IllegalStateException("The Updater was not stopped."); - } - this.stop = false; - } - - /** - * A client has requested an "update"; - * return whether the updater can start an "update". - * Side-effects: - * - If we are currently updating, set the 'again' flag. - * - If we are not currently updating, set the 'updating' flag and clear the 'again' flag. - */ - protected synchronized boolean updateCanStart() { - if (this.stop) { - return false; - } - if (this.updating.isTrue()) { - this.again = true; - return false; - } - this.updating.setTrue(); - this.again = false; - return true; - } - - /** - * The "update" has finished; - * return whether the updater must execute another "update". - * Side-effects: - * - If we are supposed to stop, clear the both the 'updating' and 'again' flags. - * - If we have to "update" again, clear the 'again' flag and leave the 'updating' flag set. - * - If we are finished, clear the 'updating' flag. - */ - protected synchronized boolean updateMustExecuteAgain() { - if (this.stop) { - return false; - } - if (this.again) { - this.again = false; - return true; - } - this.updating.setFalse(); - return false; - } - - protected synchronized void dispose() { - this.stop = true; - this.again = false; - try { - this.updating.waitUntilFalse(); - } catch (InterruptedException ex) { - // the "update" thread was interrupted while waiting - ignore - } - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractJpaContextNode.java deleted file mode 100644 index cb7cab0f38..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractJpaContextNode.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context; - -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.AbstractJpaNode; - -public abstract class AbstractJpaContextNode extends AbstractJpaNode - implements JpaContextNode -{ - // **************** constructor ******************************************** - - protected AbstractJpaContextNode(JpaNode parent) { - super(parent); - } - - - // **************** JpaNode impl ******************************************* - - @Override - public JpaContextNode getParent() { - return (JpaContextNode) super.getParent(); - } - - - // **************** JpaContextNode impl ************************************ - - /** - * Overidden in BaseJpaContext, Persistence, PersitsenceXml to throw UnsupportedOperationException - * Overidden in PersistenceUnit to return it. - */ - public PersistenceUnit getPersistenceUnit() { - return getParent().getPersistenceUnit(); - } - - /** - * Overidden in BaseJpaContext to return null - * Overidden in EntityMappings to return it. - */ - public EntityMappings getEntityMappings() { - return getParent().getEntityMappings(); - } - - /** - * Overidden in BaseJpaContext to return null - * Overidden in OrmPersistentType to return it. - */ - public OrmPersistentType getOrmPersistentType() { - return getParent().getOrmPersistentType(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java deleted file mode 100644 index 3bdca8d31f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context; - -import java.util.Collection; -import java.util.List; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.PersistenceArtifactEdit; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericRootContextNode extends AbstractJpaContextNode - implements JpaRootContextNode -{ - /* This object has no parent, so it must point to the JPA project */ - protected final JpaProject jpaProject; - - /* Main context object */ - protected PersistenceXml persistenceXml; - - - public GenericRootContextNode(JpaProject jpaProject) { - super(null); - if (jpaProject == null) { - throw new IllegalArgumentException("The JPA project must not be null"); - } - this.jpaProject = jpaProject; - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForRead(jpaProject.getProject()); - PersistenceResource pr = pae.getResource(); - - if (pr.exists()) { - this.persistenceXml = this.buildPersistenceXml(pr); - } - - pae.dispose(); - } - - @Override - protected boolean requiresParent() { - return false; - } - - - // **************** JpaNode impl ******************************************* - - @Override - public JpaProject getJpaProject() { - return this.jpaProject; - } - - @Override - public IResource getResource() { - return getJpaProject().getProject(); - } - - @Override - public JpaContextNode getParent() { - return null; - } - - - // **************** JpaContextNode impl ************************************ - - @Override - public PersistenceUnit getPersistenceUnit() { - // No PersistenceUnit in this context - return null; - } - - @Override - public EntityMappings getEntityMappings() { - // No EntityMappings in this context - return null; - } - - @Override - public OrmPersistentType getOrmPersistentType() { - // No OrmPersistentType in this context - return null; - } - - - // **************** persistence xml **************************************** - - public PersistenceXml getPersistenceXml() { - return this.persistenceXml; - } - - protected void setPersistenceXml(PersistenceXml persistenceXml) { - PersistenceXml old = this.persistenceXml; - this.persistenceXml = persistenceXml; - this.firePropertyChanged(PERSISTENCE_XML_PROPERTY, old, persistenceXml); - } - - public PersistenceXml addPersistenceXml() { - if (this.persistenceXml != null) { - throw new IllegalStateException(); - } - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(this.getJpaProject().getProject()); - PersistenceResource pr = pae.createDefaultResource(); - pae.dispose(); - PersistenceXml px = this.buildPersistenceXml(pr); - this.setPersistenceXml(px); - return px; - } - - public void removePersistenceXml() { - if (this.persistenceXml == null) { - throw new IllegalStateException(); - } - this.persistenceXml.dispose(); - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(getJpaProject().getProject()); - PersistenceResource pr = pae.getResource(); - pae.dispose(); - try { - WorkbenchResourceHelper.deleteResource(pr); - } - catch (CoreException ce) { - JptCorePlugin.log(ce); - } - - if (! pr.exists()) { - setPersistenceXml(null); - } - } - - - // **************** updating *********************************************** - - public void update(IProgressMonitor monitor) { - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForRead(getJpaProject().getProject()); - PersistenceResource pr = pae.getResource(); - - if (pr.exists()) { - if (this.persistenceXml != null) { - this.persistenceXml.update(pr); - } - else { - setPersistenceXml(this.buildPersistenceXml(pr)); - } - } - else { - setPersistenceXml(null); - } - - pae.dispose(); - } - - protected PersistenceXml buildPersistenceXml(PersistenceResource persistenceResource) { - return this.getJpaFactory().buildPersistenceXml(this, persistenceResource); - } - - - // **************** Validation ********************************************* - - /* If this is true, it may be assumed that all the requirements are valid - * for further validation. For example, if this is true at the point we - * are validating persistence units, it may be assumed that there is a - * single persistence.xml and that it has valid content down to the - * persistence unit level. */ - private boolean okToContinueValidation = true; - - public void addToMessages(List<IMessage> messages) { - addNoPersistenceXmlMessage(messages); - //TODO - multiple persistence unit message - addOrphanedJavaClassMessages(messages); - - if(okToContinueValidation) { - getPersistenceXml().addToMessages(messages); - } - - } - - protected void addNoPersistenceXmlMessage(List<IMessage> messages) { - if (persistenceXml == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PROJECT_NO_PERSISTENCE_XML, - this) - ); - okToContinueValidation = false; - } - } - - - - - protected void addOrphanedJavaClassMessages(List<IMessage> messages) { - if (getPersistenceXml() == null) { - //handled with other validation - return; - } - if (getPersistenceXml().getPersistence() == null) { - //handled with other validation - return; - } - if (getJpaProject().discoversAnnotatedClasses()) { - return; - } - Collection<String> orphanedClassNames = CollectionTools.collection(getJpaProject().annotatedClassNames()); - if (getPersistenceXml().getPersistence().persistenceUnitsSize() != 1) { - //context model currently only supports 1 persistenceUnit - return; - } - PersistenceUnit persistenceUnit = getPersistenceXml().getPersistence().persistenceUnits().next(); - for (String typeName : CollectionTools.iterable(getJpaProject().annotatedClassNames())) { - for (ClassRef classRef : CollectionTools.iterable(persistenceUnit.specifiedClassRefs())) { - if (classRef.isFor(typeName)) { - orphanedClassNames.remove(typeName); - } - } - for (MappingFileRef mappingFileRef : CollectionTools.iterable(persistenceUnit.mappingFileRefs())) { - if (mappingFileRef.getOrmXml() == null || mappingFileRef.getOrmXml().getEntityMappings() == null) { - continue; - } - if (mappingFileRef.getOrmXml().getEntityMappings().getPersistentType(typeName) != null) { - orphanedClassNames.remove(typeName); - } - } - } - - for (String orphanedTypeName : orphanedClassNames) { - JavaResourcePersistentType javaResourcePersistentType = getJpaProject().getJavaResourcePersistentType(orphanedTypeName); - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CONTEXT, - new String[] {persistenceUnit.getName()}, - javaResourcePersistentType.getResourceModel().getFile(), - javaResourcePersistentType.getMappingAnnotation().getTextRange(JDTTools.buildASTRoot(javaResourcePersistentType.getJpaCompilationUnit().getCompilationUnit()))) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JpaContextNodeAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JpaContextNodeAdapterFactory.java deleted file mode 100644 index eadbca2144..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JpaContextNodeAdapterFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jpt.core.context.JpaContextNode; - -public class JpaContextNodeAdapterFactory - implements IAdapterFactory -{ - private static Class[] PROPERTIES = - new Class[] { IResource.class, IFile.class }; - - - public Class[] getAdapterList() { - return PROPERTIES; - } - - public Object getAdapter(Object element, Class key) { - JpaContextNode node; - - if (element instanceof JpaContextNode) { - node = (JpaContextNode) element; - } - else { - return null; - } - - IResource resource = node.getResource(); - - if (key.equals(IResource.class)) { - return resource; - } - else if (key.equals(IFile.class) && resource != null && resource.getType() == IResource.FILE) { - return (IFile) resource; - } - - return null; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java deleted file mode 100644 index e3cf890046..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context; - -import java.util.Iterator; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; - -public class MappingTools -{ - /** - * Default join table name from the JPA spec: - * The concatenated names of the two associated primary - * entity tables, separated by a underscore. - * - * [owning table name]_[target table name] - */ - public static String buildJoinTableDefaultName(RelationshipMapping relationshipMapping) { - if (!relationshipMapping.isRelationshipOwner()) { - return null; - } - String owningTableName = relationshipMapping.getTypeMapping().getTableName(); - if (owningTableName == null) { - return null; - } - Entity targetEntity = relationshipMapping.getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - String targetTableName = targetEntity.getTableName(); - if (targetTableName == null) { - return null; - } - return owningTableName + '_' + targetTableName; - } - - /** - * return the join column's default name; - * which is typically <attribute name>_<referenced column name> - * but, if we don't have an attribute name (e.g. in a unidirectional - * OneToMany or ManyToMany) is - * <target entity name>_<referenced column name> - */ - // <attribute name>_<referenced column name> - // or - // <target entity name>_<referenced column name> - public static String buildJoinColumnDefaultName(JoinColumn joinColumn) { - if (joinColumn.getOwner().joinColumnsSize() != 1) { - return null; - } - String prefix = joinColumn.getOwner().getAttributeName(); - if (prefix == null) { - prefix = targetEntityName(joinColumn); - } - if (prefix == null) { - return null; - } - // TODO not sure which of these is correct... - // (the spec implies that the referenced column is always the - // primary key column of the target entity) - // String targetColumn = this.targetPrimaryKeyColumnName(); - String targetColumn = joinColumn.getReferencedColumnName(); - if (targetColumn == null) { - return null; - } - return prefix + '_' + targetColumn; - } - - /** - * return the name of the target entity - */ - protected static String targetEntityName(JoinColumn joinColumn) { - Entity targetEntity = joinColumn.getOwner().getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getName(); - } - - public static String buildJoinColumnDefaultReferencedColumnName(JoinColumn joinColumn) { - if (joinColumn.getOwner().joinColumnsSize() != 1) { - return null; - } - return targetPrimaryKeyColumnName(joinColumn); - } - - /** - * return the name of the single primary key column of the target entity - */ - protected static String targetPrimaryKeyColumnName(JoinColumn joinColumn) { - Entity targetEntity = joinColumn.getOwner().getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryKeyColumnName(); - } - - - public static Embeddable getEmbeddableFor(JavaPersistentAttribute persistentAttribute) { - String qualifiedTypeName = persistentAttribute.getResourcePersistentAttribute().getQualifiedTypeName(); - if (qualifiedTypeName == null) { - return null; - } - PersistentType persistentType = persistentAttribute.getPersistenceUnit().getPersistentType(qualifiedTypeName); - if (persistentType != null) { - if (persistentType.getMappingKey() == MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY) { - return (Embeddable) persistentType.getMapping(); - } - } - return null; - } - - public static ColumnMapping getColumnMapping(String attributeName, Embeddable embeddable) { - if (attributeName == null || embeddable == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = embeddable.getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof ColumnMapping) { - return (ColumnMapping) persAttribute.getMapping(); - } - } - } - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributePropertyTester.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributePropertyTester.java deleted file mode 100644 index 80ee5ff187..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributePropertyTester.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context; - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class PersistentAttributePropertyTester extends PropertyTester -{ - public static final String IS_MAPPED = "isMapped"; - - public static final String IS_VIRTUAL = "isVirtual"; - - - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (IS_MAPPED.equals(property)) { - Boolean expectedIsMapped; - - try { - expectedIsMapped = (Boolean) expectedValue; - } - catch (ClassCastException cce) { - return false; - } - - Boolean actualIsMapped = ((PersistentAttribute) receiver).getMappingKey() != MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - - return actualIsMapped == expectedIsMapped; - } - else if (IS_VIRTUAL.equals(property)) { - Boolean expectedIsVirtual; - - try { - expectedIsVirtual = (Boolean) expectedValue; - } - catch (ClassCastException cce) { - return false; - } - - Boolean actualIsVirtual = false; - if (receiver instanceof OrmPersistentAttribute) { - actualIsVirtual = ((OrmPersistentAttribute) receiver).isVirtual(); - } - - return actualIsVirtual == expectedIsVirtual; - } - - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java deleted file mode 100644 index 4ff0a0f130..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractJavaAttributeMapping<T extends JavaResourceNode> extends AbstractJavaJpaContextNode - implements JavaAttributeMapping -{ - protected JavaResourcePersistentAttribute resourcePersistentAttribute; - - - protected AbstractJavaAttributeMapping(JavaPersistentAttribute parent) { - super(parent); - } - - @SuppressWarnings("unchecked") - protected T getMappingResource() { - if (isDefault()) { - return (T) this.resourcePersistentAttribute.getNullMappingAnnotation(getAnnotationName()); - } - return (T) this.resourcePersistentAttribute.getMappingAnnotation(getAnnotationName()); - } - - public GenericJavaPersistentAttribute getPersistentAttribute() { - return (GenericJavaPersistentAttribute) this.getParent(); - } - - protected JavaResourcePersistentAttribute getResourcePersistentAttribute() { - return this.resourcePersistentAttribute; - } - - /** - * the persistent attribute can tell whether there is a "specified" mapping - * or a "default" one - */ - public boolean isDefault() { - return this.getPersistentAttribute().mappingIsDefault(this); - } - - protected boolean embeddableOwned() { - return this.getTypeMapping().getKey() == MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - protected boolean entityOwned() { - return this.getTypeMapping().getKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public TypeMapping getTypeMapping() { - return this.getPersistentAttribute().getTypeMapping(); - } - - public String getAttributeName() { - return this.getPersistentAttribute().getName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = null; - T mappingResource = getMappingResource(); - if (mappingResource != null) { - textRange = mappingResource.getTextRange(astRoot); - } - return (textRange != null) ? textRange : this.getPersistentAttribute().getValidationTextRange(astRoot); - } - - public String getPrimaryKeyColumnName() { - return null; - } - - public boolean isOverridableAttributeMapping() { - return false; - } - - public boolean isOverridableAssociationMapping() { - return false; - } - - public boolean isIdMapping() { - return false; - } - - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.resourcePersistentAttribute = resourcePersistentAttribute; - initialize(getMappingResource()); - } - - protected void initialize(T mappingResource) { - - } - - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.resourcePersistentAttribute = resourcePersistentAttribute; - this.update(getMappingResource()); - } - - protected void update(T mappingResource) { - - } - - - //************ Validation ************************* - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addModifierMessages(messages, astRoot); - addInvalidMappingMessage(messages, astRoot); - } - - protected void addModifierMessages(List<IMessage> messages, CompilationUnit astRoot) { - GenericJavaPersistentAttribute attribute = this.getPersistentAttribute(); - if (attribute.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - - if ( this.resourcePersistentAttribute.isForField()) { - if (this.resourcePersistentAttribute.isFinal()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, - new String[] {attribute.getName()}, - attribute, attribute.getValidationTextRange(astRoot)) - ); - } - - if (this.resourcePersistentAttribute.isPublic()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, - new String[] {attribute.getName()}, - attribute, attribute.getValidationTextRange(astRoot)) - ); - } - } - } - - protected void addInvalidMappingMessage(List<IMessage> messages, CompilationUnit astRoot) { - if (! getTypeMapping().attributeMappingKeyAllowed(this.getKey())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_MAPPING, - new String[] {this.getPersistentAttribute().getName()}, - this, this.getValidationTextRange(astRoot)) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java deleted file mode 100644 index c38a1eab19..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java +++ /dev/null @@ -1,302 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.java.JavaBaseColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.BaseColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public abstract class AbstractJavaBaseColumn<T extends BaseColumnAnnotation> extends AbstractJavaNamedColumn<T> - implements JavaBaseColumn -{ - - protected String specifiedTable; - - protected String defaultTable; - - protected Boolean specifiedUnique; - - protected Boolean specifiedNullable; - - protected Boolean specifiedInsertable; - - protected Boolean specifiedUpdatable; - - protected AbstractJavaBaseColumn(JavaJpaContextNode parent, JavaBaseColumn.Owner owner) { - super(parent, owner); - } - - @Override - protected void initialize(T column) { - super.initialize(column); - this.defaultTable = this.defaultTable(); - this.specifiedTable = this.specifiedTable(column); - this.specifiedUnique = this.specifiedUnique(column); - this.specifiedNullable = this.specifiedNullable(column); - this.specifiedInsertable = this.specifiedInsertable(column); - this.specifiedUpdatable = this.specifiedUpdatable(column); - } - - @Override - public JavaBaseColumn.Owner getOwner() { - return (JavaBaseColumn.Owner) super.getOwner(); - } - - //************** IAbstractColumn implementation ******************* - - - public String getTable() { - return (this.getSpecifiedTable() == null) ? getDefaultTable() : this.getSpecifiedTable(); - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - getColumnResource().setTable(newSpecifiedTable); - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - protected void setDefaultTable(String newDefaultTable) { - String oldDefaultTable = this.defaultTable; - this.defaultTable = newDefaultTable; - firePropertyChanged(BaseColumn.DEFAULT_TABLE_PROPERTY, oldDefaultTable, newDefaultTable); - } - - public Boolean getUnique() { - return (this.getSpecifiedUnique() == null) ? this.getDefaultUnique() : this.getSpecifiedUnique(); - } - - public Boolean getDefaultUnique() { - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getSpecifiedUnique() { - return this.specifiedUnique; - } - - public void setSpecifiedUnique(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - this.getColumnResource().setUnique(newSpecifiedUnique); - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedUnique_(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - public Boolean getNullable() { - return (this.getSpecifiedNullable() == null) ? this.getDefaultNullable() : this.getSpecifiedNullable(); - } - - public Boolean getDefaultNullable() { - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getSpecifiedNullable() { - return this.specifiedNullable; - } - - public void setSpecifiedNullable(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - this.getColumnResource().setNullable(newSpecifiedNullable); - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedNullable_(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - public Boolean getInsertable() { - return (this.getSpecifiedInsertable() == null) ? this.getDefaultInsertable() : this.getSpecifiedInsertable(); - } - - public Boolean getDefaultInsertable() { - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getSpecifiedInsertable() { - return this.specifiedInsertable; - } - - public void setSpecifiedInsertable(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - this.getColumnResource().setInsertable(newSpecifiedInsertable); - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedInsertable_(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - public Boolean getUpdatable() { - return (this.getSpecifiedUpdatable() == null) ? this.getDefaultUpdatable() : this.getSpecifiedUpdatable(); - } - - public Boolean getDefaultUpdatable() { - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getSpecifiedUpdatable() { - return this.specifiedUpdatable; - } - - public void setSpecifiedUpdatable(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - this.getColumnResource().setUpdatable(newSpecifiedUpdatable); - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedUpdatable_(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - @Override - protected String getTableName() { - return this.getTable(); - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getColumnResource().getTableTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - return getColumnResource().tableTouches(pos, astRoot); - } - - private Iterator<String> candidateTableNames() { - return this.tableIsAllowed() ? this.getOwner().getTypeMapping().associatedTableNamesIncludingInherited() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateTableNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateTableNames(), filter); - } - - private Iterator<String> quotedCandidateTableNames(Filter<String> filter) { - return StringTools.quote(this.candidateTableNames(filter)); - } - - /** - * Return whether the 'table' element is allowed. It is not allowed for - * join columns inside of join tables. - */ - public abstract boolean tableIsAllowed(); - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.tableTouches(pos, astRoot)) { - return this.quotedCandidateTableNames(filter); - } - return null; - } - - @Override - protected void update(T column) { - super.update(column); - this.setDefaultTable(this.defaultTable()); - this.setSpecifiedTable_(this.specifiedTable(column)); - this.setSpecifiedUnique_(this.specifiedUnique(column)); - this.setSpecifiedNullable_(this.specifiedNullable(column)); - this.setSpecifiedInsertable_(this.specifiedInsertable(column)); - this.setSpecifiedUpdatable_(this.specifiedUpdatable(column)); - } - - protected String defaultTable() { - return this.getOwner().getDefaultTableName(); - } - - protected String specifiedTable(BaseColumnAnnotation column) { - return column.getTable(); - } - - protected Boolean specifiedUnique(BaseColumnAnnotation column) { - return column.getUnique(); - } - - protected Boolean specifiedNullable(BaseColumnAnnotation column) { - return column.getNullable(); - } - - protected Boolean specifiedInsertable(BaseColumnAnnotation column) { - return column.getInsertable(); - } - - protected Boolean specifiedUpdatable(BaseColumnAnnotation column) { - return column.getUpdatable(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java deleted file mode 100644 index c23de9bfe6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseEmbeddedMapping; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.resource.java.NullColumn; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractJavaBaseEmbeddedMapping<T extends JavaResourceNode> extends AbstractJavaAttributeMapping<T> - implements JavaBaseEmbeddedMapping -{ - protected final List<JavaAttributeOverride> specifiedAttributeOverrides; - - protected final List<JavaAttributeOverride> virtualAttributeOverrides; - - private Embeddable embeddable; - - protected AbstractJavaBaseEmbeddedMapping(JavaPersistentAttribute parent) { - super(parent); - this.specifiedAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - } - - //****************** JavaAttributeMapping implemenation ******************* - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ATTRIBUTE_OVERRIDE, - JPA.ATTRIBUTE_OVERRIDES); - } - - //****************** AttributeOverride.Owner implemenation ******************* - - public ColumnMapping getColumnMapping(String attributeName) { - return MappingTools.getColumnMapping(attributeName, embeddable()); - } - - public boolean isVirtual(BaseOverride override) { - return this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - // Add a new attribute override - if (virtual) { - return setAttributeOverrideVirtual((JavaAttributeOverride) override); - } - return setAttributeOverrideSpecified((JavaAttributeOverride) override); - } - - protected JavaAttributeOverride setAttributeOverrideVirtual(JavaAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(getResourcePersistentAttribute(), persistentAttribute.getName()); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - break; - } - } - } - - getResourcePersistentAttribute().removeAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected JavaAttributeOverride setAttributeOverrideSpecified(JavaAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - JavaAttributeOverride newAttributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) getResourcePersistentAttribute().addAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - newAttributeOverride.initialize(attributeOverrideResource); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - - //****************** BaseEmbeddedMapping implemenation ******************* - - @SuppressWarnings("unchecked") - public ListIterator<JavaAttributeOverride> attributeOverrides() { - return new CompositeListIterator<JavaAttributeOverride>(this.specifiedAttributeOverrides(), this.virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<JavaAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.virtualAttributeOverrides); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - public ListIterator<JavaAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected void addSpecifiedAttributeOverride(int index, JavaAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - getResourcePersistentAttribute().move(targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - protected void addVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - public JavaAttributeOverride getAttributeOverrideNamed(String name) { - return (JavaAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - public boolean containsAttributeOverride(String name) { - return containsOverride(name, attributeOverrides()); - } - - public boolean containsDefaultAttributeOverride(String name) { - return containsOverride(name, virtualAttributeOverrides()); - } - - public boolean containsSpecifiedAttributeOverride(String name) { - return containsOverride(name, specifiedAttributeOverrides()); - } - - protected BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(overrides)) { - String overrideName = override.getName(); - if (overrideName == null && name == null) { - return override; - } - if (overrideName != null && overrideName.equals(name)) { - return override; - } - } - return null; - } - - protected boolean containsOverride(String name, ListIterator<? extends BaseOverride> overrides) { - return getOverrideNamed(name, overrides) != null; - } - - public Embeddable embeddable() { - return this.embeddable; - } - - - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initialize(resourcePersistentAttribute); - this.initializeAttributeOverrides(resourcePersistentAttribute); - this.initializeDefaultAttributeOverrides(resourcePersistentAttribute); - this.embeddable = MappingTools.getEmbeddableFor(getPersistentAttribute()); - } - - protected void initializeAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaResourceNode> annotations = resourcePersistentAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); - attributeOverride.initialize((AttributeOverrideAnnotation) annotations.next()); - this.specifiedAttributeOverrides.add(attributeOverride); - } - } - - protected void initializeDefaultAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - for (Iterator<String> i = allOverridableAttributeNames(); i.hasNext(); ) { - String attributeName = i.next(); - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(attributeName); - if (attributeOverride == null) { - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(resourcePersistentAttribute, attributeName)); - } - } - } @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.embeddable = MappingTools.getEmbeddableFor(getPersistentAttribute()); - this.updateSpecifiedAttributeOverrides(resourcePersistentAttribute); - this.updateVirtualAttributeOverrides(resourcePersistentAttribute); - - } - protected void updateSpecifiedAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<JavaResourceNode> resourceAttributeOverrides = resourcePersistentAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while (attributeOverrides.hasNext()) { - JavaAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update((AttributeOverrideAnnotation) resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride((AttributeOverrideAnnotation) resourceAttributeOverrides.next())); - } - } - - protected JavaAttributeOverride buildAttributeOverride(AttributeOverrideAnnotation attributeOverrideResource) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); - attributeOverride.initialize(attributeOverrideResource); - return attributeOverride; - } - - protected JavaAttributeOverride buildVirtualAttributeOverride(JavaResourcePersistentAttribute resourcePersistentAttribute, String attributeName) { - return buildAttributeOverride(buildVirtualAttributeOverrideResource(resourcePersistentAttribute, attributeName)); - } - - protected VirtualAttributeOverride buildVirtualAttributeOverrideResource(JavaResourcePersistentAttribute resourcePersistentAttribute, String attributeName) { - ColumnMapping columnMapping = (ColumnMapping) this.embeddable().getPersistentType().getAttributeNamed(attributeName).getMapping(); - return new VirtualAttributeOverride(resourcePersistentAttribute, attributeName, columnMapping.getColumn()); - } - - protected void updateVirtualAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - for (Iterator<String> i = allOverridableAttributeNames(); i.hasNext(); ) { - String attributeName = i.next(); - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(attributeName); - if (attributeOverride == null) { - addVirtualAttributeOverride(buildVirtualAttributeOverride(resourcePersistentAttribute, attributeName)); - } - else if (attributeOverride.isVirtual()) { - attributeOverride.getColumn().update(new NullColumn(resourcePersistentAttribute)); - } - } - - Collection<String> attributeNames = CollectionTools.collection(allOverridableAttributeNames()); - - //remove any default mappings that are not included in the attributeNames collection - for (JavaAttributeOverride attributeOverride : CollectionTools.iterable(virtualAttributeOverrides())) { - if (!attributeNames.contains(attributeOverride.getName()) - || containsSpecifiedAttributeOverride(attributeOverride.getName())) { - removeVirtualAttributeOverride(attributeOverride); - } - } - } - - - public Iterator<String> allOverridableAttributeNames() { - return new TransformationIterator<PersistentAttribute, String>(this.allOverridableAttributes()) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - if (this.embeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<PersistentAttribute, PersistentAttribute>(this.embeddable().getPersistentType().attributes()) { - @Override - protected boolean accept(PersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (AttributeOverride override : CollectionTools.iterable(this.attributeOverrides())) { - result = ((JavaAttributeOverride) override).javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - //******** Validation ****************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - for (Iterator<JavaAttributeOverride> stream = attributeOverrides(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaGenerator.java deleted file mode 100644 index f3392e6a17..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaGenerator.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.GeneratorAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class AbstractJavaGenerator extends AbstractJavaJpaContextNode - implements JavaGenerator -{ - protected String name; - - protected Integer specifiedInitialValue; - - protected Integer specifiedAllocationSize; - - protected GeneratorAnnotation generatorResource; - - protected AbstractJavaGenerator(JavaJpaContextNode parent) { - super(parent); - } - - public void initialize(GeneratorAnnotation generatorResource) { - this.generatorResource = generatorResource; - this.name = this.name(generatorResource); - this.specifiedInitialValue = this.specifiedInitialValue(generatorResource); - this.specifiedAllocationSize = this.specifiedAllocationSize(generatorResource); - } - - protected GeneratorAnnotation getGeneratorResource() { - return this.generatorResource; - } - - protected String name(GeneratorAnnotation generatorResource) { - return generatorResource.getName(); - } - - protected Integer specifiedInitialValue(GeneratorAnnotation generatorResource) { - return generatorResource.getInitialValue(); - } - - protected Integer specifiedAllocationSize(GeneratorAnnotation generatorResource) { - return generatorResource.getAllocationSize(); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - getGeneratorResource().setName(newName); - firePropertyChanged(Generator.NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(Generator.NAME_PROPERTY, oldName, newName); - } - - public Integer getInitialValue() { - return (this.getSpecifiedInitialValue() == null) ? this.getDefaultInitialValue() : this.getSpecifiedInitialValue(); - } - - public Integer getSpecifiedInitialValue() { - return this.specifiedInitialValue; - } - - public void setSpecifiedInitialValue(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - getGeneratorResource().setInitialValue(newSpecifiedInitialValue); - firePropertyChanged(Generator.SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - protected void setSpecifiedInitialValue_(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - firePropertyChanged(Generator.SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - public Integer getAllocationSize() { - return (this.getSpecifiedAllocationSize() == null) ? this.getDefaultAllocationSize() : this.getSpecifiedAllocationSize(); - } - - public Integer getSpecifiedAllocationSize() { - return this.specifiedAllocationSize; - } - - public void setSpecifiedAllocationSize(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - getGeneratorResource().setAllocationSize(newSpecifiedAllocationSize); - firePropertyChanged(Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - protected void setSpecifiedAllocationSize_(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - firePropertyChanged(Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - public Integer getDefaultAllocationSize() { - return Generator.DEFAULT_ALLOCATION_SIZE; - } - - public boolean isVirtual() { - return false; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - public TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.generatorResource.getTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.generatorResource.getNameTextRange(astRoot); - } - - protected void update(GeneratorAnnotation generatorResource) { - this.generatorResource = generatorResource; - this.setName_(this.name(generatorResource)); - this.setSpecifiedInitialValue_(this.specifiedInitialValue(generatorResource)); - this.setSpecifiedAllocationSize_(this.specifiedAllocationSize(generatorResource)); - } - - public boolean overrides(Generator generator) { - // java is at the base of the tree - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJpaContextNode.java deleted file mode 100644 index 34bcc085f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJpaContextNode.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.AbstractJpaContextNode; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public abstract class AbstractJavaJpaContextNode extends AbstractJpaContextNode implements JavaJpaContextNode -{ - // ********** constructor ********** - - protected AbstractJavaJpaContextNode(JpaContextNode parent) { - super(parent); - } - - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - if (this.connectionProfileIsActive()) { - Iterator<String> result = this.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - /** - * This method is called if the database is connected, allowing us to - * get candidates from the various database tables etc. - * This method should NOT be cascaded to "child" objects; it should - * only return candidates for the current object. The cascading is - * handled by #javaCompletionProposals(int, Filter, CompilationUnit). - */ - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - return null; - } - - // ********** validation ********** - - /** - * All subclass implementations {@link #addToMessages(List, CompilationUnit))} - * should be preceded by a "super" call to this method - */ - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java deleted file mode 100644 index a80d8a3d0a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java +++ /dev/null @@ -1,458 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.MultiRelationshipMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractJavaMultiRelationshipMapping<T extends RelationshipMappingAnnotation> - extends AbstractJavaRelationshipMapping<T> implements MultiRelationshipMapping -{ - - protected String mappedBy; - - protected String orderBy; - - protected boolean isNoOrdering; - - protected boolean isPkOrdering; - - protected boolean isCustomOrdering; - - //TODO should this be null if this is the non-owning side of the relationship?? - protected final JavaJoinTable joinTable; - - protected String mapKey; - - protected AbstractJavaMultiRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.joinTable = getJpaFactory().buildJavaJoinTable(this); - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - this.setMappedByOnResourceModel(newMappedBy); - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected abstract void setMappedByOnResourceModel(String mappedBy); - - public String getOrderBy() { - return this.orderBy; - } - - public void setOrderBy(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - if (newOrderBy == null) { - if (getOrderByResource() != null) { - removeOrderByResource(); - } - } - else { - if (getOrderByResource() == null) { - addOrderByResource(); - } - getOrderByResource().setValue(newOrderBy); - } - firePropertyChanged(MultiRelationshipMapping.ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - protected void setOrderBy_(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - firePropertyChanged(MultiRelationshipMapping.ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - protected OrderByAnnotation getOrderByResource() { - return (OrderByAnnotation) getResourcePersistentAttribute().getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - protected OrderByAnnotation addOrderByResource() { - return (OrderByAnnotation) getResourcePersistentAttribute().addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - protected void removeOrderByResource() { - getResourcePersistentAttribute().removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - public boolean isNoOrdering() { - return this.isNoOrdering; - } - - public void setNoOrdering(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - if (newNoOrdering) { - if (getOrderByResource() != null) { - removeOrderByResource(); - } - } - else { - //?? - } - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - protected void setNoOrdering_(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - public boolean isPkOrdering() { - return this.isPkOrdering; - } - - public void setPkOrdering(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - if (newPkOrdering) { - if (getOrderByResource() == null) { - addOrderByResource(); - } - else { - getOrderByResource().setValue(null); - } - } - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - protected void setPkOrdering_(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - public boolean isCustomOrdering() { - return this.isCustomOrdering; - } - - public void setCustomOrdering(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - if (newCustomOrdering) { - setOrderBy(""); - } - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - protected void setCustomOrdering_(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - public FetchType getDefaultFetch() { - return MultiRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - public JavaJoinTable getJoinTable() { - return this.joinTable; - } - - public boolean isJoinTableSpecified() { - return getJoinTable().isSpecified(); - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - public String getMapKey() { - return this.mapKey; - } - - public void setMapKey(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - if (oldMapKey != newMapKey) { - if (this.getMapKeyResource(getResourcePersistentAttribute()) != null) { - if (newMapKey != null) { - this.getMapKeyResource(getResourcePersistentAttribute()).setName(newMapKey); - } - else { - getResourcePersistentAttribute().removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - } - else if (newMapKey != null) { - getResourcePersistentAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getMapKeyResource(getResourcePersistentAttribute()).setName(newMapKey); - } - } - firePropertyChanged(MultiRelationshipMapping.MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - - protected void setMapKey_(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - firePropertyChanged(MultiRelationshipMapping.MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - -//TODO default orderBy - this wasn't supported in 1.0 either -// public void refreshDefaults(DefaultsContext defaultsContext) { -// super.refreshDefaults(defaultsContext); -// // if (isOrderByPk()) { -// // refreshDefaultOrderBy(defaultsContext); -// // } -// } -// -// //primary key ordering when just the @OrderBy annotation is present -// protected void refreshDefaultOrderBy(DefaultsContext defaultsContext) { -// IEntity targetEntity = getResolvedTargetEntity(); -// if (targetEntity != null) { -// setOrderBy(targetEntity.primaryKeyAttributeName() + " ASC"); -// } -// } - - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (!resourcePersistentAttribute.typeIsContainer()) { - return null; - } - return resourcePersistentAttribute.getQualifiedReferenceEntityElementTypeName(); - } - - protected abstract boolean mappedByTouches(int pos, CompilationUnit astRoot); - - protected boolean mapKeyNameTouches(int pos, CompilationUnit astRoot) { - if (getMapKeyResource(getResourcePersistentAttribute()) != null) { - return getMapKeyResource(getResourcePersistentAttribute()).nameTouches(pos, astRoot); - } - return false; - } - - protected MapKeyAnnotation getMapKeyResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (MapKeyAnnotation) resourcePersistentAttribute.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - - public Iterator<String> candidateMapKeyNames() { - return this.allTargetEntityAttributeNames(); - } - - protected Iterator<String> candidateMapKeyNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateMapKeyNames(), filter); - } - - protected Iterator<String> quotedCandidateMapKeyNames(Filter<String> filter) { - return StringTools.quote(this.candidateMapKeyNames(filter)); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getJoinTable().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.mappedByTouches(pos, astRoot)) { - return this.quotedCandidateMappedByAttributeNames(filter); - } - if (this.mapKeyNameTouches(pos, astRoot)) { - return this.quotedCandidateMapKeyNames(filter); - } - return null; - } - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initialize(resourcePersistentAttribute); - MapKeyAnnotation mapKey = this.getMapKeyResource(resourcePersistentAttribute); - if (mapKey != null) { - this.mapKey = mapKey.getName(); - } - this.initializeOrderBy(this.getOrderByResource()); - this.joinTable.initialize(resourcePersistentAttribute); - } - - @Override - protected void initialize(T relationshipMapping) { - super.initialize(relationshipMapping); - this.mappedBy = this.mappedBy(relationshipMapping); - } - - protected void initializeOrderBy(OrderByAnnotation orderBy) { - if (orderBy != null) { - this.orderBy = orderBy.getValue(); - if (orderBy.getValue() == null) { - this.isPkOrdering = true; - } - else { - this.isCustomOrdering = true; - } - } - else { - this.isNoOrdering = true; - } - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.updateMapKey(resourcePersistentAttribute); - this.updateOrderBy(this.getOrderByResource()); - this.joinTable.update(resourcePersistentAttribute); - } - - @Override - protected void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setMappedBy_(this.mappedBy(relationshipMapping)); - } - - protected void updateMapKey(JavaResourcePersistentAttribute resourcePersistentAttribute) { - MapKeyAnnotation mapKey = this.getMapKeyResource(resourcePersistentAttribute); - if (mapKey != null) { - setMapKey_(mapKey.getName()); - } - else { - setMapKey_(null); - } - } - - protected void updateOrderBy(OrderByAnnotation orderBy) { - if (orderBy != null) { - setOrderBy_(orderBy.getValue()); - if (orderBy.getValue() == null) { - setPkOrdering_(true); - setCustomOrdering_(false); - setNoOrdering_(false); - } - else { - setPkOrdering_(false); - setCustomOrdering_(true); - setNoOrdering_(false); - } - } - else { - setOrderBy_(null); - setPkOrdering_(false); - setCustomOrdering_(false); - setNoOrdering_(true); - } - } - protected abstract String mappedBy(T relationshipMapping); - - //******** Validation *********************************** - - public abstract TextRange getMappedByTextRange(CompilationUnit astRoot); - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (entityOwned() && (this.isJoinTableSpecified() || isRelationshipOwner())) { - getJoinTable().addToMessages(messages, astRoot); - } - if (this.getMappedBy() != null) { - addMappedByMessages(messages, astRoot); - } - } - - protected void addMappedByMessages(List<IMessage> messages, CompilationUnit astRoot) { - String mappedBy = this.getMappedBy(); - - if (this.isJoinTableSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_WITH_JOIN_TABLE, - this.getJoinTable(), - this.getJoinTable().getValidationTextRange(astRoot)) - ); - - } - - Entity targetEntity = this.getResolvedTargetEntity(); - - if (targetEntity == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {mappedBy}, - this, - this.getMappedByTextRange(astRoot)) - ); - return; - } - - if (! this.mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {mappedBy}, - this, - this.getMappedByTextRange(astRoot)) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, - this.getMappedByTextRange(astRoot)) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java deleted file mode 100644 index 46095b421d..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, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedColumn; -import org.eclipse.jpt.core.resource.java.NamedColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public abstract class AbstractJavaNamedColumn<T extends NamedColumnAnnotation> extends AbstractJavaJpaContextNode - implements JavaNamedColumn -{ - - protected Owner owner; - - protected String specifiedName; - - protected String defaultName; - - protected String columnDefinition; - - protected AbstractJavaNamedColumn(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - // ******************* initialization from java resource model ******************** - - protected void initialize(T column) { - this.specifiedName = column.getName(); - this.defaultName = this.defaultName(); - this.columnDefinition = column.getColumnDefinition(); - } - - - protected abstract T getColumnResource(); - - - //************** INamedColumn implementation ***************** - public String getName() { - return (this.getSpecifiedName() == null) ? getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - getColumnResource().setName(newSpecifiedName); - firePropertyChanged(NamedColumn.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(NamedColumn.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(NamedColumn.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public String getColumnDefinition() { - return this.columnDefinition; - } - - public void setColumnDefinition(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - getColumnResource().setColumnDefinition(newColumnDefinition); - firePropertyChanged(NamedColumn.COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setColumnDefinition_(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - firePropertyChanged(NamedColumn.COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - public Owner getOwner() { - return this.owner; - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getColumnResource().getNameTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.getColumnResource().nameTouches(pos, astRoot); - } - - public Column getDbColumn() { - Table table = this.getDbTable(); - return (table == null) ? null : table.getColumnNamed(this.getName()); - } - - public Table getDbTable() { - return getOwner().getDbTable(this.getTableName()); - } - - /** - * Return the name of the column's table. - */ - protected abstract String getTableName(); - - public boolean isResolved() { - return this.getDbColumn() != null; - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.nameTouches(pos, astRoot)) { - return this.quotedCandidateNames(filter); - } - return null; - } - - private Iterator<String> candidateNames() { - Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.columnNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - private Iterator<String> quotedCandidateNames(Filter<String> filter) { - return StringTools.quote(this.candidateNames(filter)); - } - - @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.defaultName()); - this.setColumnDefinition_(column.getColumnDefinition()); - } - - /** - * Return the default column name. - */ - protected String defaultName() { - return this.getOwner().getDefaultColumnName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java deleted file mode 100644 index ac1a358755..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.OverrideAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public abstract class AbstractJavaOverride extends AbstractJavaJpaContextNode implements BaseOverride -{ - - protected String name; - - protected final Owner owner; - - protected OverrideAnnotation overrideResource; - - public AbstractJavaOverride(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - protected void initialize(OverrideAnnotation overrideResource) { - this.overrideResource = overrideResource; - this.name = this.name(overrideResource); - } - - protected OverrideAnnotation getOverrideResource() { - return this.overrideResource; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.overrideResource.setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - protected void update(OverrideAnnotation overrideResource) { - this.overrideResource = overrideResource; - this.setName_(this.name(overrideResource)); - } - - protected String name(OverrideAnnotation overrideResource) { - return overrideResource.getName(); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public BaseOverride setVirtual(boolean virtual) { - return getOwner().setVirtual(virtual, this); - } - - public Owner getOwner() { - return this.owner; - } - - @Override - public JavaJpaContextNode getParent() { - return (JavaJpaContextNode) super.getParent(); - } - - protected abstract Iterator<String> candidateNames(); - - private Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - private Iterator<String> quotedCandidateNames(Filter<String> filter) { - return StringTools.quote(this.candidateNames(filter)); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.nameTouches(pos, astRoot)) { - return this.quotedCandidateNames(filter); - } - return null; - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.overrideResource.nameTouches(pos, astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.overrideResource.getTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaQuery.java deleted file mode 100644 index b085911b99..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaQuery.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaQueryHint; -import org.eclipse.jpt.core.resource.java.QueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - - -public abstract class AbstractJavaQuery extends AbstractJavaJpaContextNode - implements JavaQuery -{ - protected String name; - - protected String query; - - protected final List<JavaQueryHint> hints; - - protected QueryAnnotation queryAnnotation; - - protected AbstractJavaQuery(JavaJpaContextNode parent) { - super(parent); - this.hints = new ArrayList<JavaQueryHint>(); - } - - protected QueryAnnotation getQueryResource() { - return this.queryAnnotation; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.queryAnnotation.setName(newName); - firePropertyChanged(Query.NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(Query.NAME_PROPERTY, oldName, newName); - } - - public String getQuery() { - return this.query; - } - - public void setQuery(String newQuery) { - String oldQuery = this.query; - this.query = newQuery; - this.queryAnnotation.setQuery(newQuery); - firePropertyChanged(Query.QUERY_PROPERTY, oldQuery, newQuery); - } - - protected void setQuery_(String newQuery) { - String oldQuery = this.query; - this.query = newQuery; - firePropertyChanged(Query.QUERY_PROPERTY, oldQuery, newQuery); - } - - public ListIterator<JavaQueryHint> hints() { - return new CloneListIterator<JavaQueryHint>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public JavaQueryHint addHint(int index) { - JavaQueryHint hint = getJpaFactory().buildJavaQueryHint(this); - this.hints.add(index, hint); - this.getQueryResource().addHint(index); - this.fireItemAdded(Query.HINTS_LIST, index, hint); - return hint; - } - - protected void addHint(int index, JavaQueryHint hint) { - addItemToList(index, hint, this.hints, Query.HINTS_LIST); - } - - public void removeHint(QueryHint queryHint) { - removeHint(this.hints.indexOf(queryHint)); - } - - public void removeHint(int index) { - JavaQueryHint removedHint = this.hints.remove(index); - this.getQueryResource().removeHint(index); - fireItemRemoved(Query.HINTS_LIST, index, removedHint); - } - - protected void removeHint_(JavaQueryHint hint) { - removeItemFromList(hint, this.hints, Query.HINTS_LIST); - } - - public void moveHint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.hints, targetIndex, sourceIndex); - this.getQueryResource().moveHint(targetIndex, sourceIndex); - fireItemMoved(Query.HINTS_LIST, targetIndex, sourceIndex); - } - - protected void initialize(QueryAnnotation queryAnnotation) { - this.queryAnnotation = queryAnnotation; - this.name = queryAnnotation.getName(); - this.query = queryAnnotation.getQuery(); - this.initializeQueryHints(queryAnnotation); - } - - protected void update(QueryAnnotation queryAnnotation) { - this.queryAnnotation = queryAnnotation; - this.setName_(queryAnnotation.getName()); - this.setQuery_(queryAnnotation.getQuery()); - this.updateQueryHints(queryAnnotation); - } - - protected void initializeQueryHints(QueryAnnotation queryResource) { - ListIterator<QueryHintAnnotation> annotations = queryResource.hints(); - - while(annotations.hasNext()) { - this.hints.add(createQueryHint(annotations.next())); - } - } - - protected void updateQueryHints(QueryAnnotation queryResource) { - ListIterator<JavaQueryHint> hints = hints(); - ListIterator<QueryHintAnnotation> resourceHints = queryResource.hints(); - - while (hints.hasNext()) { - JavaQueryHint hint = hints.next(); - if (resourceHints.hasNext()) { - hint.update(resourceHints.next()); - } - else { - removeHint_(hint); - } - } - - while (resourceHints.hasNext()) { - addHint(hintsSize(), createQueryHint(resourceHints.next())); - } - } - - protected JavaQueryHint createQueryHint(QueryHintAnnotation hintResource) { - JavaQueryHint queryHint = getJpaFactory().buildJavaQueryHint(this); - queryHint.initialize(hintResource); - return queryHint; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.queryAnnotation.getTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.queryAnnotation.getNameTextRange(astRoot); - } - - public boolean overrides(Query query) { - // java is at the base of the tree - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipMapping.java deleted file mode 100644 index e3746cc254..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipMapping.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public abstract class AbstractJavaRelationshipMapping<T extends RelationshipMappingAnnotation> extends AbstractJavaAttributeMapping<T> - implements JavaRelationshipMapping -{ - - protected String specifiedTargetEntity; - - protected String defaultTargetEntity; - - protected Entity resolvedTargetEntity; - - protected final JavaCascade cascade; - - protected FetchType specifiedFetch; - - protected AbstractJavaRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.cascade = new JavaCascade(this); - } - - public String getTargetEntity() { - return (this.getSpecifiedTargetEntity() == null) ? getDefaultTargetEntity() : this.getSpecifiedTargetEntity(); - } - - public String getSpecifiedTargetEntity() { - return this.specifiedTargetEntity; - } - - public void setSpecifiedTargetEntity(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - this.getMappingResource().setTargetEntity(newSpecifiedTargetEntity); - firePropertyChanged(RelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - protected void setSpecifiedTargetEntity_(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - firePropertyChanged(RelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - public String getDefaultTargetEntity() { - return this.defaultTargetEntity; - } - - protected void setDefaultTargetEntity(String newDefaultTargetEntity) { - String oldDefaultTargetEntity = this.defaultTargetEntity; - this.defaultTargetEntity = newDefaultTargetEntity; - firePropertyChanged(RelationshipMapping.DEFAULT_TARGET_ENTITY_PROPERTY, oldDefaultTargetEntity, newDefaultTargetEntity); - } - - public Entity getResolvedTargetEntity() { - return this.resolvedTargetEntity; - } - - protected void setResolvedTargetEntity(Entity newResolvedTargetEntity) { - Entity oldResolvedTargetEntity = this.resolvedTargetEntity; - this.resolvedTargetEntity = newResolvedTargetEntity; - firePropertyChanged(RelationshipMapping.RESOLVED_TARGET_ENTITY_PROPERTY, oldResolvedTargetEntity, newResolvedTargetEntity); - } - - public JavaCascade getCascade() { - return this.cascade; - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.getMappingResource().setFetch(FetchType.toJavaResourceModel(newSpecifiedFetch)); - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.defaultTargetEntity = this.defaultTargetEntity(resourcePersistentAttribute); - super.initialize(resourcePersistentAttribute); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.setDefaultTargetEntity(this.defaultTargetEntity(resourcePersistentAttribute)); - super.update(resourcePersistentAttribute); - } - - @Override - protected void initialize(T relationshipMapping) { - this.specifiedFetch = this.fetch(relationshipMapping); - this.cascade.initialize(relationshipMapping); - this.specifiedTargetEntity = this.specifiedTargetEntity(relationshipMapping); - this.resolvedTargetEntity = this.resolveTargetEntity(relationshipMapping); - } - - @Override - protected void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setSpecifiedFetch_(this.fetch(relationshipMapping)); - this.cascade.update(relationshipMapping); - this.setSpecifiedTargetEntity_(this.specifiedTargetEntity(relationshipMapping)); - this.setResolvedTargetEntity(this.resolveTargetEntity(relationshipMapping)); - } - - protected FetchType fetch(T relationshipMapping) { - return FetchType.fromJavaResourceModel(relationshipMapping.getFetch()); - } - - protected String specifiedTargetEntity(T relationshipMapping) { - return relationshipMapping.getTargetEntity(); - } - - protected abstract String defaultTargetEntity(JavaResourcePersistentAttribute resourcePersistentAttribute); - - protected Entity resolveTargetEntity(T relationshipMapping) { - String qualifiedTargetEntity = getDefaultTargetEntity(); - if (getSpecifiedTargetEntity() != null) { - qualifiedTargetEntity = relationshipMapping.getFullyQualifiedTargetEntity(); - } - if (qualifiedTargetEntity == null) { - return null; - } - PersistentType persistentType = getPersistenceUnit().getPersistentType(qualifiedTargetEntity); - if (persistentType != null && persistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (Entity) persistentType.getMapping(); - } - return null; - } - - public Entity getEntity() { - if (getTypeMapping() instanceof Entity) { - return (Entity) getTypeMapping(); - } - return null; - } - - public Iterator<String> allTargetEntityAttributeNames() { - Entity targetEntity = this.getResolvedTargetEntity(); - return (targetEntity == null) ? EmptyIterator.<String> instance() : targetEntity.getPersistentType().allAttributeNames(); - } - - public Iterator<String> candidateMappedByAttributeNames() { - return this.allTargetEntityAttributeNames(); - } - - protected Iterator<String> candidateMappedByAttributeNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateMappedByAttributeNames(), filter); - } - - protected Iterator<String> quotedCandidateMappedByAttributeNames(Filter<String> filter) { - return StringTools.quote(this.candidateMappedByAttributeNames(filter)); - } - -} 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 17d97c0a99..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java +++ /dev/null @@ -1,433 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.SingleRelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaSingleRelationshipMapping; -import org.eclipse.jpt.core.internal.resource.java.NullJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractJavaSingleRelationshipMapping<T extends RelationshipMappingAnnotation> - extends AbstractJavaRelationshipMapping<T> implements JavaSingleRelationshipMapping -{ - - protected final List<JavaJoinColumn> specifiedJoinColumns; - - protected JavaJoinColumn defaultJoinColumn; - - protected Boolean specifiedOptional; - - protected AbstractJavaSingleRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<JavaJoinColumn>(); - } - - public FetchType getDefaultFetch() { - return SingleRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - //***************** ISingleRelationshipMapping implementation ***************** - public ListIterator<JavaJoinColumn> joinColumns() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public JavaJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(JavaJoinColumn newJoinColumn) { - JavaJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - protected ListIterator<JavaJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<JavaJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - JavaJoinColumn oldDefaultJoinColumn = this.getDefaultJoinColumn(); - if (oldDefaultJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultJoinColumn = null; - } - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - JoinColumnAnnotation joinColumnResource = (JoinColumnAnnotation) getResourcePersistentAttribute().addAnnotation(index, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumn.initialize(joinColumnResource); - this.fireItemAdded(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldDefaultJoinColumn, null); - } - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = buildJoinColumn(new NullJoinColumn(getResourcePersistentAttribute())); - } - getResourcePersistentAttribute().removeAnnotation(index, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - fireItemRemoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - getResourcePersistentAttribute().move(targetIndex, sourceIndex, JoinColumnsAnnotation.ANNOTATION_NAME); - fireItemMoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public Boolean getOptional() { - return getSpecifiedOptional() == null ? getDefaultOptional() : getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - setOptionalOnResourceModel(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - protected abstract void setOptionalOnResourceModel(Boolean newOptional); - - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initialize(resourcePersistentAttribute); - this.initializeSpecifiedJoinColumns(resourcePersistentAttribute); - this.initializeDefaultJoinColumn(resourcePersistentAttribute); - } - - @Override - protected void initialize(T relationshipMapping) { - super.initialize(relationshipMapping); - this.specifiedOptional = this.specifiedOptional(relationshipMapping); - } - - protected void initializeSpecifiedJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaResourceNode> annotations = resourcePersistentAttribute.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedJoinColumns.add(buildJoinColumn((JoinColumnAnnotation) annotations.next())); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns() && isRelationshipOwner(); - } - - protected void initializeDefaultJoinColumn(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(new NullJoinColumn(resourcePersistentAttribute)); - } - - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.updateSpecifiedJoinColumns(resourcePersistentAttribute); - this.updateDefaultJoinColumn(resourcePersistentAttribute); - } - - @Override - protected void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setSpecifiedOptional_(this.specifiedOptional(relationshipMapping)); - } - - protected abstract Boolean specifiedOptional(T relationshipMapping); - - - protected void updateSpecifiedJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<JavaResourceNode> resourceJoinColumns = resourcePersistentAttribute.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update((JoinColumnAnnotation) resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn((JoinColumnAnnotation) resourceJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(new NullJoinColumn(resourcePersistentAttribute))); - } - else { - this.defaultJoinColumn.update(new NullJoinColumn(resourcePersistentAttribute)); - } - } - - protected JavaJoinColumn buildJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - joinColumn.initialize(joinColumnResource); - return joinColumn; - } - - protected JavaJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - /** - * eliminate any "container" types - */ - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (resourcePersistentAttribute.typeIsContainer()) { - return null; - } - return resourcePersistentAttribute.getQualifiedReferenceEntityTypeName(); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaJoinColumn column : CollectionTools.iterable(this.joinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - //************* Validation ********************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (addJoinColumnMessages()) { - addJoinColumnMessages(messages, astRoot); - } - } - - //bug 192287 - do not want joinColumn validation errors on the non-owning side - //of a bidirectional relationship. This is a low risk fix for RC3, but a better - //solution would be to not have the default joinColumns on the non-owning side. - //This would fix another bug that we show default joinColumns in this situation. - protected boolean addJoinColumnMessages() { - return (entityOwned() && isRelationshipOwner()); - } - - protected void addJoinColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - - for (Iterator<JavaJoinColumn> stream = this.joinColumns(); stream.hasNext();) { - JavaJoinColumn joinColumn = stream.next(); - String table = joinColumn.getTable(); - boolean doContinue = joinColumn.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {table, joinColumn.getName()}, - joinColumn, joinColumn.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! joinColumn.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, joinColumn.getNameTextRange(astRoot)) - ); - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - } - - - public class JoinColumnOwner implements JavaJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return AbstractJavaSingleRelationshipMapping.this.getTypeMapping().getTableName(); - } - - public Entity getTargetEntity() { - return AbstractJavaSingleRelationshipMapping.this.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return AbstractJavaSingleRelationshipMapping.this.getPersistentAttribute().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return AbstractJavaSingleRelationshipMapping.this; - } - - public boolean tableNameIsInvalid(String tableName) { - return AbstractJavaSingleRelationshipMapping.this.getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TypeMapping getTypeMapping() { - return AbstractJavaSingleRelationshipMapping.this.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractJavaSingleRelationshipMapping.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return AbstractJavaSingleRelationshipMapping.this.getValidationTextRange(astRoot); - } - - public int joinColumnsSize() { - return AbstractJavaSingleRelationshipMapping.this.joinColumnsSize(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java deleted file mode 100644 index 034ac2d7ee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public abstract class AbstractJavaTable extends AbstractJavaJpaContextNode implements UniqueConstraint.Owner -{ - - protected String specifiedName; - protected String defaultName; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - protected final List<JavaUniqueConstraint> uniqueConstraints; - - - protected AbstractJavaTable(JavaJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<JavaUniqueConstraint>(); - } - - @Override - public JavaJpaContextNode getParent() { - return (JavaJpaContextNode) super.getParent(); - } - - /** - * Return the java table resource, do not return null if the java annotation does not exist. - * Use a null resource object instead of null. - */ - protected abstract TableAnnotation getTableResource(); - - /** - * Return the fully qualified annotation name of the java table resource - */ - protected abstract String getAnnotationName(); - - public String getName() { - return (this.getSpecifiedName() == null) ? getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - getTableResource().setName(newSpecifiedName); - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - getTableResource().setCatalog(newSpecifiedCatalog); - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - getTableResource().setSchema(newSpecifiedSchema); - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - - // ********** unique constraints ********** - - public ListIterator<JavaUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<JavaUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public JavaUniqueConstraint addUniqueConstraint(int index) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - this.uniqueConstraints.add(index, uniqueConstraint); - UniqueConstraintAnnotation uniqueConstraintAnnotation = this.getTableResource().addUniqueConstraint(index); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - fireItemAdded(Table.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - JavaUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - this.getTableResource().removeUniqueConstraint(index); - fireItemRemoved(Table.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getTableResource().moveUniqueConstraint(targetIndex, sourceIndex); - fireItemMoved(Table.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void addUniqueConstraint(int index, JavaUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - protected void removeUniqueConstraint_(JavaUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - - // ********** Table implementation ********** - - public TextRange getNameTextRange(CompilationUnit astRoot) { - TextRange textRange = getTableResource().getNameTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return getTableResource().nameTouches(pos, astRoot); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - TextRange textRange = getTableResource().getSchemaTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return getTableResource().schemaTouches(pos, astRoot); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return getTableResource().getCatalogTextRange(astRoot); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return getTableResource().catalogTouches(pos, astRoot); - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(Table.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(Table.DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(Table.DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - - - protected void initialize(TableAnnotation table) { - this.defaultName = this.defaultName(); - this.defaultSchema = this.defaultSchema(); - this.defaultCatalog = this.defaultCatalog(); - this.specifiedName = table.getName(); - this.specifiedSchema = table.getSchema(); - this.specifiedCatalog = table.getCatalog(); - this.initializeUniqueConstraints(table); - } - - protected void initializeUniqueConstraints(TableAnnotation table) { - for (UniqueConstraintAnnotation uniqueConstraintAnnotation : CollectionTools.iterable(table.uniqueConstraints())) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraintAnnotation)); - } - } - - protected void update(TableAnnotation table) { - this.setSpecifiedName_(table.getName()); - this.setSpecifiedSchema_(table.getSchema()); - this.setSpecifiedCatalog_(table.getCatalog()); - this.setDefaultName(this.defaultName()); - this.setDefaultSchema(this.defaultSchema()); - this.setDefaultCatalog(this.defaultCatalog()); - this.updateUniqueConstraints(table); - } - - protected abstract String defaultName(); - - protected String defaultSchema() { - if (getEntityMappings() != null) { - return getEntityMappings().getSchema(); - } - return getPersistenceUnit().getDefaultSchema(); - } - - protected String defaultCatalog() { - if (getEntityMappings() != null) { - return getEntityMappings().getCatalog(); - } - return getPersistenceUnit().getDefaultCatalog(); - } - - protected void updateUniqueConstraints(TableAnnotation table) { - ListIterator<JavaUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<UniqueConstraintAnnotation> resourceUniqueConstraints = table.uniqueConstraints(); - - while (uniqueConstraints.hasNext()) { - JavaUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected JavaUniqueConstraint buildUniqueConstraint(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - return uniqueConstraint; - } - - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getTableResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - public org.eclipse.jpt.db.Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.getTableNamed(this.getName()); - } - - public Schema getDbSchema() { - return this.getDataSource().getSchemaNamed(this.getSchema()); - } - - public boolean hasResolvedSchema() { - return this.getDbSchema() != null; - } - - public boolean isResolved() { - return this.getDbTable() != null; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaUniqueConstraint constraint : CollectionTools.iterable(this.uniqueConstraints())) { - result = constraint.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - /** - * called if the database is connected - * name, schema, catalog - */ - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.nameTouches(pos, astRoot)) { - return this.quotedCandidateNames(filter); - } - if (this.schemaTouches(pos, astRoot)) { - return this.quotedCandidateSchemas(filter); - } - if (this.catalogTouches(pos, astRoot)) { - return this.quotedCandidateCatalogs(filter); - } - return null; - } - - private Iterator<String> candidateNames() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema != null) ? dbSchema.tableNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - private Iterator<String> quotedCandidateNames(Filter<String> filter) { - return StringTools.quote(this.candidateNames(filter)); - } - - private Iterator<String> candidateSchemas() { - return this.getDataSource().schemaNames(); - } - - private Iterator<String> candidateSchemas(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateSchemas(), filter); - } - - private Iterator<String> quotedCandidateSchemas(Filter<String> filter) { - return StringTools.quote(this.candidateSchemas(filter)); - } - - private Iterator<String> candidateCatalogs() { - return this.getDataSource().catalogNames(); - } - - private Iterator<String> candidateCatalogs(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateCatalogs(), filter); - } - - private Iterator<String> quotedCandidateCatalogs(Filter<String> filter) { - return StringTools.quote(this.candidateCatalogs(filter)); - } - - public String getQualifiedName() { - return NameTools.buildQualifiedDatabaseObjectName(this.getCatalog(), this.getSchema(), this.getName()); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getQualifiedName()); - } - - @Override - public String displayString() { - return getQualifiedName(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java deleted file mode 100644 index b53ffc6144..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public abstract class AbstractJavaTypeMapping extends AbstractJavaJpaContextNode - implements JavaTypeMapping -{ - protected JavaResourcePersistentType javaResourcePersistentType; - - - protected AbstractJavaTypeMapping(JavaPersistentType parent) { - super(parent); - } - - protected JavaResourceNode getMappingResource() { - return this.javaResourcePersistentType.getMappingAnnotation(getAnnotationName()); - } - - //***************** ITypeMapping implementation ***************** - - public JavaPersistentType getPersistentType() { - return (JavaPersistentType) getParent(); - } - - public String getTableName() { - return null; - } - - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return null; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return null; - } - - public Schema getDbSchema() { - return null; - } - - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return true; - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<JavaPersistentAttribute> overridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<JavaPersistentAttribute> overridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAssociationNames() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAssociationNames() { - return EmptyIterator.instance(); - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - //******************** updatating ********************* - public void initialize(JavaResourcePersistentType javaResourcePersistentType) { - this.javaResourcePersistentType = javaResourcePersistentType; - } - - public void update(JavaResourcePersistentType javaResourcePersistentType) { - this.javaResourcePersistentType = javaResourcePersistentType; - } - - //******************** validation ********************* - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getMappingResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getPersistentType().getValidationTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAssociationOverride.java deleted file mode 100644 index 860a517991..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAssociationOverride.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaAssociationOverride extends AbstractJavaOverride - implements JavaAssociationOverride -{ - - protected final List<JavaJoinColumn> specifiedJoinColumns; - - protected final List<JavaJoinColumn> defaultJoinColumns; - - - public GenericJavaAssociationOverride(JavaJpaContextNode parent, AssociationOverride.Owner owner) { - super(parent, owner); - this.specifiedJoinColumns = new ArrayList<JavaJoinColumn>(); - this.defaultJoinColumns = new ArrayList<JavaJoinColumn>(); - } - - @Override - public JavaAssociationOverride setVirtual(boolean virtual) { - return (JavaAssociationOverride) super.setVirtual(virtual); - } - - @Override - protected AssociationOverrideAnnotation getOverrideResource() { - return (AssociationOverrideAnnotation) super.getOverrideResource(); - } - - @Override - public AssociationOverride.Owner getOwner() { - return (AssociationOverride.Owner) super.getOwner(); - } - - public ListIterator<JavaJoinColumn> joinColumns() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumns() : this.specifiedJoinColumns(); - } - - public int joinColumnsSize() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumnsSize() : this.specifiedJoinColumnsSize(); - } - - public ListIterator<JavaJoinColumn> defaultJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.defaultJoinColumns); - } - - public int defaultJoinColumnsSize() { - return this.defaultJoinColumns.size(); - } - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - JoinColumnAnnotation joinColumnResource = getOverrideResource().addJoinColumn(index); - joinColumn.initialize(joinColumnResource); - this.fireItemAdded(AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected JavaJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - getOverrideResource().removeJoinColumn(index); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedJoinColumn); - } - - protected void removeSpecifiedJoinColumn(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - getOverrideResource().moveJoinColumn(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - - @Override - protected Iterator<String> candidateNames() { - return this.getOwner().getTypeMapping().allOverridableAssociationNames(); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaJoinColumn column : CollectionTools.iterable(this.joinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - public void initialize(AssociationOverrideAnnotation associationOverride) { - super.initialize(associationOverride); - this.name = associationOverride.getName(); - initializeSpecifiedJoinColumns(associationOverride); - } - - protected void initializeSpecifiedJoinColumns(AssociationOverrideAnnotation associationOverride) { - ListIterator<JoinColumnAnnotation> annotations = associationOverride.joinColumns(); - - while(annotations.hasNext()) { - this.specifiedJoinColumns.add(createJoinColumn(annotations.next())); - } - } - - public void update(AssociationOverrideAnnotation associationOverride) { - super.update(associationOverride); - updateSpecifiedJoinColumns(associationOverride); - } - - protected void updateSpecifiedJoinColumns(AssociationOverrideAnnotation associationOverride) { - ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<JoinColumnAnnotation> resourceJoinColumns = associationOverride.joinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), createJoinColumn(resourceJoinColumns.next())); - } - } - - - protected JavaJoinColumn createJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - joinColumn.initialize(joinColumnResource); - return joinColumn; - } - - - //******************** validation ******************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addJoinColumnMessages(messages, astRoot); - } - - protected void addJoinColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - for (JavaJoinColumn joinColumn : CollectionTools.iterable(joinColumns())) { - String table = joinColumn.getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getOwner().getTypeMapping().tableNameIsInvalid(table)) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot)) - ); - } - doContinue = false; - } - - if (doContinue && ! joinColumn.isResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange(astRoot)) - ); - } - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - } - } - public class JoinColumnOwner implements JavaJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return GenericJavaAssociationOverride.this.owner.getTypeMapping().getTableName(); - } - - public String getDefaultColumnName() { - return null; - } - - public Entity getTargetEntity() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericJavaAssociationOverride.this.getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericJavaAssociationOverride.this.getOwner().getRelationshipMapping(GenericJavaAssociationOverride.this.getName()); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - - public TypeMapping getTypeMapping() { - return GenericJavaAssociationOverride.this.owner.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaAssociationOverride.this.defaultJoinColumns.contains(joinColumn); - } - - public int joinColumnsSize() { - return GenericJavaAssociationOverride.this.joinColumnsSize(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAttributeOverride.java deleted file mode 100644 index 102eb8cdd5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAttributeOverride.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaAttributeOverride extends AbstractJavaOverride - implements JavaAttributeOverride -{ - - protected final JavaColumn column; - - - public GenericJavaAttributeOverride(JavaJpaContextNode parent, AttributeOverride.Owner owner) { - super(parent, owner); - this.column = getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public JavaAttributeOverride setVirtual(boolean virtual) { - return (JavaAttributeOverride) super.setVirtual(virtual); - } - - @Override - protected AttributeOverrideAnnotation getOverrideResource() { - return (AttributeOverrideAnnotation) super.getOverrideResource(); - } - - @Override - public AttributeOverride.Owner getOwner() { - return (AttributeOverride.Owner) super.getOwner(); - } - - public ColumnAnnotation getColumnResource() { - return this.getOverrideResource().getNonNullColumn(); - } - - public String getDefaultColumnName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - return columnMapping.getColumn().getName(); - } - - public String getDefaultTableName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - String tableName = columnMapping.getColumn().getSpecifiedTable(); - if (tableName != null) { - return tableName; - } - return getOwner().getTypeMapping().getTableName(); - } - - protected ColumnMapping getColumnMapping() { - return getOwner().getColumnMapping(getName()); - } - - //************* IColumn.Owner implementation ************** - public TypeMapping getTypeMapping() { - return this.getOwner().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return this.getTypeMapping().getDbTable(tableName); - } - - //************* IAttributeOverride implementation ************** - - public JavaColumn getColumn() { - return this.column; - } - - //************* JavaOverride implementation ************** - - @Override - protected Iterator<String> candidateNames() { - return this.getOwner().getTypeMapping().allOverridableAttributeNames(); - } - - //************* java resource model -> java context model ************** - public void initialize(AttributeOverrideAnnotation attributeOverrideResource) { - super.initialize(attributeOverrideResource); - this.column.initialize(this.getColumnResource()); - } - - public void update(AttributeOverrideAnnotation attributeOverrideResource) { - super.update(attributeOverrideResource); - this.column.update(this.getColumnResource()); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - - //******************** validation ********************** - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addColumnMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - String table = getColumn().getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, getColumn().getName()}, - getColumn(), - getColumn().getTableTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, getColumn().getName()}, - getColumn(), - getColumn().getTableTextRange(astRoot)) - ); - } - doContinue = false; - } - - if (doContinue && ! getColumn().isResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), getColumn().getName()}, - getColumn(), - getColumn().getNameTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {getColumn().getName()}, - getColumn(), - getColumn().getNameTextRange(astRoot)) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaBasicMapping.java deleted file mode 100644 index 3ef2daebe9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaBasicMapping.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.LobAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaBasicMapping extends AbstractJavaAttributeMapping<BasicAnnotation> implements JavaBasicMapping -{ - protected FetchType specifiedFetch; - - protected Boolean specifiedOptional; - - protected EnumType specifiedEnumerated; - - protected final JavaColumn column; - - protected boolean lob; - - protected TemporalType temporal; - - public GenericJavaBasicMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = createJavaColumn(); - } - - protected JavaColumn createJavaColumn() { - return getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initialize(resourcePersistentAttribute); - this.column.initialize(this.getColumnResource()); - this.specifiedEnumerated = this.specifiedEnumerated(this.getEnumeratedResource()); - this.lob = this.lob(resourcePersistentAttribute); - this.temporal = this.temporal(this.getTemporalResource()); - } - - @Override - protected void initialize(BasicAnnotation basicResource) { - this.specifiedFetch = this.specifiedFetchType(basicResource); - this.specifiedOptional = this.specifiedOptional(basicResource); - } - - protected EnumeratedAnnotation getEnumeratedResource() { - return (EnumeratedAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - } - - protected TemporalAnnotation getTemporalResource() { - return (TemporalAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(TemporalAnnotation.ANNOTATION_NAME); - } - - public ColumnAnnotation getColumnResource() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** IJavaAttributeMapping implementation *************** - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return BasicAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.COLUMN, - JPA.LOB, - JPA.TEMPORAL, - JPA.ENUMERATED); - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - //************** IBasicMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getDefaultFetch() { - return BasicMapping.DEFAULT_FETCH_TYPE; - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.getMappingResource().setFetch(FetchType.toJavaResourceModel(newSpecifiedFetch)); - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - public Boolean getOptional() { - return (this.getSpecifiedOptional() == null) ? this.getDefaultOptional() : this.getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - this.getMappingResource().setOptional(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - public boolean isLob() { - return this.lob; - } - - public void setLob(boolean newLob) { - boolean oldLob = this.lob; - this.lob = newLob; - if (newLob) { - if (lobResource(getResourcePersistentAttribute()) == null) { - getResourcePersistentAttribute().addAnnotation(LobAnnotation.ANNOTATION_NAME); - } - } - else { - if (lobResource(getResourcePersistentAttribute()) != null) { - getResourcePersistentAttribute().removeAnnotation(LobAnnotation.ANNOTATION_NAME); - } - } - firePropertyChanged(BasicMapping.LOB_PROPERTY, oldLob, newLob); - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getTemporalResource().setValue(TemporalType.toJavaResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public EnumType getEnumerated() { - return (this.getSpecifiedEnumerated() == null) ? this.getDefaultEnumerated() : this.getSpecifiedEnumerated(); - } - - public EnumType getDefaultEnumerated() { - return BasicMapping.DEFAULT_ENUMERATED; - } - - public EnumType getSpecifiedEnumerated() { - return this.specifiedEnumerated; - } - - public void setSpecifiedEnumerated(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - this.getEnumeratedResource().setValue(EnumType.toJavaResourceModel(newSpecifiedEnumerated)); - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedEnumerated_(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.column.update(this.getColumnResource()); - this.setSpecifiedEnumerated_(this.specifiedEnumerated(this.getEnumeratedResource())); - this.setLob(this.lob(resourcePersistentAttribute)); - this.setTemporal_(this.temporal(this.getTemporalResource())); - } - - @Override - protected void update(BasicAnnotation basicResource) { - this.setSpecifiedFetch_(this.specifiedFetchType(basicResource)); - this.setSpecifiedOptional_(this.specifiedOptional(basicResource)); - } - - protected FetchType specifiedFetchType(BasicAnnotation basic) { - return FetchType.fromJavaResourceModel(basic.getFetch()); - } - - protected Boolean specifiedOptional(BasicAnnotation basic) { - return basic.getOptional(); - } - - protected EnumType specifiedEnumerated(EnumeratedAnnotation enumerated) { - return EnumType.fromJavaResourceModel(enumerated.getValue()); - } - - protected boolean lob(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return lobResource(resourcePersistentAttribute) != null; - } - - protected LobAnnotation lobResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (LobAnnotation) resourcePersistentAttribute.getAnnotation(LobAnnotation.ANNOTATION_NAME); - } - - protected TemporalType temporal(TemporalAnnotation temporal) { - return TemporalType.fromJavaResourceModel(temporal.getValue()); - } - - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - // ************** Validation ************************************* - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages ,astRoot); - - addColumnMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaColumn column = this.getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && column.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, column.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, column.getNameTextRange(astRoot)) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaColumn.java deleted file mode 100644 index 1f86acf3d3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaColumn.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaColumn extends AbstractJavaBaseColumn<ColumnAnnotation> implements JavaColumn -{ - - protected Integer specifiedLength; - - protected Integer specifiedPrecision; - - protected Integer specifiedScale; - - public GenericJavaColumn(JavaJpaContextNode parent, JavaColumn.Owner owner) { - super(parent, owner); - } - - @Override - public void initialize(ColumnAnnotation column) { - super.initialize(column); - this.specifiedLength = this.specifiedLength(column); - this.specifiedPrecision = this.specifiedPrecision(column); - this.specifiedScale = this.specifiedScale(column); - } - - @Override - public JavaColumn.Owner getOwner() { - return (JavaColumn.Owner) super.getOwner(); - } - - @Override - protected ColumnAnnotation getColumnResource() { - return this.getOwner().getColumnResource(); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return Column.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - getColumnResource().setLength(newSpecifiedLength); - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - public Integer getPrecision() { - return (this.getSpecifiedPrecision() == null) ? getDefaultPrecision() : this.getSpecifiedPrecision(); - } - - public Integer getDefaultPrecision() { - return Column.DEFAULT_PRECISION; - } - - public Integer getSpecifiedPrecision() { - return this.specifiedPrecision; - } - - public void setSpecifiedPrecision(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - getColumnResource().setPrecision(newSpecifiedPrecision); - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - protected void setSpecifiedPrecision_(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - public Integer getScale() { - return (this.getSpecifiedScale() == null) ? getDefaultScale() : this.getSpecifiedScale(); - } - - public Integer getDefaultScale() { - return Column.DEFAULT_SCALE; - } - - public Integer getSpecifiedScale() { - return this.specifiedScale; - } - - public void setSpecifiedScale(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - getColumnResource().setScale(newSpecifiedScale); - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - protected void setSpecifiedScale_(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - @Override - public boolean tableIsAllowed() { - return true; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - @Override - public void update(ColumnAnnotation column) { - super.update(column); - this.setSpecifiedLength_(this.specifiedLength(column)); - this.setSpecifiedPrecision_(this.specifiedPrecision(column)); - this.setSpecifiedScale_(this.specifiedScale(column)); - } - - protected Integer specifiedLength(ColumnAnnotation column) { - return column.getLength(); - } - - protected Integer specifiedPrecision(ColumnAnnotation column) { - return column.getPrecision(); - } - - protected Integer specifiedScale(ColumnAnnotation column) { - return column.getScale(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaDiscriminatorColumn.java deleted file mode 100644 index fe8379f47c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaDiscriminatorColumn.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.java.JavaDiscriminatorColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaNamedColumn; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaDiscriminatorColumn extends AbstractJavaNamedColumn<DiscriminatorColumnAnnotation> - implements JavaDiscriminatorColumn -{ - - protected DiscriminatorType specifiedDiscriminatorType; - - protected Integer specifiedLength; - - protected JavaResourcePersistentMember persistenceResource; - - public GenericJavaDiscriminatorColumn(JavaEntity parent, JavaNamedColumn.Owner owner) { - super(parent, owner); - } - - public void initialize(JavaResourcePersistentMember persistentResource) { - this.persistenceResource = persistentResource; - this.initialize(this.getColumnResource()); - } - - @Override - public void initialize(DiscriminatorColumnAnnotation column) { - super.initialize(column); - this.specifiedDiscriminatorType = this.discriminatorType(column); - this.specifiedLength = this.length(column); - } - - protected JavaEntity getJavaEntity() { - return (JavaEntity) super.getParent(); - } - - @Override - protected DiscriminatorColumnAnnotation getColumnResource() { - return (DiscriminatorColumnAnnotation) this.persistenceResource.getNonNullAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME); - } - - public DiscriminatorType getDiscriminatorType() { - return (this.getSpecifiedDiscriminatorType() == null) ? this.getDefaultDiscriminatorType() : this.getSpecifiedDiscriminatorType(); - } - - public DiscriminatorType getDefaultDiscriminatorType() { - return DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE; - } - - public DiscriminatorType getSpecifiedDiscriminatorType() { - return this.specifiedDiscriminatorType; - } - - public void setSpecifiedDiscriminatorType(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - getColumnResource().setDiscriminatorType(DiscriminatorType.toJavaResourceModel(newSpecifiedDiscriminatorType)); - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedDiscriminatorType_(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? this.getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return DiscriminatorColumn.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - getColumnResource().setLength(newSpecifiedLength); - firePropertyChanged(DiscriminatorColumn.SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(DiscriminatorColumn.SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - @Override - protected String getTableName() { - return getJavaEntity().getTableName(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - - // ********** java annotations -> persistence model ********** - - public void update(JavaResourcePersistentMember persistentResource) { - this.persistenceResource = persistentResource; - this.update(this.getColumnResource()); - } - - @Override - public void update(DiscriminatorColumnAnnotation discriminatorColumn) { - super.update(discriminatorColumn); - this.setSpecifiedDiscriminatorType_(this.discriminatorType(discriminatorColumn)); - this.setSpecifiedLength_(this.length(discriminatorColumn)); - } - - protected DiscriminatorType discriminatorType(DiscriminatorColumnAnnotation discriminatorColumn) { - return DiscriminatorType.fromJavaResourceModel(discriminatorColumn.getDiscriminatorType()); - } - - protected Integer length(DiscriminatorColumnAnnotation discriminatorColumn) { - return discriminatorColumn.getLength(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddable.java deleted file mode 100644 index 21d2bcab97..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddable.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public class GenericJavaEmbeddable extends AbstractJavaTypeMapping implements JavaEmbeddable -{ - public GenericJavaEmbeddable(JavaPersistentType parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddableAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - public boolean isMapped() { - return true; - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return attributeMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY || attributeMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedIdMapping.java deleted file mode 100644 index 4ae4b5648f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedIdMapping.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; - - -public class GenericJavaEmbeddedIdMapping extends AbstractJavaBaseEmbeddedMapping<EmbeddedIdAnnotation> - implements JavaEmbeddedIdMapping -{ - - public GenericJavaEmbeddedIdMapping(JavaPersistentAttribute parent) { - super(parent); - } - - //****************** IJavaAttributeMapping implemenation ******************* - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedIdAnnotation.ANNOTATION_NAME; - } - - @Override - public boolean isIdMapping() { - return true; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedMapping.java deleted file mode 100644 index b0fe9c987b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedMapping.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; - - -public class GenericJavaEmbeddedMapping extends AbstractJavaBaseEmbeddedMapping<EmbeddedAnnotation> implements JavaEmbeddedMapping -{ - public GenericJavaEmbeddedMapping(JavaPersistentAttribute parent) { - super(parent); - } - - //****************** IJavaAttributeMapping implemenation ******************* - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedAnnotation.ANNOTATION_NAME; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEntity.java deleted file mode 100644 index 39a29946ca..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEntity.java +++ /dev/null @@ -1,1981 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHolder; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaDiscriminatorColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.java.JavaNamedColumn; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.internal.resource.java.NullAssociationOverride; -import org.eclipse.jpt.core.internal.resource.java.NullPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaEntity extends AbstractJavaTypeMapping implements JavaEntity -{ - protected EntityAnnotation entityResource; - - protected String specifiedName; - - protected String defaultName; - - protected final JavaTable table; - - protected final List<JavaSecondaryTable> specifiedSecondaryTables; - - protected final List<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected JavaPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - protected InheritanceType specifiedInheritanceStrategy; - - protected InheritanceType defaultInheritanceStrategy; - - protected String defaultDiscriminatorValue; - - protected boolean discriminatorValueAllowed; - - protected String specifiedDiscriminatorValue; - - protected final JavaDiscriminatorColumn discriminatorColumn; - - protected JavaSequenceGenerator sequenceGenerator; - - protected JavaTableGenerator tableGenerator; - - protected final List<JavaAttributeOverride> specifiedAttributeOverrides; - - protected final List<JavaAttributeOverride> virtualAttributeOverrides; - - protected final List<JavaAssociationOverride> specifiedAssociationOverrides; - - protected final List<JavaAssociationOverride> virtualAssociationOverrides; - - protected final List<JavaNamedQuery> namedQueries; - - protected final List<JavaNamedNativeQuery> namedNativeQueries; - - protected String idClass; - - - public GenericJavaEntity(JavaPersistentType parent) { - super(parent); - this.table = getJpaFactory().buildJavaTable(this); - this.discriminatorColumn = buildJavaDiscriminatorColumn(); - this.specifiedSecondaryTables = new ArrayList<JavaSecondaryTable>(); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - this.specifiedAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - this.namedQueries = new ArrayList<JavaNamedQuery>(); - this.namedNativeQueries = new ArrayList<JavaNamedNativeQuery>(); - this.specifiedAssociationOverrides = new ArrayList<JavaAssociationOverride>(); - this.virtualAssociationOverrides = new ArrayList<JavaAssociationOverride>(); - } - - protected JavaBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected JavaDiscriminatorColumn buildJavaDiscriminatorColumn() { - return getJpaFactory().buildJavaDiscriminatorColumn(this, buildDiscriminatorColumnOwner()); - } - - protected JavaNamedColumn.Owner buildDiscriminatorColumnOwner() { - return new JavaNamedColumn.Owner(){ - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericJavaEntity.this.getDbTable(tableName); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaEntity.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public String getDefaultColumnName() { - return DiscriminatorColumn.DEFAULT_NAME; - } - }; - } - - @Override - public void initialize(JavaResourcePersistentType resourcePersistentType) { - super.initialize(resourcePersistentType); - this.entityResource = (EntityAnnotation) resourcePersistentType.getMappingAnnotation(EntityAnnotation.ANNOTATION_NAME); - - this.specifiedName = this.specifiedName(this.entityResource); - this.defaultName = this.defaultName(resourcePersistentType); - this.defaultInheritanceStrategy = this.defaultInheritanceStrategy(); - this.specifiedInheritanceStrategy = this.specifiedInheritanceStrategy(getInheritanceResource()); - this.specifiedDiscriminatorValue = this.getDiscriminatorValueResource().getValue(); - this.defaultDiscriminatorValue = this.javaDefaultDiscriminatorValue(); - this.discriminatorValueAllowed = this.discriminatorValueIsAllowed(resourcePersistentType); - this.discriminatorColumn.initialize(resourcePersistentType); - this.table.initialize(resourcePersistentType); - this.initializeSecondaryTables(resourcePersistentType); - this.initializeTableGenerator(resourcePersistentType); - this.initializeSequenceGenerator(resourcePersistentType); - this.initializePrimaryKeyJoinColumns(resourcePersistentType); - this.initializeDefaultPrimaryKeyJoinColumn(resourcePersistentType); - this.initializeSpecifiedAttributeOverrides(resourcePersistentType); - this.initializeVirtualAttributeOverrides(resourcePersistentType); - this.initializeSpecifiedAssociationOverrides(resourcePersistentType); - this.initializeDefaultAssociationOverrides(resourcePersistentType); - this.initializeNamedQueries(resourcePersistentType); - this.initializeNamedNativeQueries(resourcePersistentType); - this.initializeIdClass(resourcePersistentType); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected void initializeSecondaryTables(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedSecondaryTables.add(buildSecondaryTable((SecondaryTableAnnotation) annotations.next())); - } - } - - protected void initializeTableGenerator(JavaResourcePersistentType resourcePersistentType) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(resourcePersistentType); - if (tableGeneratorResource != null) { - this.tableGenerator = buildTableGenerator(tableGeneratorResource); - } - } - - protected void initializeSequenceGenerator(JavaResourcePersistentType resourcePersistentType) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(resourcePersistentType); - if (sequenceGeneratorResource != null) { - this.sequenceGenerator = buildSequenceGenerator(sequenceGeneratorResource); - } - } - - protected void initializePrimaryKeyJoinColumns(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) annotations.next())); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn(JavaResourcePersistentType persistentTypeResource) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(persistentTypeResource)); - } - - protected void initializeSpecifiedAttributeOverrides(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaResourceNode> annotations = persistentTypeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedAttributeOverrides.add(buildAttributeOverride((AttributeOverrideAnnotation) annotations.next())); - } - } - - protected void initializeVirtualAttributeOverrides(JavaResourcePersistentType persistentTypeResource) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(persistentTypeResource, persistentAttribute)); - } - } - } - - protected void initializeSpecifiedAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedAssociationOverrides.add(buildAssociationOverride((AssociationOverrideAnnotation) annotations.next())); - } - } - - protected void initializeDefaultAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - for (Iterator<String> i = allOverridableAssociationNames(); i.hasNext(); ) { - String associationName = i.next(); - JavaAssociationOverride associationOverride = getAssociationOverrideNamed(associationName); - if (associationOverride == null) { - this.virtualAssociationOverrides.add(buildAssociationOverride(new NullAssociationOverride(resourcePersistentType, associationName))); - } - } - } - - protected void initializeNamedQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.namedQueries.add(buildNamedQuery((NamedQueryAnnotation) annotations.next())); - } - } - - protected void initializeNamedNativeQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.namedNativeQueries.add(buildNamedNativeQuery((NamedNativeQueryAnnotation) annotations.next())); - } - } - - //query for the inheritance resource every time on setters. - //call one setter and the inheritanceResource could change. - //You could call more than one setter before this object has received any notification - //from the java resource model - protected InheritanceAnnotation getInheritanceResource() { - return (InheritanceAnnotation) this.javaResourcePersistentType.getNonNullAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - } - - protected DiscriminatorValueAnnotation getDiscriminatorValueResource() { - return (DiscriminatorValueAnnotation) this.javaResourcePersistentType.getNonNullAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - } - - protected void initializeIdClass(JavaResourcePersistentType typeResource) { - IdClassAnnotation idClassResource = (IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (idClassResource != null) { - this.idClass = idClassResource.getValue(); - } - } - - //****************** ITypeMapping implemenation ******************* - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public boolean isMapped() { - return true; - } - - @Override - public String getTableName() { - return getTable().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return getTable().getDbTable(); - } - - 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().getDatabaseObjectNamed( - CollectionTools.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 getTable().getDbSchema(); - } - - - //****************** IJavaTypeMapping implemenation ******************* - - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.TABLE, - JPA.SECONDARY_TABLE, - JPA.SECONDARY_TABLES, - JPA.PRIMARY_KEY_JOIN_COLUMN, - JPA.PRIMARY_KEY_JOIN_COLUMNS, - JPA.ID_CLASS, - JPA.INHERITANCE, - JPA.DISCRIMINATOR_VALUE, - JPA.DISCRIMINATOR_COLUMN, - JPA.SEQUENCE_GENERATOR, - JPA.TABLE_GENERATOR, - JPA.NAMED_QUERY, - JPA.NAMED_QUERIES, - JPA.NAMED_NATIVE_QUERY, - JPA.NAMED_NATIVE_QUERIES, - JPA.SQL_RESULT_SET_MAPPING, - JPA.EXCLUDE_DEFAULT_LISTENERS, - JPA.EXCLUDE_SUPERCLASS_LISTENERS, - JPA.ENTITY_LISTENERS, - JPA.PRE_PERSIST, - JPA.POST_PERSIST, - JPA.PRE_REMOVE, - JPA.POST_REMOVE, - JPA.PRE_UPDATE, - JPA.POST_UPDATE, - JPA.POST_LOAD, - JPA.ATTRIBUTE_OVERRIDE, - JPA.ATTRIBUTE_OVERRIDES, - JPA.ASSOCIATION_OVERRIDE, - JPA.ASSOCIATION_OVERRIDES); - } - - //****************** IEntity implemenation ******************* - - public String getName() { - return (this.getSpecifiedName() == null) ? this.getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - this.entityResource.setName(newSpecifiedName); - firePropertyChanged(Entity.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(Entity.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected/*private-protected*/ void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(Entity.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public JavaTable getTable() { - return this.table; - } - - public ListIterator<JavaSecondaryTable> specifiedSecondaryTables() { - return new CloneListIterator<JavaSecondaryTable>(this.specifiedSecondaryTables); - } - - public int specifiedSecondaryTablesSize() { - return this.specifiedSecondaryTables.size(); - } - - public JavaSecondaryTable addSpecifiedSecondaryTable(int index) { - JavaSecondaryTable secondaryTable = getJpaFactory().buildJavaSecondaryTable(this); - this.specifiedSecondaryTables.add(index, secondaryTable); - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) this.javaResourcePersistentType.addAnnotation(index, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - secondaryTable.initialize(secondaryTableResource); - fireItemAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); - return secondaryTable; - } - - protected void addSpecifiedSecondaryTable(int index, JavaSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void removeSpecifiedSecondaryTable(SecondaryTable secondaryTable) { - this.removeSpecifiedSecondaryTable(this.specifiedSecondaryTables.indexOf(secondaryTable)); - } - - public void removeSpecifiedSecondaryTable(int index) { - JavaSecondaryTable removedSecondaryTable = this.specifiedSecondaryTables.remove(index); - this.javaResourcePersistentType.removeAnnotation(index, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, removedSecondaryTable); - } - - protected void removeSpecifiedSecondaryTable_(JavaSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void moveSpecifiedSecondaryTable(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedSecondaryTables, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, SecondaryTablesAnnotation.ANNOTATION_NAME); - fireItemMoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<JavaSecondaryTable> secondaryTables() { - return specifiedSecondaryTables(); - } - - public int secondaryTablesSize() { - return specifiedSecondaryTablesSize(); - } - - public InheritanceType getInheritanceStrategy() { - return (this.getSpecifiedInheritanceStrategy() == null) ? this.getDefaultInheritanceStrategy() : this.getSpecifiedInheritanceStrategy(); - } - - public InheritanceType getDefaultInheritanceStrategy() { - return this.defaultInheritanceStrategy; - } - - protected void setDefaultInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.defaultInheritanceStrategy; - this.defaultInheritanceStrategy = newInheritanceType; - firePropertyChanged(DEFAULT_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - public InheritanceType getSpecifiedInheritanceStrategy() { - return this.specifiedInheritanceStrategy; - } - - public void setSpecifiedInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - getInheritanceResource().setStrategy(InheritanceType.toJavaResourceModel(newInheritanceType)); - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedInheritanceStrategy_(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - public JavaDiscriminatorColumn getDiscriminatorColumn() { - return this.discriminatorColumn; - } - - public String getDefaultDiscriminatorValue() { - return this.defaultDiscriminatorValue; - } - - protected void setDefaultDiscriminatorValue(String newDefaultDiscriminatorValue) { - String oldDefaultDiscriminatorValue = this.defaultDiscriminatorValue; - this.defaultDiscriminatorValue = newDefaultDiscriminatorValue; - firePropertyChanged(DEFAULT_DISCRIMINATOR_VALUE_PROPERTY, oldDefaultDiscriminatorValue, newDefaultDiscriminatorValue); - } - - public String getSpecifiedDiscriminatorValue() { - return this.specifiedDiscriminatorValue; - } - - public void setSpecifiedDiscriminatorValue(String newSpecifiedDiscriminatorValue) { - String oldSpecifiedDiscriminatorValue = this.specifiedDiscriminatorValue; - this.specifiedDiscriminatorValue = newSpecifiedDiscriminatorValue; - getDiscriminatorValueResource().setValue(newSpecifiedDiscriminatorValue); - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedDiscriminatorValue_(String newSpecifiedDiscriminatorValue) { - String oldSpecifiedDiscriminatorValue = this.specifiedDiscriminatorValue; - this.specifiedDiscriminatorValue = newSpecifiedDiscriminatorValue; - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - public String getDiscriminatorValue() { - return (this.getSpecifiedDiscriminatorValue() == null) ? getDefaultDiscriminatorValue() : this.getSpecifiedDiscriminatorValue(); - } - - public boolean isDiscriminatorValueAllowed() { - return this.discriminatorValueAllowed; - } - - protected void setDiscriminatorValueAllowed(boolean newDiscriminatorValueAllowed) { - boolean oldDiscriminatorValueAllowed = this.discriminatorValueAllowed; - this.discriminatorValueAllowed = newDiscriminatorValueAllowed; - firePropertyChanged(Entity.DISCRIMINATOR_VALUE_ALLOWED_PROPERTY, oldDiscriminatorValueAllowed, newDiscriminatorValueAllowed); - } - - public JavaTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); //$NON-NLS-1$ - } - this.tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - TableGeneratorAnnotation tableGeneratorResource = (TableGeneratorAnnotation) this.javaResourcePersistentType.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.javaResourcePersistentType.removeAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public JavaTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(JavaTableGenerator newTableGenerator) { - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - public JavaSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); //$NON-NLS-1$ - } - this.sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - SequenceGeneratorAnnotation sequenceGeneratorResource = (SequenceGeneratorAnnotation) this.javaResourcePersistentType.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.javaResourcePersistentType.removeAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator,null); - } - - public JavaSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(JavaSequenceGenerator newSequenceGenerator) { - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<JavaGenerator> generators() { - return new CompositeIterator<JavaGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - public ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumns() : this.defaultPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumnsSize() : this.defaultPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<JavaPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public JavaPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - return this.defaultPrimaryKeyJoinColumn; - } - - protected void setDefaultPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn newPkJoinColumn) { - JavaPrimaryKeyJoinColumn oldPkJoinColumn = this.defaultPrimaryKeyJoinColumn; - this.defaultPrimaryKeyJoinColumn = newPkJoinColumn; - firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldPkJoinColumn, newPkJoinColumn); - } - - protected ListIterator<JavaPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - if (this.defaultPrimaryKeyJoinColumn != null) { - return new SingleElementListIterator<JavaPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultPrimaryKeyJoinColumnsSize() { - return (this.defaultPrimaryKeyJoinColumn == null) ? 0 : 1; - } - - public JavaPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn oldDefaultPkJoinColumn = this.getDefaultPrimaryKeyJoinColumn(); - if (oldDefaultPkJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultPrimaryKeyJoinColumn = null; - } - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) this.javaResourcePersistentType.addAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - primaryKeyJoinColumn.initialize(pkJoinColumnResource); - this.fireItemAdded(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return primaryKeyJoinColumn; - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(primaryKeyJoinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn removedPrimaryKeyJoinColumn = this.specifiedPrimaryKeyJoinColumns.remove(index); - if (!containsSpecifiedPrimaryKeyJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(this.javaResourcePersistentType)); - } - this.javaResourcePersistentType.removeAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (this.defaultPrimaryKeyJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, null, this.defaultPrimaryKeyJoinColumn); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - this.javaResourcePersistentType.move(targetIndex, sourceIndex, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - moveItemInList(targetIndex, sourceIndex, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - @SuppressWarnings("unchecked") - public ListIterator<JavaAttributeOverride> attributeOverrides() { - return new CompositeListIterator<JavaAttributeOverride>(specifiedAttributeOverrides(), virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<JavaAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.virtualAttributeOverrides); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - public ListIterator<JavaAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected JavaAttributeOverride addSpecifiedAttributeOverride(int index) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); - this.specifiedAttributeOverrides.add(index, attributeOverride); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - attributeOverride.initialize(attributeOverrideResource); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - return attributeOverride; - } - - protected JavaAttributeOverride setAttributeOverrideVirtual(boolean virtual, JavaAttributeOverride attributeOverride) { - // Add a new attribute override - if (virtual) { - return setAttributeOverrideVirtual(attributeOverride); - } - return setAttributeOverrideSpecified(attributeOverride); - } - - protected JavaAttributeOverride setAttributeOverrideVirtual(JavaAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(this.javaResourcePersistentType, persistentAttribute); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - break; - } - } - } - - this.javaResourcePersistentType.removeAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected JavaAttributeOverride setAttributeOverrideSpecified(JavaAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - JavaAttributeOverride newAttributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - newAttributeOverride.initialize(attributeOverrideResource); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - protected AttributeOverride.Owner createAttributeOverrideOwner() { - return new AttributeOverrideOwner(); - } - - protected void addSpecifiedAttributeOverride(int index, JavaAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - protected void addVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - public JavaAttributeOverride getAttributeOverrideNamed(String name) { - return (JavaAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - public boolean containsAttributeOverride(String name) { - return containsOverride(name, attributeOverrides()); - } - - public boolean containsDefaultAttributeOverride(String name) { - return containsOverride(name, virtualAttributeOverrides()); - } - - public boolean containsSpecifiedAttributeOverride(String name) { - return containsOverride(name, specifiedAttributeOverrides()); - } - - public JavaAssociationOverride getAssociationOverrideNamed(String name) { - return (JavaAssociationOverride) getOverrideNamed(name, associationOverrides()); - } - - public boolean containsAssociationOverride(String name) { - return containsOverride(name, associationOverrides()); - } - - public boolean containsSpecifiedAssociationOverride(String name) { - return containsOverride(name, specifiedAssociationOverrides()); - } - - public boolean containsDefaultAssociationOverride(String name) { - return containsOverride(name, virtualAssociationOverrides()); - } - - private BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(overrides)) { - String overrideName = override.getName(); - if (overrideName == null && name == null) { - return override; - } - if (overrideName != null && overrideName.equals(name)) { - return override; - } - } - return null; - } - - private boolean containsOverride(String name, ListIterator<? extends BaseOverride> overrides) { - return getOverrideNamed(name, overrides) != null; - } - - - @SuppressWarnings("unchecked") - public ListIterator<JavaAssociationOverride> associationOverrides() { - return new CompositeListIterator<JavaAssociationOverride>(specifiedAssociationOverrides(), virtualAssociationOverrides()); - } - - public int associationOverridesSize() { - return this.specifiedAssociationOverridesSize() + this.virtualAssociationOverridesSize(); - } - - public ListIterator<JavaAssociationOverride> virtualAssociationOverrides() { - return new CloneListIterator<JavaAssociationOverride>(this.virtualAssociationOverrides); - } - - public int virtualAssociationOverridesSize() { - return this.virtualAssociationOverrides.size(); - } - - public ListIterator<JavaAssociationOverride> specifiedAssociationOverrides() { - return new CloneListIterator<JavaAssociationOverride>(this.specifiedAssociationOverrides); - } - - public int specifiedAssociationOverridesSize() { - return this.specifiedAssociationOverrides.size(); - } - - public JavaAssociationOverride addSpecifiedAssociationOverride(int index) { - JavaAssociationOverride associationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); - this.specifiedAssociationOverrides.add(index, associationOverride); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - associationOverride.initialize(associationOverrideResource); - this.fireItemAdded(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); - return associationOverride; - } - - protected AssociationOverride.Owner createAssociationOverrideOwner() { - return new AssociationOverrideOwner(); - } - - protected void addSpecifiedAssociationOverride(int index, JavaAssociationOverride associationOverride) { - addItemToList(index, associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeSpecifiedAssociationOverride_(JavaAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAssociationOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, AssociationOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - protected JavaAssociationOverride setAssociationOverrideVirtual(boolean virtual, JavaAssociationOverride associationOverride) { - // Add a new attribute override - if (virtual) { - return setAssociationOverrideVirtual(associationOverride); - } - return setAssociationOverrideSpecified(associationOverride); - } - - protected JavaAssociationOverride setAssociationOverrideVirtual(JavaAssociationOverride associationOverride) { - int index = this.specifiedAssociationOverrides.indexOf(associationOverride); - this.specifiedAssociationOverrides.remove(index); - String associationOverrideName = associationOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAssociationOverride virtualAssociationOverride = null; - if (associationOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAssociations())) { - if (persistentAttribute.getName().equals(associationOverrideName)) { - //store the virtualAssociationOverride so we can fire change notification later - virtualAssociationOverride = buildAssociationOverride(new NullAssociationOverride(this.javaResourcePersistentType, associationOverrideName)); - this.virtualAssociationOverrides.add(virtualAssociationOverride); - break; - } - } - } - - this.javaResourcePersistentType.removeAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); - - if (virtualAssociationOverride != null) { - fireItemAdded(Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST, virtualAssociationOverridesSize() - 1, virtualAssociationOverride); - } - return virtualAssociationOverride; - } - - protected JavaAssociationOverride setAssociationOverrideSpecified(JavaAssociationOverride oldAssociationOverride) { - int index = specifiedAssociationOverridesSize(); - JavaAssociationOverride newAssociationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); - this.specifiedAssociationOverrides.add(index, newAssociationOverride); - - AssociationOverrideAnnotation attributeOverrideResource = (AssociationOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - newAssociationOverride.initialize(attributeOverrideResource); - - int virtualIndex = this.virtualAssociationOverrides.indexOf(oldAssociationOverride); - this.virtualAssociationOverrides.remove(virtualIndex); - - newAssociationOverride.setName(oldAssociationOverride.getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST, virtualIndex, oldAssociationOverride); - this.fireItemAdded(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, newAssociationOverride); - - return newAssociationOverride; - } - - protected void addVirtualAssociationOverride(JavaAssociationOverride associationOverride) { - addItemToList(associationOverride, this.virtualAssociationOverrides, Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeVirtualAssociationOverride(JavaAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.virtualAssociationOverrides, Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - public ListIterator<JavaNamedQuery> namedQueries() { - return new CloneListIterator<JavaNamedQuery>(this.namedQueries); - } - - public int namedQueriesSize() { - return this.namedQueries.size(); - } - - public JavaNamedQuery addNamedQuery(int index) { - JavaNamedQuery namedQuery = getJpaFactory().buildJavaNamedQuery(this); - this.namedQueries.add(index, namedQuery); - NamedQueryAnnotation namedQueryAnnotation = (NamedQueryAnnotation) this.javaResourcePersistentType.addAnnotation(index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - namedQuery.initialize(namedQueryAnnotation); - fireItemAdded(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - return namedQuery; - } - - protected void addNamedQuery(int index, JavaNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - JavaNamedQuery removedNamedQuery = this.namedQueries.remove(index); - this.javaResourcePersistentType.removeAnnotation(index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - fireItemRemoved(QueryHolder.NAMED_QUERIES_LIST, index, removedNamedQuery); - } - - protected void removeNamedQuery_(JavaNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, NamedQueriesAnnotation.ANNOTATION_NAME); - fireItemMoved(QueryHolder.NAMED_QUERIES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<JavaNamedNativeQuery> namedNativeQueries() { - return new CloneListIterator<JavaNamedNativeQuery>(this.namedNativeQueries); - } - - public int namedNativeQueriesSize() { - return this.namedNativeQueries.size(); - } - - public JavaNamedNativeQuery addNamedNativeQuery(int index) { - JavaNamedNativeQuery namedNativeQuery = getJpaFactory().buildJavaNamedNativeQuery(this); - this.namedNativeQueries.add(index, namedNativeQuery); - NamedNativeQueryAnnotation namedNativeQueryAnnotation = (NamedNativeQueryAnnotation) this.javaResourcePersistentType.addAnnotation(index, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - namedNativeQuery.initialize(namedNativeQueryAnnotation); - fireItemAdded(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - return namedNativeQuery; - } - - protected void addNamedNativeQuery(int index, JavaNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - this.removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - JavaNamedNativeQuery removedNamedNativeQuery = this.namedNativeQueries.remove(index); - this.javaResourcePersistentType.removeAnnotation(index, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - fireItemRemoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, removedNamedNativeQuery); - } - - protected void removeNamedNativeQuery_(JavaNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - fireItemMoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - protected Iterator<JavaQuery> queries() { - return new CompositeIterator<JavaQuery>(this.namedNativeQueries(), this.namedQueries()); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (newIdClass != oldIdClass) { - if (newIdClass != null) { - if (getIdClassResource() == null) { - addIdClassResource(); - } - getIdClassResource().setValue(newIdClass); - } - else { - removeIdClassResource(); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected IdClassAnnotation getIdClassResource() { - return (IdClassAnnotation) this.javaResourcePersistentType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void addIdClassResource() { - this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void removeIdClassResource() { - this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - public Entity getParentEntity() { - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - TypeMapping typeMapping = i.next().getMapping(); - if (typeMapping != this && typeMapping instanceof Entity) { - return (Entity) typeMapping; - } - } - return this; - } - - public Entity getRootEntity() { - Entity rootEntity = this; - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - PersistentType persistentType = i.next(); - if (persistentType.getMapping() instanceof Entity) { - rootEntity = (Entity) persistentType.getMapping(); - } - } - return rootEntity; - } - - public String getPrimaryKeyColumnName() { - return getPrimaryKeyColumnName(getPersistentType().allAttributes()); - } - - //copied in GenericOrmEntity to avoid an API change for fixing bug 229423 in RC1 - public String getPrimaryKeyColumnName(Iterator<PersistentAttribute> attributes) { - String pkColumnName = null; - for (Iterator<PersistentAttribute> stream = attributes; stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - String name = attribute.getPrimaryKeyColumnName(); - if (name != null) { - //if the attribute is a primary key then we need to check if there is an attribute override - //and use its column name instead (bug 229423) - AttributeOverride attributeOverride = getAttributeOverrideNamed(attribute.getName()); - if (attributeOverride != null) { - name = attributeOverride.getColumn().getName(); - } - } - if (pkColumnName == null) { - pkColumnName = name; - } - else if (name != null) { - // if we encounter a composite primary key, return null - return null; - } - } - // if we encounter only a single primary key column name, return it - return pkColumnName; - } - - @Override - public boolean tableNameIsInvalid(String tableName) { - return !CollectionTools.contains(this.associatedTableNamesIncludingInherited(), tableName); - } - - @Override - public Iterator<Table> associatedTables() { - return new CompositeIterator<Table>(this.getTable(), this.secondaryTables()); - } - - @Override - public Iterator<Table> associatedTablesIncludingInherited() { - return new CompositeIterator<Table>(new TransformationIterator<TypeMapping, Iterator<Table>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<Table> transform(TypeMapping mapping) { - return new FilteringIterator<Table, Table>(mapping.associatedTables()) { - @Override - protected boolean accept(Table o) { - return true; - //TODO - //filtering these out so as to avoid the duplicate table, root and children share the same table - //return !(o instanceof SingleTableInheritanceChildTableImpl); - } - }; - } - }); - } - - @Override - public Iterator<String> associatedTableNamesIncludingInherited() { - return this.nonNullTableNames(this.associatedTablesIncludingInherited()); - } - - protected Iterator<String> nonNullTableNames(Iterator<Table> tables) { - return new FilteringIterator<String, String>(this.tableNames(tables)) { - @Override - protected boolean accept(String o) { - return o != null; - } - }; - } - - protected Iterator<String> tableNames(Iterator<Table> tables) { - return new TransformationIterator<Table, String>(tables) { - @Override - protected String transform(Table t) { - return t.getName(); - } - }; - } - - /** - * Return an iterator of Entities, each which inherits from the one before, - * and terminates at the root entity (or at the point of cyclicity). - */ - protected Iterator<TypeMapping> inheritanceHierarchy() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().inheritanceHierarchy()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - @Override - public Iterator<String> allOverridableAttributeNames() { - return new CompositeIterator<String>(new TransformationIterator<TypeMapping, Iterator<String>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<String> transform(TypeMapping mapping) { - return mapping.overridableAttributeNames(); - } - }); - } - - - @Override - public Iterator<PersistentAttribute> allOverridableAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<TypeMapping, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(TypeMapping mapping) { - return mapping.overridableAttributes(); - } - }); - } - - @Override - public Iterator<PersistentAttribute> allOverridableAssociations() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<TypeMapping, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(TypeMapping mapping) { - return mapping.overridableAssociations(); - } - }); - } - - @Override - public Iterator<String> allOverridableAssociationNames() { - return new CompositeIterator<String>(new TransformationIterator<TypeMapping, Iterator<String>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<String> transform(TypeMapping mapping) { - return mapping.overridableAssociationNames(); - } - }); - } - - @Override - public void update(JavaResourcePersistentType resourcePersistentType) { - super.update(resourcePersistentType); - this.entityResource = (EntityAnnotation) resourcePersistentType.getMappingAnnotation(EntityAnnotation.ANNOTATION_NAME); - - this.setSpecifiedName_(this.specifiedName(this.entityResource)); - this.setDefaultName(this.defaultName(resourcePersistentType)); - - this.updateInheritance(getInheritanceResource()); - this.updateDiscriminatorColumn(resourcePersistentType); - this.updateDiscriminatorValue(getDiscriminatorValueResource()); - this.setDiscriminatorValueAllowed(discriminatorValueIsAllowed(resourcePersistentType)); - this.updateTable(resourcePersistentType); - this.updateSecondaryTables(resourcePersistentType); - this.updateTableGenerator(resourcePersistentType); - this.updateSequenceGenerator(resourcePersistentType); - this.updateSpecifiedPrimaryKeyJoinColumns(resourcePersistentType); - this.updateDefaultPrimaryKeyJoinColumn(resourcePersistentType); - this.updateSpecifiedAttributeOverrides(resourcePersistentType); - this.updateVirtualAttributeOverrides(resourcePersistentType); - this.updateSpecifiedAssociationOverrides(resourcePersistentType); - this.updateVirtualAssociationOverrides(resourcePersistentType); - this.updateNamedQueries(resourcePersistentType); - this.updateNamedNativeQueries(resourcePersistentType); - this.updateIdClass(resourcePersistentType); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected String specifiedName(EntityAnnotation entityAnnotation) { - return entityAnnotation.getName(); - } - - protected String defaultName(JavaResourcePersistentType persistentTypeResource) { - return persistentTypeResource.getName(); - } - - protected void updateTable(JavaResourcePersistentType persistentTypeResource) { - getTable().update(persistentTypeResource); - } - - protected void updateInheritance(InheritanceAnnotation inheritanceResource) { - this.setSpecifiedInheritanceStrategy_(this.specifiedInheritanceStrategy(inheritanceResource)); - this.setDefaultInheritanceStrategy(this.defaultInheritanceStrategy()); - } - - protected InheritanceType specifiedInheritanceStrategy(InheritanceAnnotation inheritanceResource) { - return InheritanceType.fromJavaResourceModel(inheritanceResource.getStrategy()); - } - - protected InheritanceType defaultInheritanceStrategy() { - if (getRootEntity() == this) { - return InheritanceType.SINGLE_TABLE; - } - return getRootEntity().getInheritanceStrategy(); - } - - protected void updateDiscriminatorColumn(JavaResourcePersistentType persistentTypeResource) { - getDiscriminatorColumn().update(persistentTypeResource); - } - - protected void updateDiscriminatorValue(DiscriminatorValueAnnotation discriminatorValueResource) { - this.setSpecifiedDiscriminatorValue_(discriminatorValueResource.getValue()); - this.setDefaultDiscriminatorValue(this.javaDefaultDiscriminatorValue()); - } - - /** - * From the Spec: - * If the DiscriminatorValue annotation is not specified, a - * provider-specific function to generate a value representing - * the entity type is used for the value of the discriminator - * column. If the DiscriminatorType is STRING, the discriminator - * value default is the entity name. - * - * TODO extension point for provider-specific function? - */ - protected String javaDefaultDiscriminatorValue() { - if (this.javaResourcePersistentType.isAbstract()) { - return null; - } - if (this.getDiscriminatorType() != DiscriminatorType.STRING) { - return null; - } - return this.getName(); - } - - protected DiscriminatorType getDiscriminatorType() { - return this.getDiscriminatorColumn().getDiscriminatorType(); - } - - protected boolean discriminatorValueIsAllowed(JavaResourcePersistentType persistentTypeResource) { - return !persistentTypeResource.isAbstract(); - } - - protected void updateSecondaryTables(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaSecondaryTable> secondaryTables = specifiedSecondaryTables(); - ListIterator<JavaResourceNode> resourceSecondaryTables = persistentTypeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - while (secondaryTables.hasNext()) { - JavaSecondaryTable secondaryTable = secondaryTables.next(); - if (resourceSecondaryTables.hasNext()) { - secondaryTable.update((SecondaryTableAnnotation) resourceSecondaryTables.next()); - } - else { - removeSpecifiedSecondaryTable_(secondaryTable); - } - } - - while (resourceSecondaryTables.hasNext()) { - addSpecifiedSecondaryTable(specifiedSecondaryTablesSize(), buildSecondaryTable((SecondaryTableAnnotation) resourceSecondaryTables.next())); - } - } - - protected JavaSecondaryTable buildSecondaryTable(SecondaryTableAnnotation secondaryTableResource) { - JavaSecondaryTable secondaryTable = getJpaFactory().buildJavaSecondaryTable(this); - secondaryTable.initialize(secondaryTableResource); - return secondaryTable; - } - - protected void updateTableGenerator(JavaResourcePersistentType persistentTypeResource) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(persistentTypeResource); - if (tableGeneratorResource == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(tableGeneratorResource)); - } - else { - getTableGenerator().update(tableGeneratorResource); - } - } - } - - protected JavaTableGenerator buildTableGenerator(TableGeneratorAnnotation tableGeneratorResource) { - JavaTableGenerator generator = getJpaFactory().buildJavaTableGenerator(this); - generator.initialize(tableGeneratorResource); - return generator; - } - - protected TableGeneratorAnnotation tableGenerator(JavaResourcePersistentType persistentTypeResource) { - return (TableGeneratorAnnotation) persistentTypeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - } - - protected void updateSequenceGenerator(JavaResourcePersistentType persistentTypeResource) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(persistentTypeResource); - if (sequenceGeneratorResource == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(sequenceGeneratorResource)); - } - else { - getSequenceGenerator().update(sequenceGeneratorResource); - } - } - } - - protected JavaSequenceGenerator buildSequenceGenerator(SequenceGeneratorAnnotation sequenceGeneratorResource) { - JavaSequenceGenerator generator = getJpaFactory().buildJavaSequenceGenerator(this); - generator.initialize(sequenceGeneratorResource); - return generator; - } - - protected SequenceGeneratorAnnotation sequenceGenerator(JavaResourcePersistentType persistentTypeResource) { - return (SequenceGeneratorAnnotation) persistentTypeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - } - - - protected void updateSpecifiedPrimaryKeyJoinColumns(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<JavaResourceNode> resourcePrimaryKeyJoinColumns = persistentTypeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, 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(specifiedPrimaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) resourcePrimaryKeyJoinColumns.next())); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - primaryKeyJoinColumn.initialize(primaryKeyJoinColumnResource); - return primaryKeyJoinColumn; - } - - protected void updateDefaultPrimaryKeyJoinColumn(JavaResourcePersistentType persistentTypeResource) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(this.javaResourcePersistentType))); - } - else { - this.defaultPrimaryKeyJoinColumn.update(new NullPrimaryKeyJoinColumn(persistentTypeResource)); - } - } - - protected void updateSpecifiedAttributeOverrides(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<JavaResourceNode> resourceAttributeOverrides = persistentTypeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while (attributeOverrides.hasNext()) { - JavaAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update((AttributeOverrideAnnotation) resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride((AttributeOverrideAnnotation) resourceAttributeOverrides.next())); - } - } - - protected JavaAttributeOverride buildAttributeOverride(AttributeOverrideAnnotation attributeOverrideResource) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); - attributeOverride.initialize(attributeOverrideResource); - return attributeOverride; - } - - protected JavaAttributeOverride buildVirtualAttributeOverride(JavaResourcePersistentType resourcePersistentType, PersistentAttribute attribute) { - return buildAttributeOverride(buildVirtualAttributeOverrideResource(resourcePersistentType, attribute)); - } - - protected VirtualAttributeOverride buildVirtualAttributeOverrideResource(JavaResourcePersistentType resourcePersistentType, PersistentAttribute attribute) { - ColumnMapping columnMapping = (ColumnMapping) attribute.getMapping(); - return new VirtualAttributeOverride(resourcePersistentType, attribute.getName(), columnMapping.getColumn()); - } - - protected void updateVirtualAttributeOverrides(JavaResourcePersistentType resourcePersistentType) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - addVirtualAttributeOverride(buildVirtualAttributeOverride(resourcePersistentType, persistentAttribute)); - } - else if (attributeOverride.isVirtual()) { - attributeOverride.update(buildVirtualAttributeOverrideResource(resourcePersistentType, persistentAttribute)); - } - } - - Collection<String> attributeNames = CollectionTools.collection(allOverridableAttributeNames()); - - //remove any default mappings that are not included in the attributeNames collection - for (JavaAttributeOverride attributeOverride : CollectionTools.iterable(virtualAttributeOverrides())) { - if (!attributeNames.contains(attributeOverride.getName()) - || containsSpecifiedAttributeOverride(attributeOverride.getName())) { - removeVirtualAttributeOverride(attributeOverride); - } - } - } - - protected void updateSpecifiedAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaAssociationOverride> associationOverrides = specifiedAssociationOverrides(); - ListIterator<JavaResourceNode> resourceAssociationOverrides = resourcePersistentType.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - while (associationOverrides.hasNext()) { - JavaAssociationOverride associationOverride = associationOverrides.next(); - if (resourceAssociationOverrides.hasNext()) { - associationOverride.update((AssociationOverrideAnnotation) resourceAssociationOverrides.next()); - } - else { - removeSpecifiedAssociationOverride_(associationOverride); - } - } - - while (resourceAssociationOverrides.hasNext()) { - addSpecifiedAssociationOverride(specifiedAssociationOverridesSize(), buildAssociationOverride((AssociationOverrideAnnotation) resourceAssociationOverrides.next())); - } - } - - protected JavaAssociationOverride buildAssociationOverride(AssociationOverrideAnnotation associationOverrideResource) { - JavaAssociationOverride associationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); - associationOverride.initialize(associationOverrideResource); - return associationOverride; - } - - protected void updateVirtualAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - for (Iterator<String> i = allOverridableAssociationNames(); i.hasNext(); ) { - String associationName = i.next(); - JavaAssociationOverride associationOverride = getAssociationOverrideNamed(associationName); - if (associationOverride == null) { - associationOverride = buildAssociationOverride(new NullAssociationOverride(resourcePersistentType, associationName)); - addVirtualAssociationOverride(associationOverride); - } - else if (associationOverride.isVirtual()) { - associationOverride.update(new NullAssociationOverride(resourcePersistentType, associationName)); - } - } - - Collection<String> associationNames = CollectionTools.collection(allOverridableAssociationNames()); - - //remove any default mappings that are not included in the associationNames collection - for (JavaAssociationOverride associationOverride : CollectionTools.iterable(virtualAssociationOverrides())) { - if (!associationNames.contains(associationOverride.getName()) - || containsSpecifiedAssociationOverride(associationOverride.getName())) { - removeVirtualAssociationOverride(associationOverride); - } - } - } - - protected void updateNamedQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaNamedQuery> queries = namedQueries(); - ListIterator<JavaResourceNode> resourceNamedQueries = resourcePersistentType.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(namedQueriesSize(), buildNamedQuery((NamedQueryAnnotation) resourceNamedQueries.next())); - } - } - - protected void updateNamedNativeQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaNamedNativeQuery> queries = namedNativeQueries(); - ListIterator<JavaResourceNode> resourceNamedNativeQueries = resourcePersistentType.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(namedNativeQueriesSize(), buildNamedNativeQuery((NamedNativeQueryAnnotation) resourceNamedNativeQueries.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; - } - - protected void updateIdClass(JavaResourcePersistentType resourcePersistentType) { - IdClassAnnotation annotation = (IdClassAnnotation) resourcePersistentType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (annotation != null) { - setIdClass_(annotation.getValue()); - } - else { - setIdClass_(null); - } - } - - protected void updatePersistenceUnitGeneratorsAndQueries() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - - for (Query query : CollectionTools.iterable(namedQueries())) { - getPersistenceUnit().addQuery(query); - } - - for (Query query : CollectionTools.iterable(namedNativeQueries())) { - getPersistenceUnit().addQuery(query); - } - } - - - //******************** Code Completion ************************* - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getTable().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaSecondaryTable sTable : CollectionTools.iterable(this.secondaryTables())) { - result = sTable.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaPrimaryKeyJoinColumn column : CollectionTools.iterable(this.primaryKeyJoinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaAttributeOverride override : CollectionTools.iterable(this.attributeOverrides())) { - result = override.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaAssociationOverride override : CollectionTools.iterable(this.associationOverrides())) { - result = override.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - result = this.getDiscriminatorColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.getTableGenerator() != null) { - result = this.getTableGenerator().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - if (this.getSequenceGenerator() != null) { - result = this.getSequenceGenerator().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - - //********** Validation ******************************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - getTable().addToMessages(messages, astRoot); - addIdMessages(messages, astRoot); - addGeneratorMessages(messages, astRoot); - addQueryMessages(messages, astRoot); - - for (Iterator<JavaSecondaryTable> stream = this.specifiedSecondaryTables(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - - for (Iterator<JavaAttributeOverride> stream = this.attributeOverrides(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - - for (Iterator<JavaAssociationOverride> stream = this.associationOverrides(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - - } - - protected void addIdMessages(List<IMessage> messages, CompilationUnit astRoot) { - addNoIdMessage(messages, astRoot); - } - - protected void addNoIdMessage(List<IMessage> messages, CompilationUnit astRoot) { - if (entityHasNoId()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NO_ID, - new String[] {this.getName()}, - this, this.getValidationTextRange(astRoot)) - ); - } - } - - private boolean entityHasNoId() { - return ! this.entityHasId(); - } - - private boolean entityHasId() { - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext(); ) { - if (stream.next().isIdAttribute()) { - return true; - } - } - return false; - } - - protected void addGeneratorMessages(List<IMessage> messages, CompilationUnit astRoot) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<JavaGenerator> stream = this.generators(); stream.hasNext() ; ) { - JavaGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange(astRoot)) - ); - } - } - - masterList.add(current); - } - } - - protected void addQueryMessages(List<IMessage> messages, CompilationUnit astRoot) { - List<Query> masterList = CollectionTools.list(getPersistenceUnit().allQueries()); - - for (Iterator<JavaQuery> stream = this.queries(); stream.hasNext() ; ) { - JavaQuery current = stream.next(); - masterList.remove(current); - - for (Query each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange(astRoot)) - ); - } - } - - masterList.add(current); - } - } - - class PrimaryKeyJoinColumnOwner implements JavaBaseJoinColumn.Owner - { - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaEntity.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericJavaEntity.this.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity parentEntity = GenericJavaEntity.this.getParentEntity(); - return (parentEntity == null) ? null : parentEntity.getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericJavaEntity.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaEntity.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return GenericJavaEntity.this.getParentEntity().getPrimaryKeyColumnName(); - } - } - - class AttributeOverrideOwner implements AttributeOverride.Owner { - - public ColumnMapping getColumnMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof ColumnMapping) { - return (ColumnMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericJavaEntity.this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride attributeOverride) { - return GenericJavaEntity.this.setAttributeOverrideVirtual(virtual, (JavaAttributeOverride) attributeOverride); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public TextRange validationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - } - - class AssociationOverrideOwner implements AssociationOverride.Owner { - - public RelationshipMapping getRelationshipMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof RelationshipMapping) { - return (RelationshipMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericJavaEntity.this.virtualAssociationOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride attributeOverride) { - return GenericJavaEntity.this.setAssociationOverrideVirtual(virtual, (JavaAssociationOverride) attributeOverride); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public TextRange validationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java deleted file mode 100644 index a1253ce55e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericJavaGeneratedValue extends AbstractJavaJpaContextNode implements JavaGeneratedValue -{ - protected GenerationType strategy; - - protected String generator; - - protected String defaultGenerator; - - protected GeneratedValueAnnotation generatedValueResource; - - public GenericJavaGeneratedValue(JavaAttributeMapping parent) { - super(parent); - } - - public void initialize(GeneratedValueAnnotation generatedValue) { - this.generatedValueResource = generatedValue; - this.strategy = this.strategy(generatedValue); - this.generator = this.generator(generatedValue); - } - - public GenerationType getStrategy() { - return (this.getSpecifiedStrategy() == null) ? this.getDefaultStrategy() : this.getSpecifiedStrategy(); - } - - public GenerationType getDefaultStrategy() { - return GeneratedValue.DEFAULT_STRATEGY; - } - - public GenerationType getSpecifiedStrategy() { - return this.strategy; - } - - public void setSpecifiedStrategy(GenerationType newStrategy) { - GenerationType oldStrategy = this.strategy; - this.strategy = newStrategy; - this.generatedValueResource.setStrategy(GenerationType.toJavaResourceModel(newStrategy)); - firePropertyChanged(GeneratedValue.SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newStrategy); - } - - protected void setSpecifiedStrategy_(GenerationType newStrategy) { - GenerationType oldStrategy = this.strategy; - this.strategy = newStrategy; - firePropertyChanged(GeneratedValue.SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newStrategy); - } - - public String getGenerator() { - return (this.getSpecifiedGenerator() == null) ? this.getDefaultGenerator() : this.getSpecifiedGenerator(); - } - - public String getSpecifiedGenerator() { - return this.generator; - } - - public String getDefaultGenerator() { - return this.defaultGenerator; - } - - public void setSpecifiedGenerator(String newGenerator) { - String oldGenerator = this.generator; - this.generator = newGenerator; - this.generatedValueResource.setGenerator(newGenerator); - firePropertyChanged(GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newGenerator); - } - - protected void setSpecifiedGenerator_(String newGenerator) { - String oldGenerator = this.generator; - this.generator = newGenerator; - firePropertyChanged(GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newGenerator); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.generatedValueResource.getTextRange(astRoot); - } - - public TextRange getGeneratorTextRange(CompilationUnit astRoot) { - return this.generatedValueResource.getGeneratorTextRange(astRoot); - } - - // ********** resource model -> java context model ********** - - public void update(GeneratedValueAnnotation generatedValue) { - this.generatedValueResource = generatedValue; - this.setSpecifiedStrategy_(this.strategy(generatedValue)); - this.setSpecifiedGenerator_(this.generator(generatedValue)); - } - - protected GenerationType strategy(GeneratedValueAnnotation generatedValue) { - return GenerationType.fromJavaResourceModel(generatedValue.getStrategy()); - } - - protected String generator(GeneratedValueAnnotation generatedValue) { - return generatedValue.getGenerator(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java deleted file mode 100644 index 8d1e82fc06..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java +++ /dev/null @@ -1,487 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaIdMapping extends AbstractJavaAttributeMapping<IdAnnotation> implements JavaIdMapping -{ - protected final JavaColumn column; - - protected JavaGeneratedValue generatedValue; - - protected TemporalType temporal; - - protected JavaTableGenerator tableGenerator; - - protected JavaSequenceGenerator sequenceGenerator; - - public GenericJavaIdMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = createJavaColumn(); - } - - protected JavaColumn createJavaColumn() { - return getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initialize(resourcePersistentAttribute); - this.column.initialize(this.getColumnResource()); - this.temporal = this.temporal(this.getTemporalResource()); - this.initializeTableGenerator(resourcePersistentAttribute); - this.initializeSequenceGenerator(resourcePersistentAttribute); - this.initializeGeneratedValue(resourcePersistentAttribute); - this.updatePersistenceUnitGenerators(); - } - - protected void initializeTableGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(resourcePersistentAttribute); - if (tableGeneratorResource != null) { - this.tableGenerator = buildTableGenerator(tableGeneratorResource); - } - } - - protected void initializeSequenceGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(resourcePersistentAttribute); - if (sequenceGeneratorResource != null) { - this.sequenceGenerator = buildSequenceGenerator(sequenceGeneratorResource); - } - } - - protected void initializeGeneratedValue(JavaResourcePersistentAttribute resourcePersistentAttribute) { - GeneratedValueAnnotation generatedValueResource = generatedValue(resourcePersistentAttribute); - if (generatedValueResource != null) { - this.generatedValue = buildGeneratedValue(generatedValueResource); - } - } - - protected TemporalAnnotation getTemporalResource() { - return (TemporalAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(TemporalAnnotation.ANNOTATION_NAME); - } - - public ColumnAnnotation getColumnResource() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** IJavaAttributeMapping implementation *************** - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return IdAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.COLUMN, - JPA.GENERATED_VALUE, - JPA.TEMPORAL, - JPA.TABLE_GENERATOR, - JPA.SEQUENCE_GENERATOR); - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - //************** IIdMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getTemporalResource().setValue(TemporalType.toJavaResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public JavaGeneratedValue addGeneratedValue() { - if (getGeneratedValue() != null) { - throw new IllegalStateException("gemeratedValue already exists"); - } - this.generatedValue = getJpaFactory().buildJavaGeneratedValue(this); - GeneratedValueAnnotation generatedValueResource = (GeneratedValueAnnotation) getResourcePersistentAttribute().addAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - this.generatedValue.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"); - } - JavaGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = null; - getResourcePersistentAttribute().removeAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, null); - } - - public JavaGeneratedValue getGeneratedValue() { - return this.generatedValue; - } - - protected void setGeneratedValue(JavaGeneratedValue newGeneratedValue) { - JavaGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = newGeneratedValue; - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, newGeneratedValue); - } - - public JavaTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); - } - this.tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - TableGeneratorAnnotation tableGeneratorResource = (TableGeneratorAnnotation) getResourcePersistentAttribute().addAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - this.tableGenerator.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"); - } - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - getResourcePersistentAttribute().removeAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public JavaTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(JavaTableGenerator newTableGenerator) { - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - public JavaSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); - } - - this.sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - SequenceGeneratorAnnotation sequenceGeneratorResource = (SequenceGeneratorAnnotation) getResourcePersistentAttribute().addAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - this.sequenceGenerator.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"); - } - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - getResourcePersistentAttribute().removeAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, null); - } - - public JavaSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(JavaSequenceGenerator newSequenceGenerator) { - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<JavaGenerator> generators() { - return new CompositeIterator<JavaGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.column.update(this.getColumnResource()); - this.setTemporal_(this.temporal(this.getTemporalResource())); - this.updateTableGenerator(resourcePersistentAttribute); - this.updateSequenceGenerator(resourcePersistentAttribute); - this.updateGeneratedValue(resourcePersistentAttribute); - this.updatePersistenceUnitGenerators(); - } - - protected TemporalType temporal(TemporalAnnotation temporal) { - return TemporalType.fromJavaResourceModel(temporal.getValue()); - } - - protected void updateTableGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(resourcePersistentAttribute); - if (tableGeneratorResource == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(tableGeneratorResource)); - } - else { - getTableGenerator().update(tableGeneratorResource); - } - } - } - - protected JavaTableGenerator buildTableGenerator(TableGeneratorAnnotation tableGeneratorResource) { - JavaTableGenerator tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - tableGenerator.initialize(tableGeneratorResource); - return tableGenerator; - } - - protected void updateSequenceGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(resourcePersistentAttribute); - if (sequenceGeneratorResource == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(sequenceGeneratorResource)); - } - else { - getSequenceGenerator().update(sequenceGeneratorResource); - } - } - } - - protected JavaSequenceGenerator buildSequenceGenerator(SequenceGeneratorAnnotation sequenceGeneratorResource) { - JavaSequenceGenerator sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - sequenceGenerator.initialize(sequenceGeneratorResource); - return sequenceGenerator; - } - - protected void updateGeneratedValue(JavaResourcePersistentAttribute resourcePersistentAttribute) { - GeneratedValueAnnotation generatedValueResource = generatedValue(resourcePersistentAttribute); - if (generatedValueResource == null) { - if (getGeneratedValue() != null) { - setGeneratedValue(null); - } - } - else { - if (getGeneratedValue() == null) { - setGeneratedValue(buildGeneratedValue(generatedValueResource)); - } - else { - getGeneratedValue().update(generatedValueResource); - } - } - } - - protected JavaGeneratedValue buildGeneratedValue(GeneratedValueAnnotation generatedValueResource) { - JavaGeneratedValue generatedValue = getJpaFactory().buildJavaGeneratedValue(this); - generatedValue.initialize(generatedValueResource); - return generatedValue; - } - - protected TableGeneratorAnnotation tableGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (TableGeneratorAnnotation) resourcePersistentAttribute.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - } - - protected SequenceGeneratorAnnotation sequenceGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (SequenceGeneratorAnnotation) resourcePersistentAttribute.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - } - - protected GeneratedValueAnnotation generatedValue(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (GeneratedValueAnnotation) resourcePersistentAttribute.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - } - - protected void updatePersistenceUnitGenerators() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - } - - - // ************************************************************************* - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - @Override - public String getPrimaryKeyColumnName() { - return this.getColumn().getName(); - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public boolean isIdMapping() { - return true; - } - - //*********** Validation ************ - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addColumnMessages(messages, astRoot); - addGeneratedValueMessages(messages, astRoot); - addGeneratorMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaColumn column = this.getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && column.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, column.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, column.getNameTextRange(astRoot)) - ); - } - } - - protected void addGeneratedValueMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaGeneratedValue generatedValue = this.getGeneratedValue(); - if (generatedValue == null) { - return; - } - String generatorName = generatedValue.getGenerator(); - if (generatorName == null) { - return; - } - - for (Generator nextMasterGenerator : CollectionTools.iterable(getPersistenceUnit().allGenerators())) { - if (generatorName.equals(nextMasterGenerator.getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generatorName}, - this, - generatedValue.getGeneratorTextRange(astRoot)) - ); - } - - protected void addGeneratorMessages(List<IMessage> messages, CompilationUnit astRoot) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<JavaGenerator> stream = this.generators(); stream.hasNext() ; ) { - JavaGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange(astRoot)) - ); - } - } - - masterList.add(current); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumn.java deleted file mode 100644 index b6fa3a3aa5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumn.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public class GenericJavaJoinColumn extends AbstractJavaBaseColumn<JoinColumnAnnotation> implements JavaJoinColumn -{ - - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected JoinColumnAnnotation joinColumn; - - public GenericJavaJoinColumn(JavaJpaContextNode parent, JavaJoinColumn.Owner owner) { - super(parent, owner); - } - - @Override - protected JoinColumnAnnotation getColumnResource() { - return this.joinColumn; - } - - public String getReferencedColumnName() { - return (this.specifiedReferencedColumnName == null) ? this.defaultReferencedColumnName : this.specifiedReferencedColumnName; - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - this.joinColumn.setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - protected void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(BaseJoinColumn.DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - - @Override - public JavaJoinColumn.Owner getOwner() { - return (JavaJoinColumn.Owner) super.getOwner(); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public Table getDbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - public Column getDbReferencedColumn() { - Table table = this.getDbReferencedColumnTable(); - return (table == null) ? null : table.getColumnNamed(this.getReferencedColumnName()); - } - - @Override - public boolean tableIsAllowed() { - return this.getOwner().tableIsAllowed(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return getColumnResource().referencedColumnNameTouches(pos, astRoot); - } - - private Iterator<String> candidateReferencedColumnNames() { - Table table = this.getOwner().getDbReferencedColumnTable(); - return (table != null) ? table.columnNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateReferencedColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateReferencedColumnNames(), filter); - } - - private Iterator<String> quotedCandidateReferencedColumnNames(Filter<String> filter) { - return StringTools.quote(this.candidateReferencedColumnNames(filter)); - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.referencedColumnNameTouches(pos, astRoot)) { - return this.quotedCandidateReferencedColumnNames(filter); - } - return null; - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getReferencedColumnNameTextRange(astRoot); - return (textRange != null) ? textRange : getOwner().getValidationTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void initialize(JoinColumnAnnotation joinColumn) { - this.joinColumn = joinColumn; - super.initialize(joinColumn); - this.specifiedReferencedColumnName = joinColumn.getReferencedColumnName(); - this.defaultReferencedColumnName = this.defaultReferencedColumnName(); - } - - @Override - public void update(JoinColumnAnnotation joinColumn) { - this.joinColumn = joinColumn; - super.update(joinColumn); - this.setSpecifiedReferencedColumnName_(joinColumn.getReferencedColumnName()); - this.setDefaultReferencedColumnName(this.defaultReferencedColumnName()); - } - - @Override - protected String defaultName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultName(this); - } - - protected String defaultReferencedColumnName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultReferencedColumnName(this); - } - - @Override - protected String defaultTable() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return super.defaultTable(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTable.java deleted file mode 100644 index c6d9e299a4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTable.java +++ /dev/null @@ -1,736 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.resource.java.NullJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaJoinTable extends AbstractJavaTable implements JavaJoinTable -{ - protected final List<JavaJoinColumn> specifiedJoinColumns; - - protected JavaJoinColumn defaultJoinColumn; - - protected final List<JavaJoinColumn> specifiedInverseJoinColumns; - - protected JavaJoinColumn defaultInverseJoinColumn; - - protected JavaResourcePersistentAttribute attributeResource; - - public GenericJavaJoinTable(JavaRelationshipMapping parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<JavaJoinColumn>(); - this.specifiedInverseJoinColumns = new ArrayList<JavaJoinColumn>(); - } - - @Override - public JavaRelationshipMapping getParent() { - return (JavaRelationshipMapping) super.getParent(); - } - - //******************* AbstractJavaTable implementation ***************** - - @Override - protected String getAnnotationName() { - return JoinTableAnnotation.ANNOTATION_NAME; - } - - /** - * Default join table name from the JPA spec: - * The concatenated names of the two associated primary - * entity tables, separated by a underscore. - * - * [owning table name]_[target table name] - */ - @Override - protected String defaultName() { - return MappingTools.buildJoinTableDefaultName(getRelationshipMapping()); - } - - @Override - protected String defaultCatalog() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return super.defaultCatalog(); - } - - @Override - protected String defaultSchema() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return super.defaultSchema(); - } - - @Override - protected JoinTableAnnotation getTableResource() { - return (JoinTableAnnotation) this.attributeResource.getNonNullAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - /** - * Return the join table java resource, null if the annotation does not exist. - * Use tableResource() if you want a non null implementation - */ - protected JoinTableAnnotation getJoinTableResource() { - return (JoinTableAnnotation) this.attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - protected void addJoinTableResource() { - this.attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - - //******************* IJoinTable implementation ***************** - - public ListIterator<JavaJoinColumn> joinColumns() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public JavaJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(JavaJoinColumn newJoinColumn) { - JavaJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - protected ListIterator<JavaJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<JavaJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - JoinColumn oldDefaultJoinColumn = this.getDefaultJoinColumn(); - if (oldDefaultJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultJoinColumn = null; - } - if (getJoinTableResource() == null) { - //Add the JoinTable before creating the specifiedJoinColumn. - //Otherwise we will remove it and create another during an update - //from the java resource model - addJoinTableResource(); - } - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - JoinColumnAnnotation joinColumnResource = this.getTableResource().addJoinColumn(index); - joinColumn.initialize(joinColumnResource); - this.fireItemAdded(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, oldDefaultJoinColumn, null); - } - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = buildJoinColumn(new NullJoinColumn(getTableResource())); - } - this.getTableResource().removeJoinColumn(index); - fireItemRemoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getTableResource().moveJoinColumn(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public ListIterator<JavaJoinColumn> inverseJoinColumns() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumns() : this.defaultInverseJoinColumns(); - } - - public int inverseJoinColumnsSize() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumnsSize() : this.defaultInverseJoinColumnsSize(); - } - - public JavaJoinColumn getDefaultInverseJoinColumn() { - return this.defaultInverseJoinColumn; - } - - protected void setDefaultInverseJoinColumn(JavaJoinColumn newInverseJoinColumn) { - JavaJoinColumn oldInverseJoinColumn = this.defaultInverseJoinColumn; - this.defaultInverseJoinColumn = newInverseJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, oldInverseJoinColumn, newInverseJoinColumn); - } - - protected ListIterator<JavaJoinColumn> defaultInverseJoinColumns() { - if (this.defaultInverseJoinColumn != null) { - return new SingleElementListIterator<JavaJoinColumn>(this.defaultInverseJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultInverseJoinColumnsSize() { - return (this.defaultInverseJoinColumn == null) ? 0 : 1; - } - - public ListIterator<JavaJoinColumn> specifiedInverseJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedInverseJoinColumns); - } - - public int specifiedInverseJoinColumnsSize() { - return this.specifiedInverseJoinColumns.size(); - } - - public boolean containsSpecifiedInverseJoinColumns() { - return !this.specifiedInverseJoinColumns.isEmpty(); - } - - public JavaJoinColumn addSpecifiedInverseJoinColumn(int index) { - JoinColumn oldDefaultInverseJoinColumn = this.getDefaultInverseJoinColumn(); - if (oldDefaultInverseJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultInverseJoinColumn = null; - } - if (getJoinTableResource() == null) { - //Add the JoinTable before creating the specifiedJoinColumn. - //Otherwise we will remove it and create another during an update - //from the java resource model - addJoinTableResource(); - } - JavaJoinColumn inverseJoinColumn = getJpaFactory().buildJavaJoinColumn(this, createInverseJoinColumnOwner()); - this.specifiedInverseJoinColumns.add(index, inverseJoinColumn); - JoinColumnAnnotation joinColumnResource = this.getTableResource().addInverseJoinColumn(index); - inverseJoinColumn.initialize(joinColumnResource); - this.fireItemAdded(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, inverseJoinColumn); - if (oldDefaultInverseJoinColumn != null) { - this.firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, oldDefaultInverseJoinColumn, null); - } - return inverseJoinColumn; - } - - protected void addSpecifiedInverseJoinColumn(int index, JavaJoinColumn inverseJoinColumn) { - addItemToList(index, inverseJoinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedInverseJoinColumn(JoinColumn inverseJoinColumn) { - this.removeSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.indexOf(inverseJoinColumn)); - } - - public void removeSpecifiedInverseJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedInverseJoinColumns.remove(index); - if (!containsSpecifiedInverseJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultInverseJoinColumn = buildInverseJoinColumn(new NullJoinColumn(getTableResource())); - } - this.getTableResource().removeInverseJoinColumn(index); - fireItemRemoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultInverseJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, null, this.defaultInverseJoinColumn); - } - } - - protected void removeSpecifiedInverseJoinColumn_(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedInverseJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedInverseJoinColumns, targetIndex, sourceIndex); - this.getTableResource().moveInverseJoinColumn(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - public RelationshipMapping getRelationshipMapping() { - return this.getParent(); - } - - public boolean isSpecified() { - return getJoinTableResource() != null; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaJoinColumn column : CollectionTools.iterable(this.joinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaJoinColumn column : CollectionTools.iterable(this.inverseJoinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - protected JavaJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected JavaJoinColumn.Owner createInverseJoinColumnOwner() { - return new InverseJoinColumnOwner(); - } - - public void initialize(JavaResourcePersistentAttribute attributeResource) { - this.attributeResource = attributeResource; - JoinTableAnnotation joinTable = getTableResource(); - this.initialize(joinTable); - this.initializeSpecifiedJoinColumns(joinTable); - this.initializeDefaultJoinColumn(joinTable); - this.initializeSpecifiedInverseJoinColumns(joinTable); - this.initializeDefaultInverseJoinColumn(joinTable); - } - - protected void initializeSpecifiedJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JoinColumnAnnotation> annotations = joinTableResource.joinColumns(); - - while(annotations.hasNext()) { - this.specifiedJoinColumns.add(buildJoinColumn(annotations.next())); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns() && getRelationshipMapping().isRelationshipOwner(); - } - - protected void initializeDefaultJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(new NullJoinColumn(joinTable)); - } - - protected void initializeSpecifiedInverseJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JoinColumnAnnotation> annotations = joinTableResource.inverseJoinColumns(); - - while(annotations.hasNext()) { - this.specifiedInverseJoinColumns.add(buildInverseJoinColumn(annotations.next())); - } - } - - protected boolean shouldBuildDefaultInverseJoinColumn() { - return !containsSpecifiedInverseJoinColumns() && getRelationshipMapping().isRelationshipOwner(); - } - - protected void initializeDefaultInverseJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultInverseJoinColumn()) { - return; - } - this.defaultInverseJoinColumn = buildInverseJoinColumn(new NullJoinColumn(joinTable)); - } - - public void update(JavaResourcePersistentAttribute attributeResource) { - this.attributeResource = attributeResource; - JoinTableAnnotation joinTable = getTableResource(); - this.update(joinTable); - this.updateSpecifiedJoinColumns(joinTable); - this.updateDefaultJoinColumn(joinTable); - this.updateSpecifiedInverseJoinColumns(joinTable); - this.updateDefaultInverseJoinColumn(joinTable); - } - - protected void updateSpecifiedJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<JoinColumnAnnotation> resourceJoinColumns = joinTableResource.joinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn(resourceJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(new NullJoinColumn(joinTable))); - } - else { - this.defaultJoinColumn.update(new NullJoinColumn(joinTable)); - } - } - - protected void updateSpecifiedInverseJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JavaJoinColumn> joinColumns = specifiedInverseJoinColumns(); - ListIterator<JoinColumnAnnotation> resourceJoinColumns = joinTableResource.inverseJoinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedInverseJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedInverseJoinColumn(specifiedInverseJoinColumnsSize(), buildInverseJoinColumn(resourceJoinColumns.next())); - } - } - - protected void updateDefaultInverseJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultInverseJoinColumn()) { - setDefaultInverseJoinColumn(null); - return; - } - if (getDefaultInverseJoinColumn() == null) { - this.setDefaultInverseJoinColumn(buildInverseJoinColumn(new NullJoinColumn(joinTable))); - } - else { - this.defaultInverseJoinColumn.update(new NullJoinColumn(joinTable)); - } - } - - protected JavaJoinColumn buildJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - joinColumn.initialize(joinColumnResource); - return joinColumn; - } - - protected JavaJoinColumn buildInverseJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createInverseJoinColumnOwner()); - joinColumn.initialize(joinColumnResource); - return joinColumn; - } - - - //********************* validation ******************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - boolean doContinue = connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && !isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange(astRoot)) - ); - doContinue = false; - } - - for (Iterator<JavaJoinColumn> stream = joinColumns(); stream.hasNext(); ) { - JavaJoinColumn joinColumn = stream.next(); - - if (doContinue && ! joinColumn.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, joinColumn.getNameTextRange(astRoot)) - ); - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - - for (Iterator<JavaJoinColumn> stream = inverseJoinColumns(); stream.hasNext(); ) { - JavaJoinColumn joinColumn = stream.next(); - - if (doContinue && ! joinColumn.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, joinColumn.getNameTextRange(astRoot)) - ); - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - } - - /** - * just a little common behavior - */ - abstract class AbstractJoinColumnOwner implements JavaJoinColumn.Owner - { - AbstractJoinColumnOwner() { - super(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericJavaJoinTable.this.getRelationshipMapping(); - } - - /** - * the default table name is always valid and a specified table name - * is prohibited (which will be handled elsewhere) - */ - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - /** - * the join column can only be on the join table itself - */ - public boolean tableIsAllowed() { - return false; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - if (GenericJavaJoinTable.this.getName() == null) { - return null; - } - return (GenericJavaJoinTable.this.getName().equals(tableName)) ? GenericJavaJoinTable.this.getDbTable() : null; - } - - /** - * by default, the join column is, obviously, in the join table; - * not sure whether it can be anywhere else... - */ - public String getDefaultTableName() { - return GenericJavaJoinTable.this.getName(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaJoinTable.this.getValidationTextRange(astRoot); - } - } - - - /** - * owner for "forward-pointer" JoinColumns; - * these point at the target/inverse entity - */ - class InverseJoinColumnOwner extends AbstractJoinColumnOwner - { - public InverseJoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericJavaJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericJavaJoinTable.this.getRelationshipMapping().getPersistentAttribute().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - if (dbTable != null) { - return dbTable; - } - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaJoinTable.this.defaultInverseJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericJavaJoinTable.this.inverseJoinColumnsSize(); - } - } - - - /** - * owner for "back-pointer" JoinColumns; - * these point at the source/owning entity - */ - class JoinColumnOwner extends AbstractJoinColumnOwner - { - public JoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericJavaJoinTable.this.getRelationshipMapping().getEntity(); - } - - public String getAttributeName() { - Entity targetEntity = GenericJavaJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - String attributeName = GenericJavaJoinTable.this.getRelationshipMapping().getPersistentAttribute().getName(); - for (Iterator<PersistentAttribute> stream = targetEntity.getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - AttributeMapping mapping = attribute.getMapping(); - if (mapping instanceof NonOwningMapping) { - String mappedBy = ((NonOwningMapping) mapping).getMappedBy(); - if ((mappedBy != null) && mappedBy.equals(attributeName)) { - return attribute.getName(); - } - } - } - return null; - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - return (dbTable != null) ? dbTable : this.getTypeMapping().getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaJoinTable.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericJavaJoinTable.this.joinColumnsSize(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyMapping.java deleted file mode 100644 index 3d9bf0eebe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyMapping.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaManyToManyMapping extends AbstractJavaMultiRelationshipMapping<ManyToManyAnnotation> - implements JavaManyToManyMapping -{ - - public GenericJavaManyToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return ManyToManyAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ORDER_BY, - JPA.MAP_KEY, - JPA.JOIN_TABLE); - } - - // ********** JavaMultiRelationshipMapping implementation ********** - - @Override - protected boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.getMappingResource().mappedByTouches(pos, astRoot); - } - - - @Override - protected void setMappedByOnResourceModel(String mappedBy) { - getMappingResource().setMappedBy(mappedBy); - } - - @Override - protected String mappedBy(ManyToManyAnnotation relationshipMapping) { - return relationshipMapping.getMappedBy(); - } - - // ********** INonOwningMapping implementation ********** - - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - - @Override - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getMappingResource().getMappedByTextRange(astRoot); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneMapping.java deleted file mode 100644 index c11ca44d2c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneMapping.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaManyToOneMapping extends AbstractJavaSingleRelationshipMapping<ManyToOneAnnotation> - implements JavaManyToOneMapping -{ - - public GenericJavaManyToOneMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS, - JPA.JOIN_TABLE); - } - - public String getAnnotationName() { - return ManyToOneAnnotation.ANNOTATION_NAME; - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - @Override - protected void setOptionalOnResourceModel(Boolean newOptional) { - this.getMappingResource().setOptional(newOptional); - } - - @Override - protected Boolean specifiedOptional(ManyToOneAnnotation relationshipMapping) { - return relationshipMapping.getOptional(); - } - - //ManyToOne mapping is always the owning side - public boolean isRelationshipOwner() { - return true; - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedSuperclass.java deleted file mode 100644 index e9173c236c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedSuperclass.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -public class GenericJavaMappedSuperclass extends AbstractJavaTypeMapping - implements JavaMappedSuperclass -{ - - protected String idClass; - - public GenericJavaMappedSuperclass(JavaPersistentType parent) { - super(parent); - } - - public boolean isMapped() { - return true; - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return MappedSuperclassAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ID_CLASS, - JPA.EXCLUDE_DEFAULT_LISTENERS, - JPA.EXCLUDE_SUPERCLASS_LISTENERS, - JPA.ENTITY_LISTENERS, - JPA.PRE_PERSIST, - JPA.POST_PERSIST, - JPA.PRE_REMOVE, - JPA.POST_REMOVE, - JPA.PRE_UPDATE, - JPA.POST_UPDATE, - JPA.POST_LOAD); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (newIdClass != oldIdClass) { - if (newIdClass != null) { - if (getIdClassResource() == null) { - addIdClassResource(); - } - getIdClassResource().setValue(newIdClass); - } - else { - removeIdClassResource(); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected IdClassAnnotation getIdClassResource() { - return (IdClassAnnotation) this.javaResourcePersistentType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void addIdClassResource() { - this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void removeIdClassResource() { - this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - @Override - public Iterator<String> overridableAttributeNames() { - return this.namesOf(this.overridableAttributes()); - } - - @Override - public Iterator<JavaPersistentAttribute> overridableAttributes() { - return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(JavaPersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - @Override - public Iterator<String> overridableAssociationNames() { - return this.namesOf(this.overridableAssociations()); - } - - @Override - public Iterator<JavaPersistentAttribute> overridableAssociations() { - return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(JavaPersistentAttribute o) { - return o.isOverridableAssociation(); - } - }; - } - - protected Iterator<String> namesOf(Iterator<JavaPersistentAttribute> attributes) { - return new TransformationIterator<JavaPersistentAttribute, String>(attributes) { - @Override - protected String transform(JavaPersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - @Override - public void initialize(JavaResourcePersistentType persistentTypeResource) { - super.initialize(persistentTypeResource); - this.initializeIdClass(persistentTypeResource); - } - - protected void initializeIdClass(JavaResourcePersistentType typeResource) { - IdClassAnnotation idClassResource = (IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (idClassResource != null) { - this.idClass = idClassResource.getValue(); - } - } - - @Override - public void update(JavaResourcePersistentType persistentTypeResource) { - super.update(persistentTypeResource); - this.updateIdClass(persistentTypeResource); - } - - protected void updateIdClass(JavaResourcePersistentType typeResource) { - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (idClass != null) { - setIdClass_(idClass.getValue()); - } - else { - setIdClass_(null); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedNativeQuery.java deleted file mode 100644 index 1a1fb649fa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedNativeQuery.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; - - -public class GenericJavaNamedNativeQuery extends AbstractJavaQuery - implements JavaNamedNativeQuery -{ - - protected String resultClass; - - protected String resultSetMapping; - - public GenericJavaNamedNativeQuery(JavaJpaContextNode parent) { - super(parent); - } - - @Override - protected NamedNativeQueryAnnotation getQueryResource() { - return (NamedNativeQueryAnnotation) super.getQueryResource(); - } - - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - getQueryResource().setResultClass(newResultClass); - firePropertyChanged(NamedNativeQuery.RESULT_CLASS_PROPERTY, oldResultClass, newResultClass); - } - - protected void setResultClass_(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - firePropertyChanged(NamedNativeQuery.RESULT_CLASS_PROPERTY, oldResultClass, newResultClass); - } - - public String getResultSetMapping() { - return this.resultSetMapping; - } - - public void setResultSetMapping(String newResultSetMapping) { - String oldResultSetMapping = this.resultSetMapping; - this.resultSetMapping = newResultSetMapping; - getQueryResource().setResultSetMapping(newResultSetMapping); - firePropertyChanged(NamedNativeQuery.RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - protected void setResultSetMapping_(String newResultSetMapping) { - String oldResultSetMapping = this.resultSetMapping; - this.resultSetMapping = newResultSetMapping; - firePropertyChanged(NamedNativeQuery.RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - public void initialize(NamedNativeQueryAnnotation queryResource) { - super.initialize(queryResource); - this.resultClass = queryResource.getResultClass(); - this.resultSetMapping = queryResource.getResultSetMapping(); - } - - public void update(NamedNativeQueryAnnotation queryResource) { - super.update(queryResource); - this.setResultClass_(queryResource.getResultClass()); - this.setResultSetMapping_(queryResource.getResultSetMapping()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedQuery.java deleted file mode 100644 index c604553633..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedQuery.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; - - - -public class GenericJavaNamedQuery extends AbstractJavaQuery implements JavaNamedQuery -{ - - public GenericJavaNamedQuery(JavaJpaContextNode parent) { - super(parent); - } - - @Override - protected NamedQueryAnnotation getQueryResource() { - return (NamedQueryAnnotation) super.getQueryResource(); - } - - public void initialize(NamedQueryAnnotation queryResource) { - super.initialize(queryResource); - } - - public void update(NamedQueryAnnotation queryResource) { - super.update(queryResource); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNullAttributeMapping.java deleted file mode 100644 index badb692ade..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNullAttributeMapping.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - - -public class GenericJavaNullAttributeMapping extends AbstractJavaAttributeMapping<JavaResourceNode> -{ - public GenericJavaNullAttributeMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return null; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - @Override - protected JavaResourceNode getMappingResource() { - return null; - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToManyMapping.java deleted file mode 100644 index d5682df714..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToManyMapping.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaOneToManyMapping extends AbstractJavaMultiRelationshipMapping<OneToManyAnnotation> - implements JavaOneToManyMapping -{ - - public GenericJavaOneToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ORDER_BY, - JPA.MAP_KEY, - JPA.JOIN_TABLE, - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS); - } - - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return OneToManyAnnotation.ANNOTATION_NAME; - } - - // ********** JavaMultiRelationshipMapping implementation ********** - - @Override - protected boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.getMappingResource().mappedByTouches(pos, astRoot); - } - - @Override - protected void setMappedByOnResourceModel(String mappedBy) { - this.getMappingResource().setMappedBy(mappedBy); - } - - @Override - protected String mappedBy(OneToManyAnnotation relationshipMapping) { - return relationshipMapping.getMappedBy(); - } - - - // ********** INonOwningMapping implementation ********** - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - @Override - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getMappingResource().getMappedByTextRange(astRoot); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneMapping.java deleted file mode 100644 index a18e3b740d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneMapping.java +++ /dev/null @@ -1,308 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaOneToOneMapping extends AbstractJavaSingleRelationshipMapping<OneToOneAnnotation> - implements JavaOneToOneMapping -{ - protected String mappedBy; - - protected final List<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns; - - public GenericJavaOneToOneMapping(JavaPersistentAttribute parent) { - super(parent); - this.primaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.PRIMARY_KEY_JOIN_COLUMN, - JPA.PRIMARY_KEY_JOIN_COLUMNS, - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS, - JPA.JOIN_TABLE); - } - - public String getAnnotationName() { - return OneToOneAnnotation.ANNOTATION_NAME; - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - - public ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return new CloneListIterator<JavaPrimaryKeyJoinColumn>(this.primaryKeyJoinColumns); - } - - public int primaryKeyJoinColumnsSize() { - return this.primaryKeyJoinColumns.size(); - } - - public JavaPrimaryKeyJoinColumn addPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn pkJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createJoinColumnOwner()); - this.primaryKeyJoinColumns.add(index, pkJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) getResourcePersistentAttribute().addAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - pkJoinColumn.initialize(pkJoinColumnResource); - this.fireItemAdded(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, pkJoinColumn); - return pkJoinColumn; - } - - protected void addPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void removePrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removePrimaryKeyJoinColumn(this.primaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removePrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn removedPkJoinColumn = this.primaryKeyJoinColumns.remove(index); - getResourcePersistentAttribute().removeAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - fireItemRemoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, removedPkJoinColumn); - } - - protected void removePrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void movePrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.primaryKeyJoinColumns, targetIndex, sourceIndex); - getResourcePersistentAttribute().move(targetIndex, sourceIndex, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - fireItemMoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public boolean containsPrimaryKeyJoinColumns() { - return !this.primaryKeyJoinColumns.isEmpty(); - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - this.getMappingResource().setMappedBy(newMappedBy); - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - @Override - protected void setOptionalOnResourceModel(Boolean newOptional) { - this.getMappingResource().setOptional(newOptional); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getMappingResource().getMappedByTextRange(astRoot); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.getMappingResource().mappedByTouches(pos, astRoot); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.mappedByTouches(pos, astRoot)) { - return this.quotedCandidateMappedByAttributeNames(filter); - } - return null; - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - @Override - protected void initialize(OneToOneAnnotation oneToOneResource) { - super.initialize(oneToOneResource); - this.mappedBy = oneToOneResource.getMappedBy(); - } - - @Override - protected Boolean specifiedOptional(OneToOneAnnotation oneToOneResource) { - return oneToOneResource.getOptional(); - } - - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initialize(resourcePersistentAttribute); - this.initializePrimaryKeyJoinColumns(resourcePersistentAttribute); - } - - protected void initializePrimaryKeyJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaResourceNode> annotations = resourcePersistentAttribute.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.primaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) annotations.next())); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource) { - JavaPrimaryKeyJoinColumn pkJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createJoinColumnOwner()); - pkJoinColumn.initialize(primaryKeyJoinColumnResource); - return pkJoinColumn; - } - - @Override - protected void update(OneToOneAnnotation oneToOneResource) { - super.update(oneToOneResource); - this.setMappedBy_(oneToOneResource.getMappedBy()); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.updatePrimaryKeyJoinColumns(resourcePersistentAttribute); - } - - protected void updatePrimaryKeyJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaPrimaryKeyJoinColumn> pkJoinColumns = primaryKeyJoinColumns(); - ListIterator<JavaResourceNode> resourcePkJoinColumns = resourcePersistentAttribute.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - while (pkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn pkJoinColumn = pkJoinColumns.next(); - if (resourcePkJoinColumns.hasNext()) { - pkJoinColumn.update((PrimaryKeyJoinColumnAnnotation) resourcePkJoinColumns.next()); - } - else { - removePrimaryKeyJoinColumn_(pkJoinColumn); - } - } - - while (resourcePkJoinColumns.hasNext()) { - addPrimaryKeyJoinColumn(specifiedJoinColumnsSize(), buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) resourcePkJoinColumns.next())); - } - } - - - - //***************** Validation *********************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (this.getMappedBy() != null) { - addMappedByMessages(messages ,astRoot); - } - } - - @Override - protected boolean addJoinColumnMessages() { - if (containsPrimaryKeyJoinColumns() && !containsSpecifiedJoinColumns()) { - return false; - } - return super.addJoinColumnMessages(); - } - - protected void addMappedByMessages(List<IMessage> messages, CompilationUnit astRoot) { - String mappedBy = this.getMappedBy(); - Entity targetEntity = this.getResolvedTargetEntity(); - - if (targetEntity == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange(astRoot)) - ); - return; - } - - if (! this.mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange(astRoot)) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, this.getMappedByTextRange(astRoot)) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java deleted file mode 100644 index 501f2513af..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java +++ /dev/null @@ -1,328 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaPersistentAttribute extends AbstractJavaJpaContextNode - implements JavaPersistentAttribute -{ - protected String name; - - protected JavaAttributeMapping defaultMapping; - - protected JavaAttributeMapping specifiedMapping; - - protected JavaResourcePersistentAttribute resourcePersistentAttribute; - - public GenericJavaPersistentAttribute(JavaPersistentType parent) { - super(parent); - } - - public String getId() { - return JavaStructureNodes.PERSISTENT_ATTRIBUTE_ID; - } - - public void initialize(JavaResourcePersistentAttribute persistentAttributeResource) { - this.resourcePersistentAttribute = persistentAttributeResource; - this.name = this.name(persistentAttributeResource); - initializeDefaultMapping(persistentAttributeResource); - initializeSpecifiedMapping(persistentAttributeResource); - } - - protected void initializeDefaultMapping(JavaResourcePersistentAttribute persistentAttributeResource) { - this.defaultMapping = getJpaPlatform().buildDefaultJavaAttributeMapping(this); - this.defaultMapping.initialize(persistentAttributeResource); - } - - protected void initializeSpecifiedMapping(JavaResourcePersistentAttribute persistentAttributeResource) { - String javaMappingAnnotationName = this.javaMappingAnnotationName(persistentAttributeResource); - this.specifiedMapping = createJavaAttributeMappingFromAnnotation(javaMappingAnnotationName, persistentAttributeResource); - } - - public JavaResourcePersistentAttribute getResourcePersistentAttribute() { - return this.resourcePersistentAttribute; - } - - public JavaPersistentType getPersistentType() { - return (JavaPersistentType) this.getParent(); - } - - public JavaTypeMapping getTypeMapping() { - return this.getPersistentType().getMapping(); - } - - public String getPrimaryKeyColumnName() { - return this.getMapping().getPrimaryKeyColumnName(); - } - - public boolean isOverridableAttribute() { - return this.getMapping().isOverridableAttributeMapping(); - } - - public boolean isOverridableAssociation() { - return this.getMapping().isOverridableAssociationMapping(); - } - - public boolean isIdAttribute() { - return this.getMapping().isIdMapping(); - } - - public boolean isVirtual() { - return false; - } - - public String getName() { - return this.name; - } - - protected void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public JavaAttributeMapping getDefaultMapping() { - return this.defaultMapping; - } - - /** - * clients do not set the "default" mapping - */ - protected void setDefaultMapping(JavaAttributeMapping newDefaultMapping) { - JavaAttributeMapping oldMapping = this.defaultMapping; - this.defaultMapping = newDefaultMapping; - firePropertyChanged(PersistentAttribute.DEFAULT_MAPPING_PROPERTY, oldMapping, newDefaultMapping); - } - - public JavaAttributeMapping getSpecifiedMapping() { - return this.specifiedMapping; - } - - /** - * clients do not set the "specified" mapping; - * use #setMappingKey(String) - */ - protected void setSpecifiedMapping(JavaAttributeMapping newSpecifiedMapping) { - JavaAttributeMapping oldMapping = this.specifiedMapping; - this.specifiedMapping = newSpecifiedMapping; - firePropertyChanged(PersistentAttribute.SPECIFIED_MAPPING_PROPERTY, oldMapping, newSpecifiedMapping); - } - - - public JavaAttributeMapping getMapping() { - return (this.specifiedMapping != null) ? this.specifiedMapping : this.defaultMapping; - } - - public String getMappingKey() { - return this.getMapping().getKey(); - } - - /** - * return null if there is no "default" mapping for the attribute - */ - public String getDefaultMappingKey() { - return this.defaultMapping.getKey(); - } - - /** - * return null if there is no "specified" mapping for the attribute - */ - public String getSpecifiedMappingKey() { - return (this.specifiedMapping == null) ? null : this.specifiedMapping.getKey(); - } - - // TODO support morphing mappings, i.e. copying common settings over - // to the new mapping; this can't be done in the same was as XmlAttributeMapping - // since we don't know all the possible mapping types - public void setSpecifiedMappingKey(String newKey) { - if (newKey == getSpecifiedMappingKey()) { - return; - } - JavaAttributeMapping oldMapping = getMapping(); - JavaAttributeMapping newMapping = createJavaAttributeMappingFromMappingKey(newKey); - - this.specifiedMapping = newMapping; - if (newMapping != null) { - this.resourcePersistentAttribute.setMappingAnnotation(newMapping.getAnnotationName()); - } - else { - this.resourcePersistentAttribute.setMappingAnnotation(null); - } - firePropertyChanged(PersistentAttribute.SPECIFIED_MAPPING_PROPERTY, oldMapping, newMapping); - - if (oldMapping != null) { - Collection<String> annotationsToRemove = CollectionTools.collection(oldMapping.correspondingAnnotationNames()); - if (getMapping() != null) { - CollectionTools.removeAll(annotationsToRemove, getMapping().correspondingAnnotationNames()); - } - - for (String annotationName : annotationsToRemove) { - this.resourcePersistentAttribute.removeAnnotation(annotationName); - } - } - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public boolean contains(int offset, CompilationUnit astRoot) { - TextRange fullTextRange = this.getFullTextRange(astRoot); - // 'fullTextRange' will be null if the attribute no longer exists in the java; - // the context model can be out of synch with the resource model - // when a selection event occurs before the context model has a - // chance to synch with the resource model via the update thread - return (fullTextRange == null) ? false : fullTextRange.includes(offset); - } - - - public TextRange getFullTextRange(CompilationUnit astRoot) { - return this.resourcePersistentAttribute.getTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - public TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.resourcePersistentAttribute.getNameTextRange(astRoot); - } - - public TextRange getSelectionTextRange() { - return getSelectionTextRange(this.buildASTRoot()); - } - - protected CompilationUnit buildASTRoot() { - return JDTTools.buildASTRoot(this.resourcePersistentAttribute.getJpaCompilationUnit().getCompilationUnit()); - } - - public void update(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistentAttribute = jrpa; - this.setName(this.name(jrpa)); - this.updateDefaultMapping(jrpa); - this.updateSpecifiedMapping(jrpa); - } - - protected String name(JavaResourcePersistentAttribute jrpa) { - return jrpa.getName(); - } - - public String specifiedMappingAnnotationName() { - return (this.specifiedMapping == null) ? null : this.specifiedMapping.getAnnotationName(); - } - - protected void updateSpecifiedMapping(JavaResourcePersistentAttribute jrpa) { - String javaMappingAnnotationName = this.javaMappingAnnotationName(jrpa); - if (specifiedMappingAnnotationName() != javaMappingAnnotationName) { - setSpecifiedMapping(createJavaAttributeMappingFromAnnotation(javaMappingAnnotationName, jrpa)); - } - else { - if (getSpecifiedMapping() != null) { - getSpecifiedMapping().update(jrpa); - } - } - } - - protected void updateDefaultMapping(JavaResourcePersistentAttribute jrpa) { - String defaultMappingKey = getJpaPlatform().getDefaultJavaAttributeMappingKey(this); - if (getDefaultMapping().getKey() != defaultMappingKey) { - JavaAttributeMapping oldDefaultMapping = this.defaultMapping; - this.defaultMapping = getJpaPlatform().buildDefaultJavaAttributeMapping(this); - this.defaultMapping.initialize(jrpa); - firePropertyChanged(PersistentAttribute.DEFAULT_MAPPING_PROPERTY, oldDefaultMapping, this.defaultMapping); - } - else { - getDefaultMapping().update(jrpa); - } - } - - protected String javaMappingAnnotationName(JavaResourcePersistentAttribute jrpa) { - Annotation mappingAnnotation = (Annotation) jrpa.getMappingAnnotation(); - if (mappingAnnotation != null) { - return mappingAnnotation.getAnnotationName(); - } - return null; - } - - protected JavaAttributeMapping createJavaAttributeMappingFromMappingKey(String key) { - if (key == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - return null; - } - return getJpaPlatform().buildJavaAttributeMappingFromMappingKey(key, this); - } - - protected JavaAttributeMapping createJavaAttributeMappingFromAnnotation(String annotationName, JavaResourcePersistentAttribute jrpa) { - if (annotationName == null) { - return null; - } - JavaAttributeMapping mapping = getJpaPlatform().buildJavaAttributeMappingFromAnnotation(annotationName, this); - mapping.initialize(jrpa); - return mapping; - } - - /** - * the mapping might be "default", but it still might be a "null" mapping... - */ - public boolean mappingIsDefault(JavaAttributeMapping mapping) { - return this.defaultMapping == mapping; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return this.getMapping().javaCompletionProposals(pos, filter, astRoot); - } - - //************* Validation ****************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (this.specifiedMapping != null) { - this.specifiedMapping.addToMessages(messages, astRoot); - } - else if (this.defaultMapping != null) { - this.defaultMapping.addToMessages(messages, astRoot); - } - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - //nothing to dispose - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java deleted file mode 100644 index d53acf6da8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java +++ /dev/null @@ -1,526 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ChainIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implements JavaPersistentType -{ - protected String name; - - protected JavaTypeMapping mapping; - - protected final List<JavaPersistentAttribute> attributes; - - protected AccessType access; - - protected PersistentType parentPersistentType; - - protected JavaResourcePersistentType resourcePersistentType; - - public GenericJavaPersistentType(JpaContextNode parent, JavaResourcePersistentType resourcePersistentType) { - super(parent); - this.attributes = new ArrayList<JavaPersistentAttribute>(); - this.initialize(resourcePersistentType); - } - - @Override - public IResource getResource() { - return this.resourcePersistentType.getResourceModel().getJpaCompilationUnit().getCompilationUnit().getResource(); - } - - //****************** JpaStructureNode implementation ******************* - - public String getId() { - return JavaStructureNodes.PERSISTENT_TYPE_ID; - } - - //****************** PersistentType implementation ******************* - public String getName() { - return this.name; - } - - protected void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public JavaTypeMapping getMapping() { - return this.mapping; - } - - public String getMappingKey() { - return getMapping().getKey(); - } - - public void setMappingKey(String key) { - if (key == getMapping().getKey()) { - return; - } - JavaTypeMapping oldMapping = getMapping(); - JavaTypeMapping newMapping = createJavaTypeMappingFromMappingKey(key); - - this.mapping = newMapping; - this.resourcePersistentType.setMappingAnnotation(newMapping.getAnnotationName()); - firePropertyChanged(PersistentType.MAPPING_PROPERTY, oldMapping, newMapping); - - if (oldMapping != null) { - Collection<String> annotationsToRemove = CollectionTools.collection(oldMapping.correspondingAnnotationNames()); - if (getMapping() != null) { - CollectionTools.removeAll(annotationsToRemove, getMapping().correspondingAnnotationNames()); - } - - for (String annotationName : annotationsToRemove) { - this.resourcePersistentType.removeAnnotation(annotationName); - } - } - } - - protected void setMapping(JavaTypeMapping newMapping) { - JavaTypeMapping oldMapping = this.mapping; - this.mapping = newMapping; - firePropertyChanged(PersistentType.MAPPING_PROPERTY, oldMapping, newMapping); - } - - public boolean isMapped() { - return getMapping().isMapped(); - } - - public AccessType getAccess() { - return this.access; - } - - protected void setAccess(AccessType newAccess) { - AccessType oldAccess = this.access; - this.access = newAccess; - firePropertyChanged(PersistentType.ACCESS_PROPERTY, oldAccess, newAccess); - } - - protected Iterator<JavaPersistentAttribute> attributesNamed(final String attributeName) { - return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(attributes()) { - @Override - protected boolean accept(JavaPersistentAttribute o) { - return attributeName.equals(o.getName()); - } - }; - } - - public JavaPersistentAttribute getAttributeNamed(String attributeName) { - Iterator<JavaPersistentAttribute> stream = attributesNamed(attributeName); - return (stream.hasNext()) ? stream.next() : null; - } - - public PersistentAttribute resolveAttribute(String attributeName) { - Iterator<JavaPersistentAttribute> stream = attributesNamed(attributeName); - if (stream.hasNext()) { - JavaPersistentAttribute attribute = stream.next(); - return (stream.hasNext()) ? null /*more than one*/: attribute; - } - return (getParentPersistentType() == null) ? null : getParentPersistentType().resolveAttribute(attributeName); - } - - public ListIterator<JavaPersistentAttribute> attributes() { - return new CloneListIterator<JavaPersistentAttribute>(this.attributes); - } - - public int attributesSize() { - return this.attributes.size(); - } - - private void addAttribute(JavaPersistentAttribute attribute) { - addItemToList(attribute, this.attributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - private void removeAttribute(JavaPersistentAttribute attribute) { - removeItemFromList(attribute, this.attributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - public Iterator<String> attributeNames() { - return this.attributeNames(this.attributes()); - } - - protected Iterator<String> attributeNames(Iterator<? extends PersistentAttribute> attrs) { - return new TransformationIterator<PersistentAttribute, String>(attrs) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<PersistentAttribute> allAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<PersistentType, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(PersistentType pt) { - return pt.attributes(); - } - }); - } - - public Iterator<String> allAttributeNames() { - return this.attributeNames(this.allAttributes()); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - Iterator<String> values = this.mapping.javaCompletionProposals(pos, filter, astRoot); - if (values != null) { - return values; - } - for (Iterator<JavaPersistentAttribute> stream = attributes(); stream.hasNext();) { - values = stream.next().javaCompletionProposals(pos, filter, astRoot); - if (values != null) { - return values; - } - } - return EmptyIterator.instance(); - } - - // it would be nice if the we passed in an astRoot here, but then we - // would need to pass it to the XML structure nodes too... - public JpaStructureNode getStructureNode(int offset) { - CompilationUnit astRoot = this.buildASTRoot(); - - if (this.contains(offset, astRoot)) { - for (Iterator<JavaPersistentAttribute> stream = this.attributes(); stream.hasNext();) { - JavaPersistentAttribute persistentAttribute = stream.next(); - if (persistentAttribute.contains(offset, astRoot)) { - return persistentAttribute; - } - } - return this; - } - return null; - } - - protected CompilationUnit buildASTRoot() { - return JDTTools.buildASTRoot(this.resourcePersistentType.getJpaCompilationUnit().getCompilationUnit()); - } - - public boolean contains(int offset, CompilationUnit astRoot) { - TextRange fullTextRange = this.getFullTextRange(astRoot); - // 'fullTextRange' will be null if the type no longer exists in the java; - // the context model can be out of synch with the resource model - // when a selection event occurs before the context model has a - // chance to synch with the resource model via the update thread - return (fullTextRange == null) ? false : fullTextRange.includes(offset); - } - - - protected TextRange getFullTextRange(CompilationUnit astRoot) { - return this.resourcePersistentType.getTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - public TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.resourcePersistentType.getNameTextRange(astRoot); - } - - public TextRange getSelectionTextRange() { - return this.getSelectionTextRange(this.buildASTRoot()); - } - - - public Iterator<PersistentType> inheritanceHierarchy() { - // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(this) { - @Override - protected PersistentType nextLink(PersistentType pt) { - return pt.getParentPersistentType(); - } - }; - } - - public PersistentType getParentPersistentType() { - return this.parentPersistentType; - } - - public void setParentPersistentType(PersistentType newParentPersistentType) { - if (attributeValueHasNotChanged(this.parentPersistentType, newParentPersistentType)) { - return; - } - PersistentType oldParentPersistentType = this.parentPersistentType; - this.parentPersistentType = newParentPersistentType; - firePropertyChanged(PersistentType.PARENT_PERSISTENT_TYPE_PROPERTY, oldParentPersistentType, newParentPersistentType); - } - - public boolean hasAnyAttributeMappingAnnotations() { - if (this.resourcePersistentType.hasAnyAttributeAnnotations()) { - return true; - } - return false; - } - - // ******************** Updating ********************** - protected void initialize(JavaResourcePersistentType jrpt) { - this.resourcePersistentType = jrpt; - this.parentPersistentType = this.parentPersistentType(jrpt); - this.access = this.access(jrpt); - this.name = this.name(jrpt); - this.initializeMapping(jrpt); - this.initializePersistentAttributes(jrpt); - } - - protected void initializeMapping(JavaResourcePersistentType persistentTypeResource) { - this.mapping = getJpaPlatform().buildJavaTypeMappingFromAnnotation(this.javaMappingAnnotationName(persistentTypeResource), this); - this.mapping.initialize(persistentTypeResource); - } - - protected void initializePersistentAttributes(JavaResourcePersistentType persistentTypeResource) { - Iterator<JavaResourcePersistentAttribute> resourceAttributes = persistentTypeResource.fields(); - if (getAccess() == AccessType.PROPERTY) { - resourceAttributes = persistentTypeResource.properties(); - } - - while (resourceAttributes.hasNext()) { - this.attributes.add(createAttribute(resourceAttributes.next())); - } - } - - public void update(JavaResourcePersistentType jrpt) { - this.resourcePersistentType = jrpt; - getJpaFile(this.resourcePersistentType.getResourceModel()).addRootStructureNode(this.resourcePersistentType.getQualifiedName(), this); - updateParentPersistentType(jrpt); - updateAccess(jrpt); - updateName(jrpt); - updateMapping(jrpt); - updatePersistentAttributes(jrpt); - } - - protected void updateAccess(JavaResourcePersistentType jrpt) { - this.setAccess(this.access(jrpt)); - } - - /** - * Check the access "specified" by the java resource model. - * Check xml mapping specified access first - * If still null check java annotations if the xml is not metadata-complete = true - * If still null then set to parentPersistentType access. - * If still null check entity-mappings specified access setting if this persistent-type is listed in an orm.xml file - * If still null check the persistence-unit default Access - * Default to FIELD if all else fails. - */ - protected AccessType access(JavaResourcePersistentType jrpt) { - AccessType javaAccess = null; - boolean metadataComplete = false; - if (getOrmPersistentType() != null) { - javaAccess = getOrmPersistentType().getMapping().getSpecifiedAccess(); - metadataComplete = getOrmPersistentType().getMapping().isMetadataComplete(); - } - if (javaAccess == null && !metadataComplete) { - javaAccess = AccessType.fromJavaResourceModel(jrpt.getAccess()); - } - if (javaAccess == null) { - if (getParentPersistentType() != null) { - javaAccess = getParentPersistentType().getAccess(); - } - } - if (javaAccess == null) { - if (getEntityMappings() != null) { - javaAccess = getEntityMappings().getAccess(); - } - } - if (javaAccess == null) { - //have to check persistence-unit separately in the case where it is not listed directly in an orm.xml - //if it is listed in an orm.xml then the entityMappings().getAccess() check will cover persistence-unit.defaultAccess - if (getPersistenceUnit() != null) { - javaAccess = getPersistenceUnit().getDefaultAccess(); - } - } - if (javaAccess == null) { - javaAccess = AccessType.FIELD; - } - return javaAccess; - } - - protected void updateName(JavaResourcePersistentType jrpt) { - this.setName(this.name(jrpt)); - } - - protected String name(JavaResourcePersistentType jrpt) { - return jrpt.getQualifiedName(); - } - - protected void updateMapping(JavaResourcePersistentType jrpt) { - String javaMappingAnnotationName = this.javaMappingAnnotationName(jrpt); - if (getMapping().getAnnotationName() != javaMappingAnnotationName) { - setMapping(createJavaTypeMappingFromAnnotation(javaMappingAnnotationName, jrpt)); - } - else { - getMapping().update(jrpt); - } - } - - protected JavaTypeMapping createJavaTypeMappingFromMappingKey(String key) { - return getJpaPlatform().buildJavaTypeMappingFromMappingKey(key, this); - } - - protected JavaTypeMapping createJavaTypeMappingFromAnnotation(String annotationName, JavaResourcePersistentType jrpt) { - JavaTypeMapping typeMapping = getJpaPlatform().buildJavaTypeMappingFromAnnotation(annotationName, this); - typeMapping.initialize(jrpt); - return typeMapping; - } - - protected String javaMappingAnnotationName(JavaResourcePersistentType jrpt) { - Annotation mappingAnnotation = (Annotation) jrpt.getMappingAnnotation(); - if (mappingAnnotation != null) { - return mappingAnnotation.getAnnotationName(); - } - return null; - } - - protected void updatePersistentAttributes(JavaResourcePersistentType jrpt) { - ListIterator<JavaPersistentAttribute> contextAttributes = attributes(); - Iterator<JavaResourcePersistentAttribute> resourceAttributes = jrpt.fields(); - if (getAccess() == AccessType.PROPERTY) { - resourceAttributes = jrpt.properties(); - } - - while (contextAttributes.hasNext()) { - JavaPersistentAttribute persistentAttribute = contextAttributes.next(); - if (resourceAttributes.hasNext()) { - persistentAttribute.update(resourceAttributes.next()); - } - else { - removeAttribute(persistentAttribute); - } - } - - while (resourceAttributes.hasNext()) { - addAttribute(createAttribute(resourceAttributes.next())); - } - } - - protected JavaPersistentAttribute createAttribute(JavaResourcePersistentAttribute persistentAttributeResource) { - JavaPersistentAttribute javaPersistentAttribute = getJpaFactory().buildJavaPersistentAttribute(this); - javaPersistentAttribute.initialize(persistentAttributeResource); - return javaPersistentAttribute; - } - - public void updateParentPersistentType(JavaResourcePersistentType persistentTypeResource) { - setParentPersistentType(parentPersistentType(persistentTypeResource)); - } - - protected PersistentType parentPersistentType(JavaResourcePersistentType persistentTypeResource) { - return parentPersistentType(persistentTypeResource.getSuperClassQualifiedName()); - } - - protected PersistentType parentPersistentType(String fullyQualifiedTypeName) { - PersistentType possibleParent = possibleParent(fullyQualifiedTypeName); - if (possibleParent == null) { - return null; - } - if (possibleParent.isMapped()) { - return possibleParent; - } - return possibleParent.getParentPersistentType(); - } - - /** - * JPA spec supports the case where there are non-persistent types in the hierarchy - * This will check for a PersistentType with the given name in this PersistenceUnit. - * If it is not found then find the JavaPersistentTypeResource and look for its parent type - */ - protected PersistentType possibleParent(String fullyQualifiedTypeName) { - PersistentType possibleParent = getPersistentType(fullyQualifiedTypeName); - if (possibleParent != null) { - return possibleParent; - } - JavaResourcePersistentType jrpt = getJpaProject().getJavaResourcePersistentType(fullyQualifiedTypeName); - return (jrpt == null) ? null : this.possibleParent(jrpt.getSuperClassQualifiedName()); - } - - protected PersistentType getPersistentType(String fullyQualifiedTypeName) { - return getPersistenceUnit().getPersistentType(fullyQualifiedTypeName); - } - - //*************** Validation ****************************************** - public void addToMessages(List<IMessage> messages) { - //get astRoot here to pass down - addToMessages(messages, this.buildASTRoot()); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - try { - this.mapping.addToMessages(messages, astRoot); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - addAttributeMessages(messages, astRoot); - } - - protected void addAttributeMessages(List<IMessage> messages, CompilationUnit astRoot) { - for (JavaPersistentAttribute persistentAttribute : this.attributes) { - try { - persistentAttribute.addToMessages(messages, astRoot); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - JpaFile jpaFile = getJpaFile(this.resourcePersistentType.getResourceModel()); - - if (jpaFile != null) { - //jpaFile can be null if the .java file was deleted, - //rootStructureNodes are cleared in the dispose of JpaFile - jpaFile.removeRootStructureNode(this.resourcePersistentType.getQualifiedName()); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumn.java deleted file mode 100644 index c8e54a6168..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public class GenericJavaPrimaryKeyJoinColumn extends AbstractJavaNamedColumn<PrimaryKeyJoinColumnAnnotation> - implements JavaPrimaryKeyJoinColumn -{ - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource; - - public GenericJavaPrimaryKeyJoinColumn(JavaJpaContextNode parent, JavaBaseJoinColumn.Owner owner) { - super(parent, owner); - } - - @Override - public void initialize(PrimaryKeyJoinColumnAnnotation column) { - this.primaryKeyJoinColumnResource = column; - super.initialize(column); - this.specifiedReferencedColumnName = this.specifiedReferencedColumnName(column); - this.defaultReferencedColumnName = this.defaultReferencedColumnName(); - } - - //************** JavaNamedColumn implementation *************** - @Override - public JavaBaseJoinColumn.Owner getOwner() { - return (JavaBaseJoinColumn.Owner) super.getOwner(); - } - - @Override - protected PrimaryKeyJoinColumnAnnotation getColumnResource() { - return this.primaryKeyJoinColumnResource; - } - - //************** IAbstractJoinColumn implementation *************** - - public String getReferencedColumnName() { - return (this.specifiedReferencedColumnName == null) ? this.defaultReferencedColumnName : this.specifiedReferencedColumnName; - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - getColumnResource().setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - protected void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - @Override - protected String getTableName() { - return this.getOwner().getTypeMapping().getTableName(); - } - - public Column getDbReferencedColumn() { - Table table = this.getDbReferencedColumnTable(); - return (table == null) ? null : table.getColumnNamed(this.getReferencedColumnName()); - } - - public Table getDbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.getColumnResource().referencedColumnNameTouches(pos, astRoot); - } - - private Iterator<String> candidateReferencedColumnNames() { - Table table = this.getOwner().getDbReferencedColumnTable(); - return (table != null) ? table.columnNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateReferencedColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateReferencedColumnNames(), filter); - } - - private Iterator<String> quotedCandidateReferencedColumnNames(Filter<String> filter) { - return StringTools.quote(this.candidateReferencedColumnNames(filter)); - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.referencedColumnNameTouches(pos, astRoot)) { - return this.quotedCandidateReferencedColumnNames(filter); - } - return null; - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return this.getColumnResource().getReferencedColumnNameTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - @Override - public void update(PrimaryKeyJoinColumnAnnotation column) { - this.primaryKeyJoinColumnResource = column; - super.update(column); - this.setSpecifiedReferencedColumnName_(this.specifiedReferencedColumnName(column)); - this.setDefaultReferencedColumnName(this.defaultReferencedColumnName()); - } - - protected String specifiedReferencedColumnName(PrimaryKeyJoinColumnAnnotation column) { - return column.getReferencedColumnName(); - } - - //TODO not correct when we start supporting primaryKeyJoinColumns in 1-1 mappings - protected String defaultReferencedColumnName() { - return defaultName(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append("=>"); - sb.append(this.getReferencedColumnName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaQueryHint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaQueryHint.java deleted file mode 100644 index b6aba90d79..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaQueryHint.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaQueryHint; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaQueryHint extends AbstractJavaJpaContextNode implements JavaQueryHint -{ - protected String name; - - protected String value; - - protected QueryHintAnnotation queryHint; - - public GenericJavaQueryHint(JavaQuery parent) { - super(parent); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.queryHint.setName(newName); - firePropertyChanged(QueryHint.NAME_PROPERTY, oldName, newName); - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - String oldValue = this.value; - this.value = newValue; - this.queryHint.setValue(newValue); - firePropertyChanged(QueryHint.VALUE_PROPERTY, oldValue, newValue); - } - - - public void initialize(QueryHintAnnotation queryHint) { - this.queryHint = queryHint; - this.name = queryHint.getName(); - this.value = queryHint.getValue(); - } - - public void update(QueryHintAnnotation queryHint) { - this.queryHint = queryHint; - this.setName(queryHint.getName()); - this.setValue(queryHint.getValue()); - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSecondaryTable.java deleted file mode 100644 index 40c80979ac..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSecondaryTable.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.internal.resource.java.NullPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaSecondaryTable extends AbstractJavaTable - implements JavaSecondaryTable -{ - protected final List<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected JavaPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - protected SecondaryTableAnnotation secondaryTableResource; - - public GenericJavaSecondaryTable(JavaEntity parent) { - super(parent); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - } - - @Override - public JavaEntity getParent() { - return (JavaEntity) super.getParent(); - } - - //***************** AbstractJavaTable implementation ******************** - - @Override - protected String getAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - - @Override - protected SecondaryTableAnnotation getTableResource() { - return this.secondaryTableResource; - } - - @Override - protected String defaultName() { - return null; - } - - //***************** ISecondaryTable implementation ******************** - - - public ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumns() : this.defaultPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumnsSize() : this.defaultPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<JavaPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public JavaPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - return this.defaultPrimaryKeyJoinColumn; - } - - protected void setDefaultPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn newPkJoinColumn) { - JavaPrimaryKeyJoinColumn oldPkJoinColumn = this.defaultPrimaryKeyJoinColumn; - this.defaultPrimaryKeyJoinColumn = newPkJoinColumn; - firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldPkJoinColumn, newPkJoinColumn); - } - - protected ListIterator<JavaPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - if (this.defaultPrimaryKeyJoinColumn != null) { - return new SingleElementListIterator<JavaPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultPrimaryKeyJoinColumnsSize() { - return (this.defaultPrimaryKeyJoinColumn == null) ? 0 : 1; - } - - public JavaPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn oldDefaultPkJoinColumn = this.getDefaultPrimaryKeyJoinColumn(); - if (oldDefaultPkJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultPrimaryKeyJoinColumn = null; - } - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = this.secondaryTableResource.addPkJoinColumn(index); - primaryKeyJoinColumn.initialize(pkJoinColumnResource); - this.fireItemAdded(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return primaryKeyJoinColumn; - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn joinColumn) { - this.removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn removedPrimaryKeyJoinColumn = this.specifiedPrimaryKeyJoinColumns.remove(index); - if (!containsSpecifiedPrimaryKeyJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(this.secondaryTableResource)); - } - this.secondaryTableResource.removePkJoinColumn(index); - fireItemRemoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (this.defaultPrimaryKeyJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, null, this.defaultPrimaryKeyJoinColumn); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.secondaryTableResource.movePkJoinColumn(targetIndex, sourceIndex); - fireItemMoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public JavaEntity getJavaEntity() { - return getParent(); - } - - - //********************* updating ************************ - - public void initialize(SecondaryTableAnnotation secondaryTable) { - super.initialize(secondaryTable); - this.secondaryTableResource = secondaryTable; - this.initializeSpecifiedPrimaryKeyJoinColumns(secondaryTable); - this.initializeDefaultPrimaryKeyJoinColumn(secondaryTable); - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns(SecondaryTableAnnotation secondaryTable) { - ListIterator<PrimaryKeyJoinColumnAnnotation> annotations = secondaryTable.pkJoinColumns(); - - while(annotations.hasNext()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(annotations.next())); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn(SecondaryTableAnnotation secondaryTable) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(secondaryTable)); - } - - - public void update(SecondaryTableAnnotation secondaryTableResource) { - this.secondaryTableResource = secondaryTableResource; - super.update(secondaryTableResource); - this.updateSpecifiedPrimaryKeyJoinColumns(secondaryTableResource); - this.updateDefaultPrimaryKeyJoinColumn(secondaryTableResource); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns(SecondaryTableAnnotation secondaryTableResource) { - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<PrimaryKeyJoinColumnAnnotation> resourcePrimaryKeyJoinColumns = secondaryTableResource.pkJoinColumns(); - - while (primaryKeyJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update(resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn(resourcePrimaryKeyJoinColumns.next())); - } - } - - protected void updateDefaultPrimaryKeyJoinColumn(SecondaryTableAnnotation secondaryTableResource) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(secondaryTableResource))); - } - else { - this.defaultPrimaryKeyJoinColumn.update(new NullPrimaryKeyJoinColumn(secondaryTableResource)); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - primaryKeyJoinColumn.initialize(primaryKeyJoinColumnResource); - return primaryKeyJoinColumn; - } - - protected JavaBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - boolean doContinue = this.connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange(astRoot)) - ); - } - } - - - //********************* code completion ************************ - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaPrimaryKeyJoinColumn column : CollectionTools.iterable(this.primaryKeyJoinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - public boolean isVirtual() { - return false; - } - - class PrimaryKeyJoinColumnOwner implements JavaBaseJoinColumn.Owner - { - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaSecondaryTable.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return GenericJavaSecondaryTable.this.getJavaEntity(); - } - - public Table getDbTable(String tableName) { - return GenericJavaSecondaryTable.this.getDbTable(); - } - - public Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericJavaSecondaryTable.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaSecondaryTable.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return getJavaEntity().getPrimaryKeyColumnName(); - - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSequenceGenerator.java deleted file mode 100644 index 35e9cc6668..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSequenceGenerator.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; - - -public class GenericJavaSequenceGenerator extends AbstractJavaGenerator - implements JavaSequenceGenerator -{ - protected String specifiedSequenceName; - - public GenericJavaSequenceGenerator(JavaJpaContextNode parent) { - super(parent); - } - - @Override - protected SequenceGeneratorAnnotation getGeneratorResource() { - return (SequenceGeneratorAnnotation) super.getGeneratorResource(); - } - - public void initialize(SequenceGeneratorAnnotation sequenceGenerator) { - super.initialize(sequenceGenerator); - this.specifiedSequenceName = this.specifiedSequenceName(sequenceGenerator); - } - - public Integer getDefaultInitialValue() { - return SequenceGenerator.DEFAULT_INITIAL_VALUE; - } - - public String getSequenceName() { - return (this.getSpecifiedSequenceName() == null) ? getDefaultSequenceName() : this.getSpecifiedSequenceName(); - } - - public String getSpecifiedSequenceName() { - return this.specifiedSequenceName; - } - - public void setSpecifiedSequenceName(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - getGeneratorResource().setSequenceName(newSpecifiedSequenceName); - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - protected void setSpecifiedSequenceName_(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - public String getDefaultSequenceName() { - return null; - } - - public void update(SequenceGeneratorAnnotation sequenceGenerator) { - super.update(sequenceGenerator); - this.setSpecifiedSequenceName_(this.specifiedSequenceName(sequenceGenerator)); - } - - protected String specifiedSequenceName(SequenceGeneratorAnnotation generatorResource) { - return generatorResource.getSequenceName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTable.java deleted file mode 100644 index 8ca30304b1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTable.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaTable extends AbstractJavaTable implements JavaTable -{ - protected JavaResourcePersistentMember persistentResource; - - public GenericJavaTable(JavaEntity parent) { - super(parent); - } - - public void initialize(JavaResourcePersistentMember persistentResource) { - this.persistentResource = persistentResource; - initialize(getTableResource()); - } - - - //query for the table resource every time on setters. - //call one setter and the tableResource could change. - //You could call more than one setter before this object has received any notification - //from the java resource model - @Override - protected TableAnnotation getTableResource() { - //TODO get the NullTable from the resource model or build it here in the context model?? - return (TableAnnotation) this.persistentResource.getNonNullAnnotation(getAnnotationName()); - } - - @Override - protected String getAnnotationName() { - return TableAnnotation.ANNOTATION_NAME; - } - - @Override - public JavaEntity getParent() { - return (JavaEntity) super.getParent(); - } - - protected JavaEntity getJavaEntity() { - return getParent(); - } - - protected Entity getRootEntity() { - return getJavaEntity().getRootEntity(); - } - - @Override - /** - * Table name default to the owning java entity name. - * If this entity is part of a single table inheritance hierarchy, table - * name defaults to the root entity's table name. - */ - protected String defaultName() { - if (getJavaEntity().getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - if (getRootEntity() != getJavaEntity()) { - return getRootEntity().getTable().getName(); - } - } - return getJavaEntity().getName(); - } - - @Override - protected String defaultSchema() { - if (getJavaEntity().getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - if (getRootEntity() != getJavaEntity()) { - return getRootEntity().getTable().getSchema(); - } - } - return super.defaultSchema(); - } - - @Override - protected String defaultCatalog() { - if (getJavaEntity().getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - if (getRootEntity() != getJavaEntity()) { - return getRootEntity().getTable().getCatalog(); - } - } - return super.defaultCatalog(); - } - - public void update(JavaResourcePersistentMember persistentResource) { - this.persistentResource = persistentResource; - this.update(getTableResource()); - } - - //******************* validation ********************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - boolean doContinue = this.connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange(astRoot)) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTableGenerator.java deleted file mode 100644 index b5a260ca3c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTableGenerator.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public class GenericJavaTableGenerator extends AbstractJavaGenerator - implements JavaTableGenerator, UniqueConstraint.Owner -{ - - protected String specifiedTable; - - protected String defaultTable; - - protected String specifiedCatalog; - - protected String defaultCatalog; - - protected String specifiedSchema; - - protected String defaultSchema; - - protected String specifiedPkColumnName; - - protected String defaultPkColumnName; - - protected String specifiedValueColumnName; - - protected String defaultValueColumnName; - - protected String specifiedPkColumnValue; - - protected String defaultPkColumnValue; - - protected final List<JavaUniqueConstraint> uniqueConstraints; - - public GenericJavaTableGenerator(JavaJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<JavaUniqueConstraint>(); - } - - @Override - protected TableGeneratorAnnotation getGeneratorResource() { - return (TableGeneratorAnnotation) super.getGeneratorResource(); - } - - public Integer getDefaultInitialValue() { - return TableGenerator.DEFAULT_INITIAL_VALUE; - } - - public String getTable() { - return (this.getSpecifiedTable() == null) ? getDefaultTable() : this.getSpecifiedTable(); - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - getGeneratorResource().setTable(newSpecifiedTable); - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - getGeneratorResource().setCatalog(newSpecifiedCatalog); - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - getGeneratorResource().setSchema(newSpecifiedSchema); - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getPkColumnName() { - return (this.getSpecifiedPkColumnName() == null) ? getDefaultPkColumnName() : this.getSpecifiedPkColumnName(); - } - - public String getSpecifiedPkColumnName() { - return this.specifiedPkColumnName; - } - - public void setSpecifiedPkColumnName(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - getGeneratorResource().setPkColumnName(newSpecifiedPkColumnName); - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - protected void setSpecifiedPkColumnName_(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - public String getDefaultPkColumnName() { - return this.defaultPkColumnName; - } - - public String getValueColumnName() { - return (this.getSpecifiedValueColumnName() == null) ? getDefaultValueColumnName() : this.getSpecifiedValueColumnName(); - } - - public String getSpecifiedValueColumnName() { - return this.specifiedValueColumnName; - } - - public void setSpecifiedValueColumnName(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - getGeneratorResource().setValueColumnName(newSpecifiedValueColumnName); - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - protected void setSpecifiedValueColumnName_(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - public String getDefaultValueColumnName() { - return this.defaultValueColumnName; - } - - public String getPkColumnValue() { - return (this.getSpecifiedPkColumnValue() == null) ? getDefaultPkColumnValue() : this.getSpecifiedPkColumnValue(); - } - - public String getSpecifiedPkColumnValue() { - return this.specifiedPkColumnValue; - } - - public void setSpecifiedPkColumnValue(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - getGeneratorResource().setPkColumnValue(newSpecifiedPkColumnValue); - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - public void setSpecifiedPkColumnValue_(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - public String getDefaultPkColumnValue() { - return this.defaultPkColumnValue; - } - - - // ********** unique constraints ********** - - public ListIterator<JavaUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<JavaUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public JavaUniqueConstraint addUniqueConstraint(int index) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - this.uniqueConstraints.add(index, uniqueConstraint); - UniqueConstraintAnnotation uniqueConstraintAnnotation = this.getGeneratorResource().addUniqueConstraint(index); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - fireItemAdded(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - JavaUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - this.getGeneratorResource().removeUniqueConstraint(index); - fireItemRemoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getGeneratorResource().moveUniqueConstraint(targetIndex, sourceIndex); - fireItemMoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void addUniqueConstraint(int index, JavaUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - protected void removeUniqueConstraint_(JavaUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - - // ********** java resource model -> java context model ********** - - public void initialize(TableGeneratorAnnotation tableGenerator) { - super.initialize(tableGenerator); - this.specifiedTable = this.specifiedTable(tableGenerator); - this.specifiedCatalog = this.specifiedCatalog(tableGenerator); - this.defaultCatalog = this.defaultCatalog(); - this.specifiedSchema = this.specifiedSchema(tableGenerator); - this.defaultSchema = this.defaultSchema(); - this.specifiedPkColumnName = this.specifiedPkColumnName(tableGenerator); - this.specifiedValueColumnName = this.specifiedValueColumnName(tableGenerator); - this.specifiedPkColumnValue = this.specifiedPkColumnValue(tableGenerator); - this.initializeUniqueConstraints(tableGenerator); - } - - protected void initializeUniqueConstraints(TableGeneratorAnnotation tableGenerator) { - for (UniqueConstraintAnnotation uniqueConstraintAnnotation : CollectionTools.iterable(tableGenerator.uniqueConstraints())) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraintAnnotation)); - } - } - - public void update(TableGeneratorAnnotation tableGenerator) { - super.update(tableGenerator); - this.setSpecifiedTable_(this.specifiedTable(tableGenerator)); - this.setSpecifiedCatalog_(this.specifiedCatalog(tableGenerator)); - this.setDefaultCatalog(this.defaultCatalog()); - this.setSpecifiedSchema_(this.specifiedSchema(tableGenerator)); - this.setDefaultSchema(this.defaultSchema()); - this.setSpecifiedPkColumnName_(this.specifiedPkColumnName(tableGenerator)); - this.setSpecifiedValueColumnName_(this.specifiedValueColumnName(tableGenerator)); - this.setSpecifiedPkColumnValue_(this.specifiedPkColumnValue(tableGenerator)); - this.updateUniqueConstraints(tableGenerator); - } - - protected void updateUniqueConstraints(TableGeneratorAnnotation tableGenerator) { - ListIterator<JavaUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<UniqueConstraintAnnotation> resourceUniqueConstraints = tableGenerator.uniqueConstraints(); - - while (uniqueConstraints.hasNext()) { - JavaUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected JavaUniqueConstraint buildUniqueConstraint(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - return uniqueConstraint; - } - - protected String specifiedTable(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getTable(); - } - - protected String specifiedCatalog(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getCatalog(); - } - - protected String specifiedSchema(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getSchema(); - } - - protected String specifiedPkColumnName(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getPkColumnName(); - } - - protected String specifiedValueColumnName(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getValueColumnName(); - } - - protected String specifiedPkColumnValue(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getPkColumnValue(); - } - - protected String defaultSchema() { - if (getEntityMappings() != null) { - return getEntityMappings().getSchema(); - } - return getPersistenceUnit().getDefaultSchema(); - } - - protected String defaultCatalog() { - if (getEntityMappings() != null) { - return getEntityMappings().getCatalog(); - } - return getPersistenceUnit().getDefaultCatalog(); - } - - public Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.getTableNamed(this.getTable()); - } - - public Schema getDbSchema() { - return this.getDataSource().getSchemaNamed(this.getSchema()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTransientMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTransientMapping.java deleted file mode 100644 index d7d919db68..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTransientMapping.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaTransientMapping extends AbstractJavaAttributeMapping<TransientAnnotation> - implements JavaTransientMapping -{ - public GenericJavaTransientMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return TransientAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaUniqueConstraint.java deleted file mode 100644 index 47332c31f3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaUniqueConstraint.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public class GenericJavaUniqueConstraint extends AbstractJavaJpaContextNode - implements JavaUniqueConstraint -{ - - protected final List<String> columnNames; - - protected UniqueConstraintAnnotation uniqueConstraintAnnotation; - - protected Owner owner; - public GenericJavaUniqueConstraint(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - this.columnNames = new ArrayList<String>(); - } - - public Owner getOwner() { - return this.owner; - } - - public ListIterator<String> columnNames() { - return new CloneListIterator<String>(this.columnNames); - } - - public int columnNamesSize() { - return this.columnNames.size(); - } - - public void addColumnName(int index, String columnName) { - this.columnNames.add(index, columnName); - this.uniqueConstraintAnnotation.addColumnName(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - protected void addColumnName_(int index, String columnName) { - this.columnNames.add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - public void removeColumnName(String columnName) { - this.removeColumnName(this.columnNames.indexOf(columnName)); - } - - public void removeColumnName(int index) { - String removedColumnName = this.columnNames.remove(index); - this.uniqueConstraintAnnotation.removeColumnName(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - protected void removeColumnName_(int index) { - String removedColumnName = this.columnNames.remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - CollectionTools.move(this.columnNames, targetIndex, sourceIndex); - this.uniqueConstraintAnnotation.moveColumnName(targetIndex, sourceIndex); - fireItemMoved(UniqueConstraint.COLUMN_NAMES_LIST, targetIndex, sourceIndex); - } - - public void initialize(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - this.uniqueConstraintAnnotation = uniqueConstraintAnnotation; - this.initializeColumnNames(uniqueConstraintAnnotation); - } - - protected void initializeColumnNames(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - ListIterator<String> annotationColumnNames = uniqueConstraintAnnotation.columnNames(); - - for (String annotationColumnName : CollectionTools.iterable(annotationColumnNames)) { - this.columnNames.add(annotationColumnName); - } - } - - public void update(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - this.uniqueConstraintAnnotation = uniqueConstraintAnnotation; - this.updateColumnNames(uniqueConstraintAnnotation); - } - - protected void updateColumnNames(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - ListIterator<String> annotationColumnNames = uniqueConstraintAnnotation.columnNames(); - - int index = 0; - for (String annotationColumnName : CollectionTools.iterable(annotationColumnNames)) { - if (columnNamesSize() > index) { - if (this.columnNames.get(index) != annotationColumnName) { - addColumnName_(index, annotationColumnName); - } - } - else { - addColumnName_(index, annotationColumnName); - } - index++; - } - - for ( ; index < columnNamesSize(); ) { - removeColumnName_(index); - } - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.uniqueConstraintAnnotation.getTextRange(astRoot); - } - - private boolean columnNamesTouches(int pos, CompilationUnit astRoot) { - return this.uniqueConstraintAnnotation.columnNamesTouches(pos, astRoot); - } - - private Iterator<String> candidateColumnNames() { - return this.getOwner().candidateUniqueConstraintColumnNames(); - } - - private Iterator<String> candidateColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateColumnNames(), filter); - } - - private Iterator<String> quotedCandidateColumnNames(Filter<String> filter) { - return StringTools.quote(this.candidateColumnNames(filter)); - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.columnNamesTouches(pos, astRoot)) { - return this.quotedCandidateColumnNames(filter); - } - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaVersionMapping.java deleted file mode 100644 index f340ed2313..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaVersionMapping.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaVersionMapping extends AbstractJavaAttributeMapping<VersionAnnotation> implements JavaVersionMapping -{ - protected final JavaColumn column; - - protected TemporalType temporal; - - public GenericJavaVersionMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = createJavaColumn(); - } - - protected JavaColumn createJavaColumn() { - return getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public void initialize(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initialize(resourcePersistentAttribute); - this.column.initialize(this.getColumnResource()); - this.temporal = this.temporal(this.temporalResource()); - } - - protected TemporalAnnotation temporalResource() { - return (TemporalAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(TemporalAnnotation.ANNOTATION_NAME); - } - - public ColumnAnnotation getColumnResource() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** IJavaAttributeMapping implementation *************** - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return VersionAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.COLUMN, - JPA.TEMPORAL); - } - - //************** INamedColumn.Owner implementation *************** - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - //************** IVersionMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.temporalResource().setValue(TemporalType.toJavaResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.column.update(this.getColumnResource()); - this.setTemporal(this.temporal(this.temporalResource())); - } - - protected TemporalType temporal(TemporalAnnotation temporal) { - return TemporalType.fromJavaResourceModel(temporal.getValue()); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - //*********** Validation ****************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addColumnMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaColumn column = this.getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && column.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, column.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, column.getNameTextRange(astRoot)) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java deleted file mode 100644 index 3c37d7b648..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; - -public class JavaBasicMappingProvider - implements DefaultJavaAttributeMappingProvider -{ - - // singleton - private static final JavaBasicMappingProvider INSTANCE = new JavaBasicMappingProvider(); - - /** - * Return the singleton. - */ - public static DefaultJavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaBasicMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return BasicAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaBasicMapping(parent); - } - - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { - return persistentAttribute.getResourcePersistentAttribute().typeIsBasic(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaCascade.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaCascade.java deleted file mode 100644 index e7a21e46f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaCascade.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class JavaCascade extends AbstractJavaJpaContextNode implements Cascade -{ - protected boolean all; - - protected boolean persist; - - protected boolean merge; - - protected boolean remove; - - protected boolean refresh; - - protected RelationshipMappingAnnotation relationshipMapping; - - protected JavaCascade(JavaRelationshipMapping parent) { - super(parent); - } - - public boolean isAll() { - return this.all; - } - - public void setAll(boolean newAll) { - boolean oldAll = this.all; - this.all = newAll; - this.relationshipMapping.setCascadeAll(newAll); - firePropertyChanged(Cascade.ALL_PROPERTY, oldAll, newAll); - } - - public boolean isPersist() { - return this.persist; - } - - public void setPersist(boolean newPersist) { - boolean oldPersist = this.persist; - this.persist = newPersist; - this.relationshipMapping.setCascadePersist(newPersist); - firePropertyChanged(Cascade.PERSIST_PROPERTY, oldPersist, newPersist); - } - - public boolean isMerge() { - return this.merge; - } - - public void setMerge(boolean newMerge) { - boolean oldMerge = this.merge; - this.merge = newMerge; - this.relationshipMapping.setCascadeMerge(newMerge); - firePropertyChanged(Cascade.MERGE_PROPERTY, oldMerge, newMerge); - } - - public boolean isRemove() { - return this.remove; - } - - public void setRemove(boolean newRemove) { - boolean oldRemove = this.remove; - this.remove = newRemove; - this.relationshipMapping.setCascadeRemove(newRemove); - firePropertyChanged(Cascade.REMOVE_PROPERTY, oldRemove, newRemove); - } - - public boolean isRefresh() { - return this.refresh; - } - - public void setRefresh(boolean newRefresh) { - boolean oldRefresh = this.refresh; - this.refresh = newRefresh; - this.relationshipMapping.setCascadeRefresh(newRefresh); - firePropertyChanged(Cascade.REFRESH_PROPERTY, oldRefresh, newRefresh); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.relationshipMapping.getCascadeTextRange(astRoot); - } - - public void initialize(RelationshipMappingAnnotation relationshipMapping) { - this.relationshipMapping = relationshipMapping; - this.all = relationshipMapping.isCascadeAll(); - this.persist = relationshipMapping.isCascadePersist(); - this.merge = relationshipMapping.isCascadeMerge(); - this.remove = relationshipMapping.isCascadeRemove(); - this.refresh = relationshipMapping.isCascadeRefresh(); - } - - public void update(RelationshipMappingAnnotation relationshipMapping) { - this.relationshipMapping = relationshipMapping; - this.setAll(relationshipMapping.isCascadeAll()); - this.setPersist(relationshipMapping.isCascadePersist()); - this.setMerge(relationshipMapping.isCascadeMerge()); - this.setRemove(relationshipMapping.isCascadeRemove()); - this.setRefresh(relationshipMapping.isCascadeRefresh()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java deleted file mode 100644 index 3f8567367a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; - -public class JavaEmbeddableProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaEmbeddableProvider INSTANCE = new JavaEmbeddableProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEmbeddableProvider() { - super(); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddableAnnotation.ANNOTATION_NAME; - } - - public JavaEmbeddable buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaEmbeddable(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingProvider.java deleted file mode 100644 index bc30accc8f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; - -public class JavaEmbeddedIdMappingProvider - implements DefaultJavaAttributeMappingProvider -{ - - // singleton - private static final JavaEmbeddedIdMappingProvider INSTANCE = new JavaEmbeddedIdMappingProvider(); - - /** - * Return the singleton. - */ - public static DefaultJavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEmbeddedIdMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedIdAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaEmbeddedIdMapping(parent); - } - - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { - return MappingTools.getEmbeddableFor(persistentAttribute) != null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java deleted file mode 100644 index fdd6f131ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; - -public class JavaEmbeddedMappingProvider - implements DefaultJavaAttributeMappingProvider -{ - - // singleton - private static final JavaEmbeddedMappingProvider INSTANCE = new JavaEmbeddedMappingProvider(); - - /** - * Return the singleton. - */ - public static DefaultJavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEmbeddedMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaEmbeddedMapping(parent); - } - - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { - return MappingTools.getEmbeddableFor(persistentAttribute) != null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java deleted file mode 100644 index 7114a094ac..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; - -/** - * - */ -public class JavaEntityProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaEntityProvider INSTANCE = new JavaEntityProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEntityProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - - public JavaEntity buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaEntity(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java deleted file mode 100644 index 42db79746b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.IdAnnotation; - -public class JavaIdMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaIdMappingProvider INSTANCE = new JavaIdMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaIdMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return IdAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaIdMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingProvider.java deleted file mode 100644 index 028370fbfa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; - -public class JavaManyToManyMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaManyToManyMappingProvider INSTANCE = new JavaManyToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaManyToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return ManyToManyAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaManyToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingProvider.java deleted file mode 100644 index 757a9c1b42..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; - -public class JavaManyToOneMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaManyToOneMappingProvider INSTANCE = new JavaManyToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaManyToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return ManyToOneAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaManyToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java deleted file mode 100644 index 8f3317cc07..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; - -public class JavaMappedSuperclassProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaMappedSuperclassProvider INSTANCE = new JavaMappedSuperclassProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaMappedSuperclassProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return MappedSuperclassAnnotation.ANNOTATION_NAME; - } - - public JavaMappedSuperclass buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaMappedSuperclass(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullAttributeMappingProvider.java deleted file mode 100644 index cd209b7683..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullAttributeMappingProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; - -/** - * This mapping provider implementation is used to create a JavaNullAttributeMapping. - * A JavaNullAttributeMapping should be used when no "mapping" annotation - * exists on a Java attribute *and* no default mapping applies. - */ -public class JavaNullAttributeMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaNullAttributeMappingProvider INSTANCE = new JavaNullAttributeMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaNullAttributeMappingProvider() { - super(); - } - - public String getKey() { - return null; - } - - public String getAnnotationName() { - return null; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaNullAttributeMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java deleted file mode 100644 index b3067e7e93..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class JavaNullTypeMapping extends AbstractJavaTypeMapping -{ - public JavaNullTypeMapping(JavaPersistentType parent) { - super(parent); - } - - public String getAnnotationName() { - return null; - } - - public String getKey() { - return MappingKeys.NULL_TYPE_MAPPING_KEY; - } - - public boolean isMapped() { - return false; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - //Adding this message here because the likely solution is to add an annotation to the java file. - //This message used to be found on the <class> tag in the persistence.xml. The other possible - //way to fix the error is to remove it from the persistnce.xml. This can be accomplished - //with the Synchronize Classes action. We could also add a quick fix for this error. - messages.add(DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_INVALID_CLASS, - new String[] { this.getPersistentType().getName() }, - this, - this.getValidationTextRange(astRoot))); - } - - @Override - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getPersistentType().getValidationTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMappingProvider.java deleted file mode 100644 index bcc6313964..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMappingProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; - -/** - * This mapping provider implementation is used to create a JavaNullAttributeMapping. - * A JavaNullAttributeMapping should be used when no "mapping" annotation - * exists on a Java type. - */ -public class JavaNullTypeMappingProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaNullTypeMappingProvider INSTANCE = new JavaNullTypeMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaNullTypeMappingProvider() { - super(); - } - - public String getKey() { - return null; - } - - public String getAnnotationName() { - return null; - } - - public JavaTypeMapping buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaNullTypeMapping(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingProvider.java deleted file mode 100644 index 15b91f8a6c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; - -public class JavaOneToManyMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaOneToManyMappingProvider INSTANCE = new JavaOneToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaOneToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return OneToManyAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaOneToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingProvider.java deleted file mode 100644 index 319b9ef298..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; - -public class JavaOneToOneMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaOneToOneMappingProvider INSTANCE = new JavaOneToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaOneToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return OneToOneAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaOneToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingProvider.java deleted file mode 100644 index 4fb5aa294e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; - -public class JavaTransientMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaTransientMappingProvider INSTANCE = new JavaTransientMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaTransientMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return TransientAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaTransientMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingProvider.java deleted file mode 100644 index c17edb669e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; - -public class JavaVersionMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaVersionMappingProvider INSTANCE = new JavaVersionMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaVersionMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return VersionAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaVersionMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverride.java deleted file mode 100644 index ee891e1d6a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverride.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.internal.resource.java.AbstractJavaResourceNode; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class VirtualAttributeOverride extends AbstractJavaResourceNode implements AttributeOverrideAnnotation, Annotation -{ - private final VirtualAttributeOverrideColumn column; - - private String name; - - public VirtualAttributeOverride(JavaResourceNode parent, String name, Column column) { - super(parent); - this.name = name; - this.column = new VirtualAttributeOverrideColumn(this, column); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return AttributeOverrideAnnotation.ANNOTATION_NAME; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - if (name != null) { - createAttributeOverrideResource().setName(name); - } - } - - public ColumnAnnotation getNonNullColumn() { - return getColumn(); - } - - public ColumnAnnotation getColumn() { - return this.column; - } - - public ColumnAnnotation addColumn() { - throw new UnsupportedOperationException(); - } - - public void removeColumn() { - throw new UnsupportedOperationException(); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - protected AttributeOverrideAnnotation createAttributeOverrideResource() { - return (AttributeOverrideAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return false; - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumn.java deleted file mode 100644 index 3f0e8eff56..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumn.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.internal.resource.java.NullBaseColumn; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public class VirtualAttributeOverrideColumn extends NullBaseColumn implements ColumnAnnotation, Annotation -{ - private Column column; - - public VirtualAttributeOverrideColumn(AttributeOverrideAnnotation parent, Column column) { - super(parent); - this.column = column; - } - - @Override - public AttributeOverrideAnnotation getParent() { - return (AttributeOverrideAnnotation) super.getParent(); - } - - public String getAnnotationName() { - return ColumnAnnotation.ANNOTATION_NAME; - } - - @Override - protected ColumnAnnotation createColumnResource() { - return getParent().addColumn(); - } - - @Override - public String getName() { - if (this.column.getSpecifiedName() != null) { - return this.column.getSpecifiedName(); - } - return null; - } - - @Override - public String getTable() { - if (this.column.getSpecifiedTable() != null) { - return this.column.getSpecifiedTable(); - } - return null; - } - - @Override - public Boolean getInsertable() { - if (this.column.getSpecifiedInsertable() != null) { - return this.column.getSpecifiedInsertable(); - } - return null; - } - - @Override - public Boolean getUpdatable() { - if (this.column.getSpecifiedUpdatable() != null) { - return this.column.getSpecifiedUpdatable(); - } - return null; - } - @Override - public Boolean getNullable() { - if (this.column.getSpecifiedNullable() != null) { - return this.column.getSpecifiedNullable(); - } - return null; - } - - @Override - public Boolean getUnique() { - if (this.column.getSpecifiedUnique() != null) { - return this.column.getSpecifiedUnique(); - } - return null; - } - - @Override - public String getColumnDefinition() { - return this.column.getColumnDefinition(); - } - - public Integer getLength() { - if (this.column.getSpecifiedLength() != null) { - return this.column.getSpecifiedLength(); - } - return null; - } - - public void setLength(Integer length) { - if (length != null) { - createColumnResource().setLength(length); - } - } - - public Integer getScale() { - if (this.column.getSpecifiedScale() != null) { - return this.column.getSpecifiedScale(); - } - return null; - } - - public void setScale(Integer scale) { - if (scale != null) { - createColumnResource().setScale(scale); - } - } - - public Integer getPrecision() { - if (this.column.getSpecifiedPrecision() != null) { - return this.column.getSpecifiedPrecision(); - } - return null; - } - - public void setPrecision(Integer precision) { - if (precision != null) { - createColumnResource().setPrecision(precision); - } - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java deleted file mode 100644 index ec1153a0bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmSingleRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> extends AbstractOrmJpaContextNode - implements OrmAttributeMapping -{ - protected String name; - - protected T attributeMapping; - - protected JavaPersistentAttribute javaPersistentAttribute; - - protected AbstractOrmAttributeMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public JavaPersistentAttribute getJavaPersistentAttribute() { - return this.javaPersistentAttribute; - } - - protected void setJavaPersistentAttribute(JavaPersistentAttribute newJavaPersistentAttribute) { - JavaPersistentAttribute oldJavaPersistentAttribute = this.javaPersistentAttribute; - this.javaPersistentAttribute = newJavaPersistentAttribute; - firePropertyChanged(OrmAttributeMapping.JAVA_PERSISTENT_ATTRIBUTE_PROPERTY, oldJavaPersistentAttribute, newJavaPersistentAttribute); - - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.attributeMapping.setName(newName); - firePropertyChanged(OrmAttributeMapping.NAME_PROPERTY, oldName, newName); - getPersistentAttribute().nameChanged(oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(OrmAttributeMapping.NAME_PROPERTY, oldName, newName); - getPersistentAttribute().nameChanged(oldName, newName); - } - - public OrmPersistentAttribute getPersistentAttribute() { - return (OrmPersistentAttribute) getParent(); - } - - public String getAttributeName() { - return this.getPersistentAttribute().getName(); - } - - public boolean isDefault() { - return false; - } - - public void initializeFromOrmAttributeMapping(OrmAttributeMapping oldMapping) { - setName(oldMapping.getName()); - } - - public void initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - initializeFromOrmAttributeMapping((OrmAttributeMapping) oldMapping); - } - - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - initializeFromOrmAttributeMapping((OrmAttributeMapping) oldMapping); - } - - public void initializeFromOrmBasicMapping(OrmBasicMapping oldMapping) { - initializeFromXmlColumnMapping(oldMapping); - } - - public void initializeFromOrmIdMapping(OrmIdMapping oldMapping) { - initializeFromXmlColumnMapping(oldMapping); - } - - public void initializeFromOrmTransientMapping(OrmTransientMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmBaseEmbeddedMapping(OrmBaseEmbeddedMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmEmbeddedMapping(OrmEmbeddedMapping oldMapping) { - initializeFromOrmBaseEmbeddedMapping(oldMapping); - } - - public void initializeFromOrmEmbeddedIdMapping(OrmEmbeddedIdMapping oldMapping) { - initializeFromOrmBaseEmbeddedMapping(oldMapping); - } - - public void initializeFromOrmVersionMapping(OrmVersionMapping oldMapping) { - initializeFromXmlColumnMapping(oldMapping); - } - - public void initializeFromXmlRelationshipMapping(OrmRelationshipMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromXmlMulitRelationshipMapping(OrmMultiRelationshipMapping oldMapping) { - initializeFromXmlRelationshipMapping(oldMapping); - } - - public void initializeFromXmlSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - initializeFromXmlRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToManyMapping(OrmOneToManyMapping oldMapping) { - initializeFromXmlNonOwningMapping(oldMapping); - initializeFromXmlMulitRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToOneMapping(OrmManyToOneMapping oldMapping) { - initializeFromXmlSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToOneMapping(OrmOneToOneMapping oldMapping) { - initializeFromXmlNonOwningMapping(oldMapping); - initializeFromXmlSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToManyMapping(OrmManyToManyMapping oldMapping) { - initializeFromXmlNonOwningMapping(oldMapping); - initializeFromXmlMulitRelationshipMapping(oldMapping); - } - - public String getPrimaryKeyColumnName() { - return null; - } - - public OrmTypeMapping getTypeMapping() { - return this.getPersistentAttribute().getTypeMapping(); - } - - - public boolean isOverridableAttributeMapping() { - return false; - } - - public boolean isOverridableAssociationMapping() { - return false; - } - - public boolean isIdMapping() { - return false; - } - - protected T getAttributeMapping() { - return this.attributeMapping; - } - - public void initialize(T attributeMapping) { - this.attributeMapping = attributeMapping; - this.name = attributeMapping.getName(); - this.javaPersistentAttribute = findJavaPersistentAttribute(); - } - - public void update(T attributeMapping) { - this.attributeMapping = attributeMapping; - this.setName_(attributeMapping.getName()); - this.setJavaPersistentAttribute(findJavaPersistentAttribute()); - } - - protected JavaPersistentAttribute findJavaPersistentAttribute() { - JavaPersistentType javaPersistentType = getPersistentAttribute().getPersistentType().getJavaPersistentType(); - if (javaPersistentType != null && getName() != null) { - return javaPersistentType.getAttributeNamed(getName()); - } - return null; - } - - - protected boolean entityOwned() { - return getTypeMapping().getKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public boolean contains(int textOffset) { - return this.attributeMapping.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.attributeMapping.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return (this.getPersistentAttribute().isVirtual()) ? this.getTypeMapping().getAttributesTextRange() : this.attributeMapping.getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.attributeMapping.getNameTextRange(); - } - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addAttributeMessages(messages); - addInvalidMappingMessage(messages); - } - - protected void addAttributeMessages(List<IMessage> messages) { - addUnspecifiedAttributeMessage(messages); - addUnresolvedAttributeMessage(messages); - addModifierMessages(messages); - } - - protected void addUnspecifiedAttributeMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME, - this, - getValidationTextRange()) - ); - } - } - - protected void addUnresolvedAttributeMessage(List<IMessage> messages) { - if (! StringTools.stringIsEmpty(getName()) - && findJavaPersistentAttribute() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME, - new String[] {getName(), getPersistentAttribute().getPersistentType().getMapping().getClass_()}, - this, - getNameTextRange()) - ); - } - } - - protected void addModifierMessages(List<IMessage> messages) { - if (getKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - - if (getJavaPersistentAttribute() == null) { - return; - } - JavaResourcePersistentAttribute resourcePersistentAttribute = getJavaPersistentAttribute().getResourcePersistentAttribute(); - - if (resourcePersistentAttribute.isForField()) { - //TODO validation : need to have a validation message for final methods as well. - //From the JPA spec : No methods or persistent instance variables of the entity class may be final. - if (resourcePersistentAttribute.isFinal()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, - new String[] {getName()}, - getPersistentAttribute(), - getPersistentAttribute().getValidationTextRange()) - ); - } - - if (resourcePersistentAttribute.isPublic()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, - new String[] {getName()}, - getPersistentAttribute(), - getPersistentAttribute().getValidationTextRange()) - ); - - } - } - } - - //TODO validation message - i think more info is needed in this message. include type mapping type? - protected void addInvalidMappingMessage(List<IMessage> messages) { - if (! getTypeMapping().attributeMappingKeyAllowed(getKey())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_MAPPING, - new String[] {getName()}, - this, - getValidationTextRange()) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java deleted file mode 100644 index 6c15616ef3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java +++ /dev/null @@ -1,308 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.orm.OrmBaseColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlAbstractColumn; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class AbstractOrmBaseColumn<T extends XmlAbstractColumn> extends AbstractOrmNamedColumn<T> - implements OrmBaseColumn -{ - protected String specifiedTable; - - protected String defaultTable; - - protected Boolean specifiedUnique; - - protected Boolean specifiedNullable; - - protected Boolean specifiedInsertable; - - protected Boolean specifiedUpdatable; - - protected AbstractOrmBaseColumn(OrmJpaContextNode parent, OrmBaseColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFrom(BaseColumn oldColumn) { - super.initializeFrom(oldColumn); - setSpecifiedTable(oldColumn.getSpecifiedTable()); - setSpecifiedUnique(oldColumn.getSpecifiedUnique()); - setSpecifiedNullable(oldColumn.getSpecifiedNullable()); - setSpecifiedInsertable(oldColumn.getSpecifiedInsertable()); - setSpecifiedUpdatable(oldColumn.getSpecifiedUpdatable()); - } - - @Override - public OrmBaseColumn.Owner getOwner() { - return (OrmBaseColumn.Owner) super.getOwner(); - } - -// @Override -// protected void addInsignificantXmlFeatureIdsTo(Set<Integer> insignificantXmlFeatureIds) { -// super.addInsignificantXmlFeatureIdsTo(insignificantXmlFeatureIds); -// insignificantXmlFeatureIds.add(JpaCoreMappingsPackage.IABSTRACT_COLUMN__DEFAULT_TABLE); -// insignificantXmlFeatureIds.add(JpaCoreMappingsPackage.IABSTRACT_COLUMN__TABLE); -// } - - public String getTable() { - return (this.getSpecifiedTable() == null) ? getDefaultTable() : this.getSpecifiedTable(); - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - if (oldSpecifiedTable != newSpecifiedTable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setTable(newSpecifiedTable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedTable != null) { - addColumnResource(); - getColumnResource().setTable(newSpecifiedTable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - protected void setDefaultTable(String newDefaultTable) { - String oldDefaultTable = this.defaultTable; - this.defaultTable = newDefaultTable; - firePropertyChanged(BaseColumn.DEFAULT_TABLE_PROPERTY, oldDefaultTable, newDefaultTable); - } - - public Boolean getUnique() { - return (this.getSpecifiedUnique() == null) ? this.getDefaultUnique() : this.getSpecifiedUnique(); - } - - public Boolean getDefaultUnique() { - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getSpecifiedUnique() { - return this.specifiedUnique; - } - - public void setSpecifiedUnique(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - if (oldSpecifiedUnique != newSpecifiedUnique) { - if (this.getColumnResource() != null) { - this.getColumnResource().setUnique(newSpecifiedUnique); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedUnique != null) { - addColumnResource(); - getColumnResource().setUnique(newSpecifiedUnique); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - protected void setSpecifiedUnique_(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - public Boolean getNullable() { - return (this.getSpecifiedNullable() == null) ? this.getDefaultNullable() : this.getSpecifiedNullable(); - } - - public Boolean getDefaultNullable() { - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getSpecifiedNullable() { - return this.specifiedNullable; - } - - public void setSpecifiedNullable(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - if (oldSpecifiedNullable != newSpecifiedNullable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setNullable(newSpecifiedNullable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedNullable != null) { - addColumnResource(); - getColumnResource().setNullable(newSpecifiedNullable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - protected void setSpecifiedNullable_(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - public Boolean getInsertable() { - return (this.getSpecifiedInsertable() == null) ? this.getDefaultInsertable() : this.getSpecifiedInsertable(); - } - - public Boolean getDefaultInsertable() { - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getSpecifiedInsertable() { - return this.specifiedInsertable; - } - - public void setSpecifiedInsertable(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - if (oldSpecifiedInsertable != newSpecifiedInsertable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setInsertable(newSpecifiedInsertable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedInsertable != null) { - addColumnResource(); - getColumnResource().setInsertable(newSpecifiedInsertable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - protected void setSpecifiedInsertable_(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - public Boolean getUpdatable() { - return (this.getSpecifiedUpdatable() == null) ? this.getDefaultUpdatable() : this.getSpecifiedUpdatable(); - } - - public Boolean getDefaultUpdatable() { - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getSpecifiedUpdatable() { - return this.specifiedUpdatable; - } - - public void setSpecifiedUpdatable(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - if (oldSpecifiedUpdatable != newSpecifiedUpdatable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setUpdatable(newSpecifiedUpdatable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedUpdatable != null) { - addColumnResource(); - getColumnResource().setUpdatable(newSpecifiedUpdatable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - protected void setSpecifiedUpdatable_(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - @Override - protected String tableName() { - return this.getTable(); - } - - - public TextRange getTableTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getTableTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - @Override - protected void initialize(T column) { - super.initialize(column); - this.specifiedTable = this.specifiedTable(column); - this.defaultTable = this.defaultTable(); - //TODO default from java for all of these settings - this.specifiedNullable = this.specifiedNullable(column); - this.specifiedUpdatable = this.specifiedUpdatable(column); - this.specifiedUnique = this.specifiedUnique(column); - this.specifiedInsertable = this.specifiedInsertable(column); - } - - @Override - protected void update(T column) { - super.update(column); - setSpecifiedTable_(this.specifiedTable(column)); - setDefaultTable(this.defaultTable()); - setSpecifiedNullable_(this.specifiedNullable(column)); - setSpecifiedUpdatable_(this.specifiedUpdatable(column)); - setSpecifiedUnique_(this.specifiedUnique(column)); - setSpecifiedInsertable_(this.specifiedInsertable(column)); - } - - protected String specifiedTable(T column) { - return column == null ? null : column.getTable(); - } - - protected Boolean specifiedNullable(T column) { - return column == null ? null : column.getNullable(); - } - - protected Boolean specifiedUpdatable(T column) { - return column == null ? null : column.getUpdatable(); - } - - protected Boolean specifiedUnique(T column) { - return column == null ? null : column.getUnique(); - } - - protected Boolean specifiedInsertable(T column) { - return column == null ? null : column.getInsertable(); - } - - protected String defaultTable() { - return getOwner().getDefaultTableName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java deleted file mode 100644 index aa9c1baa60..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java +++ /dev/null @@ -1,361 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseEmbeddedMapping; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.resource.orm.BaseXmlEmbedded; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmBaseEmbeddedMapping<T extends BaseXmlEmbedded> extends AbstractOrmAttributeMapping<T> implements OrmBaseEmbeddedMapping -{ - protected final List<OrmAttributeOverride> specifiedAttributeOverrides; - - protected final List<OrmAttributeOverride> virtualAttributeOverrides; - - private Embeddable embeddable; - - protected AbstractOrmBaseEmbeddedMapping(OrmPersistentAttribute parent) { - super(parent); - this.specifiedAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - } - - @Override - public void initializeFromOrmBaseEmbeddedMapping(OrmBaseEmbeddedMapping oldMapping) { - super.initializeFromOrmBaseEmbeddedMapping(oldMapping); - int index = 0; - for (OrmAttributeOverride attributeOverride : CollectionTools.iterable(oldMapping.specifiedAttributeOverrides())) { - OrmAttributeOverride newAttributeOverride = addSpecifiedAttributeOverride(index++); - newAttributeOverride.setName(attributeOverride.getName()); - newAttributeOverride.getColumn().initializeFrom(attributeOverride.getColumn()); - } - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmAttributeOverride> attributeOverrides() { - return new CompositeListIterator<OrmAttributeOverride>(specifiedAttributeOverrides(), virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<OrmAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.virtualAttributeOverrides); - } - protected void addVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - public ListIterator<OrmAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected OrmAttributeOverride addSpecifiedAttributeOverride(int index) { - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl(); - OrmAttributeOverride attributeOverride = buildAttributeOverride(xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, attributeOverride); - this.getAttributeMapping().getAttributeOverrides().add(index, xmlAttributeOverride); - this.fireItemAdded(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - return attributeOverride; - } - - protected void addSpecifiedAttributeOverride(int index, OrmAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.getAttributeMapping().getAttributeOverrides().move(targetIndex, sourceIndex); - fireItemMoved(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - public OrmAttributeOverride getAttributeOverrideNamed(String name) { - return (OrmAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - protected BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(overrides)) { - String overrideName = override.getName(); - if (overrideName == null && name == null) { - return override; - } - if (overrideName != null && overrideName.equals(name)) { - return override; - } - } - return null; - } - - //****************** AttributeOverride.Owner implemenation ******************* - - public boolean isVirtual(BaseOverride override) { - return this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - // Add a new attribute override - if (virtual) { - return setVirtual((OrmAttributeOverride) override); - } - return setSpecified((OrmAttributeOverride) override); - } - - protected OrmAttributeOverride setVirtual(OrmAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - OrmAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEmbeddedMapping() != null) { - javaAttributeOverride = getJavaEmbeddedMapping().getAttributeOverrideNamed(attributeOverrideName); - } - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - } - } - } - - getAttributeMapping().getAttributeOverrides().remove(index); - fireItemRemoved(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected OrmAttributeOverride setSpecified(OrmAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl(); - OrmAttributeOverride newAttributeOverride = getJpaFactory().buildOrmAttributeOverride(this, this, xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - getAttributeMapping().getAttributeOverrides().add(xmlAttributeOverride); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - public ColumnMapping getColumnMapping(String attributeName) { - return MappingTools.getColumnMapping(attributeName, getEmbeddable()); - } - - public Embeddable getEmbeddable() { - return this.embeddable; - } - - public Iterator<String> allOverridableAttributeNames() { - return new TransformationIterator<PersistentAttribute, String>(this.allOverridableAttributes()) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - if (this.getEmbeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<PersistentAttribute, PersistentAttribute>(this.getEmbeddable().getPersistentType().attributes()) { - @Override - protected boolean accept(PersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - public AbstractJavaBaseEmbeddedMapping<?> getJavaEmbeddedMapping() { - JavaPersistentAttribute javaPersistentAttribute = getJavaPersistentAttribute(); - if (javaPersistentAttribute != null && javaPersistentAttribute.getMappingKey() == getKey()) { - return (AbstractJavaBaseEmbeddedMapping<?>) javaPersistentAttribute.getMapping(); - } - return null; - } - - @Override - public void initialize(T embedded) { - super.initialize(embedded); - this.embeddable = embeddableFor(findJavaPersistentAttribute()); - this.initializeSpecifiedAttributeOverrides(embedded); - this.initializeVirtualAttributeOverrides(); - } - - protected void initializeSpecifiedAttributeOverrides(T embedded) { - for (XmlAttributeOverride attributeOverride : embedded.getAttributeOverrides()) { - this.specifiedAttributeOverrides.add(buildAttributeOverride(attributeOverride)); - } - } - - protected void initializeVirtualAttributeOverrides() { - if (getPersistentAttribute().isVirtual()) { - //specifiedAttributeOverrides are used if the persistentAttribute is virtual - return; - } - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - OrmAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEmbeddedMapping() != null) { - javaAttributeOverride = getJavaEmbeddedMapping().getAttributeOverrideNamed(persistentAttribute.getName()); - } - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - } - - protected OrmAttributeOverride buildVirtualAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - return buildAttributeOverride(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - - protected XmlAttributeOverride buildVirtualXmlAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - XmlColumn xmlColumn; - if (javaAttributeOverride == null) { - ColumnMapping columnMapping = (ColumnMapping) persistentAttribute.getMapping(); - xmlColumn = new VirtualXmlColumn(getTypeMapping(), columnMapping.getColumn(), false); - } - else { - xmlColumn = new VirtualXmlColumn(getTypeMapping(), javaAttributeOverride.getColumn(), true); - } - return new VirtualXmlAttributeOverride(persistentAttribute.getName(), xmlColumn); - } - - protected OrmAttributeOverride buildAttributeOverride(XmlAttributeOverride attributeOverride) { - return getJpaFactory().buildOrmAttributeOverride(this, this, attributeOverride); - } - - @Override - public void update(T embedded) { - super.update(embedded); - this.embeddable = embeddableFor(findJavaPersistentAttribute()); - this.updateSpecifiedAttributeOverrides(embedded); - this.updateVirtualAttributeOverrides(); - } - - protected void updateSpecifiedAttributeOverrides(T embedded) { - ListIterator<OrmAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<XmlAttributeOverride> resourceAttributeOverrides = new CloneListIterator<XmlAttributeOverride>(embedded.getAttributeOverrides());//prevent ConcurrentModificiationException - - while (attributeOverrides.hasNext()) { - OrmAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update(resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride(resourceAttributeOverrides.next())); - } - } - - protected void updateVirtualAttributeOverrides() { - Iterator<PersistentAttribute> overridableAttributes = allOverridableAttributes(); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = virtualAttributeOverrides(); - - if (!getPersistentAttribute().isVirtual()) { - //specifiedAttributeOverrides are used if the persistentAttribute is virtual - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(overridableAttributes)) { - OrmAttributeOverride ormAttributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (ormAttributeOverride != null && !ormAttributeOverride.isVirtual()) { - continue; - } - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEmbeddedMapping() != null) { - javaAttributeOverride = getJavaEmbeddedMapping().getAttributeOverrideNamed(persistentAttribute.getName()); - } - if (ormAttributeOverride != null) { - if (virtualAttributeOverrides.hasNext()) { - OrmAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - virtualAttributeOverride.update(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - } - for (OrmAttributeOverride virtualAttributeOverride : CollectionTools.iterable(virtualAttributeOverrides)) { - removeVirtualAttributeOverride(virtualAttributeOverride); - } - - } - - //************ static methods ************ - - public static Embeddable embeddableFor(JavaPersistentAttribute javaPersistentAttribute) { - if (javaPersistentAttribute == null) { - return null; - } - return MappingTools.getEmbeddableFor(javaPersistentAttribute); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java deleted file mode 100644 index 048751dafa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlGenerator; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class AbstractOrmGenerator<T extends XmlGenerator> extends AbstractOrmJpaContextNode - implements OrmGenerator -{ - - protected String name; - - protected Integer specifiedInitialValue; - protected Integer defaultInitialValue; - - protected Integer specifiedAllocationSize; - protected Integer defaultAllocationSize; - - protected T generatorResource; - - protected AbstractOrmGenerator(OrmJpaContextNode parent) { - super(parent); - } - - public boolean isVirtual() { - return getGeneratorResource().isVirtual(); - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - getGeneratorResource().setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public Integer getInitialValue() { - return (this.getSpecifiedInitialValue() == null) ? this.getDefaultInitialValue() : this.getSpecifiedInitialValue(); - } - - public Integer getSpecifiedInitialValue() { - return this.specifiedInitialValue; - } - - public void setSpecifiedInitialValue(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - getGeneratorResource().setInitialValue(newSpecifiedInitialValue); - firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - protected void setSpecifiedInitialValue_(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - public Integer getDefaultInitialValue() { - return this.defaultInitialValue; - } - - protected void setDefaultInitialValue(Integer newDefaultInitialValue) { - Integer oldSpecifiedInitialValue = this.defaultInitialValue; - this.defaultInitialValue = newDefaultInitialValue; - firePropertyChanged(DEFAULT_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newDefaultInitialValue); - } - - public Integer getAllocationSize() { - return (this.getSpecifiedAllocationSize() == null) ? this.getDefaultAllocationSize() : this.getSpecifiedAllocationSize(); - } - - public Integer getSpecifiedAllocationSize() { - return this.specifiedAllocationSize; - } - - public void setSpecifiedAllocationSize(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - getGeneratorResource().setAllocationSize(newSpecifiedAllocationSize); - firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - protected void setSpecifiedAllocationSize_(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - public Integer getDefaultAllocationSize() { - return this.defaultAllocationSize; - } - - protected void setDefaultAllocationSize(Integer newDefaultAllocationSize) { - Integer oldSpecifiedAllocationSize = this.defaultAllocationSize; - this.defaultAllocationSize = newDefaultAllocationSize; - firePropertyChanged(DEFAULT_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newDefaultAllocationSize); - } - - - public void initialize(T generatorResource) { - this.generatorResource = generatorResource; - this.name = this.name(generatorResource); - this.specifiedInitialValue = this.specifiedInitialValue(generatorResource); - this.specifiedAllocationSize = this.specifiedAllocationSize(generatorResource); - //TODO defaults - } - - public void update(T generatorResource) { - this.generatorResource = generatorResource; - this.setName_(this.name(generatorResource)); - this.setSpecifiedInitialValue_(this.specifiedInitialValue(generatorResource)); - this.setSpecifiedAllocationSize_(this.specifiedAllocationSize(generatorResource)); - //TODO defaults - } - - public boolean overrides(Generator generator) { - if (getName() == null) { - return false; - } - // this isn't ideal, but it will have to do until we have further adopter input - return this.getName().equals(generator.getName()) && generator instanceof JavaGenerator; - } - - protected T getGeneratorResource() { - return this.generatorResource; - } - - protected String name(XmlGenerator generatorResource) { - return generatorResource.getName(); - } - - protected Integer specifiedInitialValue(XmlGenerator generatorResource) { - return generatorResource.getInitialValue(); - } - - protected Integer specifiedAllocationSize(XmlGenerator generatorResource) { - return generatorResource.getAllocationSize(); - } - - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.getGeneratorResource().getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - TextRange nameTextRange = this.getGeneratorResource().getNameTextRange(); - return nameTextRange != null ? nameTextRange : getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJpaContextNode.java deleted file mode 100644 index 6041d883b5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJpaContextNode.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.internal.context.AbstractJpaContextNode; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public abstract class AbstractOrmJpaContextNode extends AbstractJpaContextNode implements OrmJpaContextNode -{ - // ********** constructor ********** - - protected AbstractOrmJpaContextNode(JpaNode parent) { - super(parent); - } - - // ********** validation ********** - - /** - * All subclass implementations {@link #addToMessages(List<IMessage>)} - * should be preceded by a "super" call to this method - */ - public void addToMessages(List<IMessage> messages) { - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java deleted file mode 100644 index e283baf41b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java +++ /dev/null @@ -1,374 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.MultiRelationshipMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlMultiRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmMultiRelationshipMapping<T extends XmlMultiRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> - implements OrmMultiRelationshipMapping -{ - - protected String mappedBy; - - protected String orderBy;//TODO change this to defaultOrderBy and specifiedOrderBy? - - protected boolean isNoOrdering; - - protected boolean isPkOrdering; - - protected boolean isCustomOrdering; - - protected final OrmJoinTable joinTable; - - protected String mapKey; - - protected AbstractOrmMultiRelationshipMapping(OrmPersistentAttribute parent) { - super(parent); - this.joinTable = getJpaFactory().buildOrmJoinTable(this); - } - - @Override - public void initializeFromXmlMulitRelationshipMapping(OrmMultiRelationshipMapping oldMapping) { - super.initializeFromXmlMulitRelationshipMapping(oldMapping); - getJoinTable().initializeFrom(oldMapping.getJoinTable()); - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - public FetchType getDefaultFetch() { - return MultiRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - getAttributeMapping().setMappedBy(newMappedBy); - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - public String getOrderBy() { - return this.orderBy; - } - - public void setOrderBy(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - getAttributeMapping().setOrderBy(newOrderBy); - firePropertyChanged(ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - protected void setOrderBy_(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - firePropertyChanged(ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - public boolean isNoOrdering() { - return this.isNoOrdering; - } - - public void setNoOrdering(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - if (newNoOrdering) { - getAttributeMapping().setOrderBy(null); - } - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - protected void setNoOrdering_(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - public boolean isPkOrdering() { - return this.isPkOrdering; - } - - public void setPkOrdering(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - if (newPkOrdering) { - getAttributeMapping().setOrderBy(""); - } - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - protected void setPkOrdering_(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - public boolean isCustomOrdering() { - return this.isCustomOrdering; - } - - public void setCustomOrdering(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - if (newCustomOrdering) { - setOrderBy(""); - } - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - protected void setCustomOrdering_(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - public OrmJoinTable getJoinTable() { - return this.joinTable; - } - - public boolean isJoinTableSpecified() { - return getJoinTable().isSpecified(); - } - - public String getMapKey() { - return this.mapKey; - } - - public void setMapKey(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - if (oldMapKey != newMapKey) { - if (this.getMapKeyResource() != null) { - this.getMapKeyResource().setName(newMapKey); - if (this.getMapKeyResource().isAllFeaturesUnset()) { - removeMapKeyResource(); - } - } - else if (newMapKey != null) { - addMapKeyResource(); - getMapKeyResource().setName(newMapKey); - } - } - firePropertyChanged(MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - - protected void setMapKey_(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - firePropertyChanged(MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - - protected MapKey getMapKeyResource() { - return getAttributeMapping().getMapKey(); - } - - protected void removeMapKeyResource() { - getAttributeMapping().setMapKey(null); - } - - protected void addMapKeyResource() { - getAttributeMapping().setMapKey(OrmFactory.eINSTANCE.createMapKeyImpl()); - } - - public Iterator<String> candidateMapKeyNames() { - return this.allTargetEntityAttributeNames(); - } - -// public void refreshDefaults(DefaultsContext defaultsContext) { -// super.refreshDefaults(defaultsContext); -// // TODO -// // if (isOrderByPk()) { -// // refreshDefaultOrderBy(defaultsContext); -// // } -// } -// -// //primary key ordering when just the @OrderBy annotation is present -// protected void refreshDefaultOrderBy(DefaultsContext defaultsContext) { -// IEntity targetEntity = getResolvedTargetEntity(); -// if (targetEntity != null) { -// setOrderBy(targetEntity.primaryKeyAttributeName() + " ASC"); -// } -// } -// -// //TODO copied from JavaMultiRelationshipMapping -// /** -// * extract the element type from the specified container signature and -// * convert it into a reference entity type name; -// * return null if the type is not a valid reference entity type (e.g. it's -// * another container or an array or a primitive or other Basic type) -// */ -// @Override -// protected String javaDefaultTargetEntity(ITypeBinding typeBinding) { -// String typeName = super.javaDefaultTargetEntity(typeBinding); -// return JavaRelationshipMapping.typeNamedIsContainer(typeName) ? this.javaDefaultTargetEntityFromContainer(typeBinding) : null; -// } -// -// protected String javaDefaultTargetEntityFromContainer(ITypeBinding typeBinding) { -// return JavaMultiRelationshipMapping.javaDefaultTargetEntityFromContainer(typeBinding); -// } - - public TextRange getMappedByTextRange() { - TextRange mappedByTextRange = getAttributeMapping().getMappedByTextRange(); - return mappedByTextRange != null ? mappedByTextRange : getValidationTextRange(); - } - - @Override - public void initialize(T multiRelationshipMapping) { - super.initialize(multiRelationshipMapping); - this.mappedBy = multiRelationshipMapping.getMappedBy(); - this.mapKey = this.mapKey(multiRelationshipMapping); - this.orderBy = this.orderBy(multiRelationshipMapping); - if (this.orderBy == null) { - this.isNoOrdering = true; - } - else { - this.isCustomOrdering = true; - } - this.joinTable.initialize(multiRelationshipMapping); - } - - @Override - public void update(T multiRelationshipMapping) { - super.update(multiRelationshipMapping); - this.setMappedBy_(multiRelationshipMapping.getMappedBy()); - this.setMapKey_(this.mapKey(multiRelationshipMapping)); - this.setOrderBy_(this.orderBy(multiRelationshipMapping)); - if (getOrderBy() == null) { - setNoOrdering_(true); - setPkOrdering_(false); - setCustomOrdering_(false); - } - else { - setNoOrdering_(false); - setPkOrdering_(false); - setCustomOrdering_(true); - } - this.joinTable.update(multiRelationshipMapping); - } - - protected String mapKey(T multiRelationshipMapping) { - return multiRelationshipMapping.getMapKey() == null ? null : multiRelationshipMapping.getMapKey().getName(); - } - - protected String orderBy(T multiRelationshipMapping) { - return multiRelationshipMapping.getOrderBy(); - } - - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource) { - if (!persistentAttributeResource.typeIsContainer()) { - return null; - } - return persistentAttributeResource.getQualifiedReferenceEntityElementTypeName(); - } - - //****************** validation ******************8 - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (entityOwned() && (this.isJoinTableSpecified() || isRelationshipOwner())) { - getJoinTable().addToMessages(messages); - } - if (getMappedBy() != null) { - addMappedByMessages(messages); - } - } - - protected void addMappedByMessages(List<IMessage> messages) { - if (isJoinTableSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_WITH_JOIN_TABLE, - getJoinTable(), - getJoinTable().getValidationTextRange()) - ); - } - - if (getResolvedTargetEntity() == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = getResolvedTargetEntity().getPersistentType().resolveAttribute(getMappedBy()); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {getMappedBy()}, - this, - getMappedByTextRange()) - ); - return; - } - - if (! mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {getMappedBy()}, - this, - getMappedByTextRange()) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, - getMappedByTextRange()) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java deleted file mode 100644 index b54a586675..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.resource.orm.XmlNamedColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; - - -public abstract class AbstractOrmNamedColumn<T extends XmlNamedColumn> extends AbstractOrmJpaContextNode - implements OrmNamedColumn -{ - protected Owner owner; - - protected String specifiedName; - - protected String defaultName; - - protected String columnDefinition; - - protected AbstractOrmNamedColumn(OrmJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public void initializeFrom(NamedColumn oldColumn) { - setSpecifiedName(oldColumn.getSpecifiedName()); - setColumnDefinition(oldColumn.getColumnDefinition()); - } - - protected abstract T getColumnResource(); - - protected abstract void removeColumnResource(); - - protected abstract void addColumnResource(); - - public Owner getOwner() { - return this.owner; - } - - public String getName() { - return (this.specifiedName != null) ? this.specifiedName : this.defaultName; - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - if (oldSpecifiedName != newSpecifiedName) { - if (this.getColumnResource() != null) { - this.getColumnResource().setName(newSpecifiedName); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedName != null) { - addColumnResource(); - getColumnResource().setName(newSpecifiedName); - } - } - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public String getColumnDefinition() { - return this.columnDefinition; - } - - public void setColumnDefinition(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - if (oldColumnDefinition != newColumnDefinition) { - if (this.getColumnResource() != null) { - this.getColumnResource().setColumnDefinition(newColumnDefinition); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newColumnDefinition != null) { - addColumnResource(); - getColumnResource().setColumnDefinition(newColumnDefinition); - } - } - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - protected void setColumnDefinition_(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - public Column getDbColumn() { - Table table = this.getDbTable(); - return (table == null) ? null : table.getColumnNamed(getName()); - } - - public Table getDbTable() { - return getOwner().getDbTable(this.tableName()); - } - - protected abstract String tableName(); - - public boolean isResolved() { - return getDbColumn() != null; - } - - public TextRange getNameTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - public TextRange getValidationTextRange() { - TextRange textRange = getColumnResource().getValidationTextRange(); - if (textRange != null) { - return textRange; - } - return getOwner().getValidationTextRange(); - } - - - // ******************* initialization from orm xml resource model ******************** - - protected void initialize(T column) { - this.specifiedName = this.specifiedName(column); - this.defaultName = this.defaultName(); - this.columnDefinition = this.specifiedColumnDefinition(column); - } - - protected void update(T column) { - setSpecifiedName_(this.specifiedName(column)); - setDefaultName(this.defaultName()); - setColumnDefinition_(this.specifiedColumnDefinition(column)); - } - - protected String specifiedName(T column) { - return column == null ? null : column.getName(); - } - - protected String specifiedColumnDefinition(T column) { - return column == null ? null : column.getColumnDefinition(); - } - - /** - * Return the default column name. - */ - protected String defaultName() { - return this.getOwner().getDefaultColumnName(); - } - - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java deleted file mode 100644 index a3cf36ff69..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlQuery; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - - -public abstract class AbstractOrmQuery<E extends XmlQuery> extends AbstractOrmJpaContextNode - implements OrmQuery -{ - - protected String name; - - protected String query; - - protected final List<OrmQueryHint> hints; - - protected E queryResource; - - protected AbstractOrmQuery(OrmJpaContextNode parent) { - super(parent); - this.hints = new ArrayList<OrmQueryHint>(); - } - - protected E getQueryResource() { - return this.queryResource; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.getQueryResource().setName(newName); - firePropertyChanged(Query.NAME_PROPERTY, oldName, newName); - } - - public String getQuery() { - return this.query; - } - - public void setQuery(String newQuery) { - String oldQuery = this.query; - this.query = newQuery; - this.getQueryResource().setQuery(newQuery); - firePropertyChanged(Query.QUERY_PROPERTY, oldQuery, newQuery); - } - - public ListIterator<OrmQueryHint> hints() { - return new CloneListIterator<OrmQueryHint>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public OrmQueryHint addHint(int index) { - OrmQueryHint queryHint = getJpaFactory().buildOrmQueryHint(this); - this.hints.add(index, queryHint); - this.getQueryResource().getHints().add(index, OrmFactory.eINSTANCE.createXmlQueryHint()); - this.fireItemAdded(Query.HINTS_LIST, index, queryHint); - return queryHint; - } - - protected void addHint(int index, OrmQueryHint queryHint) { - addItemToList(index, queryHint, this.hints, Query.HINTS_LIST); - } - - public void removeHint(QueryHint queryHint) { - removeHint(this.hints.indexOf(queryHint)); - } - - public void removeHint(int index) { - OrmQueryHint queryHint = this.hints.remove(index); - this.queryResource.getHints().remove(index); - fireItemRemoved(Query.HINTS_LIST, index, queryHint); - } - - protected void removeHint_(OrmQueryHint queryHint) { - removeItemFromList(queryHint, this.hints, Query.HINTS_LIST); - } - - public void moveHint(int targetIndex, int sourceIndex) { - this.queryResource.getHints().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.hints, Query.HINTS_LIST); - - } - - - public void initialize(E queryResource) { - this.queryResource = queryResource; - this.name = queryResource.getName(); - this.query = queryResource.getQuery(); - this.initializeHints(queryResource); - } - - protected void initializeHints(E queryResource) { - for (XmlQueryHint queryhint : queryResource.getHints()) { - this.hints.add(createHint(queryhint)); - } - } - - protected OrmQueryHint createHint(XmlQueryHint queryHint) { - OrmQueryHint ormQueryHint = getJpaFactory().buildOrmQueryHint(this); - ormQueryHint.initialize(queryHint); - return ormQueryHint; - } - - public void update(E queryResource) { - this.queryResource = queryResource; - this.setName(queryResource.getName()); - this.setQuery(queryResource.getQuery()); - this.updateHints(queryResource); - } - - protected void updateHints(E queryResource) { - ListIterator<OrmQueryHint> hints = hints(); - ListIterator<XmlQueryHint> resourceHints = new CloneListIterator<XmlQueryHint>(queryResource.getHints());//prevent ConcurrentModificiationException - - while (hints.hasNext()) { - OrmQueryHint hint = hints.next(); - if (resourceHints.hasNext()) { - hint.update(resourceHints.next()); - } - else { - removeHint_(hint); - } - } - - while (resourceHints.hasNext()) { - addHint(hintsSize(), createHint(resourceHints.next())); - } - } - - public boolean overrides(Query query) { - if (getName() == null) { - return false; - } - // this isn't ideal, but it will have to do until we have further adopter input - return this.getName().equals(query.getName()) && query instanceof JavaQuery; - } - - public TextRange getValidationTextRange() { - return this.getQueryResource().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.getQueryResource().getNameTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java deleted file mode 100644 index 7406f6f2c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.XmlRelationshipMapping; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public abstract class AbstractOrmRelationshipMapping<T extends XmlRelationshipMapping> extends AbstractOrmAttributeMapping<T> - implements OrmRelationshipMapping -{ - - protected String specifiedTargetEntity; - - protected String defaultTargetEntity; - - protected Entity resolvedTargetEntity; - - protected FetchType specifiedFetch; - - protected final OrmCascade cascade; - - - protected AbstractOrmRelationshipMapping(OrmPersistentAttribute parent) { - super(parent); - this.cascade = new OrmCascade(this); - } - - public String getTargetEntity() { - return (this.getSpecifiedTargetEntity() == null) ? getDefaultTargetEntity() : this.getSpecifiedTargetEntity(); - } - - public String getSpecifiedTargetEntity() { - return this.specifiedTargetEntity; - } - - public void setSpecifiedTargetEntity(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - getAttributeMapping().setTargetEntity(newSpecifiedTargetEntity); - firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - protected void setSpecifiedTargetEntity_(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - public String getDefaultTargetEntity() { - return this.defaultTargetEntity; - } - - protected void setDefaultTargetEntity(String newDefaultTargetEntity) { - String oldDefaultTargetEntity = this.defaultTargetEntity; - this.defaultTargetEntity = newDefaultTargetEntity; - firePropertyChanged(DEFAULT_TARGET_ENTITY_PROPERTY, oldDefaultTargetEntity, newDefaultTargetEntity); - } - - public Entity getResolvedTargetEntity() { - return this.resolvedTargetEntity; - } - - protected void setResolvedTargetEntity(Entity newResolvedTargetEntity) { - Entity oldResolvedTargetEntity = this.resolvedTargetEntity; - this.resolvedTargetEntity = newResolvedTargetEntity; - firePropertyChanged(RESOLVED_TARGET_ENTITY_PROPERTY, oldResolvedTargetEntity, newResolvedTargetEntity); - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.getAttributeMapping().setFetch(FetchType.toOrmResourceModel(newSpecifiedFetch)); - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - public OrmCascade getCascade() { - return this.cascade; - } - - - @Override - public void initializeFromXmlRelationshipMapping(OrmRelationshipMapping oldMapping) { - super.initializeFromXmlRelationshipMapping(oldMapping); - setSpecifiedTargetEntity(oldMapping.getSpecifiedTargetEntity()); - setSpecifiedFetch(oldMapping.getSpecifiedFetch()); - getCascade().initializeFrom(oldMapping.getCascade()); - //TODO should we set the fetch type from a BasicMapping?? - } - - public Iterator<String> allTargetEntityAttributeNames() { - Entity targetEntity = this.getResolvedTargetEntity(); - return (targetEntity == null) ? EmptyIterator.<String> instance() : targetEntity.getPersistentType().allAttributeNames(); - } - - public Iterator<String> candidateMappedByAttributeNames() { - return this.allTargetEntityAttributeNames(); - } - - public Entity getEntity() { - if (getTypeMapping() instanceof Entity) { - return (Entity) getTypeMapping(); - } - return null; - } - - @Override - public void initialize(T relationshipMapping) { - super.initialize(relationshipMapping); - this.specifiedTargetEntity = relationshipMapping.getTargetEntity(); - this.defaultTargetEntity = this.defaultTargetEntity(); - this.resolvedTargetEntity = this.resolveTargetEntity(); - this.specifiedFetch = this.specifiedFetch(relationshipMapping); - this.cascade.initialize(relationshipMapping); - } - - @Override - public void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setSpecifiedTargetEntity_(relationshipMapping.getTargetEntity()); - this.setDefaultTargetEntity(this.defaultTargetEntity()); - this.setResolvedTargetEntity(this.resolveTargetEntity()); - this.setSpecifiedFetch_(this.specifiedFetch(relationshipMapping)); - this.cascade.update(relationshipMapping); - } - - protected FetchType specifiedFetch(XmlRelationshipMapping relationshipMapping) { - return FetchType.fromOrmResourceModel(relationshipMapping.getFetch()); - } - - protected RelationshipMapping javaRelationshipMapping() { - if (findJavaPersistentAttribute() == null) { - return null; - } - AttributeMapping javaAttributeMapping = findJavaPersistentAttribute().getMapping(); - if (javaAttributeMapping instanceof RelationshipMapping) { - return ((RelationshipMapping) javaAttributeMapping); - } - return null; - } - - protected String defaultTargetEntity() { - RelationshipMapping javaMapping = javaRelationshipMapping(); - if (javaMapping != null) { - if (getPersistentAttribute().isVirtual() && !getTypeMapping().isMetadataComplete()) { - return javaMapping.getTargetEntity(); - } - } - if (findJavaPersistentAttribute() != null) { - return defaultTargetEntity(findJavaPersistentAttribute().getResourcePersistentAttribute()); - } - return null; - } - - protected abstract String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource); - - protected Entity resolveTargetEntity() { - if (getTargetEntity() == null) { - return null; - } - PersistentType persistentType = getTargetPersistentType(); - if (persistentType != null && persistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (Entity) persistentType.getMapping(); - } - return null; - } - - protected PersistentType getTargetPersistentType() { - // try to resolve by only the locally specified name - PersistentType persistentType = getPersistenceUnit().getPersistentType(getTargetEntity()); - if (persistentType == null) { - // try to resolve by prepending the global package name - persistentType = getPersistenceUnit().getPersistentType(getEntityMappings().getPackage() + "." + getTargetEntity()); - } - return persistentType; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java deleted file mode 100644 index 5b02eba937..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.SingleRelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmSingleRelationshipMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSingleRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmSingleRelationshipMapping<T extends XmlSingleRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> implements OrmSingleRelationshipMapping -{ - - protected final List<OrmJoinColumn> specifiedJoinColumns; - - protected OrmJoinColumn defaultJoinColumn; - - protected Boolean specifiedOptional; - - protected AbstractOrmSingleRelationshipMapping(OrmPersistentAttribute parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<OrmJoinColumn>(); - } - - @Override - public void initializeFromXmlSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - super.initializeFromXmlSingleRelationshipMapping(oldMapping); - int index = 0; - for (JoinColumn joinColumn : CollectionTools.iterable(oldMapping.specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - public FetchType getDefaultFetch() { - return SingleRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - //***************** ISingleRelationshipMapping implementation ***************** - public ListIterator<OrmJoinColumn> joinColumns() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumns() : this.specifiedJoinColumns(); - } - - public int joinColumnsSize() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumnsSize() : this.specifiedJoinColumnsSize(); - } - - public OrmJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(OrmJoinColumn newJoinColumn) { - OrmJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - protected ListIterator<OrmJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<OrmJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - OrmJoinColumn oldDefaultJoinColumn = this.getDefaultJoinColumn(); - if (oldDefaultJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultJoinColumn = null; - } - XmlJoinColumn xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumnImpl(); - OrmJoinColumn joinColumn = buildJoinColumn(xmlJoinColumn); - this.specifiedJoinColumns.add(index, joinColumn); - this.getAttributeMapping().getJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldDefaultJoinColumn, null); - } - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = buildJoinColumn(null); - } - this.getAttributeMapping().getJoinColumns().remove(index); - fireItemRemoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getAttributeMapping().getJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public Boolean getOptional() { - return getSpecifiedOptional() == null ? getDefaultOptional() : getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - getAttributeMapping().setOptional(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - @Override - public void initialize(T singleRelationshipMapping) { - super.initialize(singleRelationshipMapping); - this.specifiedOptional = singleRelationshipMapping.getOptional(); - //TODO defaultOptional - this.initializeSpecifiedJoinColumns(singleRelationshipMapping); - this.initializeDefaultJoinColumn(); - } - - protected void initializeSpecifiedJoinColumns(T singleRelationshipMapping) { - if (singleRelationshipMapping == null) { - return; - } - for (XmlJoinColumn joinColumn : singleRelationshipMapping.getJoinColumns()) { - this.specifiedJoinColumns.add(buildJoinColumn(joinColumn)); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns() && isRelationshipOwner(); - } - - protected void initializeDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(null); - } - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - @Override - public void update(T singleRelationshipMapping) { - super.update(singleRelationshipMapping); - this.setSpecifiedOptional_(singleRelationshipMapping.getOptional()); - this.updateSpecifiedJoinColumns(singleRelationshipMapping); - this.updateDefaultJoinColumn(); - } - - protected void updateSpecifiedJoinColumns(T singleRelationshipMapping) { - ListIterator<OrmJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<XmlJoinColumn> resourceJoinColumns = EmptyListIterator.instance(); - if (singleRelationshipMapping != null) { - resourceJoinColumns = new CloneListIterator<XmlJoinColumn>(singleRelationshipMapping.getJoinColumns());//prevent ConcurrentModificiationException - } - - while (joinColumns.hasNext()) { - OrmJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn(resourceJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(null)); - } - else { - this.defaultJoinColumn.update(null); - } - } - - /** - * eliminate any "container" types - */ - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource) { - if (persistentAttributeResource.typeIsContainer()) { - return null; - } - return persistentAttributeResource.getQualifiedReferenceEntityTypeName(); - } - - //********************* validation ****************** - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (addJoinColumnMessages()) { - addJoinColumnMessages(messages); - } - } - - //bug 192287 - do not want joinColumn validation errors on the non-owning side - //of a bidirectional relationship. This is a low risk fix for RC3, but a better - //solution would be to not have the default joinColumns on the non-owning side. - //This would fix another bug that we show default joinColumns in this situation. - protected boolean addJoinColumnMessages() { - return (entityOwned() && isRelationshipOwner()); - } - - protected void addJoinColumnMessages(List<IMessage> messages) { - boolean doContinue = this.connectionProfileIsActive(); - - for (OrmJoinColumn joinColumn : CollectionTools.iterable(joinColumns())) { - String table = joinColumn.getTable(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! joinColumn.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange()) - ); - } - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange()) - ); - } - } - } - } - - - public class JoinColumnOwner implements OrmJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return AbstractOrmSingleRelationshipMapping.this.getTypeMapping().getTableName(); - } - - public Entity getTargetEntity() { - return AbstractOrmSingleRelationshipMapping.this.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return AbstractOrmSingleRelationshipMapping.this.getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return AbstractOrmSingleRelationshipMapping.this; - } - - public boolean tableNameIsInvalid(String tableName) { - return AbstractOrmSingleRelationshipMapping.this.getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TypeMapping getTypeMapping() { - return AbstractOrmSingleRelationshipMapping.this.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractOrmSingleRelationshipMapping.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return AbstractOrmSingleRelationshipMapping.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return AbstractOrmSingleRelationshipMapping.this.getValidationTextRange(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java deleted file mode 100644 index 46d2cdfb7c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java +++ /dev/null @@ -1,409 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBaseTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public abstract class AbstractOrmTable extends AbstractOrmJpaContextNode implements UniqueConstraint.Owner -{ - protected String specifiedName; - - protected String defaultName; - - protected String specifiedCatalog; - - protected String defaultCatalog; - - protected String specifiedSchema; - - protected String defaultSchema; - - protected final List<OrmUniqueConstraint> uniqueConstraints; - - - protected AbstractOrmTable(OrmJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<OrmUniqueConstraint>(); - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public void initializeFrom(Table oldTable) { - setSpecifiedName(oldTable.getSpecifiedName()); - setSpecifiedCatalog(oldTable.getSpecifiedCatalog()); - setSpecifiedSchema(oldTable.getSpecifiedSchema()); - } - - - public String getName() { - return (this.getSpecifiedName() == null) ? this.getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - /** - * Return null if no table resource element exists - */ - protected abstract XmlBaseTable getTableResource(); - - protected abstract void removeTableResource(); - - protected abstract void addTableResource(); - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - if (oldSpecifiedName != newSpecifiedName) { - if (this.getTableResource() != null) { - this.getTableResource().setName(newSpecifiedName); - if (this.getTableResource().isAllFeaturesUnset()) { - removeTableResource(); - } - } - else if (newSpecifiedName != null) { - addTableResource(); - getTableResource().setName(newSpecifiedName); - } - } - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(Table.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - if (oldSpecifiedCatalog != newSpecifiedCatalog) { - if (this.getTableResource() != null) { - this.getTableResource().setCatalog(newSpecifiedCatalog); - if (this.getTableResource().isAllFeaturesUnset()) { - removeTableResource(); - } - } - else if (newSpecifiedCatalog != null) { - addTableResource(); - getTableResource().setCatalog(newSpecifiedCatalog); - } - } - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(Table.DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - if (oldSpecifiedSchema != newSpecifiedSchema) { - if (this.getTableResource() != null) { - this.getTableResource().setSchema(newSpecifiedSchema); - if (this.getTableResource().isAllFeaturesUnset()) { - removeTableResource(); - } - } - else if (newSpecifiedSchema != null) { - addTableResource(); - getTableResource().setSchema(newSpecifiedSchema); - } - } - - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(Table.DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - - // ********** unique constraints ********** - - public ListIterator<OrmUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<OrmUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public OrmUniqueConstraint addUniqueConstraint(int index) { - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - OrmUniqueConstraint uniqueConstraint = buildUniqueConstraint(uniqueConstraintResource); - this.uniqueConstraints.add(index, uniqueConstraint); - - if (this.getTableResource() == null) { - addTableResource(); - } - - getTableResource().getUniqueConstraints().add(index, uniqueConstraintResource); - fireItemAdded(Table.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - protected void addUniqueConstraint(int index, OrmUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - OrmUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - getTableResource().getUniqueConstraints().remove(index); - fireItemRemoved(Table.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - protected void removeUniqueConstraint_(OrmUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getTableResource().getUniqueConstraints().move(targetIndex, sourceIndex); - fireItemMoved(Table.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - public org.eclipse.jpt.db.Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.getTableNamed(getName()); - } - - public Schema getDbSchema() { - return this.getDataSource().getSchemaNamed(getSchema()); - } - - public boolean hasResolvedSchema() { - return getDbSchema() != null; - } - - public boolean isResolved() { - return getDbTable() != null; - } - - protected void initialize(XmlBaseTable table) { - this.specifiedName = this.specifiedName(table); - this.specifiedSchema = this.specifiedSchema(table); - this.specifiedCatalog = this.specifiedCatalog(table); - this.defaultName = this.defaultName(); - this.defaultSchema = this.defaultSchema(); - this.defaultCatalog = this.defaultCatalog(); - this.initializeUniqueContraints(table); - } - - protected void initializeUniqueContraints(XmlBaseTable table) { - if (table == null) { - return; - } - for (XmlUniqueConstraint uniqueConstraint : table.getUniqueConstraints()) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraint)); - } - } - - protected void update(XmlBaseTable table) { - this.setSpecifiedName_(this.specifiedName(table)); - this.setSpecifiedSchema_(this.specifiedSchema(table)); - this.setSpecifiedCatalog_(this.specifiedCatalog(table)); - this.setDefaultName(this.defaultName()); - this.setDefaultSchema(this.defaultSchema()); - this.setDefaultCatalog(this.defaultCatalog()); - this.updateUniqueConstraints(table); - } - - protected String specifiedName(XmlBaseTable table) { - return table == null ? null : table.getName(); - } - - protected String specifiedSchema(XmlBaseTable table) { - return table == null ? null : table.getSchema(); - } - - protected String specifiedCatalog(XmlBaseTable table) { - return table == null ? null : table.getCatalog(); - } - - protected abstract String defaultName(); - - protected abstract String defaultSchema(); - - protected abstract String defaultCatalog(); - - protected void updateUniqueConstraints(XmlBaseTable table) { - ListIterator<OrmUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<XmlUniqueConstraint> resourceUniqueConstraints; - if (table == null) { - resourceUniqueConstraints = EmptyListIterator.instance(); - } - else { - resourceUniqueConstraints = new CloneListIterator<XmlUniqueConstraint>(table.getUniqueConstraints());//prevent ConcurrentModificiationException - } - while (uniqueConstraints.hasNext()) { - OrmUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected OrmUniqueConstraint buildUniqueConstraint(XmlUniqueConstraint xmlUniqueConstraint) { - return getJpaFactory().buildOrmUniqueConstraint(this, this, xmlUniqueConstraint); - } - - - public String qualifiedName() { - return NameTools.buildQualifiedDatabaseObjectName(this.getCatalog(), this.getSchema(), this.getName()); - } - - protected TextRange getNameTextRange() { - if (getTableResource() != null) { - TextRange textRange = getTableResource().getNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - protected TextRange getCatalogTextRange() { - if (getTableResource() != null) { - TextRange textRange = getTableResource().getCatalogTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - protected TextRange getSchemaTextRange() { - if (getTableResource() != null) { - TextRange textRange = getTableResource().getSchemaTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - public TextRange getValidationTextRange() { - if (getTableResource() != null) { - TextRange textRange = this.getTableResource().getValidationTextRange(); - if (textRange != null) { - return textRange; - } - } - return getParent().getValidationTextRange(); - } - - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(qualifiedName()); - } - - @Override - public String displayString() { - return qualifiedName(); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java deleted file mode 100644 index 5a6601b891..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java +++ /dev/null @@ -1,367 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> extends AbstractOrmJpaContextNode implements OrmTypeMapping -{ - - protected String class_; - - public AccessType defaultAccess; - - protected AccessType specifiedAccess; - - public boolean defaultMetadataComplete; - - protected Boolean specifiedMetadataComplete; - - protected JavaPersistentType javaPersistentType; - - protected T typeMapping; - - protected AbstractOrmTypeMapping(OrmPersistentType parent) { - super(parent); - } - - public boolean isMapped() { - return true; - } - - public String getTableName() { - return null; - } - - public String getClass_() { - return this.class_; - } - - public void setClass(String newClass) { - String oldClass = this.class_; - this.class_ = newClass; - this.getTypeMappingResource().setClassName(newClass); - firePropertyChanged(CLASS_PROPERTY, oldClass, newClass); - getPersistentType().classChanged(oldClass, newClass); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newDefaultAccess) { - AccessType oldDefaultAccess = this.defaultAccess; - this.defaultAccess = newDefaultAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldDefaultAccess, newDefaultAccess); - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - public void setSpecifiedAccess(AccessType newSpecifiedAccess) { - AccessType oldSpecifiedAccess = this.specifiedAccess; - this.specifiedAccess = newSpecifiedAccess; - this.getTypeMappingResource().setAccess(AccessType.toXmlResourceModel(newSpecifiedAccess)); - firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, oldSpecifiedAccess, newSpecifiedAccess); - } - - public AccessType getAccess() { - return (this.getSpecifiedAccess() == null) ? this.getDefaultAccess() : this.getSpecifiedAccess(); - } - - public boolean isMetadataComplete() { - if (isDefaultMetadataComplete()) { - //entity-mappings/persistence-unit-metadata/xml-mapping-metadata-complete is specified, then it overrides - //anything set here - return true; - } - return (this.getSpecifiedMetadataComplete() == null) ? this.isDefaultMetadataComplete() : this.getSpecifiedMetadataComplete().booleanValue(); - } - - public boolean isDefaultMetadataComplete() { - return this.defaultMetadataComplete; - } - - protected void setDefaultMetadataComplete(boolean newDefaultMetadataComplete) { - boolean oldMetadataComplete = this.defaultMetadataComplete; - this.defaultMetadataComplete = newDefaultMetadataComplete; - firePropertyChanged(DEFAULT_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newDefaultMetadataComplete); - } - - public Boolean getSpecifiedMetadataComplete() { - return this.specifiedMetadataComplete; - } - - public void setSpecifiedMetadataComplete(Boolean newSpecifiedMetadataComplete) { - Boolean oldMetadataComplete = this.specifiedMetadataComplete; - this.specifiedMetadataComplete = newSpecifiedMetadataComplete; - this.getTypeMappingResource().setMetadataComplete(newSpecifiedMetadataComplete); - firePropertyChanged(SPECIFIED_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newSpecifiedMetadataComplete); - } - - public OrmPersistentType getPersistentType() { - return (OrmPersistentType) getParent(); - } - - /** - * ITypeMapping is changed and various ITypeMappings may have - * common settings. In this method initialize the new ITypeMapping (this) - * fromthe old ITypeMapping (oldMapping) - * @param oldMapping - */ - public void initializeFrom(OrmTypeMapping oldMapping) { - this.setClass(oldMapping.getClass_()); - this.setSpecifiedAccess(oldMapping.getSpecifiedAccess()); - this.setSpecifiedMetadataComplete(oldMapping.getSpecifiedMetadataComplete()); - this.setDefaultAccess(oldMapping.getDefaultAccess()); - this.setDefaultMetadataComplete(oldMapping.isDefaultMetadataComplete()); - } - - public Table getPrimaryDbTable() { - return null; - } - - public Table getDbTable(String tableName) { - return null; - } - - public Schema getDbSchema() { - return null; - } - - /** - * @see TypeMapping#attributeMappingKeyAllowed(String) - * - * Default implementation: override where needed - */ - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return true; - } - - public Iterator<OrmPersistentAttribute> overridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<OrmPersistentAttribute> overridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAssociationNames() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAssociationNames() { - return EmptyIterator.instance(); - } - - public T getTypeMappingResource() { - return this.typeMapping; - } - - protected PersistenceUnitMetadata getPersistenceUnitMetadata() { - return getEntityMappings().getPersistenceUnitMetadata(); - } - - protected boolean defaultMetadataComplete() { - return getPersistenceUnitMetadata().isXmlMappingMetadataComplete(); - } - - protected AccessType defaultAccess() { - if (!isMetadataComplete()) { - if (getJavaPersistentType() != null) { - if (getJavaPersistentType().hasAnyAttributeMappingAnnotations()) { - return getJavaPersistentType().getAccess(); - } - if (getPersistentType().getParentPersistentType() != null) { - return getPersistentType().getParentPersistentType().getAccess(); - } - } - } - return getEntityMappings().getAccess(); - } - - public JavaPersistentType getJavaPersistentType() { - return this.javaPersistentType; - } - - protected void setJavaPersistentType(JavaPersistentType newJavaPersistentType) { - JavaPersistentType oldJavaPersistentType = this.javaPersistentType; - this.javaPersistentType = newJavaPersistentType; - firePropertyChanged(JAVA_PERSISTENT_TYPE_PROPERTY, oldJavaPersistentType, newJavaPersistentType); - } - - protected void initializeJavaPersistentType() { - JavaResourcePersistentType persistentTypeResource = getJavaResourcePersistentType(); - if (persistentTypeResource != null) { - this.javaPersistentType = buildJavaPersistentType(persistentTypeResource); - } - } - - protected JavaResourcePersistentType getJavaResourcePersistentType() { - // try to resolve by only the locally specified name - JavaResourcePersistentType persistentTypeResource = getJpaProject().getJavaResourcePersistentType(getClass_()); - if (persistentTypeResource == null) { - // try to resolve by prepending the global package name - persistentTypeResource = getJpaProject().getJavaResourcePersistentType(getEntityMappings().getPackage() + "." + getClass_()); - } - return persistentTypeResource; - } - - protected void updateJavaPersistentType() { - JavaResourcePersistentType persistentTypeResource = getJavaResourcePersistentType(); - if (persistentTypeResource == null) { - setJavaPersistentType(null); - } - else { - if (getJavaPersistentType() != null) { - getJavaPersistentType().update(persistentTypeResource); - } - else { - setJavaPersistentType(buildJavaPersistentType(persistentTypeResource)); - } - } - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourcePersistentType resourcePersistentType) { - return getJpaFactory().buildJavaPersistentType(this, resourcePersistentType); - } - - public void initialize(T typeMapping) { - this.typeMapping = typeMapping; - this.class_ = typeMapping.getClassName(); - this.initializeJavaPersistentType(); - this.specifiedMetadataComplete = this.metadataComplete(typeMapping); - this.defaultMetadataComplete = this.defaultMetadataComplete(); - this.specifiedAccess = AccessType.fromXmlResourceModel(typeMapping.getAccess()); - this.defaultAccess = this.defaultAccess(); - } - - public void update(T typeMapping) { - this.typeMapping = typeMapping; - this.setClass(typeMapping.getClassName()); - this.updateJavaPersistentType(); - this.setSpecifiedMetadataComplete(this.metadataComplete(typeMapping)); - this.setDefaultMetadataComplete(this.defaultMetadataComplete()); - this.setSpecifiedAccess(AccessType.fromXmlResourceModel(typeMapping.getAccess())); - this.setDefaultAccess(this.defaultAccess()); - } - - protected Boolean metadataComplete(AbstractXmlTypeMapping typeMapping) { - return typeMapping.getMetadataComplete(); - } - - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int offset) { - if (this.typeMapping.containsOffset(offset)) { - return getPersistentType(); - } - return null; - } - - public TextRange getSelectionTextRange() { - return this.typeMapping.getSelectionTextRange(); - } - - public TextRange getClassTextRange() { - return this.typeMapping.getClassTextRange(); - } - - public TextRange getAttributesTextRange() { - return this.typeMapping.getAttributesTextRange(); - } - - public boolean containsOffset(int textOffset) { - if (this.typeMapping == null) { - return false; - } - return this.typeMapping.containsOffset(textOffset); - } - - //************************* validation ************************ - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addClassMessages(messages); - } - protected void addClassMessages(List<IMessage> messages) { - addUnspecifiedClassMessage(messages); - addUnresolvedClassMessage(messages); - } - - protected void addUnspecifiedClassMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getClass_())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CLASS, - this, - this.getClassTextRange()) - ); - } - } - - protected void addUnresolvedClassMessage(List<IMessage> messages) { - if (! StringTools.stringIsEmpty(getClass_()) - && getJavaPersistentType() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNRESOLVED_CLASS, - new String[] {getClass_()}, - this, - this.getClassTextRange()) - ); - } - } - - public TextRange getValidationTextRange() { - return this.typeMapping.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java deleted file mode 100644 index 4b7293fb34..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java +++ /dev/null @@ -1,868 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHolder; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericEntityMappings extends AbstractOrmJpaContextNode implements EntityMappings -{ - protected XmlEntityMappings xmlEntityMappings; - - protected String version; - - protected String description; - - protected String package_; - - protected String defaultSchema; - - protected String specifiedSchema; - - protected String defaultCatalog; - - protected String specifiedCatalog; - - protected AccessType defaultAccess; - - protected AccessType specifiedAccess; - - protected final PersistenceUnitMetadata persistenceUnitMetadata; - - protected final List<OrmPersistentType> persistentTypes; - - protected final List<OrmSequenceGenerator> sequenceGenerators; - - protected final List<OrmTableGenerator> tableGenerators; - - protected final List<OrmNamedQuery> namedQueries; - - protected final List<OrmNamedNativeQuery> namedNativeQueries; - - - public GenericEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.persistenceUnitMetadata = getJpaFactory().buildPersistenceUnitMetadata(this, xmlEntityMappings); - this.persistentTypes = new ArrayList<OrmPersistentType>(); - this.sequenceGenerators = new ArrayList<OrmSequenceGenerator>(); - this.tableGenerators = new ArrayList<OrmTableGenerator>(); - this.namedQueries = new ArrayList<OrmNamedQuery>(); - this.namedNativeQueries = new ArrayList<OrmNamedNativeQuery>(); - this.initialize(xmlEntityMappings); - } - - public String getId() { - return OrmStructureNodes.ENTITY_MAPPINGS_ID; - } - - @Override - public EntityMappings getEntityMappings() { - return this; - } - - @Override - public OrmXml getParent() { - return (OrmXml) super.getParent(); - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - for (OrmPersistentType ormPersistentType : CollectionTools.iterable(ormPersistentTypes())) { - if (ormPersistentType.isFor(fullyQualifiedTypeName)) { - return ormPersistentType; - } - } - return null; - } - - public PersistenceUnitMetadata getPersistenceUnitMetadata() { - return this.persistenceUnitMetadata; - } - - public String getPackage() { - return this.package_; - } - - public void setPackage(String newPackage) { - String oldPackage = this.package_; - this.package_ = newPackage; - this.xmlEntityMappings.setPackage(newPackage); - firePropertyChanged(PACKAGE_PROPERTY, oldPackage, newPackage); - } - - public String getVersion() { - return this.version; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String newDescription) { - String oldDescription = this.description; - this.description = newDescription; - this.xmlEntityMappings.setDescription(newDescription); - firePropertyChanged(DESCRIPTION_PROPERTY, oldDescription, newDescription); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - this.xmlEntityMappings.setSchema(newSpecifiedSchema); - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? this.getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - this.xmlEntityMappings.setCatalog(newSpecifiedCatalog); - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? this.getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public AccessType getAccess() { - return (this.getSpecifiedAccess() == null) ? this.getDefaultAccess() : this.getSpecifiedAccess(); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newDefaultAccess) { - AccessType oldDefaultAccess = this.defaultAccess; - this.defaultAccess = newDefaultAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldDefaultAccess, newDefaultAccess); - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - public void setSpecifiedAccess(AccessType newSpecifiedAccess) { - AccessType oldSpecifiedAccess = this.specifiedAccess; - this.specifiedAccess = newSpecifiedAccess; - this.xmlEntityMappings.setAccess(AccessType.toXmlResourceModel(newSpecifiedAccess)); - firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, oldSpecifiedAccess, newSpecifiedAccess); - } - - public ListIterator<OrmPersistentType> ormPersistentTypes() { - return new CloneListIterator<OrmPersistentType>(this.persistentTypes); - } - - public int ormPersistentTypesSize() { - return this.persistentTypes.size(); - } - - public OrmPersistentType addOrmPersistentType(String mappingKey, String className) { - OrmPersistentType persistentType = getJpaFactory().buildOrmPersistentType(this, mappingKey); - int index = insertionIndex(persistentType); - this.persistentTypes.add(index, persistentType); - if (className.startsWith(getPackage() + ".")) { - // adds short name if package name is specified - className = className.substring(getPackage().length() + 1); - } - AbstractXmlTypeMapping typeMapping = persistentType.getMapping().addToResourceModel(this.xmlEntityMappings); - typeMapping.setClassName(className); - fireItemAdded(PERSISTENT_TYPES_LIST, index, persistentType); - return persistentType; - } - - protected void addOrmPersistentType(OrmPersistentType ormPersistentType) { - addItemToList(ormPersistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - protected int insertionIndex(OrmPersistentType ormPersistentType) { - return CollectionTools.insertionIndexOf(this.persistentTypes, ormPersistentType, buildMappingComparator()); - } - - private Comparator<OrmPersistentType> buildMappingComparator() { - return new Comparator<OrmPersistentType>() { - public int compare(OrmPersistentType o1, OrmPersistentType o2) { - int o1Sequence = o1.getMapping().getXmlSequence(); - int o2Sequence = o2.getMapping().getXmlSequence(); - if (o1Sequence < o2Sequence) { - return -1; - } - if (o1Sequence == o2Sequence) { - return 0; - } - return 1; - } - }; - } - - public void removeOrmPersistentType(int index) { - OrmPersistentType ormPersistentType = this.persistentTypes.get(index); - ormPersistentType.dispose(); - this.persistentTypes.remove(index); - ormPersistentType.getMapping().removeFromResourceModel(this.xmlEntityMappings); - fireItemRemoved(PERSISTENT_TYPES_LIST, index, ormPersistentType); - } - - public void removeOrmPersistentType(OrmPersistentType ormPersistentType) { - removeOrmPersistentType(this.persistentTypes.indexOf(ormPersistentType)); - } - - protected void removeOrmPersistentType_(OrmPersistentType ormPersistentType) { - ormPersistentType.dispose(); - removeItemFromList(ormPersistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - public void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping) { - ormPersistentType.dispose(); - int sourceIndex = this.persistentTypes.indexOf(ormPersistentType); - this.persistentTypes.remove(sourceIndex); - oldMapping.removeFromResourceModel(this.xmlEntityMappings); - int targetIndex = insertionIndex(ormPersistentType); - this.persistentTypes.add(targetIndex, ormPersistentType); - newMapping.addToResourceModel(this.xmlEntityMappings); - newMapping.initializeFrom(oldMapping); - //TODO are the source and target correct in this case, or is target off by one??? - fireItemMoved(PERSISTENT_TYPES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<OrmSequenceGenerator> sequenceGenerators() { - return new CloneListIterator<OrmSequenceGenerator>(this.sequenceGenerators); - } - - public int sequenceGeneratorsSize() { - return this.sequenceGenerators.size(); - } - - public OrmSequenceGenerator addSequenceGenerator(int index) { - OrmSequenceGenerator ormSequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - this.sequenceGenerators.add(index, ormSequenceGenerator); - XmlSequenceGenerator sequenceGenerator = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormSequenceGenerator.initialize(sequenceGenerator); - this.xmlEntityMappings.getSequenceGenerators().add(index, sequenceGenerator); - fireItemAdded(SEQUENCE_GENERATORS_LIST, index, ormSequenceGenerator); - return ormSequenceGenerator; - } - - protected void addSequenceGenerator(int index, OrmSequenceGenerator sequenceGenerator) { - addItemToList(index, sequenceGenerator, this.sequenceGenerators, EntityMappings.SEQUENCE_GENERATORS_LIST); - } - - public void removeSequenceGenerator(OrmSequenceGenerator sequenceGenerator) { - removeSequenceGenerator(this.sequenceGenerators.indexOf(sequenceGenerator)); - } - - public void removeSequenceGenerator(int index) { - OrmSequenceGenerator removedSequenceGenerator = this.sequenceGenerators.remove(index); - fireItemRemoved(SEQUENCE_GENERATORS_LIST, index, removedSequenceGenerator); - this.xmlEntityMappings.getSequenceGenerators().remove(index); - } - - protected void removeSequenceGenerator_(OrmSequenceGenerator sequenceGenerator) { - removeItemFromList(sequenceGenerator, this.sequenceGenerators, EntityMappings.SEQUENCE_GENERATORS_LIST); - } - - public void moveSequenceGenerator(int targetIndex, int sourceIndex) { - CollectionTools.move(this.sequenceGenerators, targetIndex, sourceIndex); - this.xmlEntityMappings.getSequenceGenerators().move(targetIndex, sourceIndex); - fireItemMoved(EntityMappings.SEQUENCE_GENERATORS_LIST, targetIndex, sourceIndex); - } - - public ListIterator<OrmTableGenerator> tableGenerators() { - return new CloneListIterator<OrmTableGenerator>(this.tableGenerators); - } - - public int tableGeneratorsSize() { - return this.tableGenerators.size(); - } - - public OrmTableGenerator addTableGenerator(int index) { - OrmTableGenerator xmlTableGenerator = getJpaFactory().buildOrmTableGenerator(this); - this.tableGenerators.add(index, xmlTableGenerator); - XmlTableGenerator tableGenerator = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - xmlTableGenerator.initialize(tableGenerator); - this.xmlEntityMappings.getTableGenerators().add(index, tableGenerator); - fireItemAdded(TABLE_GENERATORS_LIST, index, xmlTableGenerator); - return xmlTableGenerator; - } - - protected void addTableGenerator(int index, OrmTableGenerator tableGenerator) { - addItemToList(index, tableGenerator, this.tableGenerators, EntityMappings.TABLE_GENERATORS_LIST); - } - - public void removeTableGenerator(OrmTableGenerator tableGenerator) { - removeTableGenerator(this.tableGenerators.indexOf(tableGenerator)); - } - - public void removeTableGenerator(int index) { - OrmTableGenerator removedTableGenerator = this.tableGenerators.remove(index); - this.xmlEntityMappings.getTableGenerators().remove(index); - fireItemRemoved(TABLE_GENERATORS_LIST, index, removedTableGenerator); - } - - protected void removeTableGenerator_(OrmTableGenerator tableGenerator) { - removeItemFromList(tableGenerator, this.tableGenerators, EntityMappings.TABLE_GENERATORS_LIST); - } - - public void moveTableGenerator(int targetIndex, int sourceIndex) { - CollectionTools.move(this.tableGenerators, targetIndex, sourceIndex); - this.xmlEntityMappings.getTableGenerators().move(targetIndex, sourceIndex); - fireItemMoved(EntityMappings.TABLE_GENERATORS_LIST, targetIndex, sourceIndex); - } - - public ListIterator<OrmNamedQuery> namedQueries() { - return new CloneListIterator<OrmNamedQuery>(this.namedQueries); - } - - public int namedQueriesSize() { - return this.namedQueries.size(); - } - - public OrmNamedQuery addNamedQuery(int index) { - OrmNamedQuery namedQuery = getJpaFactory().buildOrmNamedQuery(this); - this.namedQueries.add(index, namedQuery); - this.xmlEntityMappings.getNamedQueries().add(index, OrmFactory.eINSTANCE.createXmlNamedQuery()); - this.fireItemAdded(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - return namedQuery; - } - - protected void addNamedQuery(int index, OrmNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - this.removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - OrmNamedQuery namedQuery = this.namedQueries.remove(index); - this.xmlEntityMappings.getNamedQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - } - - protected void removeNamedQuery_(OrmNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - this.xmlEntityMappings.getNamedQueries().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public ListIterator<OrmNamedNativeQuery> namedNativeQueries() { - return new CloneListIterator<OrmNamedNativeQuery>(this.namedNativeQueries); - } - - public int namedNativeQueriesSize() { - return this.namedNativeQueries.size(); - } - - public OrmNamedNativeQuery addNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = getJpaFactory().buildOrmNamedNativeQuery(this); - this.namedNativeQueries.add(index, namedNativeQuery); - this.xmlEntityMappings.getNamedNativeQueries().add(index, OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - this.fireItemAdded(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - return namedNativeQuery; - } - - protected void addNamedNativeQuery(int index, OrmNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = this.namedNativeQueries.remove(index); - this.xmlEntityMappings.getNamedNativeQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - } - - protected void removeNamedNativeQuery_(OrmNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - this.xmlEntityMappings.getNamedNativeQueries().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - //TODO what about qualified name? package + class - //this needs to be handled both for className and persistentType.getName(). - //moving on for now since I am just trying to get the ui compiled! just a warning that this isn't good api - public boolean containsPersistentType(String className) { - for (OrmPersistentType persistentType : CollectionTools.iterable(ormPersistentTypes())) { - if (persistentType.getName().equals(className)) { - return true; - } - } - return false; - } - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - return getPersistenceUnitMetadata().getPersistenceUnitDefaults(); - } - - protected void initialize(XmlEntityMappings entityMappings) { - this.xmlEntityMappings = entityMappings; - this.version = entityMappings.getVersion(); - this.description = entityMappings.getDescription(); - this.package_ = entityMappings.getPackage(); - this.specifiedSchema = entityMappings.getSchema(); - this.specifiedCatalog = entityMappings.getCatalog(); - this.specifiedAccess = this.specifiedAccess(entityMappings); - this.defaultAccess = getPersistenceUnit().getDefaultAccess(); - this.defaultCatalog = getPersistenceUnit().getDefaultCatalog(); - this.defaultSchema = getPersistenceUnit().getDefaultSchema(); - this.initializePersistentTypes(entityMappings); - this.initializeTableGenerators(entityMappings); - this.initializeSequenceGenerators(entityMappings); - this.initializeNamedQueries(entityMappings); - this.initializeNamedNativeQueries(entityMappings); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected void initializePersistentTypes(XmlEntityMappings entityMappings) { - this.initializeMappedSuperclasses(entityMappings); - this.initializeEntities(entityMappings); - this.initializeEmbeddables(entityMappings); - } - - protected void initializeMappedSuperclasses(XmlEntityMappings entityMappings) { - for (XmlMappedSuperclass mappedSuperclass : entityMappings.getMappedSuperclasses()) { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - ormPersistentType.initialize(mappedSuperclass); - this.persistentTypes.add(ormPersistentType); - } - } - - protected void initializeEntities(XmlEntityMappings entityMappings) { - for (XmlEntity entity : entityMappings.getEntities()) { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.ENTITY_TYPE_MAPPING_KEY); - ormPersistentType.initialize(entity); - this.persistentTypes.add(ormPersistentType); - } - } - - protected void initializeEmbeddables(XmlEntityMappings entityMappings) { - for (XmlEmbeddable embeddable : entityMappings.getEmbeddables()) { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - ormPersistentType.initialize(embeddable); - this.persistentTypes.add(ormPersistentType); - } - } - - protected void initializeTableGenerators(XmlEntityMappings entityMappings) { - for (XmlTableGenerator tableGenerator : entityMappings.getTableGenerators()) { - this.tableGenerators.add(buildTableGenerator(tableGenerator)); - } - } - - protected void initializeSequenceGenerators(XmlEntityMappings entityMappings) { - for (XmlSequenceGenerator sequenceGenerator : entityMappings.getSequenceGenerators()) { - this.sequenceGenerators.add(buildSequenceGenerator(sequenceGenerator)); - } - } - - protected void initializeNamedQueries(XmlEntityMappings entityMappings) { - for (XmlNamedQuery namedQuery : entityMappings.getNamedQueries()) { - this.namedQueries.add(buildNamedQuery(namedQuery)); - } - } - - protected void initializeNamedNativeQueries(XmlEntityMappings entityMappings) { - for (XmlNamedNativeQuery namedNativeQuery : entityMappings.getNamedNativeQueries()) { - this.namedNativeQueries.add(buildNamedNativeQuery(namedNativeQuery)); - } - } - - public void update(XmlEntityMappings entityMappings) { - this.xmlEntityMappings = entityMappings; - getJpaFile(entityMappings.getResource().getResourceModel()).addRootStructureNode(this.getMappingFileName(), this); - this.setDescription(entityMappings.getDescription()); - this.setPackage(entityMappings.getPackage()); - this.setSpecifiedSchema(entityMappings.getSchema()); - this.setSpecifiedCatalog(entityMappings.getCatalog()); - this.setSpecifiedAccess(this.specifiedAccess(entityMappings)); - this.persistenceUnitMetadata.update(entityMappings); - this.setDefaultAccess(getPersistenceUnit().getDefaultAccess()); - this.setDefaultCatalog(getPersistenceUnit().getDefaultCatalog()); - this.setDefaultSchema(getPersistenceUnit().getDefaultSchema()); - this.updatePersistentTypes(entityMappings); - this.updateTableGenerators(entityMappings); - this.updateSequenceGenerators(entityMappings); - this.updateNamedQueries(entityMappings); - this.updateNamedNativeQueries(entityMappings); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected String getMappingFileName() { - return getParent().getParent().getFileName(); - } - - protected AccessType specifiedAccess(XmlEntityMappings entityMappings) { - return AccessType.fromXmlResourceModel(entityMappings.getAccess()); - } - - protected void updatePersistentTypes(XmlEntityMappings entityMappings) { - ListIterator<OrmPersistentType> ormPersistentTypes = this.ormPersistentTypes(); - this.updateMappedSuperclasses(entityMappings, ormPersistentTypes); - this.updateEntities(entityMappings, ormPersistentTypes); - this.updateEmbeddables(entityMappings, ormPersistentTypes); - - while (ormPersistentTypes.hasNext()) { - this.removeOrmPersistentType_(ormPersistentTypes.next()); - } - } - - protected void updateMappedSuperclasses(XmlEntityMappings entityMappings, ListIterator<OrmPersistentType> ormPersistentTypes) { - ListIterator<XmlMappedSuperclass> mappedSuperclasses = new CloneListIterator<XmlMappedSuperclass>(entityMappings.getMappedSuperclasses());//prevent ConcurrentModificiationException - for (XmlMappedSuperclass mappedSuperclass : CollectionTools.iterable(mappedSuperclasses)) { - if (ormPersistentTypes.hasNext()) { - ormPersistentTypes.next().update(mappedSuperclass); - } - else { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - ormPersistentType.initialize(mappedSuperclass); - addOrmPersistentType(ormPersistentType); - } - } - } - - protected void updateEntities(XmlEntityMappings entityMappings, ListIterator<OrmPersistentType> ormPersistentTypes) { - ListIterator<XmlEntity> entities = new CloneListIterator<XmlEntity>(entityMappings.getEntities());//prevent ConcurrentModificiationException - for (XmlEntity entity : CollectionTools.iterable(entities)) { - if (ormPersistentTypes.hasNext()) { - ormPersistentTypes.next().update(entity); - } - else { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.ENTITY_TYPE_MAPPING_KEY); - ormPersistentType.initialize(entity); - addOrmPersistentType(ormPersistentType); - } - } - } - - protected void updateEmbeddables(XmlEntityMappings entityMappings, ListIterator<OrmPersistentType> ormPersistentTypes) { - ListIterator<XmlEmbeddable> embeddables = new CloneListIterator<XmlEmbeddable>(entityMappings.getEmbeddables());//prevent ConcurrentModificiationException - for (XmlEmbeddable embeddable : CollectionTools.iterable(embeddables)) { - if (ormPersistentTypes.hasNext()) { - ormPersistentTypes.next().update(embeddable); - } - else { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - ormPersistentType.initialize(embeddable); - addOrmPersistentType(ormPersistentType); - } - } - } - - protected void updateTableGenerators(XmlEntityMappings entityMappings) { - ListIterator<OrmTableGenerator> tableGenerators = tableGenerators(); - ListIterator<XmlTableGenerator> resourceTableGenerators = new CloneListIterator<XmlTableGenerator>(entityMappings.getTableGenerators());//prevent ConcurrentModificiationException - while (tableGenerators.hasNext()) { - OrmTableGenerator tableGenerator = tableGenerators.next(); - if (resourceTableGenerators.hasNext()) { - tableGenerator.update(resourceTableGenerators.next()); - } - else { - removeTableGenerator_(tableGenerator); - } - } - - while (resourceTableGenerators.hasNext()) { - addTableGenerator(tableGeneratorsSize(), buildTableGenerator(resourceTableGenerators.next())); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator tableGeneratorResource) { - OrmTableGenerator tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - tableGenerator.initialize(tableGeneratorResource); - return tableGenerator; - } - - protected void updateSequenceGenerators(XmlEntityMappings entityMappings) { - ListIterator<OrmSequenceGenerator> sequenceGenerators = sequenceGenerators(); - ListIterator<XmlSequenceGenerator> resourceSequenceGenerators = new CloneListIterator<XmlSequenceGenerator>(entityMappings.getSequenceGenerators());//prevent ConcurrentModificiationException - while (sequenceGenerators.hasNext()) { - OrmSequenceGenerator sequenceGenerator = sequenceGenerators.next(); - if (resourceSequenceGenerators.hasNext()) { - sequenceGenerator.update(resourceSequenceGenerators.next()); - } - else { - removeSequenceGenerator_(sequenceGenerator); - } - } - - while (resourceSequenceGenerators.hasNext()) { - addSequenceGenerator(sequenceGeneratorsSize(), buildSequenceGenerator(resourceSequenceGenerators.next())); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator sequenceGeneratorResource) { - OrmSequenceGenerator sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - sequenceGenerator.initialize(sequenceGeneratorResource); - return sequenceGenerator; - } - - protected void updateNamedQueries(XmlEntityMappings entityMappings) { - ListIterator<OrmNamedQuery> namedQueries = namedQueries(); - ListIterator<XmlNamedQuery> resourceNamedQueries = new CloneListIterator<XmlNamedQuery>(entityMappings.getNamedQueries());//prevent ConcurrentModificiationException - - while (namedQueries.hasNext()) { - OrmNamedQuery namedQuery = namedQueries.next(); - if (resourceNamedQueries.hasNext()) { - namedQuery.update(resourceNamedQueries.next()); - } - else { - removeNamedQuery_(namedQuery); - } - } - - while (resourceNamedQueries.hasNext()) { - addNamedQuery(namedQueriesSize(), buildNamedQuery(resourceNamedQueries.next())); - } - } - - protected OrmNamedQuery buildNamedQuery(XmlNamedQuery namedQuery) { - OrmNamedQuery ormNamedQuery = getJpaFactory().buildOrmNamedQuery(this); - ormNamedQuery.initialize(namedQuery); - return ormNamedQuery; - } - - protected void updateNamedNativeQueries(XmlEntityMappings entityMappings) { - ListIterator<OrmNamedNativeQuery> namedNativeQueries = namedNativeQueries(); - ListIterator<XmlNamedNativeQuery> resourceNamedNativeQueries = new CloneListIterator<XmlNamedNativeQuery>(entityMappings.getNamedNativeQueries());//prevent ConcurrentModificiationException - - while (namedNativeQueries.hasNext()) { - OrmNamedNativeQuery namedQuery = namedNativeQueries.next(); - if (resourceNamedNativeQueries.hasNext()) { - namedQuery.update(resourceNamedNativeQueries.next()); - } - else { - removeNamedNativeQuery_(namedQuery); - } - } - - while (resourceNamedNativeQueries.hasNext()) { - addNamedNativeQuery(namedNativeQueriesSize(), buildNamedNativeQuery(resourceNamedNativeQueries.next())); - } - } - - protected OrmNamedNativeQuery buildNamedNativeQuery(XmlNamedNativeQuery namedQuery) { - OrmNamedNativeQuery ormNamedNativeQuery =getJpaFactory().buildOrmNamedNativeQuery(this); - ormNamedNativeQuery.initialize(namedQuery); - return ormNamedNativeQuery; - } - - protected void updatePersistenceUnitGeneratorsAndQueries() { - for (Generator generator : CollectionTools.iterable(tableGenerators())) { - getPersistenceUnit().addGenerator(generator); - } - - for (Generator generator : CollectionTools.iterable(sequenceGenerators())) { - getPersistenceUnit().addGenerator(generator); - } - - for (Query query : CollectionTools.iterable(namedQueries())) { - getPersistenceUnit().addQuery(query); - } - - for (Query query : CollectionTools.iterable(namedNativeQueries())) { - getPersistenceUnit().addQuery(query); - } - } - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int textOffset) { - for (OrmPersistentType persistentType: CollectionTools.iterable(ormPersistentTypes())) { - if (persistentType.contains(textOffset)) { - return persistentType.getStructureNode(textOffset); - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - if (this.xmlEntityMappings == null) { - return false; - } - return this.xmlEntityMappings.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.xmlEntityMappings.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return null; - } - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - try { - addGeneratorMessages(messages); - addQueryMessages(messages); - } catch (Throwable exception) { - JptCorePlugin.log(exception); - } - for (OrmPersistentType ormPersistentType : CollectionTools.iterable(this.ormPersistentTypes())) { - try { - ormPersistentType.addToMessages(messages); - } catch (Throwable exception) { - JptCorePlugin.log(exception); - } - } - } - - @SuppressWarnings("unchecked") - protected void addGeneratorMessages(List<IMessage> messages) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<OrmGenerator> stream = new CompositeIterator<OrmGenerator>(this.tableGenerators(), this.sequenceGenerators()); stream.hasNext() ; ) { - OrmGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - masterList.add(current); - } - } - - @SuppressWarnings("unchecked") - protected void addQueryMessages(List<IMessage> messages) { - List<Query> masterList = CollectionTools.list(getPersistenceUnit().allQueries()); - - for (Iterator<OrmQuery> stream = new CompositeIterator<OrmQuery>(this.namedQueries(), this.namedNativeQueries()); stream.hasNext() ; ) { - OrmQuery current = stream.next(); - masterList.remove(current); - - for (Query each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - masterList.add(current); - } - } - - public void dispose() { - if (this.xmlEntityMappings.getResource() != null) { - //the resource is null if the orm.xml file was deleted - //rootStructureNodes are cleared in the dispose of JpaFile - JpaFile jpaFile = getJpaFile(this.xmlEntityMappings.getResource().getResourceModel()); - - if (jpaFile != null) { - //yes, this can also be null, seems that sometimes the resource is null and - //something it is not yet null, but we will have no jpaFile for it after a delete. - jpaFile.removeRootStructureNode(getMappingFileName()); - } - } - //still need to dispose these even in the case of a file being deleted. - //JpaFile.dispose() just removes the root structure nodes for this file, not other files (java files) - for (OrmPersistentType ormPersistentType : CollectionTools.iterable(ormPersistentTypes())) { - ormPersistentType.dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAssociationOverride.java deleted file mode 100644 index 92f2999299..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAssociationOverride.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class GenericOrmAssociationOverride extends AbstractOrmJpaContextNode - implements OrmAssociationOverride -{ - - protected String name; - - protected final List<OrmJoinColumn> specifiedJoinColumns; - - protected final List<OrmJoinColumn> defaultJoinColumns; - - private final AssociationOverride.Owner owner; - - protected XmlAssociationOverride associationOverride; - - - public GenericOrmAssociationOverride(OrmJpaContextNode parent, AssociationOverride.Owner owner, XmlAssociationOverride associationOverride) { - super(parent); - this.owner = owner; - this.specifiedJoinColumns = new ArrayList<OrmJoinColumn>(); - this.defaultJoinColumns = new ArrayList<OrmJoinColumn>(); - this.initialize(associationOverride); - } - - public OrmAssociationOverride setVirtual(boolean virtual) { - return (OrmAssociationOverride) getOwner().setVirtual(virtual, this); - } - - public Owner getOwner() { - return this.owner; - } - - // ********** IAssociationOverride implementation ********** - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.associationOverride.setName(newName); - firePropertyChanged(BaseOverride.NAME_PROPERTY, oldName, newName); - } - - - public ListIterator<OrmJoinColumn> joinColumns() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumns() : this.specifiedJoinColumns(); - } - - public int joinColumnsSize() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumnsSize() : this.specifiedJoinColumnsSize(); - } - - public ListIterator<OrmJoinColumn> defaultJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.defaultJoinColumns); - } - - public int defaultJoinColumnsSize() { - return this.defaultJoinColumns.size(); - } - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - OrmJoinColumn joinColumn = getJpaFactory().buildOrmJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - this.associationOverride.getJoinColumns().add(index, OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - this.fireItemAdded(AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected OrmJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - this.associationOverride.getJoinColumns().remove(index); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedJoinColumn); - } - - protected void removeSpecifiedJoinColumn(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - this.associationOverride.getJoinColumns().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - protected void initialize(XmlAssociationOverride associationOverride) { - this.associationOverride = associationOverride; - this.name = associationOverride.getName(); - initializeSpecifiedJoinColumns(associationOverride); - } - - protected void initializeSpecifiedJoinColumns(XmlAssociationOverride associationOverride) { - for (XmlJoinColumn joinColumn : associationOverride.getJoinColumns()) { - this.specifiedJoinColumns.add(createJoinColumn(joinColumn)); - } - } - - public void update(XmlAssociationOverride associationOverride) { - this.associationOverride = associationOverride; - this.setName(associationOverride.getName()); - updateSpecifiedJoinColumns(associationOverride); - } - - protected void updateSpecifiedJoinColumns(XmlAssociationOverride associationOverride) { - ListIterator<OrmJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<XmlJoinColumn> resourceJoinColumns = new CloneListIterator<XmlJoinColumn>(associationOverride.getJoinColumns());//prevent ConcurrentModificiationException - - while (joinColumns.hasNext()) { - OrmJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), createJoinColumn(resourceJoinColumns.next())); - } - } - - protected OrmJoinColumn createJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - - class JoinColumnOwner implements OrmJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return GenericOrmAssociationOverride.this.owner.getTypeMapping().getTableName(); - } - - public String getDefaultColumnName() { - return null; - } - - public Entity getTargetEntity() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericOrmAssociationOverride.this.getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericOrmAssociationOverride.this.owner.getRelationshipMapping(GenericOrmAssociationOverride.this.getName()); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TypeMapping getTypeMapping() { - return GenericOrmAssociationOverride.this.owner.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmAssociationOverride.this.defaultJoinColumns.contains(joinColumn); - } - - public int joinColumnsSize() { - return GenericOrmAssociationOverride.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAttributeOverride.java deleted file mode 100644 index 5344708385..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAttributeOverride.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmAttributeOverride extends AbstractOrmJpaContextNode - implements OrmAttributeOverride, OrmColumn.Owner -{ - - protected String name; - - private final Owner owner; - - protected XmlAttributeOverride attributeOverride; - - - protected final OrmColumn column; - - public GenericOrmAttributeOverride(OrmJpaContextNode parent, AttributeOverride.Owner owner, XmlAttributeOverride xmlAttributeOverride) { - super(parent); - this.owner = owner; - this.column = getJpaFactory().buildOrmColumn(this, this); - this.initialize(xmlAttributeOverride); - } - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public OrmAttributeOverride setVirtual(boolean virtual) { - return (OrmAttributeOverride) getOwner().setVirtual(virtual, this); - } - - public Owner getOwner() { - return this.owner; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.attributeOverride.setName(newName); - firePropertyChanged(BaseOverride.NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(BaseOverride.NAME_PROPERTY, oldName, newName); - } - - public OrmColumn getColumn() { - return this.column; - } - - public TypeMapping getTypeMapping() { - return getOwner().getTypeMapping(); - } - - public Table getDbTable(String tablename) { - return this.getTypeMapping().getDbTable(getColumn().getTable()); - } - - public String getDefaultColumnName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - return columnMapping.getColumn().getName(); - } - - public String getDefaultTableName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - String tableName = columnMapping.getColumn().getSpecifiedTable(); - if (tableName != null) { - return tableName; - } - return getOwner().getTypeMapping().getTableName(); - } - - protected ColumnMapping getColumnMapping() { - return getOwner().getColumnMapping(getName()); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public TextRange getValidationTextRange() { - TextRange textRange = this.attributeOverride.getValidationTextRange(); - return textRange == null ? getParent().getValidationTextRange() : textRange; - } - - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.attributeOverride.getColumn(); - } - - public void addColumnResource() { - this.attributeOverride.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.attributeOverride.setColumn(null); - } - - - //***************** updating **************** - - protected void initialize(XmlAttributeOverride attributeOverride) { - this.attributeOverride = attributeOverride; - this.name = attributeOverride.getName(); - this.column.initialize(attributeOverride.getColumn()); - } - - public void update(XmlAttributeOverride attributeOverride) { - this.attributeOverride = attributeOverride; - this.setName_(attributeOverride.getName()); - this.column.update(attributeOverride.getColumn()); - } - - //****************** validation ******************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - addColumnMessages(messages); - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && !column.isResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java deleted file mode 100644 index c6634e32ea..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmBasicMapping extends AbstractOrmAttributeMapping<XmlBasic> - implements OrmBasicMapping -{ - protected final OrmColumn column; - - protected FetchType specifiedFetch; - - protected Boolean specifiedOptional; - - protected EnumType specifiedEnumerated; - - protected TemporalType temporal; - - protected boolean lob; - - public GenericOrmBasicMapping(OrmPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildOrmColumn(this, this); - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getDefaultFetch() { - return BasicMapping.DEFAULT_FETCH_TYPE; - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.getAttributeMapping().setFetch(FetchType.toOrmResourceModel(newSpecifiedFetch)); - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - public Boolean getOptional() { - return (this.getSpecifiedOptional() == null) ? this.getDefaultOptional() : this.getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - this.getAttributeMapping().setOptional(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - public boolean isLob() { - return this.lob; - } - - public void setLob(boolean newLob) { - boolean oldLob = this.lob; - this.lob = newLob; - this.getAttributeMapping().setLob(newLob); - firePropertyChanged(BasicMapping.LOB_PROPERTY, oldLob, newLob); - } - - protected void setLob_(boolean newLob) { - boolean oldLob = this.lob; - this.lob = newLob; - firePropertyChanged(BasicMapping.LOB_PROPERTY, oldLob, newLob); - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getAttributeMapping().setTemporal(TemporalType.toOrmResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public EnumType getEnumerated() { - return (this.getSpecifiedEnumerated() == null) ? this.getDefaultEnumerated() : this.getSpecifiedEnumerated(); - } - - public EnumType getDefaultEnumerated() { - return BasicMapping.DEFAULT_ENUMERATED; - } - - public EnumType getSpecifiedEnumerated() { - return this.specifiedEnumerated; - } - - public void setSpecifiedEnumerated(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - this.getAttributeMapping().setEnumerated(EnumType.toOrmResourceModel(newSpecifiedEnumerated)); - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - protected void setSpecifiedEnumerated_(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmBasicMapping(this); - } - - - @Override - public void initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromXmlColumnMapping(oldMapping); - setTemporal(oldMapping.getTemporal()); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public int getXmlSequence() { - return 2; - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - public OrmColumn getColumn() { - return this.column; - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - @Override - public void initialize(XmlBasic basic) { - super.initialize(basic); - this.specifiedFetch = this.specifiedFetch(basic); - this.specifiedOptional = this.specifiedOptional(basic); - this.specifiedEnumerated = this.specifiedEnumerated(basic); - this.temporal = this.specifiedTemporal(basic); - this.lob = specifiedLob(basic); - this.column.initialize(basic.getColumn()); - } - - @Override - public void update(XmlBasic basic) { - super.update(basic); - this.setSpecifiedFetch_(this.specifiedFetch(basic)); - this.setSpecifiedOptional_(this.specifiedOptional(basic)); - this.setSpecifiedEnumerated_(this.specifiedEnumerated(basic)); - this.setTemporal_(this.specifiedTemporal(basic)); - this.setLob_(this.specifiedLob(basic)); - this.column.update(basic.getColumn()); - } - - protected Boolean specifiedOptional(XmlBasic basic) { - return basic.getOptional(); - } - - protected FetchType specifiedFetch(XmlBasic basic) { - return FetchType.fromOrmResourceModel(basic.getFetch()); - } - - protected EnumType specifiedEnumerated(XmlBasic basic) { - return EnumType.fromOrmResourceModel(basic.getEnumerated()); - } - - protected TemporalType specifiedTemporal(XmlBasic basic) { - return TemporalType.fromOrmResourceModel(basic.getTemporal()); - } - - protected boolean specifiedLob(XmlBasic basic) { - return basic.isLob(); - } - - public XmlBasic addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlBasic basic = OrmFactory.eINSTANCE.createXmlBasicImpl(); - getPersistentAttribute().initialize(basic); - typeMapping.getAttributes().getBasics().add(basic); - return basic; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getBasics().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.getAttributeMapping().getColumn(); - } - - public void addColumnResource() { - this.getAttributeMapping().setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.getAttributeMapping().setColumn(null); - } - - // ****************** validation **************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - if (entityOwned()) { - addColumnMessages(messages); - } - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmColumn.java deleted file mode 100644 index bc664fff2c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmColumn.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlColumn; - -public class GenericOrmColumn extends AbstractOrmBaseColumn<XmlColumn> implements OrmColumn -{ - protected Integer specifiedLength; - - protected Integer specifiedPrecision; - - protected Integer specifiedScale; - - public GenericOrmColumn(OrmJpaContextNode parent, OrmColumn.Owner owner) { - super(parent, owner); - } - - @Override - public OrmColumn.Owner getOwner() { - return (OrmColumn.Owner) super.getOwner(); - } - - public void initializeFrom(Column oldColumn) { - super.initializeFrom(oldColumn); - setSpecifiedLength(oldColumn.getSpecifiedLength()); - setSpecifiedPrecision(oldColumn.getSpecifiedPrecision()); - setSpecifiedScale(oldColumn.getSpecifiedScale()); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return Column.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - if (oldSpecifiedLength != newSpecifiedLength) { - if (this.getColumnResource() != null) { - this.getColumnResource().setLength(newSpecifiedLength); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedLength != null) { - addColumnResource(); - getColumnResource().setLength(newSpecifiedLength); - } - } - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - public Integer getPrecision() { - return (this.getSpecifiedPrecision() == null) ? getDefaultPrecision() : this.getSpecifiedPrecision(); - } - - public Integer getDefaultPrecision() { - return Column.DEFAULT_PRECISION; - } - - public Integer getSpecifiedPrecision() { - return this.specifiedPrecision; - } - - public void setSpecifiedPrecision(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - if (oldSpecifiedPrecision != newSpecifiedPrecision) { - if (this.getColumnResource() != null) { - this.getColumnResource().setPrecision(newSpecifiedPrecision); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedPrecision != null) { - addColumnResource(); - getColumnResource().setPrecision(newSpecifiedPrecision); - } - } - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - protected void setSpecifiedPrecision_(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - public Integer getScale() { - return (this.getSpecifiedScale() == null) ? getDefaultScale() : this.getSpecifiedScale(); - } - - public Integer getDefaultScale() { - return Column.DEFAULT_SCALE; - } - - public Integer getSpecifiedScale() { - return this.specifiedScale; - } - - public void setSpecifiedScale(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - if (oldSpecifiedScale != newSpecifiedScale) { - if (this.getColumnResource() != null) { - this.getColumnResource().setScale(newSpecifiedScale); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedScale != null) { - addColumnResource(); - getColumnResource().setScale(newSpecifiedScale); - } - } - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - protected void setSpecifiedScale_(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - @Override - protected XmlColumn getColumnResource() { - return getOwner().getColumnResource(); - } - - @Override - protected void addColumnResource() { - getOwner().addColumnResource(); - } - - @Override - protected void removeColumnResource() { - getOwner().removeColumnResource(); - } - - @Override - public void initialize(XmlColumn column) { - super.initialize(column); - this.specifiedLength = this.specifiedLength(column); - this.specifiedPrecision = this.specifiedPrecision(column); - this.specifiedScale = this.specifiedScale(column); - } - - @Override - public void update(XmlColumn column) { - super.update(column); - this.setSpecifiedLength_(this.specifiedLength(column)); - this.setSpecifiedPrecision_(this.specifiedPrecision(column)); - this.setSpecifiedScale_(this.specifiedScale(column)); - } - - protected Integer specifiedLength(XmlColumn column) { - return column == null ? null : column.getLength(); - } - - protected Integer specifiedPrecision(XmlColumn column) { - return column == null ? null : column.getPrecision(); - } - - protected Integer specifiedScale(XmlColumn column) { - return column == null ? null : column.getScale(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmDiscriminatorColumn.java deleted file mode 100644 index 0cf8666e95..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmDiscriminatorColumn.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlDiscriminatorColumn; -import org.eclipse.jpt.core.resource.orm.XmlEntity; - -public class GenericOrmDiscriminatorColumn extends AbstractOrmNamedColumn<XmlDiscriminatorColumn> - implements OrmDiscriminatorColumn -{ - - protected DiscriminatorType specifiedDiscriminatorType; - - protected DiscriminatorType defaultDiscriminatorType; - - protected Integer specifiedLength; - - protected XmlEntity entity; - - public GenericOrmDiscriminatorColumn(OrmJpaContextNode parent, OrmNamedColumn.Owner owner) { - super(parent, owner); - } - - public DiscriminatorType getDiscriminatorType() { - return (this.getSpecifiedDiscriminatorType() == null) ? this.getDefaultDiscriminatorType() : this.getSpecifiedDiscriminatorType(); - } - - public DiscriminatorType getDefaultDiscriminatorType() { - return DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE; - } - - public DiscriminatorType getSpecifiedDiscriminatorType() { - return this.specifiedDiscriminatorType; - } - - public void setSpecifiedDiscriminatorType(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - if (oldDiscriminatorType != newSpecifiedDiscriminatorType) { - if (this.getColumnResource() != null) { - this.getColumnResource().setDiscriminatorType(DiscriminatorType.toOrmResourceModel(newSpecifiedDiscriminatorType)); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedDiscriminatorType != null) { - addColumnResource(); - this.getColumnResource().setDiscriminatorType(DiscriminatorType.toOrmResourceModel(newSpecifiedDiscriminatorType)); - } - } - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - protected void setSpecifiedDiscriminatorType_(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? this.getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return DiscriminatorColumn.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - if (oldSpecifiedLength != newSpecifiedLength) { - if (this.getColumnResource() != null) { - this.getColumnResource().setLength(newSpecifiedLength); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedLength != null) { - addColumnResource(); - getColumnResource().setLength(newSpecifiedLength); - } - } - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - @Override - protected String tableName() { - return this.getOwner().getTypeMapping().getTableName(); - } - - - - @Override - protected XmlDiscriminatorColumn getColumnResource() { - return this.entity.getDiscriminatorColumn(); - } - - @Override - protected void addColumnResource() { - this.entity.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - } - - @Override - protected void removeColumnResource() { - this.entity.setDiscriminatorColumn(null); - } - - public void initialize(XmlEntity entity) { - this.entity = entity; - this.initialize(this.getColumnResource()); - } - - public void update(XmlEntity entity) { - this.entity = entity; - this.update(this.getColumnResource()); - } - - - @Override - protected void initialize(XmlDiscriminatorColumn column) { - super.initialize(column); - this.specifiedLength = this.specifiedLength(column); - this.specifiedDiscriminatorType = this.specifiedDiscriminatorType(column); - //TODO defaultLength, discriminator type java column - } - - @Override - protected void update(XmlDiscriminatorColumn column) { - super.update(column); - this.setSpecifiedLength_(this.specifiedLength(column)); - this.setSpecifiedDiscriminatorType_(this.specifiedDiscriminatorType(column)); - //TODO defaultLength, scale, precision from java column - } - - protected Integer specifiedLength(XmlDiscriminatorColumn column) { - return column == null ? null : column.getLength(); - } - - protected DiscriminatorType specifiedDiscriminatorType(XmlDiscriminatorColumn column) { - return column == null ? null : DiscriminatorType.fromOrmResourceModel(column.getDiscriminatorType()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddable.java deleted file mode 100644 index 437e498d60..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddable.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public class GenericOrmEmbeddable extends AbstractOrmTypeMapping<XmlEmbeddable> implements OrmEmbeddable -{ - public GenericOrmEmbeddable(OrmPersistentType parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - public int getXmlSequence() { - return 2; - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return attributeMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY || attributeMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - protected Boolean metadataComplete(XmlEmbeddable embeddable) { - return embeddable.getMetadataComplete(); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEmbeddables().remove(this.getTypeMappingResource()); - } - - public XmlEmbeddable addToResourceModel(XmlEntityMappings entityMappings) { - XmlEmbeddable embeddable = OrmFactory.eINSTANCE.createXmlEmbeddable(); - getPersistentType().initialize(embeddable); - entityMappings.getEmbeddables().add(embeddable); - return embeddable; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedIdMapping.java deleted file mode 100644 index d39b238566..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedIdMapping.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; - - -public class GenericOrmEmbeddedIdMapping extends AbstractOrmBaseEmbeddedMapping<XmlEmbeddedId> implements OrmEmbeddedIdMapping -{ - - public GenericOrmEmbeddedIdMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmEmbeddedIdMapping(this); - } - - public int getXmlSequence() { - return 1; - } - - //*************** AttributeMapping implementation ********************* - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public boolean isIdMapping() { - return true; - } - - public XmlEmbeddedId addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlEmbeddedId embeddedId = OrmFactory.eINSTANCE.createXmlEmbeddedIdImpl(); - getPersistentAttribute().initialize(embeddedId); - typeMapping.getAttributes().getEmbeddedIds().add(embeddedId); - return embeddedId; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getEmbeddedIds().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - @Override - public void initialize(XmlEmbeddedId embedded) { - super.initialize(embedded); - } - - @Override - public void update(XmlEmbeddedId embedded) { - super.update(embedded); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedMapping.java deleted file mode 100644 index 62d01d0053..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedMapping.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; - - -public class GenericOrmEmbeddedMapping extends AbstractOrmBaseEmbeddedMapping<XmlEmbedded> implements OrmEmbeddedMapping -{ - - public GenericOrmEmbeddedMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmEmbeddedMapping(this); - } - - public int getXmlSequence() { - return 8; - } - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public XmlEmbedded addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlEmbedded embedded = OrmFactory.eINSTANCE.createXmlEmbeddedImpl(); - getPersistentAttribute().initialize(embedded); - typeMapping.getAttributes().getEmbeddeds().add(embedded); - return embedded; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getEmbeddeds().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - @Override - public void initialize(XmlEmbedded embedded) { - super.initialize(embedded); - } - - @Override - public void update(XmlEmbedded embedded) { - super.update(embedded); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEntity.java deleted file mode 100644 index cfa37c050c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEntity.java +++ /dev/null @@ -1,2005 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHolder; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.Inheritance; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlIdClass; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericOrmEntity extends AbstractOrmTypeMapping<XmlEntity> implements OrmEntity -{ - protected String specifiedName; - - protected String defaultName; - - protected String idClass; - - protected final OrmTable table; - - protected final List<OrmSecondaryTable> specifiedSecondaryTables; - - protected final List<OrmSecondaryTable> virtualSecondaryTables; - - protected final List<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected final List<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns; - - protected InheritanceType specifiedInheritanceStrategy; - - protected InheritanceType defaultInheritanceStrategy; - - protected String defaultDiscriminatorValue; - - protected String specifiedDiscriminatorValue; - - protected boolean discriminatorValueAllowed; - - protected final OrmDiscriminatorColumn discriminatorColumn; - - protected OrmSequenceGenerator sequenceGenerator; - - protected OrmTableGenerator tableGenerator; - - protected final List<OrmAttributeOverride> specifiedAttributeOverrides; - - protected final List<OrmAttributeOverride> virtualAttributeOverrides; - - protected final List<OrmAssociationOverride> specifiedAssociationOverrides; - - protected final List<OrmAssociationOverride> virtualAssociationOverrides; - - protected final List<OrmNamedQuery> namedQueries; - - protected final List<OrmNamedNativeQuery> namedNativeQueries; - - public GenericOrmEntity(OrmPersistentType parent) { - super(parent); - this.table = getJpaFactory().buildOrmTable(this); - this.specifiedSecondaryTables = new ArrayList<OrmSecondaryTable>(); - this.virtualSecondaryTables = new ArrayList<OrmSecondaryTable>(); - this.discriminatorColumn = buildDiscriminatorColumn(); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - this.defaultPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - this.specifiedAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.specifiedAssociationOverrides = new ArrayList<OrmAssociationOverride>(); - this.virtualAssociationOverrides = new ArrayList<OrmAssociationOverride>(); - this.namedQueries = new ArrayList<OrmNamedQuery>(); - this.namedNativeQueries = new ArrayList<OrmNamedNativeQuery>(); - } - - protected OrmDiscriminatorColumn buildDiscriminatorColumn() { - return getJpaFactory().buildOrmDiscriminatorColumn(this, buildDiscriminatorColumnOwner()); - } - - protected OrmNamedColumn.Owner buildDiscriminatorColumnOwner() { - return new OrmNamedColumn.Owner(){ - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericOrmEntity.this.getDbTable(tableName); - } - - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - - public String getDefaultColumnName() { - //TODO default column name from java here or in XmlDiscriminatorColumn? - return DiscriminatorColumn.DEFAULT_NAME; - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - - }; - } - - // ******************* ITypeMapping implementation ******************** - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - @Override - public String getTableName() { - return getTable().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return getTable().getDbTable(); - } - - 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().getDatabaseObjectNamed( - CollectionTools.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 getTable().getDbSchema(); - } - - public JavaEntity getJavaEntity() { - if (this.javaPersistentType != null && this.javaPersistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (JavaEntity) this.javaPersistentType.getMapping(); - } - return null; - } - - public String getName() { - return (this.getSpecifiedName() == null) ? getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - this.getTypeMappingResource().setName(newSpecifiedName); - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public OrmTable getTable() { - return this.table; - } - - public ListIterator<OrmSecondaryTable> secondaryTables() { - if (specifiedSecondaryTablesSize() > 0) { - return specifiedSecondaryTables(); - } - return virtualSecondaryTables(); - } - - public int secondaryTablesSize() { - if (specifiedSecondaryTablesSize() > 0) { - return specifiedSecondaryTablesSize(); - } - return virtualSecondaryTablesSize(); - } - - public ListIterator<OrmSecondaryTable> virtualSecondaryTables() { - return new CloneListIterator<OrmSecondaryTable>(this.virtualSecondaryTables); - } - - public int virtualSecondaryTablesSize() { - return this.virtualSecondaryTables.size(); - } - - protected void addVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - addItemToList(secondaryTable, this.virtualSecondaryTables, OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST); - } - - protected void removeVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.virtualSecondaryTables, OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST); - } - - public ListIterator<OrmSecondaryTable> specifiedSecondaryTables() { - return new CloneListIterator<OrmSecondaryTable>(this.specifiedSecondaryTables); - } - - public int specifiedSecondaryTablesSize() { - return this.specifiedSecondaryTables.size(); - } - - public OrmSecondaryTable addSpecifiedSecondaryTable(int index) { - if (!secondaryTablesDefinedInXml()) { - throw new IllegalStateException("Virtual secondary tables exist, must first call setSecondaryTablesDefinedInXml(true)"); //$NON-NLS-1$ - } - XmlSecondaryTable secondaryTableResource = OrmFactory.eINSTANCE.createXmlSecondaryTableImpl(); - OrmSecondaryTable secondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(index, secondaryTable); - getTypeMappingResource().getSecondaryTables().add(index, secondaryTableResource); - fireItemAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); - return secondaryTable; - } - - protected void addSpecifiedSecondaryTable(int index, OrmSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void removeSpecifiedSecondaryTable(SecondaryTable secondaryTable) { - this.removeSpecifiedSecondaryTable(this.specifiedSecondaryTables.indexOf(secondaryTable)); - } - - public void removeSpecifiedSecondaryTable(int index) { - OrmSecondaryTable removedSecondaryTable = this.specifiedSecondaryTables.remove(index); - getTypeMappingResource().getSecondaryTables().remove(index); - fireItemRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, removedSecondaryTable); - } - - protected void removeSpecifiedSecondaryTable_(OrmSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void moveSpecifiedSecondaryTable(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedSecondaryTables, targetIndex, sourceIndex); - this.getTypeMappingResource().getSecondaryTables().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, targetIndex, sourceIndex); - } - - public boolean containsSecondaryTable(String name) { - return containsSecondaryTable(name, secondaryTables()); - } - - public boolean containsSpecifiedSecondaryTable(String name) { - return containsSecondaryTable(name, specifiedSecondaryTables()); - } - - public boolean containsVirtualSecondaryTable(String name) { - return containsSecondaryTable(name, virtualSecondaryTables()); - } - - public boolean containsVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - return this.virtualSecondaryTables.contains(secondaryTable); - } - - protected boolean containsSecondaryTable(String name, ListIterator<OrmSecondaryTable> secondaryTables) { - for (OrmSecondaryTable secondaryTable : CollectionTools.iterable(secondaryTables)) { - String secondaryTableName = secondaryTable.getName(); - if (secondaryTableName != null && secondaryTableName.equals(name)) { - return true; - } - } - return false; - } - - public boolean secondaryTablesDefinedInXml() { - return virtualSecondaryTablesSize() == 0; - } - - public void setSecondaryTablesDefinedInXml(boolean defineInXml) { - if (defineInXml == secondaryTablesDefinedInXml()) { - return; - } - if (defineInXml) { - specifySecondaryTablesInXml(); - } - else { - removeSecondaryTablesFromXml(); - } - } - - /** - * This is used to take all the java secondary tables and specify them in the xml. You must - * use setSecondaryTablesDefinedInXml(boolean) before calling addSpecifiedSecondaryTable(). - * - * Yes this code looks odd, but be careful making changes to it - */ - protected void specifySecondaryTablesInXml() { - if (virtualSecondaryTablesSize() != 0) { - List<OrmSecondaryTable> 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.createXmlSecondaryTableImpl(); - OrmSecondaryTable specifiedSecondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(specifiedSecondaryTable); - getTypeMappingResource().getSecondaryTables().add(secondaryTableResource); - specifiedSecondaryTable.initializeFrom(virtualSecondaryTable); - } - //fire change notification at the end - fireItemsRemoved(OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST, 0, 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(); - } - getTypeMappingResource().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.getTable(), this.secondaryTables()); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return new CompositeIterator<Table>(new TransformationIterator<TypeMapping, Iterator<Table>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<Table> transform(TypeMapping mapping) { - return new FilteringIterator<Table, Table>(mapping.associatedTables()) { - @Override - protected boolean accept(Table o) { - return true; - //TODO - //filtering these out so as to avoid the duplicate table, root and children share the same table - //return !(o instanceof SingleTableInheritanceChildTableImpl); - } - }; - } - }); - } - - public boolean tableNameIsInvalid(String tableName) { - return !CollectionTools.contains(this.associatedTableNamesIncludingInherited(), tableName); - } - - public InheritanceType getInheritanceStrategy() { - return (this.getSpecifiedInheritanceStrategy() == null) ? this.getDefaultInheritanceStrategy() : this.getSpecifiedInheritanceStrategy(); - } - - public InheritanceType getDefaultInheritanceStrategy() { - return this.defaultInheritanceStrategy; - } - - protected void setDefaultInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.defaultInheritanceStrategy; - this.defaultInheritanceStrategy = newInheritanceType; - firePropertyChanged(DEFAULT_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - public InheritanceType getSpecifiedInheritanceStrategy() { - return this.specifiedInheritanceStrategy; - } - - public void setSpecifiedInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - if (oldInheritanceType != newInheritanceType) { - if (this.inheritanceResource() != null) { - this.inheritanceResource().setStrategy(InheritanceType.toOrmResourceModel(newInheritanceType)); - if (this.inheritanceResource().isAllFeaturesUnset()) { - removeInheritanceResource(); - } - } - else if (newInheritanceType != null) { - addInheritanceResource(); - inheritanceResource().setStrategy(InheritanceType.toOrmResourceModel(newInheritanceType)); - } - } - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - protected void setSpecifiedInheritanceStrategy_(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - protected Inheritance inheritanceResource() { - return getTypeMappingResource().getInheritance(); - } - - protected void addInheritanceResource() { - getTypeMappingResource().setInheritance(OrmFactory.eINSTANCE.createInheritance()); - } - - protected void removeInheritanceResource() { - getTypeMappingResource().setInheritance(null); - } - - public OrmDiscriminatorColumn getDiscriminatorColumn() { - return this.discriminatorColumn; - } - - public OrmSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); //$NON-NLS-1$ - } - this.sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - getTypeMappingResource().setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, null, this.sequenceGenerator); - return this.sequenceGenerator; - } - - public void removeSequenceGenerator() { - if (getSequenceGenerator() == null) { - throw new IllegalStateException("sequenceGenerator does not exist, cannot be removed"); //$NON-NLS-1$ - } - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - this.getTypeMappingResource().setSequenceGenerator(null); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, null); - } - - public OrmSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(OrmSequenceGenerator newSequenceGenerator) { - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - public OrmTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); //$NON-NLS-1$ - } - this.tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - getTypeMappingResource().setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, null, this.tableGenerator); - return this.tableGenerator; - } - - public void removeTableGenerator() { - if (getTableGenerator() == null) { - throw new IllegalStateException("tableGenerator does not exist, cannot be removed"); //$NON-NLS-1$ - } - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - this.getTypeMappingResource().setTableGenerator(null); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public OrmTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(OrmTableGenerator newTableGenerator) { - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<OrmGenerator> generators() { - return new CompositeIterator<OrmGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - public String getDefaultDiscriminatorValue() { - return this.defaultDiscriminatorValue; - } - - protected void setDefaultDiscriminatorValue(String newDefaultDiscriminatorValue) { - String oldDefaultDiscriminatorValue = this.defaultDiscriminatorValue; - this.defaultDiscriminatorValue = newDefaultDiscriminatorValue; - firePropertyChanged(DEFAULT_DISCRIMINATOR_VALUE_PROPERTY, oldDefaultDiscriminatorValue, newDefaultDiscriminatorValue); - } - - public String getSpecifiedDiscriminatorValue() { - return this.specifiedDiscriminatorValue; - } - - public void setSpecifiedDiscriminatorValue(String newSpecifiedDiscriminatorValue) { - String oldSpecifiedDiscriminatorValue = this.specifiedDiscriminatorValue; - this.specifiedDiscriminatorValue = newSpecifiedDiscriminatorValue; - getTypeMappingResource().setDiscriminatorValue(newSpecifiedDiscriminatorValue); - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - public String getDiscriminatorValue() { - return (this.getSpecifiedDiscriminatorValue() == null) ? getDefaultDiscriminatorValue() : this.getSpecifiedDiscriminatorValue(); - } - - public boolean isDiscriminatorValueAllowed() { - return this.discriminatorValueAllowed; - } - - protected void setDiscriminatorValueAllowed(boolean newDiscriminatorValueAllowed) { - boolean oldDiscriminatorValueAllowed = this.discriminatorValueAllowed; - this.discriminatorValueAllowed = newDiscriminatorValueAllowed; - firePropertyChanged(Entity.DISCRIMINATOR_VALUE_ALLOWED_PROPERTY, oldDiscriminatorValueAllowed, newDiscriminatorValueAllowed); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumns); - } - - public int defaultPrimaryKeyJoinColumnsSize() { - return this.defaultPrimaryKeyJoinColumns.size(); - } - - public OrmPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - throw new UnsupportedOperationException("use defaultPrimaryKeyJoinColumns() instead"); //$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 xmlPrimaryKeyJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl(); - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = buildPrimaryKeyJoinColumn(xmlPrimaryKeyJoinColumn); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - this.getTypeMappingResource().getPrimaryKeyJoinColumns().add(index, xmlPrimaryKeyJoinColumn); - - this.fireItemAdded(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - this.fireListCleared(OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - return primaryKeyJoinColumn; - } - - protected OrmBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(primaryKeyJoinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPrimaryKeyJoinColumn = this.specifiedPrimaryKeyJoinColumns.remove(index); - if (!containsSpecifiedPrimaryKeyJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - initializeDefaultPrimaryKeyJoinColumns(); - } - this.getTypeMappingResource().getPrimaryKeyJoinColumns().remove(index); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (!this.defaultPrimaryKeyJoinColumns.isEmpty()) { - fireListChanged(OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.getTypeMappingResource().getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmAttributeOverride> attributeOverrides() { - return new CompositeListIterator<OrmAttributeOverride>(specifiedAttributeOverrides(), virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<OrmAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.virtualAttributeOverrides); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - protected void addVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected OrmAttributeOverride setAttributeOverrideVirtual(boolean virtual, OrmAttributeOverride attributeOverride) { - if (virtual) { - return setAttributeOverrideVirtual(attributeOverride); - } - return setAttributeOverrideSpecified(attributeOverride); - } - - protected OrmAttributeOverride setAttributeOverrideVirtual(OrmAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - OrmAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEntity() != null) { - javaAttributeOverride = getJavaEntity().getAttributeOverrideNamed(attributeOverrideName); - } - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - } - } - } - - getTypeMappingResource().getAttributeOverrides().remove(index); - fireItemRemoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected OrmAttributeOverride setAttributeOverrideSpecified(OrmAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl(); - OrmAttributeOverride newAttributeOverride = getJpaFactory().buildOrmAttributeOverride(this, createAttributeOverrideOwner(), xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - getTypeMappingResource().getAttributeOverrides().add(xmlAttributeOverride); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - public ListIterator<OrmAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected void addSpecifiedAttributeOverride(int index, OrmAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.getTypeMappingResource().getAttributeOverrides().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmAssociationOverride> associationOverrides() { - return new CompositeListIterator<OrmAssociationOverride>(specifiedAssociationOverrides(), virtualAssociationOverrides()); - } - - public int associationOverridesSize() { - return this.specifiedAssociationOverridesSize() + this.virtualAssociationOverridesSize(); - } - - public ListIterator<OrmAssociationOverride> virtualAssociationOverrides() { - return new CloneListIterator<OrmAssociationOverride>(this.virtualAssociationOverrides); - } - - public int virtualAssociationOverridesSize() { - return this.virtualAssociationOverrides.size(); - } - - public ListIterator<OrmAssociationOverride> specifiedAssociationOverrides() { - return new CloneListIterator<OrmAssociationOverride>(this.specifiedAssociationOverrides); - } - - public int specifiedAssociationOverridesSize() { - return this.specifiedAssociationOverrides.size(); - } - - protected void addSpecifiedAssociationOverride(int index, OrmAssociationOverride associationOverride) { - addItemToList(index, associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeSpecifiedAssociationOverride_(OrmAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAssociationOverrides, targetIndex, sourceIndex); - this.getTypeMappingResource().getAssociationOverrides().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - public OrmAttributeOverride getAttributeOverrideNamed(String name) { - return (OrmAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - public boolean containsAttributeOverride(String name) { - return containsOverride(name, attributeOverrides()); - } - - public boolean containsDefaultAttributeOverride(String name) { - return containsOverride(name, virtualAttributeOverrides()); - } - - public boolean containsSpecifiedAttributeOverride(String name) { - return containsOverride(name, specifiedAttributeOverrides()); - } - - public OrmAssociationOverride getAssociationOverrideNamed(String name) { - return (OrmAssociationOverride) getOverrideNamed(name, associationOverrides()); - } - - public boolean containsAssociationOverride(String name) { - return containsOverride(name, associationOverrides()); - } - - public boolean containsSpecifiedAssociationOverride(String name) { - return containsOverride(name, specifiedAssociationOverrides()); - } - - public boolean containsDefaultAssociationOverride(String name) { - return containsOverride(name, virtualAssociationOverrides()); - } - - private BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(overrides)) { - String overrideName = override.getName(); - if (overrideName == null && name == null) { - return override; - } - if (overrideName != null && overrideName.equals(name)) { - return override; - } - } - return null; - } - - private boolean containsOverride(String name, ListIterator<? extends BaseOverride> overrides) { - return getOverrideNamed(name, overrides) != null; - } - - - public ListIterator<OrmNamedQuery> namedQueries() { - return new CloneListIterator<OrmNamedQuery>(this.namedQueries); - } - - public int namedQueriesSize() { - return this.namedQueries.size(); - } - - public OrmNamedQuery addNamedQuery(int index) { - OrmNamedQuery namedQuery = getJpaFactory().buildOrmNamedQuery(this); - this.namedQueries.add(index, namedQuery); - XmlNamedQuery xmlNamedQuery = OrmFactory.eINSTANCE.createXmlNamedQuery(); - namedQuery.initialize(xmlNamedQuery); - this.getTypeMappingResource().getNamedQueries().add(index, xmlNamedQuery); - this.fireItemAdded(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - return namedQuery; - } - - protected void addNamedQuery(int index, OrmNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - OrmNamedQuery namedQuery = this.namedQueries.remove(index); - this.getTypeMappingResource().getNamedQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - } - - protected void removeNamedQuery_(OrmNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - this.getTypeMappingResource().getNamedQueries().move(targetIndex, sourceIndex); - fireItemMoved(QueryHolder.NAMED_QUERIES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<OrmNamedNativeQuery> namedNativeQueries() { - return new CloneListIterator<OrmNamedNativeQuery>(this.namedNativeQueries); - } - - public int namedNativeQueriesSize() { - return this.namedNativeQueries.size(); - } - - public OrmNamedNativeQuery addNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = getJpaFactory().buildOrmNamedNativeQuery(this); - this.namedNativeQueries.add(index, namedNativeQuery); - XmlNamedNativeQuery xmlNamedNativeQuery = OrmFactory.eINSTANCE.createXmlNamedNativeQuery(); - namedNativeQuery.initialize(xmlNamedNativeQuery); - this.getTypeMappingResource().getNamedNativeQueries().add(index, OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - this.fireItemAdded(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - return namedNativeQuery; - } - - protected void addNamedNativeQuery(int index, OrmNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - this.removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = this.namedNativeQueries.remove(index); - this.getTypeMappingResource().getNamedNativeQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - } - - protected void removeNamedNativeQuery_(OrmNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - this.getTypeMappingResource().getNamedNativeQueries().move(targetIndex, sourceIndex); - fireItemMoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - protected Iterator<OrmQuery> queries() { - return new CompositeIterator<OrmQuery>(this.namedQueries(), this.namedNativeQueries()); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (oldIdClass != newIdClass) { - if (this.idClassResource() != null) { - this.idClassResource().setClassName(newIdClass); - if (this.idClassResource().isAllFeaturesUnset()) { - removeIdClassResource(); - } - } - else if (newIdClass != null) { - addIdClassResource(); - idClassResource().setClassName(newIdClass); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected XmlIdClass idClassResource() { - return getTypeMappingResource().getIdClass(); - } - - protected void addIdClassResource() { - getTypeMappingResource().setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - } - - protected void removeIdClassResource() { - getTypeMappingResource().setIdClass(null); - } - - public Entity getParentEntity() { - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - TypeMapping tm = i.next().getMapping(); - if (tm != this && tm instanceof Entity) { - return (Entity) tm; - } - } - return this; - } - - public Entity getRootEntity() { - Entity rootEntity = null; - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - PersistentType persistentType = i.next(); - if (persistentType.getMapping() instanceof Entity) { - rootEntity = (Entity) persistentType.getMapping(); - } - } - return rootEntity; - } - -// public String primaryKeyColumnName() { -// String pkColumnName = null; -// for (Iterator<IPersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { -// IPersistentAttribute attribute = stream.next(); -// String name = attribute.primaryKeyColumnName(); -// if (pkColumnName == null) { -// pkColumnName = name; -// } -// else if (name != null) { -// // if we encounter a composite primary key, return null -// return null; -// } -// } -// // if we encounter only a single primary key column name, return it -// return pkColumnName; -// } -// -// public String primaryKeyAttributeName() { -// String pkColumnName = null; -// String pkAttributeName = null; -// for (Iterator<IPersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { -// IPersistentAttribute attribute = stream.next(); -// String name = attribute.primaryKeyColumnName(); -// if (pkColumnName == null) { -// pkColumnName = name; -// pkAttributeName = attribute.getName(); -// } -// else if (name != null) { -// // if we encounter a composite primary key, return null -// return null; -// } -// } -// // if we encounter only a single primary key column name, return it -// return pkAttributeName; -// } -// - - - public int getXmlSequence() { - return 1; - } - - /** - * Return an iterator of Entities, each which inherits from the one before, - * and terminates at the root entity (or at the point of cyclicity). - */ - protected Iterator<TypeMapping> inheritanceHierarchy() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().inheritanceHierarchy()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - @Override - public Iterator<PersistentAttribute> allOverridableAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<TypeMapping, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(TypeMapping mapping) { - return mapping.overridableAttributes(); - } - }); - } - - @Override - public Iterator<String> allOverridableAttributeNames() { - return new CompositeIterator<String>(new TransformationIterator<TypeMapping, Iterator<String>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<String> transform(TypeMapping mapping) { - return mapping.overridableAttributeNames(); - } - }); - } - - @Override - public Iterator<String> allOverridableAssociationNames() { - return new CompositeIterator<String>(new TransformationIterator<TypeMapping, Iterator<String>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<String> transform(TypeMapping mapping) { - return mapping.overridableAssociationNames(); - } - }); - } - -// -// public IAttributeOverride createAttributeOverride(int index) { -// return OrmFactory.eINSTANCE.createXmlAttributeOverride(new IEntity.AttributeOverrideOwner(this)); -// } -// -// public IAssociationOverride createAssociationOverride(int index) { -// return OrmFactory.eINSTANCE.createXmlAssociationOverride(new IEntity.AssociationOverrideOwner(this)); -// } -// -// public IAttributeOverride attributeOverrideNamed(String name) { -// return (IAttributeOverride) overrideNamed(name, getAttributeOverrides()); -// } -// -// public boolean containsAttributeOverride(String name) { -// return containsOverride(name, getAttributeOverrides()); -// } -// -// public boolean containsSpecifiedAttributeOverride(String name) { -// return containsOverride(name, getSpecifiedAttributeOverrides()); -// } -// -// public boolean containsAssociationOverride(String name) { -// return containsOverride(name, getAssociationOverrides()); -// } -// -// public boolean containsSpecifiedAssociationOverride(String name) { -// return containsOverride(name, getSpecifiedAssociationOverrides()); -// } -// -// private IOverride overrideNamed(String name, List<? extends IOverride> overrides) { -// for (IOverride override : overrides) { -// String overrideName = override.getName(); -// if (overrideName == null && name == null) { -// return override; -// } -// if (overrideName != null && overrideName.equals(name)) { -// return override; -// } -// } -// return null; -// } -// -// private boolean containsOverride(String name, List<? extends IOverride> overrides) { -// return overrideNamed(name, overrides) != null; -// } -// -// public boolean containsSpecifiedPrimaryKeyJoinColumns() { -// return !this.getSpecifiedPrimaryKeyJoinColumns().isEmpty(); -// } - - - @Override - public void initialize(XmlEntity entity) { - super.initialize(entity); - this.specifiedName = entity.getName(); - this.defaultName = this.defaultName(); - this.initializeInheritance(this.inheritanceResource()); - this.discriminatorColumn.initialize(entity); - this.specifiedDiscriminatorValue = entity.getDiscriminatorValue(); - this.defaultDiscriminatorValue = this.defaultDiscriminatorValue(); - this.discriminatorValueAllowed = this.discriminatorValueIsAllowed(); - this.table.initialize(entity); - this.initializeSpecifiedSecondaryTables(entity); - this.initializeVirtualSecondaryTables(); - this.initializeSequenceGenerator(entity); - this.initializeTableGenerator(entity); - this.initializeSpecifiedPrimaryKeyJoinColumns(entity); - this.initializeDefaultPrimaryKeyJoinColumns(); - this.initializeSpecifiedAttributeOverrides(entity); - this.initializeVirtualAttributeOverrides(); - this.initializeSpecifiedAssociationOverrides(entity); - this.initializeNamedQueries(entity); - this.initializeNamedNativeQueries(entity); - this.initializeIdClass(this.idClassResource()); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected void initializeInheritance(Inheritance inheritanceResource) { - this.specifiedInheritanceStrategy = this.specifiedInheritanceStrategy(inheritanceResource); - this.defaultInheritanceStrategy = this.defaultInheritanceStrategy(); - } - - protected void initializeSpecifiedSecondaryTables(XmlEntity entity) { - for (XmlSecondaryTable secondaryTable : entity.getSecondaryTables()) { - this.specifiedSecondaryTables.add(buildSecondaryTable(secondaryTable)); - } - } - - protected void initializeVirtualSecondaryTables() { - if (isMetadataComplete()) { - return; - } - if (getJavaEntity() == null) { - return; - } - if (specifiedSecondaryTablesSize() > 0) { - return; - } - ListIterator<JavaSecondaryTable> javaSecondaryTables = getJavaEntity().secondaryTables(); - while(javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - if (javaSecondaryTable.getName() != null) { - this.virtualSecondaryTables.add(buildVirtualSecondaryTable(javaSecondaryTable)); - } - } - } - - protected void initializeDefaultPrimaryKeyJoinColumns() { - if (isMetadataComplete()) { - return; - } - if (getJavaEntity() == null) { - this.defaultPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(null)); - return; - } - if (specifiedPrimaryKeyJoinColumnsSize() > 0) { - return; - } - ListIterator<JavaPrimaryKeyJoinColumn> javaPkJoinColumns = getJavaEntity().primaryKeyJoinColumns(); - while(javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - if (javaPkJoinColumn.getName() != null) { - this.defaultPrimaryKeyJoinColumns.add(buildVirtualPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - } - } - - protected void initializeTableGenerator(XmlEntity entity) { - if (entity.getTableGenerator() != null) { - this.tableGenerator = buildTableGenerator(entity.getTableGenerator()); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator tableGeneratorResource) { - OrmTableGenerator generator = getJpaFactory().buildOrmTableGenerator(this); - generator.initialize(tableGeneratorResource); - return generator; - } - - protected void initializeSequenceGenerator(XmlEntity entity) { - if (entity.getSequenceGenerator() != null) { - this.sequenceGenerator = buildSequenceGenerator(entity.getSequenceGenerator()); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator xmlSequenceGenerator) { - OrmSequenceGenerator generator = getJpaFactory().buildOrmSequenceGenerator(this); - generator.initialize(xmlSequenceGenerator); - return generator; - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns(XmlEntity entity) { - for (XmlPrimaryKeyJoinColumn primaryKeyJoinColumn : entity.getPrimaryKeyJoinColumns()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(primaryKeyJoinColumn)); - } - } - - protected void initializeSpecifiedAttributeOverrides(XmlEntity entity) { - for (XmlAttributeOverride attributeOverride : entity.getAttributeOverrides()) { - this.specifiedAttributeOverrides.add(buildAttributeOverride(attributeOverride)); - } - } - - protected void initializeVirtualAttributeOverrides() { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - OrmAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEntity() != null) { - javaAttributeOverride = getJavaEntity().getAttributeOverrideNamed(persistentAttribute.getName()); - } - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - } - - protected OrmAttributeOverride buildVirtualAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - return buildAttributeOverride(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - - protected XmlAttributeOverride buildVirtualXmlAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - XmlColumn xmlColumn; - if (javaAttributeOverride == null) { - ColumnMapping columnMapping = (ColumnMapping) persistentAttribute.getMapping(); - xmlColumn = new VirtualXmlColumn(this, columnMapping.getColumn(), false); - } - else { - xmlColumn = new VirtualXmlColumn(this, javaAttributeOverride.getColumn(), isMetadataComplete()); - } - return new VirtualXmlAttributeOverride(persistentAttribute.getName(), xmlColumn); - } - - protected void initializeSpecifiedAssociationOverrides(XmlEntity entity) { - for (XmlAssociationOverride associationOverride : entity.getAssociationOverrides()) { - this.specifiedAssociationOverrides.add(buildAssociationOverride(associationOverride)); - } - } - - protected void initializeNamedQueries(XmlEntity entity) { - for (XmlNamedQuery namedQuery : entity.getNamedQueries()) { - this.namedQueries.add(buildNamedQuery(namedQuery)); - } - } - - protected void initializeNamedNativeQueries(XmlEntity entity) { - for (XmlNamedNativeQuery namedNativeQuery : entity.getNamedNativeQueries()) { - this.namedNativeQueries.add(buildNamedNativeQuery(namedNativeQuery)); - } - } - - protected void initializeIdClass(XmlIdClass idClassResource) { - this.idClass = this.idClass(idClassResource); - } - - protected String idClass(XmlIdClass idClassResource) { - return idClassResource == null ? null : idClassResource.getClassName(); - } - - @Override - public void update(XmlEntity entity) { - super.update(entity); - this.setSpecifiedName(entity.getName()); - this.setDefaultName(this.defaultName()); - this.updateInheritance(this.inheritanceResource()); - this.discriminatorColumn.update(entity); - this.setSpecifiedDiscriminatorValue(entity.getDiscriminatorValue()); - this.setDefaultDiscriminatorValue(defaultDiscriminatorValue()); - this.setDiscriminatorValueAllowed(this.discriminatorValueIsAllowed()); - this.table.update(entity); - this.updateSpecifiedSecondaryTables(entity); - this.updateVirtualSecondaryTables(); - this.updateSequenceGenerator(entity); - this.updateTableGenerator(entity); - this.updateSpecifiedPrimaryKeyJoinColumns(entity); - this.updateDefaultPrimaryKeyJoinColumns(); - this.updateSpecifiedAttributeOverrides(entity); - this.updateVirtualAttributeOverrides(); - this.updateSpecifiedAssociationOverrides(entity); - this.updateNamedQueries(entity); - this.updateNamedNativeQueries(entity); - this.updateIdClass(this.idClassResource()); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected String defaultName() { - if (!isMetadataComplete()) { - JavaEntity javaEntity = getJavaEntity(); - if (javaEntity != null) { - return javaEntity.getName(); - } - } - String className = getClass_(); - if (className != null) { - return ClassTools.shortNameForClassNamed(className); - } - return null; - } - - protected String defaultDiscriminatorValue() { - //TODO default discriminator value - return null; - } - - protected boolean discriminatorValueIsAllowed() { - JavaResourcePersistentType javaResourcePersistentType = getJavaResourcePersistentType(); - return javaResourcePersistentType == null ? false : !javaResourcePersistentType.isAbstract(); - } - - protected void updateInheritance(Inheritance inheritanceResource) { - this.setSpecifiedInheritanceStrategy_(this.specifiedInheritanceStrategy(inheritanceResource)); - this.setDefaultInheritanceStrategy(this.defaultInheritanceStrategy()); - } - - protected void updateSpecifiedSecondaryTables(XmlEntity entity) { - ListIterator<OrmSecondaryTable> secondaryTables = specifiedSecondaryTables(); - ListIterator<XmlSecondaryTable> resourceSecondaryTables = new CloneListIterator<XmlSecondaryTable>(entity.getSecondaryTables());//prevent ConcurrentModificiationException - - while (secondaryTables.hasNext()) { - OrmSecondaryTable secondaryTable = secondaryTables.next(); - if (resourceSecondaryTables.hasNext()) { - secondaryTable.update(resourceSecondaryTables.next()); - } - else { - removeSpecifiedSecondaryTable_(secondaryTable); - } - } - - while (resourceSecondaryTables.hasNext()) { - addSpecifiedSecondaryTable(specifiedSecondaryTablesSize(), buildSecondaryTable(resourceSecondaryTables.next())); - } - } - - //if any secondary-tables are specified in the xml file, then all of the java secondaryTables are overriden - protected void updateVirtualSecondaryTables() { - ListIterator<OrmSecondaryTable> secondaryTables = virtualSecondaryTables(); - ListIterator<JavaSecondaryTable> javaSecondaryTables = EmptyListIterator.instance(); - - if (getJavaEntity() != null && !isMetadataComplete() && specifiedSecondaryTablesSize() == 0) { - javaSecondaryTables = getJavaEntity().secondaryTables(); - } - while (secondaryTables.hasNext()) { - OrmSecondaryTable virtualSecondaryTable = secondaryTables.next(); - if (javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - virtualSecondaryTable.update(new VirtualXmlSecondaryTable(javaSecondaryTable)); - } - else { - removeVirtualSecondaryTable(virtualSecondaryTable); - } - } - - while (javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - addVirtualSecondaryTable(buildVirtualSecondaryTable(javaSecondaryTable)); - } - } - - protected OrmSecondaryTable buildSecondaryTable(XmlSecondaryTable xmlSecondaryTable) { - return getJpaFactory().buildOrmSecondaryTable(this, xmlSecondaryTable); - } - - protected OrmSecondaryTable buildVirtualSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - return buildSecondaryTable(new VirtualXmlSecondaryTable(javaSecondaryTable)); - } - - protected void updateTableGenerator(XmlEntity entity) { - if (entity.getTableGenerator() == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(entity.getTableGenerator())); - } - else { - getTableGenerator().update(entity.getTableGenerator()); - } - } - } - - protected void updateSequenceGenerator(XmlEntity entity) { - if (entity.getSequenceGenerator() == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(entity.getSequenceGenerator())); - } - else { - getSequenceGenerator().update(entity.getSequenceGenerator()); - } - } - } - - protected InheritanceType specifiedInheritanceStrategy(Inheritance inheritanceResource) { - if (inheritanceResource == null) { - return null; - } - return InheritanceType.fromOrmResourceModel(inheritanceResource.getStrategy()); - } - - protected InheritanceType defaultInheritanceStrategy() { - if (inheritanceResource() == null && !isMetadataComplete()) { - if (getJavaEntity() != null) { - return getJavaEntity().getInheritanceStrategy(); - } - } - if (getRootEntity() == this) { - return InheritanceType.SINGLE_TABLE; - } - return getRootEntity().getInheritanceStrategy(); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns(XmlEntity entity) { - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<XmlPrimaryKeyJoinColumn> resourcePrimaryKeyJoinColumns = new CloneListIterator<XmlPrimaryKeyJoinColumn>(entity.getPrimaryKeyJoinColumns());//prevent ConcurrentModificiationException - - while (primaryKeyJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update(resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn(resourcePrimaryKeyJoinColumns.next())); - } - } - - //if there are any specified pkJoinColumns, then no default pkJoinColumns - //if the java has specified pkJoinColumns, then those are the default pkJoinColumns - //otherwise, just 1 pkJoinColumn, defaults being null if multiple primaryKey columns - protected void updateDefaultPrimaryKeyJoinColumns() { - ListIterator<OrmPrimaryKeyJoinColumn> defaultPkJoinColumns = defaultPrimaryKeyJoinColumns(); - ListIterator<JavaPrimaryKeyJoinColumn> javaPkJoinColumns = EmptyListIterator.instance(); - - if (getJavaEntity() != null && !isMetadataComplete() && specifiedPrimaryKeyJoinColumnsSize() == 0) { - javaPkJoinColumns = getJavaEntity().primaryKeyJoinColumns(); - } - while (defaultPkJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn defaultPkJoinColumn = defaultPkJoinColumns.next(); - if (javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - defaultPkJoinColumn.update(new VirtualXmlPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - else { - if (defaultPrimaryKeyJoinColumnsSize() == 1) { - defaultPkJoinColumn.update(null); - } - else { - removeDefaultPrimaryKeyJoinColumn(defaultPkJoinColumn); - } - } - } - - while (javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - addDefaultPrimaryKeyJoinColumn(buildVirtualPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - - if (defaultPrimaryKeyJoinColumnsSize() == 0 && specifiedPrimaryKeyJoinColumnsSize() == 0) { - addDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(null)); - } - } - - protected OrmPrimaryKeyJoinColumn buildVirtualPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn javaSecondaryTable) { - return buildPrimaryKeyJoinColumn(new VirtualXmlPrimaryKeyJoinColumn(javaSecondaryTable)); - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn primaryKeyJoinColumn) { - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - ormPrimaryKeyJoinColumn.initialize(primaryKeyJoinColumn); - return ormPrimaryKeyJoinColumn; - } - - protected void updateSpecifiedAttributeOverrides(XmlEntity entity) { - ListIterator<OrmAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<XmlAttributeOverride> resourceAttributeOverrides = new CloneListIterator<XmlAttributeOverride>(entity.getAttributeOverrides());//prevent ConcurrentModificiationException - - while (attributeOverrides.hasNext()) { - OrmAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update(resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride(resourceAttributeOverrides.next())); - } - } - - protected void updateVirtualAttributeOverrides() { - Iterator<PersistentAttribute> overridableAttributes = allOverridableAttributes(); - ListIterator<OrmAttributeOverride> virtualAttributeOverridesCopy = virtualAttributeOverrides(); - - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(overridableAttributes)) { - OrmAttributeOverride ormAttributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (ormAttributeOverride != null && !ormAttributeOverride.isVirtual()) { - continue; - } - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEntity() != null) { - javaAttributeOverride = getJavaEntity().getAttributeOverrideNamed(persistentAttribute.getName()); - } - if (ormAttributeOverride != null) { - if (virtualAttributeOverridesCopy.hasNext()) { - OrmAttributeOverride virtualAttributeOverride = virtualAttributeOverridesCopy.next(); - virtualAttributeOverride.update(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - for (OrmAttributeOverride virtualAttributeOverride : CollectionTools.iterable(virtualAttributeOverridesCopy)) { - removeVirtualAttributeOverride(virtualAttributeOverride); - } - } - - protected OrmAttributeOverride buildAttributeOverride(XmlAttributeOverride attributeOverride) { - return getJpaFactory().buildOrmAttributeOverride(this, createAttributeOverrideOwner(), attributeOverride); - } - - protected AttributeOverride.Owner createAttributeOverrideOwner() { - return new AttributeOverrideOwner(); - } - - protected void updateSpecifiedAssociationOverrides(XmlEntity entity) { - ListIterator<OrmAssociationOverride> associationOverrides = specifiedAssociationOverrides(); - ListIterator<XmlAssociationOverride> resourceAssociationOverrides = new CloneListIterator<XmlAssociationOverride>(entity.getAssociationOverrides());//prevent ConcurrentModificiationException - - while (associationOverrides.hasNext()) { - OrmAssociationOverride associationOverride = associationOverrides.next(); - if (resourceAssociationOverrides.hasNext()) { - associationOverride.update(resourceAssociationOverrides.next()); - } - else { - removeSpecifiedAssociationOverride_(associationOverride); - } - } - - while (resourceAssociationOverrides.hasNext()) { - addSpecifiedAssociationOverride(specifiedAssociationOverridesSize(), buildAssociationOverride(resourceAssociationOverrides.next())); - } - } - - protected OrmAssociationOverride buildAssociationOverride(XmlAssociationOverride associationOverride) { - return getJpaFactory().buildOrmAssociationOverride(this, createAssociationOverrideOwner(), associationOverride); - } - - protected AssociationOverride.Owner createAssociationOverrideOwner() { - return new AssociationOverrideOwner(); - } - - protected void updateNamedQueries(XmlEntity entity) { - ListIterator<OrmNamedQuery> queries = namedQueries(); - ListIterator<XmlNamedQuery> resourceNamedQueries = new CloneListIterator<XmlNamedQuery>(entity.getNamedQueries());//prevent ConcurrentModificiationException - - while (queries.hasNext()) { - OrmNamedQuery namedQuery = queries.next(); - if (resourceNamedQueries.hasNext()) { - namedQuery.update(resourceNamedQueries.next()); - } - else { - removeNamedQuery_(namedQuery); - } - } - - while (resourceNamedQueries.hasNext()) { - addNamedQuery(namedQueriesSize(), buildNamedQuery(resourceNamedQueries.next())); - } - } - - protected OrmNamedQuery buildNamedQuery(XmlNamedQuery namedQuery) { - OrmNamedQuery ormNamedQuery = getJpaFactory().buildOrmNamedQuery(this); - ormNamedQuery.initialize(namedQuery); - return ormNamedQuery; - } - - protected void updateNamedNativeQueries(XmlEntity entity) { - ListIterator<OrmNamedNativeQuery> queries = namedNativeQueries(); - ListIterator<XmlNamedNativeQuery> resourceNamedNativeQueries = new CloneListIterator<XmlNamedNativeQuery>(entity.getNamedNativeQueries());//prevent ConcurrentModificiationException - - while (queries.hasNext()) { - OrmNamedNativeQuery namedQuery = queries.next(); - if (resourceNamedNativeQueries.hasNext()) { - namedQuery.update(resourceNamedNativeQueries.next()); - } - else { - removeNamedNativeQuery_(namedQuery); - } - } - - while (resourceNamedNativeQueries.hasNext()) { - addNamedNativeQuery(namedNativeQueriesSize(), buildNamedNativeQuery(resourceNamedNativeQueries.next())); - } - } - - protected OrmNamedNativeQuery buildNamedNativeQuery(XmlNamedNativeQuery namedQuery) { - OrmNamedNativeQuery ormNamedNativeQuery = getJpaFactory().buildOrmNamedNativeQuery(this); - ormNamedNativeQuery.initialize(namedQuery); - return ormNamedNativeQuery; - } - - protected void updateIdClass(XmlIdClass idClassResource) { - this.setIdClass_(this.idClass(idClassResource)); - } - - protected void updatePersistenceUnitGeneratorsAndQueries() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - - for (Query query : CollectionTools.iterable(namedQueries())) { - getPersistenceUnit().addQuery(query); - } - - for (Query query : CollectionTools.iterable(namedNativeQueries())) { - getPersistenceUnit().addQuery(query); - } - } - - - // ************************************************************************* - - public String getPrimaryKeyColumnName() { - return getPrimaryKeyColumnName(getPersistentType().allAttributes()); - } - - //copied in GenericJavaEntity to avoid an API change for fixing bug 229423 in RC1 - public String getPrimaryKeyColumnName(Iterator<PersistentAttribute> attributes) { - String pkColumnName = null; - for (Iterator<PersistentAttribute> stream = attributes; stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - String name = attribute.getPrimaryKeyColumnName(); - if (name != null) { - //if the attribute is a primary key then we need to check if there is an attribute override - //and use its column name instead (bug 229423) - AttributeOverride attributeOverride = getAttributeOverrideNamed(attribute.getName()); - if (attributeOverride != null) { - name = attributeOverride.getColumn().getName(); - } - } - if (pkColumnName == null) { - pkColumnName = name; - } - else if (name != null) { - // if we encounter a composite primary key, return null - return null; - } - } - // if we encounter only a single primary key column name, return it - return pkColumnName; - } - - //********** Validation ************************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - getTable().addToMessages(messages); - addIdMessages(messages); - addGeneratorMessages(messages); - addQueryMessages(messages); - for (OrmSecondaryTable secondaryTable : CollectionTools.iterable(secondaryTables())) { - secondaryTable.addToMessages(messages); - } - - for (OrmAttributeOverride attributeOverride : CollectionTools.iterable(attributeOverrides())) { - attributeOverride.addToMessages(messages); - } - - for (OrmAssociationOverride associationOverride : CollectionTools.iterable(associationOverrides())) { - associationOverride.addToMessages(messages); - } - } - - protected void addIdMessages(List<IMessage> messages) { - addNoIdMessage(messages); - } - - protected void addNoIdMessage(List<IMessage> messages) { - if (entityHasNoId()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NO_ID, - new String[] {this.getName()}, - this, - this.getValidationTextRange()) - ); - } - } - - private boolean entityHasNoId() { - return ! this.entityHasId(); - } - - protected void addGeneratorMessages(List<IMessage> messages) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<OrmGenerator> stream = this.generators(); stream.hasNext() ; ) { - OrmGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - - masterList.add(current); - } - } - - protected void addQueryMessages(List<IMessage> messages) { - List<Query> masterList = CollectionTools.list(getPersistenceUnit().allQueries()); - - for (Iterator<OrmQuery> stream = this.queries(); stream.hasNext() ; ) { - OrmQuery current = stream.next(); - masterList.remove(current); - - for (Query each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - - masterList.add(current); - } - } - - private boolean entityHasId() { - for (Iterator<PersistentAttribute> stream = this.getPersistentType().allAttributes(); stream.hasNext(); ) { - if (stream.next().isIdAttribute()) { - return true; - } - } - return false; - } - - public TypeMapping typeMapping() { - return this; - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEntities().remove(this.getTypeMappingResource()); - } - - public XmlEntity addToResourceModel(XmlEntityMappings entityMappings) { - XmlEntity entity = OrmFactory.eINSTANCE.createXmlEntity(); - getPersistentType().initialize(entity); - entityMappings.getEntities().add(entity); - return entity; - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - class PrimaryKeyJoinColumnOwner implements OrmBaseJoinColumn.Owner - { - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericOrmEntity.this.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity parentEntity = GenericOrmEntity.this.getParentEntity(); - return (parentEntity == null) ? null : parentEntity.getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericOrmEntity.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmEntity.this.defaultPrimaryKeyJoinColumns.contains(joinColumn); - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return GenericOrmEntity.this.getParentEntity().getPrimaryKeyColumnName(); - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - } - - class AttributeOverrideOwner implements AttributeOverride.Owner { - - public ColumnMapping getColumnMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof ColumnMapping) { - return (ColumnMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericOrmEntity.this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - return GenericOrmEntity.this.setAttributeOverrideVirtual(virtual, (OrmAttributeOverride) override); - } - - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - - } - - class AssociationOverrideOwner implements AssociationOverride.Owner { - - public RelationshipMapping getRelationshipMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof RelationshipMapping) { - return (RelationshipMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericOrmEntity.this.virtualAssociationOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - // TODO Auto-generated method stub - return null; - } - - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java deleted file mode 100644 index 2fe5dac4af..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmGeneratedValue extends AbstractOrmJpaContextNode implements OrmGeneratedValue -{ - - protected GenerationType specifiedStrategy; - - protected String specifiedGenerator; - protected String defaultGenerator; - - protected XmlGeneratedValue generatedValue; - - public GenericOrmGeneratedValue(OrmJpaContextNode parent) { - super(parent); - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public GenerationType getStrategy() { - return (this.getSpecifiedStrategy() == null) ? this.getDefaultStrategy() : this.getSpecifiedStrategy(); - } - - public GenerationType getDefaultStrategy() { - return GeneratedValue.DEFAULT_STRATEGY; - } - - public GenerationType getSpecifiedStrategy() { - return this.specifiedStrategy; - } - - public void setSpecifiedStrategy(GenerationType newSpecifiedStrategy) { - GenerationType oldStrategy = this.specifiedStrategy; - this.specifiedStrategy = newSpecifiedStrategy; - this.generatedValue.setStrategy(GenerationType.toOrmResourceModel(newSpecifiedStrategy)); - firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newSpecifiedStrategy); - } - - protected void setSpecifiedStrategy_(GenerationType newSpecifiedStrategy) { - GenerationType oldStrategy = this.specifiedStrategy; - this.specifiedStrategy = newSpecifiedStrategy; - firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newSpecifiedStrategy); - } - - public String getGenerator() { - return (this.getSpecifiedGenerator() == null) ? this.getDefaultGenerator() : this.getSpecifiedGenerator(); - } - - public String getDefaultGenerator() { - return this.defaultGenerator; - } - - protected void setDefaultGenerator(String newDefaultGenerator) { - String oldGenerator = this.defaultGenerator; - this.defaultGenerator = newDefaultGenerator; - firePropertyChanged(DEFAULT_GENERATOR_PROPERTY, oldGenerator, newDefaultGenerator); - } - - public String getSpecifiedGenerator() { - return this.specifiedGenerator; - } - - public void setSpecifiedGenerator(String newSpecifiedGenerator) { - String oldGenerator = this.specifiedGenerator; - this.specifiedGenerator = newSpecifiedGenerator; - this.generatedValue.setGenerator(newSpecifiedGenerator); - firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newSpecifiedGenerator); - } - - protected void setSpecifiedGenerator_(String newSpecifiedGenerator) { - String oldGenerator = this.specifiedGenerator; - this.specifiedGenerator = newSpecifiedGenerator; - firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newSpecifiedGenerator); - } - - public TextRange getGeneratorTextRange() { - TextRange textRange = this.generatedValue.getGeneratorTextRange(); - return textRange != null ? textRange : getValidationTextRange(); - } - - - // ********** resource model -> java context model ********** - - public void initialize(XmlGeneratedValue generatedValue) { - this.generatedValue = generatedValue; - this.specifiedStrategy = this.strategy(generatedValue); - this.specifiedGenerator = this.generator(generatedValue); - //TODO - this.defaultGenerator = null; - } - - public void update(XmlGeneratedValue generatedValue) { - this.generatedValue = generatedValue; - this.setSpecifiedStrategy_(this.strategy(generatedValue)); - this.setSpecifiedGenerator_(this.generator(generatedValue)); - //TODO - this.setDefaultGenerator(null); - } - - protected GenerationType strategy(XmlGeneratedValue generatedValue) { - return GenerationType.fromOrmResourceModel(generatedValue.getStrategy()); - } - - protected String generator(XmlGeneratedValue generatedValue) { - return generatedValue.getGenerator(); - } - - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.generatedValue.getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java deleted file mode 100644 index 04b3f75f3b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java +++ /dev/null @@ -1,494 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmIdMapping extends AbstractOrmAttributeMapping<XmlId> - implements OrmIdMapping -{ - protected final OrmColumn column; - - protected OrmGeneratedValue generatedValue; - - protected TemporalType temporal; - - protected OrmTableGenerator tableGenerator; - protected OrmSequenceGenerator sequenceGenerator; - - - public GenericOrmIdMapping(OrmPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildOrmColumn(this, this); - } - - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public int getXmlSequence() { - return 0; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmIdMapping(this); - } - - @Override - public void initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromXmlColumnMapping(oldMapping); - setTemporal(oldMapping.getTemporal()); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - - public OrmColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getAttributeMapping().setTemporal(TemporalType.toOrmResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public OrmGeneratedValue addGeneratedValue() { - if (getGeneratedValue() != null) { - throw new IllegalStateException("gemeratedValue already exists"); - } - this.generatedValue = getJpaFactory().buildOrmGeneratedValue(this); - this.getAttributeMapping().setGeneratedValue(OrmFactory.eINSTANCE.createXmlGeneratedValueImpl()); - firePropertyChanged(GENERATED_VALUE_PROPERTY, null, this.generatedValue); - return this.generatedValue; - } - - public void removeGeneratedValue() { - if (getGeneratedValue() == null) { - throw new IllegalStateException("gemeratedValue does not exist, cannot be removed"); - } - OrmGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = null; - this.getAttributeMapping().setGeneratedValue(null); - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, null); - } - - public OrmGeneratedValue getGeneratedValue() { - return this.generatedValue; - } - - protected void setGeneratedValue(OrmGeneratedValue newGeneratedValue) { - OrmGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = newGeneratedValue; - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, newGeneratedValue); - } - - public OrmSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); - } - this.sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - this.getAttributeMapping().setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, null, this.sequenceGenerator); - return this.sequenceGenerator; - } - - public void removeSequenceGenerator() { - if (getSequenceGenerator() == null) { - throw new IllegalStateException("sequenceGenerator does not exist, cannot be removed"); - } - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - this.getAttributeMapping().setSequenceGenerator(null); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, null); - } - - public OrmSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(OrmSequenceGenerator newSequenceGenerator) { - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - public OrmTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); - } - this.tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - this.getAttributeMapping().setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, null, this.tableGenerator); - return this.tableGenerator; - } - - public void removeTableGenerator() { - if (getTableGenerator() == null) { - throw new IllegalStateException("tableGenerator does not exist, cannot be removed"); - } - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - this.getAttributeMapping().setTableGenerator(null); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public OrmTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(OrmTableGenerator newTableGenerator) { - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<OrmGenerator> generators() { - return new CompositeIterator<OrmGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - @Override - public String getPrimaryKeyColumnName() { - return this.getColumn().getName(); - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public boolean isIdMapping() { - return true; - } - - public XmlId addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlId id = OrmFactory.eINSTANCE.createXmlIdImpl(); - getPersistentAttribute().initialize(id); - typeMapping.getAttributes().getIds().add(id); - return id; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getIds().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - @Override - public void initialize(XmlId id) { - super.initialize(id); - this.temporal = this.specifiedTemporal(id); - this.column.initialize(id.getColumn()); - this.initializeSequenceGenerator(id); - this.initializeTableGenerator(id); - this.initializeGeneratedValue(id); - this.updatePersistenceUnitGenerators(); - } - - protected TemporalType specifiedTemporal(XmlId id) { - return TemporalType.fromOrmResourceModel(id.getTemporal()); - } - - protected void initializeSequenceGenerator(XmlId id) { - if (id.getSequenceGenerator() != null) { - this.sequenceGenerator = buildSequenceGenerator(id.getSequenceGenerator()); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator xmlSequenceGenerator) { - OrmSequenceGenerator sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - sequenceGenerator.initialize(xmlSequenceGenerator); - return sequenceGenerator; - } - - protected void initializeTableGenerator(XmlId id) { - if (id.getTableGenerator() != null) { - this.tableGenerator = buildTableGenerator(id.getTableGenerator()); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator tableGeneratorResource) { - OrmTableGenerator tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - tableGenerator.initialize(tableGeneratorResource); - return tableGenerator; - } - - protected void initializeGeneratedValue(XmlId id) { - if (id.getGeneratedValue() != null) { - this.generatedValue = buildGeneratedValue(id.getGeneratedValue()); - } - } - - protected OrmGeneratedValue buildGeneratedValue(XmlGeneratedValue xmlGeneratedValue) { - OrmGeneratedValue ormGeneratedValue = getJpaFactory().buildOrmGeneratedValue(this); - ormGeneratedValue.initialize(xmlGeneratedValue); - return ormGeneratedValue; - } - @Override - public void update(XmlId id) { - super.update(id); - this.setTemporal_(this.specifiedTemporal(id)); - this.column.update(id.getColumn()); - this.updateSequenceGenerator(id); - this.updateTableGenerator(id); - this.updateGeneratedValue(id); - this.updatePersistenceUnitGenerators(); - } - - protected void updateSequenceGenerator(XmlId id) { - if (id.getSequenceGenerator() == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(id.getSequenceGenerator())); - } - else { - getSequenceGenerator().update(id.getSequenceGenerator()); - } - } - } - - protected void updateTableGenerator(XmlId id) { - if (id.getTableGenerator() == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(id.getTableGenerator())); - } - else { - getTableGenerator().update(id.getTableGenerator()); - } - } - } - - protected void updateGeneratedValue(XmlId id) { - if (id.getGeneratedValue() == null) { - if (getGeneratedValue() != null) { - setGeneratedValue(null); - } - } - else { - if (getGeneratedValue() == null) { - setGeneratedValue(buildGeneratedValue(id.getGeneratedValue())); - getGeneratedValue().initialize(id.getGeneratedValue()); - } - else { - getGeneratedValue().update(id.getGeneratedValue()); - } - } - } - - protected void updatePersistenceUnitGenerators() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - } - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.getAttributeMapping().getColumn(); - } - - public void addColumnResource() { - this.getAttributeMapping().setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.getAttributeMapping().setColumn(null); - } - - // ****************** validation **************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (entityOwned()) { - addColumnMessages(messages); - } - addGeneratedValueMessages(messages); - addGeneratorMessages(messages); - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = this.connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {getPersistentAttribute().getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getPersistentAttribute().getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } - - protected void addGeneratedValueMessages(List<IMessage> messages) { - OrmGeneratedValue generatedValue = getGeneratedValue(); - if (generatedValue == null) { - return; - } - String generatorName = generatedValue.getGenerator(); - if (generatorName == null) { - return; - } - - for (Generator nextMasterGenerator : CollectionTools.iterable(getPersistenceUnit().allGenerators())) { - if (generatorName.equals(nextMasterGenerator.getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generatorName}, - this, - generatedValue.getGeneratorTextRange()) - ); - } - - protected void addGeneratorMessages(List<IMessage> messages) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<OrmGenerator> stream = this.generators(); stream.hasNext() ; ) { - OrmGenerator current = stream.next(); - if (current.isVirtual()) { - return; - } - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - - masterList.add(current); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumn.java deleted file mode 100644 index 03f210e9f5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumn.java +++ /dev/null @@ -1,240 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericOrmJoinColumn extends AbstractOrmBaseColumn<XmlJoinColumn> implements OrmJoinColumn -{ - - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected XmlJoinColumn joinColumn; - - public GenericOrmJoinColumn(OrmJpaContextNode parent, OrmJoinColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFrom(JoinColumn oldColumn) { - super.initializeFrom(oldColumn); - setSpecifiedReferencedColumnName(oldColumn.getSpecifiedReferencedColumnName()); - } - - public String getReferencedColumnName() { - return (this.getSpecifiedReferencedColumnName() == null) ? getDefaultReferencedColumnName() : this.getSpecifiedReferencedColumnName(); - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - getColumnResource().setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - @Override - public OrmJoinColumn.Owner getOwner() { - return (OrmJoinColumn.Owner) this.owner; - } - - public Table dbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - public Column getDbReferencedColumn() { - Table table = dbReferencedColumnTable(); - return (table == null) ? null : table.getColumnNamed(getReferencedColumnName()); - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getReferencedColumnNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - - @Override - protected XmlJoinColumn getColumnResource() { - return this.joinColumn; - } - - @Override - protected void addColumnResource() { - //joinColumns are part of a collection, the join-column element will be removed/added - //when the XmlJoinColumn is removed/added to the XmlEntity collection - } - - @Override - protected void removeColumnResource() { - //joinColumns are part of a collection, the pk-join-column element will be removed/added - //when the XmlJoinColumn is removed/added to the XmlEntity collection - } - - - @Override - public void initialize(XmlJoinColumn column) { - this.joinColumn = column; - super.initialize(column); - this.specifiedReferencedColumnName = specifiedReferencedColumnName(column); - this.defaultReferencedColumnName = defaultReferencedColumnName(); - } - - @Override - public void update(XmlJoinColumn column) { - this.joinColumn = column; - super.update(column); - this.setSpecifiedReferencedColumnName_(specifiedReferencedColumnName(column)); - this.setDefaultReferencedColumnName(defaultReferencedColumnName()); - } - - protected String specifiedReferencedColumnName(XmlJoinColumn column) { - return column == null ? null : column.getReferencedColumnName(); - } - - @Override - protected String defaultName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultName(this); - } - - protected String defaultReferencedColumnName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!relationshipMapping.isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultReferencedColumnName(this); - } - - @Override - protected String defaultTable() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!relationshipMapping.isRelationshipOwner()) { - return null; - } - return super.defaultTable(); - } - - - //******************* validation *********************** - - /** used internally as a mechanism to short circuit continued message adding */ - private boolean doContinue; - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - this.doContinue = this.connectionProfileIsActive(); - - OrmRelationshipMapping mapping = (OrmRelationshipMapping) getOwner().getRelationshipMapping(); - //TODO why is this commented out? i copied it like this from the maintenance stream -// if (doContinue && typeMapping.tableNameIsInvalid(table)) { -// if (mapping.isVirtual()) { -// messages.add( -// JpaValidationMessages.buildMessage( -// IMessage.HIGH_SEVERITY, -// IJpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, -// new String[] {mapping.getPersistentAttribute().getName(), table, column.getName()}, -// column, column.getTableTextRange()) -// ); -// } -// else { -// messages.add( -// JpaValidationMessages.buildMessage( -// IMessage.HIGH_SEVERITY, -// IJpaValidationMessages.COLUMN_UNRESOLVED_TABLE, -// new String[] {table, column.getName()}, -// column, column.getTableTextRange()) -// ); -// } -// doContinue = false; -// } -// - if (this.doContinue && ! isResolved()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {mapping.getName(), getName()}, - this, - getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange()) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTable.java deleted file mode 100644 index 74609dd1c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTable.java +++ /dev/null @@ -1,695 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmJoinTable extends AbstractOrmTable implements OrmJoinTable -{ - - protected final List<OrmJoinColumn> specifiedJoinColumns; - - protected OrmJoinColumn defaultJoinColumn; - - protected final List<OrmJoinColumn> specifiedInverseJoinColumns; - - protected OrmJoinColumn defaultInverseJoinColumn; - - protected XmlRelationshipMapping relationshipMappingResource; - - public GenericOrmJoinTable(OrmRelationshipMapping parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<OrmJoinColumn>(); - this.specifiedInverseJoinColumns = new ArrayList<OrmJoinColumn>(); - } - - @Override - public OrmRelationshipMapping getParent() { - return (OrmRelationshipMapping) super.getParent(); - } - - public OrmRelationshipMapping getRelationshipMapping() { - return getParent(); - } - - public void initializeFrom(JoinTable oldJoinTable) { - super.initializeFrom(oldJoinTable); - int index = 0; - for (JoinColumn joinColumn : CollectionTools.iterable(oldJoinTable.specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - index = 0; - for (JoinColumn joinColumn : CollectionTools.iterable(oldJoinTable.specifiedInverseJoinColumns())) { - OrmJoinColumn newJoinColumn = addSpecifiedInverseJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - //******************* AbstractOrmTable implementation ***************** - - @Override - protected String defaultCatalog() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return getEntityMappings().getCatalog(); - } - - @Override - protected String defaultName() { - return MappingTools.buildJoinTableDefaultName(getRelationshipMapping()); - } - - @Override - protected String defaultSchema() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return getEntityMappings().getSchema(); - } - - @Override - protected void removeTableResource() { - this.relationshipMappingResource.setJoinTable(null); - } - - @Override - protected void addTableResource() { - this.relationshipMappingResource.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - - } - - @Override - protected XmlJoinTable getTableResource() { - return this.relationshipMappingResource.getJoinTable(); - } - - - //******************* JoinTable implementation ***************** - - //****************** join columns ********************** - public ListIterator<OrmJoinColumn> joinColumns() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - protected ListIterator<OrmJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<OrmJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - public OrmJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(OrmJoinColumn newJoinColumn) { - OrmJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - if (getTableResource() == null) { - addTableResource(); - } - OrmJoinColumn joinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - XmlJoinColumn xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumnImpl(); - joinColumn.initialize(xmlJoinColumn); - this.getTableResource().getJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = buildJoinColumn(null); - } - this.getTableResource().getJoinColumns().remove(index); - fireItemRemoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getTableResource().getJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - //****************** inverse join columns ********************** - - public ListIterator<OrmJoinColumn> inverseJoinColumns() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumns() : this.defaultInverseJoinColumns(); - } - - public int inverseJoinColumnsSize() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumnsSize() : this.defaultInverseJoinColumnsSize(); - } - - public ListIterator<OrmJoinColumn> specifiedInverseJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedInverseJoinColumns); - } - - public int specifiedInverseJoinColumnsSize() { - return this.specifiedInverseJoinColumns.size(); - } - - protected ListIterator<OrmJoinColumn> defaultInverseJoinColumns() { - if (this.defaultInverseJoinColumn != null) { - return new SingleElementListIterator<OrmJoinColumn>(this.defaultInverseJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultInverseJoinColumnsSize() { - return (this.defaultInverseJoinColumn == null) ? 0 : 1; - } - - public OrmJoinColumn getDefaultInverseJoinColumn() { - return this.defaultInverseJoinColumn; - } - - protected void setDefaultInverseJoinColumn(OrmJoinColumn newJoinColumn) { - OrmJoinColumn oldJoinColumn = this.defaultInverseJoinColumn; - this.defaultInverseJoinColumn = newJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - public boolean containsSpecifiedInverseJoinColumns() { - return !this.specifiedInverseJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedInverseJoinColumn(int index) { - if (getTableResource() == null) { - addTableResource(); - } - OrmJoinColumn joinColumn = getJpaFactory().buildOrmJoinColumn(this, new InverseJoinColumnOwner()); - this.specifiedInverseJoinColumns.add(index, joinColumn); - XmlJoinColumn xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumnImpl(); - joinColumn.initialize(xmlJoinColumn); - this.getTableResource().getInverseJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected void addSpecifiedInverseJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedInverseJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedInverseJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedInverseJoinColumns.remove(index); - if (!containsSpecifiedInverseJoinColumns()) { - //create the defaultInverseJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultInverseJoinColumn = buildInverseJoinColumn(null); - } - this.getTableResource().getInverseJoinColumns().remove(index); - fireItemRemoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultInverseJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, null, this.defaultInverseJoinColumn); - } - } - - protected void removeSpecifiedInverseJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedInverseJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedInverseJoinColumns, targetIndex, sourceIndex); - this.getTableResource().getInverseJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - // ****************** OrmJoinTable implementation ***************** - public boolean isSpecified() { - return this.getTableResource() != null && getTableResource().isSpecified(); - } - - public void initialize(XmlRelationshipMapping relationshipMapping) { - this.relationshipMappingResource = relationshipMapping; - this.initialize(this.getTableResource()); - } - - public void update(XmlRelationshipMapping relationshipMapping) { - this.relationshipMappingResource = relationshipMapping; - this.update(this.getTableResource()); - } - - protected void initialize(XmlJoinTable joinTable) { - super.initialize(joinTable); - this.initializeSpecifiedJoinColumns(joinTable); - this.initializeDefaultJoinColumn(); - this.initializeSpecifiedInverseJoinColumns(joinTable); - this.initializeDefaultInverseJoinColumn(); - } - - protected void initializeSpecifiedJoinColumns(XmlJoinTable joinTable) { - if (joinTable == null) { - return; - } - for (XmlJoinColumn joinColumn : joinTable.getJoinColumns()) { - this.specifiedJoinColumns.add(buildJoinColumn(joinColumn)); - } - } - - protected void initializeDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(null); - } - - protected void initializeSpecifiedInverseJoinColumns(XmlJoinTable joinTable) { - if (joinTable == null) { - return; - } - for (XmlJoinColumn joinColumn : joinTable.getInverseJoinColumns()) { - this.specifiedInverseJoinColumns.add(buildInverseJoinColumn(joinColumn)); - } - } - - protected void initializeDefaultInverseJoinColumn() { - if (!shouldBuildDefaultInverseJoinColumn()) { - return; - } - this.defaultInverseJoinColumn = buildInverseJoinColumn(null); - } - - protected void update(XmlJoinTable joinTable) { - super.update(joinTable); - this.updateSpecifiedJoinColumns(joinTable); - this.updateDefaultJoinColumn(); - this.updateSpecifiedInverseJoinColumns(joinTable); - this.updateDefaultInverseJoinColumn(); - } - - protected void updateSpecifiedJoinColumns(XmlJoinTable joinTable) { - ListIterator<OrmJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<XmlJoinColumn> resourceJoinColumns = EmptyListIterator.instance(); - if (joinTable != null) { - resourceJoinColumns = new CloneListIterator<XmlJoinColumn>(joinTable.getJoinColumns());//prevent ConcurrentModificiationException - } - - while (joinColumns.hasNext()) { - OrmJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn(resourceJoinColumns.next())); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns(); - } - - protected void updateDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(null)); - } - else { - this.defaultJoinColumn.update(null); - } - } - - protected void updateSpecifiedInverseJoinColumns(XmlJoinTable joinTable) { - ListIterator<OrmJoinColumn> inverseJoinColumns = specifiedInverseJoinColumns(); - ListIterator<XmlJoinColumn> resourceInverseJoinColumns = EmptyListIterator.instance(); - if (joinTable != null) { - resourceInverseJoinColumns = new CloneListIterator<XmlJoinColumn>(joinTable.getInverseJoinColumns());//prevent ConcurrentModificiationException - } - - while (inverseJoinColumns.hasNext()) { - OrmJoinColumn joinColumn = inverseJoinColumns.next(); - if (resourceInverseJoinColumns.hasNext()) { - joinColumn.update(resourceInverseJoinColumns.next()); - } - else { - removeSpecifiedInverseJoinColumn_(joinColumn); - } - } - - while (resourceInverseJoinColumns.hasNext()) { - addSpecifiedInverseJoinColumn(specifiedInverseJoinColumnsSize(), buildInverseJoinColumn(resourceInverseJoinColumns.next())); - } - } - - protected boolean shouldBuildDefaultInverseJoinColumn() { - return !containsSpecifiedInverseJoinColumns(); - } - - protected void updateDefaultInverseJoinColumn() { - if (!shouldBuildDefaultInverseJoinColumn()) { - setDefaultInverseJoinColumn(null); - return; - } - if (getDefaultInverseJoinColumn() == null) { - this.setDefaultInverseJoinColumn(buildInverseJoinColumn(null)); - } - else { - this.defaultInverseJoinColumn.update(null); - } - } - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - protected OrmJoinColumn buildInverseJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new InverseJoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - - // ************************** validation *********************** - - /** used internally as a mechanism to short circuit continued message adding */ - private boolean doContinue; - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - this.addTableMessages(messages); - - if (this.doContinue) { - for (OrmJoinColumn joinColumn : CollectionTools.iterable(joinColumns())) { - joinColumn.addToMessages(messages); - } - - for (OrmJoinColumn joinColumn : CollectionTools.iterable(inverseJoinColumns())) { - joinColumn.addToMessages(messages); - } - } - } - - protected void addTableMessages(List<IMessage> messages) { - this.doContinue = connectionProfileIsActive(); - String schema = getSchema(); - OrmRelationshipMapping mapping = getRelationshipMapping(); - - if (this.doContinue && ! hasResolvedSchema()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {mapping.getName(), schema, getName()}, - this, - getSchemaTextRange()) - ); - - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange()) - ); - } - this.doContinue = false; - } - - if (this.doContinue && ! isResolved()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_NAME, - new String[] {mapping.getName(), getName()}, - this, - getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange()) - ); - } - } - } - /** - * just a little common behavior - */ - abstract class AbstractJoinColumnOwner implements OrmJoinColumn.Owner - { - AbstractJoinColumnOwner() { - super(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericOrmJoinTable.this.getRelationshipMapping(); - } - - /** - * the default table name is always valid and a specified table name - * is prohibited (which will be handled elsewhere) - */ - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - /** - * the join column can only be on the join table itself - */ - public boolean tableIsAllowed() { - return false; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - if (GenericOrmJoinTable.this.getName() == null) { - return null; - } - return (GenericOrmJoinTable.this.getName().equals(tableName)) ? GenericOrmJoinTable.this.getDbTable() : null; - } - - /** - * by default, the join column is, obviously, in the join table; - * not sure whether it can be anywhere else... - */ - public String getDefaultTableName() { - return GenericOrmJoinTable.this.getName(); - } - - public TextRange getValidationTextRange() { - return GenericOrmJoinTable.this.getValidationTextRange(); - } - } - - - /** - * owner for "forward-pointer" JoinColumns; - * these point at the target/inverse entity - */ - class InverseJoinColumnOwner extends AbstractJoinColumnOwner - { - public InverseJoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericOrmJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericOrmJoinTable.this.getRelationshipMapping().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - if (dbTable != null) { - return dbTable; - } - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmJoinTable.this.defaultInverseJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericOrmJoinTable.this.inverseJoinColumnsSize(); - } - - } - - - /** - * owner for "back-pointer" JoinColumns; - * these point at the source/owning entity - */ - class JoinColumnOwner extends AbstractJoinColumnOwner - { - public JoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericOrmJoinTable.this.getRelationshipMapping().getEntity(); - } - - public String getAttributeName() { - Entity targetEntity = GenericOrmJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - String attributeName = GenericOrmJoinTable.this.getRelationshipMapping().getName(); - for (Iterator<PersistentAttribute> stream = targetEntity.getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - AttributeMapping mapping = attribute.getMapping(); - if (mapping instanceof NonOwningMapping) { - String mappedBy = ((NonOwningMapping) mapping).getMappedBy(); - if ((mappedBy != null) && mappedBy.equals(attributeName)) { - return attribute.getName(); - } - } - } - return null; - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - return (dbTable != null) ? dbTable : getTypeMapping().getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmJoinTable.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericOrmJoinTable.this.joinColumnsSize(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyMapping.java deleted file mode 100644 index c7341a8f49..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyMapping.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; - -public class GenericOrmManyToManyMapping extends AbstractOrmMultiRelationshipMapping<XmlManyToMany> - implements OrmManyToManyMapping -{ - - public GenericOrmManyToManyMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToManyMapping(this); - } - - @Override - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - super.initializeFromXmlNonOwningMapping(oldMapping); - setMappedBy(oldMapping.getMappedBy()); - } - - public int getXmlSequence() { - return 7; - } - - // ********** NonOwningMapping implementation ********** - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - - public XmlManyToMany addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlManyToMany manyToMany = OrmFactory.eINSTANCE.createXmlManyToManyImpl(); - getPersistentAttribute().initialize(manyToMany); - typeMapping.getAttributes().getManyToManys().add(manyToMany); - return manyToMany; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getManyToManys().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneMapping.java deleted file mode 100644 index 7bf9876ee8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneMapping.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; - - -public class GenericOrmManyToOneMapping extends AbstractOrmSingleRelationshipMapping<XmlManyToOne> - implements OrmManyToOneMapping -{ - - public GenericOrmManyToOneMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public int getXmlSequence() { - return 4; - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - //ManyToOne mapping is always the owning side - public boolean isRelationshipOwner() { - return true; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToOneMapping(this); - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - public XmlManyToOne addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlManyToOne manyToOne = OrmFactory.eINSTANCE.createXmlManyToOneImpl(); - getPersistentAttribute().initialize(manyToOne); - typeMapping.getAttributes().getManyToOnes().add(manyToOne); - return manyToOne; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getManyToOnes().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedSuperclass.java deleted file mode 100644 index c7d81fdf0f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedSuperclass.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlIdClass; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - - -public class GenericOrmMappedSuperclass extends AbstractOrmTypeMapping<XmlMappedSuperclass> - implements OrmMappedSuperclass -{ - protected String idClass; - - public GenericOrmMappedSuperclass(OrmPersistentType parent) { - super(parent); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (oldIdClass != newIdClass) { - if (this.idClassResource() != null) { - this.idClassResource().setClassName(newIdClass); - if (this.idClassResource().isAllFeaturesUnset()) { - removeIdClassResource(); - } - } - else if (newIdClass != null) { - addIdClassResource(); - idClassResource().setClassName(newIdClass); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected XmlIdClass idClassResource() { - return getTypeMappingResource().getIdClass(); - } - - protected void addIdClassResource() { - getTypeMappingResource().setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - } - - protected void removeIdClassResource() { - getTypeMappingResource().setIdClass(null); - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - @Override - public Iterator<String> overridableAttributeNames() { - return this.namesOf(this.overridableAttributes()); - } - - @Override - public Iterator<OrmPersistentAttribute> overridableAttributes() { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(OrmPersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - @Override - public Iterator<String> overridableAssociationNames() { - return this.namesOf(this.overridableAssociations()); - } - - @Override - public Iterator<OrmPersistentAttribute> overridableAssociations() { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(OrmPersistentAttribute o) { - return o.isOverridableAssociation(); - } - }; - } - - private Iterator<String> namesOf(Iterator<OrmPersistentAttribute> attributes) { - return new TransformationIterator<OrmPersistentAttribute, String>(attributes) { - @Override - protected String transform(OrmPersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public int getXmlSequence() { - return 0; - } - - protected Boolean metadataComplete(XmlMappedSuperclass mappedSuperclass) { - return mappedSuperclass.getMetadataComplete(); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getMappedSuperclasses().remove(this.getTypeMappingResource()); - } - - public XmlMappedSuperclass addToResourceModel(XmlEntityMappings entityMappings) { - XmlMappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createXmlMappedSuperclass(); - getPersistentType().initialize(mappedSuperclass); - entityMappings.getMappedSuperclasses().add(mappedSuperclass); - return mappedSuperclass; - } - - - - @Override - public void initialize(XmlMappedSuperclass mappedSuperclass) { - super.initialize(mappedSuperclass); - this.initializeIdClass(this.idClassResource()); - } - - protected void initializeIdClass(XmlIdClass idClassResource) { - this.idClass = this.idClass(idClassResource); - } - - @Override - public void update(XmlMappedSuperclass mappedSuperclass) { - super.update(mappedSuperclass); - this.updateIdClass(this.idClassResource()); - } - - protected void updateIdClass(XmlIdClass idClassResource) { - this.setIdClass_(this.idClass(idClassResource)); - } - - protected String idClass(XmlIdClass idClassResource) { - return idClassResource == null ? null : idClassResource.getClassName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedNativeQuery.java deleted file mode 100644 index 11151b5175..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedNativeQuery.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; - - -public class GenericOrmNamedNativeQuery extends AbstractOrmQuery<XmlNamedNativeQuery> - implements OrmNamedNativeQuery -{ - - protected String resultClass; - - protected String resultSetMapping; - - - public GenericOrmNamedNativeQuery(OrmJpaContextNode parent) { - super(parent); - } - - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - getQueryResource().setResultClass(newResultClass); - firePropertyChanged(NamedNativeQuery.RESULT_CLASS_PROPERTY, oldResultClass, newResultClass); - } - - public String getResultSetMapping() { - return this.resultSetMapping; - } - - public void setResultSetMapping(String newResultSetMapping) { - String oldResultSetMapping = this.resultSetMapping; - this.resultSetMapping = newResultSetMapping; - getQueryResource().setResultSetMapping(newResultSetMapping); - firePropertyChanged(NamedNativeQuery.RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - - @Override - public void initialize(XmlNamedNativeQuery queryResource) { - super.initialize(queryResource); - this.resultClass = queryResource.getResultClass(); - this.resultSetMapping = queryResource.getResultSetMapping(); - } - - @Override - public void update(XmlNamedNativeQuery queryResource) { - super.update(queryResource); - this.setResultClass(queryResource.getResultClass()); - this.setResultSetMapping(queryResource.getResultSetMapping()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedQuery.java deleted file mode 100644 index 5bd004150f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedQuery.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; - - -public class GenericOrmNamedQuery extends AbstractOrmQuery<XmlNamedQuery> implements OrmNamedQuery -{ - - public GenericOrmNamedQuery(OrmJpaContextNode parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNullAttributeMapping.java deleted file mode 100644 index 5ab796605c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNullAttributeMapping.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; - - -public class GenericOrmNullAttributeMapping extends AbstractOrmAttributeMapping<XmlNullAttributeMapping> -{ - - public GenericOrmNullAttributeMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public int getXmlSequence() { - return -1; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmAttributeMapping(this); - } - - public String getKey() { - return null; - } - - public XmlAttributeMapping addToResourceModel(AbstractXmlTypeMapping typeMapping) { - throw new UnsupportedOperationException(); - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToManyMapping.java deleted file mode 100644 index 430dd74a1a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToManyMapping.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; - - -public class GenericOrmOneToManyMapping extends AbstractOrmMultiRelationshipMapping<XmlOneToMany> - implements OrmOneToManyMapping -{ - - public GenericOrmOneToManyMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToManyMapping(this); - } - - @Override - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - super.initializeFromXmlNonOwningMapping(oldMapping); - setMappedBy(oldMapping.getMappedBy()); - } - - public int getXmlSequence() { - return 5; - } - - // ********** NonOwningMapping implementation ********** - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - public XmlOneToMany addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlOneToMany oneToMany = OrmFactory.eINSTANCE.createXmlOneToManyImpl(); - getPersistentAttribute().initialize(oneToMany); - typeMapping.getAttributes().getOneToManys().add(oneToMany); - return oneToMany; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getOneToManys().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java deleted file mode 100644 index b9cf47f2f2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmOneToOneMapping extends AbstractOrmSingleRelationshipMapping<XmlOneToOne> - implements OrmOneToOneMapping -{ - - protected String mappedBy; - - protected final List<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns; - - - public GenericOrmOneToOneMapping(OrmPersistentAttribute parent) { - super(parent); - this.primaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToOneMapping(this); - } - - @Override - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - super.initializeFromXmlNonOwningMapping(oldMapping); - setMappedBy(oldMapping.getMappedBy()); - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.primaryKeyJoinColumns); - } - - public int primaryKeyJoinColumnsSize() { - return this.primaryKeyJoinColumns.size(); - } - - public OrmPrimaryKeyJoinColumn addPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn pkJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, new JoinColumnOwner()); - XmlPrimaryKeyJoinColumn xmlPkJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl(); - this.primaryKeyJoinColumns.add(index, pkJoinColumn); - this.getAttributeMapping().getPrimaryKeyJoinColumns().add(index, xmlPkJoinColumn); - pkJoinColumn.initialize(xmlPkJoinColumn); - this.fireItemAdded(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, pkJoinColumn); - return pkJoinColumn; - } - - protected void addPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void removePrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removePrimaryKeyJoinColumn(this.primaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removePrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPkJoinColumn = this.primaryKeyJoinColumns.remove(index); - this.getAttributeMapping().getPrimaryKeyJoinColumns().remove(index); - fireItemRemoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, removedPkJoinColumn); - } - - protected void removePrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void movePrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.primaryKeyJoinColumns, targetIndex, sourceIndex); - this.getAttributeMapping().getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public boolean containsPrimaryKeyJoinColumns() { - return !this.primaryKeyJoinColumns.isEmpty(); - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - getAttributeMapping().setMappedBy(newMappedBy); - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - public TextRange getMappedByTextRange() { - TextRange mappedByTextRange = getAttributeMapping().getMappedByTextRange(); - return mappedByTextRange != null ? mappedByTextRange : getValidationTextRange(); - } - - - public int getXmlSequence() { - return 6; - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - public XmlOneToOne addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlOneToOne oneToOne = OrmFactory.eINSTANCE.createXmlOneToOneImpl(); - getPersistentAttribute().initialize(oneToOne); - typeMapping.getAttributes().getOneToOnes().add(oneToOne); - return oneToOne; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getOneToOnes().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - - //***************** Validation *********************************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (this.getMappedBy() != null) { - addMappedByMessages(messages); - } - } - - @Override - protected boolean addJoinColumnMessages() { - if (containsPrimaryKeyJoinColumns() && !containsSpecifiedJoinColumns()) { - return false; - } - return super.addJoinColumnMessages(); - } - - protected void addMappedByMessages(List<IMessage> messages) { - String mappedBy = this.getMappedBy(); - Entity targetEntity = this.getResolvedTargetEntity(); - - if (targetEntity == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange()) - ); - return; - } - - if (! this.mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange()) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, this.getMappedByTextRange()) - ); - } - } - - @Override - public void initialize(XmlOneToOne oneToOne) { - super.initialize(oneToOne); - this.mappedBy = oneToOne.getMappedBy(); - this.initializePrimaryKeyJoinColumns(oneToOne); - } - - protected void initializePrimaryKeyJoinColumns(XmlOneToOne oneToOne) { - if (oneToOne == null) { - return; - } - for (XmlPrimaryKeyJoinColumn pkJoinColumn : oneToOne.getPrimaryKeyJoinColumns()) { - this.primaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(pkJoinColumn)); - } - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn xmlPkJoinColumn) { - OrmPrimaryKeyJoinColumn ormPkJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, new JoinColumnOwner()); - ormPkJoinColumn.initialize(xmlPkJoinColumn); - return ormPkJoinColumn; - } - - - @Override - public void update(XmlOneToOne oneToOne) { - super.update(oneToOne); - this.setMappedBy_(oneToOne.getMappedBy()); - this.updatePrimaryKeyJoinColumns(oneToOne); - } - - - protected void updatePrimaryKeyJoinColumns(XmlOneToOne oneToOne) { - ListIterator<OrmPrimaryKeyJoinColumn> pkJoinColumns = primaryKeyJoinColumns(); - ListIterator<XmlPrimaryKeyJoinColumn> resourcePkJoinColumns = EmptyListIterator.instance(); - if (oneToOne != null) { - resourcePkJoinColumns = new CloneListIterator<XmlPrimaryKeyJoinColumn>(oneToOne.getPrimaryKeyJoinColumns());//prevent ConcurrentModificiationException - } - - while (pkJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn pkJoinColumn = pkJoinColumns.next(); - if (resourcePkJoinColumns.hasNext()) { - pkJoinColumn.update(resourcePkJoinColumns.next()); - } - else { - removePrimaryKeyJoinColumn_(pkJoinColumn); - } - } - - while (resourcePkJoinColumns.hasNext()) { - addPrimaryKeyJoinColumn(primaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn(resourcePkJoinColumns.next())); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java deleted file mode 100644 index 98d1a5c909..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java +++ /dev/null @@ -1,357 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmPersistentAttribute extends AbstractOrmJpaContextNode - implements OrmPersistentAttribute -{ - - protected List<OrmAttributeMappingProvider> attributeMappingProviders; - - protected OrmAttributeMapping attributeMapping; - - public GenericOrmPersistentAttribute(OrmPersistentType parent, String mappingKey) { - super(parent); - this.attributeMappingProviders = buildAttributeMappingProviders(); - this.attributeMapping = buildAttributeMapping(mappingKey); - } - - protected List<OrmAttributeMappingProvider> buildAttributeMappingProviders() { - List<OrmAttributeMappingProvider> list = new ArrayList<OrmAttributeMappingProvider>(); - list.add(OrmEmbeddedMappingProvider.instance()); //bug 190344 need to test default embedded before basic - list.add(OrmBasicMappingProvider.instance()); - list.add(OrmTransientMappingProvider.instance()); - list.add(OrmIdMappingProvider.instance()); - list.add(OrmManyToManyMappingProvider.instance()); - list.add(OrmOneToManyMappingProvider.instance()); - list.add(OrmManyToOneMappingProvider.instance()); - list.add(OrmOneToOneMappingProvider.instance()); - list.add(OrmVersionMappingProvider.instance()); - list.add(OrmEmbeddedIdMappingProvider.instance()); - return list; - } - - protected OrmAttributeMappingProvider attributeMappingProvider(String key) { - for (OrmAttributeMappingProvider provider : this.attributeMappingProviders) { - if (provider.getKey().equals(key)) { - return provider; - } - } - return OrmNullAttributeMappingProvider.instance(); - } - - protected OrmAttributeMapping buildAttributeMapping(String key) { - return this.attributeMappingProvider(key).buildAttributeMapping(getJpaFactory(), this); - } - - public String getId() { - return OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID; - } - - public String getName() { - return getMapping().getName(); - } - - public void nameChanged(String oldName, String newName) { - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public OrmAttributeMapping getSpecifiedMapping() { - return this.attributeMapping; - } - - public OrmAttributeMapping getMapping() { - return this.attributeMapping; - } - - public String getMappingKey() { - return this.getMapping().getKey(); - } - - public String getDefaultMappingKey() { - return null; - } - - public void setSpecifiedMappingKey(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmAttributeMapping oldMapping = getMapping(); - this.attributeMapping = buildAttributeMapping(newMappingKey); - getPersistentType().changeMapping(this, oldMapping, this.attributeMapping); - firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, this.attributeMapping); - } - - protected void setSpecifiedMappingKey_(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmAttributeMapping oldMapping = getMapping(); - this.attributeMapping = buildAttributeMapping(newMappingKey); - firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, this.attributeMapping); - } - - public Collection<OrmAttributeMappingProvider> attributeMappingProviders() { - return this.attributeMappingProviders; - } - - public OrmPersistentType getPersistentType() { - return (OrmPersistentType) getParent(); - } - - public OrmTypeMapping getTypeMapping() { - return getPersistentType().getMapping(); - } - - public boolean isVirtual() { - return getPersistentType().containsVirtualPersistentAttribute(this); - } - - public void makeVirtual() { - if (isVirtual()) { - throw new IllegalStateException("Attribute is already virtual"); - } - getOrmPersistentType().makePersistentAttributeVirtual(this); - } - - public void makeSpecified() { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); - } - if (getMappingKey() == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - throw new IllegalStateException("Use makeSpecified(String) instead and specify a mapping type"); - } - getOrmPersistentType().makePersistentAttributeSpecified(this); - } - - public void makeSpecified(String mappingKey) { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); - } - getOrmPersistentType().makePersistentAttributeSpecified(this, mappingKey); - } - - public String getPrimaryKeyColumnName() { - return getMapping().getPrimaryKeyColumnName(); - } - - public boolean isOverridableAttribute() { - return this.getMapping().isOverridableAttributeMapping(); - } - - public boolean isOverridableAssociation() { - return this.getMapping().isOverridableAssociationMapping(); - } - - public boolean isIdAttribute() { - return this.getMapping().isIdMapping(); - } - - //TODO is there a way to avoid a method for every mapping type? - //I am trying to take adavantage of generics here, but it sure is - //leading to a lot of duplicated code. - KFM - public void initialize(XmlBasic basic) { - ((OrmBasicMapping) getMapping()).initialize(basic); - } - - public void initialize(XmlEmbedded embedded) { - ((OrmEmbeddedMapping) getMapping()).initialize(embedded); - } - - public void initialize(XmlVersion version) { - ((OrmVersionMapping) getMapping()).initialize(version); - } - - public void initialize(XmlManyToOne manyToOne) { - ((OrmManyToOneMapping) getMapping()).initialize(manyToOne); - } - - public void initialize(XmlOneToMany oneToMany) { - ((OrmOneToManyMapping) getMapping()).initialize(oneToMany); - } - - public void initialize(XmlOneToOne oneToOne) { - ((OrmOneToOneMapping) getMapping()).initialize(oneToOne); - } - - public void initialize(XmlManyToMany manyToMany) { - ((OrmManyToManyMapping) getMapping()).initialize(manyToMany); - } - - public void initialize(XmlId id) { - ((OrmIdMapping) getMapping()).initialize(id); - } - - public void initialize(XmlEmbeddedId embeddedId) { - ((OrmEmbeddedIdMapping) getMapping()).initialize(embeddedId); - } - - public void initialize(XmlTransient transientResource) { - ((OrmTransientMapping) getMapping()).initialize(transientResource); - } - - public void initialize(XmlNullAttributeMapping xmlNullAttributeMapping) { - ((GenericOrmNullAttributeMapping) getMapping()).initialize(xmlNullAttributeMapping); - } - - public void update(XmlId id) { - if (getMappingKey() != MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - } - ((OrmIdMapping) getMapping()).update(id); - } - - public void update(XmlEmbeddedId embeddedId) { - if (getMappingKey() != MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - } - ((OrmEmbeddedIdMapping) getMapping()).update(embeddedId); - } - - public void update(XmlBasic basic) { - if (getMappingKey() != MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - } - ((OrmBasicMapping) getMapping()).update(basic); - } - - public void update(XmlVersion version) { - if (getMappingKey() != MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - } - ((OrmVersionMapping) getMapping()).update(version); - } - - public void update(XmlManyToOne manyToOne) { - if (getMappingKey() != MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - ((OrmManyToOneMapping) getMapping()).update(manyToOne); - } - - public void update(XmlOneToMany oneToMany) { - if (getMappingKey() != MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - ((OrmOneToManyMapping) getMapping()).update(oneToMany); - } - - public void update(XmlOneToOne oneToOne) { - if (getMappingKey() != MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - ((OrmOneToOneMapping) getMapping()).update(oneToOne); - } - - public void update(XmlManyToMany manyToMany) { - if (getMappingKey() != MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - ((OrmManyToManyMapping) getMapping()).update(manyToMany); - } - - public void update(XmlEmbedded embedded) { - if (getMappingKey() != MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - } - ((OrmEmbeddedMapping) getMapping()).update(embedded); - } - - public void update(XmlTransient transientResource) { - if (getMappingKey() != MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - } - ((OrmTransientMapping) getMapping()).update(transientResource); - } - - public void update(XmlNullAttributeMapping xmlNullAttributeMapping) { - if (getMappingKey() != MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - } - ((GenericOrmNullAttributeMapping) getMapping()).update(xmlNullAttributeMapping); - } - - public JpaStructureNode getStructureNode(int offset) { - return this; - } - - public boolean contains(int textOffset) { - if (isVirtual()) { - return false; - } - return this.attributeMapping.contains(textOffset); - } - - public TextRange getSelectionTextRange() { - if (isVirtual()) { - return null; - } - return this.attributeMapping.getSelectionTextRange(); - } - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - getMapping().addToMessages(messages); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return getPersistentType().getMapping().getAttributesTextRange(); - } - return this.attributeMapping.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - //nothing to dispose - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java deleted file mode 100644 index dc7054e620..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java +++ /dev/null @@ -1,896 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ChainIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmPersistentType extends AbstractOrmJpaContextNode implements OrmPersistentType -{ - protected final List<OrmPersistentAttribute> specifiedPersistentAttributes; - - protected final List<OrmPersistentAttribute> virtualPersistentAttributes; - - protected final Collection<OrmTypeMappingProvider> typeMappingProviders; - - protected OrmTypeMapping ormTypeMapping; - - protected PersistentType parentPersistentType; - - public GenericOrmPersistentType(EntityMappings parent, String mappingKey) { - super(parent); - this.typeMappingProviders = buildTypeMappingProviders(); - this.ormTypeMapping = buildOrmTypeMapping(mappingKey); - this.specifiedPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); - this.virtualPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); - } - - public String getId() { - return OrmStructureNodes.PERSISTENT_TYPE_ID; - } - - public boolean isFor(String fullyQualifiedTypeName) { - String className = getMapping().getClass_(); - if (className == null) { - return false; - } - if (className.equals(fullyQualifiedTypeName)) { - return true; - } - if ((getEntityMappings().getPackage() + "." + className).equals(fullyQualifiedTypeName)) { - return true; - } - return false; - } - - protected OrmTypeMapping buildOrmTypeMapping(String key) { - return getTypeMappingProvider(key).buildTypeMapping(getJpaFactory(), this); - } - - protected Collection<OrmTypeMappingProvider> buildTypeMappingProviders() { - Collection<OrmTypeMappingProvider> collection = new ArrayList<OrmTypeMappingProvider>(); - collection.add(new OrmEntityProvider()); - collection.add(new OrmMappedSuperclassProvider()); - collection.add(new OrmEmbeddableProvider()); - return collection; - } - - protected OrmTypeMappingProvider getTypeMappingProvider(String key) { - for (OrmTypeMappingProvider provider : this.typeMappingProviders) { - if (provider.getKey().equals(key)) { - return provider; - } - } - throw new IllegalArgumentException(); - } - - public OrmTypeMapping getMapping() { - return this.ormTypeMapping; - } - - public void setMappingKey(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmTypeMapping oldMapping = getMapping(); - this.ormTypeMapping = buildOrmTypeMapping(newMappingKey); - getEntityMappings().changeMapping(this, oldMapping, this.ormTypeMapping); - firePropertyChanged(MAPPING_PROPERTY, oldMapping, this.ormTypeMapping); - } - - protected void setMappingKey_(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmTypeMapping oldMapping = getMapping(); - this.ormTypeMapping = buildOrmTypeMapping(newMappingKey); - firePropertyChanged(MAPPING_PROPERTY, oldMapping, this.ormTypeMapping); - } - - public Iterator<PersistentType> inheritanceHierarchy() { - // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(this) { - @Override - protected PersistentType nextLink(PersistentType pt) { - return pt.getParentPersistentType(); - } - }; - } - - public PersistentType getParentPersistentType() { - return this.parentPersistentType; - } - - public void setParentPersistentType(PersistentType newParentPersistentType) { - if (attributeValueHasNotChanged(this.parentPersistentType, newParentPersistentType)) { - return; - } - PersistentType oldParentPersistentType = this.parentPersistentType; - this.parentPersistentType = newParentPersistentType; - firePropertyChanged(PersistentType.PARENT_PERSISTENT_TYPE_PROPERTY, oldParentPersistentType, newParentPersistentType); - } - - public AccessType getAccess() { - return getMapping().getAccess(); - } - - public void changeMapping(OrmPersistentAttribute ormPersistentAttribute, OrmAttributeMapping oldMapping, OrmAttributeMapping newMapping) { - int sourceIndex = this.specifiedPersistentAttributes.indexOf(ormPersistentAttribute); - if (sourceIndex != -1) { - this.specifiedPersistentAttributes.remove(sourceIndex); - oldMapping.removeFromResourceModel(getMapping().getTypeMappingResource()); - } - if (getMapping().getTypeMappingResource().getAttributes() == null) { - getMapping().getTypeMappingResource().setAttributes(OrmFactory.eINSTANCE.createAttributes()); - } - int targetIndex = insertionIndex(ormPersistentAttribute); - this.specifiedPersistentAttributes.add(targetIndex, ormPersistentAttribute); - newMapping.addToResourceModel(getMapping().getTypeMappingResource()); - oldMapping.initializeOn(newMapping); - if (sourceIndex != -1) { - //TODO are the source and target correct in this case, or is target off by one??? - fireItemMoved(SPECIFIED_ATTRIBUTES_LIST, targetIndex, sourceIndex); - } - } - - public void makePersistentAttributeVirtual(OrmPersistentAttribute ormPersistentAttribute) { - if (ormPersistentAttribute.isVirtual()) { - throw new IllegalStateException("Attribute is already virtual"); - } - JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getMapping().getJavaPersistentAttribute(); - OrmPersistentAttribute virtualPersistentAttribute = null; - if (javaPersistentAttribute != null) { - virtualPersistentAttribute = createVirtualPersistentAttribute(javaPersistentAttribute); - this.virtualPersistentAttributes.add(virtualPersistentAttribute); - } - this.removeSpecifiedPersistentAttribute(ormPersistentAttribute); - if (virtualPersistentAttribute != null) { - fireItemAdded(VIRTUAL_ATTRIBUTES_LIST, virtualAttributesSize() - 1, virtualPersistentAttribute); - } - } - - public void makePersistentAttributeSpecified(OrmPersistentAttribute ormPersistentAttribute) { - makePersistentAttributeSpecified(ormPersistentAttribute, ormPersistentAttribute.getMappingKey()); - } - - public void makePersistentAttributeSpecified(OrmPersistentAttribute ormPersistentAttribute, String mappingKey) { - if (!ormPersistentAttribute.isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); - } - if (mappingKey == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - throw new IllegalStateException("Use makePersistentAttributeSpecified(OrmPersistentAttribute, String) instead and specify a mapping type"); - } - - OrmPersistentAttribute newPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, mappingKey); - if (getMapping().getTypeMappingResource().getAttributes() == null) { - getMapping().getTypeMappingResource().setAttributes(OrmFactory.eINSTANCE.createAttributes()); - } - int insertionIndex = insertionIndex(newPersistentAttribute); - this.specifiedPersistentAttributes.add(insertionIndex, newPersistentAttribute); - newPersistentAttribute.getMapping().addToResourceModel(getMapping().getTypeMappingResource()); - - int removalIndex = this.virtualPersistentAttributes.indexOf(ormPersistentAttribute); - this.virtualPersistentAttributes.remove(ormPersistentAttribute); - newPersistentAttribute.getSpecifiedMapping().setName(ormPersistentAttribute.getName()); - - fireItemAdded(PersistentType.SPECIFIED_ATTRIBUTES_LIST, insertionIndex, newPersistentAttribute); - fireItemRemoved(VIRTUAL_ATTRIBUTES_LIST, removalIndex, ormPersistentAttribute); - } - - public Iterator<String> allAttributeNames() { - return this.attributeNames(this.allAttributes()); - } - - public Iterator<PersistentAttribute> allAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<PersistentType, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(PersistentType pt) { - return pt.attributes(); - } - }); - } - - protected Iterator<OrmPersistentAttribute> attributesNamed(final String attributeName) { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(attributes()) { - @Override - protected boolean accept(OrmPersistentAttribute o) { - if (attributeName == null && o.getName() == null) { - return true; - } - if (attributeName != null && attributeName.equals(o.getName())) { - return true; - } - return false; - } - }; - } - - public OrmPersistentAttribute getAttributeNamed(String attributeName) { - Iterator<OrmPersistentAttribute> stream = attributesNamed(attributeName); - return (stream.hasNext()) ? stream.next() : null; - } - - public Iterator<String> attributeNames() { - return this.attributeNames(this.attributes()); - } - - protected Iterator<String> attributeNames(Iterator<? extends PersistentAttribute> attrs) { - return new TransformationIterator<PersistentAttribute, String>(attrs) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - protected OrmPersistentAttribute specifiedAttributeNamed(String attributeName) { - Iterator<OrmPersistentAttribute> stream = specifiedAttributesNamed(attributeName); - return (stream.hasNext()) ? stream.next() : null; - - } - - protected Iterator<OrmPersistentAttribute> specifiedAttributesNamed(final String attributeName) { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(specifiedAttributes()) { - @Override - protected boolean accept(OrmPersistentAttribute ormPersistentAttribute) { - return attributeName.equals(ormPersistentAttribute.getName()); - } - }; - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmPersistentAttribute> attributes() { - return new CompositeListIterator<OrmPersistentAttribute>(specifiedAttributes(), virtualAttributes()); - } - - public int attributesSize() { - return specifiedAttributesSize() + virtualAttributesSize(); - } - - public ListIterator<OrmPersistentAttribute> specifiedAttributes() { - return new CloneListIterator<OrmPersistentAttribute>(this.specifiedPersistentAttributes); - } - - public int specifiedAttributesSize() { - return this.specifiedPersistentAttributes.size(); - } - - public ListIterator<OrmPersistentAttribute> virtualAttributes() { - return new CloneListIterator<OrmPersistentAttribute>(this.virtualPersistentAttributes); - } - - public int virtualAttributesSize() { - return this.virtualPersistentAttributes.size(); - } - - protected void addVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - addItemToList(ormPersistentAttribute, this.virtualPersistentAttributes, OrmPersistentType.VIRTUAL_ATTRIBUTES_LIST); - } - - protected void removeVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - removeItemFromList(ormPersistentAttribute, this.virtualPersistentAttributes, OrmPersistentType.VIRTUAL_ATTRIBUTES_LIST); - } - - public boolean containsVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - return this.virtualPersistentAttributes.contains(ormPersistentAttribute); - } - - public OrmPersistentAttribute addSpecifiedPersistentAttribute(String mappingKey, String attributeName) { - OrmPersistentAttribute persistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, mappingKey); - int index = insertionIndex(persistentAttribute); - if (getMapping().getTypeMappingResource().getAttributes() == null) { - getMapping().getTypeMappingResource().setAttributes(OrmFactory.eINSTANCE.createAttributes()); - } - this.specifiedPersistentAttributes.add(index, persistentAttribute); - persistentAttribute.getMapping().addToResourceModel(getMapping().getTypeMappingResource()); - - persistentAttribute.getSpecifiedMapping().setName(attributeName); - fireItemAdded(PersistentType.SPECIFIED_ATTRIBUTES_LIST, index, persistentAttribute); - return persistentAttribute; - } - - protected int insertionIndex(OrmPersistentAttribute persistentAttribute) { - return CollectionTools.insertionIndexOf(this.specifiedPersistentAttributes, persistentAttribute, buildMappingComparator()); - } - - protected Comparator<OrmPersistentAttribute> buildMappingComparator() { - return new Comparator<OrmPersistentAttribute>() { - public int compare(OrmPersistentAttribute o1, OrmPersistentAttribute o2) { - int o1Sequence = o1.getMapping().getXmlSequence(); - int o2Sequence = o2.getMapping().getXmlSequence(); - if (o1Sequence < o2Sequence) { - return -1; - } - if (o1Sequence == o2Sequence) { - return 0; - } - return 1; - } - }; - } - - - protected void addSpecifiedPersistentAttribute_(OrmPersistentAttribute ormPersistentAttribute) { - addItemToList(ormPersistentAttribute, this.specifiedPersistentAttributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - protected void removeSpecifiedPersistentAttribute_(OrmPersistentAttribute ormPersistentAttribute) { - removeItemFromList(ormPersistentAttribute, this.specifiedPersistentAttributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - public void removeSpecifiedPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - int index = this.specifiedPersistentAttributes.indexOf(ormPersistentAttribute); - this.specifiedPersistentAttributes.remove(ormPersistentAttribute); - ormPersistentAttribute.getMapping().removeFromResourceModel(this.ormTypeMapping.getTypeMappingResource()); - fireItemRemoved(PersistentType.SPECIFIED_ATTRIBUTES_LIST, index, ormPersistentAttribute); - } - - public String getName() { - return getMapping().getClass_(); - } - - public void classChanged(String oldClass, String newClass) { - firePropertyChanged(NAME_PROPERTY, oldClass, newClass); - } - - public boolean isMapped() { - return true; - } - - public String getMappingKey() { - return getMapping().getKey(); - } - - public JavaPersistentType getJavaPersistentType() { - return getMapping().getJavaPersistentType(); - } - - - //TODO is there a way to avoid a method for every mapping type? - //I am trying to take adavantage of generics here, but it sure is - //leading to a lot of duplicated code. - KFM - public void initialize(XmlEntity entity) { - ((OrmEntity) getMapping()).initialize(entity); - this.initializeParentPersistentType(); - this.initializePersistentAttributes(entity); - } - - public void initialize(XmlMappedSuperclass mappedSuperclass) { - ((OrmMappedSuperclass) getMapping()).initialize(mappedSuperclass); - this.initializeParentPersistentType(); - this.initializePersistentAttributes(mappedSuperclass); - } - - public void initialize(XmlEmbeddable embeddable) { - ((OrmEmbeddable) getMapping()).initialize(embeddable); - this.initializeParentPersistentType(); - this.initializePersistentAttributes(embeddable); - } - - protected void initializePersistentAttributes(AbstractXmlTypeMapping typeMapping) { - Attributes attributes = typeMapping.getAttributes(); - if (attributes != null) { - this.initializeSpecifiedPersistentAttributes(attributes); - } - this.initializeVirtualPersistentAttributes(); - } - - protected void initializeSpecifiedPersistentAttributes(Attributes attributes) { - for (XmlId id : attributes.getIds()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(id); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlEmbeddedId embeddedId : attributes.getEmbeddedIds()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embeddedId); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlBasic basic : attributes.getBasics()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(basic); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlVersion version : attributes.getVersions()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(version); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlManyToOne manyToOne : attributes.getManyToOnes()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToOne); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlOneToMany oneToMany : attributes.getOneToManys()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToMany); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlOneToOne oneToOne : attributes.getOneToOnes()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToOne); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlManyToMany manyToMany : attributes.getManyToManys()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToMany); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlEmbedded embedded : attributes.getEmbeddeds()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embedded); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlTransient transientResource : attributes.getTransients()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(transientResource); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - } - - protected void initializeVirtualPersistentAttributes() { - ListIterator<JavaPersistentAttribute> javaAttributes = javaPersistentAttributes(); - - while (javaAttributes.hasNext()) { - JavaPersistentAttribute javaPersistentAttribute = javaAttributes.next(); - if (specifiedAttributeNamed(javaPersistentAttribute.getName()) == null) { - OrmPersistentAttribute ormPersistentAttribute = createVirtualPersistentAttribute(javaPersistentAttribute); - this.virtualPersistentAttributes.add(ormPersistentAttribute); - } - } - } - - protected ListIterator<JavaPersistentAttribute> javaPersistentAttributes() { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - if (javaPersistentType != null) { - return javaPersistentType.attributes(); - } - return EmptyListIterator.instance(); - } - - protected void initializeParentPersistentType() { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - if (javaPersistentType != null) { - this.parentPersistentType = javaPersistentType.getParentPersistentType(); - } - } - - public void update(XmlEntity entity) { - if (getMappingKey() != MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - setMappingKey_(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - } - ((OrmEntity) getMapping()).update(entity); - this.updateParentPersistentType(); - this.updatePersistentAttributes(entity); - } - - public void update(XmlMappedSuperclass mappedSuperclass) { - if (getMappingKey() != MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY) { - setMappingKey_(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - } - ((OrmMappedSuperclass) getMapping()).update(mappedSuperclass); - this.updateParentPersistentType(); - this.updatePersistentAttributes(mappedSuperclass); - } - - public void update(XmlEmbeddable embeddable) { - if (getMappingKey() != MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY) { - setMappingKey_(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - } - ((OrmEmbeddable) getMapping()).update(embeddable); - this.updateParentPersistentType(); - this.updatePersistentAttributes(embeddable); - } - - protected void updateParentPersistentType() { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - setParentPersistentType(javaPersistentType == null ? null : javaPersistentType.getParentPersistentType()); - } - - protected void updatePersistentAttributes(AbstractXmlTypeMapping typeMapping) { - ListIterator<OrmPersistentAttribute> ormPersistentAttributes = this.specifiedAttributes(); - if (typeMapping.getAttributes() != null) { - this.updateIds(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateEmbeddedIds(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateBasics(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateVersions(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateManyToOnes(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateOneToManys(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateOneToOnes(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateManyToManys(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateEmbeddeds(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateTransients(typeMapping.getAttributes(), ormPersistentAttributes); - } - while (ormPersistentAttributes.hasNext()) { - this.removeSpecifiedPersistentAttribute_(ormPersistentAttributes.next()); - } - this.updateVirtualPersistentAttributes(); - } - - protected void updateVirtualAttribute(OrmPersistentAttribute ormPersistentAttribute, JavaPersistentAttribute javaAttribute) { - String javaMappingKey = javaAttribute.getMappingKey(); - JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); - if (getMapping().isMetadataComplete()) { - javaMappingKey = javaAttribute.getDefaultMappingKey(); - javaAttributeMapping = javaAttribute.getDefaultMapping(); - } - - if (javaMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlBasic(getMapping(), (JavaBasicMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlEmbedded(getMapping(), (JavaEmbeddedMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlEmbeddedId(getMapping(), (JavaEmbeddedIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlId(getMapping(), (JavaIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlManyToMany(ormPersistentAttribute, (JavaManyToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlManyToOne((JavaManyToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlOneToMany(ormPersistentAttribute, (JavaOneToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlOneToOne((JavaOneToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlTransient((JavaTransientMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlVersion(getMapping(), (JavaVersionMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlNullAttributeMapping(getMapping(), javaAttributeMapping, getMapping().isMetadataComplete())); - } - } - - protected void updateVirtualPersistentAttributes() { - ListIterator<JavaPersistentAttribute> javaAttributes = this.javaPersistentAttributes(); - ListIterator<OrmPersistentAttribute> xmlVirtualAttributes = this.virtualAttributes(); - for (JavaPersistentAttribute javaAttribute : CollectionTools.iterable(javaAttributes)) { - if (specifiedAttributeNamed(javaAttribute.getName()) == null) { - if (xmlVirtualAttributes.hasNext()) { - updateVirtualAttribute(xmlVirtualAttributes.next(), javaAttribute); - } - else { - OrmPersistentAttribute ormPersistentAttribute = createVirtualPersistentAttribute(javaAttribute); - addVirtualPersistentAttribute(ormPersistentAttribute); - } - } - } - - while (xmlVirtualAttributes.hasNext()) { - this.removeVirtualPersistentAttribute(xmlVirtualAttributes.next()); - } - - } - - protected void addVirtualPersistentAttribute(JavaPersistentAttribute javaAttribute) { - addVirtualPersistentAttribute(createVirtualPersistentAttribute(javaAttribute)); - } - - protected OrmPersistentAttribute createVirtualPersistentAttribute(JavaPersistentAttribute javaAttribute) { - String javaMappingKey = javaAttribute.getMappingKey(); - JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); - if (getMapping().isMetadataComplete()) { - javaMappingKey = javaAttribute.getDefaultMappingKey(); - javaAttributeMapping = javaAttribute.getDefaultMapping(); - } - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, javaMappingKey); - - if (javaMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlBasic(getMapping(), (JavaBasicMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlEmbeddedId(getMapping(), (JavaEmbeddedIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlEmbedded(getMapping(), (JavaEmbeddedMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlId(getMapping(), (JavaIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlManyToMany(ormPersistentAttribute, (JavaManyToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlManyToOne((JavaManyToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlOneToMany(ormPersistentAttribute, (JavaOneToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlOneToOne((JavaOneToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlTransient((JavaTransientMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlVersion(getMapping(), (JavaVersionMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlNullAttributeMapping(getMapping(), javaAttributeMapping, getMapping().isMetadataComplete())); - } - return ormPersistentAttribute; - } - - protected void updateIds(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlId> ids = new CloneListIterator<XmlId>(attributes.getIds());//prevent ConcurrentModificiationException - for (XmlId id : CollectionTools.iterable(ids)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(id); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(id); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateEmbeddedIds(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlEmbeddedId> embeddedIds = new CloneListIterator<XmlEmbeddedId>(attributes.getEmbeddedIds());//prevent ConcurrentModificiationException - for (XmlEmbeddedId embeddedId : CollectionTools.iterable(embeddedIds)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(embeddedId); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embeddedId); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateBasics(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlBasic> basics = new CloneListIterator<XmlBasic>(attributes.getBasics());//prevent ConcurrentModificiationException - for (XmlBasic basic : CollectionTools.iterable(basics)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(basic); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(basic); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateVersions(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlVersion> versions = new CloneListIterator<XmlVersion>(attributes.getVersions());//prevent ConcurrentModificiationException - for (XmlVersion version : CollectionTools.iterable(versions)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(version); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(version); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateManyToOnes(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlManyToOne> manyToOnes = new CloneListIterator<XmlManyToOne>(attributes.getManyToOnes());//prevent ConcurrentModificiationException - for (XmlManyToOne manyToOne : CollectionTools.iterable(manyToOnes)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(manyToOne); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToOne); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateOneToManys(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlOneToMany> oneToManys = new CloneListIterator<XmlOneToMany>(attributes.getOneToManys());//prevent ConcurrentModificiationException - for (XmlOneToMany oneToMany : CollectionTools.iterable(oneToManys)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(oneToMany); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToMany); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateOneToOnes(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlOneToOne> oneToOnes = new CloneListIterator<XmlOneToOne>(attributes.getOneToOnes());//prevent ConcurrentModificiationException - for (XmlOneToOne oneToOne : CollectionTools.iterable(oneToOnes)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(oneToOne); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToOne); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateManyToManys(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlManyToMany> manyToManys = new CloneListIterator<XmlManyToMany>(attributes.getManyToManys());//prevent ConcurrentModificiationException - for (XmlManyToMany manyToMany : CollectionTools.iterable(manyToManys)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(manyToMany); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToMany); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateEmbeddeds(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlEmbedded> embeddeds = new CloneListIterator<XmlEmbedded>(attributes.getEmbeddeds());//prevent ConcurrentModificiationException - for (XmlEmbedded embedded : CollectionTools.iterable(embeddeds)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(embedded); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embedded); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateTransients(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlTransient> transients = new CloneListIterator<XmlTransient>(attributes.getTransients());//prevent ConcurrentModificiationException - for (XmlTransient transientResource : CollectionTools.iterable(transients)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(transientResource); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(transientResource); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - public PersistentAttribute resolveAttribute(String attributeName) { - Iterator<OrmPersistentAttribute> attributes = attributesNamed(attributeName); - if (attributes.hasNext()) { - OrmPersistentAttribute attribute = attributes.next(); - return attributes.hasNext() ? null /* more than one */: attribute; - } - else if (getParentPersistentType() != null) { - return getParentPersistentType().resolveAttribute(attributeName); - } - else { - return null; - } - } - - @Override - public OrmPersistentType getOrmPersistentType() { - return this; - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (OrmPersistentAttribute attribute : CollectionTools.iterable(specifiedAttributes())) { - if (attribute.contains(textOffset)) { - return attribute; - } - } - return this; - } - - public boolean contains(int textOffset) { - return this.ormTypeMapping.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.ormTypeMapping.getSelectionTextRange(); - } - - //******************** validation ********************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - try { - getMapping().addToMessages(messages); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - - for (OrmPersistentAttribute persistentAttribute : CollectionTools.iterable(this.attributes())) { - try { - persistentAttribute.addToMessages(messages); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - } - - public TextRange getValidationTextRange() { - return this.ormTypeMapping.getValidationTextRange(); - } - - public void dispose() { - if (getJavaPersistentType() != null) { - getJavaPersistentType().dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumn.java deleted file mode 100644 index 8a664ad8e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; - -public class GenericOrmPrimaryKeyJoinColumn extends AbstractOrmNamedColumn<XmlPrimaryKeyJoinColumn> - implements OrmPrimaryKeyJoinColumn -{ - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected XmlPrimaryKeyJoinColumn primaryKeyJoinColumn; - - public GenericOrmPrimaryKeyJoinColumn(OrmJpaContextNode parent, OrmBaseJoinColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFrom(PrimaryKeyJoinColumn oldPkJoinColumn) { - super.initializeFrom(oldPkJoinColumn); - setSpecifiedReferencedColumnName(oldPkJoinColumn.getSpecifiedReferencedColumnName()); - } - - @Override - protected XmlPrimaryKeyJoinColumn getColumnResource() { - return this.primaryKeyJoinColumn; - } - - @Override - protected void addColumnResource() { - //primaryKeyJoinColumns are part of a collection, the pk-join-column element will be removed/added - //when the XmlPrimaryKeyJoinColumn is removed/added to the XmlEntity collection - } - - @Override - protected void removeColumnResource() { - //primaryKeyJoinColumns are part of a collection, the pk-join-column element will be removed/added - //when the XmlPrimaryKeyJoinColumn is removed/added to the XmlEntity collection - } - - public String getReferencedColumnName() { - return (this.getSpecifiedReferencedColumnName() == null) ? getDefaultReferencedColumnName() : this.getSpecifiedReferencedColumnName(); - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - getColumnResource().setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - protected void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - @Override - public OrmBaseJoinColumn.Owner getOwner() { - return (OrmBaseJoinColumn.Owner) this.owner; - } - - public Column getDbReferencedColumn() { - Table table = this.dbReferencedColumnTable(); - return (table == null) ? null : table.getColumnNamed(this.getReferencedColumnName()); - } - - public Table dbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - @Override - protected String tableName() { - return this.getOwner().getTypeMapping().getTableName(); - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getReferencedColumnNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - @Override - public void initialize(XmlPrimaryKeyJoinColumn column) { - this.primaryKeyJoinColumn = column; - super.initialize(column); - this.specifiedReferencedColumnName = specifiedReferencedColumnName(column); - this.defaultReferencedColumnName = defaultReferencedColumnName(); - } - - @Override - public void update(XmlPrimaryKeyJoinColumn column) { - this.primaryKeyJoinColumn = column; - super.update(column); - this.setSpecifiedReferencedColumnName_(specifiedReferencedColumnName(column)); - this.setDefaultReferencedColumnName(defaultReferencedColumnName()); - } - - protected String specifiedReferencedColumnName(XmlPrimaryKeyJoinColumn column) { - return column == null ? null : column.getReferencedColumnName(); - } - - //TODO not correct when we start supporting primaryKeyJoinColumns in 1-1 mappings - protected String defaultReferencedColumnName() { - return defaultName(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmQueryHint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmQueryHint.java deleted file mode 100644 index 0110bd7884..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmQueryHint.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericOrmQueryHint extends AbstractOrmJpaContextNode implements OrmQueryHint -{ - - protected String name; - - protected String value; - - protected XmlQueryHint queryHint; - - public GenericOrmQueryHint(OrmQuery parent) { - super(parent); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.queryHint.setName(newName); - firePropertyChanged(QueryHint.NAME_PROPERTY, oldName, newName); - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - String oldValue = this.value; - this.value = newValue; - this.queryHint.setValue(newValue); - firePropertyChanged(QueryHint.VALUE_PROPERTY, oldValue, newValue); - } - - public void initialize(XmlQueryHint queryHint) { - this.queryHint = queryHint; - this.name = queryHint.getName(); - this.value = queryHint.getValue(); - } - - public void update(XmlQueryHint queryHint) { - this.queryHint = queryHint; - this.setName(queryHint.getName()); - this.setValue(queryHint.getValue()); - } - - public TextRange getValidationTextRange() { - return this.queryHint.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSecondaryTable.java deleted file mode 100644 index 8ccd9ff4e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSecondaryTable.java +++ /dev/null @@ -1,351 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmSecondaryTable extends AbstractOrmTable - implements OrmSecondaryTable -{ - protected XmlSecondaryTable secondaryTable; - - protected final List<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected OrmPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - public GenericOrmSecondaryTable(OrmEntity parent, XmlSecondaryTable xmlSecondaryTable) { - super(parent); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - initialize(xmlSecondaryTable); - } - - public void initializeFrom(SecondaryTable oldSecondaryTable) { - super.initializeFrom(oldSecondaryTable); - for (PrimaryKeyJoinColumn oldPkJoinColumn : CollectionTools.iterable(oldSecondaryTable.specifiedPrimaryKeyJoinColumns())) { - OrmPrimaryKeyJoinColumn newPkJoinColumn = addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize()); - newPkJoinColumn.initializeFrom(oldPkJoinColumn); - } - } - - @Override - public OrmEntity getParent() { - return (OrmEntity) super.getParent(); - } - - public OrmEntity getOrmEntity() { - return getParent(); - } - - public OrmPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - return this.defaultPrimaryKeyJoinColumn; - } - - protected void setDefaultPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn newPkJoinColumn) { - OrmPrimaryKeyJoinColumn oldPkJoinColumn = this.defaultPrimaryKeyJoinColumn; - this.defaultPrimaryKeyJoinColumn = newPkJoinColumn; - firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldPkJoinColumn, newPkJoinColumn); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumns() : this.defaultPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumnsSize() : this.defaultPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - protected ListIterator<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - if (this.defaultPrimaryKeyJoinColumn != null) { - return new SingleElementListIterator<OrmPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultPrimaryKeyJoinColumnsSize() { - return (this.defaultPrimaryKeyJoinColumn == null) ? 0 : 1; - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public OrmPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn oldDefaultPkJoinColumn = this.getDefaultPrimaryKeyJoinColumn(); - if (oldDefaultPkJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultPrimaryKeyJoinColumn = null; - } - XmlPrimaryKeyJoinColumn xmlPrimaryKeyJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl(); - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = createPrimaryKeyJoinColumn(xmlPrimaryKeyJoinColumn); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - this.secondaryTable.getPrimaryKeyJoinColumns().add(index, xmlPrimaryKeyJoinColumn); - - this.fireItemAdded(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return primaryKeyJoinColumn; - } - - protected OrmBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPrimaryKeyJoinColumn = this.specifiedPrimaryKeyJoinColumns.remove(index); - if (!containsSpecifiedPrimaryKeyJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultPrimaryKeyJoinColumn = createPrimaryKeyJoinColumn(null); - } - this.secondaryTable.getPrimaryKeyJoinColumns().remove(index); - fireItemRemoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (this.defaultPrimaryKeyJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, null, this.defaultPrimaryKeyJoinColumn); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.secondaryTable.getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - public boolean isVirtual() { - return getOrmEntity().containsVirtualSecondaryTable(this); - } - - @Override - protected void addTableResource() { - //secondaryTables are part of a collection, the secondary-table element will be removed/added - //when the XmlSecondaryTable is removed/added to the XmlEntity collection - } - - @Override - protected void removeTableResource() { - //secondaryTables are part of a collection, the secondary-table element will be removed/added - //when the XmlSecondaryTable is removed/added to the XmlEntity collection - } - - @Override - protected XmlSecondaryTable getTableResource() { - return this.secondaryTable; - } - - protected void initialize(XmlSecondaryTable secondaryTable) { - this.secondaryTable = secondaryTable; - super.initialize(secondaryTable); - this.initializeSpecifiedPrimaryKeyJoinColumns(secondaryTable); - this.initializeDefaultPrimaryKeyJoinColumn(); - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns(XmlSecondaryTable secondaryTable) { - for (XmlPrimaryKeyJoinColumn primaryKeyJoinColumn : secondaryTable.getPrimaryKeyJoinColumns()) { - this.specifiedPrimaryKeyJoinColumns.add(createPrimaryKeyJoinColumn(primaryKeyJoinColumn)); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = createPrimaryKeyJoinColumn(null); - } - - public void update(XmlSecondaryTable secondaryTable) { - this.secondaryTable = secondaryTable; - super.update(secondaryTable); - this.updateSpecifiedPrimaryKeyJoinColumns(secondaryTable); - this.updateDefaultPrimaryKeyJoinColumn(); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns(XmlSecondaryTable secondaryTable) { - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<XmlPrimaryKeyJoinColumn> resourcePrimaryKeyJoinColumns = new CloneListIterator<XmlPrimaryKeyJoinColumn>(secondaryTable.getPrimaryKeyJoinColumns());//prevent ConcurrentModificiationException - - while (primaryKeyJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update(resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize(), createPrimaryKeyJoinColumn(resourcePrimaryKeyJoinColumns.next())); - } - } - - protected void updateDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(createPrimaryKeyJoinColumn(null)); - } - else { - this.defaultPrimaryKeyJoinColumn.update(null); - } - } - - protected OrmPrimaryKeyJoinColumn createPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn xmlPrimaryKeyJoinColumn) { - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - ormPrimaryKeyJoinColumn.initialize(xmlPrimaryKeyJoinColumn); - return ormPrimaryKeyJoinColumn; - } - - @Override - //no default name for secondaryTables - protected String defaultName() { - return null; - } - - @Override - protected String defaultCatalog() { - return getEntityMappings().getCatalog(); - } - - @Override - protected String defaultSchema() { - return getEntityMappings().getSchema(); - } - - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addTableMessages(messages); - - for (OrmPrimaryKeyJoinColumn pkJoinColumn : CollectionTools.iterable(this.primaryKeyJoinColumns())) { - pkJoinColumn.addToMessages(messages); - } - } - - protected void addTableMessages(List<IMessage> messages) { - boolean doContinue = connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange()) - ); - doContinue = false; - } - - if (doContinue && ! isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange()) - ); - } - } - - class PrimaryKeyJoinColumnOwner implements OrmBaseJoinColumn.Owner - { - - public TypeMapping getTypeMapping() { - return GenericOrmSecondaryTable.this.getOrmEntity(); - } - - public Table getDbTable(String tableName) { - return GenericOrmSecondaryTable.this.getDbTable(); - } - - public Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericOrmSecondaryTable.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmSecondaryTable.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return getOrmEntity().getParentEntity().getPrimaryKeyColumnName(); - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSequenceGenerator.java deleted file mode 100644 index b42cac0d45..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSequenceGenerator.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; - - -public class GenericOrmSequenceGenerator extends AbstractOrmGenerator<XmlSequenceGenerator> - implements OrmSequenceGenerator -{ - - protected String specifiedSequenceName; - - protected String defaultSequenceName; - - public GenericOrmSequenceGenerator(OrmJpaContextNode parent) { - super(parent); - } - - public String getSequenceName() { - return (this.getSpecifiedSequenceName() == null) ? getDefaultSequenceName() : this.getSpecifiedSequenceName(); - } - - public String getSpecifiedSequenceName() { - return this.specifiedSequenceName; - } - - public void setSpecifiedSequenceName(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - getGeneratorResource().setSequenceName(newSpecifiedSequenceName); - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - protected void setSpecifiedSequenceName_(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - public String getDefaultSequenceName() { - return this.defaultSequenceName; - } - - protected void setDefaultSequenceName(String newDefaultSequenceName) { - String oldSpecifiedSequenceName = this.defaultSequenceName; - this.defaultSequenceName = newDefaultSequenceName; - firePropertyChanged(DEFAULT_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newDefaultSequenceName); - } - - @Override - public void initialize(XmlSequenceGenerator sequenceGenerator) { - super.initialize(sequenceGenerator); - this.specifiedSequenceName = this.specifiedSequenceName(sequenceGenerator); - //TODO default sequence name - } - - @Override - public void update(XmlSequenceGenerator sequenceGenerator) { - super.update(sequenceGenerator); - this.setSpecifiedSequenceName_(this.specifiedSequenceName(sequenceGenerator)); - //TODO default sequence name - } - - protected String specifiedSequenceName(XmlSequenceGenerator generatorResource) { - return generatorResource.getSequenceName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTable.java deleted file mode 100644 index d0c3730735..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTable.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlTable; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericOrmTable extends AbstractOrmTable implements OrmTable -{ - - protected XmlEntity entity; - - public GenericOrmTable(OrmEntity parent) { - super(parent); - } - - public OrmEntity getOrmEntity() { - return (OrmEntity) super.getParent(); - } - - @Override - protected XmlTable getTableResource() { - return this.entity.getTable(); - } - - @Override - protected void removeTableResource() { - this.entity.setTable(null); - } - - @Override - protected void addTableResource() { - this.entity.setTable(OrmFactory.eINSTANCE.createXmlTable()); - - } - - protected JavaTable getJavaTable() { - JavaEntity javaEntity = getOrmEntity().getJavaEntity(); - if (javaEntity != null) { - return javaEntity.getTable(); - } - return null; - } - - public void initialize(XmlEntity entity) { - this.entity = entity; - this.initialize(this.getTableResource()); - } - - public void update(XmlEntity entity) { - this.entity = entity; - this.update(this.getTableResource()); - } - - @Override - protected String defaultName() { - JavaTable javaTable = getJavaTable(); - if (javaTable != null) { - if (!getOrmEntity().isMetadataComplete() && getTableResource() == null && javaTable.getSpecifiedName() != null) { - return javaTable.getSpecifiedName(); - } - } - Entity rootEntity = getOrmEntity().getRootEntity(); - if (rootEntity != getOrmEntity()) { - if (rootEntity.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - return rootEntity.getTable().getName(); - } - } - return getOrmEntity().getName(); - } - - @Override - protected String defaultSchema() { - JavaTable javaTable = getJavaTable(); - if (javaTable != null ) { - if (getOrmEntity().isMetadataComplete() || (getTableResource() != null)) { - return javaTable.getDefaultSchema(); - } - return javaTable.getSchema(); - } - Entity rootEntity = getOrmEntity().getRootEntity(); - if (rootEntity != getOrmEntity()) { - if (rootEntity.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - return rootEntity.getTable().getSchema(); - } - } - return getEntityMappings().getSchema(); - } - - @Override - protected String defaultCatalog() { - JavaTable javaTable = getJavaTable(); - if (javaTable != null) { - if (getOrmEntity().isMetadataComplete() || (getTableResource() != null)) { - return javaTable.getDefaultCatalog(); - } - return javaTable.getCatalog(); - } - Entity rootEntity = getOrmEntity().getRootEntity(); - if (rootEntity != getOrmEntity()) { - if (rootEntity.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - return rootEntity.getTable().getCatalog(); - } - } - return getEntityMappings().getCatalog(); - } - - //*********** Validation ******************************* - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - boolean doContinue = connectionProfileIsActive(); - String schema = this.getSchema(); - - if (doContinue && ! this.hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, this.getName()}, - this, - this.getSchemaTextRange()) - ); - doContinue = false; - } - - if (doContinue && ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange()) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTableGenerator.java deleted file mode 100644 index 0d8dd025bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTableGenerator.java +++ /dev/null @@ -1,410 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public class GenericOrmTableGenerator extends AbstractOrmGenerator<XmlTableGenerator> implements OrmTableGenerator, UniqueConstraint.Owner -{ - protected String specifiedTable; - protected String defaultTable; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - protected String specifiedPkColumnName; - protected String defaultPkColumnName; - - protected String specifiedValueColumnName; - protected String defaultValueColumnName; - - protected String specifiedPkColumnValue; - protected String defaultPkColumnValue; - - protected final List<OrmUniqueConstraint> uniqueConstraints; - - - public GenericOrmTableGenerator(OrmJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<OrmUniqueConstraint>(); - } - - public String getTable() { - return (this.getSpecifiedTable() == null) ? getDefaultTable() : this.getSpecifiedTable(); - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - getGeneratorResource().setTable(newSpecifiedTable); - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - protected void setDefaultTable(String newDefaultTable) { - String oldDefaultTable = this.defaultTable; - this.defaultTable = newDefaultTable; - firePropertyChanged(DEFAULT_TABLE_PROPERTY, oldDefaultTable, newDefaultTable); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - getGeneratorResource().setCatalog(newSpecifiedCatalog); - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(TableGenerator.DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - getGeneratorResource().setSchema(newSpecifiedSchema); - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(TableGenerator.DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getPkColumnName() { - return (this.getSpecifiedPkColumnName() == null) ? getDefaultPkColumnName() : this.getSpecifiedPkColumnName(); - } - - public String getSpecifiedPkColumnName() { - return this.specifiedPkColumnName; - } - - public void setSpecifiedPkColumnName(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - getGeneratorResource().setPkColumnName(newSpecifiedPkColumnName); - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - protected void setSpecifiedPkColumnName_(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - public String getDefaultPkColumnName() { - return this.defaultPkColumnName; - } - - protected void setDefaultPkColumnName(String newDefaultPkColumnName) { - String oldDefaultPkColumnName = this.defaultPkColumnName; - this.defaultPkColumnName = newDefaultPkColumnName; - firePropertyChanged(DEFAULT_PK_COLUMN_NAME_PROPERTY, oldDefaultPkColumnName, newDefaultPkColumnName); - } - - public String getValueColumnName() { - return (this.getSpecifiedValueColumnName() == null) ? getDefaultValueColumnName() : this.getSpecifiedValueColumnName(); - } - - public String getSpecifiedValueColumnName() { - return this.specifiedValueColumnName; - } - - public void setSpecifiedValueColumnName(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - getGeneratorResource().setValueColumnName(newSpecifiedValueColumnName); - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - protected void setSpecifiedValueColumnName_(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - public String getDefaultValueColumnName() { - return this.defaultValueColumnName; - } - - protected void setDefaultValueColumnName(String newDefaultValueColumnName) { - String oldDefaultValueColumnName = this.defaultValueColumnName; - this.defaultValueColumnName = newDefaultValueColumnName; - firePropertyChanged(DEFAULT_VALUE_COLUMN_NAME_PROPERTY, oldDefaultValueColumnName, newDefaultValueColumnName); - } - - public String getPkColumnValue() { - return (this.getSpecifiedPkColumnValue() == null) ? getDefaultPkColumnValue() : this.getSpecifiedPkColumnValue(); - } - - public String getSpecifiedPkColumnValue() { - return this.specifiedPkColumnValue; - } - - public void setSpecifiedPkColumnValue(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - getGeneratorResource().setPkColumnValue(newSpecifiedPkColumnValue); - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - protected void setSpecifiedPkColumnValue_(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - public String getDefaultPkColumnValue() { - return this.defaultPkColumnValue; - } - - public void setDefaultPkColumnValue(String newDefaultPkColumnValue) { - String oldDefaultPkColumnValue = this.defaultPkColumnValue; - this.defaultPkColumnValue = newDefaultPkColumnValue; - firePropertyChanged(DEFAULT_PK_COLUMN_VALUE_PROPERTY, oldDefaultPkColumnValue, newDefaultPkColumnValue); - } - - - // ********** unique constraints ********** - - public ListIterator<OrmUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<OrmUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public OrmUniqueConstraint addUniqueConstraint(int index) { - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - OrmUniqueConstraint uniqueConstraint = buildUniqueConstraint(uniqueConstraintResource); - this.uniqueConstraints.add(index, uniqueConstraint); - getGeneratorResource().getUniqueConstraints().add(index, uniqueConstraintResource); - fireItemAdded(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - protected void addUniqueConstraint(int index, OrmUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - OrmUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - getGeneratorResource().getUniqueConstraints().remove(index); - fireItemRemoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - protected void removeUniqueConstraint_(OrmUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getGeneratorResource().getUniqueConstraints().move(targetIndex, sourceIndex); - fireItemMoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - public Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.getTableNamed(this.getTable()); - } - - public Schema getDbSchema() { - return this.getDataSource().getSchemaNamed(this.getSchema()); - } - - // ********** orm resource model -> context model ********** - - @Override - public void initialize(XmlTableGenerator tableGenerator) { - super.initialize(tableGenerator); - this.specifiedTable = this.specifiedTable(tableGenerator); - this.specifiedCatalog = this.specifiedCatalog(tableGenerator); - this.defaultCatalog = this.defaultCatalog(); - this.specifiedSchema = this.specifiedSchema(tableGenerator); - this.defaultSchema = this.defaultSchema(); - this.specifiedPkColumnName = this.specifiedPkColumnName(tableGenerator); - this.specifiedValueColumnName = this.specifiedValueColumnName(tableGenerator); - this.specifiedPkColumnValue = this.specifiedPkColumnValue(tableGenerator); - this.initializeUniqueContraints(tableGenerator); - } - - protected void initializeUniqueContraints(XmlTableGenerator tableGenerator) { - if (tableGenerator == null) { - return; - } - for (XmlUniqueConstraint uniqueConstraint : tableGenerator.getUniqueConstraints()) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraint)); - } - } - - @Override - public void update(XmlTableGenerator tableGenerator) { - super.update(tableGenerator); - this.setSpecifiedTable_(this.specifiedTable(tableGenerator)); - this.setSpecifiedCatalog_(this.specifiedCatalog(tableGenerator)); - this.setDefaultCatalog(this.defaultCatalog()); - this.setSpecifiedSchema_(this.specifiedSchema(tableGenerator)); - this.setDefaultSchema(this.defaultSchema()); - this.setSpecifiedPkColumnName_(this.specifiedPkColumnName(tableGenerator)); - this.setSpecifiedValueColumnName_(this.specifiedValueColumnName(tableGenerator)); - this.setSpecifiedPkColumnValue_(this.specifiedPkColumnValue(tableGenerator)); - //TODO defaults - this.updateUniqueConstraints(tableGenerator); - } - - protected String specifiedTable(XmlTableGenerator tableGenerator) { - return tableGenerator.getTable(); - } - - protected String specifiedCatalog(XmlTableGenerator tableGenerator) { - return tableGenerator.getCatalog(); - } - - protected String specifiedSchema(XmlTableGenerator tableGenerator) { - return tableGenerator.getSchema(); - } - - protected String specifiedPkColumnName(XmlTableGenerator tableGenerator) { - return tableGenerator.getPkColumnName(); - } - - protected String specifiedValueColumnName(XmlTableGenerator tableGenerator) { - return tableGenerator.getValueColumnName(); - } - - protected String specifiedPkColumnValue(XmlTableGenerator tableGenerator) { - return tableGenerator.getPkColumnValue(); - } - - protected String defaultSchema() { - return getEntityMappings().getSchema(); - } - - protected String defaultCatalog() { - return getEntityMappings().getCatalog(); - } - - protected void updateUniqueConstraints(XmlTableGenerator tableGenerator) { - ListIterator<OrmUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<XmlUniqueConstraint> resourceUniqueConstraints; - if (tableGenerator == null) { - resourceUniqueConstraints = EmptyListIterator.instance(); - } - else { - resourceUniqueConstraints = new CloneListIterator<XmlUniqueConstraint>(tableGenerator.getUniqueConstraints());//prevent ConcurrentModificiationException - } - - while (uniqueConstraints.hasNext()) { - OrmUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected OrmUniqueConstraint buildUniqueConstraint(XmlUniqueConstraint xmlUniqueConstraint) { - return getJpaFactory().buildOrmUniqueConstraint(this, this, xmlUniqueConstraint); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTransientMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTransientMapping.java deleted file mode 100644 index 15aa020230..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTransientMapping.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTransient; - - -public class GenericOrmTransientMapping extends AbstractOrmAttributeMapping<XmlTransient> implements OrmTransientMapping -{ - - public GenericOrmTransientMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmTransientMapping(this); - } - - public int getXmlSequence() { - return 9; - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public XmlTransient addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlTransient transientResource = OrmFactory.eINSTANCE.createXmlTransientImpl(); - getPersistentAttribute().initialize(transientResource); - typeMapping.getAttributes().getTransients().add(transientResource); - return transientResource; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getTransients().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - @Override - public void initialize(XmlTransient transientResource) { - super.initialize(transientResource); - } - - @Override - public void update(XmlTransient transientResource) { - super.update(transientResource); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java deleted file mode 100644 index beeda806a7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class GenericOrmUniqueConstraint extends AbstractOrmJpaContextNode - implements OrmUniqueConstraint -{ - - protected final List<String> columnNames; - - protected XmlUniqueConstraint uniqueConstraint; - - protected UniqueConstraint.Owner owner; - - public GenericOrmUniqueConstraint(OrmJpaContextNode parent, UniqueConstraint.Owner owner, XmlUniqueConstraint uniqueConstraint) { - super(parent); - this.owner = owner; - this.columnNames = new ArrayList<String>(); - this.initialize(uniqueConstraint); - } - - public ListIterator<String> columnNames() { - return new CloneListIterator<String>(this.columnNames); - } - - public int columnNamesSize() { - return this.columnNames.size(); - } - - public void addColumnName(int index, String columnName) { - this.columnNames.add(index, columnName); - this.uniqueConstraint.getColumnNames().add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - protected void addColumnName_(int index, String columnName) { - this.columnNames.add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - public void removeColumnName(String columnName) { - this.removeColumnName(this.columnNames.indexOf(columnName)); - } - - public void removeColumnName(int index) { - String removedColumnName = this.columnNames.remove(index); - this.uniqueConstraint.getColumnNames().remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - protected void removeColumnName_(int index) { - String removedColumnName = this.columnNames.remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - CollectionTools.move(this.columnNames, targetIndex, sourceIndex); - this.uniqueConstraint.getColumnNames().move(targetIndex, sourceIndex); - fireItemMoved(UniqueConstraint.COLUMN_NAMES_LIST, targetIndex, sourceIndex); - } - - public TextRange getValidationTextRange() { - return this.uniqueConstraint.getValidationTextRange(); - } - - protected void initialize(XmlUniqueConstraint uniqueConstraint) { - this.uniqueConstraint = uniqueConstraint; - this.initializeColumnNames(uniqueConstraint); - } - - protected void initializeColumnNames(XmlUniqueConstraint uniqueConstraint) { - ListIterator<String> xmlColumnNames = new CloneListIterator<String>(uniqueConstraint.getColumnNames()); - - for (String annotationColumnName : CollectionTools.iterable(xmlColumnNames)) { - this.columnNames.add(annotationColumnName); - } - } - - public void update(XmlUniqueConstraint uniqueConstraint) { - this.uniqueConstraint = uniqueConstraint; - this.updateColumnNames(uniqueConstraint); - } - - protected void updateColumnNames(XmlUniqueConstraint uniqueConstraint) { - ListIterator<String> xmlColumnNames = new CloneListIterator<String>(uniqueConstraint.getColumnNames()); - - int index = 0; - for (String xmlColumnName : CollectionTools.iterable(xmlColumnNames)) { - if (columnNamesSize() > index) { - if (this.columnNames.get(index) != xmlColumnName) { - addColumnName_(index, xmlColumnName); - } - } - else { - addColumnName_(index, xmlColumnName); - } - index++; - } - - for ( ; index < columnNamesSize(); ) { - removeColumnName_(index); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java deleted file mode 100644 index 488342b8f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmVersionMapping extends AbstractOrmAttributeMapping<XmlVersion> - implements OrmVersionMapping -{ - protected final OrmColumn column; - - protected TemporalType temporal; - - public GenericOrmVersionMapping(OrmPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildOrmColumn(this, this); - } - - public int getXmlSequence() { - return 3; - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmVersionMapping(this); - } - - @Override - public void initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromXmlColumnMapping(oldMapping); - setTemporal(oldMapping.getTemporal()); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public OrmColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getAttributeMapping().setTemporal(TemporalType.toOrmResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public XmlVersion addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlVersion version = OrmFactory.eINSTANCE.createXmlVersionImpl(); - getPersistentAttribute().initialize(version); - typeMapping.getAttributes().getVersions().add(version); - return version; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getVersions().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - @Override - public void initialize(XmlVersion version) { - super.initialize(version); - this.temporal = this.specifiedTemporal(version); - this.column.initialize(version.getColumn()); - } - - @Override - public void update(XmlVersion version) { - super.update(version); - this.setTemporal_(this.specifiedTemporal(version)); - this.column.update(version.getColumn()); - } - - protected TemporalType specifiedTemporal(XmlVersion version) { - return TemporalType.fromOrmResourceModel(version.getTemporal()); - } - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.getAttributeMapping().getColumn(); - } - - public void addColumnResource() { - this.getAttributeMapping().setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.getAttributeMapping().setColumn(null); - } - - // ****************** validation **************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (entityOwned()) { - addColumnMessages(messages); - } - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && this.connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {getPersistentAttribute().getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getPersistentAttribute().getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitDefaults.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitDefaults.java deleted file mode 100644 index 9f10a4dad0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitDefaults.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; - -public class GenericPersistenceUnitDefaults extends AbstractOrmJpaContextNode - implements PersistenceUnitDefaults -{ - protected String specifiedSchema; - - protected String defaultSchema; - - protected String specifiedCatalog; - - protected String defaultCatalog; - - protected AccessType access; - - protected boolean cascadePersist; - - protected XmlEntityMappings entityMappings; - - public GenericPersistenceUnitDefaults(PersistenceUnitMetadata parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.initialize(xmlEntityMappings); - } - - public AccessType getAccess() { - return this.access; - } - - public void setAccess(AccessType newAccess) { - AccessType oldAccess = this.access; - this.access = newAccess; - if (oldAccess != newAccess) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setAccess(AccessType.toXmlResourceModel(newAccess)); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setAccess(AccessType.toXmlResourceModel(newAccess)); - } - } - firePropertyChanged(PersistenceUnitDefaults.ACCESS_PROPERTY, oldAccess, newAccess); - } - - protected void setAccess_(AccessType newAccess) { - AccessType oldAccess = this.access; - this.access = newAccess; - firePropertyChanged(PersistenceUnitDefaults.ACCESS_PROPERTY, oldAccess, newAccess); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? this.getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newCatalog) { - String oldCatalog = this.specifiedCatalog; - this.specifiedCatalog = newCatalog; - if (oldCatalog != newCatalog) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setCatalog(newCatalog); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setCatalog(newCatalog); - } - } - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_CATALOG_PROPERTY, oldCatalog, newCatalog); - } - - protected void setSpecifiedCatalog_(String newCatalog) { - String oldCatalog = this.specifiedCatalog; - this.specifiedCatalog = newCatalog; - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_CATALOG_PROPERTY, oldCatalog, newCatalog); - } - - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? this.getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSchema) { - String oldSchema = this.specifiedSchema; - this.specifiedSchema = newSchema; - if (oldSchema != newSchema) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setSchema(newSchema); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setSchema(newSchema); - } - } - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_SCHEMA_PROPERTY, oldSchema, newSchema); - } - - protected void setSpecifiedSchema_(String newSchema) { - String oldSchema = this.specifiedSchema; - this.specifiedSchema = newSchema; - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_SCHEMA_PROPERTY, oldSchema, newSchema); - } - - public boolean isCascadePersist() { - return this.cascadePersist; - } - - public void setCascadePersist(boolean newCascadePersist) { - boolean oldCascadePersist = this.cascadePersist; - this.cascadePersist = newCascadePersist; - if (oldCascadePersist != newCascadePersist) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setCascadePersist(newCascadePersist); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else if (newCascadePersist) { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setCascadePersist(newCascadePersist); - } - } - firePropertyChanged(PersistenceUnitDefaults.CASCADE_PERSIST_PROPERTY, oldCascadePersist, newCascadePersist); - } - - protected void setCascadePersist_(boolean newCascadePersist) { - boolean oldCascadePersist = this.cascadePersist; - this.cascadePersist = newCascadePersist; - firePropertyChanged(PersistenceUnitDefaults.CASCADE_PERSIST_PROPERTY, oldCascadePersist, newCascadePersist); - } - - protected void initialize(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitDefaults() != null) { - this.access = AccessType.fromXmlResourceModel(this.persistenceUnitDefaults().getAccess()); - this.cascadePersist = this.persistenceUnitDefaults().isCascadePersist(); - this.specifiedCatalog = this.persistenceUnitDefaults().getCatalog(); - this.specifiedSchema = this.persistenceUnitDefaults().getSchema(); - } - } - - - public void update(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitDefaults() != null) { - this.setAccess_(AccessType.fromXmlResourceModel(this.persistenceUnitDefaults().getAccess())); - this.setCascadePersist_(this.persistenceUnitDefaults().isCascadePersist()); - this.setSpecifiedCatalog_(this.persistenceUnitDefaults().getCatalog()); - this.setSpecifiedSchema_(this.persistenceUnitDefaults().getSchema()); - } - else { - this.setAccess_(null); - this.setCascadePersist_(false); - this.setSpecifiedCatalog_(null); - this.setSpecifiedSchema_(null); - } - this.setDefaultSchema(this.projectDefaultSchemaName()); - this.setDefaultCatalog(this.projectDefaultCatalogName()); - } - - protected String projectDefaultSchemaName() { - Schema projectDefaultSchema = getJpaProject().getDefaultSchema(); - return projectDefaultSchema == null ? null : projectDefaultSchema.getName(); - } - - protected String projectDefaultCatalogName() { - Catalog catalog = this.getJpaProject().getDataSource().getDefaultCatalog(); - return (catalog == null) ? null : catalog.getName(); - } - - protected XmlPersistenceUnitDefaults persistenceUnitDefaults() { - if (persistenceUnitMetadata() != null) { - return persistenceUnitMetadata().getPersistenceUnitDefaults(); - } - return null; - } - - protected XmlPersistenceUnitMetadata persistenceUnitMetadata() { - return this.entityMappings.getPersistenceUnitMetadata(); - } - - public TextRange getValidationTextRange() { - if (persistenceUnitDefaults() != null) { - return persistenceUnitDefaults().getValidationTextRange(); - } - return this.entityMappings.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitMetadata.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitMetadata.java deleted file mode 100644 index c970efe73a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitMetadata.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericPersistenceUnitMetadata extends AbstractOrmJpaContextNode - implements PersistenceUnitMetadata -{ - protected boolean xmlMappingMetadataComplete; - - protected final PersistenceUnitDefaults persistenceUnitDefaults; - - protected XmlEntityMappings entityMappings; - - public GenericPersistenceUnitMetadata(EntityMappings parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.persistenceUnitDefaults = getJpaFactory().buildPersistenceUnitDefaults(this, xmlEntityMappings); - this.initialize(xmlEntityMappings); - } - - public boolean isXmlMappingMetadataComplete() { - return this.xmlMappingMetadataComplete; - } - - public void setXmlMappingMetadataComplete(boolean newXmlMappingMetadataComplete) { - boolean oldXmlMappingMetadataComplete = this.xmlMappingMetadataComplete; - this.xmlMappingMetadataComplete = newXmlMappingMetadataComplete; - if (oldXmlMappingMetadataComplete != newXmlMappingMetadataComplete) { - if (this.persistenceUnitMetadata() != null) { - this.persistenceUnitMetadata().setXmlMappingMetadataComplete(newXmlMappingMetadataComplete); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - else if (newXmlMappingMetadataComplete) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - this.persistenceUnitMetadata().setXmlMappingMetadataComplete(newXmlMappingMetadataComplete); - } - } - firePropertyChanged(PersistenceUnitMetadata.XML_MAPPING_METADATA_COMPLETE_PROPERTY, oldXmlMappingMetadataComplete, newXmlMappingMetadataComplete); - } - - protected void setXmlMappingMetadataComplete_(boolean newXmlMappingMetadataComplete) { - boolean oldXmlMappingMetadataComplete = this.xmlMappingMetadataComplete; - this.xmlMappingMetadataComplete = newXmlMappingMetadataComplete; - firePropertyChanged(PersistenceUnitMetadata.XML_MAPPING_METADATA_COMPLETE_PROPERTY, oldXmlMappingMetadataComplete, newXmlMappingMetadataComplete); - } - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - return this.persistenceUnitDefaults; - } - - protected void initialize(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitMetadata() != null) { - this.xmlMappingMetadataComplete = this.persistenceUnitMetadata().isXmlMappingMetadataComplete(); - } - } - - public void update(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitMetadata() != null) { - setXmlMappingMetadataComplete_(this.persistenceUnitMetadata().isXmlMappingMetadataComplete()); - } - else { - setXmlMappingMetadataComplete_(false); - } - this.persistenceUnitDefaults.update(entityMappings); - } - - protected XmlPersistenceUnitMetadata persistenceUnitMetadata() { - return this.entityMappings.getPersistenceUnitMetadata(); - } - - public TextRange getValidationTextRange() { - if (persistenceUnitMetadata() != null) { - return persistenceUnitMetadata().getValidationTextRange(); - } - return this.entityMappings.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java deleted file mode 100644 index e5dd187a11..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmBasicMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmBasicMappingProvider INSTANCE = new OrmBasicMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmBasicMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public OrmBasicMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmBasicMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmCascade.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmCascade.java deleted file mode 100644 index 22a3f1e316..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmCascade.java +++ /dev/null @@ -1,246 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; - - -public class OrmCascade extends AbstractOrmJpaContextNode implements Cascade, OrmJpaContextNode -{ - - protected boolean all; - - protected boolean persist; - - protected boolean merge; - - protected boolean remove; - - protected boolean refresh; - - - protected XmlRelationshipMapping relationshipMapping; - - protected OrmCascade(OrmRelationshipMapping parent) { - super(parent); - } - - public void initializeFrom(Cascade oldCascade) { - setAll(oldCascade.isAll()); - setPersist(oldCascade.isPersist()); - setMerge(oldCascade.isMerge()); - setRemove(oldCascade.isRemove()); - setRefresh(oldCascade.isRefresh()); - } - - public boolean isAll() { - return this.all; - } - - public void setAll(boolean newAll) { - boolean oldAll = this.all; - this.all = newAll; - if (oldAll != newAll) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeAll(newAll); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newAll != false) { - addCascadeResource(); - getCascadeResource().setCascadeAll(newAll); - } - } - firePropertyChanged(ALL_PROPERTY, oldAll, newAll); - } - - protected void setAll_(boolean newAll) { - boolean oldAll = this.all; - this.all = newAll; - firePropertyChanged(ALL_PROPERTY, oldAll, newAll); - } - - public boolean isPersist() { - return this.persist; - } - - public void setPersist(boolean newPersist) { - boolean oldPersist = this.persist; - this.persist = newPersist; - if (oldPersist != newPersist) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadePersist(newPersist); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newPersist != false) { - addCascadeResource(); - getCascadeResource().setCascadePersist(newPersist); - } - } - firePropertyChanged(PERSIST_PROPERTY, oldPersist, newPersist); - } - - protected void setPersist_(boolean newPersist) { - boolean oldPersist = this.persist; - this.persist = newPersist; - firePropertyChanged(PERSIST_PROPERTY, oldPersist, newPersist); - } - - - public boolean isMerge() { - return this.merge; - } - - public void setMerge(boolean newMerge) { - boolean oldMerge = this.merge; - this.merge = newMerge; - if (oldMerge != newMerge) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeMerge(newMerge); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newMerge != false) { - addCascadeResource(); - getCascadeResource().setCascadeMerge(newMerge); - } - } - firePropertyChanged(MERGE_PROPERTY, oldMerge, newMerge); - } - - protected void setMerge_(boolean newMerge) { - boolean oldMerge = this.merge; - this.merge = newMerge; - firePropertyChanged(MERGE_PROPERTY, oldMerge, newMerge); - } - - public boolean isRemove() { - return this.remove; - } - - public void setRemove(boolean newRemove) { - boolean oldRemove = this.remove; - this.remove = newRemove; - if (oldRemove != newRemove) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeRemove(newRemove); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newRemove != false) { - addCascadeResource(); - getCascadeResource().setCascadeRemove(newRemove); - } - } - firePropertyChanged(REMOVE_PROPERTY, oldRemove, newRemove); - } - - protected void setRemove_(boolean newRemove) { - boolean oldRemove = this.remove; - this.remove = newRemove; - firePropertyChanged(REMOVE_PROPERTY, oldRemove, newRemove); - } - - public boolean isRefresh() { - return this.refresh; - } - - public void setRefresh(boolean newRefresh) { - boolean oldRefresh = this.refresh; - this.refresh = newRefresh; - if (oldRefresh != newRefresh) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeRefresh(newRefresh); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newRefresh != false) { - addCascadeResource(); - getCascadeResource().setCascadeRefresh(newRefresh); - } - } - firePropertyChanged(REFRESH_PROPERTY, oldRefresh, newRefresh); - } - - protected void setRefresh_(boolean newRefresh) { - boolean oldRefresh = this.refresh; - this.refresh = newRefresh; - firePropertyChanged(REFRESH_PROPERTY, oldRefresh, newRefresh); - } - - - protected CascadeType getCascadeResource() { - return this.relationshipMapping.getCascade(); - } - - protected void removeCascadeResource() { - this.relationshipMapping.setCascade(null); - } - - protected void addCascadeResource() { - this.relationshipMapping.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - } - - public void initialize(XmlRelationshipMapping relationshipMapping) { - this.relationshipMapping = relationshipMapping; - CascadeType cascade = getCascadeResource(); - this.all = this.all(cascade); - this.persist = this.persist(cascade); - this.merge = this.merge(cascade); - this.remove = this.remove(cascade); - this.refresh = this.refresh(cascade); - } - - public void update(XmlRelationshipMapping relationshipMapping) { - this.relationshipMapping = relationshipMapping; - CascadeType cascade = getCascadeResource(); - this.setAll_(this.all(cascade)); - this.setPersist_(this.persist(cascade)); - this.setMerge_(this.merge(cascade)); - this.setRemove_(this.remove(cascade)); - this.setRefresh_(this.refresh(cascade)); - } - - protected boolean all(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeAll(); - } - - protected boolean persist(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadePersist(); - } - - protected boolean merge(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeMerge(); - } - - protected boolean remove(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeRemove(); - } - - protected boolean refresh(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeRefresh(); - } - - public TextRange getValidationTextRange() { - return this.getCascadeResource().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java deleted file mode 100644 index 9dc3cae9cb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; - - -public class OrmEmbeddableProvider implements OrmTypeMappingProvider -{ - - public OrmEmbeddable buildTypeMapping(JpaFactory factory, OrmPersistentType parent) { - return factory.buildOrmEmbeddable(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java deleted file mode 100644 index 2a3162affd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmEmbeddedIdMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmEmbeddedIdMappingProvider INSTANCE = new OrmEmbeddedIdMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmEmbeddedIdMappingProvider() { - super(); - } - - public OrmEmbeddedIdMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmEmbeddedIdMapping(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java deleted file mode 100644 index dcf069189a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmEmbeddedMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmEmbeddedMappingProvider INSTANCE = new OrmEmbeddedMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmEmbeddedMappingProvider() { - super(); - } - - public OrmEmbeddedMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmEmbeddedMapping(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java deleted file mode 100644 index 10c69c5333..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; - - -public class OrmEntityProvider implements OrmTypeMappingProvider -{ - public OrmEntity buildTypeMapping(JpaFactory factory, OrmPersistentType parent) { - return factory.buildOrmEntity(parent); - } - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java deleted file mode 100644 index 302c800245..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmIdMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmIdMappingProvider INSTANCE = new OrmIdMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmIdMappingProvider() { - super(); - } - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public OrmIdMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmIdMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java deleted file mode 100644 index 5dbfd0c6bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmManyToManyMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmManyToManyMappingProvider INSTANCE = new OrmManyToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmManyToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public OrmManyToManyMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmManyToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java deleted file mode 100644 index bf5acb53c0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmManyToOneMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmManyToOneMappingProvider INSTANCE = new OrmManyToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmManyToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public OrmManyToOneMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmManyToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java deleted file mode 100644 index 18e970fd24..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; - - -public class OrmMappedSuperclassProvider implements OrmTypeMappingProvider -{ - public OrmMappedSuperclass buildTypeMapping(JpaFactory factory, OrmPersistentType parent) { - return factory.buildOrmMappedSuperclass(parent); - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java deleted file mode 100644 index 1ea615a7ee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmNullAttributeMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmNullAttributeMappingProvider INSTANCE = new OrmNullAttributeMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmNullAttributeMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - } - - public OrmAttributeMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmNullAttributeMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java deleted file mode 100644 index 0ec7805f0b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmOneToManyMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmOneToManyMappingProvider INSTANCE = new OrmOneToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmOneToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public OrmOneToManyMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmOneToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java deleted file mode 100644 index 6b600fa27e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmOneToOneMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmOneToOneMappingProvider INSTANCE = new OrmOneToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmOneToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public OrmOneToOneMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmOneToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java deleted file mode 100644 index c3197b3dcd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; - -public class OrmTransientMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmTransientMappingProvider INSTANCE = new OrmTransientMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmTransientMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public OrmTransientMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmTransientMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java deleted file mode 100644 index 50ac6eaa2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; - -public class OrmVersionMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmVersionMappingProvider INSTANCE = new OrmVersionMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmVersionMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public OrmVersionMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmVersionMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java deleted file mode 100644 index 3153f0fcfc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.List; -import org.eclipse.core.resources.IResource; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class OrmXmlImpl extends AbstractOrmJpaContextNode - implements OrmXml -{ - protected OrmResource ormResource; - - protected EntityMappings entityMappings; - - - public OrmXmlImpl(MappingFileRef parent, OrmResource ormResource) { - super(parent); - this.initialize(ormResource); - } - - @Override - public MappingFileRef getParent() { - return (MappingFileRef) super.getParent(); - } - - public String getId() { - // isn't actually displayed, so needs no details page - return null; - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - if (getEntityMappings() != null) { - return getEntityMappings().getPersistentType(fullyQualifiedTypeName); - } - return null; - } - - @Override - public IResource getResource() { - return ormResource.getFile(); - } - - // **************** persistence ******************************************** - - @Override - public EntityMappings getEntityMappings() { - return this.entityMappings; - } - - protected void setEntityMappings(EntityMappings newEntityMappings) { - EntityMappings oldEntityMappings = this.entityMappings; - this.entityMappings = newEntityMappings; - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, oldEntityMappings, newEntityMappings); - } - - public EntityMappings addEntityMappings() { - if (this.entityMappings != null) { - throw new IllegalStateException(); - } - - XmlEntityMappings xmlEntityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - this.entityMappings = buildEntityMappings(xmlEntityMappings); - this.ormResource.getContents().add(xmlEntityMappings); - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, null, this.entityMappings); - return this.entityMappings; - } - - public void removeEntityMappings() { - if (this.entityMappings == null) { - throw new IllegalStateException(); - } - this.entityMappings.dispose(); - EntityMappings oldEntityMappings = this.entityMappings; - - this.entityMappings = null; - XmlEntityMappings xmlEntityMappings = this.ormResource.getEntityMappings(); //TODO helper removeEntityMappings method on ormResource?? - this.ormResource.getContents().remove(xmlEntityMappings); - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, oldEntityMappings, null); - } - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - if (getEntityMappings() != null) { - return getEntityMappings().getPersistenceUnitDefaults(); - } - return null; - } - // **************** updating *********************************************** - - protected void initialize(OrmResource ormResource) { - this.ormResource = ormResource; - if (ormResource.getEntityMappings() != null) { - this.entityMappings = buildEntityMappings(ormResource.getEntityMappings()); - } - } - - public void update(OrmResource ormResource) { - this.ormResource = ormResource; - if (ormResource.getEntityMappings() != null) { - if (this.entityMappings != null) { - this.entityMappings.update(ormResource.getEntityMappings()); - } - else { - setEntityMappings(buildEntityMappings(ormResource.getEntityMappings())); - } - } - else { - if (getEntityMappings() != null) { - getEntityMappings().dispose(); - } - setEntityMappings(null); - } - } - - protected EntityMappings buildEntityMappings(XmlEntityMappings xmlEntityMappings) { - return getJpaFactory().buildEntityMappings(this, xmlEntityMappings); - } - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int textOffset) { - if (entityMappings.containsOffset(textOffset)) { - return entityMappings.getStructureNode(textOffset); - } - return this; - } - - // never actually selected - public TextRange getSelectionTextRange() { - return TextRange.Empty.instance(); - } - - public TextRange getValidationTextRange() { - return TextRange.Empty.instance(); - } - - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - if (getEntityMappings() != null) { - getEntityMappings().addToMessages(messages); - } - } - - public void dispose() { - if (getEntityMappings() != null) { - getEntityMappings().dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java deleted file mode 100644 index b5f5c117d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.CascadeType; - -public class VirtualCascadeType extends AbstractJpaEObject implements CascadeType -{ - Cascade javaCascade; - - protected boolean metadataComplete; - - public VirtualCascadeType(Cascade javaCascade, boolean metadataComplete) { - super(); - this.javaCascade = javaCascade; - this.metadataComplete = metadataComplete; - } - - public void update(Cascade javaCascade) { - this.javaCascade = javaCascade; - } - - public boolean isCascadeAll() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isAll(); - } - - public void setCascadeAll(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadeMerge() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isMerge(); - } - - public void setCascadeMerge(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadePersist() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isPersist(); - } - - public void setCascadePersist(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadeRefresh() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isRefresh(); - } - - public void setCascadeRefresh(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadeRemove() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isRemove(); - } - - public void setCascadeRemove(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java deleted file mode 100644 index f354af95fe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaMultiRelationshipMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.MapKey; - -public class VirtualMapKey extends AbstractJpaEObject implements MapKey -{ - JavaMultiRelationshipMapping javaMultiRelationshipMapping; - - protected boolean metadataComplete; - - public VirtualMapKey(JavaMultiRelationshipMapping javaMultiRelationshipMapping, boolean metadataComplete) { - super(); - this.javaMultiRelationshipMapping = javaMultiRelationshipMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.javaMultiRelationshipMapping.getMapKey(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaMultiRelationshipMapping javaMultiRelationshipMapping) { - this.javaMultiRelationshipMapping = javaMultiRelationshipMapping; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java deleted file mode 100644 index 7618d713d0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; - -public class VirtualXmlAttributeOverride extends AbstractJpaEObject implements XmlAttributeOverride -{ - - protected String name; - - protected final XmlColumn column; - - protected VirtualXmlAttributeOverride(String name, XmlColumn xmlColumn) { - super(); - this.name = name; - this.column = xmlColumn; - } - - public String getName() { - return this.name; - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java deleted file mode 100644 index 9ac0ae3828..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualBasic is an implementation of Basic used when there is - * no tag in the orm.xml and an underlying javaBasicMapping exists. - */ -public class VirtualXmlBasic extends AbstractJpaEObject implements XmlBasic -{ - JavaBasicMapping javaBasicMapping; - - protected final VirtualXmlColumn column; - - protected boolean metadataComplete; - - public VirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping, boolean metadataComplete) { - super(); - this.javaBasicMapping = javaBasicMapping; - this.metadataComplete = metadataComplete; - this.column = new VirtualXmlColumn(ormTypeMapping, javaBasicMapping.getColumn(), metadataComplete); - } - - public String getName() { - return this.javaBasicMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaBasicMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaBasicMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getOptional() { - if (this.metadataComplete) { - return this.javaBasicMapping.getDefaultOptional(); - } - return this.javaBasicMapping.getOptional(); - } - - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isLob() { - if (this.metadataComplete) { - return false; - } - return this.javaBasicMapping.isLob(); - } - - public void setLob(boolean newLob) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TemporalType getTemporal() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(this.javaBasicMapping.getTemporal()); - } - - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EnumType getEnumerated() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.EnumType.toOrmResourceModel(this.javaBasicMapping.getDefaultEnumerated()); - } - return org.eclipse.jpt.core.context.EnumType.toOrmResourceModel(this.javaBasicMapping.getEnumerated()); - } - - public void setEnumerated(EnumType newEnumerated) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public void update(JavaBasicMapping javaBasicMapping) { - this.javaBasicMapping = javaBasicMapping; - this.column.update(javaBasicMapping.getColumn()); - } - - public TextRange getNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java deleted file mode 100644 index 7c8dbce6ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * A virtual column is used to represent the XmlColumn resource object - * within a virtual mapping. A virtual mapping is one which is not specified - * in the orm.xml file, but is implied from the underlying java. Virtual column - * is not used when the mapping is specified in the orm.xml, but the column tag does not exist. - * - * A virtual column delegates to the underlying java column for its state. The metadataComplete - * flag determines whether it will get specified or default information from the java column - * - */ -public class VirtualXmlColumn extends AbstractJpaEObject implements XmlColumn -{ - - protected Column column; - - protected boolean metadataComplete; - - protected OrmTypeMapping ormTypeMapping; - - - protected VirtualXmlColumn(OrmTypeMapping ormTypeMapping, Column column, boolean metadataComplete) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.column = column; - this.metadataComplete = metadataComplete; - } - - public String getColumnDefinition() { - if (this.metadataComplete) { - return null; - } - return this.column.getColumnDefinition(); - } - - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getInsertable() { - if (this.metadataComplete) { - return this.column.getDefaultInsertable(); - } - return this.column.getInsertable(); - } - - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getLength() { - if (this.metadataComplete) { - return this.column.getDefaultLength(); - } - return this.column.getLength(); - } - - public void setLength(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return this.column.getDefaultName(); - } - return this.column.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getNullable() { - if (this.metadataComplete) { - return this.column.getDefaultNullable(); - } - return this.column.getNullable(); - } - - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getPrecision() { - if (this.metadataComplete) { - return this.column.getDefaultPrecision(); - } - return this.column.getPrecision(); - } - - public void setPrecision(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getScale() { - if (this.metadataComplete) { - return this.column.getDefaultScale(); - } - return this.column.getScale(); - } - - public void setScale(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTable() { - if (!this.metadataComplete) { - if (this.column.getSpecifiedTable() != null) { - return this.column.getSpecifiedTable(); - } - } - return this.ormTypeMapping.getTableName(); - } - - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUnique() { - if (this.metadataComplete) { - return this.column.getDefaultUnique(); - } - return this.column.getUnique(); - } - - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUpdatable() { - if (this.metadataComplete) { - return this.column.getDefaultUpdatable(); - } - return this.column.getUpdatable(); - } - - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(Column column) { - this.column = column; - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getTableTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java deleted file mode 100644 index 2e144ba5b1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualEmbedded is an implementation of Embedded used when there is - * no tag in the orm.xml and an underlying javaEmbeddedMapping exists. - */ -public class VirtualXmlEmbedded extends AbstractJpaEObject implements XmlEmbedded -{ - JavaEmbeddedMapping javaEmbeddedMapping; - - protected boolean metadataComplete; - - protected OrmTypeMapping ormTypeMapping; - - public VirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping, boolean metadataComplete) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaEmbeddedMapping = javaEmbeddedMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaEmbeddedMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.metadataComplete) { - javaAttributeOverrides = this.javaEmbeddedMapping.attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaEmbeddedMapping.virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn(), this.metadataComplete); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } - - public void update(JavaEmbeddedMapping javaEmbeddedMapping) { - this.javaEmbeddedMapping = javaEmbeddedMapping; - } - - public TextRange getNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java deleted file mode 100644 index 8b1a6f6dc7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualEmbeddedId is an implementation of EmbeddedId used when there is - * no tag in the orm.xml and an underlying javaEmbeddedIdMapping exists. - */ -public class VirtualXmlEmbeddedId extends AbstractJpaEObject implements XmlEmbeddedId -{ - JavaEmbeddedIdMapping javaEmbeddedIdMapping; - - protected boolean metadataComplete; - - protected OrmTypeMapping ormTypeMapping; - - public VirtualXmlEmbeddedId(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping, boolean metadataComplete) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaEmbeddedIdMapping = javaEmbeddedIdMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaEmbeddedIdMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED_ID__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.metadataComplete) { - javaAttributeOverrides = this.javaEmbeddedIdMapping.attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaEmbeddedIdMapping.virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn(), this.metadataComplete); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } - - public void update(JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - this.javaEmbeddedIdMapping = javaEmbeddedIdMapping; - } - - public TextRange getNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java deleted file mode 100644 index ba814d42c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.GenerationType; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlGeneratedValue extends AbstractJpaEObject implements XmlGeneratedValue -{ - JavaGeneratedValue javaGeneratedValue; - - protected boolean metadataComplete; - - - public VirtualXmlGeneratedValue(JavaGeneratedValue javaGeneratedValue, boolean metadataComplete) { - super(); - this.javaGeneratedValue = javaGeneratedValue; - this.metadataComplete = metadataComplete; - } - - - public String getGenerator() { - if (this.metadataComplete) { - return null; - } - return this.javaGeneratedValue.getGenerator(); - } - - public GenerationType getStrategy() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.GenerationType.toOrmResourceModel(this.javaGeneratedValue.getStrategy()); - } - - public void setGenerator(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void setStrategy(GenerationType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TextRange getGeneratorTextRange() { - return null; - } - - public void update(JavaGeneratedValue javaGeneratedValue) { - this.javaGeneratedValue = javaGeneratedValue; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java deleted file mode 100644 index 308ce8b5e7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualId is an implementation of Id used when there is - * no tag in the orm.xml and an underlying javaIdMapping exists. - */ -public class VirtualXmlId extends AbstractJpaEObject implements XmlId -{ - JavaIdMapping javaIdMapping; - - protected boolean metadataComplete; - - protected final VirtualXmlColumn column; - - protected final VirtualXmlGeneratedValue virtualGeneratedValue; - - protected final VirtualXmlTableGenerator virtualTableGenerator; - - protected final VirtualXmlSequenceGenerator virtualSequenceGenerator; - - - - public VirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping, boolean metadataComplete) { - super(); - this.javaIdMapping = javaIdMapping; - this.metadataComplete = metadataComplete; - this.column = new VirtualXmlColumn(ormTypeMapping, javaIdMapping.getColumn(), metadataComplete); - this.virtualGeneratedValue = new VirtualXmlGeneratedValue(javaIdMapping.getGeneratedValue(), metadataComplete); - this.virtualTableGenerator = new VirtualXmlTableGenerator(javaIdMapping.getTableGenerator(), metadataComplete); - this.virtualSequenceGenerator = new VirtualXmlSequenceGenerator(javaIdMapping.getSequenceGenerator(), metadataComplete); - } - - public String getName() { - return this.javaIdMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TemporalType getTemporal() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(this.javaIdMapping.getTemporal()); - } - - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public XmlGeneratedValue getGeneratedValue() { - if (this.metadataComplete) { - return null; - } - if (this.javaIdMapping.getGeneratedValue() != null) { - return this.virtualGeneratedValue; - } - return null; - } - - public void setGeneratedValue(XmlGeneratedValue value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlSequenceGenerator getSequenceGenerator() { - if (this.metadataComplete) { - return null; - } - if (this.javaIdMapping.getSequenceGenerator() != null) { - return this.virtualSequenceGenerator; - } - return null; - } - - public void setSequenceGenerator(XmlSequenceGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlTableGenerator getTableGenerator() { - if (this.metadataComplete) { - return null; - } - if (this.javaIdMapping.getTableGenerator() != null) { - return this.virtualTableGenerator; - } - return null; - } - - public void setTableGenerator(XmlTableGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public void update(JavaIdMapping javaIdMapping) { - this.javaIdMapping = javaIdMapping; - this.column.update(javaIdMapping.getColumn()); - this.virtualGeneratedValue.update(javaIdMapping.getGeneratedValue()); - this.virtualTableGenerator.update(javaIdMapping.getTableGenerator()); - this.virtualSequenceGenerator.update(javaIdMapping.getSequenceGenerator()); - } - - public TextRange getNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java deleted file mode 100644 index 60505b096e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlJoinColumn extends AbstractJpaEObject implements XmlJoinColumn -{ - protected JavaJoinColumn javaJoinColumn; - - protected boolean metadataComplete; - - protected VirtualXmlJoinColumn(JavaJoinColumn javaJoinColumn, boolean metadataComplete) { - super(); - this.javaJoinColumn = javaJoinColumn; - this.metadataComplete = metadataComplete; - } - - public String getColumnDefinition() { - if (this.metadataComplete) { - return null; - } - return this.javaJoinColumn.getColumnDefinition(); - } - - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getInsertable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultInsertable(); - } - return this.javaJoinColumn.getInsertable(); - } - - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultName(); - } - return this.javaJoinColumn.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getReferencedColumnName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultReferencedColumnName(); - } - return this.javaJoinColumn.getReferencedColumnName(); - } - - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getNullable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultNullable(); - } - return this.javaJoinColumn.getNullable(); - } - - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultTable(); - } - return this.javaJoinColumn.getTable(); - } - - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUnique() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultUnique(); - } - return this.javaJoinColumn.getUnique(); - } - - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUpdatable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultUpdatable(); - } - return this.javaJoinColumn.getUpdatable(); - } - - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaJoinColumn javaJoinColumn) { - this.javaJoinColumn = javaJoinColumn; - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getTableTextRange() { - return null; - } - - public TextRange getReferencedColumnNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java deleted file mode 100644 index 9275d0a514..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlJoinTable extends AbstractJpaEObject implements XmlJoinTable -{ - - protected JavaJoinTable javaJoinTable; - - protected boolean metadataComplete; - - protected OrmPersistentAttribute ormPersistentAttribute; - - - protected VirtualXmlJoinTable(OrmPersistentAttribute ormPersistentAttribute, JavaJoinTable javaJoinTable, boolean metadataComplete) { - super(); - this.ormPersistentAttribute = ormPersistentAttribute; - this.javaJoinTable = javaJoinTable; - this.metadataComplete = metadataComplete; - } - - protected OrmRelationshipMapping ormRelationshipMapping() { - return (OrmRelationshipMapping) this.ormPersistentAttribute.getMapping(); - } - - public String getName() { - if (!this.metadataComplete) { - if (this.javaJoinTable.getSpecifiedName() != null) { - return this.javaJoinTable.getSpecifiedName(); - } - } - return MappingTools.buildJoinTableDefaultName(ormRelationshipMapping()); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getCatalog() { - if (this.metadataComplete) { - return this.javaJoinTable.getDefaultCatalog(); - } - return this.javaJoinTable.getCatalog(); - } - - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getSchema() { - if (this.metadataComplete) { - return this.javaJoinTable.getDefaultSchema(); - } - return this.javaJoinTable.getSchema(); - } - - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__JOIN_COLUMNS); - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaJoinTable.specifiedJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - public EList<XmlJoinColumn> getInverseJoinColumns() { - EList<XmlJoinColumn> inverseJoinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__INVERSE_JOIN_COLUMNS); - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaJoinTable.specifiedInverseJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - inverseJoinColumns.add(xmlJoinColumn); - } - - return inverseJoinColumns; - } - - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_JOIN_TABLE__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.javaJoinTable.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, this.metadataComplete); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - public void update(JavaJoinTable javaJoinTable) { - this.javaJoinTable = javaJoinTable; - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getCatalogTextRange() { - return null; - } - - public TextRange getSchemaTextRange() { - return null; - } - - public boolean isSpecified() { - return this.javaJoinTable.isSpecified(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java deleted file mode 100644 index 3983e29227..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualManyToMany is an implementation of ManyToMany used when there is - * no tag in the orm.xml and an underlying javaManyToManyMapping exists. - */ -public class VirtualXmlManyToMany extends AbstractJpaEObject implements XmlManyToMany -{ - JavaManyToManyMapping javaManyToManyMapping; - - protected boolean metadataComplete; - - protected final VirtualXmlJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - //TODO joinColumns not yet supported in the context model -// protected EList<JoinColumn> virtualJoinColumns; - - public VirtualXmlManyToMany(OrmPersistentAttribute ormPersistentAttribute, JavaManyToManyMapping javaManyToManyMapping, boolean metadataComplete) { - super(); - this.javaManyToManyMapping = javaManyToManyMapping; - this.metadataComplete = metadataComplete; -// this.initializeJoinColumns(javaOneToManyMapping); - this.virtualCascadeType = new VirtualCascadeType(javaManyToManyMapping.getCascade(), this.metadataComplete); - this.virtualJoinTable = new VirtualXmlJoinTable(ormPersistentAttribute, javaManyToManyMapping.getJoinTable(), metadataComplete); - this.mapKey = new VirtualMapKey(javaManyToManyMapping, metadataComplete); - } - -// protected void initializeJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// this.virtualJoinColumns = new BasicEList<JoinColumn>(); -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumns.next(), this.metadataComplete)); -// } -// } - - public String getName() { - return this.javaManyToManyMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToManyMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToManyMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - return null; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - return this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaManyToManyMapping.getDefaultTargetEntity(); - } - return this.javaManyToManyMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getMappedBy() { - if (this.metadataComplete) { - return null; - } - return this.javaManyToManyMapping.getMappedBy(); - } - - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public MapKey getMapKey() { - return this.mapKey; - } - - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getOrderBy() { - if (this.metadataComplete) { - return null; - } - return this.javaManyToManyMapping.getOrderBy(); - } - - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaManyToManyMapping javaManyToManyMapping) { - this.javaManyToManyMapping = javaManyToManyMapping; - this.virtualCascadeType.update(javaManyToManyMapping.getCascade()); - this.virtualJoinTable.update(javaManyToManyMapping.getJoinTable()); -// this.updateJoinColumns(javaOneToManyMapping); - } - -// protected void updateJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// ListIterator<JoinColumn> virtualJoinColumns = this.virtualJoinColumns.listIterator(); -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// IJavaJoinColumn javaJoinColumn = javaJoinColumns.next(); -// if (virtualJoinColumns.hasNext()) { -// VirtualJoinColumn virtualJoinColumn = (VirtualJoinColumn) virtualJoinColumns.next(); -// virtualJoinColumn.update(javaJoinColumn); -// } -// else { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumn, this.metadataComplete)); -// } -// } -// -// while(virtualJoinColumns.hasNext()) { -// this.virtualJoinColumns.remove(virtualJoinColumns.next()); -// } -// } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getMappedByTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java deleted file mode 100644 index 349ec76333..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualManyToOne is an implementation of ManyToOne used when there is - * no tag in the orm.xml and an underlying javaManyToOneMapping exists. - */ -public class VirtualXmlManyToOne extends AbstractJpaEObject implements XmlManyToOne -{ - JavaManyToOneMapping javaManyToOneMapping; - - protected boolean metadataComplete; - -// protected VirtualJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - public VirtualXmlManyToOne(JavaManyToOneMapping javaManyToOneMapping, boolean metadataComplete) { - super(); - this.javaManyToOneMapping = javaManyToOneMapping; - this.metadataComplete = metadataComplete; - this.virtualCascadeType = new VirtualCascadeType(javaManyToOneMapping.getCascade(), this.metadataComplete); - } - - public String getName() { - return this.javaManyToOneMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToOneMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToOneMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getOptional() { - if (this.metadataComplete) { - return this.javaManyToOneMapping.getDefaultOptional(); - } - return this.javaManyToOneMapping.getOptional(); - } - - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__JOIN_COLUMNS); - //TODO here i'm using joinColumns() while VirtualXmlJoinTable uses specifiedJoinColumns()??? - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaManyToOneMapping.joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - //TODO we don't yet support JoinTable in the context model for many-to-one mappings - return null;//this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaManyToOneMapping.getDefaultTargetEntity(); - } - return this.javaManyToOneMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaManyToOneMapping javaManyToOneMapping) { - this.javaManyToOneMapping = javaManyToOneMapping; - this.virtualCascadeType.update(javaManyToOneMapping.getCascade()); - } - - public TextRange getNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java deleted file mode 100644 index 7f63835d9a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualVersion is an implementation of Version used when there is - * no tag in the orm.xml and an underlying javaVersionMapping exists. - */ -public class VirtualXmlNullAttributeMapping extends AbstractJpaEObject implements XmlNullAttributeMapping -{ - JavaAttributeMapping javaAttributeMapping; - - protected boolean metadataComplete; - - public VirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, boolean metadataComplete) { - super(); - this.javaAttributeMapping = javaAttributeMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaAttributeMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaAttributeMapping javaAttributeMapping) { - this.javaAttributeMapping = javaAttributeMapping; - } - - public TextRange getNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java deleted file mode 100644 index 53469b4aba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualOneToMany is an implementation of OneToMany used when there is - * no tag in the orm.xml and an underlying javaOneToManyMapping exists. - */ -public class VirtualXmlOneToMany extends AbstractJpaEObject implements XmlOneToMany -{ - JavaOneToManyMapping javaOneToManyMapping; - - protected boolean metadataComplete; - - protected final VirtualXmlJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - //TODO joinColumns not yet supported in the context model -// protected EList<JoinColumn> virtualJoinColumns; - - public VirtualXmlOneToMany(OrmPersistentAttribute ormPersistentAttribute, JavaOneToManyMapping javaOneToManyMapping, boolean metadataComplete) { - super(); - this.javaOneToManyMapping = javaOneToManyMapping; - this.metadataComplete = metadataComplete; -// this.initializeJoinColumns(javaOneToManyMapping); - this.virtualCascadeType = new VirtualCascadeType(javaOneToManyMapping.getCascade(), this.metadataComplete); - this.virtualJoinTable = new VirtualXmlJoinTable(ormPersistentAttribute, javaOneToManyMapping.getJoinTable(), metadataComplete); - this.mapKey = new VirtualMapKey(javaOneToManyMapping, metadataComplete); - } - -// protected void initializeJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// this.virtualJoinColumns = new BasicEList<JoinColumn>(); -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumns.next(), this.metadataComplete)); -// } -// } - - public String getName() { - return this.javaOneToManyMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToManyMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToManyMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - return null; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - return this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaOneToManyMapping.getDefaultTargetEntity(); - } - return this.javaOneToManyMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getMappedBy() { - if (this.metadataComplete) { - return null; - } - return this.javaOneToManyMapping.getMappedBy(); - } - - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public MapKey getMapKey() { - return this.mapKey; - } - - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getOrderBy() { - if (this.metadataComplete) { - return null; - } - return this.javaOneToManyMapping.getOrderBy(); - } - - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaOneToManyMapping javaOneToManyMapping) { - this.javaOneToManyMapping = javaOneToManyMapping; - this.virtualCascadeType.update(javaOneToManyMapping.getCascade()); - this.virtualJoinTable.update(javaOneToManyMapping.getJoinTable()); -// this.updateJoinColumns(javaOneToManyMapping); - } - -// protected void updateJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// ListIterator<JoinColumn> virtualJoinColumns = this.virtualJoinColumns.listIterator(); -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// IJavaJoinColumn javaJoinColumn = javaJoinColumns.next(); -// if (virtualJoinColumns.hasNext()) { -// VirtualJoinColumn virtualJoinColumn = (VirtualJoinColumn) virtualJoinColumns.next(); -// virtualJoinColumn.update(javaJoinColumn); -// } -// else { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumn, this.metadataComplete)); -// } -// } -// -// while(virtualJoinColumns.hasNext()) { -// this.virtualJoinColumns.remove(virtualJoinColumns.next()); -// } -// } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getMappedByTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java deleted file mode 100644 index b771b2b2c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualOneToOne is an implementation of OneToOne used when there is - * no tag in the orm.xml and an underlying javaOneToOneMapping exists. - */ -public class VirtualXmlOneToOne extends AbstractJpaEObject implements XmlOneToOne -{ - JavaOneToOneMapping javaOneToOneMapping; - - protected boolean metadataComplete; - -// protected VirtualJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - public VirtualXmlOneToOne(JavaOneToOneMapping javaOneToOneMapping, boolean metadataComplete) { - super(); - this.javaOneToOneMapping = javaOneToOneMapping; - this.metadataComplete = metadataComplete; - this.virtualCascadeType = new VirtualCascadeType(javaOneToOneMapping.getCascade(), this.metadataComplete); - } - - public String getName() { - return this.javaOneToOneMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToOneMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToOneMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getOptional() { - if (this.metadataComplete) { - return this.javaOneToOneMapping.getDefaultOptional(); - } - return this.javaOneToOneMapping.getOptional(); - } - - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - //TODO need to check metadataComplete here - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_ONE_TO_ONE__JOIN_COLUMNS); - //TODO here i'm using joinColumns() while VirtualXmlJoinTable uses specifiedJoinColumns()??? - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaOneToOneMapping.joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - //TODO we don't yet support JoinTable in the context model for many-to-one mappings - return null;//this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaOneToOneMapping.getDefaultTargetEntity(); - } - return this.javaOneToOneMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getMappedBy() { - if (this.metadataComplete) { - return null; - } - return this.javaOneToOneMapping.getMappedBy(); - } - - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> joinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_ONE_TO_ONE__PRIMARY_KEY_JOIN_COLUMNS); - if (!this.metadataComplete) { - for (JavaPrimaryKeyJoinColumn joinColumn : CollectionTools.iterable(this.javaOneToOneMapping.primaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(joinColumn/*, this.metadataComplete*/); - joinColumns.add(xmlJoinColumn); - } - } - return joinColumns; - } - - public void update(JavaOneToOneMapping javaOneToOneMapping) { - this.javaOneToOneMapping = javaOneToOneMapping; - this.virtualCascadeType.update(javaOneToOneMapping.getCascade()); - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getMappedByTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java deleted file mode 100644 index 9465b2ec3c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * A virtual primary key join column is used to represent the XmlPrimaryKeyJoinColumn resource object - * within a virtual secondary table. A virtual secondary table is one which is not specified - * in the orm.xml file, but is implied from the underlying java. Virtual pk join column - * is not used when the secondary table is specified in the orm.xml. - * - * A virtual pk join column delegates to the underlying java pk join column for its state. - */ -public class VirtualXmlPrimaryKeyJoinColumn extends AbstractJpaEObject implements XmlPrimaryKeyJoinColumn -{ - - protected JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn; - - - protected VirtualXmlPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn) { - super(); - this.javaPrimaryKeyJoinColumn = javaPrimaryKeyJoinColumn; - } - - public String getName() { - return this.javaPrimaryKeyJoinColumn.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getColumnDefinition() { - return this.javaPrimaryKeyJoinColumn.getColumnDefinition(); - } - - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getReferencedColumnName() { - return this.javaPrimaryKeyJoinColumn.getReferencedColumnName(); - } - - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getReferencedColumnNameTextRange() { - return null; - } - - public void update(JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn) { - this.javaPrimaryKeyJoinColumn = javaPrimaryKeyJoinColumn; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java deleted file mode 100644 index 5d5a009a51..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * A virtual secondary table is used to represent the XmlSecondaryTable resource object. - * A virtual secondary table is one which is not specified in the orm.xml file, - * but is implied from the underlying java. Virtual secondary table - * is not used when the secondary table is specified in the orm.xml. - * - * A virtual secondary table delegates to the underlying java secondary table for its state. - */ -public class VirtualXmlSecondaryTable extends AbstractJpaEObject implements XmlSecondaryTable -{ - - protected JavaSecondaryTable javaSecondaryTable; - - protected VirtualXmlSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - super(); - this.javaSecondaryTable = javaSecondaryTable; - } - - public String getName() { - return this.javaSecondaryTable.getSpecifiedName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getCatalog() { - return this.javaSecondaryTable.getSpecifiedCatalog(); - } - - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getSchema() { - return this.javaSecondaryTable.getSpecifiedSchema(); - } - - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - //VirtualXmlSecondaryTable is rebuilt everytime, so rebuilding the joinColumns list as well - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> primaryKeyJoinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_SECONDARY_TABLE_IMPL__PRIMARY_KEY_JOIN_COLUMNS); - - for (JavaPrimaryKeyJoinColumn pkJoinColumn : CollectionTools.iterable(this.javaSecondaryTable.specifiedPrimaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlPkJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(pkJoinColumn); - primaryKeyJoinColumns.add(xmlPkJoinColumn); - } - - return primaryKeyJoinColumns; - } - - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_SECONDARY_TABLE__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.javaSecondaryTable.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, true); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getCatalogTextRange() { - return null; - } - - public TextRange getSchemaTextRange() { - return null; - } - - public void update(JavaSecondaryTable javaSecondaryTable) { - this.javaSecondaryTable = javaSecondaryTable; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java deleted file mode 100644 index c6ab23dc26..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlSequenceGenerator extends AbstractJpaEObject implements XmlSequenceGenerator -{ - JavaSequenceGenerator javaSequenceGenerator; - - protected boolean metadataComplete; - - - public VirtualXmlSequenceGenerator(JavaSequenceGenerator javaSequenceGenerator, boolean metadataComplete) { - super(); - this.javaSequenceGenerator = javaSequenceGenerator; - this.metadataComplete = metadataComplete; - } - - public String getSequenceName() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getSequenceName(); - } - - public void setSequenceName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getAllocationSize(); - } - - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getInitialValue(); - } - - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaSequenceGenerator javaSequenceGenerator) { - this.javaSequenceGenerator = javaSequenceGenerator; - } - - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - public boolean isVirtual() { - return true; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java deleted file mode 100644 index 332f6cae25..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlTableGenerator extends AbstractJpaEObject implements XmlTableGenerator -{ - JavaTableGenerator javaTableGenerator; - - protected boolean metadataComplete; - - - public VirtualXmlTableGenerator(JavaTableGenerator javaTableGenerator, boolean metadataComplete) { - super(); - this.javaTableGenerator = javaTableGenerator; - this.metadataComplete = metadataComplete; - } - - public String getCatalog() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getCatalog(); - } - - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getPkColumnName() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getPkColumnName(); - } - - public void setPkColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getPkColumnValue() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getPkColumnValue(); - } - - public void setPkColumnValue(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getSchema() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getSchema(); - } - - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTable() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getTable(); - } - - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getValueColumnName() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getValueColumnName(); - } - - public void setValueColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getAllocationSize(); - } - - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getInitialValue(); - } - - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_TABLE_GENERATOR__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.javaTableGenerator.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, this.metadataComplete); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - public void update(JavaTableGenerator javaTableGenerator) { - this.javaTableGenerator = javaTableGenerator; - } - - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - public boolean isVirtual() { - return true; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java deleted file mode 100644 index 8e80ccc9e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualTransient is an implementation of Transient used when there is - * no tag in the orm.xml and an underlying javaTransientMapping exists. - */ -public class VirtualXmlTransient extends AbstractJpaEObject implements XmlTransient -{ - JavaTransientMapping javaTransientMapping; - - protected boolean metadataComplete; - - public VirtualXmlTransient(JavaTransientMapping javaTransientMapping, boolean metadataComplete) { - super(); - this.javaTransientMapping = javaTransientMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaTransientMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaTransientMapping javaTransientMapping) { - this.javaTransientMapping = javaTransientMapping; - } - - - public TextRange getNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java deleted file mode 100644 index 4f106eace8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EDataTypeEList; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlUniqueConstraint extends AbstractJpaEObject implements XmlUniqueConstraint -{ - protected JavaUniqueConstraint javaUniqueConstraint; - - protected boolean metadataComplete; - - protected VirtualXmlUniqueConstraint(JavaUniqueConstraint javaUniqueConstraint, boolean metadataComplete) { - super(); - this.javaUniqueConstraint = javaUniqueConstraint; - this.metadataComplete = metadataComplete; - } - - public EList<String> getColumnNames() { - EList<String> columnNames = new EDataTypeEList<String>(String.class, this, OrmPackage.XML_UNIQUE_CONSTRAINT_IMPL__COLUMN_NAMES); - - for (String columnName : CollectionTools.iterable(this.javaUniqueConstraint.columnNames())) { - columnNames.add(columnName); - } - return columnNames; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java deleted file mode 100644 index c402e38e7e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualVersion is an implementation of Version used when there is - * no tag in the orm.xml and an underlying javaVersionMapping exists. - */ -public class VirtualXmlVersion extends AbstractJpaEObject implements XmlVersion -{ - JavaVersionMapping javaVersionMapping; - - protected final VirtualXmlColumn column; - - protected boolean metadataComplete; - - public VirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping, boolean metadataComplete) { - super(); - this.javaVersionMapping = javaVersionMapping; - this.metadataComplete = metadataComplete; - this.column = new VirtualXmlColumn(ormTypeMapping, javaVersionMapping.getColumn(), metadataComplete); - } - - public String getName() { - return this.javaVersionMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TemporalType getTemporal() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(this.javaVersionMapping.getTemporal()); - } - - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaVersionMapping javaVersionMapping) { - this.javaVersionMapping = javaVersionMapping; - this.column.update(javaVersionMapping.getColumn()); - } - - - public TextRange getNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceJpaContextNode.java deleted file mode 100644 index 0896417bdd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceJpaContextNode.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.List; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.persistence.PersistenceJpaContextNode; -import org.eclipse.jpt.core.internal.context.AbstractJpaContextNode; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public abstract class AbstractPersistenceJpaContextNode extends AbstractJpaContextNode implements PersistenceJpaContextNode -{ - // ********** constructor ********** - - protected AbstractPersistenceJpaContextNode(JpaContextNode parent) { - super(parent); - } - - // ********** validation ********** - - /** - * All subclass implementations {@link #addToMessages(List<IMessage>)} - * should be preceded by a "super" call to this method - */ - public void addToMessages(List<IMessage> messages) { - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java deleted file mode 100644 index 47698fe05a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.List; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -/** - * This is the context model object which corresponds to the - * persistence resource model object XmlJavaClassRef. - * XmlJavaClassRef corresponds to the class tag in the persistence.xml - */ -public class GenericClassRef extends AbstractPersistenceJpaContextNode - implements ClassRef -{ - //this is null for the implied classRef case - protected XmlJavaClassRef xmlJavaClassRef; - - protected String className; - - protected JavaPersistentType javaPersistentType; - - - public GenericClassRef(PersistenceUnit parent, XmlJavaClassRef classRef) { - super(parent); - initialize(classRef); - } - - public GenericClassRef(PersistenceUnit parent, String className) { - super(parent); - initialize(className); - } - - public String getId() { - return PersistenceStructureNodes.CLASS_REF_ID; - } - - public boolean isFor(String fullyQualifiedTypeName) { - if (getClassName() == null) { - return false; - } - return getClassName().equals(fullyQualifiedTypeName); - } - - public boolean isVirtual() { - return this.xmlJavaClassRef == null; - } - - - // **************** class name ********************************************* - - public String getClassName() { - return this.className; - } - - public void setClassName(String newClassName) { - String oldClassName = this.className; - this.className = newClassName; - this.xmlJavaClassRef.setJavaClass(newClassName); - firePropertyChanged(CLASS_NAME_PROPERTY, oldClassName, newClassName); - } - - protected void setClassName_(String newClassName) { - String oldClassName = this.className; - this.className = newClassName; - firePropertyChanged(CLASS_NAME_PROPERTY, oldClassName, newClassName); - } - - - // **************** java persistent type *********************************** - - public JavaPersistentType getJavaPersistentType() { - return this.javaPersistentType; - } - - protected void setJavaPersistentType(JavaPersistentType newJavaPersistentType) { - JavaPersistentType oldJavaPersistentType = this.javaPersistentType; - this.javaPersistentType = newJavaPersistentType; - firePropertyChanged(ClassRef.JAVA_PERSISTENT_TYPE_PROPERTY, oldJavaPersistentType, newJavaPersistentType); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlJavaClassRef classRef) { - this.xmlJavaClassRef = classRef; - this.className = classRef.getJavaClass(); - initializeJavaPersistentType(); - } - - protected void initialize(String className) { - this.className = className; - initializeJavaPersistentType(); - } - - protected void initializeJavaPersistentType() { - JavaResourcePersistentType jrpt = getJpaProject().getJavaResourcePersistentType(getClassName()); - if (jrpt != null) { - this.javaPersistentType = buildJavaPersistentType(jrpt); - } - } - - public void update(XmlJavaClassRef classRef) { - this.xmlJavaClassRef = classRef; - setClassName_(classRef.getJavaClass()); - updateJavaPersistentType(); - } - - public void update(String className) { - this.xmlJavaClassRef = null; - setClassName_(className); - updateJavaPersistentType(); - } - - protected void updateJavaPersistentType() { - JavaResourcePersistentType jrpt = getJpaProject().getJavaResourcePersistentType(getClassName()); - if (jrpt == null) { - if (getJavaPersistentType() != null) { - getJavaPersistentType().dispose(); - } - setJavaPersistentType(null); - } - else { - if (getJavaPersistentType() != null) { - getJavaPersistentType().update(jrpt); - } - else { - setJavaPersistentType(buildJavaPersistentType(jrpt)); - } - } - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourcePersistentType jrpt) { - return getJpaFactory().buildJavaPersistentType(this, jrpt); - } - - - // ************************************************************************* - - // ************************* validation ********************************* - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addUnspecifiedClassMessage(messages); - addUnresolvedClassMessage(messages); - addJavaPersistentTypeMessages(messages); - } - - protected void addUnspecifiedClassMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getClassName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_CLASS, - this, getValidationTextRange()) - ); - } - } - - protected void addUnresolvedClassMessage(List<IMessage> messages) { - if (! StringTools.stringIsEmpty(getClassName()) && getJavaPersistentType() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_CLASS, - new String[] {getClassName()}, - this, - this.getValidationTextRange()) - ); - } - } - - protected void addJavaPersistentTypeMessages(List<IMessage> messages) { - if (getJavaPersistentType() != null) { //class might not resolve to a java type - MappingFileRef mappingFileRef = getMappingFileContaining(getClassName()); - if (mappingFileRef != null) { - messages.add(DefaultJpaValidationMessages.buildMessage( - IMessage.LOW_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_REDUNDANT_CLASS, - new String[] { this.getClassName(), mappingFileRef.getFileName()}, - this, - this.getValidationTextRange())); - } - else { - try { - //bug 190062 - only add java validation messages if this class is not listed in a mapping file - getJavaPersistentType().addToMessages(messages); - } catch (Throwable t) { - JptCorePlugin.log(t); - } - } - } - } - - //possibly move this and make it API on PersistenceUnit - /** - * Return the mapping file that contains a persistent type for the given - * type name. Return null if no mapping file contains the persistent type. - */ - protected MappingFileRef getMappingFileContaining(String fullyQualifiedTypeName) { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(getPersistenceUnit().mappingFileRefs())) { - if (mappingFileRef.getPersistentType(fullyQualifiedTypeName) != null) { - return mappingFileRef; - } - } - return null; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public boolean containsOffset(int textOffset) { - if (isVirtual()) { - return false; - } - return this.xmlJavaClassRef.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - if (isVirtual()) { - return null; - } - return this.xmlJavaClassRef.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return null; - } - return this.xmlJavaClassRef.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(getClassName()); - } - - public void dispose() { - if (getJavaPersistentType() != null) { - getJavaPersistentType().dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java deleted file mode 100644 index c53de37e86..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.List; -import org.eclipse.core.resources.IProject; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericMappingFileRef extends AbstractPersistenceJpaContextNode - implements MappingFileRef -{ - //this is null for the implied mappingFileRef case - protected XmlMappingFileRef xmlMappingFileRef; - - protected String fileName; - - protected OrmXml ormXml; - - public GenericMappingFileRef(PersistenceUnit parent, XmlMappingFileRef mappingFileRef) { - super(parent); - this.initialize(mappingFileRef); - } - - public String getId() { - return PersistenceStructureNodes.MAPPING_FILE_REF_ID; - } - - - public boolean isVirtual() { - return xmlMappingFileRef == null; - } - - - // **************** file name ********************************************** - - public String getFileName() { - return this.fileName; - } - - public void setFileName(String newFileName) { - this.xmlMappingFileRef.setFileName(newFileName); - setFileName_(newFileName); - } - - protected void setFileName_(String newFileName) { - String oldFileName = this.fileName; - this.fileName = newFileName; - firePropertyChanged(FILE_NAME_PROPERTY, oldFileName, newFileName); - } - - public OrmXml getOrmXml() { - return this.ormXml; - } - - protected void setOrmXml(OrmXml newOrmXml) { - OrmXml oldOrmXml = this.ormXml; - this.ormXml = newOrmXml; - firePropertyChanged(ORM_XML_PROPERTY, oldOrmXml, newOrmXml); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlMappingFileRef mappingFileRef) { - this.xmlMappingFileRef = mappingFileRef; - initializeFileName(); - initializeOrmXml(); - } - - protected void initializeFileName() { - if (isVirtual()) { - fileName = JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH; - } - else { - fileName = xmlMappingFileRef.getFileName(); - } - } - - protected void initializeOrmXml() { - if (fileName != null) { - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForRead(getJpaProject().getProject()); - OrmResource ormResource = oae.getResource(fileName); - - if (ormResource != null && ormResource.exists()) { - ormXml = buildOrmXml(ormResource); - } - oae.dispose(); - } - } - - public void update(XmlMappingFileRef mappingFileRef) { - xmlMappingFileRef = mappingFileRef; - updateFileName(); - updateOrmXml(); - } - - protected void updateFileName() { - if (isVirtual()) { - setFileName_(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - } - else { - setFileName_(xmlMappingFileRef.getFileName()); - } - } - - protected void updateOrmXml() { - if (fileName != null) { - IProject project = getJpaProject().getProject(); - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForRead(project); - OrmResource ormResource = oae.getResource(JptCorePlugin.getOrmXmlDeploymentURI(project, fileName)); - if (ormResource != null && ormResource.exists()) { - if (ormXml != null) { - ormXml.update(ormResource); - } - else { - setOrmXml(buildOrmXml(ormResource)); - } - } - else { - if (getOrmXml() != null) { - getOrmXml().dispose(); - } - setOrmXml(null); - } - oae.dispose(); - } - else { - if (getOrmXml() != null) { - getOrmXml().dispose(); - } - setOrmXml(null); - } - } - - protected OrmXml buildOrmXml(OrmResource ormResource) { - return getJpaFactory().buildOrmXml(this, ormResource); - } - - - // ************************************************************************* - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - if (getOrmXml() != null) { - return getOrmXml().getPersistenceUnitDefaults(); - } - return null; - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - if (getOrmXml() != null) { - return getOrmXml().getPersistentType(fullyQualifiedTypeName); - } - return null; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public boolean containsOffset(int textOffset) { - if (this.xmlMappingFileRef == null) { - return false; - } - return this.xmlMappingFileRef.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - if (isVirtual()) { - return null; - } - return this.xmlMappingFileRef.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return getPersistenceUnit().getValidationTextRange(); - } - return this.xmlMappingFileRef.getValidationTextRange(); - } - - //**************** Validation ************************* - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - this.addUnspecifiedMappingFileMessage(messages); - this.addUnresolvedMappingFileMessage(messages); - this.addInvalidMappingFileContentMessage(messages); - if (getOrmXml() != null) { - getOrmXml().addToMessages(messages); - } - } - - - protected void addUnspecifiedMappingFileMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getFileName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE, - this, - getValidationTextRange()) - ); - } - } - - protected void addUnresolvedMappingFileMessage(List<IMessage> messages) { - if (!StringTools.stringIsEmpty(getFileName()) && getOrmXml() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE, - new String[] {getFileName()}, - this, - getValidationTextRange()) - ); - } - } - - protected void addInvalidMappingFileContentMessage(List<IMessage> messages) { - if (getOrmXml() != null - && getOrmXml().getEntityMappings() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_INVALID_MAPPING_FILE, - new String[] {getFileName()}, - this, - getValidationTextRange()) - ); - } - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getFileName()); - } - - public void dispose() { - if (getOrmXml() != null) { - getOrmXml().dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java deleted file mode 100644 index 9aa1a83e05..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericPersistence extends AbstractPersistenceJpaContextNode - implements Persistence -{ - protected XmlPersistence xmlPersistence; - - // the implementation here is a single persistence unit, although the API - // is for a list. we will want to support multiple persistence units soon. - protected PersistenceUnit persistenceUnit; - - public GenericPersistence(PersistenceXml parent, XmlPersistence xmlPersistence) { - super(parent); - this.initialize(xmlPersistence); - } - - public String getId() { - return PersistenceStructureNodes.PERSISTENCE_ID; - } - - - // **************** persistence units ************************************** - - public ListIterator<PersistenceUnit> persistenceUnits() { - if (persistenceUnit == null) { - return EmptyListIterator.instance(); - } - else { - return new SingleElementListIterator<PersistenceUnit>(persistenceUnit); - } - } - - public int persistenceUnitsSize() { - return (persistenceUnit == null) ? 0 : 1; - } - - public PersistenceUnit addPersistenceUnit() { - return addPersistenceUnit(persistenceUnitsSize()); - } - - public PersistenceUnit addPersistenceUnit(int index) { - if (index > 0 || persistenceUnit != null) { - throw new IllegalStateException("This implementation does not support multiple persistence units."); - } - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - persistenceUnit = createPersistenceUnit(xmlPersistenceUnit); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - fireItemAdded(PERSISTENCE_UNITS_LIST, index, persistenceUnit); - return persistenceUnit; - } - - public void removePersistenceUnit(PersistenceUnit persistenceUnit) { - removePersistenceUnit(0); - } - - public void removePersistenceUnit(int index) { - if (index > 0 ) { - throw new IllegalArgumentException(new Integer(index).toString()); - } - PersistenceUnit oldPersistenceUnit = persistenceUnit; - persistenceUnit.dispose(); - persistenceUnit = null; - xmlPersistence.getPersistenceUnits().remove(index); - fireItemRemoved(PERSISTENCE_UNITS_LIST, index, oldPersistenceUnit); - } - - protected void addPersistenceUnit_(PersistenceUnit newPersistenceUnit) { - persistenceUnit = newPersistenceUnit; - fireItemAdded(PERSISTENCE_UNITS_LIST, 0, persistenceUnit); - } - - protected void removePersistenceUnit_(PersistenceUnit oldPersistenceUnit) { - persistenceUnit.dispose(); - persistenceUnit = null; - fireItemRemoved(PERSISTENCE_UNITS_LIST, 0, oldPersistenceUnit); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlPersistence xmlPersistence) { - this.xmlPersistence = xmlPersistence; - initializePersistenceUnits(xmlPersistence); - } - - protected void initializePersistenceUnits(XmlPersistence persistence) { - // only adding one here, until we support multiple persistence units - if (xmlPersistence.getPersistenceUnits().size() > 0) { - persistenceUnit = createPersistenceUnit(persistence.getPersistenceUnits().get(0)); - } - } - - public void update(XmlPersistence persistence) { - this.xmlPersistence = persistence; - getJpaFile(this.xmlPersistence.getResource().getResourceModel()).addRootStructureNode(this, this); - XmlPersistenceUnit xmlPersistenceUnit = null; - if (persistence.getPersistenceUnits().size() > 0) { - xmlPersistenceUnit = persistence.getPersistenceUnits().get(0); - } - - if (persistenceUnit != null) { - if (xmlPersistenceUnit != null) { - persistenceUnit.update(xmlPersistenceUnit); - } - else { - removePersistenceUnit_(persistenceUnit); - } - } - else { - if (xmlPersistenceUnit != null) { - addPersistenceUnit_(createPersistenceUnit(xmlPersistenceUnit)); - } - } - } - - protected PersistenceUnit createPersistenceUnit(XmlPersistenceUnit xmlPersistenceUnit) { - return getJpaFactory().buildPersistenceUnit(this, xmlPersistenceUnit); - } - - - // ************************************************************************* - - @Override - public PersistenceUnit getPersistenceUnit() { - throw new UnsupportedOperationException("No PersistenceUnit in this context"); - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (PersistenceUnit persistenceUnit : CollectionTools.iterable(persistenceUnits())) { - if (persistenceUnit.containsOffset(textOffset)) { - return persistenceUnit.getStructureNode(textOffset); - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - if (xmlPersistence == null) { - return false; - } - return xmlPersistence.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return xmlPersistence.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return xmlPersistence.getValidationTextRange(); - } - - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - //persistence root validation - addNoPersistenceUnitMessage(messages); - - // note to neil (or whomever): extraneous persistence units can be - // accessed through the XmlPersistence resource object - addMultiplePersistenceUnitMessage(messages); - - - //persistence unit validation - if (persistenceUnit != null) { - persistenceUnit.addToMessages(messages); - } - } - - protected void addNoPersistenceUnitMessage(List<IMessage> messages) { - if (persistenceUnit == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_NO_PERSISTENCE_UNIT, - this, - this.getValidationTextRange()) - ); - } - } - - protected void addMultiplePersistenceUnitMessage(List<IMessage> messages) { - if (xmlPersistence.getPersistenceUnits().size() > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS, - this, - this.getValidationTextRange()) - ); - } - } - - public void dispose() { - getJpaFile(this.xmlPersistence.getResource().getResourceModel()).removeRootStructureNode(this); - for (PersistenceUnit persistenceUnit : CollectionTools.iterable(persistenceUnits())) { - persistenceUnit.dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceUnit.java deleted file mode 100644 index 6a4b38c013..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceUnit.java +++ /dev/null @@ -1,1245 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.Set; - -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.XmlProperties; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyCompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericPersistenceUnit extends AbstractPersistenceJpaContextNode - implements PersistenceUnit -{ - protected XmlPersistenceUnit xmlPersistenceUnit; - - protected String name; - - protected PersistenceUnitTransactionType specifiedTransactionType; - - protected PersistenceUnitTransactionType defaultTransactionType; - - protected String description; - - protected String provider; - - protected String jtaDataSource; - - protected String nonJtaDataSource; - - protected final List<MappingFileRef> specifiedMappingFileRefs; - - protected MappingFileRef impliedMappingFileRef; - - protected final List<ClassRef> specifiedClassRefs; - - protected final List<ClassRef> impliedClassRefs; - - protected Boolean specifiedExcludeUnlistedClasses; - - protected boolean defaultExcludeUnlistedClasses = false; - - protected final List<Property> properties; - - /* global generator definitions, defined elsewhere in model */ - protected final List<Generator> generators; - - /* global query definitions, defined elsewhere in model */ - protected final List<Query> queries; - - - protected String defaultSchema; - protected String defaultCatalog; - protected AccessType defaultAccess; - protected boolean defaultCascadePersist; - - public GenericPersistenceUnit(Persistence parent, XmlPersistenceUnit persistenceUnit) { - super(parent); - this.specifiedMappingFileRefs = new ArrayList<MappingFileRef>(); - this.specifiedClassRefs = new ArrayList<ClassRef>(); - this.impliedClassRefs = new ArrayList<ClassRef>(); - this.properties = new ArrayList<Property>(); - this.generators = new ArrayList<Generator>(); - this.queries = new ArrayList<Query>(); - this.initialize(persistenceUnit); - } - - @Override - protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) { - super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - nonUpdateAspectNames.add(GENERATORS_LIST); - nonUpdateAspectNames.add(QUERIES_LIST); - } - - public String getId() { - return PersistenceStructureNodes.PERSISTENCE_UNIT_ID; - } - - @Override - public PersistenceUnit getPersistenceUnit() { - return this; - } - - - // **************** parent ************************************************* - - @Override - public Persistence getParent() { - return (Persistence) super.getParent(); - } - - - // **************** name *************************************************** - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.xmlPersistenceUnit.setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - - // **************** transaction type *************************************** - - public PersistenceUnitTransactionType getTransactionType() { - return (isTransactionTypeDefault()) ? - getDefaultTransactionType() : getSpecifiedTransactionType(); - } - - public PersistenceUnitTransactionType getSpecifiedTransactionType() { - return this.specifiedTransactionType; - } - - public void setSpecifiedTransactionType(PersistenceUnitTransactionType newTransactionType) { - PersistenceUnitTransactionType oldTransactionType = this.specifiedTransactionType; - this.specifiedTransactionType = newTransactionType; - this.xmlPersistenceUnit.setTransactionType(PersistenceUnitTransactionType.toXmlResourceModel(newTransactionType)); - firePropertyChanged(SPECIFIED_TRANSACTION_TYPE_PROPERTY, oldTransactionType, newTransactionType); - } - - public boolean isTransactionTypeDefault() { - return this.specifiedTransactionType == null; - } - - public PersistenceUnitTransactionType getDefaultTransactionType() { - return this.defaultTransactionType; - } - - protected void setDefaultTransactionType(PersistenceUnitTransactionType newTransactionType) { - PersistenceUnitTransactionType oldTransactionType = this.defaultTransactionType; - this.defaultTransactionType = newTransactionType; - firePropertyChanged(DEFAULT_TRANSACTION_TYPE_PROPERTY, oldTransactionType, newTransactionType); - } - - // **************** description ******************************************** - - public String getDescription() { - return this.description; - } - - public void setDescription(String newDescription) { - String oldDescription = this.description; - this.description = newDescription; - this.xmlPersistenceUnit.setDescription(newDescription); - firePropertyChanged(DESCRIPTION_PROPERTY, oldDescription, newDescription); - } - - - // **************** provider *********************************************** - - public String getProvider() { - return this.provider; - } - - public void setProvider(String newProvider) { - String oldProvider = this.provider; - this.provider = newProvider; - this.xmlPersistenceUnit.setProvider(newProvider); - firePropertyChanged(PROVIDER_PROPERTY, oldProvider, newProvider); - } - - - // **************** jta data source **************************************** - - public String getJtaDataSource() { - return this.jtaDataSource; - } - - public void setJtaDataSource(String newJtaDataSource) { - String oldJtaDataSource = this.jtaDataSource; - this.jtaDataSource = newJtaDataSource; - this.xmlPersistenceUnit.setJtaDataSource(newJtaDataSource); - firePropertyChanged(JTA_DATA_SOURCE_PROPERTY, oldJtaDataSource, newJtaDataSource); - } - - - // **************** non-jta data source ************************************ - - public String getNonJtaDataSource() { - return this.nonJtaDataSource; - } - - public void setNonJtaDataSource(String newNonJtaDataSource) { - String oldNonJtaDataSource = this.nonJtaDataSource; - this.nonJtaDataSource = newNonJtaDataSource; - this.xmlPersistenceUnit.setNonJtaDataSource(newNonJtaDataSource); - firePropertyChanged(NON_JTA_DATA_SOURCE_PROPERTY, oldNonJtaDataSource, newNonJtaDataSource); - } - - - // **************** mapping file refs ************************************** - - public ListIterator<MappingFileRef> mappingFileRefs() { - if (impliedMappingFileRef == null) { - return specifiedMappingFileRefs(); - } - else { - return new ReadOnlyCompositeListIterator<MappingFileRef>( - specifiedMappingFileRefs(), impliedMappingFileRef); - } - } - - public int mappingFileRefsSize() { - if (impliedMappingFileRef == null) { - return specifiedMappingFileRefsSize(); - } - return 1 + specifiedMappingFileRefsSize(); - } - - // **************** specified mapping file refs **************************** - - public ListIterator<MappingFileRef> specifiedMappingFileRefs() { - return new CloneListIterator<MappingFileRef>(specifiedMappingFileRefs); - } - - public int specifiedMappingFileRefsSize() { - return specifiedMappingFileRefs.size(); - } - - public MappingFileRef addSpecifiedMappingFileRef() { - return addSpecifiedMappingFileRef(specifiedMappingFileRefs.size()); - } - - public MappingFileRef addSpecifiedMappingFileRef(int index) { - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - MappingFileRef mappingFileRef = buildMappingFileRef(xmlMappingFileRef); - specifiedMappingFileRefs.add(index, mappingFileRef); - this.xmlPersistenceUnit.getMappingFiles().add(index, xmlMappingFileRef); - fireItemAdded(SPECIFIED_MAPPING_FILE_REF_LIST, index, mappingFileRef); - return mappingFileRef; - } - - public void removeSpecifiedMappingFileRef(MappingFileRef mappingFileRef) { - removeSpecifiedMappingFileRef(specifiedMappingFileRefs.indexOf(mappingFileRef)); - } - - public void removeSpecifiedMappingFileRef(int index) { - MappingFileRef mappingFileRefRemoved = specifiedMappingFileRefs.remove(index); - mappingFileRefRemoved.dispose(); - this.xmlPersistenceUnit.getMappingFiles().remove(index); - fireItemRemoved(SPECIFIED_MAPPING_FILE_REF_LIST, index, mappingFileRefRemoved); - } - - protected void addSpecifiedMappingFileRef_(MappingFileRef mappingFileRef) { - addSpecifiedMappingFileRef_(specifiedMappingFileRefs.size(), mappingFileRef); - } - - protected void addSpecifiedMappingFileRef_(int index, MappingFileRef mappingFileRef) { - addItemToList(index, mappingFileRef, specifiedMappingFileRefs, SPECIFIED_MAPPING_FILE_REF_LIST); - } - - protected void removeSpecifiedMappingFileRef_(MappingFileRef mappingFileRef) { - removeSpecifiedMappingFileRef_(specifiedMappingFileRefs.indexOf(mappingFileRef)); - } - - protected void removeSpecifiedMappingFileRef_(int index) { - specifiedMappingFileRefs.get(index).dispose(); - removeItemFromList(index, specifiedMappingFileRefs, SPECIFIED_MAPPING_FILE_REF_LIST); - } - - - // **************** implied mapping file ref ******************************* - - public MappingFileRef getImpliedMappingFileRef() { - return impliedMappingFileRef; - } - - protected MappingFileRef setImpliedMappingFileRef() { - if (impliedMappingFileRef != null) { - throw new IllegalStateException("The implied mapping file ref is already set."); - } - MappingFileRef mappingFileRef = buildMappingFileRef(null); - impliedMappingFileRef = mappingFileRef; - firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, null, mappingFileRef); - return mappingFileRef; - } - - protected void unsetImpliedMappingFileRef() { - if (impliedMappingFileRef == null) { - throw new IllegalStateException("The implied mapping file ref is already unset."); - } - MappingFileRef mappingFileRef = impliedMappingFileRef; - impliedMappingFileRef.dispose(); - impliedMappingFileRef = null; - firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, mappingFileRef, null); - } - - - // **************** class refs ********************************************* - - @SuppressWarnings("unchecked") - public ListIterator<ClassRef> classRefs() { - return new ReadOnlyCompositeListIterator<ClassRef>( - specifiedClassRefs(), impliedClassRefs()); - } - - public int classRefsSize() { - return specifiedClassRefsSize() + impliedClassRefsSize(); - } - - // **************** specified class refs *********************************** - - public ListIterator<ClassRef> specifiedClassRefs() { - return new CloneListIterator<ClassRef>(this.specifiedClassRefs); - } - - public int specifiedClassRefsSize() { - return specifiedClassRefs.size(); - } - - public ClassRef addSpecifiedClassRef() { - return addSpecifiedClassRef(this.specifiedClassRefsSize()); - } - - public ClassRef addSpecifiedClassRef(int index) { - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - ClassRef classRef = buildClassRef(xmlClassRef); - this.specifiedClassRefs.add(index, classRef); - this.xmlPersistenceUnit.getClasses().add(index, xmlClassRef); - fireItemAdded(SPECIFIED_CLASS_REF_LIST, index, classRef); - return classRef; - } - - public void removeSpecifiedClassRef(ClassRef classRef) { - removeSpecifiedClassRef(this.specifiedClassRefs.indexOf(classRef)); - } - - public void removeSpecifiedClassRef(int index) { - ClassRef classRefRemoved = this.specifiedClassRefs.remove(index); - classRefRemoved.dispose(); - this.xmlPersistenceUnit.getClasses().remove(index); - fireItemRemoved(SPECIFIED_CLASS_REF_LIST, index, classRefRemoved); - } - - protected void addSpecifiedClassRef_(ClassRef classRef) { - addSpecifiedClassRef_(this.specifiedClassRefs.size(), classRef); - } - - protected void addSpecifiedClassRef_(int index, ClassRef classRef) { - addItemToList(index, classRef, this.specifiedClassRefs, SPECIFIED_CLASS_REF_LIST); - } - - protected void removeSpecifiedClassRef_(ClassRef classRef) { - classRef.dispose(); - removeSpecifiedClassRef_(this.specifiedClassRefs.indexOf(classRef)); - } - - protected void removeSpecifiedClassRef_(int index) { - removeItemFromList(index, this.specifiedClassRefs, SPECIFIED_CLASS_REF_LIST); - } - - - // **************** implied class refs ************************************* - - public ListIterator<ClassRef> impliedClassRefs() { - return new CloneListIterator<ClassRef>(impliedClassRefs); - } - - public int impliedClassRefsSize() { - return impliedClassRefs.size(); - } - - protected ClassRef addImpliedClassRef(String className) { - return addImpliedClassRef(impliedClassRefs.size(), className); - } - - protected ClassRef addImpliedClassRef(int index, String className) { - ClassRef classRef = buildClassRef(className); - addItemToList(index, classRef, impliedClassRefs, IMPLIED_CLASS_REF_LIST); - return classRef; - } - - protected void removeImpliedClassRef(ClassRef classRef) { - classRef.dispose(); - removeImpliedClassRef(impliedClassRefs.indexOf(classRef)); - } - - protected void removeImpliedClassRef(int index) { - removeItemFromList(index, impliedClassRefs, IMPLIED_CLASS_REF_LIST); - } - - - // **************** exclude unlisted classes ******************************* - - public boolean isExcludeUnlistedClasses() { - return getSpecifiedExcludeUnlistedClasses() == null ? getDefaultExcludeUnlistedClasses() : getSpecifiedExcludeUnlistedClasses().booleanValue(); - } - - public Boolean getSpecifiedExcludeUnlistedClasses() { - return this.specifiedExcludeUnlistedClasses; - } - - public void setSpecifiedExcludeUnlistedClasses(Boolean newExcludeUnlistedClasses) { - Boolean oldExcludeUnlistedClasses = this.specifiedExcludeUnlistedClasses; - this.specifiedExcludeUnlistedClasses = newExcludeUnlistedClasses; - - this.xmlPersistenceUnit.setExcludeUnlistedClasses(this.specifiedExcludeUnlistedClasses); - - firePropertyChanged(SPECIFIED_EXCLUDE_UNLISTED_CLASSED_PROPERTY, oldExcludeUnlistedClasses, newExcludeUnlistedClasses); - } - - public boolean getDefaultExcludeUnlistedClasses() { - // TODO - calculate default - // This is determined from the project - return this.defaultExcludeUnlistedClasses; - } - - - // **************** properties ********************************************* - - public ListIterator<Property> properties() { - return new CloneListIterator<Property>(this.properties); - } - - public int propertiesSize() { - return this.properties.size(); - } - - public Property getProperty(String key) { - if (key == null) { - throw new IllegalStateException("Cannot getProperty: key is null."); - } - for(Property property : this.properties) { - if(key.equals(property.getName())) { - return property; - } - } - return null; - } - - public ListIterator<Property> propertiesWithPrefix(String keyPrefix) { - if (keyPrefix == null) { - throw new IllegalStateException("Cannot find propertiesWithPrefix: keyPrefix is null."); - } - List<Property> properties = new ArrayList<Property>(); - - for(Property property : this.properties) { - if(property.getName() != null && property.getName().startsWith(keyPrefix)) { - properties.add( property); - } - } - return properties.listIterator(); - } - - public Property getProperty(String key, String value) { - if (key == null || value == null) { - throw new IllegalStateException("Cannot getProperty: key or value is null."); - } - for(Property property : this.properties) { - if(key.equals(property.getName())) { - if(value.equals(property.getValue())) { - return property; - } - } - } - return null; - } - - protected Property getProperty(int index) { - return this.properties.get(index); - } - - protected XmlProperty getXmlProperty(String name, String value) { - if (this.xmlPersistenceUnit.getProperties() == null) { - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - this.xmlPersistenceUnit.setProperties(xmlProperties); - } - for(XmlProperty xmlProperty : this.xmlPersistenceUnit.getProperties().getProperties()) { - if(name.equals(xmlProperty.getName()) && value.equals(xmlProperty.getValue())) { - return xmlProperty; - } - } - return null; - } - - /** - * Adds or Changes Property with the given key and value. - */ - public void putProperty(String key, String value, boolean allowDuplicates) { - if( ! allowDuplicates && this.containsProperty(key)) { - this.putXmlProperty(key, value, this.getProperty(key).getValue()); - return; - } - if( value != null) { - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName(key); - xmlProperty.setValue(value); - - this.addXmlProperty(xmlProperty, propertiesSize()); - return; - } - } - - public void replacePropertyValue(String key, String oldValue, String newValue) { - - this.putXmlProperty(key, newValue, oldValue); - } - - protected void putXmlProperty(String key, String value, String oldValue) { - if( value == null) { - this.removeProperty(key); - return; - } - - XmlProperty xmlProperty = this.getXmlProperty(key, oldValue); - if(xmlProperty == null) { - throw new NoSuchElementException("Missing Property name: " + key + ", value: " + oldValue); - } - xmlProperty.setValue(value); - } - - public boolean containsProperty(String key) { - return (this.getProperty(key) != null); - } - - public Property addProperty() { - return addProperty(propertiesSize()); - } - - public Property addProperty(int index) { - return this.addXmlProperty(PersistenceFactory.eINSTANCE.createXmlProperty(), index); - } - - protected Property addXmlProperty(XmlProperty xmlProperty, int index) { - - Property property = buildProperty(xmlProperty); - - if (this.xmlPersistenceUnit.getProperties() == null) { - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - this.xmlPersistenceUnit.setProperties(xmlProperties); - } - - this.properties.add(index, property); - this.xmlPersistenceUnit.getProperties().getProperties().add(index, xmlProperty); - this.fireItemAdded(PROPERTIES_LIST, index, property); - return property; - } - - public void removeProperty(String key) { - this.removeProperty(this.getProperty(key)); - } - - public void removeProperty(String key, String value) { - this.removeProperty(this.getProperty(key, value)); - } - - public void removeProperty(Property property) { - if (property != null) { - this.removeProperty(this.properties.indexOf(property)); - } - } - - protected void removeProperty(int index) { - Property propertyRemoved = this.properties.remove(index); - this.xmlPersistenceUnit.getProperties().getProperties().remove(index); - - if (this.xmlPersistenceUnit.getProperties().getProperties().isEmpty()) { - this.xmlPersistenceUnit.setProperties(null); - } - - fireItemRemoved(PROPERTIES_LIST, index, propertyRemoved); - } - - protected void addProperty_(Property property) { - addProperty_(this.properties.size(), property); - } - - protected void addProperty_(int index, Property property) { - addItemToList(index, property, this.properties, PROPERTIES_LIST); - } - - protected void removeProperty_(Property property) { - removeProperty_(this.properties.indexOf(property)); - } - - protected void removeProperty_(int index) { - removeItemFromList(index, this.properties, PROPERTIES_LIST); - } - - - // **************** Persistence Unit Defaults ********************************************* - - //TODO validation for multiple persistenceUnitDefaults. - - //Take the first PersistenceUnitDefaults found in an orm.xml file and use - //this for the defaults of the PersistenceUnit. - protected PersistenceUnitDefaults persistenceUnitDefaults() { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - PersistenceUnitDefaults persistenceUnitDefaults = mappingFileRef.getPersistenceUnitDefaults(); - if (persistenceUnitDefaults != null) { - return persistenceUnitDefaults; - } - } - return null; - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newDefaultAccess) { - AccessType oldDefaultAccess = this.defaultAccess; - this.defaultAccess = newDefaultAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldDefaultAccess, newDefaultAccess); - } - - public boolean getDefaultCascadePersist() { - return this.defaultCascadePersist; - } - - protected void setDefaultCascadePersist(boolean newDefaultCascadePersist) { - boolean oldDefaultCascadePersist = this.defaultCascadePersist; - this.defaultCascadePersist = newDefaultCascadePersist; - firePropertyChanged(DEFAULT_CASCADE_PERSIST_PROPERTY, oldDefaultCascadePersist, newDefaultCascadePersist); - } - - - // **************** global generator and query support ********************* - - public void addGenerator(Generator generator) { - this.generators.add(generator); - } - - public ListIterator<Generator> allGenerators() { - return new CloneListIterator<Generator>(this.generators); - } - - public void addQuery(Query query) { - this.queries.add(query); - } - - public ListIterator<Query> allQueries() { - return new CloneListIterator<Query>(this.queries); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlPersistenceUnit xmlPersistenceUnit) { - this.xmlPersistenceUnit = xmlPersistenceUnit; - this.name = xmlPersistenceUnit.getName(); - - //initialize specified classRefs before mappingFileRefs because of - //JpaFile rootStructureNode, we want the mapping file to "win", - //as it would in a Jpa runtime implementation - initializeSpecifiedClassRefs(xmlPersistenceUnit); - initializeMappingFileRefs(xmlPersistenceUnit); - //initialize implied classRefs last since they depend on both - //specified classRefs and mappingFileRefs - initializeImpliedClassRefs(xmlPersistenceUnit); - initializeProperties(xmlPersistenceUnit); - initializePersistenceUnitDefaults(); - this.specifiedExcludeUnlistedClasses = xmlPersistenceUnit.getExcludeUnlistedClasses(); - this.specifiedTransactionType = specifiedTransactionType(xmlPersistenceUnit); - this.defaultTransactionType = defaultTransacationType(); - this.description = xmlPersistenceUnit.getDescription(); - this.provider = xmlPersistenceUnit.getProvider(); - this.jtaDataSource = xmlPersistenceUnit.getJtaDataSource(); - this.nonJtaDataSource = xmlPersistenceUnit.getNonJtaDataSource(); - this.specifiedExcludeUnlistedClasses = xmlPersistenceUnit.getExcludeUnlistedClasses(); - } - - protected void initializeMappingFileRefs(XmlPersistenceUnit xmlPersistenceUnit) { - for (XmlMappingFileRef xmlMappingFileRef : xmlPersistenceUnit.getMappingFiles()) { - specifiedMappingFileRefs.add(buildMappingFileRef(xmlMappingFileRef)); - } - if (! impliedMappingFileIsSpecified() && impliedMappingFileExists()) { - impliedMappingFileRef = buildMappingFileRef(null); - } - } - - protected void initializeSpecifiedClassRefs(XmlPersistenceUnit xmlPersistenceUnit) { - for (XmlJavaClassRef xmlJavaClassRef : xmlPersistenceUnit.getClasses()) { - specifiedClassRefs.add(buildClassRef(xmlJavaClassRef)); - } - } - - protected void initializeImpliedClassRefs(XmlPersistenceUnit xmlPersistenceUnit) { - if (getJpaProject().discoversAnnotatedClasses() && ! isExcludeUnlistedClasses()) { - for (String typeName : CollectionTools.iterable(this.getJpaProject().annotatedClassNames())) { - if ( ! classIsSpecified(typeName)) { - impliedClassRefs.add(buildClassRef(typeName)); - } - } - } - } - - protected void initializeProperties(XmlPersistenceUnit xmlPersistenceUnit) { - XmlProperties xmlProperties = xmlPersistenceUnit.getProperties(); - if (xmlProperties == null) { - return; - } - for (XmlProperty xmlProperty : xmlProperties.getProperties()) { - this.properties.add(buildProperty(xmlProperty)); - } - } - - protected void initializePersistenceUnitDefaults() { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - if (persistenceUnitDefaults != null) { - this.defaultSchema = this.schema(persistenceUnitDefaults); - this.defaultCatalog = this.catalog(persistenceUnitDefaults); - this.defaultAccess = this.access(persistenceUnitDefaults); - this.defaultCascadePersist = this.cascadePersist(persistenceUnitDefaults); - } - else { - this.defaultSchema = null; - this.defaultCatalog = null; - this.defaultAccess = null; - this.defaultCascadePersist = false; - } - } - - public void update(XmlPersistenceUnit persistenceUnit) { - this.xmlPersistenceUnit = persistenceUnit; - this.generators.clear(); - this.queries.clear(); - updateName(persistenceUnit); - updateSpecifiedTransactionType(persistenceUnit); - updateDefaultTransactionType(); - updateDescription(persistenceUnit); - updateProvider(persistenceUnit); - updateJtaDataSource(persistenceUnit); - updateNonJtaDataSource(persistenceUnit); - //update specified classRefs before mappingFileRefs because of - //JpaFile rootStructureNode, we want the mapping file to "win", - //as it would in a Jpa runtime implementation - updateSpecifiedClassRefs(persistenceUnit); - updateMappingFileRefs(persistenceUnit); - //update implied classRefs last since they depend on both - //specified classRefs and mappingFileRefs - updateImpliedClassRefs(persistenceUnit); - updateExcludeUnlistedClasses(persistenceUnit); - updateProperties(persistenceUnit); - updatePersistenceUnitDefaults(); - generatorRepositoryUpdated(); - queryRepositoryUpdated(); - } - - protected void updateName(XmlPersistenceUnit persistenceUnit) { - setName(persistenceUnit.getName()); - } - - protected void updateSpecifiedTransactionType(XmlPersistenceUnit persistenceUnit) { - setSpecifiedTransactionType(specifiedTransactionType(persistenceUnit)); - } - - protected PersistenceUnitTransactionType specifiedTransactionType(XmlPersistenceUnit persistenceUnit) { - return PersistenceUnitTransactionType.fromXmlResourceModel(persistenceUnit.getTransactionType()); - } - - protected void updateDefaultTransactionType() { - setDefaultTransactionType(defaultTransacationType()); - } - - protected PersistenceUnitTransactionType defaultTransacationType() { - // TODO - calculate default - // From the JPA spec: "In a Java EE environment, if this element is not - // specified, the default is JTA. In a Java SE environment, if this element - // is not specified, a default of RESOURCE_LOCAL may be assumed." - return null; - } - - protected void updateDescription(XmlPersistenceUnit persistenceUnit) { - setDescription(persistenceUnit.getDescription()); - } - - protected void updateProvider(XmlPersistenceUnit persistenceUnit) { - setProvider(persistenceUnit.getProvider()); - } - - protected void updateJtaDataSource(XmlPersistenceUnit persistenceUnit) { - setJtaDataSource(persistenceUnit.getJtaDataSource()); - } - - protected void updateNonJtaDataSource(XmlPersistenceUnit persistenceUnit) { - setNonJtaDataSource(persistenceUnit.getNonJtaDataSource()); - } - - protected void updateMappingFileRefs(XmlPersistenceUnit persistenceUnit) { - Iterator<MappingFileRef> stream = specifiedMappingFileRefs(); - Iterator<XmlMappingFileRef> stream2 = new CloneIterator<XmlMappingFileRef>(persistenceUnit.getMappingFiles());//prevent ConcurrentModificiationException - - while (stream.hasNext()) { - MappingFileRef mappingFileRef = stream.next(); - if (stream2.hasNext()) { - mappingFileRef.update(stream2.next()); - } - else { - removeSpecifiedMappingFileRef_(mappingFileRef); - } - } - - while (stream2.hasNext()) { - addSpecifiedMappingFileRef_(buildMappingFileRef(stream2.next())); - } - - if (impliedMappingFileIsSpecified()) { - if (impliedMappingFileRef != null) { - unsetImpliedMappingFileRef(); - } - } - else { - if (impliedMappingFileExists()) { - if (impliedMappingFileRef == null) { - setImpliedMappingFileRef(); - } - getImpliedMappingFileRef().update(null); - } - else { - if (impliedMappingFileRef != null) { - unsetImpliedMappingFileRef(); - } - } - } - } - - protected boolean impliedMappingFileIsSpecified() { - String impliedMappingFile = JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH; - for (MappingFileRef each : specifiedMappingFileRefs) { - if (impliedMappingFile.equals(each.getFileName())) { - return true; - } - } - return false; - } - - protected boolean impliedMappingFileExists() { - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForRead(getJpaProject().getProject()); - OrmResource or = oae.getResource(JptCorePlugin.getDefaultOrmXmlDeploymentURI(getJpaProject().getProject())); - boolean exists = or != null && or.exists(); - oae.dispose(); - return exists; - } - - protected MappingFileRef buildMappingFileRef(XmlMappingFileRef xmlMappingFileRef) { - return getJpaFactory().buildMappingFileRef(this, xmlMappingFileRef); - } - - protected void updateSpecifiedClassRefs(XmlPersistenceUnit persistenceUnit) { - Iterator<ClassRef> stream = specifiedClassRefs(); - Iterator<XmlJavaClassRef> stream2 = new CloneIterator<XmlJavaClassRef>(persistenceUnit.getClasses());//prevent ConcurrentModificiationException - - while (stream.hasNext()) { - ClassRef classRef = stream.next(); - if (stream2.hasNext()) { - classRef.update(stream2.next()); - } - else { - removeSpecifiedClassRef_(classRef); - } - } - - while (stream2.hasNext()) { - addSpecifiedClassRef_(buildClassRef(stream2.next())); - } - } - - protected void updateImpliedClassRefs(XmlPersistenceUnit persistenceUnit) { - Iterator<ClassRef> impliedRefs = impliedClassRefs(); - Iterator<String> annotatedClassNames = getJpaProject().annotatedClassNames(); - - - if ( ! isExcludeUnlistedClasses()) { - while (impliedRefs.hasNext()) { - ClassRef classRef = impliedRefs.next(); - boolean updated = false; - while (! updated && annotatedClassNames.hasNext()) { - String annotatedClassName = annotatedClassNames.next(); - if ( ! classIsSpecified(annotatedClassName)) { - classRef.update(annotatedClassName); - updated = true; - } - } - if (! annotatedClassNames.hasNext() && ! updated) { - removeImpliedClassRef(classRef); - } - } - - while (annotatedClassNames.hasNext()) { - String annotatedClassName = annotatedClassNames.next(); - if ( ! classIsSpecified(annotatedClassName)) { - addImpliedClassRef(annotatedClassName); - } - } - } - else { - for (ClassRef classRef : CollectionTools.iterable(impliedClassRefs())) { - removeImpliedClassRef(classRef); - } - } - } - - protected ClassRef buildClassRef(XmlJavaClassRef xmlClassRef) { - return getJpaFactory().buildClassRef(this, xmlClassRef); - } - - protected ClassRef buildClassRef(String className) { - return getJpaFactory().buildClassRef(this, className); - } - - /** - * Return true if the class is specified either as a class - * or listed in a mapping file - */ - protected boolean classIsSpecified(String className) { - for (ClassRef specifiedClassRef : CollectionTools.iterable(specifiedClassRefs())) { - if (className.equals(specifiedClassRef.getClassName())) { - return true; - } - } - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - if (mappingFileRef.getPersistentType(className) != null) { - return true; - } - } - return false; - } - - protected void updateExcludeUnlistedClasses(XmlPersistenceUnit persistenceUnit) { - setSpecifiedExcludeUnlistedClasses(persistenceUnit.getExcludeUnlistedClasses()); - } - - protected void updateProperties(XmlPersistenceUnit persistenceUnit) { - XmlProperties xmlProperties = persistenceUnit.getProperties(); - - Iterator<Property> stream = properties(); - Iterator<XmlProperty> stream2; - - if (xmlProperties == null) { - stream2 = EmptyIterator.instance(); - } - else { - stream2 = new CloneIterator<XmlProperty>(xmlProperties.getProperties());//avoid ConcurrentModificationException - } - - while (stream.hasNext()) { - Property property = stream.next(); - if (stream2.hasNext()) { - property.update(stream2.next()); - } - else { - removeProperty_(property); - } - } - - while (stream2.hasNext()) { - addProperty_(buildProperty(stream2.next())); - } - } - - protected Property buildProperty(XmlProperty xmlProperty) { - return getJpaFactory().buildProperty(this, xmlProperty); - } - - protected void updatePersistenceUnitDefaults() { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - this.setDefaultSchema(this.schema(persistenceUnitDefaults)); - this.setDefaultCatalog(this.catalog(persistenceUnitDefaults)); - this.setDefaultAccess(this.access(persistenceUnitDefaults)); - this.setDefaultCascadePersist(this.cascadePersist(persistenceUnitDefaults)); - } - - protected String schema(PersistenceUnitDefaults persistenceUnitDefaults) { - if (persistenceUnitDefaults != null) { - if (persistenceUnitDefaults.getSchema() != null) { - return persistenceUnitDefaults.getSchema(); - } - } - Schema projectDefaultSchema = projectDefaultSchema(); - return projectDefaultSchema == null ? null : projectDefaultSchema.getName(); - } - - protected Schema projectDefaultSchema() { - return getJpaProject().getDefaultSchema(); - } - - protected String catalog(PersistenceUnitDefaults persistenceUnitDefaults) { - if (persistenceUnitDefaults != null) { - if (persistenceUnitDefaults.getCatalog() != null) { - return persistenceUnitDefaults.getCatalog(); - } - } - return projectDefaultCatalogName(); - } - - protected String projectDefaultCatalogName() { - Catalog catalog = this.getJpaProject().getDataSource().getDefaultCatalog(); - return (catalog == null) ? null : catalog.getName(); - } - - protected AccessType access(PersistenceUnitDefaults persistenceUnitDefaults) { - return persistenceUnitDefaults == null ? null : persistenceUnitDefaults.getAccess(); - } - - protected boolean cascadePersist(PersistenceUnitDefaults persistenceUnitDefaults) { - return persistenceUnitDefaults == null ? false : persistenceUnitDefaults.isCascadePersist(); - } - - // This is called after the persistence unit has been updated to ensure - // we catch all added generators - protected void generatorRepositoryUpdated() { - fireListChanged(GENERATORS_LIST); - } - - // This is called after the persistence unit has been updated to ensure - // we catch all added queries - protected void queryRepositoryUpdated() { - fireListChanged(QUERIES_LIST); - } - - - // ********** Validation *********************************************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addMappingFileMessages(messages); - addClassMessages(messages); - } - - protected void addMappingFileMessages(List<IMessage> messages) { - addMultipleMetadataMessages(messages); - addDuplicateMappingFileMessages(messages); - - for (Iterator<MappingFileRef> stream = mappingFileRefs(); stream.hasNext();) { - stream.next().addToMessages(messages); - } - } - - protected void addMultipleMetadataMessages(List<IMessage> messages) { - Collection<PersistenceUnitDefaults> puDefaultsCollection = persistenceUnitDefaultsForValidation(); - if (puDefaultsCollection.size() > 1) { - for (PersistenceUnitDefaults puDefaults : puDefaultsCollection) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_MAPPINGS_MULTIPLE_METADATA, - new String[] {this.getName()}, - puDefaults) - ); - } - } - } - - protected void addDuplicateMappingFileMessages(List<IMessage> messages) { - HashBag<String> fileBag = new HashBag<String>( - CollectionTools.collection( - new TransformationIterator<MappingFileRef, String>(this.mappingFileRefs()) { - @Override - protected String transform(MappingFileRef mappingFileRef) { - return mappingFileRef.getFileName(); - } - } - ) - ); - for (MappingFileRef mappingFileRef : CollectionTools.iterable(this.mappingFileRefs())) { - if (fileBag.count(mappingFileRef.getFileName()) > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE, - new String[] {mappingFileRef.getFileName()}, - mappingFileRef, - mappingFileRef.getValidationTextRange()) - ); - } - } - } - - protected void addClassMessages(List<IMessage> messages) { - addDuplicateClassMessages(messages); - - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - classRef.addToMessages(messages); - } - } - - protected void addDuplicateClassMessages(List<IMessage> messages) { - HashBag<String> classNameBag = new HashBag<String>( - CollectionTools.collection( - new TransformationIterator<ClassRef, String>(this.classRefs()) { - @Override - protected String transform(ClassRef classRef) { - return classRef.getClassName(); - } - } - ) - ); - for (ClassRef javaClassRef : CollectionTools.iterable(this.classRefs())) { - if (javaClassRef.getClassName() != null - && classNameBag.count(javaClassRef.getClassName()) > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_CLASS, - new String[] {javaClassRef.getClassName()}, - javaClassRef, - javaClassRef.getValidationTextRange()) - ); - } - } - } - - private Collection<PersistenceUnitDefaults> persistenceUnitDefaultsForValidation() { - ArrayList<PersistenceUnitDefaults> puDefaults = new ArrayList<PersistenceUnitDefaults>(); - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - PersistenceUnitDefaults persistenceUnitDefaults = mappingFileRef.getPersistenceUnitDefaults(); - if (persistenceUnitDefaults != null) { - puDefaults.add(persistenceUnitDefaults); - } - } - return puDefaults; - } - - //************************************* - - public PersistentType getPersistentType(String fullyQualifiedTypeName) { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - OrmPersistentType ormPersistentType = mappingFileRef.getPersistentType(fullyQualifiedTypeName); - if (ormPersistentType != null) { - return ormPersistentType; - } - } - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - if (classRef.isFor(fullyQualifiedTypeName)) { - return classRef.getJavaPersistentType(); - } - } - return null; - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - if (mappingFileRef.containsOffset(textOffset)) { - return mappingFileRef; - } - } - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - if (classRef.containsOffset(textOffset)) { - return classRef; - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - if (xmlPersistenceUnit == null) { - return false; - } - return xmlPersistenceUnit.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return xmlPersistenceUnit.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return xmlPersistenceUnit.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - classRef.dispose(); - } - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - mappingFileRef.dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java deleted file mode 100644 index f0d76469bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import java.util.List; -import org.eclipse.core.resources.IResource; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericPersistenceXml extends AbstractPersistenceJpaContextNode - implements PersistenceXml -{ - protected PersistenceResource persistenceResource; - - protected Persistence persistence; - - - public GenericPersistenceXml(JpaRootContextNode parent, PersistenceResource persistenceResource) { - super(parent); - this.initialize(persistenceResource); - } - - public String getId() { - // isn't actually displayed, so needs no details page - return null; - } - - @Override - public JpaRootContextNode getParent() { - return (JpaRootContextNode) super.getParent(); - } - - @Override - public IResource getResource() { - return persistenceResource.getFile(); - } - - // **************** persistence ******************************************** - - public Persistence getPersistence() { - return persistence; - } - - public Persistence addPersistence() { - if (persistence != null) { - throw new IllegalStateException(); - } - - XmlPersistence xmlPersistence = PersistenceFactory.eINSTANCE.createXmlPersistence(); - persistence = buildPersistence(xmlPersistence); - persistenceResource.getContents().add(xmlPersistence); - firePropertyChanged(PERSISTENCE_PROPERTY, null, persistence); - return persistence; - } - - public void removePersistence() { - if (persistence == null) { - throw new IllegalStateException(); - } - this.persistence.dispose(); - Persistence oldPersistence = persistence; - persistence = null; - XmlPersistence xmlPersistence = persistenceResource.getPersistence(); - persistenceResource.getContents().remove(xmlPersistence); - firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, null); - } - - protected void setPersistence_(Persistence newPersistence) { - Persistence oldPersistence = persistence; - persistence = newPersistence; - firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, newPersistence); - } - - - // **************** updating *********************************************** - - protected void initialize(PersistenceResource persistenceResource) { - this.persistenceResource = persistenceResource; - if (persistenceResource.getPersistence() != null) { - this.persistence = buildPersistence(persistenceResource.getPersistence()); - } - } - - public void update(PersistenceResource persistenceResource) { - this.persistenceResource = persistenceResource; - if (persistenceResource.getPersistence() != null) { - if (this.persistence != null) { - this.persistence.update(persistenceResource.getPersistence()); - } - else { - setPersistence_(buildPersistence(persistenceResource.getPersistence())); - } - } - else { - if (getPersistence() != null) { - getPersistence().dispose(); - } - setPersistence_(null); - } - } - - protected Persistence buildPersistence(XmlPersistence xmlPersistence) { - return getJpaFactory().buildPersistence(this, xmlPersistence); - } - - - // ************************************************************************* - - @Override - public PersistenceUnit getPersistenceUnit() { - throw new UnsupportedOperationException("No PersistenceUnit in this context"); - } - - - public JpaStructureNode getStructureNode(int textOffset) { - if (persistence.containsOffset(textOffset)) { - return persistence.getStructureNode(textOffset); - } - return this; - } - - // never actually selected - public TextRange getSelectionTextRange() { - return TextRange.Empty.instance(); - } - - public TextRange getValidationTextRange() { - return TextRange.Empty.instance(); - } - - - // **************** validation ********************************************* - - private boolean okToContinueValidation = true; - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addInvalidPersistenceXmlContentMessage(messages); - - if (okToContinueValidation){ - getPersistence().addToMessages(messages); - } - } - - protected void addInvalidPersistenceXmlContentMessage(List<IMessage> messages) { - if (this.persistence == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_XML_INVALID_CONTENT, - this) - ); - okToContinueValidation = false; - } - } - - public void dispose() { - this.persistence.dispose(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericProperty.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericProperty.java deleted file mode 100644 index f3d17d64ec..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericProperty.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.context.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericProperty extends AbstractPersistenceJpaContextNode - implements Property -{ - protected String name; - - protected String value; - - protected XmlProperty property; - - public GenericProperty(PersistenceUnit parent, XmlProperty property) { - super(parent); - this.initialize(property); - } - - // **************** name *************************************************** - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.property.setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - - // **************** value ************************************************** - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - String oldValue = this.value; - this.value = newValue; - this.property.setValue(newValue); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlProperty property) { - this.property = property; - this.name = property.getName(); - this.value = property.getValue(); - } - - public void update(XmlProperty property) { - this.property = property; - setName(property.getName()); - setValue(property.getValue()); - } - - // **************** validation *********************************************** - - public TextRange getValidationTextRange() { - return this.property.getValidationTextRange(); - } - - // **************** toString - @Override - public void toString(StringBuilder sb) - { - sb.append(" (name: "); - sb.append(name); - sb.append(", value: "); - sb.append(value); - sb.append(')'); - } - -} 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 c1d28a0177..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProperties.java +++ /dev/null @@ -1,94 +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.facet; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProperties; - -public interface JpaFacetDataModelProperties extends IDataModelProperties -{ - /** - * Required, type String, identifies Jpa Platform - */ - public static final String PLATFORM_ID = "JpaFacetDataModelProperties.PLATFORM_ID"; - - /** - * Not required, type String, identifies database connection - */ - public static final String CONNECTION = "JpaFacetDataModelProperties.CONNECTION"; - - /** - * Required, type Boolean, identifies whether database connection is active - */ - public static final String CONNECTION_ACTIVE = "JpaFacetDataModelProperties.CONNECTION_ACTIVE"; - - /** - * Required, type Boolean, identifies if the user wishes to override default schema name - */ - public static final String USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA = - "JpaFacetDataModelProperties.USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA"; - - /** - * Not required, type String, identifies the user overridden default schema name - */ - public static final String USER_OVERRIDE_DEFAULT_SCHEMA = - "JpaFacetDataModelProperties.USER_OVERRIDE_DEFAULT_SCHEMA"; - - /** - * 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 - */ - public static final String RUNTIME = "JpaFacetDataModelProperties.RUNTIME"; - - /** - * Required, type boolean, opposite of USE_USER_JPA_LIBRARY, identifies whether - * server runtime provides JPA implementation - * If this is true, then the property JPA_LIBRARY is not used - */ - public static final String USE_SERVER_JPA_IMPLEMENTATION = "JpaFacetDataModelProperties.USE_SERVER_JPA_IMPLEMENTATION"; - - /** - * Required, type boolean, opposite of USE_SERVER_JPA_IMPLEMENTATION, identifies - * whether the user is providing his own JPA library - * (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) - * If this is true, then the property JPA_LIBRARY is used - */ - public static final String USE_USER_JPA_LIBRARY = "JpaFacetDataModelProperties.USE_USER_JPA_LIBRARY"; - - /** - * Not required, type String, identifies JPA implementation library. - * Only used if the property USE_SERVER_JPA_IMPLEMENTATION is false. - */ - public static final String JPA_LIBRARY = "JpaFacetDataModelProperties.JPA_LIBRARY"; - - /** - * Required, type boolean, opposite of LIST_ANNOTATED_CLASSES, identifies - * whether all annotated classes are to be automatically included as part of - * all persistence units - */ - public static final String DISCOVER_ANNOTATED_CLASSES = "JpaFacetDataModelProperties.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) - */ - public static final String LIST_ANNOTATED_CLASSES = "JpaFacetDataModelProperties.LIST_ANNOTATED_CLASSES"; - - /** - * Required, type boolean, details whether orm.xml should be created - */ - public static final String CREATE_ORM_XML = "JpaFacetDataModelProperties.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 e079866c9c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java +++ /dev/null @@ -1,437 +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.facet; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.JptCoreMessages; -import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.db.Schema; -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.TransformationIterator; -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.frameworks.internal.plugin.WTPCommonMessages; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; -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 static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE; - - private static final String RUNTIME_NONE = - WTPCommonPlugin.getResourceString(WTPCommonMessages.RUNTIME_NONE, null); - - 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_SCHEMA_NOT_SPECIFIED_STATUS = - buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED); - - private static final IStatus RUNTIME_NOT_SPECIFIED_STATUS = - buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_NOT_SPECIFIED); - - private static final IStatus RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS = - buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30); - - private static final IStatus LIBRARY_NOT_SPECIFIED_STATUS = - buildWarningStatus(JptCoreMessages.VALIDATE_LIBRARY_NOT_SPECIFIED); - - /** - * required default constructor - */ - public JpaFacetDataModelProvider() { - super(); - } - - - @Override - public Set<String> getPropertyNames() { - @SuppressWarnings("unchecked") - Set<String> propertyNames = super.getPropertyNames(); - propertyNames.add(PLATFORM_ID); - propertyNames.add(CONNECTION); - propertyNames.add(CONNECTION_ACTIVE); - propertyNames.add(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); - propertyNames.add(USER_OVERRIDE_DEFAULT_SCHEMA); - propertyNames.add(RUNTIME); - propertyNames.add(USE_SERVER_JPA_IMPLEMENTATION); - propertyNames.add(USE_USER_JPA_LIBRARY); - propertyNames.add(JPA_LIBRARY); - propertyNames.add(DISCOVER_ANNOTATED_CLASSES); - propertyNames.add(LIST_ANNOTATED_CLASSES); - propertyNames.add(CREATE_ORM_XML); - return propertyNames; - } - - @Override - public boolean isPropertyEnabled(String propertyName) { - if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA); - } - if (propertyName.equals(JPA_LIBRARY)) { - return getBooleanProperty(USE_USER_JPA_LIBRARY); - } - return super.isPropertyEnabled(propertyName); - } - - @Override - public Object getDefaultProperty(String propertyName) { - if (propertyName.equals(FACET_ID)) { - return JptCorePlugin.FACET_ID; - } - if (propertyName.equals(PLATFORM_ID)) { - return JptCorePlugin.getDefaultJpaPlatformId(); - } - if (propertyName.equals(CONNECTION)) { - return null; - } - if (propertyName.equals(CONNECTION_ACTIVE)) { - return Boolean.valueOf(connectionIsActive()); - } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - return Boolean.FALSE; - } - if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return getDefaultSchemaName(); - } - if (propertyName.equals(RUNTIME)) { - return null; - } - if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) { - return Boolean.valueOf(this.runtimeSupportsEjb30(this.runtime())); - } - if (propertyName.equals(USE_USER_JPA_LIBRARY)) { - return Boolean.valueOf( ! getBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION)); - } - if (propertyName.equals(JPA_LIBRARY)) { - return JptCorePlugin.getDefaultJpaLibrary(); - } - if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { - return Boolean.valueOf(this.runtimeSupportsEjb30(this.runtime())); - } - if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { - return Boolean.valueOf( ! getBooleanProperty(DISCOVER_ANNOTATED_CLASSES)); - } - if (propertyName.equals(CREATE_ORM_XML)) { - return Boolean.TRUE; - } - return super.getDefaultProperty(propertyName); - } - - - - @Override - public boolean propertySet(String propertyName, Object propertyValue) { - boolean ok = super.propertySet(propertyName, propertyValue); - if (propertyName.equals(RUNTIME)) { - this.model.notifyPropertyChange(USE_SERVER_JPA_IMPLEMENTATION, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USE_USER_JPA_LIBRARY, IDataModel.DEFAULT_CHG); - // need to fire that the default change for using user library may have - // actually changed enablement for library - this.model.notifyPropertyChange(JPA_LIBRARY, IDataModel.ENABLE_CHG); - this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG); - } - if (propertyName.equals(CONNECTION)) { - this.model.notifyPropertyChange(CONNECTION, IDataModel.VALID_VALUES_CHG); - this.model.setBooleanProperty(CONNECTION_ACTIVE, connectionIsActive()); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); - } - if (propertyName.equals(CONNECTION_ACTIVE)) { - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG); - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG); - } - if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG); - if (! ((Boolean) propertyValue).booleanValue()) { - this.model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null); - } - } - if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) { - this.model.setBooleanProperty(USE_USER_JPA_LIBRARY, ! ((Boolean) propertyValue).booleanValue()); - } - if (propertyName.equals(USE_USER_JPA_LIBRARY)) { - this.model.setBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION, ! ((Boolean) propertyValue).booleanValue()); - this.model.notifyPropertyChange(JPA_LIBRARY, IDataModel.ENABLE_CHG); - } - if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) { - this.model.setBooleanProperty(LIST_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); - } - if (propertyName.equals(LIST_ANNOTATED_CLASSES)) { - this.model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue()); - } - return ok; - } - - private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0]; - - @Override - public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { - if (propertyName.equals(PLATFORM_ID)) { - return CollectionTools.array( - new TransformationIterator<String, DataModelPropertyDescriptor>( - JpaPlatformRegistry.instance().jpaPlatformIds()) { - @Override - protected DataModelPropertyDescriptor transform(String platformId) { - return platformIdPropertyDescriptor(platformId); - } - }, - EMPTY_DMPD_ARRAY); - } - if (propertyName.equals(CONNECTION)) { - return CollectionTools.array( - new TransformationIterator<String, DataModelPropertyDescriptor>( - new CompositeIterator<String>( - null, - this.getConnectionProfileFactory().connectionProfileNames())) { - @Override - protected DataModelPropertyDescriptor transform(String next) { - return connectionPropertyDescriptor(next); - } - }, - EMPTY_DMPD_ARRAY); - } - if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return CollectionTools.array( - new TransformationIterator<String, DataModelPropertyDescriptor>(schemaNames()) { - @Override - protected DataModelPropertyDescriptor transform(String next) { - return new DataModelPropertyDescriptor(next); - } - }, - EMPTY_DMPD_ARRAY); - } - if (propertyName.equals(JPA_LIBRARY)) { - String[] libraries = CollectionTools.sort(JavaCore.getUserLibraryNames()); - DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[libraries.length + 1]; - descriptors[0] = new DataModelPropertyDescriptor("", RUNTIME_NONE); //$NON-NLS-1$ - - int i = 1; - for (String library : libraries) { - descriptors[i++] = new DataModelPropertyDescriptor(library, library); - } - return descriptors; - } - - return super.getValidPropertyDescriptors(propertyName); - } - - @Override - public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) { - if (propertyName.equals(PLATFORM_ID)) { - return platformIdPropertyDescriptor(getStringProperty(PLATFORM_ID)); - } - if (propertyName.equals(CONNECTION)) { - return connectionPropertyDescriptor(getStringProperty(CONNECTION)); - } - return super.getPropertyDescriptor(propertyName); - } - - DataModelPropertyDescriptor platformIdPropertyDescriptor(String platformId) { - return new DataModelPropertyDescriptor( - platformId, JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId)); - } - - DataModelPropertyDescriptor connectionPropertyDescriptor(String connection) { - return StringTools.stringIsEmpty(connection) ? - new DataModelPropertyDescriptor(null, JptCoreMessages.NONE) - : - new DataModelPropertyDescriptor(connection); - } - - @Override - public IStatus validate(String name) { - if (name.equals(PLATFORM_ID)) { - return this.validatePlatformId(this.getStringProperty(name)); - } - if (name.equals(CONNECTION)) { - return this.validateConnectionName(this.getStringProperty(name)); - } - if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA) - || name.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) { - return this.validateUserOverrideDefaultSchema(); - } - if (name.equals(USE_SERVER_JPA_IMPLEMENTATION)) { - return this.validateJpaLibrary(this.getBooleanProperty(name)); - } - if (name.equals(DISCOVER_ANNOTATED_CLASSES)) { - return this.validatePersistentClassManagement(this.getBooleanProperty(name)); - } - return super.validate(name); - } - - private IRuntime runtime() { - return (IRuntime) this.getProperty(RUNTIME); - } - - private boolean runtimeSupportsEjb30(IRuntime runtime) { - IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$ - return (runtime == null) ? false : runtime.supports(ejb30); - } - - private String getConnectionName() { - return this.getStringProperty(CONNECTION); - } - - private ConnectionProfile getConnectionProfile() { - return this.buildConnectionProfile(this.getConnectionName()); - } - - 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(); - } - - private ConnectionProfile buildConnectionProfile(String name) { - return this.getConnectionProfileFactory().buildConnectionProfile(name); - } - - private boolean connectionIsActive() { - return this.connectionIsActive(this.getConnectionName()); - } - - private boolean connectionIsActive(String connectionName) { - ConnectionProfile cp = this.buildConnectionProfile(connectionName); - return (cp != null) && cp.isActive(); - } - - private String getDefaultSchemaName() { - ConnectionProfile cp = this.getConnectionProfile(); - if (cp == null) { - return null; - } - Database db = cp.getDatabase(); - if (db == null) { - return null; - } - Schema schema = db.getDefaultSchema(); - return (schema == null) ? null : schema.getName(); - } - - private List<String> buildSortedSchemaNames() { - ConnectionProfile cp = this.getConnectionProfile(); - if (cp == null) { - return Collections.emptyList(); - } - Database db = cp.getDatabase(); - if (db == null) { - return Collections.emptyList(); - } - return CollectionTools.sort(CollectionTools.list(db.schemaNames())); - } - - private Iterator<String> schemaNames() { - String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA); - List<String> schemaNames = this.buildSortedSchemaNames(); - - if (StringTools.stringIsEmpty(setValue) || schemaNames.contains(setValue)) { - return schemaNames.iterator(); - } - return new CompositeIterator<String>(setValue, schemaNames.iterator()); - } - - - // ********** validation ********** - - private IStatus validatePlatformId(String platformId) { - return StringTools.stringIsEmpty(platformId) ? - PLATFORM_NOT_SPECIFIED_STATUS - : - OK_STATUS; - } - - private IStatus validateConnectionName(String connectionName) { - return StringTools.stringIsEmpty(connectionName) ? - OK_STATUS - : - this.getConnectionStatus(connectionName); - } - - private IStatus getConnectionStatus(String connectionName) { - return this.connectionIsActive(connectionName) ? - OK_STATUS - : - CONNECTION_NOT_CONNECTED_STATUS; - } - - private IStatus validateUserOverrideDefaultSchema() { - if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA))) { - return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS; - } - } - return OK_STATUS; - } - - private IStatus validateJpaLibrary(boolean useServerJpaImplementation) { - if (useServerJpaImplementation) { - IRuntime runtime = this.runtime(); - if (runtime == null) { - return RUNTIME_NOT_SPECIFIED_STATUS; - } - if ( ! this.runtimeSupportsEjb30(runtime)) { - return RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS; - } - } else { - if (StringTools.stringIsEmpty(this.getStringProperty(JPA_LIBRARY))) { - return LIBRARY_NOT_SPECIFIED_STATUS; - } - } - return OK_STATUS; - } - - private IStatus validatePersistentClassManagement(boolean discoverAnnotatedClasses) { - // TODO warning if "discovery" is used, but no runtime specified ?? - 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 f9c295e591..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetInstallDelegate.java +++ /dev/null @@ -1,133 +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.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.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathAttribute; -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.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil; -import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants; -import org.eclipse.jst.j2ee.project.EarUtilities; -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, 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; - this.configureClasspath(javaProject, dataModel, monitor); - - // project settings - JptCorePlugin.setJpaPlatformId(project, dataModel.getStringProperty(PLATFORM_ID)); - JptCorePlugin.setConnectionProfileName(project, dataModel.getStringProperty(CONNECTION)); - if (dataModel.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - JptCorePlugin.setUserOverrideDefaultSchemaName(project, dataModel.getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA)); - } - JptCorePlugin.setDiscoverAnnotatedClasses(project, dataModel.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES)); - - // defaults settings - JptCorePlugin.setDefaultJpaPlatformId(dataModel.getStringProperty(PLATFORM_ID)); - - monitor.worked(1); - } - - private void configureClasspath(IJavaProject javaProject, IDataModel dataModel, IProgressMonitor monitor) throws CoreException { - boolean useServerLibrary = dataModel.getBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION); - if (useServerLibrary) { - return; - } - - String jpaLibrary = dataModel.getStringProperty(JPA_LIBRARY); - if (StringTools.stringIsEmpty(jpaLibrary)) { - return; - } - - // build the JPA library to be added to the classpath - IClasspathAttribute[] attributes = this.buildClasspathAttributes(javaProject.getProject()); - IClasspathEntry jpaLibraryEntry = - JavaCore.newContainerEntry( - new Path(JavaCore.USER_LIBRARY_CONTAINER_ID + "/" + jpaLibrary), - null, attributes, true - ); - - // if the JPA library is already there, do nothing - IClasspathEntry[] classpath = javaProject.getRawClasspath(); - if (CollectionTools.contains(classpath, jpaLibraryEntry)) { - return; - } - - // add the JPA library to the classpath - int len = classpath.length; - IClasspathEntry[] newClasspath = new IClasspathEntry[len + 1]; - System.arraycopy(classpath, 0, newClasspath, 0, len); - newClasspath[len] = jpaLibraryEntry; - javaProject.setRawClasspath(newClasspath, monitor); - } - - private static final IClasspathAttribute[] EMPTY_CLASSPATH_ATTRIBUTES = new IClasspathAttribute[0]; - - private IClasspathAttribute[] buildClasspathAttributes(IProject project) { - boolean webApp = JptCorePlugin.projectHasWebFacet(project); - if ( ! webApp && this.projectIsStandalone(project)) { - return EMPTY_CLASSPATH_ATTRIBUTES; - } - return new IClasspathAttribute[] { - JavaCore.newClasspathAttribute( - IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY, - ClasspathDependencyUtil.getDefaultRuntimePath(webApp).toString() - ) - }; - } - - private boolean projectIsStandalone(IProject project) { - return EarUtilities.isStandaloneProject(project); - } - - 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/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 8a4d527887..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java +++ /dev/null @@ -1,471 +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.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 CollectionTools.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 CollectionTools.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); - } - - private 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); - } - - private 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)); - } - if (getExistingOrmFile() != null) { - return new Status( - IStatus.ERROR, JptCorePlugin.PLUGIN_ID, - JptCoreMessages.VALIDATE_ORM_FILE_ALREADY_EXISTS); - } - return Status.OK_STATUS; - } - - private 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 - private IProject getProject() { - String projectName = (String) model.getProperty(PROJECT_NAME); - if (StringTools.stringIsEmpty(projectName)) { - return null; - } - return ProjectUtilities.getProject(projectName); - } - - private 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 - private 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 - */ - private 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 - */ - private 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 - */ - private 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 - */ - private 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; - } - - private 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; - } - - private PersistenceUnit getDefaultPersistenceUnit() { - JpaProject jpaProject = getJpaProject(); - if (jpaProject == null) { - return null; - } - PersistenceXml persistenceXml = jpaProject.getRootContext().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(); - } - - private PersistenceUnit getPersistenceUnit() { - String pUnitName = getStringProperty(PERSISTENCE_UNIT); - JpaProject jpaProject = - (StringTools.stringIsEmpty(pUnitName)) ? null : getJpaProject(); - PersistenceXml persistenceXml = - (jpaProject == null) ? null : jpaProject.getRootContext().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; - } - - private Iterator<IProject> jpaIProjects() { - return new FilteringIterator<IProject, IProject>(CollectionTools.iterator(ProjectUtilities.getAllProjects())) { - @Override - protected boolean accept(IProject project) { - try { - return FacetedProjectFramework.hasProjectFacet(project, JptCorePlugin.FACET_ID); - } - catch (CoreException ce) { - return false; - } - } - }; - } - - private Iterator<PersistenceUnit> persistenceUnits() { - return new CompositeIterator<PersistenceUnit>( - new TransformationIterator<IProject, Iterator<PersistenceUnit>>(jpaIProjects()) { - @Override - protected Iterator<PersistenceUnit> transform(IProject jpaIProject) { - JpaProject jpaProject = JptCorePlugin.getJpaProject(jpaIProject); - PersistenceXml persistenceXml = - (jpaProject == null) ? null : jpaProject.getRootContext().getPersistenceXml(); - Persistence persistence = - (persistenceXml == null) ? null : persistenceXml.getPersistence(); - return (persistence == null) ? EmptyIterator.<PersistenceUnit>instance() : persistence.persistenceUnits(); - } - }); - } - - private 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 bbacaab32d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/OrmFileCreationOperation.java +++ /dev/null @@ -1,166 +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 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.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.persistence.PersistenceArtifactEdit; -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 - createOrmXml(folder); - // Add orm file to persistence unit if specified - addOrmXmlToPersistenceXml(); - return OK_STATUS; - } - - private 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"); - } - return project; - } - - private JpaProject getJpaProject() throws ExecutionException { - IProject project = getProject(); - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - if (jpaProject == null) { - throw new ExecutionException("Project does not have JPA content"); - } - return jpaProject; - } - - private PersistenceUnit getPersistenceUnit() throws ExecutionException { - String pUnitName = getDataModel().getStringProperty(PERSISTENCE_UNIT); - JpaProject jpaProject = getJpaProject(); - PersistenceXml persistenceXml = jpaProject.getRootContext().getPersistenceXml(); - if (persistenceXml == null) { - throw new ExecutionException("Project does not have a persistence.xml file"); - } - Persistence persistence = persistenceXml.getPersistence(); - if (persistence == null) { - throw new ExecutionException("persistence.xml does not have a persistence node."); - } - 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 + "\'"); - } - - /** - * 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 - private 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); - } - } - // Return the source folder - return folder; - } - - @SuppressWarnings("unchecked") - private void createOrmXml(IFolder folder) throws ExecutionException { - String filePath = getDataModel().getStringProperty(FILE_PATH); - IFile file = folder.getFile(new Path(filePath)); - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForWrite(getProject()); - OrmResource ormResource = oae.getResource(file); - XmlEntityMappings entityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - entityMappings.setVersion("1.0"); - ormResource.getContents().add(entityMappings); - - AccessType defaultAccess = (AccessType) getDataModel().getProperty(DEFAULT_ACCESS); - if (defaultAccess != null) { - XmlPersistenceUnitMetadata puMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - entityMappings.setPersistenceUnitMetadata(puMetadata); - XmlPersistenceUnitDefaults puDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - puMetadata.setPersistenceUnitDefaults(puDefaults); - puDefaults.setAccess(defaultAccess); - } - - oae.save(null); - oae.dispose(); - } - - private void addOrmXmlToPersistenceXml() throws ExecutionException { - if (! getDataModel().getBooleanProperty(ADD_TO_PERSISTENCE_UNIT)) { - return; - } - - String filePath = getDataModel().getStringProperty(FILE_PATH); - PersistenceUnit pUnit = getPersistenceUnit(); - 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()); - - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(getProject()); - pae.getResource((IFile) pUnit.getResource()); - - pae.save(null); - pae.dispose(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericEntityGeneratorDatabaseAnnotationNameBuilder.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericEntityGeneratorDatabaseAnnotationNameBuilder.java deleted file mode 100644 index fc98a9926f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/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.platform; - -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.getAnnotationIdentifier(entityName); - } - - public String buildColumnAnnotationName(String attributeName, Column column) { - return column.getAnnotationIdentifier(attributeName); - } - - public String buildJoinColumnAnnotationName(String attributeName, ForeignKey foreignKey) { - return foreignKey.getJoinColumnAnnotationIdentifier(attributeName); - } - - public String buildJoinColumnAnnotationName(Column column) { - return column.getAnnotationIdentifier(); - } - - public String buildJoinTableAnnotationName(Table table) { - return table.getAnnotationIdentifier(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationProvider.java deleted file mode 100644 index dd94860a5b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationProvider.java +++ /dev/null @@ -1,325 +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.platform; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.internal.resource.java.AssociationOverrideImpl.AssociationOverrideAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AssociationOverridesImpl.AssociationOverridesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AttributeOverrideImpl.AttributeOverrideAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.AttributeOverridesImpl.AttributeOverridesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.BasicImpl.BasicAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ColumnImpl.ColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.DiscriminatorColumnImpl.DiscriminatorColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.DiscriminatorValueImpl.DiscriminatorValueAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddableImpl.EmbeddableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddedIdImpl.EmbeddedIdAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EmbeddedImpl.EmbeddedAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EntityImpl.EntityAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.EnumeratedImpl.EnumeratedAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.GeneratedValueImpl.GeneratedValueAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.IdClassImpl.IdClassAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.IdImpl.IdAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.InheritanceImpl.InheritanceAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinColumnImpl.JoinColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinColumnsImpl.JoinColumnsAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.JoinTableImpl.JoinTableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.LobImpl.LobAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ManyToManyImpl.ManyToManyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.ManyToOneImpl.ManyToOneAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.MapKeyImpl.MapKeyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.MappedSuperclassImpl.MappedSuperclassAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedNativeQueriesImpl.NamedNativeQueriesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedNativeQueryImpl.NamedNativeQueryAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedQueriesImpl.NamedQueriesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.NamedQueryImpl.NamedQueryAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OneToManyImpl.OneToManyAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OneToOneImpl.OneToOneAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.OrderByImpl.OrderByAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.PrimaryKeyJoinColumnImpl.PrimaryKeyJoinColumnAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.PrimaryKeyJoinColumnsImpl.PrimaryKeyJoinColumnsAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SecondaryTableImpl.SecondaryTableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SecondaryTablesImpl.SecondaryTablesAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.SequenceGeneratorImpl.SequenceGeneratorAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TableGeneratorImpl.TableGeneratorAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TableImpl.TableAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TemporalImpl.TemporalAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.TransientImpl.TransientAnnotationDefinition; -import org.eclipse.jpt.core.internal.resource.java.VersionImpl.VersionAnnotationDefinition; -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.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationListIterator; - -public class GenericJpaAnnotationProvider implements JpaAnnotationProvider -{ - /** - * Ordered list of possible type mapping annotations. Ordered because this - * is used to determine the mapping in the case where 2 mapping annotations exist - */ - private List<AnnotationDefinition> typeMappingAnnotationDefinitions; - - private Collection<AnnotationDefinition> typeAnnotationDefinitions; - - /** - * Ordered list of possible attribute mapping annotations. Ordered because this - * is used to determine the mapping in the case where 2 mapping annotations exist - */ - private List<AnnotationDefinition> attributeMappingAnnotationDefinitions; - - private Collection<AnnotationDefinition> attributeAnnotationDefinitions; - - - protected GenericJpaAnnotationProvider() { - super(); - } - - - protected ListIterator<AnnotationDefinition> typeMappingAnnotationDefinitions() { - if (this.typeMappingAnnotationDefinitions == null) { - this.typeMappingAnnotationDefinitions = new ArrayList<AnnotationDefinition>(); - this.addTypeMappingAnnotationDefinitionsTo(this.typeMappingAnnotationDefinitions); - } - return new CloneListIterator<AnnotationDefinition>(this.typeMappingAnnotationDefinitions); - } - - /** - * Override this to specify more or different type mapping definitions. - * The default includes the JPA spec-defined type mappings of - * Embeddable, Entity, MappedSuperclass - */ - protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(EmbeddableAnnotationDefinition.instance()); - definitions.add(EntityAnnotationDefinition.instance()); - definitions.add(MappedSuperclassAnnotationDefinition.instance()); - } - - protected Iterator<AnnotationDefinition> typeAnnotationDefinitions() { - if (this.typeAnnotationDefinitions == null) { - this.typeAnnotationDefinitions = new ArrayList<AnnotationDefinition>(); - this.addTypeAnnotationDefinitionsTo(this.typeAnnotationDefinitions); - } - return new CloneIterator<AnnotationDefinition>(this.typeAnnotationDefinitions); - } - - /** - * Override this to specify more or different type annotation definitions. - * The default includes the JPA spec-defined annotations. - */ - protected void addTypeAnnotationDefinitionsTo(Collection<AnnotationDefinition> definitions) { - definitions.add(AssociationOverrideAnnotationDefinition.instance()); - definitions.add(AssociationOverridesAnnotationDefinition.instance()); - definitions.add(AttributeOverrideAnnotationDefinition.instance()); - definitions.add(AttributeOverrideAnnotationDefinition.instance()); - definitions.add(AttributeOverridesAnnotationDefinition.instance()); - definitions.add(DiscriminatorColumnAnnotationDefinition.instance()); - definitions.add(DiscriminatorValueAnnotationDefinition.instance()); - definitions.add(IdClassAnnotationDefinition.instance()); - definitions.add(InheritanceAnnotationDefinition.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()); - } - - protected ListIterator<AnnotationDefinition> attributeMappingAnnotationDefinitions() { - if (this.attributeMappingAnnotationDefinitions == null) { - this.attributeMappingAnnotationDefinitions = new ArrayList<AnnotationDefinition>(); - this.addAttributeMappingAnnotationDefinitionsTo(this.attributeMappingAnnotationDefinitions); - } - return new CloneListIterator<AnnotationDefinition>(this.attributeMappingAnnotationDefinitions); - } - - /** - * Override this to specify more or different attribute mapping definitions. - * The default includes the JPA spec-defined attribute mappings of - * Basic, Id, Transient OneToOne, OneToMany, ManyToOne, ManyToMany, Embedded, EmbeddedId, Version. - */ - protected void addAttributeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(BasicAnnotationDefinition.instance()); - definitions.add(EmbeddedAnnotationDefinition.instance()); - definitions.add(EmbeddedIdAnnotationDefinition.instance()); - definitions.add(IdAnnotationDefinition.instance()); - definitions.add(ManyToManyAnnotationDefinition.instance()); - definitions.add(ManyToOneAnnotationDefinition.instance()); - definitions.add(OneToManyAnnotationDefinition.instance()); - definitions.add(OneToOneAnnotationDefinition.instance()); - definitions.add(TransientAnnotationDefinition.instance()); - definitions.add(VersionAnnotationDefinition.instance()); - } - - protected Iterator<AnnotationDefinition> attributeAnnotationDefinitions() { - if (this.attributeAnnotationDefinitions == null) { - this.attributeAnnotationDefinitions = new ArrayList<AnnotationDefinition>(); - this.addAttributeAnnotationDefinitionsTo(this.attributeAnnotationDefinitions); - } - return new CloneIterator<AnnotationDefinition>(this.attributeAnnotationDefinitions); - } - - /** - * Override this to specify more or different attribute annotation definitions. - * The default includes the JPA spec-defined annotations. - */ - protected void addAttributeAnnotationDefinitionsTo(Collection<AnnotationDefinition> definitions) { - definitions.add(AssociationOverrideAnnotationDefinition.instance()); - definitions.add(AssociationOverridesAnnotationDefinition.instance()); - definitions.add(AttributeOverrideAnnotationDefinition.instance()); - definitions.add(AttributeOverridesAnnotationDefinition.instance()); - definitions.add(ColumnAnnotationDefinition.instance()); - definitions.add(EnumeratedAnnotationDefinition.instance()); - definitions.add(GeneratedValueAnnotationDefinition.instance()); - definitions.add(JoinColumnAnnotationDefinition.instance()); - definitions.add(JoinColumnsAnnotationDefinition.instance()); - definitions.add(JoinTableAnnotationDefinition.instance()); - definitions.add(LobAnnotationDefinition.instance()); - definitions.add(MapKeyAnnotationDefinition.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()); - } - - //********************* IJpaPlatform implementation ************************* - - public Annotation buildTypeMappingAnnotation(JavaResourcePersistentType parent, Type type, String mappingAnnotationName) { - AnnotationDefinition annotationDefinition = typeMappingAnnotationDefinition(mappingAnnotationName); - return annotationDefinition.buildAnnotation(parent, type); - } - - public Annotation buildNullTypeMappingAnnotation(JavaResourcePersistentType parent, Type type, String mappingAnnotationName) { - AnnotationDefinition annotationDefinition = typeMappingAnnotationDefinition(mappingAnnotationName); - return annotationDefinition.buildNullAnnotation(parent, type); - } - - public Annotation buildTypeAnnotation(JavaResourcePersistentType parent, Type type, String annotationName) { - AnnotationDefinition annotationDefinition = typeAnnotationDefinition(annotationName); - return annotationDefinition.buildAnnotation(parent, type); - } - - public Annotation buildNullTypeAnnotation(JavaResourcePersistentType parent, Type type, String annotationName) { - AnnotationDefinition annotationDefinition = typeAnnotationDefinition(annotationName); - return annotationDefinition.buildNullAnnotation(parent, type); - } - - public ListIterator<String> typeMappingAnnotationNames() { - return new TransformationListIterator<AnnotationDefinition, String>(typeMappingAnnotationDefinitions()) { - @Override - protected String transform(AnnotationDefinition next) { - return next.getAnnotationName(); - } - }; - } - - public Iterator<String> typeAnnotationNames() { - return new TransformationIterator<AnnotationDefinition, String>(typeAnnotationDefinitions()) { - @Override - protected String transform(AnnotationDefinition next) { - return next.getAnnotationName(); - } - }; - } - - public Annotation buildAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String mappingAnnotationName) { - AnnotationDefinition annotationDefinition = attributeMappingAnnotationDefinition(mappingAnnotationName); - return annotationDefinition.buildAnnotation(parent, attribute); - } - - public Annotation buildNullAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName) { - AnnotationDefinition annotationDefinition = attributeMappingAnnotationDefinition(annotationName); - return annotationDefinition.buildNullAnnotation(parent, attribute); - } - - public Annotation buildAttributeAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName) { - AnnotationDefinition annotationDefinition = attributeAnnotationDefinition(annotationName); - return annotationDefinition.buildAnnotation(parent, attribute); - } - - public Annotation buildNullAttributeAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName) { - AnnotationDefinition annotationDefinition = attributeAnnotationDefinition(annotationName); - return annotationDefinition.buildNullAnnotation(parent, attribute); - } - - public ListIterator<String> attributeMappingAnnotationNames() { - return new TransformationListIterator<AnnotationDefinition, String>(attributeMappingAnnotationDefinitions()) { - @Override - protected String transform(AnnotationDefinition next) { - return next.getAnnotationName(); - } - }; - } - - public Iterator<String> attributeAnnotationNames() { - return new TransformationIterator<AnnotationDefinition, String>(attributeAnnotationDefinitions()) { - @Override - protected String transform(AnnotationDefinition next) { - return next.getAnnotationName(); - } - }; - } - - private AnnotationDefinition typeMappingAnnotationDefinition(String mappingAnnotationName) { - for (ListIterator<AnnotationDefinition> i = typeMappingAnnotationDefinitions(); i.hasNext(); ) { - AnnotationDefinition definition = i.next(); - if (definition.getAnnotationName().equals(mappingAnnotationName)) { - return definition; - } - } - throw new IllegalArgumentException(mappingAnnotationName + " is an unsupported type mapping annotation"); - } - - private AnnotationDefinition typeAnnotationDefinition(String annotationName) { - for (Iterator<AnnotationDefinition> i = typeAnnotationDefinitions(); i.hasNext(); ) { - AnnotationDefinition definition = i.next(); - if (definition.getAnnotationName().equals(annotationName)) { - return definition; - } - } - throw new IllegalArgumentException(annotationName + " is an unsupported type annotation"); - } - - private AnnotationDefinition attributeMappingAnnotationDefinition(String mappingAnnotationName) { - for (ListIterator<AnnotationDefinition> i = attributeMappingAnnotationDefinitions(); i.hasNext(); ) { - AnnotationDefinition definition = i.next(); - if (definition.getAnnotationName().equals(mappingAnnotationName)) { - return definition; - } - } - throw new IllegalArgumentException(mappingAnnotationName + " is an unsupported attribute mapping annotation"); - } - - private AnnotationDefinition attributeAnnotationDefinition(String annotationName) { - for (Iterator<AnnotationDefinition> i = attributeAnnotationDefinitions(); i.hasNext(); ) { - AnnotationDefinition definition = i.next(); - if (definition.getAnnotationName().equals(annotationName)) { - return definition; - } - } - throw new IllegalArgumentException(annotationName + " is an unsupported attribute annotation"); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java deleted file mode 100644 index ed503de644..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java +++ /dev/null @@ -1,620 +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.platform; - -import java.io.IOException; -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.jdt.core.JavaCore; -import org.eclipse.jpt.core.JpaDataSource; -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaColumn; -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.JavaGeneratedValue; -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.JavaJpaContextNode; -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.JavaNamedColumn; -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.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.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.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.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.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.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.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.OrmUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.GenericJpaDataSource; -import org.eclipse.jpt.core.internal.GenericJpaFile; -import org.eclipse.jpt.core.internal.GenericJpaProject; -import org.eclipse.jpt.core.internal.context.GenericRootContextNode; -import org.eclipse.jpt.core.internal.context.java.GenericJavaAssociationOverride; -import org.eclipse.jpt.core.internal.context.java.GenericJavaAttributeOverride; -import org.eclipse.jpt.core.internal.context.java.GenericJavaBasicMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaColumn; -import org.eclipse.jpt.core.internal.context.java.GenericJavaDiscriminatorColumn; -import org.eclipse.jpt.core.internal.context.java.GenericJavaEmbeddable; -import org.eclipse.jpt.core.internal.context.java.GenericJavaEmbeddedIdMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaEmbeddedMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaEntity; -import org.eclipse.jpt.core.internal.context.java.GenericJavaGeneratedValue; -import org.eclipse.jpt.core.internal.context.java.GenericJavaIdMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaJoinColumn; -import org.eclipse.jpt.core.internal.context.java.GenericJavaJoinTable; -import org.eclipse.jpt.core.internal.context.java.GenericJavaManyToManyMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaManyToOneMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaMappedSuperclass; -import org.eclipse.jpt.core.internal.context.java.GenericJavaNamedNativeQuery; -import org.eclipse.jpt.core.internal.context.java.GenericJavaNamedQuery; -import org.eclipse.jpt.core.internal.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaOneToManyMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaOneToOneMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.GenericJavaPersistentType; -import org.eclipse.jpt.core.internal.context.java.GenericJavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.context.java.GenericJavaQueryHint; -import org.eclipse.jpt.core.internal.context.java.GenericJavaSecondaryTable; -import org.eclipse.jpt.core.internal.context.java.GenericJavaSequenceGenerator; -import org.eclipse.jpt.core.internal.context.java.GenericJavaTable; -import org.eclipse.jpt.core.internal.context.java.GenericJavaTableGenerator; -import org.eclipse.jpt.core.internal.context.java.GenericJavaTransientMapping; -import org.eclipse.jpt.core.internal.context.java.GenericJavaUniqueConstraint; -import org.eclipse.jpt.core.internal.context.java.GenericJavaVersionMapping; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericEntityMappings; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmAssociationOverride; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmAttributeOverride; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmBasicMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmColumn; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmDiscriminatorColumn; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmEmbeddable; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmEmbeddedIdMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmEmbeddedMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmEntity; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmGeneratedValue; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmIdMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmJoinColumn; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmJoinTable; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmManyToManyMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmManyToOneMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmMappedSuperclass; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmNamedNativeQuery; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmNamedQuery; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmNullAttributeMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmOneToManyMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmOneToOneMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmQueryHint; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmSecondaryTable; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmSequenceGenerator; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmTable; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmTableGenerator; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmTransientMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmUniqueConstraint; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmVersionMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericPersistenceUnitDefaults; -import org.eclipse.jpt.core.internal.context.orm.GenericPersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.context.orm.OrmXmlImpl; -import org.eclipse.jpt.core.internal.context.persistence.GenericClassRef; -import org.eclipse.jpt.core.internal.context.persistence.GenericMappingFileRef; -import org.eclipse.jpt.core.internal.context.persistence.GenericPersistence; -import org.eclipse.jpt.core.internal.context.persistence.GenericPersistenceUnit; -import org.eclipse.jpt.core.internal.context.persistence.GenericPersistenceXml; -import org.eclipse.jpt.core.internal.context.persistence.GenericProperty; -import org.eclipse.jpt.core.internal.resource.java.JavaResourceModelImpl; -import org.eclipse.jpt.core.internal.utility.jdt.DefaultAnnotationEditFormatter; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.orm.OrmResourceModel; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.resource.persistence.PersistenceResourceModel; -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; - -public class GenericJpaFactory implements JpaFactory -{ - protected GenericJpaFactory() { - super(); - } - - - // **************** Core objects ****************************************** - - public JpaProject buildJpaProject(JpaProject.Config config) throws CoreException { - return new GenericJpaProject(config); - } - - public JpaDataSource buildJpaDataSource(JpaProject jpaProject, String connectionProfileName) { - return new GenericJpaDataSource(jpaProject, connectionProfileName); - } - - public JpaFile buildJpaFile(JpaProject jpaProject, IFile file, ResourceModel resourceModel) { - return new GenericJpaFile(jpaProject, file, resourceModel); - } - - - // **************** Resource objects ************************************** - - public boolean hasRelevantContent(IFile file) { - if (! JavaCore.create(file.getProject()).isOnClasspath(file)) { - return false; - } - IContentType contentType = this.contentType(file); - if (contentType == null) { - return false; - } - String contentTypeId = contentType.getId(); - return supportsContentType(contentTypeId); - } - - protected boolean supportsContentType(String contentTypeId) { - return contentTypeId.equals(JavaCore.JAVA_SOURCE_CONTENT_TYPE) - || contentTypeId.equals(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE) - || contentTypeId.equals(JptCorePlugin.ORM_XML_CONTENT_TYPE); - } - - public ResourceModel buildResourceModel(JpaProject jpaProject, IFile file) { - if (! JavaCore.create(jpaProject.getProject()).isOnClasspath(file)) { - throw new IllegalArgumentException("The file" + file + " is not on the project classpath"); - } - IContentType contentType = this.contentType(file); - if (contentType == null) { - throw new IllegalArgumentException("The file" + file + " does not have a supported content type"); - } - String contentTypeId = contentType.getId(); - return buildResourceModel(jpaProject, file, contentTypeId); - } - - protected ResourceModel buildResourceModel(JpaProject jpaProject, IFile file, String contentTypeId) { - if (JavaCore.JAVA_SOURCE_CONTENT_TYPE.equals(contentTypeId)) { - return buildJavaResourceModel(jpaProject, file); - } - else if (JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE.equals(contentTypeId)) { - return buildPersistenceResourceModel(file); - } - else if (JptCorePlugin.ORM_XML_CONTENT_TYPE.equals(contentTypeId)) { - return buildOrmResourceModel(file); - } - - return null; - } - - protected ResourceModel buildJavaResourceModel(JpaProject jpaProject, IFile file) { - return new JavaResourceModelImpl( - file, jpaProject.getJpaPlatform().getAnnotationProvider(), - jpaProject.getModifySharedDocumentCommandExecutorProvider(), - DefaultAnnotationEditFormatter.instance()); - } - - protected ResourceModel buildPersistenceResourceModel(IFile file) { - return new PersistenceResourceModel(file); - } - - protected ResourceModel buildOrmResourceModel(IFile file) { - return new OrmResourceModel(file); - } - - // attempting to get the contentType based on the file contents. - // have to check the file contents instead of just the file name - // because for xml we base it on the rootElement name - private IContentType contentType(IFile file) { - try { - return Platform.getContentTypeManager().findContentTypeFor(file.getContents(), file.getName()); - } - catch (IOException ex) { - JptCorePlugin.log(ex); - } - catch (CoreException ex) { - JptCorePlugin.log(ex); - } - return null; - } - - - // **************** Context objects *************************************** - - public JpaRootContextNode buildRootContext(JpaProject parent) { - return new GenericRootContextNode(parent); - } - - public PersistenceXml buildPersistenceXml(JpaRootContextNode parent, PersistenceResource persistenceResource) { - return new GenericPersistenceXml(parent, persistenceResource); - } - - public OrmXml buildOrmXml(MappingFileRef parent, OrmResource ormResource) { - return new OrmXmlImpl(parent, ormResource); - } - - 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 PersistenceUnitDefaults buildPersistenceUnitDefaults(PersistenceUnitMetadata parent, XmlEntityMappings xmlEntityMappings) { - return new GenericPersistenceUnitDefaults(parent, xmlEntityMappings); - } - - public Persistence buildPersistence(PersistenceXml parent, XmlPersistence xmlPersistence) { - return new GenericPersistence(parent, xmlPersistence); - } - - public PersistenceUnit buildPersistenceUnit(Persistence parent, XmlPersistenceUnit persistenceUnit) { - return new GenericPersistenceUnit(parent, persistenceUnit); - } - - public MappingFileRef buildMappingFileRef(PersistenceUnit parent, XmlMappingFileRef xmlMappingFileRef) { - return new GenericMappingFileRef(parent, xmlMappingFileRef); - } - - 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 Property buildProperty(PersistenceUnit parent, XmlProperty xmlProperty) { - return new GenericProperty(parent, xmlProperty); - } - - public JavaPersistentType buildJavaPersistentType(JpaContextNode parent, JavaResourcePersistentType resourcePersistentType) { - return new GenericJavaPersistentType(parent, resourcePersistentType); - } - - public JavaPersistentAttribute buildJavaPersistentAttribute(JavaPersistentType parent) { - return new GenericJavaPersistentAttribute(parent); - } - - 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 JavaColumn buildJavaColumn(JavaJpaContextNode parent, JavaColumn.Owner owner) { - return new GenericJavaColumn(parent, owner); - } - - public JavaDiscriminatorColumn buildJavaDiscriminatorColumn(JavaEntity parent, JavaNamedColumn.Owner owner) { - return new GenericJavaDiscriminatorColumn(parent, owner); - } - - public JavaJoinColumn buildJavaJoinColumn(JavaJpaContextNode parent, JavaJoinColumn.Owner owner) { - return new GenericJavaJoinColumn(parent, owner); - } - - public JavaJoinTable buildJavaJoinTable(JavaRelationshipMapping 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 JavaSequenceGenerator buildJavaSequenceGenerator(JavaJpaContextNode parent) { - return new GenericJavaSequenceGenerator(parent); - } - - public JavaTableGenerator buildJavaTableGenerator(JavaJpaContextNode parent) { - return new GenericJavaTableGenerator(parent); - } - - public JavaGeneratedValue buildJavaGeneratedValue(JavaAttributeMapping parent) { - return new GenericJavaGeneratedValue(parent); - } - - public JavaPrimaryKeyJoinColumn buildJavaPrimaryKeyJoinColumn(JavaJpaContextNode parent, JavaBaseJoinColumn.Owner owner) { - return new GenericJavaPrimaryKeyJoinColumn(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 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 OrmPersistentType buildOrmPersistentType(EntityMappings parent, String mappingKey) { - return new GenericOrmPersistentType(parent, mappingKey); - } - - public OrmEntity buildOrmEntity(OrmPersistentType parent) { - return new GenericOrmEntity(parent); - } - - public OrmMappedSuperclass buildOrmMappedSuperclass(OrmPersistentType parent) { - return new GenericOrmMappedSuperclass(parent); - } - - public OrmEmbeddable buildOrmEmbeddable(OrmPersistentType parent) { - return new GenericOrmEmbeddable(parent); - } - - public OrmPersistentAttribute buildOrmPersistentAttribute(OrmPersistentType parent, String mappingKey) { - return new GenericOrmPersistentAttribute(parent, mappingKey); - } - - public OrmTable buildOrmTable(OrmEntity parent) { - return new GenericOrmTable(parent); - } - - public OrmSecondaryTable buildOrmSecondaryTable(OrmEntity parent, XmlSecondaryTable xmlSecondaryTable) { - return new GenericOrmSecondaryTable(parent, xmlSecondaryTable); - } - - public OrmPrimaryKeyJoinColumn buildOrmPrimaryKeyJoinColumn(OrmJpaContextNode parent, OrmBaseJoinColumn.Owner owner) { - return new GenericOrmPrimaryKeyJoinColumn(parent, owner); - } - - public OrmJoinTable buildOrmJoinTable(OrmRelationshipMapping parent) { - return new GenericOrmJoinTable(parent); - } - - public OrmJoinColumn buildOrmJoinColumn(OrmJpaContextNode parent, OrmJoinColumn.Owner owner) { - return new GenericOrmJoinColumn(parent, owner); - } - - public OrmAttributeOverride buildOrmAttributeOverride(OrmJpaContextNode parent, AttributeOverride.Owner owner, XmlAttributeOverride xmlAttributeOverride) { - return new GenericOrmAttributeOverride(parent, owner, xmlAttributeOverride); - } - - public OrmAssociationOverride buildOrmAssociationOverride(OrmJpaContextNode parent, AssociationOverride.Owner owner, XmlAssociationOverride xmlAssociationOverride) { - return new GenericOrmAssociationOverride(parent, owner, xmlAssociationOverride); - } - - public OrmDiscriminatorColumn buildOrmDiscriminatorColumn(OrmEntity parent, OrmNamedColumn.Owner owner) { - return new GenericOrmDiscriminatorColumn(parent, owner); - } - - public OrmColumn buildOrmColumn(OrmJpaContextNode parent, OrmColumn.Owner owner) { - return new GenericOrmColumn(parent, owner); - } - - public OrmGeneratedValue buildOrmGeneratedValue(OrmJpaContextNode parent) { - return new GenericOrmGeneratedValue(parent); - } - - public OrmSequenceGenerator buildOrmSequenceGenerator(OrmJpaContextNode parent) { - return new GenericOrmSequenceGenerator(parent); - } - - public OrmTableGenerator buildOrmTableGenerator(OrmJpaContextNode parent) { - return new GenericOrmTableGenerator(parent); - } - - public OrmNamedNativeQuery buildOrmNamedNativeQuery(OrmJpaContextNode parent) { - return new GenericOrmNamedNativeQuery(parent); - } - - public OrmNamedQuery buildOrmNamedQuery(OrmJpaContextNode parent) { - return new GenericOrmNamedQuery(parent); - } - - public OrmQueryHint buildOrmQueryHint(OrmQuery parent) { - return new GenericOrmQueryHint(parent); - } - - public OrmBasicMapping buildOrmBasicMapping(OrmPersistentAttribute parent) { - return new GenericOrmBasicMapping(parent); - } - - public OrmEmbeddedMapping buildOrmEmbeddedMapping(OrmPersistentAttribute parent) { - return new GenericOrmEmbeddedMapping(parent); - } - - public OrmEmbeddedIdMapping buildOrmEmbeddedIdMapping(OrmPersistentAttribute parent) { - return new GenericOrmEmbeddedIdMapping(parent); - } - - public OrmIdMapping buildOrmIdMapping(OrmPersistentAttribute parent) { - return new GenericOrmIdMapping(parent); - } - - public OrmManyToManyMapping buildOrmManyToManyMapping(OrmPersistentAttribute parent) { - return new GenericOrmManyToManyMapping(parent); - } - - public OrmManyToOneMapping buildOrmManyToOneMapping(OrmPersistentAttribute parent) { - return new GenericOrmManyToOneMapping(parent); - } - - public OrmOneToManyMapping buildOrmOneToManyMapping(OrmPersistentAttribute parent) { - return new GenericOrmOneToManyMapping(parent); - } - - public OrmOneToOneMapping buildOrmOneToOneMapping(OrmPersistentAttribute parent) { - return new GenericOrmOneToOneMapping(parent); - } - - public OrmTransientMapping buildOrmTransientMapping(OrmPersistentAttribute parent) { - return new GenericOrmTransientMapping(parent); - } - - public OrmVersionMapping buildOrmVersionMapping(OrmPersistentAttribute parent) { - return new GenericOrmVersionMapping(parent); - } - - public OrmAttributeMapping buildOrmNullAttributeMapping(OrmPersistentAttribute parent) { - return new GenericOrmNullAttributeMapping(parent); - } - - public OrmUniqueConstraint buildOrmUniqueConstraint(OrmJpaContextNode parent, UniqueConstraint.Owner owner, XmlUniqueConstraint xmlUniqueConstraint) { - return new GenericOrmUniqueConstraint(parent, owner, xmlUniqueConstraint); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java deleted file mode 100644 index 2e43677eea..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java +++ /dev/null @@ -1,304 +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.platform; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.resources.IFile; -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.JpaProject; -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaBasicMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddableProvider; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedIdMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaEntityProvider; -import org.eclipse.jpt.core.internal.context.java.JavaIdMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaManyToManyMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaManyToOneMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaMappedSuperclassProvider; -import org.eclipse.jpt.core.internal.context.java.JavaNullAttributeMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaOneToManyMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaOneToOneMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaTransientMappingProvider; -import org.eclipse.jpt.core.internal.context.java.JavaVersionMappingProvider; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.DatabaseFinder; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJpaPlatform - implements JpaPlatform -{ - public static final String ID = "generic"; //$NON-NLS-1$ - - private String id; - - protected JpaFactory jpaFactory; - - protected JpaAnnotationProvider annotationProvider; - - protected List<JavaTypeMappingProvider> javaTypeMappingProviders; - - protected List<JavaAttributeMappingProvider> javaAttributeMappingProviders; - - protected List<DefaultJavaAttributeMappingProvider> defaultJavaAttributeMappingProviders; - - - /** - * zero-argument constructor - */ - public GenericJpaPlatform() { - super(); - } - - public String getId() { - return this.id; - } - - /** - * ************* - * * IMPORTANT * For INTERNAL use only !! - * ************* - * - * @see JpaPlatform#setId(String) - */ - public void setId(String theId) { - this.id = theId; - } - - - // **************** Model construction/updating ************************** - - public synchronized JpaFactory getJpaFactory() { - if (this.jpaFactory == null) { - this.jpaFactory = this.buildJpaFactory(); - } - return this.jpaFactory; - } - - protected JpaFactory buildJpaFactory() { - return new GenericJpaFactory(); - } - - public JpaFile buildJpaFile(JpaProject jpaProject, IFile file) { - if (this.getJpaFactory().hasRelevantContent(file)) { - ResourceModel resourceModel = this.getJpaFactory().buildResourceModel(jpaProject, file); - return this.getJpaFactory().buildJpaFile(jpaProject, file, resourceModel); - } - return null; - } - - - // **************** Java annotation support ******************************** - - public synchronized JpaAnnotationProvider getAnnotationProvider() { - if (this.annotationProvider == null) { - this.annotationProvider = this.buildAnnotationProvider(); - } - return this.annotationProvider; - } - - protected JpaAnnotationProvider buildAnnotationProvider() { - return new GenericJpaAnnotationProvider(); - } - - - // **************** Type mapping providers ******************************** - - public JavaTypeMapping buildJavaTypeMappingFromMappingKey(String typeMappingKey, JavaPersistentType parent) { - return this.javaTypeMappingProviderFromMappingKey(typeMappingKey).buildMapping(parent, this.getJpaFactory()); - } - - public JavaTypeMapping buildJavaTypeMappingFromAnnotation(String mappingAnnotationName, JavaPersistentType parent) { - return this.javaTypeMappingProviderFromAnnotation(mappingAnnotationName).buildMapping(parent, this.getJpaFactory()); - } - - protected synchronized Iterator<JavaTypeMappingProvider> javaTypeMappingProviders() { - if (this.javaTypeMappingProviders == null) { - this.javaTypeMappingProviders = new ArrayList<JavaTypeMappingProvider>(); - this.addJavaTypeMappingProvidersTo(this.javaTypeMappingProviders); - } - return new CloneIterator<JavaTypeMappingProvider>(this.javaTypeMappingProviders); - } - - /** - * Override this to specify more or different type mapping providers. - * The default includes the JPA spec-defined type mappings of - * Entity, MappedSuperclass, and Embeddable - */ - protected void addJavaTypeMappingProvidersTo(List<JavaTypeMappingProvider> providers) { - providers.add(JavaEntityProvider.instance()); - providers.add(JavaMappedSuperclassProvider.instance()); - providers.add(JavaEmbeddableProvider.instance()); - providers.add(JavaNullTypeMappingProvider.instance()); - } - - protected JavaTypeMappingProvider javaTypeMappingProviderFromMappingKey(String typeMappingKey) { - for (Iterator<JavaTypeMappingProvider> stream = this.javaTypeMappingProviders(); stream.hasNext(); ) { - JavaTypeMappingProvider provider = stream.next(); - if (provider.getKey() == typeMappingKey) { - return provider; - } - } - throw new IllegalArgumentException("Illegal type mapping key: " + typeMappingKey); //$NON-NLS-1$ - } - - protected JavaTypeMappingProvider javaTypeMappingProviderFromAnnotation(String annotationName) { - for (Iterator<JavaTypeMappingProvider> stream = this.javaTypeMappingProviders(); stream.hasNext(); ) { - JavaTypeMappingProvider provider = stream.next(); - if (provider.getAnnotationName() == annotationName) { - return provider; - } - } - throw new IllegalArgumentException("Illegal annotation name: " + annotationName); //$NON-NLS-1$ - } - - - // **************** Attribute mapping providers ******************************** - - public JavaAttributeMapping buildJavaAttributeMappingFromMappingKey(String attributeMappingKey, JavaPersistentAttribute parent) { - return this.javaAttributeMappingProviderFromMappingKey(attributeMappingKey).buildMapping(parent, this.getJpaFactory()); - } - - public JavaAttributeMapping buildJavaAttributeMappingFromAnnotation(String mappingAnnotationName, JavaPersistentAttribute parent) { - return this.javaAttributeMappingProviderFromAnnotation(mappingAnnotationName).buildMapping(parent, this.getJpaFactory()); - } - - public JavaAttributeMapping buildDefaultJavaAttributeMapping(JavaPersistentAttribute parent) { - return this.defaultJavaAttributeMappingProvider(parent).buildMapping(parent, this.getJpaFactory()); - } - - protected synchronized Iterator<JavaAttributeMappingProvider> javaAttributeMappingProviders() { - if (this.javaAttributeMappingProviders == null) { - this.javaAttributeMappingProviders = new ArrayList<JavaAttributeMappingProvider>(); - this.addJavaAttributeMappingProvidersTo(this.javaAttributeMappingProviders); - } - return new CloneIterator<JavaAttributeMappingProvider>(this.javaAttributeMappingProviders); - } - - /** - * Override this to specify more or different attribute mapping providers. - * The default includes the JPA spec-defined attribute mappings of - * Basic, Id, Transient OneToOne, OneToMany, ManyToOne, ManyToMany, Embeddable, EmbeddedId, Version. - */ - protected void addJavaAttributeMappingProvidersTo(List<JavaAttributeMappingProvider> providers) { - providers.add(JavaBasicMappingProvider.instance()); - providers.add(JavaEmbeddedMappingProvider.instance()); - providers.add(JavaEmbeddedIdMappingProvider.instance()); - providers.add(JavaIdMappingProvider.instance()); - providers.add(JavaManyToManyMappingProvider.instance()); - providers.add(JavaManyToOneMappingProvider.instance()); - providers.add(JavaOneToManyMappingProvider.instance()); - providers.add(JavaOneToOneMappingProvider.instance()); - providers.add(JavaTransientMappingProvider.instance()); - providers.add(JavaVersionMappingProvider.instance()); - } - - protected JavaAttributeMappingProvider javaAttributeMappingProviderFromMappingKey(String attributeMappingKey) { - for (Iterator<JavaAttributeMappingProvider> stream = this.javaAttributeMappingProviders(); stream.hasNext(); ) { - JavaAttributeMappingProvider provider = stream.next(); - if (provider.getKey() == attributeMappingKey) { - return provider; - } - } - throw new IllegalArgumentException("Illegal attribute mapping key: " + attributeMappingKey); //$NON-NLS-1$ - } - - protected JavaAttributeMappingProvider javaAttributeMappingProviderFromAnnotation(String annotationName) { - for (Iterator<JavaAttributeMappingProvider> stream = this.javaAttributeMappingProviders(); stream.hasNext(); ) { - JavaAttributeMappingProvider provider = stream.next(); - if (provider.getAnnotationName() == annotationName) { - return provider; - } - } - throw new IllegalArgumentException("Illegal annotation name: " + annotationName); //$NON-NLS-1$ - } - - protected synchronized ListIterator<DefaultJavaAttributeMappingProvider> defaultJavaAttributeMappingProviders() { - if (this.defaultJavaAttributeMappingProviders == null) { - this.defaultJavaAttributeMappingProviders = new ArrayList<DefaultJavaAttributeMappingProvider>(); - this.addDefaultJavaAttributeMappingProvidersTo(this.defaultJavaAttributeMappingProviders); - } - return new CloneListIterator<DefaultJavaAttributeMappingProvider>(this.defaultJavaAttributeMappingProviders); - } - - /** - * Override this to specify more or different default attribute mapping providers. - * The default includes the JPA spec-defined attribute mappings of - * Embedded and Basic. - */ - protected void addDefaultJavaAttributeMappingProvidersTo(List<DefaultJavaAttributeMappingProvider> providers) { - providers.add(JavaEmbeddedMappingProvider.instance()); // bug 190344 need to test default embedded before basic - providers.add(JavaBasicMappingProvider.instance()); - } - - protected JavaAttributeMappingProvider defaultJavaAttributeMappingProvider(JavaPersistentAttribute persistentAttribute) { - for (Iterator<DefaultJavaAttributeMappingProvider> stream = this.defaultJavaAttributeMappingProviders(); stream.hasNext(); ) { - DefaultJavaAttributeMappingProvider provider = stream.next(); - if (provider.defaultApplies(persistentAttribute)) { - return provider; - } - } - return this.getNullAttributeMappingProvider(); - } - - public String getDefaultJavaAttributeMappingKey(JavaPersistentAttribute persistentAttribute) { - return this.defaultJavaAttributeMappingProvider(persistentAttribute).getKey(); - } - - /** - * the "null" attribute mapping is used when the attribute is neither - * modified with a mapping annotation nor mapped by a "default" mapping - */ - protected JavaAttributeMappingProvider getNullAttributeMappingProvider() { - return JavaNullAttributeMappingProvider.instance(); - } - - - // **************** Validation ********************************************* - - public void addToMessages(JpaProject project, List<IMessage> messages) { - project.addToMessages(messages); - } - - - // **************** Database ********************************************* - - public ConnectionProfileFactory getConnectionProfileFactory() { - return JptDbPlugin.instance().getConnectionProfileFactory(); - } - - public EntityGeneratorDatabaseAnnotationNameBuilder getEntityGeneratorDatabaseAnnotationNameBuilder() { - return GenericEntityGeneratorDatabaseAnnotationNameBuilder.instance(); - } - - public DatabaseFinder getDatabaseFinder() { - return DatabaseFinder.Default.instance(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformRegistry.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformRegistry.java deleted file mode 100644 index 38213f9792..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JpaPlatformRegistry.java +++ /dev/null @@ -1,237 +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.platform; - -import java.util.HashMap; -import java.util.Iterator; -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.JptCorePlugin; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -/** - * 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 = "jpaPlatform"; //$NON-NLS-1$ - private static final String EL_PLATFORM = "jpaPlatform"; //$NON-NLS-1$ - private static final String AT_ID = "id"; //$NON-NLS-1$ - private static final String AT_LABEL = "label"; //$NON-NLS-1$ - private static final String AT_CLASS = "class"; //$NON-NLS-1$ - private static final String AT_DEFAULT = "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 (Iterator<IConfigurationElement> stream = this.configElements(); stream.hasNext(); ) { - this.addConfigElementTo(stream.next(), configElements); - } - return configElements; - } - - /** - * Return the configuration elements from the Eclipse platform extension - * registry. - */ - private Iterator<IConfigurationElement> configElements() { - return new CompositeIterator<IConfigurationElement>( - new TransformationIterator<IExtension, Iterator<IConfigurationElement>>(this.extensions()) { - @Override - protected Iterator<IConfigurationElement> transform(IExtension extension) { - return CollectionTools.iterator(extension.getConfigurationElements()); - } - } - ); - } - - private Iterator<IExtension> extensions() { - return CollectionTools.iterator(this.extensionPoint().getExtensions()); - } - - private IExtensionPoint extensionPoint() { - return Platform.getExtensionRegistry().getExtensionPoint(JptCorePlugin.PLUGIN_ID, EXTENSION_ID); - } - - private void addConfigElementTo(IConfigurationElement configElement, HashMap<String, IConfigurationElement> configElements) { - if ( ! configElement.getName().equals(EL_PLATFORM)) { - return; - } - if ( ! this.configElementIsValid(configElement)) { - return; - } - - String id = configElement.getAttribute(AT_ID); - IConfigurationElement prev = configElements.get(id); - if (prev == null) { - configElements.put(id, configElement); - } else { - this.logDuplicatePlatform(prev, configElement); - } - } - - /** - * check *all* attributes before returning - */ - private boolean configElementIsValid(IConfigurationElement configElement) { - boolean valid = true; - if (configElement.getAttribute(AT_ID) == null) { - this.logMissingAttribute(configElement, AT_ID); - valid = false; - } - if (configElement.getAttribute(AT_LABEL) == null) { - logMissingAttribute(configElement, AT_LABEL); - valid = false; - } - if (configElement.getAttribute(AT_CLASS) == null) { - logMissingAttribute(configElement, AT_CLASS); - 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(AT_LABEL); - } - - /** - * 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 (String platformId : jpaPlatformConfigurationElements.keySet()) { - if ("true".equals(jpaPlatformConfigurationElements.get(platformId).getAttribute(AT_DEFAULT))) { - return platformId; - } - } - 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(String id) { - IConfigurationElement configElement = this.jpaPlatformConfigurationElements.get(id); - if (configElement == null) { - throw new IllegalArgumentException(id); - } - JpaPlatform platform; - try { - platform = (JpaPlatform) configElement.createExecutableExtension(AT_CLASS); - } catch (CoreException ex) { - this.logFailedInstantiation(configElement, ex); - throw new IllegalArgumentException(id); - } - platform.setId(id); - return platform; - } - - - // ********** errors ********** - - // TODO externalize strings - private void logMissingAttribute(IConfigurationElement configElement, String attributeName) { - String message = - "An extension element \"" - + configElement.getName() - + "\" in plugin \"" - + configElement.getContributor().getName() - + "\" is missing a required attribute \"" - + attributeName - + "\"."; - JptCorePlugin.log(message); - } - - // TODO externalize strings - private void logDuplicatePlatform(IConfigurationElement prevConfigElement, IConfigurationElement newConfigElement) { - String message = - "The plugins \"" - + prevConfigElement.getContributor().getName() - + "\" and \"" - + newConfigElement.getContributor().getName() - + "\" have registered a duplicate attribute \"id\" " - + "for the extension element \"jpaPlatform\"."; - JptCorePlugin.log(message); - } - - // TODO externalize strings - private void logFailedInstantiation(IConfigurationElement configElement, CoreException ex) { - String message = - "Could not instantiate the class \"" - + configElement.getAttribute(AT_CLASS) - + "\" for the extension element \"" - + configElement.getName() - + "\" in the plugin \"" - + configElement.getContributor().getName() - + "\"."; - JptCorePlugin.log(message); - JptCorePlugin.log(ex); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java deleted file mode 100644 index 190fdf53c8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceConstants.java +++ /dev/null @@ -1,20 +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.prefs; - -/** - * Constant definitions for plug-in preferences - */ -public class JpaPreferenceConstants -{ - public static final String PREF_DEFAULT_JPA_LIB = "defaultJpaLib"; - - public static final String PREF_DEFAULT_JPA_PLATFORM = "defaultJpaPlatform"; -} 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 dde4b89381..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/prefs/JpaPreferenceInitializer.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.prefs; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.core.runtime.preferences.DefaultScope; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.platform.GenericJpaPlatform; -import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Class used to initialize default preference values. - */ -public class JpaPreferenceInitializer extends AbstractPreferenceInitializer -{ - @Override - public void initializeDefaultPreferences() { - IEclipsePreferences node = new DefaultScope().getNode(JptCorePlugin.instance().getBundle().getSymbolicName()); - - // default JPA platform - String defaultPlatformId = JpaPlatformRegistry.instance().getDefaultJpaPlatformId(); - if (StringTools.stringIsEmpty(defaultPlatformId)) { - defaultPlatformId = GenericJpaPlatform.ID; - } - node.put(JpaPreferenceConstants.PREF_DEFAULT_JPA_PLATFORM, defaultPlatformId); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/common/translators/BooleanTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/common/translators/BooleanTranslator.java deleted file mode 100644 index 8dcc16aaf0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/common/translators/BooleanTranslator.java +++ /dev/null @@ -1,37 +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.resource.common.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 domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, BOOLEAN_FEATURE | BOOLEAN_LOWERCASE); - } - - public BooleanTranslator(String domNameAndPath, EStructuralFeature aFeature, int style) { - super(domNameAndPath, aFeature, BOOLEAN_FEATURE | BOOLEAN_LOWERCASE | style); - } - - @Override - public Object convertStringToValue(String strValue, EObject owner) { - return Boolean.valueOf(strValue); - } - - @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/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 f0fb9e4117..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.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.resource.java; - -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.utility.CommandExecutorProvider; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.CallbackChangeSupport; -import org.eclipse.jpt.utility.internal.model.ChangeSupport; - -/** - * resource containment hierarchy - */ -public abstract class AbstractJavaResourceNode - extends AbstractModel - implements JavaResourceNode, CallbackChangeSupport.Source -{ - private final JavaResourceNode parent; - - - // ********** construction ********** - - protected AbstractJavaResourceNode(JavaResourceNode parent) { - super(); - this.checkParent(parent); - this.parent = parent; - } - - protected void checkParent(JavaResourceNode p) { - if (p == null) { - if (this.requiresParent()) { - throw new IllegalArgumentException("'parent' cannot be null"); - } - } else { - if (this.forbidsParent()) { - throw new IllegalArgumentException("'parent' must be null"); - } - } - } - - protected boolean requiresParent() { - return true; - } - - protected boolean forbidsParent() { - return ! this.requiresParent(); // assume 'parent' is not optional - } - - @Override - protected ChangeSupport buildChangeSupport() { - return new CallbackChangeSupport(this); - } - - - // ********** JavaResourceNode implementation ********** - - public JpaCompilationUnit getJpaCompilationUnit() { - return this.parent.getJpaCompilationUnit(); - } - - public JavaResourceModel getResourceModel() { - return this.getJpaCompilationUnit().getResourceModel(); - } - - - // ********** CallbackChangeSupport.Source implementation ********** - - public void aspectChanged(String aspectName) { - this.getJpaCompilationUnit().resourceChanged(); - } - - - // ********** convenience methods ********** - - protected JavaResourceNode getParent() { - return this.parent; - } - - public JpaAnnotationProvider getAnnotationProvider() { - return this.getJpaCompilationUnit().getAnnotationProvider(); - } - - public CommandExecutorProvider getModifySharedDocumentCommandExecutorProvider() { - return this.getJpaCompilationUnit().getModifySharedDocumentCommandExecutorProvider(); - } - - public AnnotationEditFormatter getAnnotationEditFormatter() { - return this.getJpaCompilationUnit().getAnnotationEditFormatter(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourcePersistentMember.java deleted file mode 100644 index a4354ff0dd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourcePersistentMember.java +++ /dev/null @@ -1,563 +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.resource.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.ListIterator; -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.MethodSignature; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; - -public abstract class AbstractJavaResourcePersistentMember<E extends Member> - extends AbstractJavaResourceNode - implements JavaResourcePersistentMember -{ - private final E member; - - /** - * stores all annotations(non-mapping) except duplicates, java compiler has an error for duplicates - */ - private final Collection<Annotation> annotations; - - /** - * stores all mapping annotations except duplicates, java compiler has an error for duplicates - */ - private final Collection<Annotation> mappingAnnotations; - - private boolean persistable; - - AbstractJavaResourcePersistentMember(JavaResourceNode parent, E member){ - super(parent); - this.member = member; - this.annotations = new ArrayList<Annotation>(); - this.mappingAnnotations = new ArrayList<Annotation>(); - } - - public void initialize(CompilationUnit astRoot) { - getMember().getBodyDeclaration(astRoot).accept(this.buildInitialAnnotationVisitor(astRoot)); - this.persistable = buildPersistable(astRoot); - } - - protected ASTVisitor buildInitialAnnotationVisitor(CompilationUnit astRoot) { - return new LocalASTVisitor(astRoot, this.getMember().getBodyDeclaration(astRoot)) { - @Override - protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - AbstractJavaResourcePersistentMember.this.addInitialAnnotation(node, this.astRoot); - } - }; - } - - protected void addInitialAnnotation(org.eclipse.jdt.core.dom.Annotation node, CompilationUnit astRoot) { - String qualifiedAnnotationName = JDTTools.resolveAnnotation(node); - if (qualifiedAnnotationName == null) { - return; - } - if (isPossibleAnnotation(qualifiedAnnotationName)) { - if (getAnnotation(qualifiedAnnotationName) == null) { //don't want duplicates - Annotation annotation = buildAnnotation(qualifiedAnnotationName); - annotation.initialize(astRoot); - this.annotations.add(annotation); - } - } - else if (isPossibleMappingAnnotation(qualifiedAnnotationName)) { - if (getMappingAnnotation(qualifiedAnnotationName) == null) { //don't want duplicates - Annotation annotation = buildMappingAnnotation(qualifiedAnnotationName); - annotation.initialize(astRoot); - this.mappingAnnotations.add(annotation); - } - } - } - - public E getMember() { - return this.member; - } - - protected abstract Annotation buildAnnotation(String annotationName); - - protected abstract Annotation buildNullAnnotation(String annotationName); - - protected abstract Annotation buildMappingAnnotation(String mappingAnnotationName); - - protected abstract Annotation buildNullMappingAnnotation(String annotationName); - - protected abstract ListIterator<String> possibleMappingAnnotationNames(); - - protected abstract boolean isPossibleAnnotation(String annotationName); - - protected abstract boolean isPossibleMappingAnnotation(String annotationName); - - protected boolean buildPersistable(CompilationUnit astRoot) { - return this.getMember().isPersistable(astRoot); - } - - - public Annotation getAnnotation(String annotationName) { - for (Iterator<Annotation> i = annotations(); i.hasNext(); ) { - Annotation annotation = i.next(); - if (annotation.getAnnotationName().equals(annotationName)) { - return annotation; - } - } - return null; - } - - public JavaResourceNode getNonNullAnnotation(String annotationName) { - Annotation annotation = getAnnotation(annotationName); - if (annotation == null) { - return buildNullAnnotation(annotationName); - } - return annotation; - } - - public Annotation getMappingAnnotation(String annotationName) { - for (Iterator<Annotation> i = mappingAnnotations(); i.hasNext(); ) { - Annotation mappingAnnotation = i.next(); - if (mappingAnnotation.getAnnotationName().equals(annotationName)) { - return mappingAnnotation; - } - } - return null; - } - - public JavaResourceNode getNullMappingAnnotation(String annotationName) { - return buildNullMappingAnnotation(annotationName); - } - - @SuppressWarnings("unchecked") - public Iterator<Annotation> annotations() { - return new CloneIterator<Annotation>(this.annotations); - } - - public int annotationsSize() { - return this.annotations.size(); - } - - public Annotation addAnnotation(String annotationName) { - Annotation annotation = buildAnnotation(annotationName); - this.annotations.add(annotation); - annotation.newAnnotation(); - this.fireItemAdded(ANNOTATIONS_COLLECTION, annotation); - return annotation; - } - - @SuppressWarnings("unchecked") - protected ContainerAnnotation<NestableAnnotation> addContainerAnnotation(String containerAnnotationName) { - return (ContainerAnnotation<NestableAnnotation>) addAnnotation(containerAnnotationName); - } - - protected ContainerAnnotation<NestableAnnotation> addContainerAnnotationTwoNestableAnnotations(String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = buildContainerAnnotation(containerAnnotationName); - this.annotations.add(containerAnnotation); - containerAnnotation.newAnnotation(); - containerAnnotation.addInternal(0).newAnnotation(); - containerAnnotation.addInternal(1).newAnnotation(); - return containerAnnotation; - } - - @SuppressWarnings("unchecked") - protected ContainerAnnotation<NestableAnnotation> buildContainerAnnotation(String containerAnnotationName) { - return (ContainerAnnotation<NestableAnnotation>) buildAnnotation(containerAnnotationName); - } - - @SuppressWarnings("unchecked") - protected ContainerAnnotation<NestableAnnotation> getContainerAnnotation(String containerAnnotationName) { - return (ContainerAnnotation<NestableAnnotation>) getAnnotation(containerAnnotationName); - } - - protected NestableAnnotation getNestableAnnotation(String nestableAnnotationName) { - return (NestableAnnotation) getAnnotation(nestableAnnotationName); - } - - protected NestableAnnotation addNestableAnnotation(String nestableAnnotationName) { - return (NestableAnnotation) addAnnotation(nestableAnnotationName); - } - - //TODO it seems we should be firing one change notification here, that a new nestable annotation was added. - public NestableAnnotation addAnnotation(int index, String nestableAnnotationName, String containerAnnotationName) { - NestableAnnotation nestedAnnotation = (NestableAnnotation) getAnnotation(nestableAnnotationName); - - ContainerAnnotation<NestableAnnotation> containerAnnotation = getContainerAnnotation(containerAnnotationName); - - if (containerAnnotation != null) { - //ignore any nestableAnnotation and just add to the plural one - NestableAnnotation newNestedAnnotation = ContainerAnnotationTools.addNestedAnnotation(index, containerAnnotation); - //TODO any event notification being fired for the add??? - return newNestedAnnotation; - } - if (nestedAnnotation == null) { - //add the nestable since neither nestable or container exists - return addNestableAnnotation(nestableAnnotationName); - } - //move the nestable to a new container annotation and add to it - ContainerAnnotation<NestableAnnotation> newContainerAnnotation = addContainerAnnotationTwoNestableAnnotations(containerAnnotationName); - if (index == 0) { - newContainerAnnotation.nestedAnnotationAt(1).initializeFrom(nestedAnnotation); - } - else { - newContainerAnnotation.nestedAnnotationAt(0).initializeFrom(nestedAnnotation); - } - removeAnnotation(nestedAnnotation); - return newContainerAnnotation.nestedAnnotationAt(index); - } - - public void move(int targetIndex, int sourceIndex, String containerAnnotationName) { - move(targetIndex, sourceIndex, getContainerAnnotation(containerAnnotationName)); - } - - protected void move(int targetIndex, int sourceIndex, ContainerAnnotation<NestableAnnotation> containerAnnotation) { - containerAnnotation.move(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, containerAnnotation); - } - - protected void addAnnotation(Annotation annotation) { - addItemToCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); - } - - protected void removeAnnotation(Annotation annotation) { - removeAnnotation_(annotation); - //TODO looks odd that we remove the annotation here, but in addAnnotation(Annotation) we don't do the same - annotation.removeAnnotation(); - } - - protected void removeAnnotation_(Annotation annotation) { - removeItemFromCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); - } - - protected void addMappingAnnotation(String mappingAnnotationName) { - if (getMappingAnnotation(mappingAnnotationName) != null) { - return; - } - Annotation mappingAnnotation = buildMappingAnnotation(mappingAnnotationName); - addMappingAnnotation(mappingAnnotation); - //TODO should this be done here or should creating the Annotation do this?? - mappingAnnotation.newAnnotation(); - } - - protected void addMappingAnnotation(Annotation annotation) { - addItemToCollection(annotation, this.mappingAnnotations, MAPPING_ANNOTATIONS_COLLECTION); - } - - protected void removeMappingAnnotation(Annotation annotation) { - removeMappingAnnotation_(annotation); - annotation.removeAnnotation(); - } - - protected void removeMappingAnnotation_(Annotation annotation) { - removeItemFromCollection(annotation, this.mappingAnnotations, MAPPING_ANNOTATIONS_COLLECTION); - } - - @SuppressWarnings("unchecked") - public Iterator<Annotation> mappingAnnotations() { - return new CloneIterator<Annotation>(this.mappingAnnotations); - } - - public int mappingAnnotationsSize() { - return this.mappingAnnotations.size(); - } - - public void removeAnnotation(String annotationName) { - Annotation annotation = getAnnotation(annotationName); - if (annotation != null) { - removeAnnotation(annotation); - } - } - - public void removeAnnotation(int index, String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = getContainerAnnotation(containerAnnotationName); - if (containerAnnotation == null) { - Annotation annotation = getAnnotation(nestableAnnotationName); - removeAnnotation(annotation); - } - else { - removeAnnotation(index, containerAnnotation); - } - } - - protected void removeAnnotation(int index, ContainerAnnotation<NestableAnnotation> containerAnnotation) { - NestableAnnotation nestableAnnotation = containerAnnotation.nestedAnnotationAt(index); - containerAnnotation.remove(index); - //TODO move these 2 lines to the ContainerAnnotation implementation, i think - nestableAnnotation.removeAnnotation(); - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, containerAnnotation); - - if (containerAnnotation.nestedAnnotationsSize() == 0) { - removeAnnotation(containerAnnotation); - } - else if (containerAnnotation.nestedAnnotationsSize() == 1) { - NestableAnnotation nestedAnnotation = containerAnnotation.nestedAnnotationAt(0); - - this.annotations.remove(containerAnnotation); - containerAnnotation.removeAnnotation(); - - - NestableAnnotation newAnnotation = (NestableAnnotation) buildAnnotation(containerAnnotation.getNestableAnnotationName()); - this.annotations.add(newAnnotation); - newAnnotation.newAnnotation(); - - newAnnotation.initializeFrom(nestedAnnotation); - - this.fireItemAdded(ANNOTATIONS_COLLECTION, newAnnotation); - fireItemRemoved(ANNOTATIONS_COLLECTION, containerAnnotation); - } - } - // removes all other *mapping* annotations that exist, not just the one returned by mappingAnnotation() - // mappingAnnotation() returns the first mapping annotation found in the source. if there are multiple - // mapping annotations (which is a validation error condition) then calling this api would not work - // because the new mapping annotatio would be added to the end of the list of annotations. - public void setMappingAnnotation(String annotationName) { - if (getMappingAnnotation(annotationName) != null) { - throw new IllegalStateException("The mapping annotation named " + annotationName + " already exists."); - } - Annotation oldMapping = getMappingAnnotation(); - Annotation newMapping = null; - if (oldMapping != null) { - removeUnnecessaryAnnotations(annotationName); - } - if (annotationName != null) { - if (getMappingAnnotation(annotationName) != null) { - return; - } - newMapping = buildMappingAnnotation(annotationName); - this.mappingAnnotations.add(newMapping); - newMapping.newAnnotation(); - } - //have to hold property change notification until the end so a project update does not occur - //before we are finished removing the old mapping and adding the new mapping - //just firing collectio changed since one or more removes and one add was completed. - //if we ever listen for specific events instead of just doing a mass update, we might need to make this more specific - fireCollectionChanged(MAPPING_ANNOTATIONS_COLLECTION); - } - /** - * Remove all mapping annotations that already exist. - * No change notification fired. - */ - protected void removeUnnecessaryAnnotations(String newMappingAnnotationName) { - for (ListIterator<String> i = possibleMappingAnnotationNames(); i.hasNext(); ) { - String mappingAnnotationName = i.next(); - if (mappingAnnotationName != newMappingAnnotationName) { - Annotation mappingAnnotation = getMappingAnnotation(mappingAnnotationName); - if (mappingAnnotation != null) { - this.mappingAnnotations.remove(mappingAnnotation); - mappingAnnotation.removeAnnotation(); - } - } - } - } - - //TODO need property change notification on this mappingAnnotation changing - //from the context model we don't really care if their are multiple mapping annotations, - //just which one we need to use - public Annotation getMappingAnnotation() { - for (ListIterator<String> i = possibleMappingAnnotationNames(); i.hasNext(); ) { - String mappingAnnotationName = i.next(); - for (Iterator<Annotation> j = mappingAnnotations(); j.hasNext(); ) { - Annotation mappingAnnotation = j.next(); - if (mappingAnnotationName == mappingAnnotation.getAnnotationName()) { - return mappingAnnotation; - } - } - } - return null; - } - - @SuppressWarnings("unchecked") - public ListIterator<NestableAnnotation> annotations(String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = getContainerAnnotation(containerAnnotationName); - if (containerAnnotation != null) { - return containerAnnotation.nestedAnnotations(); - } - NestableAnnotation nestableAnnotation = getNestableAnnotation(nestableAnnotationName); - if (nestableAnnotation != null) { - return new SingleElementListIterator<NestableAnnotation>(nestableAnnotation); - } - return EmptyListIterator.instance(); - } - - public void update(CompilationUnit astRoot) { - this.updateAnnotations(astRoot); - this.setPersistable(this.buildPersistable(astRoot)); - } - - public void resolveTypes(CompilationUnit astRoot) { - this.setPersistable(this.buildPersistable(astRoot)); - } - - protected void updateAnnotations(CompilationUnit astRoot) { - getMember().getBodyDeclaration(astRoot).accept(this.buildUpdateAnnotationVisitor(astRoot)); - removeMappingAnnotationsNotInSource(astRoot); - removeAnnotationsNotInSource(astRoot); - } - - protected void removeAnnotationsNotInSource(CompilationUnit astRoot) { - for (Annotation annotation : CollectionTools.iterable(annotations())) { - if (annotation.getJdtAnnotation(astRoot) == null) { - removeAnnotation_(annotation); - } - } - } - - protected void removeMappingAnnotationsNotInSource(CompilationUnit astRoot) { - for (Annotation mappingAnnotation : CollectionTools.iterable(mappingAnnotations())) { - if (mappingAnnotation.getJdtAnnotation(astRoot) == null) { - removeMappingAnnotation_(mappingAnnotation); - } - } - } - - protected ASTVisitor buildUpdateAnnotationVisitor(CompilationUnit astRoot) { - return new LocalASTVisitor(astRoot, this.getMember().getBodyDeclaration(astRoot)) { - @Override - protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - AbstractJavaResourcePersistentMember.this.addOrUpdateAnnotation(node, this.astRoot); - } - }; - } - - protected void addOrUpdateAnnotation(org.eclipse.jdt.core.dom.Annotation node, CompilationUnit astRoot) { - String qualifiedAnnotationName = JDTTools.resolveAnnotation(node); - if (qualifiedAnnotationName == null) { - return; - } - if (isPossibleAnnotation(qualifiedAnnotationName)) { - Annotation annotation = getAnnotation(qualifiedAnnotationName); - if (annotation != null) { - annotation.update(astRoot); - } - else { - annotation = buildAnnotation(qualifiedAnnotationName); - annotation.initialize(astRoot); - addAnnotation(annotation); - } - } - else if (isPossibleMappingAnnotation(qualifiedAnnotationName)) { - Annotation annotation = getMappingAnnotation(qualifiedAnnotationName); - if (annotation != null) { - annotation.update(astRoot); - } - else { - annotation = buildMappingAnnotation(qualifiedAnnotationName); - annotation.initialize(astRoot); - addMappingAnnotation(annotation); - } - } - } - - public boolean isFor(String memberName, int occurrence) { - return this.member.matches(memberName, occurrence); - } - - public boolean isFor(MethodSignature methodSignature, int occurrence) { - return false; - } - - public boolean isPersistable() { - return this.persistable; - } - - protected void setPersistable(boolean newPersistable) { - boolean oldPersistable = this.persistable; - this.persistable = newPersistable; - firePropertyChanged(PERSISTABLE_PROPERTY, oldPersistable, newPersistable); - //TODO change notification to parent so that the context model gets notification - //that the list of persistable fields has been updated - // - } - - public boolean isPersisted() { - return getMappingAnnotation() != null; - } - - public TextRange fullTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.getMember().getBodyDeclaration(astRoot)); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return this.fullTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getMember().getNameTextRange(astRoot); - } - - protected TextRange getTextRange(ASTNode astNode) { - return (astNode == null) ? null : new ASTNodeTextRange(astNode); - } - - protected static <T extends JavaResourcePersistentMember> Iterator<T> persistableMembers(Iterator<T> attributes) { - return new FilteringIterator<T, T>(attributes) { - @Override - protected boolean accept(T attribute) { - return attribute.isPersistable(); - } - }; - } - - - // ********** AST visitor ********** - - protected abstract class LocalASTVisitor extends ASTVisitor { - protected final CompilationUnit astRoot; - protected final BodyDeclaration bodyDeclaration; - - protected LocalASTVisitor(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); - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractNamedColumn.java deleted file mode 100644 index 6df800a7c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractNamedColumn.java +++ /dev/null @@ -1,146 +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.resource.java; - -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.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; - -public abstract class AbstractNamedColumn extends AbstractResourceAnnotation<Member> implements NamedColumnAnnotation -{ - // hold this so we can get the 'name' text range - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - - // hold this so we can get the 'columnDefinition' text range - private final DeclarationAnnotationElementAdapter<String> columnDefinitionDeclarationAdapter; - - private final AnnotationElementAdapter<String> nameAdapter; - - private final AnnotationElementAdapter<String> columnDefinitionAdapter; - - private String name; - private String columnDefinition; - - public AbstractNamedColumn(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.nameDeclarationAdapter = this.buildStringElementAdapter(this.nameElementName()); - this.nameAdapter = this.buildShortCircuitElementAdapter(this.nameDeclarationAdapter); - this.columnDefinitionDeclarationAdapter = this.buildStringElementAdapter(this.columnDefinitionElementName()); - this.columnDefinitionAdapter = this.buildShortCircuitElementAdapter(this.columnDefinitionDeclarationAdapter); - } - - protected DeclarationAnnotationElementAdapter<String> buildStringElementAdapter(String elementName) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(getDeclarationAnnotationAdapter(), elementName); - } - - protected DeclarationAnnotationElementAdapter<Boolean> buildBooleanElementAdapter(String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(getDeclarationAnnotationAdapter(), elementName, BooleanExpressionConverter.instance()); - } - - protected DeclarationAnnotationElementAdapter<Integer> buildIntegerElementAdapter(String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Integer>(getDeclarationAnnotationAdapter(), elementName, NumberIntegerExpressionConverter.instance()); - } - - protected AnnotationElementAdapter<String> buildShortCircuitElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(getMember(), daea); - } - - protected AnnotationElementAdapter<Boolean> buildShortCircuitBooleanElementAdapter(DeclarationAnnotationElementAdapter<Boolean> daea) { - return new ShortCircuitAnnotationElementAdapter<Boolean>(getMember(), daea); - } - - protected AnnotationElementAdapter<Integer> buildShortCircuitIntegerElementAdapter(DeclarationAnnotationElementAdapter<Integer> daea) { - return new ShortCircuitAnnotationElementAdapter<Integer>(getMember(), daea); - } - - protected AnnotationElementAdapter<String> buildShortCircuitStringElementAdapter(String elementName) { - return this.buildShortCircuitElementAdapter(this.buildStringElementAdapter(elementName)); - } - protected abstract String nameElementName(); - - protected abstract String columnDefinitionElementName(); - - public void initialize(CompilationUnit astRoot) { - this.name = this.name(astRoot); - this.columnDefinition = this.columnDefinition(astRoot); - } - - public void initializeFrom(NestableAnnotation oldAnnotation) { - NamedColumnAnnotation oldColumn = (NamedColumnAnnotation) oldAnnotation; - setName(oldColumn.getName()); - setColumnDefinition(oldColumn.getColumnDefinition()); - } - - //************* NamedColumn implementation ************** - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public String getColumnDefinition() { - return this.columnDefinition; - } - - public void setColumnDefinition(String newColumnDefinition) { - if (attributeValueHasNotChanged(this.columnDefinition, newColumnDefinition)) { - return; - } - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - this.columnDefinitionAdapter.setValue(newColumnDefinition); - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public TextRange getColumnDefinitionTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.columnDefinitionDeclarationAdapter, astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.nameDeclarationAdapter, pos, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - this.setColumnDefinition(this.columnDefinition(astRoot)); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - protected String columnDefinition(CompilationUnit astRoot) { - return this.columnDefinitionAdapter.getValue(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractNamedQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractNamedQuery.java deleted file mode 100644 index f73e8e651b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractNamedQuery.java +++ /dev/null @@ -1,309 +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.resource.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -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.ContainerAnnotation; -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.NestableQueryHint; -import org.eclipse.jpt.core.resource.java.QueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.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.iterators.CloneListIterator; - -public abstract class AbstractNamedQuery extends AbstractResourceAnnotation<Type> - implements QueryAnnotation -{ - // hold this so we can get the 'name' text range - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - - // hold this so we can get the 'query' text range - private final DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter; - - private final AnnotationElementAdapter<String> nameAdapter; - - private final AnnotationElementAdapter<String> queryAdapter; - - private String name; - - private String query; - - private final List<NestableQueryHint> hints; - private final HintsContainerAnnotation hintsContainerAnnotation; - - protected AbstractNamedQuery(JavaResourceNode parent, Type type,DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, type, daa, annotationAdapter); - this.nameDeclarationAdapter = nameAdapter(daa); - this.queryDeclarationAdapter = queryAdapter(daa); - this.nameAdapter = this.buildAdapter(this.nameDeclarationAdapter); - this.queryAdapter = this.buildAdapter(this.queryDeclarationAdapter); - this.hints = new ArrayList<NestableQueryHint>(); - this.hintsContainerAnnotation = new HintsContainerAnnotation(); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.name(astRoot); - this.query = this.query(astRoot); - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this.hintsContainerAnnotation); - } - - - // ********** initialization ********** - protected AnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(getMember(), daea); - } - - protected DeclarationAnnotationElementAdapter<String> nameAdapter(DeclarationAnnotationAdapter daa) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daa, nameElementName()); - } - - protected DeclarationAnnotationElementAdapter<String> queryAdapter(DeclarationAnnotationAdapter daa) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daa, queryElementName()); - } - - protected abstract String nameElementName(); - - protected abstract String queryElementName(); - - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public String getQuery() { - return this.query; - } - - public void setQuery(String newQuery) { - if (attributeValueHasNotChanged(this.query, newQuery)) { - return; - } - String oldQuery = this.query; - this.query = newQuery; - this.queryAdapter.setValue(newQuery); - firePropertyChanged(QUERY_PROPERTY, oldQuery, newQuery); - } - - public ListIterator<QueryHintAnnotation> hints() { - return new CloneListIterator<QueryHintAnnotation>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public NestableQueryHint hintAt(int index) { - return this.hints.get(index); - } - - public int indexOfHint(QueryHintAnnotation queryHint) { - return this.hints.indexOf(queryHint); - } - - public NestableQueryHint addHint(int index) { - NestableQueryHint queryHint = (NestableQueryHint) ContainerAnnotationTools.addNestedAnnotation(index, this.hintsContainerAnnotation); - fireItemAdded(QueryAnnotation.HINTS_LIST, index, queryHint); - return queryHint; - } - - private void addHint(int index, NestableQueryHint queryHint) { - addItemToList(index, queryHint, this.hints, HINTS_LIST); - } - - public void removeHint(int index) { - NestableQueryHint queryHint = hintAt(index); - removeHint(queryHint); - queryHint.removeAnnotation(); - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, this.hintsContainerAnnotation); - } - - private void removeHint(NestableQueryHint queryHint) { - removeItemFromList(queryHint, this.hints, HINTS_LIST); - } - - public void moveHint(int targetIndex, int sourceIndex) { - moveHintInternal(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, this.hintsContainerAnnotation); - fireItemMoved(QueryAnnotation.HINTS_LIST, targetIndex, sourceIndex); - } - - protected void moveHintInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.hints, targetIndex, sourceIndex); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public TextRange getQueryTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.queryDeclarationAdapter, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - this.setQuery(this.query(astRoot)); - this.updateQueryHintsFromJava(astRoot); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - protected String query(CompilationUnit astRoot) { - return this.queryAdapter.getValue(astRoot); - } - - private void updateQueryHintsFromJava(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this.hintsContainerAnnotation); - } - - protected abstract NestableQueryHint createQueryHint(int index); - - // ********** persistence model -> java annotations ********** - public IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) super.getAnnotationAdapter(); - } - - public void moveAnnotation(int newIndex) { - getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - public void initializeFrom(NestableAnnotation oldAnnotation) { - AbstractNamedQuery oldNamedQuery = (AbstractNamedQuery) oldAnnotation; - setName(oldNamedQuery.getName()); - setQuery(oldNamedQuery.getQuery()); - for (QueryHintAnnotation queryHint : CollectionTools.iterable(oldNamedQuery.hints())) { - NestableQueryHint newQueryHint = addHint(oldNamedQuery.indexOfHint(queryHint)); - newQueryHint.initializeFrom((NestableQueryHint) queryHint); - } - } - - - private class HintsContainerAnnotation extends AbstractJavaResourceNode implements ContainerAnnotation<NestableQueryHint> { - - public HintsContainerAnnotation() { - super(AbstractNamedQuery.this); - } - - public void initialize(CompilationUnit astRoot) { - // nothing to initialize - } - - public NestableQueryHint add(int index) { - NestableQueryHint queryHint = AbstractNamedQuery.this.createQueryHint(index); - AbstractNamedQuery.this.addHint(index, queryHint); - return queryHint; - } - - public NestableQueryHint addInternal(int index) { - NestableQueryHint queryHint = AbstractNamedQuery.this.createQueryHint(index); - AbstractNamedQuery.this.hints.add(index, queryHint); - return queryHint; - } - - public String getAnnotationName() { - return AbstractNamedQuery.this.getAnnotationName(); - } - - public String getNestableAnnotationName() { - return JPA.QUERY_HINT; - } - - public int indexOf(NestableQueryHint hint) { - return AbstractNamedQuery.this.indexOfHint(hint); - } - - public void move(int targetIndex, int sourceIndex) { - AbstractNamedQuery.this.moveHint(targetIndex, sourceIndex); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - AbstractNamedQuery.this.moveHintInternal(targetIndex, sourceIndex); - } - - public NestableQueryHint nestedAnnotationAt(int index) { - return AbstractNamedQuery.this.hintAt(index); - } - - public NestableQueryHint nestedAnnotationFor(Annotation jdtAnnotation) { - for (NestableQueryHint uniqueConstraint : CollectionTools.iterable(nestedAnnotations())) { - if (jdtAnnotation == uniqueConstraint.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return uniqueConstraint; - } - } - return null; - } - - public ListIterator<NestableQueryHint> nestedAnnotations() { - return new CloneListIterator<NestableQueryHint>(AbstractNamedQuery.this.hints); - } - - public int nestedAnnotationsSize() { - return AbstractNamedQuery.this.hintsSize(); - } - - public void remove(NestableQueryHint queryHint) { - AbstractNamedQuery.this.removeHint(queryHint); - } - - public void remove(int index) { - AbstractNamedQuery.this.removeHint(nestedAnnotationAt(index)); - } - - public Annotation getJdtAnnotation(CompilationUnit astRoot) { - return AbstractNamedQuery.this.getJdtAnnotation(astRoot); - } - - public void newAnnotation() { - AbstractNamedQuery.this.newAnnotation(); - } - - public void removeAnnotation() { - AbstractNamedQuery.this.removeAnnotation(); - } - - public void update(CompilationUnit astRoot) { - AbstractNamedQuery.this.update(astRoot); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return AbstractNamedQuery.this.getTextRange(astRoot); - } - - public String getElementName() { - return "hints"; - } - - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractRelationshipMappingAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractRelationshipMappingAnnotation.java deleted file mode 100644 index c31060dd2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractRelationshipMappingAnnotation.java +++ /dev/null @@ -1,314 +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.resource.java; - -import java.util.List; -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.CollectionTools; - - -public abstract class AbstractRelationshipMappingAnnotation extends AbstractResourceAnnotation<Attribute> implements RelationshipMappingAnnotation -{ - // hold this so we can get the 'targetEntity' text range - private final DeclarationAnnotationElementAdapter<String> targetEntityDeclarationAdapter; - - // hold this so we can get the 'fetch' text range - private final DeclarationAnnotationElementAdapter<String> fetchDeclarationAdapter; - - // hold this so we can get the 'cascade' text range - private final DeclarationAnnotationElementAdapter<String[]> cascadeDeclarationAdapter; - - private final AnnotationElementAdapter<String> targetEntityAdapter; - - private final AnnotationElementAdapter<String> fetchAdapter; - - private final AnnotationElementAdapter<String[]> cascadeAdapter; - - private String targetEntity; - - private String fullyQualifiedTargetEntity; - - private FetchType fetch; - - protected boolean cascadeAll; - - protected boolean cascadePersist; - - protected boolean cascadeMerge; - - protected boolean cascadeRemove; - - protected boolean cascadeRefresh; - - - public AbstractRelationshipMappingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, DeclarationAnnotationAdapter daa) { - super(parent, attribute, daa); - this.targetEntityDeclarationAdapter = targetEntityAdapter(); - this.targetEntityAdapter = buildAnnotationElementAdapter(this.targetEntityDeclarationAdapter); - this.fetchDeclarationAdapter = fetchAdapter(); - this.fetchAdapter = buildAnnotationElementAdapter(this.fetchDeclarationAdapter); - this.cascadeDeclarationAdapter = cascadeAdapter(); - this.cascadeAdapter = new ShortCircuitArrayAnnotationElementAdapter<String>(attribute, this.cascadeDeclarationAdapter); - } - - protected AnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.getMember(), daea); - } - - protected AnnotationElementAdapter<Boolean> buildBooleanAnnotationElementAdapter(DeclarationAnnotationElementAdapter<Boolean> daea) { - return new ShortCircuitAnnotationElementAdapter<Boolean>(this.getMember(), daea); - } - - /** - * return the Java adapter's 'targetEntity' element adapter config - */ - protected abstract DeclarationAnnotationElementAdapter<String> targetEntityAdapter(); - - /** - * return the Java adapter's 'cascade' element adapter config - */ - protected abstract DeclarationAnnotationElementAdapter<String[]> cascadeAdapter(); - - /** - * return the Java adapter's 'fetch' element adapter config - */ - protected abstract DeclarationAnnotationElementAdapter<String> fetchAdapter(); - - public void initialize(CompilationUnit astRoot) { - this.targetEntity = this.targetEntity(astRoot); - this.fullyQualifiedTargetEntity = this.fullyQualifiedTargetEntity(astRoot); - this.fetch = this.fetch(astRoot); - this.initializeCascadeTypes(astRoot); - } - - protected void initializeCascadeTypes(CompilationUnit astRoot) { - String[] javaValue = this.cascadeAdapter.getValue(astRoot); - CascadeType[] cascadeTypes = CascadeType.fromJavaAnnotationValue(javaValue); - - this.cascadeAll = CollectionTools.contains(cascadeTypes, CascadeType.ALL); - this.cascadeMerge = CollectionTools.contains(cascadeTypes, CascadeType.MERGE); - this.cascadePersist = CollectionTools.contains(cascadeTypes, CascadeType.PERSIST); - this.cascadeRefresh = CollectionTools.contains(cascadeTypes, CascadeType.REFRESH); - this.cascadeRemove = CollectionTools.contains(cascadeTypes, CascadeType.REMOVE); - } - - public String getTargetEntity() { - return this.targetEntity; - } - - public void setTargetEntity(String newTargetEntity) { - if (attributeValueHasNotChanged(this.targetEntity, newTargetEntity)) { - return; - } - String oldTargetEntity = this.targetEntity; - this.targetEntity = newTargetEntity; - this.targetEntityAdapter.setValue(newTargetEntity); - firePropertyChanged(TARGET_ENTITY_PROPERTY, oldTargetEntity, newTargetEntity); - } - - public String getFullyQualifiedTargetEntity() { - return this.fullyQualifiedTargetEntity; - } - - protected void setFullyQualifiedTargetEntity(String newTargetEntity) { - String oldTargetEntity = this.fullyQualifiedTargetEntity; - this.fullyQualifiedTargetEntity = newTargetEntity; - firePropertyChanged(FULLY_QUALFIEID_TARGET_ENTITY_PROPERTY, oldTargetEntity, newTargetEntity); - } - - public FetchType getFetch() { - return this.fetch; - } - - public void setFetch(FetchType newFetch) { - if (attributeValueHasNotChanged(this.fetch, newFetch)) { - return; - } - FetchType oldFetch = this.fetch; - this.fetch = newFetch; - this.fetchAdapter.setValue(FetchType.toJavaAnnotationValue(newFetch)); - firePropertyChanged(FETCH_PROPERTY, oldFetch, newFetch); - } - - public boolean isCascadeAll() { - return this.cascadeAll; - } - - public void setCascadeAll(boolean newCascadeAll) { - if (this.cascadeAll == newCascadeAll) { - return; - } - boolean oldCascadeAll = this.cascadeAll; - this.cascadeAll = newCascadeAll; - setCascade(newCascadeAll, CascadeType.ALL); - firePropertyChanged(CASCADE_ALL_PROPERTY, oldCascadeAll, newCascadeAll); - } - - public boolean isCascadePersist() { - return this.cascadePersist; - } - - public void setCascadePersist(boolean newCascadePersist) { - if (this.cascadePersist == newCascadePersist) { - return; - } - boolean oldCascadePersist = this.cascadePersist; - this.cascadePersist = newCascadePersist; - setCascade(newCascadePersist, CascadeType.PERSIST); - firePropertyChanged(CASCADE_PERSIST_PROPERTY, oldCascadePersist, newCascadePersist); - } - - public boolean isCascadeMerge() { - return this.cascadeMerge; - } - - public void setCascadeMerge(boolean newCascadeMerge) { - if (this.cascadeMerge == newCascadeMerge) { - return; - } - boolean oldCascadeMerge = this.cascadeMerge; - this.cascadeMerge = newCascadeMerge; - setCascade(newCascadeMerge, CascadeType.MERGE); - firePropertyChanged(CASCADE_MERGE_PROPERTY, oldCascadeMerge, newCascadeMerge); - } - - public boolean isCascadeRemove() { - return this.cascadeRemove; - } - - public void setCascadeRemove(boolean newCascadeRemove) { - if (this.cascadeRemove == newCascadeRemove) { - return; - } - boolean oldCascadeRemove = this.cascadeRemove; - this.cascadeRemove = newCascadeRemove; - setCascade(newCascadeRemove, CascadeType.REMOVE); - firePropertyChanged(CASCADE_REMOVE_PROPERTY, oldCascadeRemove, newCascadeRemove); - } - - public boolean isCascadeRefresh() { - return this.cascadeRefresh; - } - - public void setCascadeRefresh(boolean newCascadeRefresh) { - if (this.cascadeRefresh == newCascadeRefresh) { - return; - } - boolean oldCascadeRefresh = this.cascadeRefresh; - this.cascadeRefresh = newCascadeRefresh; - setCascade(newCascadeRefresh, CascadeType.REFRESH); - firePropertyChanged(CASCADE_REFRESH_PROPERTY, oldCascadeRefresh, newCascadeRefresh); - } - - private void setCascadeTypes(CascadeType[] cascadeTypes) { - String[] newJavaValue = CascadeType.toJavaAnnotationValue(cascadeTypes); - this.cascadeAdapter.setValue(newJavaValue); - } - - private void setCascade(boolean isSet, CascadeType cascadeType) { - String[] javaValue = this.cascadeAdapter.getValue(); - CascadeType[] cascadeTypes = CascadeType.fromJavaAnnotationValue(javaValue); - List<CascadeType> cascadeCollection = CollectionTools.list(cascadeTypes); - - if (cascadeCollection.contains(cascadeType)) { - if (!isSet) { - cascadeCollection.remove(cascadeType); - setCascadeTypes(cascadeCollection.toArray(new CascadeType[cascadeCollection.size()])); - } - } - else { - if (isSet) { - cascadeCollection.add(cascadeType); - setCascadeTypes(cascadeCollection.toArray(new CascadeType[cascadeCollection.size()])); - } - } - } - - public TextRange getTargetEntityTextRange(CompilationUnit astRoot) { - return getElementTextRange(this.targetEntityDeclarationAdapter, astRoot); - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - return getElementTextRange(this.fetchDeclarationAdapter, astRoot); - } - - public TextRange getCascadeTextRange(CompilationUnit astRoot) { - return getElementTextRange(this.cascadeDeclarationAdapter, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setFetch(this.fetch(astRoot)); - this.setTargetEntity(this.targetEntity(astRoot)); - this.setFullyQualifiedTargetEntity(this.fullyQualifiedTargetEntity(astRoot)); - this.updateCascadeFromJava(astRoot); - } - - protected FetchType fetch(CompilationUnit astRoot) { - return FetchType.fromJavaAnnotationValue(this.fetchAdapter.getValue(astRoot)); - } - - protected String targetEntity(CompilationUnit astRoot) { - return this.targetEntityAdapter.getValue(astRoot); - } - - private void updateCascadeFromJava(CompilationUnit astRoot) { - String[] javaValue = this.cascadeAdapter.getValue(astRoot); - CascadeType[] cascadeTypes = CascadeType.fromJavaAnnotationValue(javaValue); - setCascadeAll(CollectionTools.contains(cascadeTypes, CascadeType.ALL)); - setCascadeMerge(CollectionTools.contains(cascadeTypes, CascadeType.MERGE)); - setCascadePersist(CollectionTools.contains(cascadeTypes, CascadeType.PERSIST)); - setCascadeRefresh(CollectionTools.contains(cascadeTypes, CascadeType.REFRESH)); - setCascadeRemove(CollectionTools.contains(cascadeTypes, CascadeType.REMOVE)); - } - - private String fullyQualifiedTargetEntity(CompilationUnit astRoot) { - if (getTargetEntity() == null) { - return null; - } - return JDTTools.resolveFullyQualifiedName(this.targetEntityAdapter.getExpression(astRoot)); - } - - // ********** static methods ********** - - protected static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - // TODO what about QualifiedType? - return buildAnnotationElementAdapter(annotationAdapter, elementName, SimpleTypeStringExpressionConverter.instance()); - } - - protected static DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String> converter) { - return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, false, converter); - } - - protected static DeclarationAnnotationElementAdapter<String> buildFetchAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new EnumDeclarationAnnotationElementAdapter(annotationAdapter, elementName, false); - } - - protected 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/AbstractResourceAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractResourceAnnotation.java deleted file mode 100644 index 1036203dc1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractResourceAnnotation.java +++ /dev/null @@ -1,133 +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.resource.java; - -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; - -public abstract class AbstractResourceAnnotation<E extends Member> - extends AbstractJavaResourceNode - implements Annotation -{ - private final E member; - - private final DeclarationAnnotationAdapter daa; - - private final AnnotationAdapter annotationAdapter; - - protected AbstractResourceAnnotation(JavaResourceNode parent, E member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent); - this.member = member; - this.daa = daa; - this.annotationAdapter = annotationAdapter; - } - - public E getMember() { - return this.member; - } - - protected AbstractResourceAnnotation(JavaResourceNode parent, E member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - - public AnnotationAdapter getAnnotationAdapter() { - return this.annotationAdapter; - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return getAnnotationAdapter().getAnnotation(astRoot); - } - - public DeclarationAnnotationAdapter getDeclarationAnnotationAdapter() { - return this.daa; - } - - public void removeAnnotation() { - getAnnotationAdapter().removeAnnotation(); - } - - public void newAnnotation() { - getAnnotationAdapter().newMarkerAnnotation(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return getAnnotationTextRange(astRoot); - } - - protected TextRange getTextRange(ASTNode astNode) { - return (astNode == null) ? null : new ASTNodeTextRange(astNode); - } - - /** - * Return the text range corresponding to the specified annotation. - * If the annotation is missing, return null. - */ - protected TextRange getAnnotationTextRange(CompilationUnit astRoot) { - return this.getTextRange(getAnnotation(astRoot)); - } - - protected org.eclipse.jdt.core.dom.Annotation getAnnotation(CompilationUnit astRoot) { - return this.daa.getAnnotation(getMember().getModifiedDeclaration(astRoot)); - - } - - protected Expression getAnnotationElementExpression(DeclarationAnnotationElementAdapter<?> adapter, CompilationUnit astRoot) { - return adapter.getExpression(getMember().getModifiedDeclaration(astRoot)); - } - - protected TextRange getAnnotationElementTextRange(DeclarationAnnotationElementAdapter<?> adapter, CompilationUnit astRoot) { - return this.getTextRange(getAnnotationElementExpression(adapter, astRoot)); - - } - - /** - * Convenience method. If the specified element is missing - * return the member's text range instead. - */ - protected TextRange getElementTextRange(DeclarationAnnotationElementAdapter<?> elementAdapter, CompilationUnit astRoot) { - return this.getElementTextRange(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.getTextRange(astRoot); - } - - /** - * Convenience method. Return whether the specified position touches the element. - * Returns false if the element does not exist - */ - protected boolean elementTouches(DeclarationAnnotationElementAdapter<?> elementAdapter, int pos, CompilationUnit astRoot) { - return this.elementTouches(getAnnotationElementTextRange(elementAdapter, astRoot), pos); - } - - /** - * Convenience method. Return whether element's text range is not - * null (meaning the element exists) and the specified position touches it. - */ - protected boolean elementTouches(TextRange elementTextRange, int pos) { - return (elementTextRange != null) && elementTextRange.touches(pos); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractResourceTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractResourceTable.java deleted file mode 100644 index 76381127c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractResourceTable.java +++ /dev/null @@ -1,339 +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.resource.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraint; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.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; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public abstract class AbstractResourceTable extends AbstractResourceAnnotation<Member> implements TableAnnotation -{ - // hold this so we can get the 'name' text range - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - - // hold this so we can get the 'schema' text range - private final DeclarationAnnotationElementAdapter<String> schemaDeclarationAdapter; - - // hold this so we can get the 'catalog' text range - private final DeclarationAnnotationElementAdapter<String> catalogDeclarationAdapter; - - private final AnnotationElementAdapter<String> nameAdapter; - - private final AnnotationElementAdapter<String> schemaAdapter; - - private final AnnotationElementAdapter<String> catalogAdapter; - - private String name; - - private String catalog; - - private String schema; - - private final List<NestableUniqueConstraint> uniqueConstraints; - - private final UniqueConstraintsContainerAnnotation uniqueConstraintsContainerAnnotation; - - protected AbstractResourceTable(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.nameDeclarationAdapter = this.nameAdapter(daa); - this.schemaDeclarationAdapter = this.schemaAdapter(daa); - this.catalogDeclarationAdapter = this.catalogAdapter(daa); - this.nameAdapter = buildAnnotationElementAdapter(this.nameDeclarationAdapter); - this.schemaAdapter = buildAnnotationElementAdapter(this.schemaDeclarationAdapter); - this.catalogAdapter = buildAnnotationElementAdapter(this.catalogDeclarationAdapter); - this.uniqueConstraints = new ArrayList<NestableUniqueConstraint>(); - this.uniqueConstraintsContainerAnnotation = new UniqueConstraintsContainerAnnotation(); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.name(astRoot); - this.catalog = this.catalog(astRoot); - this.schema = this.schema(astRoot); - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this.uniqueConstraintsContainerAnnotation); - } - - protected AnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(this.getMember(), daea); - } - - /** - * Build and return a declaration element adapter for the table's 'name' element - */ - protected abstract DeclarationAnnotationElementAdapter<String> nameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter); - - /** - * Build and return a declaration element adapter for the table's 'schema' element - */ - protected abstract DeclarationAnnotationElementAdapter<String> schemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter); - - /** - * Build and return a declaration element adapter for the table's 'catalog' element - */ - protected abstract DeclarationAnnotationElementAdapter<String> catalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter); - - - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String newCatalog) { - if (attributeValueHasNotChanged(this.catalog, newCatalog)) { - return; - } - String oldCatalog = this.catalog; - this.catalog = newCatalog; - this.catalogAdapter.setValue(newCatalog); - firePropertyChanged(CATALOG_PROPERTY, oldCatalog, newCatalog); - } - - public String getSchema() { - return this.schema; - } - - public void setSchema(String newSchema) { - if (attributeValueHasNotChanged(this.schema, newSchema)) { - return; - } - String oldSchema = this.schema; - this.schema = newSchema; - this.schemaAdapter.setValue(newSchema); - firePropertyChanged(SCHEMA_PROPERTY, oldSchema, newSchema); - } - - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return new CloneListIterator<UniqueConstraintAnnotation>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public NestableUniqueConstraint uniqueConstraintAt(int index) { - return this.uniqueConstraints.get(index); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - return this.uniqueConstraints.indexOf(uniqueConstraint); - } - - public NestableUniqueConstraint addUniqueConstraint(int index) { - NestableUniqueConstraint uniqueConstraint = (NestableUniqueConstraint) ContainerAnnotationTools.addNestedAnnotation(index, this.uniqueConstraintsContainerAnnotation); - fireItemAdded(TableAnnotation.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - private void addUniqueConstraint(int index, NestableUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - public void removeUniqueConstraint(int index) { - NestableUniqueConstraint uniqueConstraint = this.uniqueConstraintAt(index); - removeUniqueConstraint(uniqueConstraint); - uniqueConstraint.removeAnnotation(); - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, this.uniqueConstraintsContainerAnnotation); - } - - private void removeUniqueConstraint(NestableUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - moveUniqueConstraintInternal(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, this.uniqueConstraintsContainerAnnotation); - fireItemMoved(TableAnnotation.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void moveUniqueConstraintInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - } - - protected abstract NestableUniqueConstraint createUniqueConstraint(int index); - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - return getElementTextRange(this.schemaDeclarationAdapter, astRoot); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return getElementTextRange(this.catalogDeclarationAdapter, astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.nameDeclarationAdapter, pos, astRoot); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.catalogDeclarationAdapter, pos, astRoot); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.schemaDeclarationAdapter, pos, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - this.setSchema(this.schema(astRoot)); - this.setCatalog(this.catalog(astRoot)); - this.updateUniqueConstraintsFromJava(astRoot); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - protected String schema(CompilationUnit astRoot) { - return this.schemaAdapter.getValue(astRoot); - } - - protected String catalog(CompilationUnit astRoot) { - return this.catalogAdapter.getValue(astRoot); - } - - /** - * here we just worry about getting the unique constraints lists the same size; - * then we delegate to the unique constraints to synch themselves up - */ - private void updateUniqueConstraintsFromJava(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this.uniqueConstraintsContainerAnnotation); - } - - - private class UniqueConstraintsContainerAnnotation extends AbstractJavaResourceNode - implements ContainerAnnotation<NestableUniqueConstraint> - { - public UniqueConstraintsContainerAnnotation() { - super(AbstractResourceTable.this); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public NestableUniqueConstraint addInternal(int index) { - NestableUniqueConstraint uniqueConstraint = AbstractResourceTable.this.createUniqueConstraint(index); - AbstractResourceTable.this.uniqueConstraints.add(index, uniqueConstraint); - return uniqueConstraint; - } - - public NestableUniqueConstraint add(int index) { - NestableUniqueConstraint uniqueConstraint = AbstractResourceTable.this.createUniqueConstraint(index); - AbstractResourceTable.this.addUniqueConstraint(index, uniqueConstraint); - return uniqueConstraint; - } - - public String getAnnotationName() { - return AbstractResourceTable.this.getAnnotationName(); - } - - public String getNestableAnnotationName() { - return JPA.UNIQUE_CONSTRAINT; - } - - public int indexOf(NestableUniqueConstraint uniqueConstraint) { - return AbstractResourceTable.this.indexOfUniqueConstraint(uniqueConstraint); - } - - public void move(int targetIndex, int sourceIndex) { - AbstractResourceTable.this.moveUniqueConstraint(targetIndex, sourceIndex); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - AbstractResourceTable.this.moveUniqueConstraintInternal(targetIndex, sourceIndex); - } - - public NestableUniqueConstraint nestedAnnotationAt(int index) { - return AbstractResourceTable.this.uniqueConstraintAt(index); - } - - public NestableUniqueConstraint nestedAnnotationFor(Annotation jdtAnnotation) { - for (NestableUniqueConstraint uniqueConstraint : CollectionTools.iterable(nestedAnnotations())) { - if (jdtAnnotation == uniqueConstraint.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return uniqueConstraint; - } - } - return null; - } - - public ListIterator<NestableUniqueConstraint> nestedAnnotations() { - return new CloneListIterator<NestableUniqueConstraint>(AbstractResourceTable.this.uniqueConstraints); - } - - public int nestedAnnotationsSize() { - return AbstractResourceTable.this.uniqueConstraintsSize(); - } - - public void remove(NestableUniqueConstraint uniqueConstraint) { - AbstractResourceTable.this.removeUniqueConstraint(uniqueConstraint); - } - - public void remove(int index) { - this.remove(nestedAnnotationAt(index)); - } - - public Annotation getJdtAnnotation(CompilationUnit astRoot) { - return AbstractResourceTable.this.getJdtAnnotation(astRoot); - } - - public void newAnnotation() { - AbstractResourceTable.this.newAnnotation(); - } - - public void removeAnnotation() { - AbstractResourceTable.this.removeAnnotation(); - } - - public void update(CompilationUnit astRoot) { - AbstractResourceTable.this.update(astRoot); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return AbstractResourceTable.this.getTextRange(astRoot); - } - - public String getElementName() { - return "uniqueConstraints"; - } - - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverrideImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverrideImpl.java deleted file mode 100644 index 0fa1e787b1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverrideImpl.java +++ /dev/null @@ -1,285 +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.resource.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.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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverride; -import org.eclipse.jpt.core.resource.java.NestableJoinColumn; -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.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; - -public class AssociationOverrideImpl - extends OverrideImpl - implements NestableAssociationOverride -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final List<NestableJoinColumn> joinColumns; - - private final JoinColumnsContainerAnnotation joinColumnsContainerAnnotation; - - protected AssociationOverrideImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.joinColumns = new ArrayList<NestableJoinColumn>(); - this.joinColumnsContainerAnnotation = new JoinColumnsContainerAnnotation(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this.joinColumnsContainerAnnotation); - } - - public String getAnnotationName() { - return AssociationOverrideAnnotation.ANNOTATION_NAME; - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - AssociationOverrideAnnotation oldAssociationOverride = (AssociationOverrideAnnotation) oldAnnotation; - for (JoinColumnAnnotation joinColumn : CollectionTools.iterable(oldAssociationOverride.joinColumns())) { - NestableJoinColumn newJoinColumn = addJoinColumn(oldAssociationOverride.indexOfJoinColumn(joinColumn)); - newJoinColumn.initializeFrom((NestableAnnotation) joinColumn); - } - } - - - // ************* Association implementation ******************* - - public ListIterator<JoinColumnAnnotation> joinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.joinColumns); - } - - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - public NestableJoinColumn joinColumnAt(int index) { - return this.joinColumns.get(index); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public NestableJoinColumn addJoinColumn(int index) { - NestableJoinColumn joinColumn = (NestableJoinColumn) ContainerAnnotationTools.addNestedAnnotation(index, this.joinColumnsContainerAnnotation); - fireItemAdded(AssociationOverrideAnnotation.JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - private void addJoinColumn(int index, NestableJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.joinColumns, AssociationOverrideAnnotation.JOIN_COLUMNS_LIST); - } - - public void removeJoinColumn(int index) { - NestableJoinColumn joinColumn = this.joinColumns.get(index); - removeJoinColumn(joinColumn); - joinColumn.removeAnnotation(); - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, this.joinColumnsContainerAnnotation); - } - - private void removeJoinColumn(NestableJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.joinColumns, AssociationOverrideAnnotation.JOIN_COLUMNS_LIST); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - moveJoinColumnInternal(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, this.joinColumnsContainerAnnotation); - fireItemMoved(AssociationOverrideAnnotation.JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected void moveJoinColumnInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.joinColumns, targetIndex, sourceIndex); - } - - protected NestableJoinColumn createJoinColumn(int index) { - return JoinColumnImpl.createAssociationOverrideJoinColumn(getDeclarationAnnotationAdapter(), this, getMember(), index); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.updateJoinColumnsFromJava(astRoot); - } - - private void updateJoinColumnsFromJava(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this.joinColumnsContainerAnnotation); - } - - - // ********** static methods ********** - static AssociationOverrideImpl createAssociationOverride(JavaResourceNode parent, Member member) { - return new AssociationOverrideImpl(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - static AssociationOverrideImpl createNestedAssociationOverride(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new AssociationOverrideImpl(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(attributeOverridesAdapter, index, JPA.ASSOCIATION_OVERRIDE); - } - - private class JoinColumnsContainerAnnotation extends AbstractJavaResourceNode - implements ContainerAnnotation<NestableJoinColumn> - { - public JoinColumnsContainerAnnotation() { - super(AssociationOverrideImpl.this); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public NestableJoinColumn addInternal(int index) { - NestableJoinColumn joinColumn = AssociationOverrideImpl.this.createJoinColumn(index); - AssociationOverrideImpl.this.joinColumns.add(index, joinColumn); - return joinColumn; - } - - public NestableJoinColumn add(int index) { - NestableJoinColumn joinColumn = AssociationOverrideImpl.this.createJoinColumn(index); - AssociationOverrideImpl.this.addJoinColumn(index, joinColumn); - return joinColumn; - } - - public int indexOf(NestableJoinColumn pkJoinColumn) { - return AssociationOverrideImpl.this.indexOfJoinColumn(pkJoinColumn); - } - - public void move(int targetIndex, int sourceIndex) { - AssociationOverrideImpl.this.moveJoinColumn(targetIndex, sourceIndex); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - AssociationOverrideImpl.this.moveJoinColumnInternal(targetIndex, sourceIndex); - } - - public NestableJoinColumn nestedAnnotationAt(int index) { - return AssociationOverrideImpl.this.joinColumnAt(index); - } - - public ListIterator<NestableJoinColumn> nestedAnnotations() { - return new CloneListIterator<NestableJoinColumn>(AssociationOverrideImpl.this.joinColumns); - } - - public int nestedAnnotationsSize() { - return joinColumnsSize(); - } - - public void remove(int index) { - this.remove(nestedAnnotationAt(index)); - } - - public void remove(NestableJoinColumn joinColumn) { - AssociationOverrideImpl.this.removeJoinColumn(joinColumn); - } - - public String getAnnotationName() { - return AssociationOverrideImpl.this.getAnnotationName(); - } - - public String getNestableAnnotationName() { - return JPA.JOIN_COLUMN; - } - - public NestableJoinColumn nestedAnnotationFor(org.eclipse.jdt.core.dom.Annotation jdtAnnotation) { - for (NestableJoinColumn pkJoinColumn : CollectionTools.iterable(nestedAnnotations())) { - if (jdtAnnotation == pkJoinColumn.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return pkJoinColumn; - } - } - return null; - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return AssociationOverrideImpl.this.getJdtAnnotation(astRoot); - } - - public void newAnnotation() { - AssociationOverrideImpl.this.newAnnotation(); - } - - public void removeAnnotation() { - AssociationOverrideImpl.this.removeAnnotation(); - } - - public void update(CompilationUnit astRoot) { - AssociationOverrideImpl.this.update(astRoot); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return AssociationOverrideImpl.this.getTextRange(astRoot); - } - - public String getElementName() { - return "joinColumns"; - } - - } - - public static class AssociationOverrideAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final AssociationOverrideAnnotationDefinition INSTANCE = new AssociationOverrideAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private AssociationOverrideAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return AssociationOverrideImpl.createAssociationOverride(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return AssociationOverrideAnnotation.ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverridesImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverridesImpl.java deleted file mode 100644 index 393e49852c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AssociationOverridesImpl.java +++ /dev/null @@ -1,152 +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.resource.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAssociationOverride; -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; - -public class AssociationOverridesImpl extends AbstractResourceAnnotation<Member> implements AssociationOverridesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected final List<NestableAssociationOverride> associationOverrides; - - protected AssociationOverridesImpl(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.associationOverrides = new ArrayList<NestableAssociationOverride>(); - } - - public void initialize(CompilationUnit astRoot) { - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getNestableAnnotationName() { - return AssociationOverrideAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableAssociationOverride> nestedAnnotations() { - return new CloneListIterator<NestableAssociationOverride>(this.associationOverrides); - } - - public int nestedAnnotationsSize() { - return this.associationOverrides.size(); - } - - public NestableAssociationOverride addInternal(int index) { - NestableAssociationOverride associationOverride = createAssociationOverride(index); - this.associationOverrides.add(index, associationOverride); - return associationOverride; - } - - public NestableAssociationOverride add(int index) { - NestableAssociationOverride associationOverride = createAssociationOverride(index); - add(index, associationOverride); - return associationOverride; - } - - private void add(int index, NestableAssociationOverride associationOverride) { - addItemToList(index, associationOverride, this.associationOverrides, ASSOCIATION_OVERRIDES_LIST); - } - - public void remove(NestableAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.associationOverrides, ASSOCIATION_OVERRIDES_LIST); - } - - public void remove(int index) { - removeItemFromList(index, this.associationOverrides, ASSOCIATION_OVERRIDES_LIST); - } - - public int indexOf(NestableAssociationOverride associationOverride) { - return this.associationOverrides.indexOf(associationOverride); - } - - public NestableAssociationOverride nestedAnnotationAt(int index) { - return this.associationOverrides.get(index); - } - - public NestableAssociationOverride nestedAnnotationFor(Annotation jdtAnnotation) { - for (NestableAssociationOverride associationOverride : this.associationOverrides) { - if (jdtAnnotation == associationOverride.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return associationOverride; - } - } - return null; - } - - public void move(int targetIndex, int sourceIndex) { - moveItemInList(targetIndex, sourceIndex, this.associationOverrides, ASSOCIATION_OVERRIDES_LIST); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.associationOverrides, targetIndex, sourceIndex); - } - - public String getElementName() { - return "value"; - } - - public void update(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this); - } - - private AssociationOverrideImpl createAssociationOverride(int index) { - return AssociationOverrideImpl.createNestedAssociationOverride(this, getMember(), index, getDeclarationAnnotationAdapter()); - } - - public static class AssociationOverridesAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final AssociationOverridesAnnotationDefinition INSTANCE = new AssociationOverridesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private AssociationOverridesAnnotationDefinition() { - super(); - } - - public AssociationOverridesAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new AssociationOverridesImpl(parent, member); - } - - public AssociationOverridesAnnotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverrideImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverrideImpl.java deleted file mode 100644 index 6078367bef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverrideImpl.java +++ /dev/null @@ -1,163 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAttributeOverride; -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; - -public class AttributeOverrideImpl - extends OverrideImpl - implements NestableAttributeOverride -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final MemberAnnotationAdapter columnAdapter; - - private ColumnImpl column; - - - protected AttributeOverrideImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.columnAdapter = new MemberAnnotationAdapter(getMember(), ColumnImpl.buildAttributeOverrideAnnotationAdapter(getDeclarationAnnotationAdapter())); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - if (this.columnAdapter.getAnnotation(astRoot) != null) { - this.column = ColumnImpl.createAttributeOverrideColumn(this, getMember(), getDeclarationAnnotationAdapter()); - this.column.initialize(astRoot); - } - } - - public String getAnnotationName() { - return AttributeOverrideAnnotation.ANNOTATION_NAME; - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - AttributeOverrideAnnotation oldAttributeOverride = (AttributeOverrideAnnotation) oldAnnotation; - if (oldAttributeOverride.getColumn() != null) { - ColumnAnnotation column = addColumn(); - ((NestableAnnotation) column).initializeFrom((NestableAnnotation) oldAttributeOverride.getColumn()); - } - } - - //************ AttributeOverride implementation **************** - - public ColumnAnnotation getNonNullColumn() { - return (getColumn() != null) ? getColumn() : new NullAttributeOverrideColumn(this); - } - - public ColumnAnnotation getColumn() { - return this.column; - } - - public ColumnAnnotation addColumn() { - ColumnImpl column = ColumnImpl.createAttributeOverrideColumn(this, getMember(), getDeclarationAnnotationAdapter()); - column.newAnnotation(); - setColumn(column); - return column; - } - - public void removeColumn() { - this.column.removeAnnotation(); - setColumn(null); - } - - protected void setColumn(ColumnImpl newColumn) { - ColumnImpl oldColumn = this.column; - this.column = newColumn; - firePropertyChanged(AttributeOverrideAnnotation.COLUMN_PROPERTY, oldColumn, newColumn); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - if (this.columnAdapter.getAnnotation(astRoot) == null) { - this.setColumn(null); - } - else { - if (getColumn() != null) { - getColumn().update(astRoot); - } - else { - ColumnImpl column = ColumnImpl.createAttributeOverrideColumn(this, getMember(), getDeclarationAnnotationAdapter()); - column.initialize(astRoot); - this.setColumn(column); - } - } - } - - // ********** static methods ********** - static AttributeOverrideImpl createAttributeOverride(JavaResourceNode parent, Member member) { - return new AttributeOverrideImpl(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - static AttributeOverrideImpl createNestedAttributeOverride(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new AttributeOverrideImpl(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(attributeOverridesAdapter, index, JPA.ATTRIBUTE_OVERRIDE); - } - - public static class AttributeOverrideAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final AttributeOverrideAnnotationDefinition INSTANCE = new AttributeOverrideAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private AttributeOverrideAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return AttributeOverrideImpl.createAttributeOverride(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return AttributeOverrideAnnotation.ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverridesImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverridesImpl.java deleted file mode 100644 index e34de7acdd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AttributeOverridesImpl.java +++ /dev/null @@ -1,153 +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.resource.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAttributeOverride; -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; - -public class AttributeOverridesImpl extends AbstractResourceAnnotation<Member> implements AttributeOverridesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final List<NestableAttributeOverride> attributesOverrides; - - protected AttributeOverridesImpl(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.attributesOverrides = new ArrayList<NestableAttributeOverride>(); - } - - public void initialize(CompilationUnit astRoot) { - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getNestableAnnotationName() { - return AttributeOverrideAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableAttributeOverride> nestedAnnotations() { - return new CloneListIterator<NestableAttributeOverride>(this.attributesOverrides); - } - - public int nestedAnnotationsSize() { - return this.attributesOverrides.size(); - } - - public NestableAttributeOverride addInternal(int index) { - NestableAttributeOverride attributeOverride = createAttributeOverride(index); - this.attributesOverrides.add(index, attributeOverride); - return attributeOverride; - } - - public NestableAttributeOverride add(int index) { - NestableAttributeOverride attributeOverride = createAttributeOverride(index); - add(index, attributeOverride); - return attributeOverride; - } - - private void add(int index, NestableAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.attributesOverrides, ATTRIBUTE_OVERRIDES_LIST); - } - - public void remove(NestableAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.attributesOverrides, ATTRIBUTE_OVERRIDES_LIST); - } - - public void remove(int index) { - removeItemFromList(index, this.attributesOverrides, ATTRIBUTE_OVERRIDES_LIST); - } - - public int indexOf(NestableAttributeOverride attributeOverride) { - return this.attributesOverrides.indexOf(attributeOverride); - } - - public NestableAttributeOverride nestedAnnotationAt(int index) { - return this.attributesOverrides.get(index); - } - - public NestableAttributeOverride nestedAnnotationFor(Annotation jdtAnnotation) { - for (NestableAttributeOverride attributeOverride : this.attributesOverrides) { - if (jdtAnnotation == attributeOverride.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return attributeOverride; - } - } - return null; - } - - public void move(int targetIndex, int sourceIndex) { - moveItemInList(targetIndex, sourceIndex, this.attributesOverrides, ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.attributesOverrides, targetIndex, sourceIndex); - } - - public String getElementName() { - return "value"; - } - - public void update(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this); - } - - private AttributeOverrideImpl createAttributeOverride(int index) { - return AttributeOverrideImpl.createNestedAttributeOverride(this, getMember(), index, getDeclarationAnnotationAdapter()); - } - - - public static class AttributeOverridesAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final AttributeOverridesAnnotationDefinition INSTANCE = new AttributeOverridesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private AttributeOverridesAnnotationDefinition() { - super(); - } - - public AttributeOverridesAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new AttributeOverridesImpl(parent, member); - } - - public AttributeOverridesAnnotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BaseColumnImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BaseColumnImpl.java deleted file mode 100644 index 83558cd2ba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BaseColumnImpl.java +++ /dev/null @@ -1,233 +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.resource.java; - -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; - -public abstract class BaseColumnImpl extends AbstractNamedColumn implements BaseColumnAnnotation -{ - // hold this so we can get the 'table' text range - private final DeclarationAnnotationElementAdapter<String> tableDeclarationAdapter; - - // hold this so we can get the 'unique' text range - private final DeclarationAnnotationElementAdapter<Boolean> uniqueDeclarationAdapter; - - // hold this so we can get the 'nullable' text range - private final DeclarationAnnotationElementAdapter<Boolean> nullableDeclarationAdapter; - - // hold this so we can get the 'insertable' text range - private final DeclarationAnnotationElementAdapter<Boolean> insertableDeclarationAdapter; - - // hold this so we can get the 'updatable' text range - private final DeclarationAnnotationElementAdapter<Boolean> updatableDeclarationAdapter; - - private final AnnotationElementAdapter<String> tableAdapter; - - private final AnnotationElementAdapter<Boolean> uniqueAdapter; - - private final AnnotationElementAdapter<Boolean> nullableAdapter; - - private final AnnotationElementAdapter<Boolean> insertableAdapter; - - private final AnnotationElementAdapter<Boolean> updatableAdapter; - - private String table; - private Boolean unique; - private Boolean nullable; - private Boolean insertable; - private Boolean updatable; - - - public BaseColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - public BaseColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.tableDeclarationAdapter = this.buildStringElementAdapter(this.tableElementName()); - this.tableAdapter = this.buildShortCircuitElementAdapter(this.tableDeclarationAdapter); - this.uniqueDeclarationAdapter = this.buildBooleanElementAdapter(this.uniqueElementName()); - this.uniqueAdapter = this.buildShortCircuitBooleanElementAdapter(this.uniqueDeclarationAdapter); - this.nullableDeclarationAdapter = this.buildBooleanElementAdapter(this.nullableElementName()); - this.nullableAdapter = this.buildShortCircuitBooleanElementAdapter(this.nullableDeclarationAdapter); - this.insertableDeclarationAdapter = this.buildBooleanElementAdapter(this.insertableElementName()); - this.insertableAdapter = this.buildShortCircuitBooleanElementAdapter(this.insertableDeclarationAdapter); - this.updatableDeclarationAdapter = this.buildBooleanElementAdapter(this.updatableElementName()); - this.updatableAdapter = this.buildShortCircuitBooleanElementAdapter(this.updatableDeclarationAdapter); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.table = this.table(astRoot); - this.unique = this.unique(astRoot); - this.nullable = this.nullable(astRoot); - this.insertable = this.insertable(astRoot); - this.updatable = this.updatable(astRoot); - } - - protected abstract String tableElementName(); - - protected abstract String uniqueElementName(); - - protected abstract String nullableElementName(); - - protected abstract String insertableElementName(); - - protected abstract String updatableElementName(); - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - BaseColumnAnnotation oldColumn = (BaseColumnAnnotation) oldAnnotation; - setTable(oldColumn.getTable()); - setUnique(oldColumn.getUnique()); - setNullable(oldColumn.getNullable()); - setInsertable(oldColumn.getInsertable()); - setUpdatable(oldColumn.getUpdatable()); - } - - //************* AbstractColumn implementation ************* - public String getTable() { - return this.table; - } - - public void setTable(String newTable) { - if (attributeValueHasNotChanged(this.table, newTable)) { - return; - } - String oldTable = this.table; - this.table = newTable; - this.tableAdapter.setValue(newTable); - firePropertyChanged(TABLE_PROPERTY, oldTable, newTable); - } - - public Boolean getUnique() { - return this.unique; - } - - public void setUnique(Boolean newUnique) { - if (attributeValueHasNotChanged(this.unique, newUnique)) { - return; - } - Boolean oldUnique = this.unique; - this.unique = newUnique; - this.uniqueAdapter.setValue(newUnique); - firePropertyChanged(UNIQUE_PROPERTY, oldUnique, newUnique); - } - - public Boolean getNullable() { - return this.nullable; - } - - public void setNullable(Boolean newNullable) { - if (attributeValueHasNotChanged(this.nullable, newNullable)) { - return; - } - Boolean oldNullable = this.nullable; - this.nullable = newNullable; - this.nullableAdapter.setValue(newNullable); - firePropertyChanged(NULLABLE_PROPERTY, oldNullable, newNullable); - } - - public Boolean getInsertable() { - return this.insertable; - } - - public void setInsertable(Boolean newInsertable) { - if (attributeValueHasNotChanged(this.insertable, newInsertable)) { - return; - } - Boolean oldInsertable = this.insertable; - this.insertable = newInsertable; - this.insertableAdapter.setValue(newInsertable); - firePropertyChanged(INSERTABLE_PROPERTY, oldInsertable, newInsertable); - } - - public Boolean getUpdatable() { - return this.updatable; - } - - public void setUpdatable(Boolean newUpdatable) { - if (attributeValueHasNotChanged(this.updatable, newUpdatable)) { - return; - } - Boolean oldUpdatable = this.updatable; - this.updatable = newUpdatable; - this.updatableAdapter.setValue(newUpdatable); - firePropertyChanged(UPDATABLE_PROPERTY, oldUpdatable, newUpdatable); - } - - public TextRange getNullableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nullableDeclarationAdapter, astRoot); - } - - public TextRange getInsertableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.insertableDeclarationAdapter, astRoot); - } - - public TextRange getUniqueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.uniqueDeclarationAdapter, astRoot); - } - - public TextRange getUpdatableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.updatableDeclarationAdapter, 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); - } - - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setTable(this.table(astRoot)); - this.setUnique(this.unique(astRoot)); - this.setNullable(this.nullable(astRoot)); - this.setInsertable(this.insertable(astRoot)); - this.setUpdatable(this.updatable(astRoot)); - } - - protected String table(CompilationUnit astRoot) { - return this.tableAdapter.getValue(astRoot); - } - - protected Boolean unique(CompilationUnit astRoot) { - return this.uniqueAdapter.getValue(astRoot); - } - - protected Boolean nullable(CompilationUnit astRoot) { - return this.nullableAdapter.getValue(astRoot); - } - - protected Boolean insertable(CompilationUnit astRoot) { - return this.insertableAdapter.getValue(astRoot); - } - - protected Boolean updatable(CompilationUnit astRoot) { - return this.updatableAdapter.getValue(astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BasicImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BasicImpl.java deleted file mode 100644 index cd187a977d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/BasicImpl.java +++ /dev/null @@ -1,155 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.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.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - - -public class BasicImpl extends AbstractResourceAnnotation<Attribute> implements BasicAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final AnnotationElementAdapter<Boolean> optionalAdapter; - - private final AnnotationElementAdapter<String> fetchAdapter; - - private static final DeclarationAnnotationElementAdapter<Boolean> OPTIONAL_ADAPTER = buildOptionalAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private Boolean optional; - - private FetchType fetch; - - protected BasicImpl(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 void initialize(CompilationUnit astRoot) { - this.optional = this.optional(astRoot); - this.fetch = this.fetch(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - //*************** Basic implementation **************** - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean newOptional) { - if (attributeValueHasNotChanged(this.optional, newOptional)) { - return; - } - Boolean oldOptional = this.optional; - this.optional = newOptional; - this.optionalAdapter.setValue(newOptional); - firePropertyChanged(OPTIONAL_PROPERTY, oldOptional, newOptional); - } - - public FetchType getFetch() { - return this.fetch; - } - - public void setFetch(FetchType newFetch) { - if (attributeValueHasNotChanged(this.fetch, newFetch)) { - return; - } - FetchType oldFetch = this.fetch; - this.fetch = newFetch; - this.fetchAdapter.setValue(FetchType.toJavaAnnotationValue(newFetch)); - firePropertyChanged(FETCH_PROPERTY, oldFetch, newFetch); - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(FETCH_ADAPTER, astRoot); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(OPTIONAL_ADAPTER, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setOptional(this.optional(astRoot)); - this.setFetch(this.fetch(astRoot)); - } - - protected FetchType fetch(CompilationUnit astRoot) { - return FetchType.fromJavaAnnotationValue(this.fetchAdapter.getValue(astRoot)); - } - - protected Boolean optional(CompilationUnit astRoot) { - return this.optionalAdapter.getValue(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); - } - - public static class BasicAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final BasicAnnotationDefinition INSTANCE = new BasicAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static BasicAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private BasicAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new BasicImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullBasic(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java deleted file mode 100644 index b4f56ed5ab..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ColumnImpl.java +++ /dev/null @@ -1,242 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -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; - -public class ColumnImpl extends BaseColumnImpl implements ColumnAnnotation, NestableAnnotation -{ - // 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); - - // hold this so we can get the 'length' text range - private final DeclarationAnnotationElementAdapter<Integer> lengthDeclarationAdapter; - - // hold this so we can get the 'precision' text range - private final DeclarationAnnotationElementAdapter<Integer> precisionDeclarationAdapter; - - // hold this so we can get the 'scale' text range - private final DeclarationAnnotationElementAdapter<Integer> scaleDeclarationAdapter; - - private final AnnotationElementAdapter<Integer> lengthAdapter; - - private final AnnotationElementAdapter<Integer> precisionAdapter; - - private final AnnotationElementAdapter<Integer> scaleAdapter; - - private Integer length; - - private Integer precision; - - private Integer scale; - - protected ColumnImpl(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); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.length = this.length(astRoot); - this.precision = this.precision(astRoot); - this.scale = this.scale(astRoot); - } - - @Override - protected String nameElementName() { - return JPA.COLUMN__NAME; - } - - @Override - protected String columnDefinitionElementName() { - return JPA.COLUMN__COLUMN_DEFINITION; - } - - @Override - protected String tableElementName() { - return JPA.COLUMN__TABLE; - } - - @Override - protected String uniqueElementName() { - return JPA.COLUMN__UNIQUE; - } - - @Override - protected String nullableElementName() { - return JPA.COLUMN__NULLABLE; - } - - @Override - protected String insertableElementName() { - return JPA.COLUMN__INSERTABLE; - } - - @Override - protected String updatableElementName() { - return JPA.COLUMN__UPDATABLE; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void moveAnnotation(int newIndex) { - //TODO move makes no sense for Column. maybe NestableAnnotation - //needs to be split up and we could have IndexableAnnotation - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - ColumnAnnotation oldColumn = (ColumnAnnotation) oldAnnotation; - setLength(oldColumn.getLength()); - setPrecision(oldColumn.getPrecision()); - setScale(oldColumn.getScale()); - } - - //************** Column implementation ************** - public Integer getLength() { - return this.length; - } - - public void setLength(Integer newLength) { - if (attributeValueHasNotChanged(this.length, newLength)) { - return; - } - Integer oldLength = this.length; - this.length = newLength; - this.lengthAdapter.setValue(newLength); - firePropertyChanged(LENGTH_PROPERTY, oldLength, newLength); - } - - public Integer getPrecision() { - return this.precision; - } - - public void setPrecision(Integer newPrecision) { - if (attributeValueHasNotChanged(this.precision, newPrecision)) { - return; - } - Integer oldPrecision = this.precision; - this.precision = newPrecision; - this.precisionAdapter.setValue(newPrecision); - firePropertyChanged(PRECISION_PROPERTY, oldPrecision, newPrecision); - } - - public Integer getScale() { - return this.scale; - } - - public void setScale(Integer newScale) { - if (attributeValueHasNotChanged(this.scale, newScale)) { - return; - } - Integer oldScale = this.scale; - this.scale = newScale; - this.scaleAdapter.setValue(newScale); - firePropertyChanged(SCALE_PROPERTY, oldScale, newScale); - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.lengthDeclarationAdapter, astRoot); - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.precisionDeclarationAdapter, astRoot); - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.scaleDeclarationAdapter, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setLength(this.length(astRoot)); - this.setPrecision(this.precision(astRoot)); - this.setScale(this.scale(astRoot)); - } - - protected Integer length(CompilationUnit astRoot) { - return this.lengthAdapter.getValue(astRoot); - } - - protected Integer precision(CompilationUnit astRoot) { - return this.precisionAdapter.getValue(astRoot); - } - - protected Integer scale(CompilationUnit astRoot) { - return this.scaleAdapter.getValue(astRoot); - } - - // ********** static methods ********** - - static ColumnImpl createAttributeOverrideColumn(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter attributeOverrideAnnotationAdapter) { - return new ColumnImpl(parent, member, buildAttributeOverrideAnnotationAdapter(attributeOverrideAnnotationAdapter)); - } - - static DeclarationAnnotationAdapter buildAttributeOverrideAnnotationAdapter(DeclarationAnnotationAdapter attributeOverrideAnnotationAdapter) { - return new NestedDeclarationAnnotationAdapter(attributeOverrideAnnotationAdapter, JPA.ATTRIBUTE_OVERRIDE__COLUMN, JPA.COLUMN); - } - - public static class ColumnAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final ColumnAnnotationDefinition INSTANCE = new ColumnAnnotationDefinition(); - - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private ColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new ColumnImpl(parent, member, ColumnImpl.MAPPING_DECLARATION_ANNOTATION_ADAPTER); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullColumn(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ContainerAnnotationTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ContainerAnnotationTools.java deleted file mode 100644 index eb7a5d2755..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ContainerAnnotationTools.java +++ /dev/null @@ -1,198 +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.resource.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.ASTVisitor; -import org.eclipse.jdt.core.dom.CompilationUnit; -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.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.NestableAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class ContainerAnnotationTools -{ - - public static NestableAnnotation addNestedAnnotation(int index, ContainerAnnotation<? extends NestableAnnotation> containerAnnotation) { - int size = containerAnnotation.nestedAnnotationsSize(); - NestableAnnotation nestedAnnotation = containerAnnotation.addInternal(size); - nestedAnnotation.newAnnotation(); - containerAnnotation.moveInternal(index, size); - synchAnnotationsAfterMove(index, size, containerAnnotation); - return nestedAnnotation; - } - - /** - * synchronize the source annotations with the model nestableAnnotations, - * starting at the end of the list to prevent overlap - */ - public static void synchAnnotationsAfterAdd(int index, ContainerAnnotation<? extends NestableAnnotation> containerAnnotation) { - List<NestableAnnotation> nestableAnnotations = CollectionTools.list(containerAnnotation.nestedAnnotations()); - for (int i = nestableAnnotations.size(); i-- > index;) { - synch(nestableAnnotations.get(i), i); - } - } - - /** - * synchronize the source annotations with the model nestableAnnotations, - * starting at the specified index to prevent overlap - */ - public static void synchAnnotationsAfterRemove(int index, ContainerAnnotation<? extends NestableAnnotation> pluralAnnotation) { - List<NestableAnnotation> nestableAnnotations = CollectionTools.list(pluralAnnotation.nestedAnnotations()); - for (int i = index; i < nestableAnnotations.size(); i++) { - synch(nestableAnnotations.get(i), i); - } - } - - private static void synch(NestableAnnotation nestableAnnotation, int index) { - nestableAnnotation.moveAnnotation(index); - } - - /** - * synchronize the annotations with the model nestableAnnotations - */ - public static void synchAnnotationsAfterMove(int targetIndex, int sourceIndex, ContainerAnnotation<? extends NestableAnnotation> containerAnnotation) { - NestableAnnotation nestableAnnotation = containerAnnotation.nestedAnnotationAt(targetIndex); - - synch(nestableAnnotation, containerAnnotation.nestedAnnotationsSize()); - - List<NestableAnnotation> nestableAnnotations = CollectionTools.list(containerAnnotation.nestedAnnotations()); - if (sourceIndex < targetIndex) { - for (int i = sourceIndex; i < targetIndex; i++) { - synch(nestableAnnotations.get(i), i); - } - } - else { - for (int i = sourceIndex; i > targetIndex; i-- ) { - synch(nestableAnnotations.get(i), i); - } - } - synch(nestableAnnotation, targetIndex); - } - - - public static void initializeNestedAnnotations(CompilationUnit astRoot, ContainerAnnotation<?> containerAnnotation) { - addAnnotationsFromSource(astRoot, containerAnnotation); - } - - private static void addAnnotationsFromSource(CompilationUnit astRoot, ContainerAnnotation<? extends NestableAnnotation> containerAnnotation) { - containerAnnotation.getJdtAnnotation(astRoot).accept(initialJavaMemberAnnotationAstVisitor(astRoot, containerAnnotation)); - } - - /** - * Only visit the member value pair with the given element name. - * If there is no element name (like in the case of value elements) - * then we will visit all annotations with the annotation name inside - * the given container annotation - */ - private static ASTVisitor initialJavaMemberAnnotationAstVisitor(final CompilationUnit astRoot, final ContainerAnnotation<? extends NestableAnnotation> containerAnnotation) { - return new ASTVisitor() { - @Override - public boolean visit(MemberValuePair node) { - return node.getName().getFullyQualifiedName().equals(containerAnnotation.getElementName()); - } - @Override - public boolean visit(SingleMemberAnnotation node) { - return visit((org.eclipse.jdt.core.dom.Annotation) node); - } - - @Override - public boolean visit(NormalAnnotation node) { - return visit((org.eclipse.jdt.core.dom.Annotation) node); - } - - @Override - public boolean visit(MarkerAnnotation node) { - return visit((org.eclipse.jdt.core.dom.Annotation) node); - } - - private boolean visit(org.eclipse.jdt.core.dom.Annotation node) { - if (containerAnnotation.getAnnotationName().equals(JDTTools.resolveAnnotation(node))) { - return true; - } - if (containerAnnotation.getNestableAnnotationName().equals(JDTTools.resolveAnnotation(node))) { - Annotation nestedAnnotation = containerAnnotation.addInternal(containerAnnotation.nestedAnnotationsSize()); - nestedAnnotation.initialize(astRoot); - } - return false; - } - }; - } - - public static void updateNestedAnnotationsFromJava(CompilationUnit astRoot, ContainerAnnotation<?> containerAnnotation) { - addOrUpdateAnnotationInSource(astRoot, containerAnnotation); - //TODO not sure how to handle generics here and get rid of this warning - removeAnnotationsNotInSource(astRoot, (ContainerAnnotation<NestableAnnotation>) containerAnnotation); - } - - private static void addOrUpdateAnnotationInSource(CompilationUnit astRoot, ContainerAnnotation<? extends NestableAnnotation> containerAnnotation) { - containerAnnotation.getJdtAnnotation(astRoot).accept(javaMemberAnnotationAstVisitor(astRoot, containerAnnotation)); - } - - private static void removeAnnotationsNotInSource(CompilationUnit astRoot, ContainerAnnotation<NestableAnnotation> containerAnnotation) { - for (NestableAnnotation annotation : CollectionTools.iterable(containerAnnotation.nestedAnnotations())) { - if (annotation.getJdtAnnotation(astRoot) == null) { - containerAnnotation.remove(annotation); - } - } - } - - /** - * Only visit the member value pair with the given element name. - * If there is no element name (like in the case of value elements) - * then we will visit all annotations with the annotation name inside - * the given container annotation - */ - private static ASTVisitor javaMemberAnnotationAstVisitor(final CompilationUnit astRoot, final ContainerAnnotation<? extends NestableAnnotation> containerAnnotation) { - return new ASTVisitor() { - @Override - public boolean visit(MemberValuePair node) { - return node.getName().getFullyQualifiedName().equals(containerAnnotation.getElementName()); - } - - @Override - public boolean visit(SingleMemberAnnotation node) { - return visit((org.eclipse.jdt.core.dom.Annotation) node); - } - - @Override - public boolean visit(NormalAnnotation node) { - return visit((org.eclipse.jdt.core.dom.Annotation) node); - } - - @Override - public boolean visit(MarkerAnnotation node) { - return visit((org.eclipse.jdt.core.dom.Annotation) node); - } - - private boolean visit(org.eclipse.jdt.core.dom.Annotation node) { - if (containerAnnotation.getAnnotationName().equals(JDTTools.resolveAnnotation(node))) { - return true; - } - if (containerAnnotation.getNestableAnnotationName().equals(JDTTools.resolveAnnotation(node))) { - NestableAnnotation nestedAnnotation = containerAnnotation.nestedAnnotationFor(node); - if (nestedAnnotation != null) { - nestedAnnotation.update(astRoot); - } - else { - nestedAnnotation = containerAnnotation.add(containerAnnotation.nestedAnnotationsSize()); - nestedAnnotation.initialize(astRoot); - } - } - return false; - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorColumnImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorColumnImpl.java deleted file mode 100644 index 313591848b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorColumnImpl.java +++ /dev/null @@ -1,168 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -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; - -public class DiscriminatorColumnImpl extends AbstractNamedColumn implements DiscriminatorColumnAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> DISCRIMINATOR_TYPE_ADAPTER = buildDiscriminatorTypeAdapter(); - - // hold this so we can get the 'length' text range - private final DeclarationAnnotationElementAdapter<Integer> lengthDeclarationAdapter; - - private final AnnotationElementAdapter<String> discriminatorTypeAdapter; - - private final AnnotationElementAdapter<Integer> lengthAdapter; - - private DiscriminatorType discriminatorType; - - private Integer length; - - protected DiscriminatorColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - super(parent, member, daa, new MemberAnnotationAdapter(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); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.discriminatorType = this.discriminatorType(astRoot); - this.length = this.length(astRoot); - } - - @Override - protected String nameElementName() { - return JPA.DISCRIMINATOR_COLUMN__NAME; - } - - @Override - protected String columnDefinitionElementName() { - return JPA.DISCRIMINATOR_COLUMN__COLUMN_DEFINITION; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void moveAnnotation(int newIndex) { - //TODO move makes no sense for DiscriminatorColumn. maybe NestableAnnotation - //needs to be split up and we could have IndexableAnnotation - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - DiscriminatorColumnAnnotation oldColumn = (DiscriminatorColumnAnnotation) oldAnnotation; - setLength(oldColumn.getLength()); - setDiscriminatorType(oldColumn.getDiscriminatorType()); - } - - public DiscriminatorType getDiscriminatorType() { - return this.discriminatorType; - } - - public void setDiscriminatorType(DiscriminatorType newDiscriminatorType) { - if (attributeValueHasNotChanged(this.discriminatorType, newDiscriminatorType)) { - return; - } - DiscriminatorType oldDiscriminatorType = this.discriminatorType; - this.discriminatorType = newDiscriminatorType; - this.discriminatorTypeAdapter.setValue(DiscriminatorType.toJavaAnnotationValue(newDiscriminatorType)); - firePropertyChanged(DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newDiscriminatorType); - } - - public Integer getLength() { - return this.length; - } - - public void setLength(Integer newLength) { - if (attributeValueHasNotChanged(this.length, newLength)) { - return; - } - Integer oldLength = this.length; - this.length = newLength; - this.lengthAdapter.setValue(newLength); - firePropertyChanged(LENGTH_PROPERTY, oldLength, newLength); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setLength(this.length(astRoot)); - this.setDiscriminatorType(this.discriminatorType(astRoot)); - } - - protected Integer length(CompilationUnit astRoot) { - return this.lengthAdapter.getValue(astRoot); - } - - protected DiscriminatorType discriminatorType(CompilationUnit astRoot) { - return DiscriminatorType.fromJavaAnnotationValue(this.discriminatorTypeAdapter.getValue(astRoot)); - } - - // ********** static methods ********** - private static DeclarationAnnotationElementAdapter<String> buildDiscriminatorTypeAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.DISCRIMINATOR_COLUMN__DISCRIMINATOR_TYPE); - } - - public static class DiscriminatorColumnAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final DiscriminatorColumnAnnotationDefinition INSTANCE = new DiscriminatorColumnAnnotationDefinition(); - - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private DiscriminatorColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new DiscriminatorColumnImpl(parent, member, DiscriminatorColumnImpl.DECLARATION_ANNOTATION_ADAPTER); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullDiscriminatorColumn(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorValueImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorValueImpl.java deleted file mode 100644 index fa984e0423..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/DiscriminatorValueImpl.java +++ /dev/null @@ -1,115 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.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; -import org.eclipse.jpt.core.utility.jdt.Type; - -public class DiscriminatorValueImpl extends AbstractResourceAnnotation<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; - - protected DiscriminatorValueImpl(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(type, VALUE_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.value(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - if (attributeValueHasNotChanged(this.value, newValue)) { - return; - } - String oldValue = this.value; - this.value = newValue; - this.valueAdapter.setValue(newValue); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.value(astRoot)); - } - - protected String value(CompilationUnit astRoot) { - return this.valueAdapter.getValue(astRoot); - } - - // ********** static methods ********** - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.DISCRIMINATOR_VALUE__VALUE); - } - - - public static class DiscriminatorValueAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final DiscriminatorValueAnnotationDefinition INSTANCE = new DiscriminatorValueAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private DiscriminatorValueAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new DiscriminatorValueImpl(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullDiscriminatorValue(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddableImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddableImpl.java deleted file mode 100644 index b07d922b85..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddableImpl.java +++ /dev/null @@ -1,76 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - - -public class EmbeddableImpl extends AbstractResourceAnnotation<Type> implements EmbeddableAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected EmbeddableImpl(JavaResourcePersistentType parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void update(CompilationUnit astRoot) { - //no annotation members - } - - - public static class EmbeddableAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final EmbeddableAnnotationDefinition INSTANCE = new EmbeddableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static EmbeddableAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EmbeddableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new EmbeddableImpl((JavaResourcePersistentType) parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedIdImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedIdImpl.java deleted file mode 100644 index fafea9073a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedIdImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class EmbeddedIdImpl extends AbstractResourceAnnotation<Attribute> implements EmbeddedIdAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected EmbeddedIdImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void update(CompilationUnit astRoot) { - //no annotation members - } - - - public static class EmbeddedIdAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final EmbeddedIdAnnotationDefinition INSTANCE = new EmbeddedIdAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static EmbeddedIdAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EmbeddedIdAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new EmbeddedIdImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedImpl.java deleted file mode 100644 index da799de963..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EmbeddedImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - - -public class EmbeddedImpl extends AbstractResourceAnnotation<Attribute> implements EmbeddedAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected EmbeddedImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void update(CompilationUnit astRoot) { - //no annotation members - } - - public static class EmbeddedAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final EmbeddedAnnotationDefinition INSTANCE = new EmbeddedAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static EmbeddedAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EmbeddedAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new EmbeddedImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullEmbedded(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EntityImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EntityImpl.java deleted file mode 100644 index b9254badad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EntityImpl.java +++ /dev/null @@ -1,120 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -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.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - - -public class EntityImpl extends AbstractResourceAnnotation<Type> implements EntityAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final AnnotationElementAdapter<String> nameAdapter; - - private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildNameAdapter(); - - private String name; - - protected EntityImpl(JavaResourcePersistentType parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(getMember(), NAME_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.name(astRoot); - } - - //*********** Annotation implementation **************** - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - - //*********** Entity implementation **************** - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(EntityAnnotation.NAME_PROPERTY, oldName, newName); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(NAME_ADAPTER, astRoot); - } - - //*********** JavaResource implementation **************** - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(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 - } - - - public static class EntityAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final EntityAnnotationDefinition INSTANCE = new EntityAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static EntityAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EntityAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new EntityImpl((JavaResourcePersistentType) parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EnumeratedImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EnumeratedImpl.java deleted file mode 100644 index 9caf0c0544..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/EnumeratedImpl.java +++ /dev/null @@ -1,116 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.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.Attribute; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class EnumeratedImpl extends AbstractResourceAnnotation<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; - - protected EnumeratedImpl(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, VALUE_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.value(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public EnumType getValue() { - return this.value; - } - - public void setValue(EnumType newValue) { - if (attributeValueHasNotChanged(this.value, newValue)) { - return; - } - EnumType oldValue = this.value; - this.value = newValue; - this.valueAdapter.setValue(EnumType.toJavaAnnotationValue(newValue)); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.value(astRoot)); - } - - protected EnumType value(CompilationUnit astRoot) { - return EnumType.fromJavaAnnotationValue(this.valueAdapter.getValue(astRoot)); - } - - // ********** static methods ********** - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ENUMERATED__VALUE); - } - - public static class EnumeratedAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final EnumeratedAnnotationDefinition INSTANCE = new EnumeratedAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EnumeratedAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new EnumeratedImpl(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullEnumerated(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueImpl.java deleted file mode 100644 index 68438c0a09..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueImpl.java +++ /dev/null @@ -1,152 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.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; - -public class GeneratedValueImpl extends AbstractResourceAnnotation<Member> implements GeneratedValueAnnotation -{ - private final AnnotationElementAdapter<String> strategyAdapter; - - private final AnnotationElementAdapter<String> generatorAdapter; - - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> STRATEGY_ADAPTER = buildStrategyAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> GENERATOR_ADAPTER = buildGeneratorAdapter(); - - private GenerationType strategy; - - private String generator; - - - protected GeneratedValueImpl(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 void initialize(CompilationUnit astRoot) { - this.strategy = this.strategy(astRoot); - this.generator = this.generator(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public GenerationType getStrategy() { - return this.strategy; - } - - public void setStrategy(GenerationType newStrategy) { - if (attributeValueHasNotChanged(this.strategy, newStrategy)) { - return; - } - GenerationType oldStrategy = this.strategy; - this.strategy = newStrategy; - this.strategyAdapter.setValue(GenerationType.toJavaAnnotationValue(newStrategy)); - firePropertyChanged(STRATEGY_PROPERTY, oldStrategy, newStrategy); - } - - public String getGenerator() { - return this.generator; - } - - public void setGenerator(String newGenerator) { - if (attributeValueHasNotChanged(this.generator, newGenerator)) { - return; - } - String oldGenerator = this.generator; - this.generator = newGenerator; - this.generatorAdapter.setValue(newGenerator); - firePropertyChanged(GENERATOR_PROPERTY, oldGenerator, newGenerator); - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(STRATEGY_ADAPTER, astRoot); - } - - public TextRange getGeneratorTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(GENERATOR_ADAPTER, astRoot); - } - - // ********** java annotations -> persistence model ********** - public void update(CompilationUnit astRoot) { - this.setStrategy(this.strategy(astRoot)); - this.setGenerator(this.generator(astRoot)); - } - - protected GenerationType strategy(CompilationUnit astRoot) { - return GenerationType.fromJavaAnnotationValue(this.strategyAdapter.getValue(astRoot)); - } - - protected String generator(CompilationUnit astRoot) { - return this.generatorAdapter.getValue(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); - } - - public static class GeneratedValueAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final GeneratedValueAnnotationDefinition INSTANCE = new GeneratedValueAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private GeneratedValueAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new GeneratedValueImpl(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratorImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratorImpl.java deleted file mode 100644 index abbbfa7d63..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratorImpl.java +++ /dev/null @@ -1,163 +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.resource.java; - -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; - -public abstract class GeneratorImpl extends AbstractResourceAnnotation<Member> implements GeneratorAnnotation -{ - // hold this so we can get the 'name' text range - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - - // hold this so we can get the 'initialValue' text range - private final DeclarationAnnotationElementAdapter<Integer> initialValueDeclarationAdapter; - - // hold this so we can get the 'allocationSize' text range - private final DeclarationAnnotationElementAdapter<Integer> allocationSizeDeclarationAdapter; - - private final AnnotationElementAdapter<String> nameAdapter; - - private final AnnotationElementAdapter<Integer> initialValueAdapter; - - private final AnnotationElementAdapter<Integer> allocationSizeAdapter; - - private String name; - - private Integer initialValue; - - private Integer allocationSize; - - public GeneratorImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - super(parent, member, daa); - this.nameDeclarationAdapter = this.nameAdapter(); - this.nameAdapter = this.buildAdapter(this.nameDeclarationAdapter); - this.initialValueDeclarationAdapter = this.initialValueAdapter(); - this.initialValueAdapter = this.buildIntegerAdapter(this.initialValueDeclarationAdapter); - this.allocationSizeDeclarationAdapter = this.allocationSizeAdapter(); - this.allocationSizeAdapter = this.buildIntegerAdapter(this.allocationSizeDeclarationAdapter); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.name(astRoot); - this.initialValue = this.initialValue(astRoot); - this.allocationSize = this.allocationSize(astRoot); - } - - // ********** initialization ********** - protected AnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(getMember(), daea); - } - - protected AnnotationElementAdapter<Integer> buildIntegerAdapter(DeclarationAnnotationElementAdapter<Integer> daea) { - return new ShortCircuitAnnotationElementAdapter<Integer>(getMember(), daea); - } - - protected abstract DeclarationAnnotationAdapter annotationAdapter(); - - protected abstract DeclarationAnnotationElementAdapter<String> nameAdapter(); - - protected abstract DeclarationAnnotationElementAdapter<Integer> initialValueAdapter(); - - protected abstract DeclarationAnnotationElementAdapter<Integer> allocationSizeAdapter(); - - - - public Integer getAllocationSize() { - return this.allocationSize; - } - - public void setAllocationSize(Integer newAllocationSize) { - if (attributeValueHasNotChanged(this.allocationSize, newAllocationSize)) { - return; - } - Integer oldAllocationSize = this.allocationSize; - this.allocationSize = newAllocationSize; - this.allocationSizeAdapter.setValue(newAllocationSize); - firePropertyChanged(ALLOCATION_SIZE_PROPERTY, oldAllocationSize, newAllocationSize); - } - - public Integer getInitialValue() { - return this.initialValue; - } - - public void setInitialValue(Integer newInitialValue) { - if (attributeValueHasNotChanged(this.initialValue, newInitialValue)) { - return; - } - Integer oldInitialValue = this.initialValue; - this.initialValue = newInitialValue; - this.initialValueAdapter.setValue(newInitialValue); - firePropertyChanged(INITIAL_VALUE_PROPERTY, oldInitialValue, newInitialValue); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public TextRange getInitialValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.initialValueDeclarationAdapter, astRoot); - } - - public TextRange getAllocationSizeTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.allocationSizeDeclarationAdapter, astRoot); - } - - // ********** java annotations -> persistence model ********** - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - this.setAllocationSize(this.allocationSize(astRoot)); - this.setInitialValue(this.initialValue(astRoot)); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - protected Integer allocationSize(CompilationUnit astRoot) { - return this.allocationSizeAdapter.getValue(astRoot); - } - - protected Integer initialValue(CompilationUnit astRoot) { - return this.initialValueAdapter.getValue(astRoot); - } - - // ********** static methods ********** - protected static DeclarationAnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(annotationAdapter, elementName); - } - - protected 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/IdClassImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdClassImpl.java deleted file mode 100644 index f41a8e4596..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdClassImpl.java +++ /dev/null @@ -1,139 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.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; -import org.eclipse.jpt.core.utility.jdt.Type; - -public class IdClassImpl extends AbstractResourceAnnotation<Type> implements IdClassAnnotation -{ - private final AnnotationElementAdapter<String> valueAdapter; - - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); - - private String value; - - private String fullyQualifiedValue; - - public IdClassImpl(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(type, VALUE_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.value(astRoot); - this.fullyQualifiedValue = fullyQualifiedClass(astRoot); - } - - public String getAnnotationName() { - return IdClassAnnotation.ANNOTATION_NAME; - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - if (attributeValueHasNotChanged(this.value, newValue)) { - return; - } - String oldValue = this.value; - this.value = newValue; - this.valueAdapter.setValue(newValue); - firePropertyChanged(IdClassAnnotation.VALUE_PROPERTY, oldValue, newValue); - } - - public String getFullyQualifiedClass() { - return this.fullyQualifiedValue; - } - - private void setFullyQualifiedClass(String newQualifiedClass) { - String oldQualifiedClass = this.fullyQualifiedValue; - this.fullyQualifiedValue = newQualifiedClass; - firePropertyChanged(IdClassAnnotation.FULLY_QUALIFIED_CLASS_PROPERTY, oldQualifiedClass, newQualifiedClass); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.value(astRoot)); - this.setFullyQualifiedClass(this.fullyQualifiedClass(astRoot)); - } - - protected String value(CompilationUnit astRoot) { - return this.valueAdapter.getValue(astRoot); - } - - private String fullyQualifiedClass(CompilationUnit astRoot) { - if (getValue() == null) { - return null; - } - return 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()); - } - - - public static class IdClassAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final IdClassAnnotationDefinition INSTANCE = new IdClassAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private IdClassAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new IdClassImpl(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdImpl.java deleted file mode 100644 index 04d7c9b796..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/IdImpl.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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - - -public class IdImpl extends AbstractResourceAnnotation<Attribute> implements IdAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected IdImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void update(CompilationUnit astRoot) { - //no annotation members - } - - public static class IdAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final IdAnnotationDefinition INSTANCE = new IdAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static IdAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private IdAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new IdImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/InheritanceImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/InheritanceImpl.java deleted file mode 100644 index bb48af99c5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/InheritanceImpl.java +++ /dev/null @@ -1,115 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -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.JavaResourceNode; -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; -import org.eclipse.jpt.core.utility.jdt.Type; - -public class InheritanceImpl extends AbstractResourceAnnotation<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; - - protected InheritanceImpl(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.strategyAdapter = new ShortCircuitAnnotationElementAdapter<String>(type, STRATEGY_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.strategy = this.strategy(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public InheritanceType getStrategy() { - return this.strategy; - } - - public void setStrategy(InheritanceType newStrategy) { - if (attributeValueHasNotChanged(this.strategy, newStrategy)) { - return; - } - InheritanceType oldStrategy = this.strategy; - this.strategy = newStrategy; - this.strategyAdapter.setValue(InheritanceType.toJavaAnnotationValue(newStrategy)); - firePropertyChanged(STRATEGY_PROPERTY, oldStrategy, newStrategy); - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(STRATEGY_ADAPTER, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setStrategy(this.strategy(astRoot)); - } - - protected InheritanceType strategy(CompilationUnit astRoot) { - return InheritanceType.fromJavaAnnotationValue(this.strategyAdapter.getValue(astRoot)); - } - - // ********** static methods ********** - private static DeclarationAnnotationElementAdapter<String> buildStrategyAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.INHERITANCE__STRATEGY); - } - - public static class InheritanceAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final InheritanceAnnotationDefinition INSTANCE = new InheritanceAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private InheritanceAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new InheritanceImpl(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullInheritance(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourceModelImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourceModelImpl.java deleted file mode 100644 index 72a535074d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourceModelImpl.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import java.util.ArrayList; -import java.util.Collection; -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.ResourceModelListener; -import org.eclipse.jpt.core.internal.AbstractResourceModel; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.utility.CommandExecutorProvider; -import org.eclipse.jpt.utility.internal.BitTools; - -// TODO we need access to the JPA platform -public class JavaResourceModelImpl - extends AbstractResourceModel - implements JavaResourceModel -{ - private final Collection<ResourceModelListener> resourceModelListeners; - - private final JpaCompilationUnit jpaCompilationUnit; - - - public JavaResourceModelImpl( - IFile file, JpaAnnotationProvider annotationProvider, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - super(file); - this.resourceModelListeners = new ArrayList<ResourceModelListener>(); - // TODO use JPA factory, via the platform - this.jpaCompilationUnit = - new JpaCompilationUnitImpl(file, annotationProvider, modifySharedDocumentCommandExecutorProvider, annotationEditFormatter, this); - } - - public String getResourceType() { - return JAVA_RESOURCE_TYPE; - } - - public JpaCompilationUnit getJpaCompilationUnit() { - return this.jpaCompilationUnit; - } - - public void addResourceModelChangeListener(ResourceModelListener listener) { - if (listener == null) { - throw new IllegalArgumentException("Listener cannot be null"); - } - if (this.resourceModelListeners.contains(listener)) { - throw new IllegalArgumentException("Listener " + listener + " already added"); - } - this.resourceModelListeners.add(listener); - } - - public void removeResourceModelChangeListener(ResourceModelListener listener) { - if (!this.resourceModelListeners.contains(listener)) { - throw new IllegalArgumentException("Listener " + listener + " was never added"); - } - this.resourceModelListeners.add(listener); - } - - public void resourceChanged() { - if (this.jpaCompilationUnit == null) { - throw new IllegalStateException("Change events should not be fired during construction"); - } - for (ResourceModelListener listener : this.resourceModelListeners) { - listener.resourceModelChanged(); - } - } - - public void javaElementChanged(ElementChangedEvent event) { - synchWithJavaDelta(event.getDelta()); - } - - private void synchWithJavaDelta(IJavaElementDelta delta) { - switch (delta.getElement().getElementType()) { - case IJavaElement.JAVA_PROJECT : - if (this.updateOnClasspathChanges(delta)) { - break; - } - case IJavaElement.JAVA_MODEL : - case IJavaElement.PACKAGE_FRAGMENT_ROOT : - case IJavaElement.PACKAGE_FRAGMENT : - this.synchChildrenWithJavaDelta(delta); - break; - case IJavaElement.COMPILATION_UNIT : - this.synchCompilationUnitWithJavaDelta(delta); - break; - default : - break; // the event is somehow lower than a compilation unit - } - } - - private void synchChildrenWithJavaDelta(IJavaElementDelta delta) { - for (IJavaElementDelta child : delta.getAffectedChildren()) { - this.synchWithJavaDelta(child); // recurse - } - } - - private void synchCompilationUnitWithJavaDelta(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; - } - if (delta.getKind() == IJavaElementDelta.REMOVED) { - //we get the java notification for removal before we get the resource notification. - //we do not need to handle this event and will get exceptions building an astRoot if we try. - return; - } - if (delta.getElement().equals(this.jpaCompilationUnit.getCompilationUnit())) { - //TODO possibly hop on the UI thread here so that we know only 1 thread is changing our model - this.jpaCompilationUnit.updateFromJava(); - } - } - - //bug 235384 - we need to update all compilation units when a classpath change occurs. - //The persistence.jar could have been added/removed from the classpath which affects - //whether we know about the jpa annotations or not. - private boolean updateOnClasspathChanges(IJavaElementDelta delta) { - if (BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED) || - BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_CLASSPATH_CHANGED)) { - this.jpaCompilationUnit.updateFromJava(); - return true; - } - return false; - } - - public void updateFromResource() { - this.jpaCompilationUnit.updateFromJava(); - } - - public void resolveTypes() { - this.jpaCompilationUnit.resolveTypes(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourcePersistentAttributeImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourcePersistentAttributeImpl.java deleted file mode 100644 index 7786aca6b9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourcePersistentAttributeImpl.java +++ /dev/null @@ -1,486 +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.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; - -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jpt.core.internal.utility.jdt.JDTFieldAttribute; -import org.eclipse.jpt.core.internal.utility.jdt.JDTMethodAttribute; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -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.CollectionTools; - -public class JavaResourcePersistentAttributeImpl - extends AbstractJavaResourcePersistentMember<Attribute> - implements JavaResourcePersistentAttribute -{ - - private boolean typeIsBasic; - - private String qualifiedTypeName; - - private boolean typeIsContainer; - - private String qualifiedReferenceEntityTypeName; - - private String qualifiedReferenceEntityElementTypeName; - - private boolean public_; // 'public' is a reserved word - - private boolean final_; // 'final' is a reserved word - - /** - * construct field attribute - */ - public static JavaResourcePersistentAttribute newInstance( - JavaResourcePersistentType parent, - Type declaringType, - String name, - int occurrence, - JpaCompilationUnit jpaCompilationUnit, - CompilationUnit astRoot) { - Attribute attribute = new JDTFieldAttribute( - declaringType, - name, - occurrence, - jpaCompilationUnit.getCompilationUnit(), - jpaCompilationUnit.getModifySharedDocumentCommandExecutorProvider(), - jpaCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentAttribute field = new JavaResourcePersistentAttributeImpl(parent, attribute); - field.initialize(astRoot); - return field; - } - - /** - * construct property attribute - */ - public static JavaResourcePersistentAttribute newInstance( - JavaResourcePersistentType parent, - Type declaringType, - MethodSignature signature, - int occurrence, - JpaCompilationUnit jpaCompilationUnit, - CompilationUnit astRoot) { - Attribute attribute = JDTMethodAttribute.newInstance( - declaringType, - signature, - occurrence, - jpaCompilationUnit.getCompilationUnit(), - jpaCompilationUnit.getModifySharedDocumentCommandExecutorProvider(), - jpaCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentAttribute field = new JavaResourcePersistentAttributeImpl(parent, attribute); - field.initialize(astRoot); - return field; - } - - public JavaResourcePersistentAttributeImpl(JavaResourcePersistentType parent, Attribute attribute){ - super(parent, attribute); - } - - public String getName() { - return getMember().getAttributeName(); - } - - // ******** AbstractJavaPersistentResource implementation ******** - - @Override - protected Annotation buildMappingAnnotation(String mappingAnnotationName) { - return getAnnotationProvider().buildAttributeMappingAnnotation(this, getMember(), mappingAnnotationName); - } - - @Override - protected Annotation buildAnnotation(String annotationName) { - return getAnnotationProvider().buildAttributeAnnotation(this, getMember(), annotationName); - } - - @Override - protected Annotation buildNullAnnotation(String annotationName) { - return getAnnotationProvider().buildNullAttributeAnnotation(this, getMember(), annotationName); - } - - @Override - protected Annotation buildNullMappingAnnotation(String annotationName) { - return getAnnotationProvider().buildNullAttributeMappingAnnotation(this, getMember(), annotationName); - } - - @Override - protected ListIterator<String> possibleMappingAnnotationNames() { - return getAnnotationProvider().attributeMappingAnnotationNames(); - } - - @Override - protected boolean isPossibleAnnotation(String annotationName) { - return CollectionTools.contains(getAnnotationProvider().attributeAnnotationNames(), annotationName); - } - - @Override - protected boolean isPossibleMappingAnnotation(String annotationName) { - return CollectionTools.contains(getAnnotationProvider().attributeMappingAnnotationNames(), annotationName); - } - - @Override - @SuppressWarnings("unchecked") - //overriding purely to suppress the warning you get at the class level - public ListIterator<NestableAnnotation> annotations(String nestableAnnotationName, String containerAnnotationName) { - return super.annotations(nestableAnnotationName, containerAnnotationName); - } - - @Override - @SuppressWarnings("unchecked") - //overriding purely to suppress the warning you get at the class level - public Iterator<Annotation> mappingAnnotations() { - return super.mappingAnnotations(); - } - - @Override - @SuppressWarnings("unchecked") - //overriding purely to suppress the warning you get at the class level - public Iterator<Annotation> annotations() { - return super.annotations(); - } - - @Override - public boolean isFor(MethodSignature signature, int occurrence) { - return ((MethodAttribute) this.getMember()).matches(signature, occurrence); - } - - // ******** JavaPersistentAttributeResource implementation ******** - - public boolean isForField() { - return getMember().isField(); - } - - public boolean isForProperty() { - return !isForField(); - } - - public boolean hasAnyAnnotation() { - if (mappingAnnotationsSize() > 0) { - return true; - } - if (annotationsSize() > 0) { - return true; - } - return false; - } - - public boolean isPublic() { - return this.public_; - } - - protected void setPublic(boolean newPublic) { - boolean oldPublic = this.public_; - this.public_ = newPublic; - firePropertyChanged(PUBLIC_PROPERTY, oldPublic, newPublic); - } - - public boolean isFinal() { - return this.final_; - } - - protected void setFinal(boolean newFinal) { - boolean oldFinal = this.final_; - this.final_ = newFinal; - firePropertyChanged(FINAL_PROPERTY, oldFinal, newFinal); - } - - public boolean typeIsBasic() { - return this.typeIsBasic; - } - - protected void setTypeIsBasic(boolean newTypeIsBasic) { - boolean oldTypeIsBasic = this.typeIsBasic; - this.typeIsBasic = newTypeIsBasic; - firePropertyChanged(TYPE_IS_BASIC_PROPERTY, oldTypeIsBasic, newTypeIsBasic); - } - - public String getQualifiedTypeName() { - return this.qualifiedTypeName; - } - - protected void setQualifiedTypeName(String newQualifiedTypeName) { - String oldQualifiedTypeName = this.qualifiedTypeName; - this.qualifiedTypeName = newQualifiedTypeName; - firePropertyChanged(QUALIFIED_TYPE_NAME_PROPERTY, oldQualifiedTypeName, newQualifiedTypeName); - } - - public String getQualifiedReferenceEntityTypeName() { - return this.qualifiedReferenceEntityTypeName; - } - - protected void setQualifiedReferenceEntityTypeName(String newQualifiedReferenceEntityTypeName) { - String oldQualifiedReferenceEntityTypeName = this.qualifiedReferenceEntityTypeName; - this.qualifiedReferenceEntityTypeName = newQualifiedReferenceEntityTypeName; - firePropertyChanged(QUALIFIED_REFERENCE_ENTITY_TYPE_NAME_PROPERTY, oldQualifiedReferenceEntityTypeName, newQualifiedReferenceEntityTypeName); - } - - public String getQualifiedReferenceEntityElementTypeName() { - return this.qualifiedReferenceEntityElementTypeName; - } - - protected void setQualifiedReferenceEntityElementTypeName(String newQualifiedReferenceEntityElementTypeName) { - String oldQualifiedReferenceEntityElementTypeName = this.qualifiedReferenceEntityElementTypeName; - this.qualifiedReferenceEntityElementTypeName = newQualifiedReferenceEntityElementTypeName; - firePropertyChanged(QUALIFIED_REFERENCE_ENTITY_ELEMENT_TYPE_NAME_PROPERTY, oldQualifiedReferenceEntityElementTypeName, newQualifiedReferenceEntityElementTypeName); - } - - public boolean typeIsContainer() { - return this.typeIsContainer; - } - - protected void setTypeIsContainer(boolean newTypeIsContainer) { - boolean oldTypeIsContainer = this.typeIsContainer; - this.typeIsContainer = newTypeIsContainer; - firePropertyChanged(TYPE_IS_CONTAINER_PROPERTY, oldTypeIsContainer, newTypeIsContainer); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.typeIsBasic = this.typeIsBasic(astRoot); - this.qualifiedTypeName = this.qualifiedTypeName(astRoot); - this.qualifiedReferenceEntityTypeName = this.qualifiedReferenceEntityTypeName(astRoot); - this.qualifiedReferenceEntityElementTypeName = this.qualifiedReferenceEntityElementTypeName(astRoot); - this.typeIsContainer = this.typeIsContainer(astRoot); - this.final_ = this.isFinal(astRoot); - this.public_ = this.isPublic(astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setTypeIsBasic(this.typeIsBasic(astRoot)); - this.setQualifiedTypeName(this.qualifiedTypeName(astRoot)); - this.setQualifiedReferenceEntityTypeName(this.qualifiedReferenceEntityTypeName(astRoot)); - this.setQualifiedReferenceEntityElementTypeName(this.qualifiedReferenceEntityElementTypeName(astRoot)); - this.setTypeIsContainer(this.typeIsContainer(astRoot)); - this.setFinal(this.isFinal(astRoot)); - this.setPublic(this.isPublic(astRoot)); - } - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - this.setTypeIsBasic(this.typeIsBasic(astRoot)); - this.setQualifiedTypeName(this.qualifiedTypeName(astRoot)); - this.setQualifiedReferenceEntityTypeName(this.qualifiedReferenceEntityTypeName(astRoot)); - this.setQualifiedReferenceEntityElementTypeName(this.qualifiedReferenceEntityElementTypeName(astRoot)); - this.setTypeIsContainer(this.typeIsContainer(astRoot)); - } - - protected boolean typeIsBasic(CompilationUnit astRoot) { - return typeIsBasic(this.getMember().getTypeBinding(astRoot), astRoot.getAST()); - } - - protected boolean isFinal(CompilationUnit astRoot) { - IBinding binding = getMember().getBinding(astRoot); - return (binding == null) ? false : Modifier.isFinal(binding.getModifiers()); - } - - protected boolean isPublic(CompilationUnit astRoot) { - IBinding binding = getMember().getBinding(astRoot); - return (binding == null) ? false : Modifier.isPublic(binding.getModifiers()); - } - - protected String qualifiedReferenceEntityTypeName(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getMember().getTypeBinding(astRoot); - return (typeBinding == null) ? null : buildReferenceEntityTypeName(typeBinding); - } - - public static String buildReferenceEntityTypeName(ITypeBinding typeBinding) { - if (typeBinding == null) { - return null; - } - if (typeBinding.isArray()) { - return null; // arrays cannot be entities - } - return typeBinding.getTypeDeclaration().getQualifiedName(); - } - - protected String qualifiedReferenceEntityElementTypeName(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getMember().getTypeBinding(astRoot); - if (typeBinding == null) { - return null; - } - - ITypeBinding[] typeArguments = typeBinding.getTypeArguments(); - if (typeArguments.length != 1) { - return null; - } - ITypeBinding elementTypeBinding = typeArguments[0]; - String elementTypeName = buildReferenceEntityTypeName(elementTypeBinding); - return typeNamedIsContainer(elementTypeName) ? null : elementTypeName; - } - - - protected boolean typeIsContainer(CompilationUnit astRoot) { - String typeName = buildReferenceEntityTypeName(this.getMember().getTypeBinding(astRoot)); - return (typeName == null) ? false : typeNamedIsContainer(typeName); - } - - /** - * return whether the specified non-array type is one of the container - * types allowed by the JPA spec - */ - public static boolean typeNamedIsContainer(String typeName) { - return CollectionTools.contains(CONTAINER_TYPE_NAMES, typeName); - } - - private static final String[] CONTAINER_TYPE_NAMES = { - java.util.Collection.class.getName(), - java.util.Set.class.getName(), - java.util.List.class.getName(), - java.util.Map.class.getName() - }; - - protected String qualifiedTypeName(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getMember().getTypeBinding(astRoot); - return (typeBinding == null) ? null : typeBinding.getTypeDeclaration().getQualifiedName(); - } - - - /** - * 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: - * primitive types - * byte[] - * Byte[] - * char[] - * Character[] - * primitive wrappers - * 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 static boolean typeIsBasic(ITypeBinding typeBinding, AST ast) { - if (typeBinding == null) { - return false; // type not found - } - if (typeBinding.isPrimitive()) { - return true; - } - if (typeBinding.isArray()) { - if (typeBinding.getDimensions() > 1) { - return false; // multi-dimensional arrays are not supported - } - ITypeBinding elementTypeBinding = typeBinding.getElementType(); - if (elementTypeBinding == null) { - return false;// unable to resolve the type - } - return elementTypeIsValid(elementTypeBinding.getQualifiedName()); - } - String typeName = typeBinding.getQualifiedName(); - if (typeIsPrimitiveWrapper(typeName)) { - return true; - } - if (typeIsOtherSupportedType(typeName)) { - return true; - } - if (typeBinding.isEnum()) { - return true; - } - if (typeImplementsSerializable(typeBinding, ast)) { - return true; - } - return false; - } - - /** - * Return whether the specified type is a valid element type for - * a one-dimensional array: - * byte - * char - * java.lang.Byte - * java.lang.Character - */ - private static boolean elementTypeIsValid(String elementTypeName) { - return CollectionTools.contains(VALID_ELEMENT_TYPE_NAMES, elementTypeName); - } - - private static final String[] VALID_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 a primitive wrapper. - */ - private static boolean typeIsPrimitiveWrapper(String typeName) { - return CollectionTools.contains(PRIMITIVE_WRAPPER_TYPE_NAMES, typeName); - } - - private static final String[] PRIMITIVE_WRAPPER_TYPE_NAMES = { - java.lang.Byte.class.getName(), - java.lang.Character.class.getName(), - java.lang.Double.class.getName(), - java.lang.Float.class.getName(), - java.lang.Integer.class.getName(), - java.lang.Long.class.getName(), - java.lang.Short.class.getName(), - java.lang.Boolean.class.getName(), - }; - - /** - * Return whether the specified type is among the various other types - * that default to a Basic mapping. - */ - private static boolean typeIsOtherSupportedType(String typeName) { - return CollectionTools.contains(OTHER_SUPPORTED_TYPE_NAMES, typeName); - } - - private static final String[] OTHER_SUPPORTED_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(), - }; - - /** - * Return whether the specified type implements java.io.Serializable. - */ - private static boolean typeImplementsSerializable(ITypeBinding typeBinding, AST ast) { - ITypeBinding serializableTypeBinding = ast.resolveWellKnownType(SERIALIZABLE_TYPE_NAME); - return typeBinding.isAssignmentCompatible(serializableTypeBinding); - } - - private static final String SERIALIZABLE_TYPE_NAME = java.io.Serializable.class.getName(); - - @Override - public void toString(StringBuilder sb) { - sb.append(getName()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourcePersistentTypeImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourcePersistentTypeImpl.java deleted file mode 100644 index 1c07092f83..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JavaResourcePersistentTypeImpl.java +++ /dev/null @@ -1,663 +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.resource.java; - -import java.util.Collection; -import java.util.HashMap; -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.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.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.core.resource.java.JpaCompilationUnit; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -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.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public class JavaResourcePersistentTypeImpl - extends AbstractJavaResourcePersistentMember<Type> - implements JavaResourcePersistentType -{ - private String qualifiedName; - - private String name; - - private String superClassQualifiedName; - - private boolean abstract_; // 'abstract' is a reserved word - - /** - * store all member types including those that aren't persistable so we can - * generate validation errors - */ - private final Vector<JavaResourcePersistentType> nestedTypes; - - private final Vector<JavaResourcePersistentAttribute> fields; - - private final Vector<JavaResourcePersistentAttribute> methods; - - private AccessType accessType; - - - // ********** construction ********** - - /** - * build top-level persistent type - */ - // TODO use JPA factory - public static JavaResourcePersistentType newInstance( - JpaCompilationUnit jpaCompilationUnit, - TypeDeclaration typeDeclaration, - CompilationUnit astRoot) { - Type type = new JDTType( - typeDeclaration, - jpaCompilationUnit.getCompilationUnit(), - jpaCompilationUnit.getModifySharedDocumentCommandExecutorProvider(), - jpaCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentType jrpt = new JavaResourcePersistentTypeImpl(jpaCompilationUnit, type); - jrpt.initialize(astRoot); - return jrpt; - } - - /** - * build nested persistent type - */ - // TODO use JPA factory - protected static JavaResourcePersistentType newInstance( - JpaCompilationUnit jpaCompilationUnit, - Type declaringType, - TypeDeclaration typeDeclaration, - int occurrence, - CompilationUnit astRoot) { - Type type = new JDTType( - declaringType, - typeDeclaration, - occurrence, - jpaCompilationUnit.getCompilationUnit(), - jpaCompilationUnit.getModifySharedDocumentCommandExecutorProvider(), - jpaCompilationUnit.getAnnotationEditFormatter()); - JavaResourcePersistentType jrpt = new JavaResourcePersistentTypeImpl(jpaCompilationUnit, type); - jrpt.initialize(astRoot); - return jrpt; - } - - public JavaResourcePersistentTypeImpl(JpaCompilationUnit jpaCompilationUnit, Type type) { - super(jpaCompilationUnit, type); - this.nestedTypes = new Vector<JavaResourcePersistentType>(); - this.fields = new Vector<JavaResourcePersistentAttribute>(); - this.methods = new Vector<JavaResourcePersistentAttribute>(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.qualifiedName = this.buildQualifiedName(astRoot); - this.name = this.buildName(astRoot); - this.superClassQualifiedName = this.buildSuperClassQualifiedName(astRoot); - this.abstract_ = this.buildAbstract(astRoot); - this.initializeNestedTypes(astRoot); - this.initializeFields(astRoot); - this.initializeMethods(astRoot); - this.accessType = this.buildAccessType(); - } - - protected void initializeNestedTypes(CompilationUnit astRoot) { - CounterMap counters = new CounterMap(); - for (TypeDeclaration td : this.getMember().getTypes(astRoot)) { - String tdName = td.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - this.nestedTypes.add(this.buildNestedType(td, occurrence, astRoot)); - } - } - - protected void initializeFields(CompilationUnit astRoot) { - CounterMap counters = new CounterMap(); - for (FieldDeclaration fieldDeclaration : this.getMember().getFields(astRoot)) { - for (VariableDeclarationFragment fragment : fragments(fieldDeclaration)) { - String fieldName = fragment.getName().getFullyQualifiedName(); - int occurrence = counters.increment(fieldName); - this.fields.add(this.buildField(fieldName, occurrence, astRoot)); - } - } - } - - protected void initializeMethods(CompilationUnit astRoot) { - CounterMap counters = new CounterMap(); - for (MethodDeclaration methodDeclaration : this.getMember().getMethods(astRoot)) { - MethodSignature signature = JDTTools.buildMethodSignature(methodDeclaration); - int occurrence = counters.increment(signature); - this.methods.add(this.buildMethod(signature, occurrence, astRoot)); - } - } - - - // ********** AbstractJavaResourcePersistentMember implementation ********** - - @Override - protected Annotation buildMappingAnnotation(String mappingAnnotationName) { - return getAnnotationProvider().buildTypeMappingAnnotation(this, getMember(), mappingAnnotationName); - } - - @Override - protected Annotation buildNullMappingAnnotation(String annotationName) { - return getAnnotationProvider().buildNullTypeMappingAnnotation(this, getMember(), annotationName); - } - - @Override - protected Annotation buildAnnotation(String annotationName) { - return getAnnotationProvider().buildTypeAnnotation(this, getMember(), annotationName); - } - - @Override - protected Annotation buildNullAnnotation(String annotationName) { - return getAnnotationProvider().buildNullTypeAnnotation(this, getMember(), annotationName); - } - - @Override - protected ListIterator<String> possibleMappingAnnotationNames() { - return getAnnotationProvider().typeMappingAnnotationNames(); - } - - @Override - protected boolean isPossibleAnnotation(String annotationName) { - return CollectionTools.contains(getAnnotationProvider().typeAnnotationNames(), annotationName); - } - - @Override - protected boolean isPossibleMappingAnnotation(String annotationName) { - return CollectionTools.contains(getAnnotationProvider().typeMappingAnnotationNames(), annotationName); - } - - @Override - @SuppressWarnings("unchecked") - //overriding purely to suppress the warning you get at the class level - public ListIterator<NestableAnnotation> annotations(String nestableAnnotationName, String containerAnnotationName) { - return super.annotations(nestableAnnotationName, containerAnnotationName); - } - - @Override - @SuppressWarnings("unchecked") - //overriding purely to suppress the warning you get at the class level - public Iterator<Annotation> mappingAnnotations() { - return super.mappingAnnotations(); - } - - @Override - @SuppressWarnings("unchecked") - //overriding purely to suppress the warning you get at the class level - public Iterator<Annotation> annotations() { - return super.annotations(); - } - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - - this.setSuperClassQualifiedName(this.buildSuperClassQualifiedName(astRoot)); - - for (Iterator<JavaResourcePersistentAttribute> stream = this.fields_(); stream.hasNext(); ) { - stream.next().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 (Iterator<JavaResourcePersistentAttribute> stream = this.methods_(); stream.hasNext(); ) { - stream.next().resolveTypes(astRoot); - } - for (Iterator<JavaResourcePersistentType> stream = this.nestedTypes_(); stream.hasNext(); ) { - stream.next().resolveTypes(astRoot); - } - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ******** JavaResourcePersistentType implementation ******** - - public JavaResourcePersistentType getJavaPersistentTypeResource(String fullyQualifiedTypeName) { - // TODO not sure why a null name is coming through here... ~bjv -// if (fullyQualifiedTypeName.equals(this.getQualifiedName())) { - if (this.getQualifiedName().equals(fullyQualifiedTypeName)) { - return this; - } - for (Iterator<JavaResourcePersistentType> stream = this.nestedTypes(); stream.hasNext(); ) { - JavaResourcePersistentType jrpt = stream.next(); - // recurse - JavaResourcePersistentType nestedJRPT = jrpt.getJavaPersistentTypeResource(fullyQualifiedTypeName); - if (nestedJRPT != null) { - return nestedJRPT; - } - } - return null; - } - - /** - * check only persistable attributes - */ - public boolean hasAnyAttributeAnnotations() { - for (Iterator<JavaResourcePersistentAttribute> stream = this.attributes(); stream.hasNext(); ) { - if (stream.next().hasAnyAnnotation()) { - return true; - } - } - return false; - } - - - // ********** nested types ********** - - /** - * return only persistable nested types - */ - public Iterator<JavaResourcePersistentType> nestedTypes() { - //TODO since we are filtering how do we handle the case where a type becomes persistable? - //what kind of change notificiation for that case? - return new FilteringIterator<JavaResourcePersistentType, JavaResourcePersistentType>(this.nestedTypes_()) { - @Override - protected boolean accept(JavaResourcePersistentType jrpt) { - return jrpt.isPersistable(); - } - }; - } - - /** - * *all* nested types - */ - protected Iterator<JavaResourcePersistentType> nestedTypes_() { - return new CloneIterator<JavaResourcePersistentType>(this.nestedTypes); - } - - protected void addNestedType(JavaResourcePersistentType nestedType) { - this.addItemToCollection(nestedType, this.nestedTypes, NESTED_TYPES_COLLECTION); - } - - protected void removeNestedType(JavaResourcePersistentType nestedType) { - this.removeItemFromCollection(nestedType, this.nestedTypes, NESTED_TYPES_COLLECTION); - } - - protected void removeNestedTypes(Collection<JavaResourcePersistentType> remove) { - this.removeItemsFromCollection(remove, this.nestedTypes, NESTED_TYPES_COLLECTION); - } - - protected JavaResourcePersistentType getNestedType(String typeName, int occurrence) { - for (Iterator<JavaResourcePersistentType> stream = this.nestedTypes_(); stream.hasNext(); ) { - JavaResourcePersistentType nestedType = stream.next(); - if (nestedType.isFor(typeName, occurrence)) { - return nestedType; - } - } - return null; - } - - - // ********** attributes ********** - - /** - * return only persistable attributes - */ - // TODO since we are filtering, how do we handle the case where an attribute becomes persistable? - // what kind of change notification for that case? - public Iterator<JavaResourcePersistentAttribute> attributes() { - return persistableMembers(this.attributes_()); - } - - /** - * *all* fields and methods - */ - @SuppressWarnings("unchecked") - protected Iterator<JavaResourcePersistentAttribute> attributes_() { - return new CompositeIterator<JavaResourcePersistentAttribute>(this.fields_(), this.methods_()); - } - - - // ********** fields ********** - - /** - * return only persistable fields - */ - public Iterator<JavaResourcePersistentAttribute> fields() { - return persistableMembers(this.fields_()); - } - - /** - * *all* fields - */ - protected Iterator<JavaResourcePersistentAttribute> fields_() { - return new CloneIterator<JavaResourcePersistentAttribute>(this.fields); - } - - protected void addField(JavaResourcePersistentAttribute attribute) { - this.addItemToCollection(attribute, this.fields, ATTRIBUTES_COLLECTION); - } - - protected void removeField(JavaResourcePersistentAttribute attribute) { - this.removeItemFromCollection(attribute, this.fields, ATTRIBUTES_COLLECTION); - } - - protected void removeFields(Collection<JavaResourcePersistentAttribute> remove) { - this.removeItemsFromCollection(remove, this.fields, ATTRIBUTES_COLLECTION); - } - - protected JavaResourcePersistentAttribute getField(String fieldName, int occurrence) { - for (Iterator<JavaResourcePersistentAttribute> stream = this.fields_(); stream.hasNext(); ) { - JavaResourcePersistentAttribute field = stream.next(); - if (field.isFor(fieldName, occurrence)) { - return field; - } - } - return null; - } - - - // ********** methods ********** - - /** - * return only persistable properties - */ - public Iterator<JavaResourcePersistentAttribute> properties() { - return persistableMembers(this.methods_()); - } - - /** - * *all* methods - */ - protected Iterator<JavaResourcePersistentAttribute> methods_() { - return new CloneIterator<JavaResourcePersistentAttribute>(this.methods); - } - - protected void addMethod(JavaResourcePersistentAttribute attribute) { - this.addItemToCollection(attribute, this.methods, ATTRIBUTES_COLLECTION); - } - - protected void removeMethod(JavaResourcePersistentAttribute attribute) { - this.removeItemFromCollection(attribute, this.methods, ATTRIBUTES_COLLECTION); - } - - protected void removeMethods(Collection<JavaResourcePersistentAttribute> remove) { - this.removeItemsFromCollection(remove, this.methods, ATTRIBUTES_COLLECTION); - } - - protected JavaResourcePersistentAttribute getMethod(MethodSignature signature, int occurrence) { - for (Iterator<JavaResourcePersistentAttribute> stream = this.methods_(); stream.hasNext(); ) { - JavaResourcePersistentAttribute method = stream.next(); - if (method.isFor(signature, occurrence)) { - return method; - } - } - return null; - } - - - // ********** simple instance variables ********** - - public String getQualifiedName() { - return this.qualifiedName; - } - - protected void setQualifiedName(String qualifiedName) { - String old = this.qualifiedName; - this.qualifiedName = qualifiedName; - this.firePropertyChanged(QUALIFIED_NAME_PROPERTY, old, qualifiedName); - } - - public String getName() { - return this.name; - } - - protected void setName(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - public String getSuperClassQualifiedName() { - return this.superClassQualifiedName; - } - - protected void setSuperClassQualifiedName(String superClassQualifiedName) { - String old = this.superClassQualifiedName; - this.superClassQualifiedName = superClassQualifiedName; - this.firePropertyChanged(SUPER_CLASS_QUALIFIED_NAME_PROPERTY, old, superClassQualifiedName); - } - - public boolean isAbstract() { - return this.abstract_; - } - - protected void setAbstract(boolean abstract_) { - boolean old = this.abstract_; - this.abstract_ = abstract_; - this.firePropertyChanged(ABSTRACT_PROPERTY, old, abstract_); - } - - public AccessType getAccess() { - return this.accessType; - } - - // 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 - protected void setAccess(AccessType accessType) { - AccessType old = this.accessType; - this.accessType = accessType; - this.firePropertyChanged(ACCESS_PROPERTY, old, accessType); - } - - - // ********** update from Java ********** - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setQualifiedName(this.buildQualifiedName(astRoot)); - this.setName(this.buildName(astRoot)); - this.setSuperClassQualifiedName(this.buildSuperClassQualifiedName(astRoot)); - this.setAbstract(this.buildAbstract(astRoot)); - this.updateNestedTypes(astRoot); - this.updateFields(astRoot); - this.updateMethods(astRoot); - this.setAccess(this.buildAccessType()); - } - - protected void updateNestedTypes(CompilationUnit astRoot) { - CounterMap counters = new CounterMap(); - @SuppressWarnings("unchecked") - Vector<JavaResourcePersistentType> nestedTypesToRemove = (Vector<JavaResourcePersistentType>) this.nestedTypes.clone(); - for (TypeDeclaration typeDeclaration : this.getMember().getTypes(astRoot)) { - String tdName = typeDeclaration.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - - JavaResourcePersistentType nestedType = this.getNestedType(tdName, occurrence); - if (nestedType == null) { - this.addNestedType(this.buildNestedType(typeDeclaration, occurrence, astRoot)); - } else { - nestedTypesToRemove.remove(nestedType); - nestedType.update(astRoot); - } - } - this.removeNestedTypes(nestedTypesToRemove); - } - - protected void updateFields(CompilationUnit astRoot) { - CounterMap counters = new CounterMap(); - @SuppressWarnings("unchecked") - Vector<JavaResourcePersistentAttribute> fieldsToRemove = (Vector<JavaResourcePersistentAttribute>) this.fields.clone(); - for (FieldDeclaration fieldDeclaration : this.getMember().getFields(astRoot)) { - 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); - } - - protected void updateMethods(CompilationUnit astRoot) { - CounterMap counters = new CounterMap(); - @SuppressWarnings("unchecked") - Vector<JavaResourcePersistentAttribute> methodsToRemove = (Vector<JavaResourcePersistentAttribute>) this.methods.clone(); - for (MethodDeclaration methodDeclaration : this.getMember().getMethods(astRoot)) { - 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); - } - - - // ********** building state from AST ********** - - protected String buildQualifiedName(CompilationUnit astRoot) { - return this.getMember().getBinding(astRoot).getQualifiedName(); - } - - protected String buildName(CompilationUnit astRoot) { - return this.getMember().getBinding(astRoot).getName(); - } - - protected String buildSuperClassQualifiedName(CompilationUnit astRoot) { - ITypeBinding typeBinding = this.getMember().getBinding(astRoot); - if (typeBinding == null) { - return null; - } - ITypeBinding superClassTypeBinding = typeBinding.getSuperclass(); - if (superClassTypeBinding == null) { - return null; - } - return superClassTypeBinding.getTypeDeclaration().getQualifiedName(); - } - - protected boolean buildAbstract(CompilationUnit astRoot) { - return Modifier.isAbstract(this.getMember().getBinding(astRoot).getModifiers()); - } - - // TODO use JPA factory - protected JavaResourcePersistentType buildNestedType(TypeDeclaration nestedTypeDeclaration, int occurrence, CompilationUnit astRoot) { - return newInstance(this.getJpaCompilationUnit(), this.getMember(), nestedTypeDeclaration, occurrence, astRoot); - } - - // TODO use JPA factory - protected JavaResourcePersistentAttribute buildField(String fieldName, int occurrence, CompilationUnit astRoot) { - return JavaResourcePersistentAttributeImpl.newInstance(this, this.getMember(), fieldName, occurrence, this.getJpaCompilationUnit(), astRoot); - } - - // TODO use JPA factory - protected JavaResourcePersistentAttribute buildMethod(MethodSignature signature, int occurrence, CompilationUnit astRoot) { - return JavaResourcePersistentAttributeImpl.newInstance(this, this.getMember(), signature, occurrence, this.getJpaCompilationUnit(), astRoot); - } - - /** - * Return the AccessType currently implied by the Java source code: - * - 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) - */ - protected AccessType buildAccessType() { - boolean hasPersistableFields = false; - boolean hasPersistableProperties = false; - for (JavaResourcePersistentAttribute field : CollectionTools.iterable(fields())) { - hasPersistableFields = true; - if (field.hasAnyAnnotation()) { - // any field is annotated => FIELD - return AccessType.FIELD; - } - } - for (JavaResourcePersistentAttribute property : CollectionTools.iterable(properties())) { - hasPersistableProperties = true; - if (property.hasAnyAnnotation()) { - // none of the fields are annotated and a getter is annotated => PROPERTY - return AccessType.PROPERTY; - } - } - - if (hasPersistableProperties && !hasPersistableFields) { - return AccessType.PROPERTY; - } - //no annotations exist, access is null at the resource model level - return null; - } - - - // ********** static methods ********** - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - protected static List<VariableDeclarationFragment> fragments(FieldDeclaration fd) { - return fd.fragments(); - } - - - // ********** StringCounter ********** - - protected static class CounterMap { - HashMap<Object, Counter> counters = new HashMap<Object, Counter>(); - - /** - * 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/JoinColumnImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnImpl.java deleted file mode 100644 index 9d9765e827..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnImpl.java +++ /dev/null @@ -1,225 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinColumn; -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; - -public class JoinColumnImpl extends BaseColumnImpl implements NestableJoinColumn -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - // hold this so we can get the 'referenced column name' text range - private final DeclarationAnnotationElementAdapter<String> referencedColumnNameDeclarationAdapter; - - private final AnnotationElementAdapter<String> referencedColumnNameAdapter; - - private String referencedColumnName; - - public JoinColumnImpl(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 JoinColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - public JoinColumnImpl(JavaResourceNode parent, Member member, IndexedDeclarationAnnotationAdapter idaa) { - this(parent, member, idaa, new MemberIndexedAnnotationAdapter(member, idaa)); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.referencedColumnName = this.referencedColumnName(astRoot); - } - - @Override - protected String nameElementName() { - return JPA.JOIN_COLUMN__NAME; - } - - @Override - protected String columnDefinitionElementName() { - return JPA.JOIN_COLUMN__COLUMN_DEFINITION; - } - - @Override - protected String tableElementName() { - return JPA.JOIN_COLUMN__TABLE; - } - - @Override - protected String uniqueElementName() { - return JPA.JOIN_COLUMN__UNIQUE; - } - - @Override - protected String nullableElementName() { - return JPA.JOIN_COLUMN__NULLABLE; - } - - @Override - protected String insertableElementName() { - return JPA.JOIN_COLUMN__INSERTABLE; - } - - @Override - protected String updatableElementName() { - return JPA.JOIN_COLUMN__UPDATABLE; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - private IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) super.getAnnotationAdapter(); - } - - public void moveAnnotation(int newIndex) { - getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - JoinColumnAnnotation oldColumn = (JoinColumnAnnotation) oldAnnotation; - setReferencedColumnName(oldColumn.getReferencedColumnName()); - } - - //************ JoinColumn implementation *************** - public String getReferencedColumnName() { - return this.referencedColumnName; - } - - public void setReferencedColumnName(String newReferencedColumnName) { - if (attributeValueHasNotChanged(this.referencedColumnName, newReferencedColumnName)) { - return; - } - String oldReferencedColumnName = this.referencedColumnName; - this.referencedColumnName = newReferencedColumnName; - this.referencedColumnNameAdapter.setValue(newReferencedColumnName); - firePropertyChanged(REFERENCED_COLUMN_NAME_PROPERTY, oldReferencedColumnName, newReferencedColumnName); - } - - 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); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setReferencedColumnName(this.referencedColumnName(astRoot)); - } - - protected String referencedColumnName(CompilationUnit astRoot) { - return this.referencedColumnNameAdapter.getValue(astRoot); - } - - // ********** static methods ********** - - static JoinColumnImpl createJoinColumn(JavaResourceNode parent, Member member) { - return new JoinColumnImpl(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - static JoinColumnImpl createNestedJoinColumn(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter joinColumnsAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, joinColumnsAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new JoinColumnImpl(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter joinColumnsAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(joinColumnsAdapter, index, JPA.JOIN_COLUMN); - } - static NestableJoinColumn createJoinTableJoinColumn(JavaResourceNode parent, Member member, int index) { - return new JoinColumnImpl(parent, member, buildJoinTableAnnotationAdapter(index)); - } - - private static IndexedDeclarationAnnotationAdapter buildJoinTableAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(JoinTableImpl.DECLARATION_ANNOTATION_ADAPTER, JPA.JOIN_TABLE__JOIN_COLUMNS, index, JPA.JOIN_COLUMN); - } - - static NestableJoinColumn createJoinTableInverseJoinColumn(JavaResourceNode parent, Member member, int index) { - return new JoinColumnImpl(parent, member, buildJoinTableInverseAnnotationAdapter(index)); - } - - private static IndexedDeclarationAnnotationAdapter buildJoinTableInverseAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(JoinTableImpl.DECLARATION_ANNOTATION_ADAPTER, JPA.JOIN_TABLE__INVERSE_JOIN_COLUMNS, index, JPA.JOIN_COLUMN); - } - - - static NestableJoinColumn createAssociationOverrideJoinColumn(DeclarationAnnotationAdapter associationOverrideAdapter, JavaResourceNode parent, Member member, int index) { - return new JoinColumnImpl(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); - } - - - public static class JoinColumnAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final JoinColumnAnnotationDefinition INSTANCE = new JoinColumnAnnotationDefinition(); - - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JoinColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return JoinColumnImpl.createJoinColumn(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnsImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnsImpl.java deleted file mode 100644 index c10206642c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinColumnsImpl.java +++ /dev/null @@ -1,156 +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.resource.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.NestableJoinColumn; -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; - -public class JoinColumnsImpl extends AbstractResourceAnnotation<Member> implements JoinColumnsAnnotation -{ - - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private List<NestableJoinColumn> joinColumns; - - protected JoinColumnsImpl(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.joinColumns = new ArrayList<NestableJoinColumn>(); - } - - public void initialize(CompilationUnit astRoot) { - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getNestableAnnotationName() { - return JoinColumnAnnotation.ANNOTATION_NAME; - } - - public ListIterator<NestableJoinColumn> nestedAnnotations() { - return new CloneListIterator<NestableJoinColumn>(this.joinColumns); - } - - public int nestedAnnotationsSize() { - return this.joinColumns.size(); - } - - public NestableJoinColumn addInternal(int index) { - JoinColumnImpl joinColumn = createJoinColumn(index); - this.joinColumns.add(index, joinColumn); - return joinColumn; - } - - public NestableJoinColumn add(int index) { - JoinColumnImpl joinColumn = createJoinColumn(index); - add(index, joinColumn); - return joinColumn; - } - - protected void add(int index, NestableJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.joinColumns, JOIN_COLUMNS_LIST); - } - - public void remove(NestableJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.joinColumns, JOIN_COLUMNS_LIST); - } - - public void remove(int index) { - removeItemFromList(index, this.joinColumns, JOIN_COLUMNS_LIST); - } - - public int indexOf(NestableJoinColumn joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public NestableJoinColumn nestedAnnotationAt(int index) { - return this.joinColumns.get(index); - } - - public NestableJoinColumn nestedAnnotationFor(Annotation jdtAnnotation) { - for (NestableJoinColumn joinColumn : this.joinColumns) { - if (jdtAnnotation == joinColumn.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return joinColumn; - } - } - return null; - } - - public void move(int targetIndex, int sourceIndex) { - moveItemInList(targetIndex, sourceIndex, this.joinColumns, JOIN_COLUMNS_LIST); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.joinColumns, targetIndex, sourceIndex); - } - - public String getElementName() { - return "value"; - } - - public void update(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this); - } - - private JoinColumnImpl createJoinColumn(int index) { - return JoinColumnImpl.createNestedJoinColumn(this, getMember(), index, getDeclarationAnnotationAdapter()); - } - - - public static class JoinColumnsAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final JoinColumnsAnnotationDefinition INSTANCE = new JoinColumnsAnnotationDefinition(); - - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JoinColumnsAnnotationDefinition() { - super(); - } - - public JoinColumnsAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new JoinColumnsImpl(parent, member); - } - - public JoinColumnsAnnotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinTableImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinTableImpl.java deleted file mode 100644 index 0d4834f69f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JoinTableImpl.java +++ /dev/null @@ -1,389 +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.resource.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.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -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.NestableJoinColumn; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class JoinTableImpl extends AbstractResourceTable implements JoinTableAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JoinTableAnnotation.ANNOTATION_NAME); - - private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.JOIN_TABLE__NAME); - - private static final DeclarationAnnotationElementAdapter<String> SCHEMA_ADAPTER = ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.JOIN_TABLE__SCHEMA); - - private static final DeclarationAnnotationElementAdapter<String> CATALOG_ADAPTER = ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.JOIN_TABLE__CATALOG); - - private final List<NestableJoinColumn> joinColumns; - - private final List<NestableJoinColumn> inverseJoinColumns; - - private final JoinColumnsContainerAnnotation joinColumnsContainerAnnotation; - - private final InverseJoinColumnsContainerAnnotation inverseJoinColumnsContainerAnnotation; - - protected JoinTableImpl(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - this.joinColumns = new ArrayList<NestableJoinColumn>(); - this.inverseJoinColumns = new ArrayList<NestableJoinColumn>(); - this.joinColumnsContainerAnnotation = new JoinColumnsContainerAnnotation(); - this.inverseJoinColumnsContainerAnnotation = new InverseJoinColumnsContainerAnnotation(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this.joinColumnsContainerAnnotation); - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this.inverseJoinColumnsContainerAnnotation); - } - - public String getAnnotationName() { - return JoinTableAnnotation.ANNOTATION_NAME; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> nameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @JoinTable is never nested - return NAME_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> schemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @JoinTable is never nested - return SCHEMA_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> catalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @JoinTable is never nested - return CATALOG_ADAPTER; - } - - @Override - protected NestableUniqueConstraint createUniqueConstraint(int index) { - return UniqueConstraintImpl.createJoinTableUniqueConstraint(this, this.getMember(), index); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.updateJoinColumnsFromJava(astRoot); - this.updateInverseJoinColumnsFromJava(astRoot); - } - - private void updateJoinColumnsFromJava(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this.joinColumnsContainerAnnotation); - } - - private void updateInverseJoinColumnsFromJava(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this.inverseJoinColumnsContainerAnnotation); - } - - public ListIterator<JoinColumnAnnotation> joinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.joinColumns); - } - - public int joinColumnsSize() { - return this.joinColumns.size(); - } - - public NestableJoinColumn joinColumnAt(int index) { - return this.joinColumns.get(index); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - return this.joinColumns.indexOf(joinColumn); - } - - public JoinColumnAnnotation addJoinColumn(int index) { - NestableJoinColumn joinColumn = (NestableJoinColumn) ContainerAnnotationTools.addNestedAnnotation(index, this.joinColumnsContainerAnnotation); - fireItemAdded(JoinTableAnnotation.JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected void addJoinColumn(int index, NestableJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.joinColumns, JOIN_COLUMNS_LIST); - } - - public void removeJoinColumn(int index) { - NestableJoinColumn joinColumn = this.joinColumns.get(index); - removeJoinColumn(joinColumn); - joinColumn.removeAnnotation(); - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, this.joinColumnsContainerAnnotation); - } - - protected void removeJoinColumn(NestableJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.joinColumns, JOIN_COLUMNS_LIST); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - moveJoinColumnInternal(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, this.joinColumnsContainerAnnotation); - fireItemMoved(JoinTableAnnotation.JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected void moveJoinColumnInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.joinColumns, targetIndex, sourceIndex); - } - - public ListIterator<JoinColumnAnnotation> inverseJoinColumns() { - return new CloneListIterator<JoinColumnAnnotation>(this.inverseJoinColumns); - } - - public int inverseJoinColumnsSize() { - return this.inverseJoinColumns.size(); - } - - public NestableJoinColumn inverseJoinColumnAt(int index) { - return this.inverseJoinColumns.get(index); - } - - public int indexOfInverseJoinColumn(JoinColumnAnnotation joinColumn) { - return this.inverseJoinColumns.indexOf(joinColumn); - } - - public JoinColumnAnnotation addInverseJoinColumn(int index) { - NestableJoinColumn inverseJoinColumn = (NestableJoinColumn) ContainerAnnotationTools.addNestedAnnotation(index, this.inverseJoinColumnsContainerAnnotation); - fireItemAdded(JoinTableAnnotation.INVERSE_JOIN_COLUMNS_LIST, index, inverseJoinColumn); - return inverseJoinColumn; - } - - private void addInverseJoinColumn(int index, NestableJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.inverseJoinColumns, INVERSE_JOIN_COLUMNS_LIST); - } - - public void removeInverseJoinColumn(int index) { - NestableJoinColumn joinColumn = this.inverseJoinColumns.get(index); - this.removeInverseJoinColumn(joinColumn); - joinColumn.removeAnnotation(); - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, this.inverseJoinColumnsContainerAnnotation); - } - - protected void removeInverseJoinColumn(NestableJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.inverseJoinColumns, INVERSE_JOIN_COLUMNS_LIST); - } - - public void moveInverseJoinColumn(int targetIndex, int sourceIndex) { - moveInverseJoinColumnInternal(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, this.inverseJoinColumnsContainerAnnotation); - fireItemMoved(JoinTableAnnotation.INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected void moveInverseJoinColumnInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.inverseJoinColumns, targetIndex, sourceIndex); - } - - protected NestableJoinColumn createJoinColumn(int index) { - return JoinColumnImpl.createJoinTableJoinColumn(this, getMember(), index); - } - - protected NestableJoinColumn createInverseJoinColumn(int index) { - return JoinColumnImpl.createJoinTableInverseJoinColumn(this, getMember(), index); - } - - private class JoinColumnsContainerAnnotation extends AbstractContainerAnnotation { - - public NestableJoinColumn addInternal(int index) { - NestableJoinColumn joinColumn = JoinTableImpl.this.createJoinColumn(index); - JoinTableImpl.this.joinColumns.add(index, joinColumn); - return joinColumn; - } - - public NestableJoinColumn add(int index) { - NestableJoinColumn joinColumn = JoinTableImpl.this.createJoinColumn(index); - JoinTableImpl.this.addJoinColumn(index, joinColumn); - return joinColumn; - } - - public int indexOf(NestableJoinColumn joinColumn) { - return JoinTableImpl.this.indexOfJoinColumn(joinColumn); - } - - public void move(int targetIndex, int sourceIndex) { - JoinTableImpl.this.moveJoinColumn(targetIndex, sourceIndex); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - JoinTableImpl.this.moveJoinColumnInternal(targetIndex, sourceIndex); - } - - public NestableJoinColumn nestedAnnotationAt(int index) { - return JoinTableImpl.this.joinColumnAt(index); - } - - public ListIterator<NestableJoinColumn> nestedAnnotations() { - return new CloneListIterator<NestableJoinColumn>(JoinTableImpl.this.joinColumns); - } - - public int nestedAnnotationsSize() { - return joinColumnsSize(); - } - - public void remove(NestableJoinColumn nestedAnnotation) { - JoinTableImpl.this.removeJoinColumn(nestedAnnotation); - } - public String getElementName() { - return "joinColumns"; - } - } - - private class InverseJoinColumnsContainerAnnotation extends AbstractContainerAnnotation { - - public NestableJoinColumn addInternal(int index) { - NestableJoinColumn joinColumn = JoinTableImpl.this.createInverseJoinColumn(index); - JoinTableImpl.this.inverseJoinColumns.add(index, joinColumn); - return joinColumn; - } - - public NestableJoinColumn add(int index) { - NestableJoinColumn joinColumn = JoinTableImpl.this.createInverseJoinColumn(index); - JoinTableImpl.this.addInverseJoinColumn(index, joinColumn); - return joinColumn; - } - - public int indexOf(NestableJoinColumn joinColumn) { - return JoinTableImpl.this.indexOfInverseJoinColumn(joinColumn); - } - - public void move(int targetIndex, int sourceIndex) { - JoinTableImpl.this.moveInverseJoinColumn(targetIndex, sourceIndex); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - JoinTableImpl.this.moveInverseJoinColumnInternal(targetIndex, sourceIndex); - } - - public NestableJoinColumn nestedAnnotationAt(int index) { - return JoinTableImpl.this.inverseJoinColumnAt(index); - } - - public ListIterator<NestableJoinColumn> nestedAnnotations() { - return new CloneListIterator<NestableJoinColumn>(JoinTableImpl.this.inverseJoinColumns); - } - - public int nestedAnnotationsSize() { - return inverseJoinColumnsSize(); - } - - public void remove(NestableJoinColumn nestedAnnotation) { - JoinTableImpl.this.removeInverseJoinColumn(nestedAnnotation); - } - - public String getElementName() { - return "inverseJoinColumns"; - } - } - - private abstract class AbstractContainerAnnotation extends AbstractJavaResourceNode implements ContainerAnnotation<NestableJoinColumn> { - - public AbstractContainerAnnotation() { - super(JoinTableImpl.this); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return JoinTableImpl.this.getAnnotationName(); - } - - public String getNestableAnnotationName() { - return JPA.JOIN_COLUMN; - } - - public void remove(int index) { - this.remove(nestedAnnotationAt(index)); - } - - public NestableJoinColumn nestedAnnotationFor(org.eclipse.jdt.core.dom.Annotation jdtAnnotation) { - for (NestableJoinColumn joinColumn : CollectionTools.iterable(nestedAnnotations())) { - if (jdtAnnotation == joinColumn.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return joinColumn; - } - } - return null; - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return JoinTableImpl.this.getJdtAnnotation(astRoot); - } - - public void newAnnotation() { - JoinTableImpl.this.newAnnotation(); - } - - public void removeAnnotation() { - JoinTableImpl.this.removeAnnotation(); - } - - public void update(CompilationUnit astRoot) { - JoinTableImpl.this.update(astRoot); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return JoinTableImpl.this.getTextRange(astRoot); - } - } - public static class JoinTableAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final JoinTableAnnotationDefinition INSTANCE = new JoinTableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JoinTableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new JoinTableImpl(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullJoinTable(parent); - } - - public String getAnnotationName() { - return JoinTableAnnotation.ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JpaCompilationUnitImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JpaCompilationUnitImpl.java deleted file mode 100644 index 2c457ca45d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JpaCompilationUnitImpl.java +++ /dev/null @@ -1,239 +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.resource.java; - -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.JavaCore; -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.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.utility.CommandExecutorProvider; - -public class JpaCompilationUnitImpl - extends AbstractJavaResourceNode - implements JpaCompilationUnit -{ - protected final JpaAnnotationProvider annotationProvider; - - protected final CommandExecutorProvider modifySharedDocumentCommandExecutorProvider; - - protected final AnnotationEditFormatter annotationEditFormatter; - - protected final JavaResourceModel javaResourceModel; - - protected final ICompilationUnit compilationUnit; - - /** - * 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 JpaCompilationUnitImpl( - IFile file, - JpaAnnotationProvider annotationProvider, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter, - JavaResourceModel javaResourceModel) { - super(null); // the JPA compilation unit is the root of its sub-tree - this.annotationProvider = annotationProvider; - this.modifySharedDocumentCommandExecutorProvider = modifySharedDocumentCommandExecutorProvider; - this.annotationEditFormatter = annotationEditFormatter; - this.javaResourceModel = javaResourceModel; - this.compilationUnit = JavaCore.createCompilationUnitFrom(file); - this.openCompilationUnit(); - this.persistentType = this.buildJavaResourcePersistentType(); - } - - 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 JavaResourcePersistentType buildJavaResourcePersistentType() { - return this.buildJavaResourcePersistentType(this.buildASTRoot()); - } - - protected JavaResourcePersistentType buildJavaResourcePersistentType(CompilationUnit astRoot) { - TypeDeclaration td = this.getPrimaryType(astRoot); - return (td == null) ? null : this.buildJavaResourcePersistentType(astRoot, td); - } - - public void initialize(CompilationUnit astRoot) { - // never called? - } - - - // ********** overrides ********** - - @Override - protected boolean requiresParent() { - return false; - } - - @Override - public JpaCompilationUnit getJpaCompilationUnit() { - return this; - } - - @Override - public JpaAnnotationProvider getAnnotationProvider() { - return this.annotationProvider; - } - - @Override - public CommandExecutorProvider getModifySharedDocumentCommandExecutorProvider() { - return this.modifySharedDocumentCommandExecutorProvider; - } - - @Override - public AnnotationEditFormatter getAnnotationEditFormatter() { - return this.annotationEditFormatter; - } - - @Override - public JavaResourceModel getResourceModel() { - return this.javaResourceModel; - } - - - // ********** JpaCompilationUnit implementation ********** - - public ICompilationUnit getCompilationUnit() { - return this.compilationUnit; - } - - public JavaResourcePersistentType getJavaPersistentTypeResource(String fullyQualifiedTypeName) { - return (this.persistentType == null) ? null : this.persistentType.getJavaPersistentTypeResource(fullyQualifiedTypeName); - } - - /** - * The persistentType resource for the compilation unit's primary type. - * Will be null if the primary type is null. - */ - public JavaResourcePersistentType getPersistentType() { - return this.persistentType; - //TODO should i only be returning this if it returns true to isPersistable? - //that's how we handle nestedTypes on JavaPersistentTypeResource - //return this.persistentType.isPersistable() ? this.persistentType : null; - } - - protected void setPersistentType(JavaResourcePersistentType persistentType) { - JavaResourcePersistentType old = this.persistentType; - this.persistentType = persistentType; - this.firePropertyChanged(PERSISTENT_TYPE_PROPERTY, old, persistentType); - } - - public void updateFromJava() { - this.update(this.buildASTRoot()); - } - - public void update(CompilationUnit astRoot) { - TypeDeclaration td = this.getPrimaryType(astRoot); - if (td == null) { - this.setPersistentType(null); - } else { - if (this.persistentType == null) { - this.setPersistentType(this.buildJavaResourcePersistentType(astRoot, td)); - } else { - this.persistentType.update(astRoot); - } - } - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public void resourceChanged() { - this.javaResourceModel.resourceChanged(); - } - - public void resolveTypes() { - if (this.persistentType != null) { - this.persistentType.resolveTypes(this.buildASTRoot()); - } - } - - - // ********** internal ********** - - protected CompilationUnit buildASTRoot() { - return JDTTools.buildASTRoot(this.compilationUnit); - } - - // TODO use JPA factory - protected JavaResourcePersistentType buildJavaResourcePersistentType(CompilationUnit astRoot, TypeDeclaration typeDeclaration) { - return JavaResourcePersistentTypeImpl.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 - */ - 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 (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"); - return (index == -1) ? fileName : fileName.substring(0, index); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.persistentType.getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/LobImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/LobImpl.java deleted file mode 100644 index 5ee3d79469..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/LobImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class LobImpl extends AbstractResourceAnnotation<Attribute> implements LobAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected LobImpl(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public void update(CompilationUnit astRoot) { - //nothing to update - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - public static class LobAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final LobAnnotationDefinition INSTANCE = new LobAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private LobAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new LobImpl(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToManyImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToManyImpl.java deleted file mode 100644 index d0145453a6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToManyImpl.java +++ /dev/null @@ -1,165 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -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.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.Member; - - -public class ManyToManyImpl extends AbstractRelationshipMappingAnnotation 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[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> MAPPED_BY_ADAPTER = buildMappedByAdapter(); - - private final AnnotationElementAdapter<String> mappedByAdapter; - - private String mappedBy; - - protected ManyToManyImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.mappedByAdapter = buildAnnotationElementAdapter(MAPPED_BY_ADAPTER); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.mappedBy = this.mappedBy(astRoot); - } - - //**************** AbstractRelationshipMappingAnnotation implementation ************** - - @Override - protected DeclarationAnnotationElementAdapter<String> targetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String[]> cascadeAdapter() { - return CASCADE_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> fetchAdapter() { - return FETCH_ADAPTER; - } - - - //**************** Annotation implementation ************** - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - if (attributeValueHasNotChanged(this.mappedBy, newMappedBy)) { - return; - } - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - this.mappedByAdapter.setValue(newMappedBy); - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setMappedBy(this.mappedBy(astRoot)); - } - - protected String mappedBy(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.MANY_TO_MANY__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_MANY__CASCADE); - } - - private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() { - return buildFetchAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_MANY__FETCH); - } - - - 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 - } - - - public static class ManyToManyAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final ManyToManyAnnotationDefinition INSTANCE = new ManyToManyAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static ManyToManyAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private ManyToManyAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new ManyToManyImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToOneImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToOneImpl.java deleted file mode 100644 index e0cbe75534..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/ManyToOneImpl.java +++ /dev/null @@ -1,164 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -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.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.Member; - - -public class ManyToOneImpl extends AbstractRelationshipMappingAnnotation 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[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<Boolean> OPTIONAL_ADAPTER = buildOptionalAdapter(); - - private final AnnotationElementAdapter<Boolean> optionalAdapter; - - private Boolean optional; - - protected ManyToOneImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.optionalAdapter = this.buildBooleanAnnotationElementAdapter(OPTIONAL_ADAPTER); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.optional = this.optional(astRoot); - } - - //**************** AbstractRelationshipMappingAnnotation implementation ************** - - @Override - protected DeclarationAnnotationElementAdapter<String> targetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String[]> cascadeAdapter() { - return CASCADE_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> fetchAdapter() { - return FETCH_ADAPTER; - } - - //**************** Annotation implementation ************** - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean newOptional) { - if (attributeValueHasNotChanged(this.optional, newOptional)) { - return; - } - Boolean oldOptional = this.optional; - this.optional = newOptional; - this.optionalAdapter.setValue(newOptional); - firePropertyChanged(OPTIONAL_PROPERTY, oldOptional, newOptional); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return getElementTextRange(OPTIONAL_ADAPTER, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setOptional(this.optional(astRoot)); - } - - protected Boolean optional(CompilationUnit astRoot) { - return this.optionalAdapter.getValue(astRoot); - } - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter() { - return buildTargetEntityAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_ONE__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.MANY_TO_ONE__CASCADE); - } - - 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<Boolean> buildOptionalAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return new ConversionDeclarationAnnotationElementAdapter<Boolean>(annotationAdapter, elementName, false, BooleanExpressionConverter.instance()); - } - - - public static class ManyToOneAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final ManyToOneAnnotationDefinition INSTANCE = new ManyToOneAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static ManyToOneAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private ManyToOneAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new ManyToOneImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MapKeyImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MapKeyImpl.java deleted file mode 100644 index 039f64fc0d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MapKeyImpl.java +++ /dev/null @@ -1,120 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -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; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class MapKeyImpl extends AbstractResourceAnnotation<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; - - protected MapKeyImpl(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, NAME_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.name = name(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - 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); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - // ********** static methods ********** - private static DeclarationAnnotationElementAdapter<String> buildNameAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.MAP_KEY__NAME, false); - } - - - public static class MapKeyAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final MapKeyAnnotationDefinition INSTANCE = new MapKeyAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private MapKeyAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new MapKeyImpl(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MappedSuperclassImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MappedSuperclassImpl.java deleted file mode 100644 index 83c2dde0ca..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/MappedSuperclassImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; - - -public class MappedSuperclassImpl extends AbstractResourceAnnotation<Type> implements MappedSuperclassAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected MappedSuperclassImpl(JavaResourcePersistentType parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void update(CompilationUnit astRoot) { - //no annotation members - } - - public static class MappedSuperclassAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final MappedSuperclassAnnotationDefinition INSTANCE = new MappedSuperclassAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static MappedSuperclassAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private MappedSuperclassAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new MappedSuperclassImpl((JavaResourcePersistentType) parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueriesImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueriesImpl.java deleted file mode 100644 index 86adc83e30..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueriesImpl.java +++ /dev/null @@ -1,156 +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.resource.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.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -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.NestableNamedNativeQuery; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class NamedNativeQueriesImpl extends AbstractResourceAnnotation<Type> implements NamedNativeQueriesAnnotation -{ - - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private List<NestableNamedNativeQuery> namedNativeQueries; - - protected NamedNativeQueriesImpl(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.namedNativeQueries = new ArrayList<NestableNamedNativeQuery>(); - } - - public void initialize(CompilationUnit astRoot) { - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this); - } - - public String getAnnotationName() { - return NamedNativeQueriesAnnotation.ANNOTATION_NAME; - } - - public String getNestableAnnotationName() { - return NamedNativeQueryAnnotation.ANNOTATION_NAME; - } - - public String getElementName() { - return "value"; - } - - public ListIterator<NestableNamedNativeQuery> nestedAnnotations() { - return new CloneListIterator<NestableNamedNativeQuery>(this.namedNativeQueries); - } - - public int nestedAnnotationsSize() { - return this.namedNativeQueries.size(); - } - - public NestableNamedNativeQuery addInternal(int index) { - NestableNamedNativeQuery namedNativeQuery = createNamedNativeQuery(index); - this.namedNativeQueries.add(index, namedNativeQuery); - return namedNativeQuery; - } - - public NestableNamedNativeQuery add(int index) { - NestableNamedNativeQuery namedNativeQuery = createNamedNativeQuery(index); - add(index, namedNativeQuery); - return namedNativeQuery; - } - - protected void add(int index, NestableNamedNativeQuery query) { - addItemToList(index, query, this.namedNativeQueries, NamedNativeQueriesAnnotation.NAMED_NATIVE_QUERIES_LIST); - } - - public void remove(NestableNamedNativeQuery query) { - removeItemFromList(query, this.namedNativeQueries, NamedNativeQueriesAnnotation.NAMED_NATIVE_QUERIES_LIST); - } - - public void remove(int index) { - removeItemFromList(index, this.namedNativeQueries, NamedNativeQueriesAnnotation.NAMED_NATIVE_QUERIES_LIST); - } - - public int indexOf(NestableNamedNativeQuery query) { - return this.namedNativeQueries.indexOf(query); - } - - public NestableNamedNativeQuery nestedAnnotationAt(int index) { - return this.namedNativeQueries.get(index); - } - - public NestableNamedNativeQuery nestedAnnotationFor(org.eclipse.jdt.core.dom.Annotation jdtAnnotation) { - for (NestableNamedNativeQuery namedQuery : this.namedNativeQueries) { - if (jdtAnnotation == namedQuery.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return namedQuery; - } - } - return null; - } - - public void move(int targetIndex, int sourceIndex) { - moveItemInList(targetIndex, sourceIndex, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - } - - public void update(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this); - } - - private NamedNativeQueryImpl createNamedNativeQuery(int index) { - return NamedNativeQueryImpl.createNestedNamedNativeQuery(this, getMember(), index, getDeclarationAnnotationAdapter()); - } - - - public static class NamedNativeQueriesAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final NamedNativeQueriesAnnotationDefinition INSTANCE = new NamedNativeQueriesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private NamedNativeQueriesAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NamedNativeQueriesImpl(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueryImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueryImpl.java deleted file mode 100644 index 98a055003e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedNativeQueryImpl.java +++ /dev/null @@ -1,233 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableNamedNativeQuery; -import org.eclipse.jpt.core.resource.java.NestableQueryHint; -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; -import org.eclipse.jpt.core.utility.jdt.Type; - -public class NamedNativeQueryImpl extends AbstractNamedQuery - implements NestableNamedNativeQuery -{ - - public static final SimpleDeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - // hold this so we can get the 'resultClass' text range - private final DeclarationAnnotationElementAdapter<String> resultClassDeclarationAdapter; - - // hold this so we can get the 'resultSetMapping' text range - private final DeclarationAnnotationElementAdapter<String> resultSetMappingDeclarationAdapter; - - - private final AnnotationElementAdapter<String> resultClassAdapter; - - private final AnnotationElementAdapter<String> resultSetMappingAdapter; - - private String resultClass; - - private String fullyQualifiedResultClass; - - private String resultSetMapping; - - protected NamedNativeQueryImpl(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, type, daa, annotationAdapter); - this.resultClassDeclarationAdapter = resultClassAdapter(daa); - this.resultClassAdapter = this.buildAdapter(this.resultClassDeclarationAdapter); - this.resultSetMappingDeclarationAdapter = resultSetMappingAdapter(daa); - this.resultSetMappingAdapter = this.buildAdapter(this.resultSetMappingDeclarationAdapter); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.resultClass = this.resultClass(astRoot); - this.fullyQualifiedResultClass = this.fullyQualifiedResultClass(astRoot); - this.resultSetMapping = this.resultSetMapping(astRoot); - } - - - // ********** initialization ********** - protected DeclarationAnnotationElementAdapter<String> resultClassAdapter(DeclarationAnnotationAdapter daa) { - return new ConversionDeclarationAnnotationElementAdapter<String>(daa, JPA.NAMED_NATIVE_QUERY__RESULT_CLASS, SimpleTypeStringExpressionConverter.instance()); - } - - protected DeclarationAnnotationElementAdapter<String> resultSetMappingAdapter(DeclarationAnnotationAdapter daa) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daa, JPA.NAMED_NATIVE_QUERY__RESULT_SET_MAPPING); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - //************* AbstractNamedQuery implementation ************* - - @Override - protected String nameElementName() { - return JPA.NAMED_NATIVE_QUERY__NAME; - } - - @Override - protected String queryElementName() { - return JPA.NAMED_NATIVE_QUERY__QUERY; - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - NamedNativeQueryAnnotation oldNamedQuery = (NamedNativeQueryAnnotation) oldAnnotation; - setResultClass(oldNamedQuery.getResultClass()); - setResultSetMapping(oldNamedQuery.getResultSetMapping()); - } - - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String newResultClass) { - if (attributeValueHasNotChanged(this.resultClass, newResultClass)) { - return; - } - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - this.resultClassAdapter.setValue(newResultClass); - firePropertyChanged(RESULT_CLASS_PROPERTY, oldResultClass, newResultClass); - } - - public String getFullyQualifiedResultClass() { - return this.fullyQualifiedResultClass; - } - - protected void setFullyQualifiedResultClass(String newQualifiedResultClass) { - String oldFullyQualifiedResultClass = this.fullyQualifiedResultClass; - this.fullyQualifiedResultClass = newQualifiedResultClass; - firePropertyChanged(FULLY_QUALIFIED_RESULT_CLASS_PROPERTY, oldFullyQualifiedResultClass, newQualifiedResultClass); - } - - public String getResultSetMapping() { - return this.resultSetMapping; - } - - public void setResultSetMapping(String newResultSetMapping) { - if (attributeValueHasNotChanged(this.resultSetMapping, newResultSetMapping)) { - return; - } - String oldResultSetMapping = this.resultSetMapping; - this.resultSetMapping = newResultSetMapping; - this.resultSetMappingAdapter.setValue(newResultSetMapping); - firePropertyChanged(RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - public TextRange getResultClassTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.resultClassDeclarationAdapter, astRoot); - } - - public TextRange getResultSetMappingTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.resultSetMappingDeclarationAdapter, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setResultClass(this.resultClass(astRoot)); - this.setFullyQualifiedResultClass(this.fullyQualifiedResultClass(astRoot)); - this.setResultSetMapping(this.resultSetMapping(astRoot)); - } - - protected String resultClass(CompilationUnit astRoot) { - return this.resultClassAdapter.getValue(astRoot); - } - - protected String resultSetMapping(CompilationUnit astRoot) { - return this.resultSetMappingAdapter.getValue(astRoot); - } - - protected String fullyQualifiedResultClass(CompilationUnit astRoot) { - if (getResultClass() == null) { - return null; - } - return JDTTools.resolveFullyQualifiedName(this.resultClassAdapter.getExpression(astRoot)); - } - - @Override - protected NestableQueryHint createQueryHint(int index) { - return QueryHintImpl.createNamedNativeQueryQueryHint(this, this.getMember(), this.getDeclarationAnnotationAdapter(), index); - } - - // ********** static methods ********** - static NamedNativeQueryImpl createNamedNativeQuery(JavaResourceNode parent, Type type) { - return new NamedNativeQueryImpl(parent, type, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(type, DECLARATION_ANNOTATION_ADAPTER)); - } - - static NamedNativeQueryImpl createNestedNamedNativeQuery(JavaResourceNode parent, Type type, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(type, idaa); - return new NamedNativeQueryImpl(parent, type, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter namedQueriesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(namedQueriesAdapter, index, JPA.NAMED_NATIVE_QUERY); - } - - public static class NamedNativeQueryAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final NamedNativeQueryAnnotationDefinition INSTANCE = new NamedNativeQueryAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private NamedNativeQueryAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return NamedNativeQueryImpl.createNamedNativeQuery(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueriesImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueriesImpl.java deleted file mode 100644 index 24220a0f35..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueriesImpl.java +++ /dev/null @@ -1,155 +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.resource.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.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableNamedQuery; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class NamedQueriesImpl extends AbstractResourceAnnotation<Type> implements NamedQueriesAnnotation -{ - - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(NamedQueriesAnnotation.ANNOTATION_NAME); - - private List<NestableNamedQuery> namedQueries; - - protected NamedQueriesImpl(JavaResourceNode parent, Type type) { - super(parent, type, DECLARATION_ANNOTATION_ADAPTER); - this.namedQueries = new ArrayList<NestableNamedQuery>(); - } - - public void initialize(CompilationUnit astRoot) { - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this); - } - - public String getAnnotationName() { - return NamedQueriesAnnotation.ANNOTATION_NAME; - } - - public String getNestableAnnotationName() { - return NamedQueryAnnotation.ANNOTATION_NAME; - } - - public String getElementName() { - return "value"; - } - - public ListIterator<NestableNamedQuery> nestedAnnotations() { - return new CloneListIterator<NestableNamedQuery>(this.namedQueries); - } - - public int nestedAnnotationsSize() { - return this.namedQueries.size(); - } - - public NestableNamedQuery addInternal(int index) { - NestableNamedQuery namedQuery = createNamedQuery(index); - this.namedQueries.add(index, namedQuery); - return namedQuery; - } - - public NestableNamedQuery add(int index) { - NestableNamedQuery namedQuery = createNamedQuery(index); - add(index, namedQuery); - return namedQuery; - } - - protected void add(int index, NestableNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, NamedQueriesAnnotation.NAMED_QUERIES_LIST); - } - - public void remove(NestableNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, NamedQueriesAnnotation.NAMED_QUERIES_LIST); - } - - public void remove(int index) { - removeItemFromList(index, this.namedQueries, NamedQueriesAnnotation.NAMED_QUERIES_LIST); - } - - public int indexOf(NestableNamedQuery attributeOverride) { - return this.namedQueries.indexOf(attributeOverride); - } - - public NestableNamedQuery nestedAnnotationAt(int index) { - return this.namedQueries.get(index); - } - - public NestableNamedQuery nestedAnnotationFor(org.eclipse.jdt.core.dom.Annotation jdtAnnotation) { - for (NestableNamedQuery namedQuery : this.namedQueries) { - if (jdtAnnotation == namedQuery.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return namedQuery; - } - } - return null; - } - - public void move(int targetIndex, int sourceIndex) { - moveItemInList(targetIndex, sourceIndex, this.namedQueries, NamedQueriesAnnotation.NAMED_QUERIES_LIST); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - } - - public void update(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this); - } - - private NamedQueryImpl createNamedQuery(int index) { - return NamedQueryImpl.createNestedNamedQuery(this, getMember(), index, getDeclarationAnnotationAdapter()); - } - - public static class NamedQueriesAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final NamedQueriesAnnotationDefinition INSTANCE = new NamedQueriesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private NamedQueriesAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NamedQueriesImpl(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueryImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueryImpl.java deleted file mode 100644 index ae1c4f09f4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NamedQueryImpl.java +++ /dev/null @@ -1,107 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableNamedQuery; -import org.eclipse.jpt.core.resource.java.NestableQueryHint; -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; -import org.eclipse.jpt.core.utility.jdt.Type; - -public class NamedQueryImpl extends AbstractNamedQuery - implements NestableNamedQuery -{ - - public static final SimpleDeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected NamedQueryImpl(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, type, daa, annotationAdapter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - //************* AbstractNamedQuery implementation ************* - @Override - protected String nameElementName() { - return JPA.NAMED_QUERY__NAME; - } - - @Override - protected String queryElementName() { - return JPA.NAMED_QUERY__QUERY; - } - - @Override - protected NestableQueryHint createQueryHint(int index) { - return QueryHintImpl.createNamedQueryQueryHint(this, getMember(), this.getDeclarationAnnotationAdapter(), index); - } - - // ********** static methods ********** - static NamedQueryImpl createNamedQuery(JavaResourceNode parent, Type type) { - return new NamedQueryImpl(parent, type, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(type, DECLARATION_ANNOTATION_ADAPTER)); - } - - static NamedQueryImpl createNestedNamedQuery(JavaResourceNode parent, Type type, int index, DeclarationAnnotationAdapter attributeOverridesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, attributeOverridesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(type, idaa); - return new NamedQueryImpl(parent, type, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter namedQueriesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(namedQueriesAdapter, index, JPA.NAMED_QUERY); - } - - public static class NamedQueryAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final NamedQueryAnnotationDefinition INSTANCE = new NamedQueryAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private NamedQueryAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return NamedQueryImpl.createNamedQuery(parent, (Type) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAssociationOverride.java deleted file mode 100644 index c00fb97128..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAssociationOverride.java +++ /dev/null @@ -1,116 +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.java; - -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - - -public class NullAssociationOverride extends AbstractJavaResourceNode implements AssociationOverrideAnnotation, Annotation -{ - private String name; - - public NullAssociationOverride(JavaResourceNode parent, String name) { - super(parent); - this.name = name; - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return AssociationOverrideAnnotation.ANNOTATION_NAME; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - if (name != null) { - createAssociationOverrideResource().setName(name); - } - } - - public ListIterator<JoinColumnAnnotation> joinColumns() { - return EmptyListIterator.instance(); - } - - public JoinColumnAnnotation joinColumnAt(int index) { - return null; - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - throw new UnsupportedOperationException(); - } - - public int joinColumnsSize() { - return 0; - } - - 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 JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - protected AssociationOverrideAnnotation createAssociationOverrideResource() { - return (AssociationOverrideAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return false; - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumn.java deleted file mode 100644 index b73262e6a2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumn.java +++ /dev/null @@ -1,80 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullAttributeOverrideColumn extends NullBaseColumn implements ColumnAnnotation, Annotation -{ - public NullAttributeOverrideColumn(AttributeOverrideAnnotation parent) { - super(parent); - } - - @Override - public AttributeOverrideAnnotation getParent() { - return (AttributeOverrideAnnotation) super.getParent(); - } - - public String getAnnotationName() { - return ColumnAnnotation.ANNOTATION_NAME; - } - - @Override - protected ColumnAnnotation createColumnResource() { - return getParent().addColumn(); - } - - public Integer getLength() { - return null; - } - - public void setLength(Integer length) { - if (length != null) { - createColumnResource().setLength(length); - } - } - - public Integer getScale() { - return null; - } - - public void setScale(Integer scale) { - if (scale != null) { - createColumnResource().setScale(scale); - } - } - - public Integer getPrecision() { - return null; - } - - public void setPrecision(Integer precision) { - if (precision != null) { - createColumnResource().setPrecision(precision); - } - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumn.java deleted file mode 100644 index 3639b674e1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumn.java +++ /dev/null @@ -1,101 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.BaseColumnAnnotation; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class NullBaseColumn extends NullNamedColumn implements BaseColumnAnnotation, Annotation -{ - protected NullBaseColumn(JavaResourceNode parent) { - super(parent); - } - - @Override - protected abstract BaseColumnAnnotation createColumnResource(); - - public String getTable() { - return null; - } - - public void setTable(String table) { - if (table != null) { - createColumnResource().setTable(table); - } - } - - public Boolean getUnique() { - return null; - } - - public void setUnique(Boolean unique) { - if (unique != null) { - createColumnResource().setUnique(unique); - } - } - - public Boolean getUpdatable() { - return null; - } - - public void setUpdatable(Boolean updatable) { - if (updatable != null) { - createColumnResource().setUpdatable(updatable); - } - } - - public Boolean getInsertable() { - return null; - } - - public void setInsertable(Boolean insertable) { - if (insertable != null) { - createColumnResource().setInsertable(insertable); - } - } - - public Boolean getNullable() { - return null; - } - - public void setNullable(Boolean nullable) { - if (nullable != null) { - createColumnResource().setNullable(nullable); - } - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getUniqueTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getUpdatableTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getInsertableTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getNullableTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTable.java deleted file mode 100644 index b0663e2009..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTable.java +++ /dev/null @@ -1,141 +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.resource.java; - -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public abstract class NullBaseTable extends AbstractJavaResourceNode implements Annotation -{ - protected NullBaseTable(JavaResourcePersistentMember parent) { - super(parent); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - protected TableAnnotation createTableResource() { - return (TableAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public String getName() { - return null; - } - - public void setName(String name) { - if (name != null) { - createTableResource().setName(name); - } - } - - public String getCatalog() { - return null; - } - - public void setCatalog(String catalog) { - if (catalog != null) { - createTableResource().setCatalog(catalog); - } - } - - public String getSchema() { - return null; - } - - public void setSchema(String schema) { - if (schema != null) { - createTableResource().setSchema(schema); - } - } - - public UniqueConstraintAnnotation addUniqueConstraint(int index) { - return createTableResource().addUniqueConstraint(index); - } - - public void removeUniqueConstraint(int index) { - throw new UnsupportedOperationException(); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - throw new UnsupportedOperationException(); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - public UniqueConstraintAnnotation uniqueConstraintAt(int index) { - throw new UnsupportedOperationException(); - } - - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return EmptyListIterator.instance(); - } - - public int uniqueConstraintsSize() { - return 0; - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - return null; - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return false; - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return false; - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return false; - } - - 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/NullBasic.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasic.java deleted file mode 100644 index a3c65b2adf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasic.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullBasic extends AbstractJavaResourceNode implements BasicAnnotation, Annotation -{ - protected NullBasic(JavaResourcePersistentMember parent) { - super(parent); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return BasicAnnotation.ANNOTATION_NAME; - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - protected BasicAnnotation createBasicResource() { - getParent().setMappingAnnotation(getAnnotationName()); - return (BasicAnnotation) getParent().getMappingAnnotation(); - } - - public FetchType getFetch() { - return null; - } - - public void setFetch(FetchType fetch) { - if (fetch != null) { - createBasicResource().setFetch(fetch); - } - } - - public Boolean getOptional() { - return null; - } - - public void setOptional(Boolean optional) { - if (optional != null) { - createBasicResource().setOptional(optional); - } - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getFetchTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumn.java deleted file mode 100644 index 9691145c81..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumn.java +++ /dev/null @@ -1,80 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullColumn extends NullBaseColumn implements ColumnAnnotation, Annotation -{ - public NullColumn(JavaResourcePersistentMember parent) { - super(parent); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - public String getAnnotationName() { - return ColumnAnnotation.ANNOTATION_NAME; - } - - @Override - protected ColumnAnnotation createColumnResource() { - return (ColumnAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public Integer getLength() { - return null; - } - - public void setLength(Integer length) { - if (length != null) { - createColumnResource().setLength(length); - } - } - - public Integer getScale() { - return null; - } - - public void setScale(Integer scale) { - if (scale != null) { - createColumnResource().setScale(scale); - } - } - - public Integer getPrecision() { - return null; - } - - public void setPrecision(Integer precision) { - if (precision != null) { - createColumnResource().setPrecision(precision); - } - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumn.java deleted file mode 100644 index 5f00a9132d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumn.java +++ /dev/null @@ -1,58 +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.resource.java; - -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; - - - -public class NullDiscriminatorColumn extends NullNamedColumn implements DiscriminatorColumnAnnotation, Annotation -{ - public NullDiscriminatorColumn(JavaResourcePersistentMember parent) { - super(parent); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - public String getAnnotationName() { - return DiscriminatorColumnAnnotation.ANNOTATION_NAME; - } - - @Override - protected DiscriminatorColumnAnnotation createColumnResource() { - return (DiscriminatorColumnAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public DiscriminatorType getDiscriminatorType() { - return null; - } - - public void setDiscriminatorType(DiscriminatorType discriminatorType) { - if (discriminatorType != null) { - createColumnResource().setDiscriminatorType(discriminatorType); - } - } - - public Integer getLength() { - return null; - } - - public void setLength(Integer length) { - if (length != null) { - createColumnResource().setLength(length); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValue.java deleted file mode 100644 index 6703b8d02f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValue.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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullDiscriminatorValue extends AbstractJavaResourceNode implements DiscriminatorValueAnnotation, Annotation -{ - protected NullDiscriminatorValue(JavaResourcePersistentMember parent) { - super(parent); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return DiscriminatorValueAnnotation.ANNOTATION_NAME; - } - - public String getValue() { - return null; - } - - public void setValue(String value) { - if (value != null) { - createDiscriminatorValueResource().setValue(value); - } - } - - protected DiscriminatorValueAnnotation createDiscriminatorValueResource() { - return (DiscriminatorValueAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEmbedded.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEmbedded.java deleted file mode 100644 index a015e0b4ff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEmbedded.java +++ /dev/null @@ -1,60 +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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullEmbedded extends AbstractJavaResourceNode implements EmbeddedAnnotation, Annotation -{ - protected NullEmbedded(JavaResourcePersistentMember parent) { - super(parent); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return EmbeddedAnnotation.ANNOTATION_NAME; - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumerated.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumerated.java deleted file mode 100644 index 7f039d1c79..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumerated.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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.EnumType; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullEnumerated extends AbstractJavaResourceNode implements EnumeratedAnnotation, Annotation -{ - protected NullEnumerated(JavaResourcePersistentMember parent) { - super(parent); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return EnumeratedAnnotation.ANNOTATION_NAME; - } - - protected EnumeratedAnnotation createEnumeratedResource() { - return (EnumeratedAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - - public EnumType getValue() { - return null; - } - - public void setValue(EnumType value) { - if (value != null) { - createEnumeratedResource().setValue(value); - } - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritance.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritance.java deleted file mode 100644 index 3e543408a4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritance.java +++ /dev/null @@ -1,79 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullInheritance extends AbstractJavaResourceNode implements InheritanceAnnotation, Annotation -{ - protected NullInheritance(JavaResourcePersistentMember parent) { - super(parent); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return InheritanceAnnotation.ANNOTATION_NAME; - } - - public InheritanceType getStrategy() { - return null; - } - - public void setStrategy(InheritanceType strategy) { - if (strategy != null) { - createInheritanceResource().setStrategy(strategy); - } - - } - - protected InheritanceAnnotation createInheritanceResource() { - return (InheritanceAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - - } - - public TextRange getStrategyTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinColumn.java deleted file mode 100644 index 4fc798cf24..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinColumn.java +++ /dev/null @@ -1,50 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - - -public class NullJoinColumn extends NullBaseColumn implements JoinColumnAnnotation, Annotation -{ - public NullJoinColumn(JavaResourceNode parent) { - super(parent); - } - - public String getAnnotationName() { - return JoinColumnAnnotation.ANNOTATION_NAME; - } - - @Override - protected JoinColumnAnnotation createColumnResource() { - throw new UnsupportedOperationException(); - } - - 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/NullJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTable.java deleted file mode 100644 index cd6098a296..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTable.java +++ /dev/null @@ -1,84 +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.resource.java; - -import java.util.ListIterator; -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.utility.internal.iterators.EmptyListIterator; - - -public class NullJoinTable extends NullBaseTable implements JoinTableAnnotation -{ - protected NullJoinTable(JavaResourcePersistentMember parent) { - super(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public JoinColumnAnnotation addInverseJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation addJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public int indexOfInverseJoinColumn(JoinColumnAnnotation joinColumn) { - throw new UnsupportedOperationException(); - } - - public int indexOfJoinColumn(JoinColumnAnnotation joinColumn) { - throw new UnsupportedOperationException(); - } - - public JoinColumnAnnotation inverseJoinColumnAt(int index) { - return null; - } - - public ListIterator<JoinColumnAnnotation> inverseJoinColumns() { - return EmptyListIterator.instance(); - } - - public int inverseJoinColumnsSize() { - return 0; - } - - public JoinColumnAnnotation joinColumnAt(int index) { - return null; - } - - public ListIterator<JoinColumnAnnotation> joinColumns() { - return EmptyListIterator.instance(); - } - - public int joinColumnsSize() { - return 0; - } - - public void moveInverseJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void moveJoinColumn(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public void removeInverseJoinColumn(int index) { - throw new UnsupportedOperationException(); - } - - public void removeJoinColumn(int index) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumn.java deleted file mode 100644 index c32c95faa2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumn.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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.NamedColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class NullNamedColumn extends AbstractJavaResourceNode implements NamedColumnAnnotation, Annotation -{ - protected NullNamedColumn(JavaResourceNode parent) { - super(parent); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - protected abstract NamedColumnAnnotation createColumnResource(); - - public String getName() { - return null; - } - - public void setName(String name) { - if (name != null) { - createColumnResource().setName(name); - } - } - - public String getColumnDefinition() { - return null; - } - - public void setColumnDefinition(String columnDefinition) { - if (columnDefinition != null) { - createColumnResource().setColumnDefinition(columnDefinition); - } - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getColumnDefinitionTextRange(CompilationUnit astRoot) { - return null; - } - - 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/resource/java/NullPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullPrimaryKeyJoinColumn.java deleted file mode 100644 index d7d91f1387..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,50 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - - -public class NullPrimaryKeyJoinColumn extends NullNamedColumn implements PrimaryKeyJoinColumnAnnotation, Annotation -{ - public NullPrimaryKeyJoinColumn(JavaResourceNode parent) { - super(parent); - } - - public String getAnnotationName() { - return PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME; - } - - @Override - protected PrimaryKeyJoinColumnAnnotation createColumnResource() { - throw new UnsupportedOperationException(); - } - - 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/NullTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTable.java deleted file mode 100644 index 1d5f9f6185..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTable.java +++ /dev/null @@ -1,28 +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.resource.java; - -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TableAnnotation; - - -public class NullTable extends NullBaseTable implements TableAnnotation -{ - protected NullTable(JavaResourcePersistentMember 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/NullTemporal.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporal.java deleted file mode 100644 index 49fed0de9d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporal.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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalType; -import org.eclipse.jpt.core.utility.TextRange; - - -public class NullTemporal extends AbstractJavaResourceNode implements TemporalAnnotation, Annotation -{ - protected NullTemporal(JavaResourcePersistentMember parent) { - super(parent); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return TemporalAnnotation.ANNOTATION_NAME; - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - protected TemporalAnnotation createTemporalResource() { - return (TemporalAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - - public TemporalType getValue() { - return null; - } - - public void setValue(TemporalType value) { - if (value != null) { - createTemporalResource().setValue(value); - } - } - - public void update(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToManyImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToManyImpl.java deleted file mode 100644 index a5a75af7f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToManyImpl.java +++ /dev/null @@ -1,161 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -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.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.Member; - -public class OneToManyImpl extends AbstractRelationshipMappingAnnotation 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[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> MAPPED_BY_ADAPTER = buildMappedByAdapter(); - - private final AnnotationElementAdapter<String> mappedByAdapter; - - private String mappedBy; - - protected OneToManyImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.mappedByAdapter = buildAnnotationElementAdapter(MAPPED_BY_ADAPTER); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.mappedBy = this.mappedBy(astRoot); - } - - //**************** AbstractRelationshipMappingAnnotation implementation ************** - - @Override - protected DeclarationAnnotationElementAdapter<String> targetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String[]> cascadeAdapter() { - return CASCADE_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> fetchAdapter() { - return FETCH_ADAPTER; - } - - //**************** Annotation implementation ************** - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - if (attributeValueHasNotChanged(this.mappedBy, newMappedBy)) { - return; - } - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - this.mappedByAdapter.setValue(newMappedBy); - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - 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); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setMappedBy(this.mappedBy(astRoot)); - } - - protected String mappedBy(CompilationUnit astRoot) { - return this.mappedByAdapter.getValue(astRoot); - } - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter() { - return buildTargetEntityAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_MANY__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_MANY__CASCADE); - } - - private static DeclarationAnnotationElementAdapter<String> buildFetchAdapter() { - return buildFetchAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_MANY__FETCH); - } - - 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 - } - - public static class OneToManyAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final OneToManyAnnotationDefinition INSTANCE = new OneToManyAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static OneToManyAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OneToManyAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new OneToManyImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToOneImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToOneImpl.java deleted file mode 100644 index 902de6ccec..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OneToOneImpl.java +++ /dev/null @@ -1,205 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -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.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.Member; - -public class OneToOneImpl extends AbstractRelationshipMappingAnnotation 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[]> CASCADE_ADAPTER = buildCascadeAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> FETCH_ADAPTER = buildFetchAdapter(); - - private static final DeclarationAnnotationElementAdapter<Boolean> OPTIONAL_ADAPTER = buildOptionalAdapter(); - - private static final DeclarationAnnotationElementAdapter<String> MAPPED_BY_ADAPTER = buildMappedByAdapter(); - - private final AnnotationElementAdapter<Boolean> optionalAdapter; - - private final AnnotationElementAdapter<String> mappedByAdapter; - - - private Boolean optional; - - private String mappedBy; - - public OneToOneImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.mappedByAdapter = buildAnnotationElementAdapter(MAPPED_BY_ADAPTER); - this.optionalAdapter = this.buildBooleanAnnotationElementAdapter(OPTIONAL_ADAPTER); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.mappedBy = this.mappedBy(astRoot); - this.optional = this.optional(astRoot); - } - - //**************** AbstractRelationshipMappingAnnotation implementation ************** - - @Override - protected DeclarationAnnotationElementAdapter<String> targetEntityAdapter() { - return TARGET_ENTITY_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String[]> cascadeAdapter() { - return CASCADE_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> fetchAdapter() { - return FETCH_ADAPTER; - } - - //**************** Annotation implementation ************** - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - public Boolean getOptional() { - return this.optional; - } - - public void setOptional(Boolean newOptional) { - if (attributeValueHasNotChanged(this.optional, newOptional)) { - return; - } - Boolean oldOptional = this.optional; - this.optional = newOptional; - this.optionalAdapter.setValue(newOptional); - firePropertyChanged(OPTIONAL_PROPERTY, oldOptional, newOptional); - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - if (attributeValueHasNotChanged(this.mappedBy, newMappedBy)) { - return; - } - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - this.mappedByAdapter.setValue(newMappedBy); - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return getElementTextRange(MAPPED_BY_ADAPTER, astRoot); - } - - public TextRange getOptionalTextRange(CompilationUnit astRoot) { - return getElementTextRange(OPTIONAL_ADAPTER, astRoot); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(MAPPED_BY_ADAPTER, pos, astRoot); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setOptional(this.optional(astRoot)); - this.setMappedBy(this.mappedByAdapter.getValue(astRoot)); - } - - protected String mappedBy(CompilationUnit astRoot) { - return this.mappedByAdapter.getValue(astRoot); - } - - protected Boolean optional(CompilationUnit astRoot) { - return this.optionalAdapter.getValue(astRoot); - } - - - // ********** static methods ********** - - private static DeclarationAnnotationElementAdapter<String> buildTargetEntityAdapter() { - return buildTargetEntityAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__TARGET_ENTITY); - } - - private static DeclarationAnnotationElementAdapter<String[]> buildCascadeAdapter() { - return buildEnumArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__CASCADE); - } - - 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> buildMappedByAdapter() { - return ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER, JPA.ONE_TO_ONE__MAPPED_BY, false); // false = do not remove annotation when empty - } - - public static class OneToOneAnnotationDefinition implements AnnotationDefinition - { - - // singleton - private static final OneToOneAnnotationDefinition INSTANCE = new OneToOneAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static OneToOneAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OneToOneAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new OneToOneImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OrderByImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OrderByImpl.java deleted file mode 100644 index 4b364ebfa6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OrderByImpl.java +++ /dev/null @@ -1,116 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -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; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class OrderByImpl extends AbstractResourceAnnotation<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; - - protected OrderByImpl(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, VALUE_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.value(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - if (attributeValueHasNotChanged(this.value, newValue)) { - return; - } - String oldValue = this.value; - this.value = newValue; - this.valueAdapter.setValue(newValue); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.value(astRoot)); - } - - protected String value(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); - } - - - public static class OrderByAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final OrderByAnnotationDefinition INSTANCE = new OrderByAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrderByAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new OrderByImpl(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OverrideImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OverrideImpl.java deleted file mode 100644 index 023d24dd87..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/OverrideImpl.java +++ /dev/null @@ -1,92 +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.resource.java; - -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.JPA; -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; - -public abstract class OverrideImpl - extends AbstractResourceAnnotation<Member> - implements OverrideAnnotation -{ - // hold this so we can get the 'name' text range - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - - private final AnnotationElementAdapter<String> nameAdapter; - - private String name; - - - protected OverrideImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.nameDeclarationAdapter = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, JPA.ATTRIBUTE_OVERRIDE__NAME, false); // false = do not remove annotation when empty - this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(getMember(),this.nameDeclarationAdapter); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.name(astRoot); - } - - public IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) super.getAnnotationAdapter(); - } - - public void moveAnnotation(int newIndex) { - getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - public void initializeFrom(NestableAnnotation oldAnnotation) { - OverrideAnnotation oldOverride = (OverrideAnnotation) oldAnnotation; - setName(oldOverride.getName()); - } - - //************ AttriubteOverride implementation **************** - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(OverrideAnnotation.NAME_PROPERTY, oldName, newName); - } - - 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); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnImpl.java deleted file mode 100644 index cf074f5fc1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnImpl.java +++ /dev/null @@ -1,184 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -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.resource.java.NestablePrimaryKeyJoinColumn; -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; - -public class PrimaryKeyJoinColumnImpl extends AbstractNamedColumn implements NestablePrimaryKeyJoinColumn -{ - - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - // hold this so we can get the 'referenced column name' text range - private final DeclarationAnnotationElementAdapter<String> referencedColumnNameDeclarationAdapter; - - private final AnnotationElementAdapter<String> referencedColumnNameAdapter; - - private String referencedColumnName; - - protected PrimaryKeyJoinColumnImpl(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); - } - - protected PrimaryKeyJoinColumnImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa) { - this(parent, member, daa, new MemberAnnotationAdapter(member, daa)); - } - - protected PrimaryKeyJoinColumnImpl(JavaResourceNode parent, Member member, IndexedDeclarationAnnotationAdapter idaa) { - this(parent, member, idaa, new MemberIndexedAnnotationAdapter(member, idaa)); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.referencedColumnName = this.referencedColumnName(astRoot); - } - - @Override - protected String nameElementName() { - return JPA.PRIMARY_KEY_JOIN_COLUMN__NAME; - } - - @Override - protected String columnDefinitionElementName() { - return JPA.PRIMARY_KEY_JOIN_COLUMN__COLUMN_DEFINITION; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - private IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) super.getAnnotationAdapter(); - } - - public void moveAnnotation(int newIndex) { - getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - @Override - public void initializeFrom(NestableAnnotation oldAnnotation) { - super.initializeFrom(oldAnnotation); - PrimaryKeyJoinColumnAnnotation oldColumn = (PrimaryKeyJoinColumnAnnotation) oldAnnotation; - setReferencedColumnName(oldColumn.getReferencedColumnName()); - } - - public String getReferencedColumnName() { - return this.referencedColumnName; - } - - public void setReferencedColumnName(String newReferencedColumnName) { - if (attributeValueHasNotChanged(this.referencedColumnName, newReferencedColumnName)) { - return; - } - String oldReferencedColumnName = this.referencedColumnName; - this.referencedColumnName = newReferencedColumnName; - this.referencedColumnNameAdapter.setValue(newReferencedColumnName); - firePropertyChanged(REFERENCED_COLUMN_NAME_PROPERTY, oldReferencedColumnName, newReferencedColumnName); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setReferencedColumnName(this.referencedColumnName(astRoot)); - } - - protected String referencedColumnName(CompilationUnit astRoot) { - return this.referencedColumnNameAdapter.getValue(astRoot); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.elementTouches(this.referencedColumnNameDeclarationAdapter, pos, astRoot); - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.referencedColumnNameDeclarationAdapter, astRoot); - } - - // ********** static methods ********** - - static PrimaryKeyJoinColumnImpl createPrimaryKeyJoinColumn(JavaResourceNode parent, Member member) { - return new PrimaryKeyJoinColumnImpl(parent, member, DECLARATION_ANNOTATION_ADAPTER); - } - - static PrimaryKeyJoinColumnImpl createNestedPrimaryKeyJoinColumn(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter pkJoinColumnsAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, pkJoinColumnsAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new PrimaryKeyJoinColumnImpl(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter pkJoinColumnsAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(pkJoinColumnsAdapter, index, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - - - static NestablePrimaryKeyJoinColumn createSecondaryTablePrimaryKeyJoinColumn(DeclarationAnnotationAdapter secondaryTableAdapter, JavaResourceNode parent, Member member, int index) { - return new PrimaryKeyJoinColumnImpl(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); - } - - public static class PrimaryKeyJoinColumnAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final PrimaryKeyJoinColumnAnnotationDefinition INSTANCE = new PrimaryKeyJoinColumnAnnotationDefinition(); - - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private PrimaryKeyJoinColumnAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return PrimaryKeyJoinColumnImpl.createPrimaryKeyJoinColumn(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnsImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnsImpl.java deleted file mode 100644 index 2fbcee6a4b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/PrimaryKeyJoinColumnsImpl.java +++ /dev/null @@ -1,156 +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.resource.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestablePrimaryKeyJoinColumn; -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; - -public class PrimaryKeyJoinColumnsImpl extends AbstractResourceAnnotation<Member> implements PrimaryKeyJoinColumnsAnnotation -{ - - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private List<NestablePrimaryKeyJoinColumn> pkJoinColumns; - - protected PrimaryKeyJoinColumnsImpl(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.pkJoinColumns = new ArrayList<NestablePrimaryKeyJoinColumn>(); - } - - public void initialize(CompilationUnit astRoot) { - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getNestableAnnotationName() { - return PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME; - } - - public String getElementName() { - return "value"; - } - - public ListIterator<NestablePrimaryKeyJoinColumn> nestedAnnotations() { - return new CloneListIterator<NestablePrimaryKeyJoinColumn>(this.pkJoinColumns); - } - - public int nestedAnnotationsSize() { - return this.pkJoinColumns.size(); - } - - public NestablePrimaryKeyJoinColumn addInternal(int index) { - NestablePrimaryKeyJoinColumn pkJoinColumn = createPrimaryKeyJoinColumn(index); - this.pkJoinColumns.add(index, pkJoinColumn); - return pkJoinColumn; - } - - public NestablePrimaryKeyJoinColumn add(int index) { - NestablePrimaryKeyJoinColumn pkJoinColumn = createPrimaryKeyJoinColumn(index); - add(index, pkJoinColumn); - return pkJoinColumn; - } - - protected void add(int index, NestablePrimaryKeyJoinColumn pkJoinColumn) { - addItemToList(index, pkJoinColumn, this.pkJoinColumns, PK_JOIN_COLUMNS_LIST); - } - - public void remove(NestablePrimaryKeyJoinColumn pkJoinColumn) { - removeItemFromList(pkJoinColumn, this.pkJoinColumns, PK_JOIN_COLUMNS_LIST); - } - - public void remove(int index) { - removeItemFromList(index, this.pkJoinColumns, PK_JOIN_COLUMNS_LIST); - } - - public int indexOf(NestablePrimaryKeyJoinColumn pkJoinColumn) { - return this.pkJoinColumns.indexOf(pkJoinColumn); - } - - public NestablePrimaryKeyJoinColumn nestedAnnotationAt(int index) { - return this.pkJoinColumns.get(index); - } - - public NestablePrimaryKeyJoinColumn nestedAnnotationFor(Annotation jdtAnnotation) { - for (NestablePrimaryKeyJoinColumn pkJoinColumn : this.pkJoinColumns) { - if (jdtAnnotation == pkJoinColumn.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return pkJoinColumn; - } - } - return null; - } - - public void move(int targetIndex, int sourceIndex) { - moveItemInList(targetIndex, sourceIndex, this.pkJoinColumns, PK_JOIN_COLUMNS_LIST); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.pkJoinColumns, targetIndex, sourceIndex); - } - - public void update(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this); - } - - private PrimaryKeyJoinColumnImpl createPrimaryKeyJoinColumn(int index) { - return PrimaryKeyJoinColumnImpl.createNestedPrimaryKeyJoinColumn(this, getMember(), index, getDeclarationAnnotationAdapter()); - } - - - public static class PrimaryKeyJoinColumnsAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final PrimaryKeyJoinColumnsAnnotationDefinition INSTANCE = new PrimaryKeyJoinColumnsAnnotationDefinition(); - - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private PrimaryKeyJoinColumnsAnnotationDefinition() { - super(); - } - - public PrimaryKeyJoinColumnsAnnotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new PrimaryKeyJoinColumnsImpl(parent, member); - } - - public PrimaryKeyJoinColumnsAnnotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/QueryHintImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/QueryHintImpl.java deleted file mode 100644 index ee8afbc629..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/QueryHintImpl.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.resource.java; - -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.NestableQueryHint; -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; - -public class QueryHintImpl extends AbstractResourceAnnotation<Type> - implements NestableQueryHint -{ - - // hold this so we can get the 'name' text range - private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; - - // hold this so we can get the 'value' text range - private final DeclarationAnnotationElementAdapter<String> valueDeclarationAdapter; - - private final AnnotationElementAdapter<String> nameAdapter; - - private final AnnotationElementAdapter<String> valueAdapter; - - private String name; - - private String value; - - public QueryHintImpl(JavaResourceNode parent, Type type, IndexedDeclarationAnnotationAdapter idaa) { - super(parent, type, idaa, new MemberIndexedAnnotationAdapter(type, idaa)); - this.nameDeclarationAdapter = this.nameAdapter(idaa); - this.nameAdapter = this.buildAdapter(this.nameDeclarationAdapter); - this.valueDeclarationAdapter = this.valueAdapter(idaa); - this.valueAdapter = this.buildAdapter(this.valueDeclarationAdapter); - } - - public void initialize(CompilationUnit astRoot) { - this.name = this.name(astRoot); - this.value = this.value(astRoot); - } - - // ********** initialization ********** - protected AnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new ShortCircuitAnnotationElementAdapter<String>(getMember(), daea); - } - - protected DeclarationAnnotationElementAdapter<String> nameAdapter(DeclarationAnnotationAdapter daa) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daa, JPA.QUERY_HINT__NAME); - } - - protected DeclarationAnnotationElementAdapter<String> valueAdapter(DeclarationAnnotationAdapter daa) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(daa, JPA.QUERY_HINT__VALUE); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public IndexedAnnotationAdapter getAnnotationAdapter() { - return (IndexedAnnotationAdapter) super.getAnnotationAdapter(); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - if (attributeValueHasNotChanged(this.name, newName)) { - return; - } - String oldName = this.name; - this.name = newName; - this.nameAdapter.setValue(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - if (attributeValueHasNotChanged(this.value, newValue)) { - return; - } - String oldValue = this.value; - this.value = newValue; - this.valueAdapter.setValue(newValue); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(this.valueDeclarationAdapter, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setName(this.name(astRoot)); - this.setValue(this.value(astRoot)); - } - - protected String name(CompilationUnit astRoot) { - return this.nameAdapter.getValue(astRoot); - } - - protected String value(CompilationUnit astRoot) { - return this.valueAdapter.getValue(astRoot); - } - - // ********** persistence model -> java annotations ********** - public void moveAnnotation(int newIndex) { - getAnnotationAdapter().moveAnnotation(newIndex); - } - - public void initializeFrom(NestableAnnotation oldAnnotation) { - QueryHintAnnotation oldQueryHint = (QueryHintAnnotation) oldAnnotation; - setName(oldQueryHint.getName()); - setValue(oldQueryHint.getValue()); - } - - // ********** static methods ********** - static QueryHintImpl createNamedQueryQueryHint(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter namedQueryAdapter, int index) { - return new QueryHintImpl(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 QueryHintImpl createNamedNativeQueryQueryHint(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter namedNativeQueryAdapter, int index) { - return new QueryHintImpl(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/SecondaryTableImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTableImpl.java deleted file mode 100644 index dc7da417d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTableImpl.java +++ /dev/null @@ -1,322 +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.resource.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.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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -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.resource.java.NestablePrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.NestableSecondaryTable; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraint; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -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.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.iterators.CloneListIterator; - -public class SecondaryTableImpl extends AbstractResourceTable implements NestableSecondaryTable -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(SecondaryTableAnnotation.ANNOTATION_NAME); - - private final List<NestablePrimaryKeyJoinColumn> pkJoinColumns; - - private final PkJoinColumnsContainerAnnotation pkJoinColumnsContainerAnnotation; - - - protected SecondaryTableImpl(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent, member, daa, annotationAdapter); - this.pkJoinColumns = new ArrayList<NestablePrimaryKeyJoinColumn>(); - this.pkJoinColumnsContainerAnnotation = new PkJoinColumnsContainerAnnotation(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this.pkJoinColumnsContainerAnnotation); - } - - @Override - protected DeclarationAnnotationElementAdapter<String> catalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.SECONDARY_TABLE__CATALOG); - } - - @Override - protected DeclarationAnnotationElementAdapter<String> nameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.SECONDARY_TABLE__NAME); - } - - @Override - protected DeclarationAnnotationElementAdapter<String> schemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(declarationAnnotationAdapter, JPA.SECONDARY_TABLE__SCHEMA); - } - - public IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) super.getAnnotationAdapter(); - } - - public String getAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - - public void moveAnnotation(int newIndex) { - getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - public void initializeFrom(NestableAnnotation oldAnnotation) { - SecondaryTableAnnotation oldSecondaryTable = (SecondaryTableAnnotation) oldAnnotation; - setName(oldSecondaryTable.getName()); - setCatalog(oldSecondaryTable.getCatalog()); - setSchema(oldSecondaryTable.getSchema()); - for (UniqueConstraintAnnotation uniqueConstraint : CollectionTools.iterable(oldSecondaryTable.uniqueConstraints())) { - NestableUniqueConstraint newUniqueConstraint = addUniqueConstraint(oldSecondaryTable.indexOfUniqueConstraint(uniqueConstraint)); - newUniqueConstraint.initializeFrom((NestableAnnotation) uniqueConstraint); - } - for (PrimaryKeyJoinColumnAnnotation pkJoinColumn : CollectionTools.iterable(oldSecondaryTable.pkJoinColumns())) { - NestablePrimaryKeyJoinColumn newPkJoinColumn = addPkJoinColumn(oldSecondaryTable.indexOfPkJoinColumn(pkJoinColumn)); - newPkJoinColumn.initializeFrom((NestableAnnotation) pkJoinColumn); - } - } - - @Override - protected NestableUniqueConstraint createUniqueConstraint(int index) { - return UniqueConstraintImpl.createSecondaryTableUniqueConstraint(this, this.getMember(), this.getDeclarationAnnotationAdapter(), index); - } - - // ************* SecondaryTable implementation ******************* - - - public ListIterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns() { - return new CloneListIterator<PrimaryKeyJoinColumnAnnotation>(this.pkJoinColumns); - } - - public int pkJoinColumnsSize() { - return this.pkJoinColumns.size(); - } - - public NestablePrimaryKeyJoinColumn pkJoinColumnAt(int index) { - return this.pkJoinColumns.get(index); - } - - public int indexOfPkJoinColumn(PrimaryKeyJoinColumnAnnotation joinColumn) { - return this.pkJoinColumns.indexOf(joinColumn); - } - - public NestablePrimaryKeyJoinColumn addPkJoinColumn(int index) { - NestablePrimaryKeyJoinColumn pkJoinColumn = (NestablePrimaryKeyJoinColumn) ContainerAnnotationTools.addNestedAnnotation(index, this.pkJoinColumnsContainerAnnotation); - fireItemAdded(SecondaryTableAnnotation.PK_JOIN_COLUMNS_LIST, index, pkJoinColumn); - return pkJoinColumn; - } - - protected void addPkJoinColumn(int index, NestablePrimaryKeyJoinColumn pkJoinColumn) { - addItemToList(index, pkJoinColumn, this.pkJoinColumns, PK_JOIN_COLUMNS_LIST); - } - - public void removePkJoinColumn(int index) { - NestablePrimaryKeyJoinColumn pkJoinColumn = this.pkJoinColumns.get(index); - removePkJoinColumn(pkJoinColumn); - pkJoinColumn.removeAnnotation(); - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, this.pkJoinColumnsContainerAnnotation); - } - - protected void removePkJoinColumn(NestablePrimaryKeyJoinColumn pkJoinColumn) { - removeItemFromList(pkJoinColumn, this.pkJoinColumns, SecondaryTableAnnotation.PK_JOIN_COLUMNS_LIST); - } - - public void movePkJoinColumn(int targetIndex, int sourceIndex) { - movePkJoinColumnInternal(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, this.pkJoinColumnsContainerAnnotation); - fireItemMoved(SecondaryTableAnnotation.PK_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected void movePkJoinColumnInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.pkJoinColumns, targetIndex, sourceIndex); - } - - - protected NestablePrimaryKeyJoinColumn createPrimaryKeyJoinColumn(int index) { - return PrimaryKeyJoinColumnImpl.createSecondaryTablePrimaryKeyJoinColumn(getDeclarationAnnotationAdapter(), this, getMember(), index); - } - - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.updatePkJoinColumnsFromJava(astRoot); - } - - private void updatePkJoinColumnsFromJava(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this.pkJoinColumnsContainerAnnotation); - } - - // ********** static methods ********** - static SecondaryTableImpl createSecondaryTable(JavaResourceNode parent, Member member) { - return new SecondaryTableImpl(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - static SecondaryTableImpl createNestedSecondaryTable(JavaResourceNode parent, Member member, int index, DeclarationAnnotationAdapter secondaryTablesAdapter) { - IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, secondaryTablesAdapter); - IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member, idaa); - return new SecondaryTableImpl(parent, member, idaa, annotationAdapter); - } - - private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter secondaryTablesAdapter) { - return new NestedIndexedDeclarationAnnotationAdapter(secondaryTablesAdapter, index, JPA.SECONDARY_TABLE); - } - - - private class PkJoinColumnsContainerAnnotation extends AbstractJavaResourceNode - implements ContainerAnnotation<NestablePrimaryKeyJoinColumn> - { - public PkJoinColumnsContainerAnnotation() { - super(SecondaryTableImpl.this); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public NestablePrimaryKeyJoinColumn addInternal(int index) { - NestablePrimaryKeyJoinColumn pKJoinColumn = SecondaryTableImpl.this.createPrimaryKeyJoinColumn(index); - SecondaryTableImpl.this.pkJoinColumns.add(index, pKJoinColumn); - return pKJoinColumn; - } - - public NestablePrimaryKeyJoinColumn add(int index) { - NestablePrimaryKeyJoinColumn pKJoinColumn = SecondaryTableImpl.this.createPrimaryKeyJoinColumn(index); - SecondaryTableImpl.this.addPkJoinColumn(index, pKJoinColumn); - return pKJoinColumn; - } - - public int indexOf(NestablePrimaryKeyJoinColumn pkJoinColumn) { - return SecondaryTableImpl.this.indexOfPkJoinColumn(pkJoinColumn); - } - - public void move(int targetIndex, int sourceIndex) { - SecondaryTableImpl.this.movePkJoinColumn(targetIndex, sourceIndex); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - SecondaryTableImpl.this.movePkJoinColumnInternal(targetIndex, sourceIndex); - } - - public NestablePrimaryKeyJoinColumn nestedAnnotationAt(int index) { - return SecondaryTableImpl.this.pkJoinColumnAt(index); - } - - public ListIterator<NestablePrimaryKeyJoinColumn> nestedAnnotations() { - return new CloneListIterator<NestablePrimaryKeyJoinColumn>(SecondaryTableImpl.this.pkJoinColumns); - } - - public int nestedAnnotationsSize() { - return pkJoinColumnsSize(); - } - - public String getAnnotationName() { - return SecondaryTableImpl.this.getAnnotationName(); - } - - public String getNestableAnnotationName() { - return JPA.PRIMARY_KEY_JOIN_COLUMN; - } - - public NestablePrimaryKeyJoinColumn nestedAnnotationFor(org.eclipse.jdt.core.dom.Annotation jdtAnnotation) { - for (NestablePrimaryKeyJoinColumn pkJoinColumn : CollectionTools.iterable(nestedAnnotations())) { - if (jdtAnnotation == pkJoinColumn.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return pkJoinColumn; - } - } - return null; - } - - public void remove(int index) { - this.remove(nestedAnnotationAt(index)); - } - - public void remove(NestablePrimaryKeyJoinColumn pkJoinColumn) { - SecondaryTableImpl.this.removePkJoinColumn(pkJoinColumn); - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return SecondaryTableImpl.this.getJdtAnnotation(astRoot); - } - - public void newAnnotation() { - SecondaryTableImpl.this.newAnnotation(); - } - - public void removeAnnotation() { - SecondaryTableImpl.this.removeAnnotation(); - } - - public void update(CompilationUnit astRoot) { - SecondaryTableImpl.this.update(astRoot); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return SecondaryTableImpl.this.getTextRange(astRoot); - } - - public String getElementName() { - return "pkJoinColumns"; - } - } - - public static class SecondaryTableAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final SecondaryTableAnnotationDefinition INSTANCE = new SecondaryTableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private SecondaryTableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return SecondaryTableImpl.createSecondaryTable(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTablesImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTablesImpl.java deleted file mode 100644 index 4fb30c832d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SecondaryTablesImpl.java +++ /dev/null @@ -1,160 +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.resource.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.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.NestableSecondaryTable; -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; - -public class SecondaryTablesImpl extends AbstractResourceAnnotation<Member> implements SecondaryTablesAnnotation -{ - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - private final List<NestableSecondaryTable> secondaryTables; - - protected SecondaryTablesImpl(JavaResourcePersistentType parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.secondaryTables = new ArrayList<NestableSecondaryTable>(); - } - - public void initialize(CompilationUnit astRoot) { - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public String getNestableAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - - public String getElementName() { - return "value"; - } - - public ListIterator<NestableSecondaryTable> nestedAnnotations() { - return new CloneListIterator<NestableSecondaryTable>(this.secondaryTables); - } - - public int nestedAnnotationsSize() { - return this.secondaryTables.size(); - } - - public NestableSecondaryTable addInternal(int index) { - NestableSecondaryTable secondaryTable = createSecondaryTable(index); - this.secondaryTables.add(index, secondaryTable); - return secondaryTable; - } - - public NestableSecondaryTable add(int index) { - NestableSecondaryTable secondaryTable = createSecondaryTable(index); - this.add(index, secondaryTable); - return secondaryTable; - } - - protected void add(int index, NestableSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.secondaryTables, SecondaryTablesAnnotation.SECONDARY_TABLES_LIST); - } - - public void remove(NestableSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.secondaryTables, SecondaryTablesAnnotation.SECONDARY_TABLES_LIST); - } - - public void remove(int index) { - removeItemFromList(index, this.secondaryTables, SecondaryTablesAnnotation.SECONDARY_TABLES_LIST); - } - - public int indexOf(NestableSecondaryTable secondaryTable) { - return this.secondaryTables.indexOf(secondaryTable); - } - - public NestableSecondaryTable nestedAnnotationAt(int index) { - return this.secondaryTables.get(index); - } - - public NestableSecondaryTable nestedAnnotationFor(org.eclipse.jdt.core.dom.Annotation jdtAnnotation) { - for (NestableSecondaryTable secondaryTable : this.secondaryTables) { - if (jdtAnnotation == secondaryTable.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return secondaryTable; - } - } - return null; - } - - public void move(int targetIndex, int sourceIndex) { - moveItemInList(targetIndex, sourceIndex, this.secondaryTables, SecondaryTablesAnnotation.SECONDARY_TABLES_LIST); - } - //TODO this move is different than how we handle SecondarTable.pkJoinColumns -// public void movePkJoinColumn(int oldIndex, int newIndex) { -// movePkJoinColumnInternal(oldIndex, newIndex); -// ContainerAnnotationTools.synchAnnotationsAfterMove(newIndex, oldIndex, this.pkJoinColumnsContainerAnnotation); -// fireItemMoved(SecondaryTable.PK_JOIN_COLUMNS_LIST, newIndex, oldIndex); -// } - - public void moveInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.secondaryTables, targetIndex, sourceIndex); - } - - public void update(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this); - } - - private SecondaryTableImpl createSecondaryTable(int index) { - return SecondaryTableImpl.createNestedSecondaryTable(this, getMember(), index, getDeclarationAnnotationAdapter()); - } - - public static class SecondaryTablesAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final SecondaryTablesAnnotationDefinition INSTANCE = new SecondaryTablesAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private SecondaryTablesAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SecondaryTablesImpl((JavaResourcePersistentType) parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SequenceGeneratorImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SequenceGeneratorImpl.java deleted file mode 100644 index 10e0808e29..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/SequenceGeneratorImpl.java +++ /dev/null @@ -1,150 +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.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -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; - -public class SequenceGeneratorImpl extends GeneratorImpl implements SequenceGeneratorAnnotation -{ - private final AnnotationElementAdapter<String> sequenceNameAdapter; - - 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 String sequenceName; - - protected SequenceGeneratorImpl(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER); - this.sequenceNameAdapter = this.buildAdapter(SEQUENCE_NAME_ADAPTER); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.sequenceName = this.sequenceName(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - //************ GeneratorImpl implementation ************** - - @Override - protected DeclarationAnnotationElementAdapter<Integer> allocationSizeAdapter() { - return ALLOCATION_SIZE_ADAPTER; - } - - @Override - protected DeclarationAnnotationAdapter annotationAdapter() { - return DECLARATION_ANNOTATION_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<Integer> initialValueAdapter() { - return INITIAL_VALUE_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> nameAdapter() { - return NAME_ADAPTER; - } - - - public String getSequenceName() { - return this.sequenceName; - } - - public void setSequenceName(String newSequenceName) { - if (attributeValueHasNotChanged(this.sequenceName, newSequenceName)) { - return; - } - String oldSequenceName = this.sequenceName; - this.sequenceName = newSequenceName; - this.sequenceNameAdapter.setValue(newSequenceName); - firePropertyChanged(SEQUENCE_NAME_PROPERTY, oldSequenceName, newSequenceName); - } - - public TextRange getSequenceNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(SEQUENCE_NAME_ADAPTER, astRoot); - } - - // ********** java annotations -> persistence model ********** - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setSequenceName(this.sequenceName(astRoot)); - } - - protected String sequenceName(CompilationUnit astRoot) { - return this.sequenceNameAdapter.getValue(astRoot); - } - - // ********** 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); - } - - public static class SequenceGeneratorAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final SequenceGeneratorAnnotationDefinition INSTANCE = new SequenceGeneratorAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private SequenceGeneratorAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new SequenceGeneratorImpl(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableGeneratorImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableGeneratorImpl.java deleted file mode 100644 index f6aa40e628..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableGeneratorImpl.java +++ /dev/null @@ -1,483 +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.resource.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.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.ContainerAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraint; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -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.Member; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class TableGeneratorImpl extends GeneratorImpl implements TableGeneratorAnnotation -{ - private final AnnotationElementAdapter<String> tableAdapter; - - private final AnnotationElementAdapter<String> catalogAdapter; - - private final AnnotationElementAdapter<String> schemaAdapter; - - private final AnnotationElementAdapter<String> pkColumnNameAdapter; - - private final AnnotationElementAdapter<String> valueColumnNameAdapter; - - private final AnnotationElementAdapter<String> pkColumnValueAdapter; - - 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 static final DeclarationAnnotationElementAdapter<String> CATALOG_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__CATALOG); - - private static final DeclarationAnnotationElementAdapter<String> SCHEMA_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__SCHEMA); - - private static final DeclarationAnnotationElementAdapter<String> PK_COLUMN_NAME_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__PK_COLUMN_NAME); - - private static final DeclarationAnnotationElementAdapter<String> VALUE_COLUMN_NAME_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__VALUE_COLUMN_NAME); - - private static final DeclarationAnnotationElementAdapter<String> PK_COLUMN_VALUE_ADAPTER = buildAdapter(JPA.TABLE_GENERATOR__PK_COLUMN_VALUE); - - private String table; - - private String catalog; - - private String schema; - - private String pkColumnName; - - private String valueColumnName; - - private String pkColumnValue; - - private final List<NestableUniqueConstraint> uniqueConstraints; - - private final UniqueConstraintsContainerAnnotation uniqueConstraintsContainerAnnotation; - - - protected TableGeneratorImpl(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); - this.uniqueConstraints = new ArrayList<NestableUniqueConstraint>(); - this.uniqueConstraintsContainerAnnotation = new UniqueConstraintsContainerAnnotation(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.table = this.table(astRoot); - this.catalog = this.catalog(astRoot); - this.schema = this.schema(astRoot); - this.pkColumnName = this.pkColumnName(astRoot); - this.valueColumnName = this.valueColumnName(astRoot); - this.pkColumnValue = this.pkColumnValue(astRoot); - ContainerAnnotationTools.initializeNestedAnnotations(astRoot, this.uniqueConstraintsContainerAnnotation); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - - //************ GeneratorImpl implementation ************** - - @Override - protected DeclarationAnnotationElementAdapter<Integer> allocationSizeAdapter() { - return ALLOCATION_SIZE_ADAPTER; - } - - @Override - protected DeclarationAnnotationAdapter annotationAdapter() { - return DECLARATION_ANNOTATION_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<Integer> initialValueAdapter() { - return INITIAL_VALUE_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> nameAdapter() { - return NAME_ADAPTER; - } - - public String getTable() { - return this.table; - } - - public void setTable(String newTable) { - if (attributeValueHasNotChanged(this.table, newTable)) { - return; - } - String oldTable = this.table; - this.table = newTable; - this.tableAdapter.setValue(newTable); - firePropertyChanged(TABLE_PROPERTY, oldTable, newTable); - } - - public String getCatalog() { - return this.catalog; - } - - public void setCatalog(String newCatalog) { - if (attributeValueHasNotChanged(this.catalog, newCatalog)) { - return; - } - String oldCatalog = this.catalog; - this.catalog = newCatalog; - this.catalogAdapter.setValue(newCatalog); - firePropertyChanged(CATALOG_PROPERTY, oldCatalog, newCatalog); - } - - public String getSchema() { - return this.schema; - } - - public void setSchema(String newSchema) { - if (attributeValueHasNotChanged(this.schema, newSchema)) { - return; - } - String oldSchema = this.schema; - this.schema = newSchema; - this.schemaAdapter.setValue(newSchema); - firePropertyChanged(SCHEMA_PROPERTY, oldSchema, newSchema); - } - - public String getPkColumnName() { - return this.pkColumnName; - } - - public void setPkColumnName(String newPkColumnName) { - if (attributeValueHasNotChanged(this.pkColumnName, newPkColumnName)) { - return; - } - String oldPkColumnName = this.pkColumnName; - this.pkColumnName = newPkColumnName; - this.pkColumnNameAdapter.setValue(newPkColumnName); - firePropertyChanged(PK_COLUMN_NAME_PROPERTY, oldPkColumnName, newPkColumnName); - } - - public String getValueColumnName() { - return this.valueColumnName; - } - - public void setValueColumnName(String newValueColumnName) { - if (attributeValueHasNotChanged(this.valueColumnName, newValueColumnName)) { - return; - } - String oldValueColumnName = this.valueColumnName; - this.valueColumnName = newValueColumnName; - this.valueColumnNameAdapter.setValue(newValueColumnName); - firePropertyChanged(VALUE_COLUMN_NAME_PROPERTY, oldValueColumnName, newValueColumnName); - } - - public String getPkColumnValue() { - return this.pkColumnValue; - } - - public void setPkColumnValue(String newPkColumnValue) { - if (attributeValueHasNotChanged(this.pkColumnValue, newPkColumnValue)) { - return; - } - String oldPkColumnValue = this.pkColumnValue; - this.pkColumnValue = newPkColumnValue; - this.pkColumnValueAdapter.setValue(newPkColumnValue); - firePropertyChanged(PK_COLUMN_VALUE_PROPERTY, oldPkColumnValue, newPkColumnValue); - } - - public ListIterator<UniqueConstraintAnnotation> uniqueConstraints() { - return new CloneListIterator<UniqueConstraintAnnotation>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public NestableUniqueConstraint uniqueConstraintAt(int index) { - return this.uniqueConstraints.get(index); - } - - public int indexOfUniqueConstraint(UniqueConstraintAnnotation uniqueConstraint) { - return this.uniqueConstraints.indexOf(uniqueConstraint); - } - - public NestableUniqueConstraint addUniqueConstraint(int index) { - NestableUniqueConstraint uniqueConstraint = (NestableUniqueConstraint) ContainerAnnotationTools.addNestedAnnotation(index, this.uniqueConstraintsContainerAnnotation); - fireItemAdded(TableGeneratorAnnotation.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - private void addUniqueConstraint(int index, NestableUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - public void removeUniqueConstraint(int index) { - NestableUniqueConstraint uniqueConstraint = this.uniqueConstraints.get(index); - removeUniqueConstraint(uniqueConstraint); - uniqueConstraint.removeAnnotation(); - synchUniqueConstraintAnnotationsAfterRemove(index); - } - - protected void removeUniqueConstraint(NestableUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - moveUniqueConstraintInternal(targetIndex, sourceIndex); - ContainerAnnotationTools.synchAnnotationsAfterMove(targetIndex, sourceIndex, this.uniqueConstraintsContainerAnnotation); - fireItemMoved(TableAnnotation.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void moveUniqueConstraintInternal(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - } - - /** - * synchronize the annotations with the model join columns, - * starting at the specified index to prevent overlap - */ - private void synchUniqueConstraintAnnotationsAfterRemove(int index) { - ContainerAnnotationTools.synchAnnotationsAfterRemove(index, this.uniqueConstraintsContainerAnnotation); - } - - protected NestableUniqueConstraint createUniqueConstraint(int index) { - return UniqueConstraintImpl.createTableGeneratorUniqueConstraint(this, this.getMember(), index); - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(TABLE_ADAPTER, astRoot); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(CATALOG_ADAPTER, astRoot); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(SCHEMA_ADAPTER, astRoot); - } - - public TextRange getPkColumnNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(PK_COLUMN_NAME_ADAPTER, astRoot); - } - - public TextRange getPkColumnValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(PK_COLUMN_VALUE_ADAPTER, astRoot); - } - - public TextRange getValueColumnNameTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_COLUMN_NAME_ADAPTER, astRoot); - } - - // ********** java annotations -> persistence model ********** - @Override - public void update(CompilationUnit astRoot) { - super.update(astRoot); - this.setTable(this.table(astRoot)); - this.setCatalog(this.catalog(astRoot)); - this.setSchema(this.schema(astRoot)); - this.setPkColumnName(this.pkColumnName(astRoot)); - this.setValueColumnName(this.valueColumnName(astRoot)); - this.setPkColumnValue(this.pkColumnValue(astRoot)); - this.updateUniqueConstraintsFromJava(astRoot); - } - - protected String table(CompilationUnit astRoot) { - return this.tableAdapter.getValue(astRoot); - } - protected String catalog(CompilationUnit astRoot) { - return this.catalogAdapter.getValue(astRoot); - } - protected String schema(CompilationUnit astRoot) { - return this.schemaAdapter.getValue(astRoot); - } - protected String pkColumnName(CompilationUnit astRoot) { - return this.pkColumnNameAdapter.getValue(astRoot); - } - protected String valueColumnName(CompilationUnit astRoot) { - return this.valueColumnNameAdapter.getValue(astRoot); - } - protected String pkColumnValue(CompilationUnit astRoot) { - return this.pkColumnValueAdapter.getValue(astRoot); - } - - /** - * here we just worry about getting the unique constraints lists the same size; - * then we delegate to the unique constraints to synch themselves up - */ - private void updateUniqueConstraintsFromJava(CompilationUnit astRoot) { - ContainerAnnotationTools.updateNestedAnnotationsFromJava(astRoot, this.uniqueConstraintsContainerAnnotation); - } - - // ********** 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); - } - - - private class UniqueConstraintsContainerAnnotation extends AbstractJavaResourceNode - implements ContainerAnnotation<NestableUniqueConstraint> - { - public UniqueConstraintsContainerAnnotation() { - super(TableGeneratorImpl.this); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public NestableUniqueConstraint addInternal(int index) { - NestableUniqueConstraint uniqueConstraint = TableGeneratorImpl.this.createUniqueConstraint(index); - TableGeneratorImpl.this.uniqueConstraints.add(index, uniqueConstraint); - return uniqueConstraint; - } - - public NestableUniqueConstraint add(int index) { - NestableUniqueConstraint uniqueConstraint = TableGeneratorImpl.this.createUniqueConstraint(index); - TableGeneratorImpl.this.addUniqueConstraint(index, uniqueConstraint); - return uniqueConstraint; - } - - public String getAnnotationName() { - return TableGeneratorImpl.this.getAnnotationName(); - } - - public String getNestableAnnotationName() { - return JPA.UNIQUE_CONSTRAINT; - } - - public int indexOf(NestableUniqueConstraint uniqueConstraint) { - return TableGeneratorImpl.this.indexOfUniqueConstraint(uniqueConstraint); - } - - public void move(int targetIndex, int sourceIndex) { - TableGeneratorImpl.this.moveUniqueConstraint(targetIndex, sourceIndex); - } - - public void moveInternal(int targetIndex, int sourceIndex) { - TableGeneratorImpl.this.moveUniqueConstraintInternal(targetIndex, sourceIndex); - } - - public NestableUniqueConstraint nestedAnnotationAt(int index) { - return TableGeneratorImpl.this.uniqueConstraintAt(index); - } - - public NestableUniqueConstraint nestedAnnotationFor(org.eclipse.jdt.core.dom.Annotation jdtAnnotation) { - for (NestableUniqueConstraint uniqueConstraint : CollectionTools.iterable(nestedAnnotations())) { - if (jdtAnnotation == uniqueConstraint.getJdtAnnotation((CompilationUnit) jdtAnnotation.getRoot())) { - return uniqueConstraint; - } - } - return null; - } - - public ListIterator<NestableUniqueConstraint> nestedAnnotations() { - return new CloneListIterator<NestableUniqueConstraint>(TableGeneratorImpl.this.uniqueConstraints); - } - - public int nestedAnnotationsSize() { - return TableGeneratorImpl.this.uniqueConstraints.size(); - } - - public void remove(NestableUniqueConstraint uniqueConstraint) { - TableGeneratorImpl.this.removeUniqueConstraint(uniqueConstraint); - } - - public void remove(int index) { - this.remove(nestedAnnotationAt(index)); - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return TableGeneratorImpl.this.getJdtAnnotation(astRoot); - } - - public void newAnnotation() { - TableGeneratorImpl.this.newAnnotation(); - } - - public void removeAnnotation() { - TableGeneratorImpl.this.removeAnnotation(); - } - - public void update(CompilationUnit astRoot) { - TableGeneratorImpl.this.update(astRoot); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return TableGeneratorImpl.this.getTextRange(astRoot); - } - - public String getElementName() { - return "uniqueConstraints"; - } - } - - public static class TableGeneratorAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final TableGeneratorAnnotationDefinition INSTANCE = new TableGeneratorAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private TableGeneratorAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new TableGeneratorImpl(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableImpl.java deleted file mode 100644 index b7a7d57a5e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TableImpl.java +++ /dev/null @@ -1,99 +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.resource.java; - -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.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.NestableUniqueConstraint; -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; - -public class TableImpl extends AbstractResourceTable -{ - 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); - - protected TableImpl(JavaResourceNode parent, Member member) { - super(parent, member, DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member, DECLARATION_ANNOTATION_ADAPTER)); - } - - public String getAnnotationName() { - return TableAnnotation.ANNOTATION_NAME; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> nameAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @Table is never nested - return NAME_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> schemaAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @Table is never nested - return SCHEMA_ADAPTER; - } - - @Override - protected DeclarationAnnotationElementAdapter<String> catalogAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter) { - // ignore the daa passed in, @Table is never nested - return CATALOG_ADAPTER; - } - - @Override - protected NestableUniqueConstraint createUniqueConstraint(int index) { - return UniqueConstraintImpl.createTableUniqueConstraint(this, this.getMember(), index); - } - - public static class TableAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final TableAnnotationDefinition INSTANCE = new TableAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private TableAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new TableImpl(parent, member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullTable(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TemporalImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TemporalImpl.java deleted file mode 100644 index 0b9db97d51..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TemporalImpl.java +++ /dev/null @@ -1,116 +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.resource.java; - -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.Annotation; -import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -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; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class TemporalImpl extends AbstractResourceAnnotation<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; - - protected TemporalImpl(JavaResourceNode parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, VALUE_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - this.value = this.value(astRoot); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public TemporalType getValue() { - return this.value; - } - - public void setValue(TemporalType newValue) { - if (attributeValueHasNotChanged(this.value, newValue)) { - return; - } - TemporalType oldValue = this.value; - this.value = newValue; - this.valueAdapter.setValue(TemporalType.toJavaAnnotationValue(newValue)); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - public TextRange getValueTextRange(CompilationUnit astRoot) { - return this.getElementTextRange(VALUE_ADAPTER, astRoot); - } - - public void update(CompilationUnit astRoot) { - this.setValue(this.value(astRoot)); - } - - protected TemporalType value(CompilationUnit astRoot) { - return TemporalType.fromJavaAnnotationValue(this.valueAdapter.getValue(astRoot)); - } - - // ********** static methods ********** - private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { - return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JPA.TEMPORAL__VALUE); - } - - public static class TemporalAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final TemporalAnnotationDefinition INSTANCE = new TemporalAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static AnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private TemporalAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new TemporalImpl(parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return new NullTemporal(parent); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TransientImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TransientImpl.java deleted file mode 100644 index 7fa56b9349..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/TransientImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class TransientImpl extends AbstractResourceAnnotation<Attribute> implements TransientAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - protected TransientImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void update(CompilationUnit astRoot) { - //no annotation members - } - - public static class TransientAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final TransientAnnotationDefinition INSTANCE = new TransientAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static TransientAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private TransientAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new TransientImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/UniqueConstraintImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/UniqueConstraintImpl.java deleted file mode 100644 index fd5b604362..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/UniqueConstraintImpl.java +++ /dev/null @@ -1,184 +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.resource.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.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.NestedIndexedDeclarationAnnotationAdapter; -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.NestableUniqueConstraint; -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; - -public class UniqueConstraintImpl extends AbstractResourceAnnotation<Member> implements NestableUniqueConstraint -{ - - public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.UNIQUE_CONSTRAINT); - - private final DeclarationAnnotationElementAdapter<String[]> columnNamesDeclarationAdapter; - - private final AnnotationElementAdapter<String[]> columnNamesAdapter; - - private final List<String> columnNames; - - - public UniqueConstraintImpl(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); - this.columnNames = new ArrayList<String>(); - } - - public void initialize(CompilationUnit astRoot) { - String[] javaColumnNames = this.columnNamesAdapter.getValue(astRoot); - for (int i = 0; i < javaColumnNames.length; i++) { - this.columnNames.add(javaColumnNames[i]); - } - } - - protected AnnotationElementAdapter<String[]> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String[]> daea) { - return new ShortCircuitArrayAnnotationElementAdapter<String>(getMember(), daea); - } - - protected static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { - return buildArrayAnnotationElementAdapter(annotationAdapter, elementName, AnnotationStringArrayExpressionConverter.forStrings()); - } - - protected static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String[]> converter) { - return new ConversionDeclarationAnnotationElementAdapter<String[]>(annotationAdapter, elementName, false, converter); - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - @Override - public IndexedAnnotationAdapter getAnnotationAdapter() { - return (IndexedAnnotationAdapter) super.getAnnotationAdapter(); - } - - public void initializeFrom(NestableAnnotation oldAnnotation) { - UniqueConstraintAnnotation oldUniqueConstraint = (UniqueConstraintAnnotation) oldAnnotation; - for (String columnName : CollectionTools.iterable(oldUniqueConstraint.columnNames())) { - addColumnName(columnNamesSize(), columnName); - } - } - - public ListIterator<String> columnNames() { - return new CloneListIterator<String>(this.columnNames); - } - - public int columnNamesSize() { - return this.columnNames.size(); - } - - public void addColumnName(String columnName) { - addColumnName(columnNamesSize(), columnName); - } - - public void addColumnName(int index, String columnName) { - addColumnName_(index, columnName); - this.columnNamesAdapter.setValue(this.columnNames.toArray(new String[this.columnNames.size()])); - } - - protected void addColumnName_(int index, String columnName) { - addItemToList(index, columnName, this.columnNames, COLUMN_NAMES_LIST); - } - - public void removeColumnName(String columnName) { - removeItemFromList(columnName, this.columnNames, COLUMN_NAMES_LIST); - this.columnNamesAdapter.setValue(this.columnNames.toArray(new String[this.columnNames.size()])); - } - - public void removeColumnName(int index) { - removeItemFromList(index, this.columnNames, COLUMN_NAMES_LIST); - this.columnNamesAdapter.setValue(this.columnNames.toArray(new String[this.columnNames.size()])); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - 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 update(CompilationUnit astRoot) { - this.updateColumnNamesFromJava(astRoot); - } - - protected void updateColumnNamesFromJava(CompilationUnit astRoot) { - String[] javaColumnNames = this.columnNamesAdapter.getValue(astRoot); - //TODO hmm, seems we need change notification for this - CollectionTools.retainAll(this.columnNames, javaColumnNames); - for (int i = 0; i < javaColumnNames.length; i++) { - String columnName = javaColumnNames[i]; - if (!this.columnNames.contains(columnName)) { - addColumnName_(columnNamesSize(), columnName); - } - } - } - - // ********** persistence model -> java annotations ********** - public void moveAnnotation(int newIndex) { - getAnnotationAdapter().moveAnnotation(newIndex); - } - - // ********** static methods ********** - static NestableUniqueConstraint createSecondaryTableUniqueConstraint(JavaResourceNode parent, Member member, DeclarationAnnotationAdapter declarationAnnotationAdapter, int index) { - return new UniqueConstraintImpl(parent, member, buildSecondaryTableUniqueConstraintAnnotationAdapter(declarationAnnotationAdapter, index)); - } - - private static IndexedDeclarationAnnotationAdapter buildSecondaryTableUniqueConstraintAnnotationAdapter(DeclarationAnnotationAdapter declarationAnnotationAdapter, int index) { - return new NestedIndexedDeclarationAnnotationAdapter(declarationAnnotationAdapter, JPA.SECONDARY_TABLE__UNIQUE_CONSTRAINTS, index, JPA.UNIQUE_CONSTRAINT); - } - - static NestableUniqueConstraint createJoinTableUniqueConstraint(JavaResourceNode parent, Member member, int index) { - return new UniqueConstraintImpl(parent, member, buildJoinTableUniqueConstraintAnnotationAdapter(index)); - } - - private static IndexedDeclarationAnnotationAdapter buildJoinTableUniqueConstraintAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(JoinTableImpl.DECLARATION_ANNOTATION_ADAPTER, JPA.JOIN_TABLE__UNIQUE_CONSTRAINTS, index, JPA.UNIQUE_CONSTRAINT); - } - - static NestableUniqueConstraint createTableUniqueConstraint(JavaResourceNode parent, Member member, int index) { - return new UniqueConstraintImpl(parent, member, buildTableUniqueConstraintAnnotationAdapter(index)); - } - - private static IndexedDeclarationAnnotationAdapter buildTableUniqueConstraintAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(TableImpl.DECLARATION_ANNOTATION_ADAPTER, JPA.TABLE__UNIQUE_CONSTRAINTS, index, JPA.UNIQUE_CONSTRAINT); - } - - static NestableUniqueConstraint createTableGeneratorUniqueConstraint(JavaResourceNode parent, Member member, int index) { - return new UniqueConstraintImpl(parent, member, buildTableGeneratorUniqueConstraintAnnotationAdapter(index)); - } - - private static IndexedDeclarationAnnotationAdapter buildTableGeneratorUniqueConstraintAnnotationAdapter(int index) { - return new NestedIndexedDeclarationAnnotationAdapter(TableGeneratorImpl.DECLARATION_ANNOTATION_ADAPTER, JPA.TABLE_GENERATOR__UNIQUE_CONSTRAINTS, index, JPA.UNIQUE_CONSTRAINT); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/VersionImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/VersionImpl.java deleted file mode 100644 index fad1135cd3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/VersionImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -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.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; - -public class VersionImpl extends AbstractResourceAnnotation<Attribute> implements VersionAnnotation -{ - private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); - - public VersionImpl(JavaResourcePersistentAttribute parent, Attribute attribute) { - super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER); - } - - public void initialize(CompilationUnit astRoot) { - //nothing to initialize - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - - public void update(CompilationUnit astRoot) { - //no annotation members - } - - public static class VersionAnnotationDefinition implements AnnotationDefinition - { - // singleton - private static final VersionAnnotationDefinition INSTANCE = new VersionAnnotationDefinition(); - - /** - * Return the singleton. - */ - public static VersionAnnotationDefinition instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private VersionAnnotationDefinition() { - super(); - } - - public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { - return new VersionImpl((JavaResourcePersistentAttribute) parent, (Attribute) member); - } - - public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) { - return null; - } - - public String getAnnotationName() { - return ANNOTATION_NAME; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AssociationOverrideTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AssociationOverrideTranslator.java deleted file mode 100644 index 13fd060358..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AssociationOverrideTranslator.java +++ /dev/null @@ -1,53 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class AssociationOverrideTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public AssociationOverrideTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createJoinColumnTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAssociationOverride_Name(), DOM_ATTRIBUTE); - } - - private Translator createJoinColumnTranslator() { - return new JoinColumnTranslator(JOIN_COLUMN, ORM_PKG.getXmlAssociationOverride_JoinColumns()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AttributeOverrideTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AttributeOverrideTranslator.java deleted file mode 100644 index 4edfc341c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AttributeOverrideTranslator.java +++ /dev/null @@ -1,53 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class AttributeOverrideTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public AttributeOverrideTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createColumnTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeOverride_Name(), DOM_ATTRIBUTE); - } - - private Translator createColumnTranslator() { - return new ColumnTranslator(COLUMN, ORM_PKG.getXmlAttributeOverride_Column()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AttributesTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AttributesTranslator.java deleted file mode 100644 index 0b78832ee0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/AttributesTranslator.java +++ /dev/null @@ -1,88 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class AttributesTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public AttributesTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createIdTranslator(), - createEmbeddedIdTranslator(), - createBasicTranslator(), - createVersionTranslator(), - createManyToOneTranslator(), - createOneToManyTranslator(), - createOneToOneTranslator(), - createManyToManyTranslator(), - createEmbeddedTranslator(), - createTransientTranslator() - }; - } - - private Translator createIdTranslator() { - return new IdTranslator(ID, ORM_PKG.getAttributes_Ids()); - } - - private Translator createEmbeddedIdTranslator() { - return new EmbeddedIdTranslator(EMBEDDED_ID, ORM_PKG.getAttributes_EmbeddedIds()); - } - - private Translator createBasicTranslator() { - return new BasicTranslator(BASIC, ORM_PKG.getAttributes_Basics()); - } - - private Translator createVersionTranslator() { - return new VersionTranslator(VERSION, ORM_PKG.getAttributes_Versions()); - } - - private Translator createManyToOneTranslator() { - return new ManyToOneTranslator(MANY_TO_ONE, ORM_PKG.getAttributes_ManyToOnes()); - } - - private Translator createOneToManyTranslator() { - return new OneToManyTranslator(ONE_TO_MANY, ORM_PKG.getAttributes_OneToManys()); - } - - private Translator createOneToOneTranslator() { - return new OneToOneTranslator(ONE_TO_ONE, ORM_PKG.getAttributes_OneToOnes()); - } - - private Translator createManyToManyTranslator() { - return new ManyToManyTranslator(MANY_TO_MANY, ORM_PKG.getAttributes_ManyToManys()); - } - - private Translator createEmbeddedTranslator() { - return new EmbeddedTranslator(EMBEDDED, ORM_PKG.getAttributes_Embeddeds()); - } - - private Translator createTransientTranslator() { - return new TransientTranslator(TRANSIENT, ORM_PKG.getAttributes_Transients()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/BasicTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/BasicTranslator.java deleted file mode 100644 index 556c5ccc7f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/BasicTranslator.java +++ /dev/null @@ -1,79 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.internal.resource.common.translators.BooleanTranslator; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class BasicTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public BasicTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlBasicImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createFetchTranslator(), - createOptionalTranslator(), - createColumnTranslator(), - createLobTranslator(), - createTemporalTranslator(), - createEnumeratedTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createFetchTranslator() { - return new Translator(FETCH, ORM_PKG.getXmlBasic_Fetch(), DOM_ATTRIBUTE); - } - - private Translator createOptionalTranslator() { - return new BooleanTranslator(OPTIONAL, ORM_PKG.getXmlBasic_Optional(), DOM_ATTRIBUTE); - } - - private Translator createColumnTranslator() { - return new ColumnTranslator(COLUMN, ORM_PKG.getColumnMapping_Column()); - } - - private Translator createLobTranslator() { - return new EmptyTagBooleanTranslator(LOB, ORM_PKG.getXmlBasic_Lob()); - } - - private Translator createTemporalTranslator() { - return new Translator(TEMPORAL, ORM_PKG.getXmlBasic_Temporal()); - } - - private Translator createEnumeratedTranslator() { - return new Translator(ENUMERATED, ORM_PKG.getXmlBasic_Enumerated()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/CascadeTypeTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/CascadeTypeTranslator.java deleted file mode 100644 index d66f4a515c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/CascadeTypeTranslator.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class CascadeTypeTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public CascadeTypeTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createCascadeTypeImpl(); - } - - protected Translator[] createChildren() { - return new Translator[] { - createCascadeAllTranslator(), - createCascadePersistTranslator(), - createCascadeMergeTranslator(), - createCascadeRemoveTranslator(), - createCascadeRefreshTranslator() - }; - } - - private Translator createCascadeAllTranslator() { - return new EmptyTagBooleanTranslator(CASCADE_ALL, ORM_PKG.getCascadeType_CascadeAll()); - } - - private Translator createCascadePersistTranslator() { - return new EmptyTagBooleanTranslator(CASCADE_PERSIST, ORM_PKG.getCascadeType_CascadePersist()); - } - - private Translator createCascadeMergeTranslator() { - return new EmptyTagBooleanTranslator(CASCADE_MERGE, ORM_PKG.getCascadeType_CascadeMerge()); - } - - private Translator createCascadeRemoveTranslator() { - return new EmptyTagBooleanTranslator(CASCADE_REMOVE, ORM_PKG.getCascadeType_CascadeRemove()); - } - - private Translator createCascadeRefreshTranslator() { - return new EmptyTagBooleanTranslator(CASCADE_REFRESH, ORM_PKG.getCascadeType_CascadeRefresh()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ColumnResultTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ColumnResultTranslator.java deleted file mode 100644 index e59c405adb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ColumnResultTranslator.java +++ /dev/null @@ -1,43 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class ColumnResultTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public ColumnResultTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getColumnResult_Name(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ColumnTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ColumnTranslator.java deleted file mode 100644 index 03941953bb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ColumnTranslator.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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.internal.resource.common.translators.BooleanTranslator; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class ColumnTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public ColumnTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlColumnImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createUniqueTranslator(), - createNullableTranslator(), - createInsertableTranslator(), - createUpdatableTranslator(), - createColumnDefinitionTranslator(), - createTableTranslator(), - createLengthTranslator(), - createPrecisionTranslator(), - createScaleTranslator(), - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlNamedColumn_Name(), DOM_ATTRIBUTE); - } - - private Translator createUniqueTranslator() { - return new BooleanTranslator(UNIQUE, ORM_PKG.getXmlAbstractColumn_Unique(), DOM_ATTRIBUTE); - } - - private Translator createNullableTranslator() { - return new BooleanTranslator(NULLABLE, ORM_PKG.getXmlAbstractColumn_Nullable(), DOM_ATTRIBUTE); - } - - private Translator createInsertableTranslator() { - return new BooleanTranslator(INSERTABLE, ORM_PKG.getXmlAbstractColumn_Insertable(), DOM_ATTRIBUTE); - } - - private Translator createUpdatableTranslator() { - return new BooleanTranslator(UPDATABLE, ORM_PKG.getXmlAbstractColumn_Updatable(), DOM_ATTRIBUTE); - } - - private Translator createColumnDefinitionTranslator() { - return new Translator(COLUMN_DEFINITION, ORM_PKG.getXmlNamedColumn_ColumnDefinition(), DOM_ATTRIBUTE); - } - - private Translator createTableTranslator() { - return new Translator(TABLE, ORM_PKG.getXmlAbstractColumn_Table(), DOM_ATTRIBUTE); - } - - private Translator createLengthTranslator() { - return new Translator(LENGTH, ORM_PKG.getXmlColumn_Length(), DOM_ATTRIBUTE); - } - - private Translator createPrecisionTranslator() { - return new Translator(PRECISION, ORM_PKG.getXmlColumn_Precision(), DOM_ATTRIBUTE); - } - - private Translator createScaleTranslator() { - return new Translator(SCALE, ORM_PKG.getXmlColumn_Scale(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/DiscriminatorColumnTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/DiscriminatorColumnTranslator.java deleted file mode 100644 index 1566293eb8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/DiscriminatorColumnTranslator.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class DiscriminatorColumnTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public DiscriminatorColumnTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createDiscrminiatorTypeTranslator(), - createColumnDefinitionTranslator(), - createLengthTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlNamedColumn_Name(), DOM_ATTRIBUTE); - } - - protected Translator createDiscrminiatorTypeTranslator() { - return new Translator(DISCRIMINATOR_TYPE, ORM_PKG.getXmlDiscriminatorColumn_DiscriminatorType(), DOM_ATTRIBUTE); - } - - private Translator createColumnDefinitionTranslator() { - return new Translator(COLUMN_DEFINITION, ORM_PKG.getXmlNamedColumn_ColumnDefinition(), DOM_ATTRIBUTE); - } - - protected Translator createLengthTranslator() { - return new Translator(LENGTH, ORM_PKG.getXmlDiscriminatorColumn_Length(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddableTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddableTranslator.java deleted file mode 100644 index 881359acd2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddableTranslator.java +++ /dev/null @@ -1,61 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EmbeddableTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EmbeddableTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createClassTranslator(), - createAccessTranslator(), - createMetadataCompleteTranslator(), - createDescriptionTranslator(), - createAttributesTranslator() - }; - } - - private Translator createClassTranslator() { - return new Translator(CLASS, ORM_PKG.getAbstractXmlTypeMapping_ClassName(), DOM_ATTRIBUTE); - } - - private Translator createAccessTranslator() { - return new Translator(ACCESS, ORM_PKG.getAbstractXmlTypeMapping_Access(), DOM_ATTRIBUTE); - } - - private Translator createMetadataCompleteTranslator() { - return new Translator(METADATA_COMPLETE, ORM_PKG.getAbstractXmlTypeMapping_MetadataComplete(), DOM_ATTRIBUTE); - } - - private Translator createDescriptionTranslator() { - return new Translator(DESCRIPTION, ORM_PKG.getAbstractXmlTypeMapping_Description()); - } - - private Translator createAttributesTranslator() { - return new AttributesTranslator(ATTRIBUTES, ORM_PKG.getAbstractXmlTypeMapping_Attributes()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddedIdTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddedIdTranslator.java deleted file mode 100644 index 48c1e2fdab..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddedIdTranslator.java +++ /dev/null @@ -1,54 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EmbeddedIdTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EmbeddedIdTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlEmbeddedIdImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createAttributeOverrideTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createAttributeOverrideTranslator() { - return new AttributeOverrideTranslator(ATTRIBUTE_OVERRIDE, ORM_PKG.getBaseXmlEmbedded_AttributeOverrides()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddedTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddedTranslator.java deleted file mode 100644 index 184b8b25de..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmbeddedTranslator.java +++ /dev/null @@ -1,54 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EmbeddedTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EmbeddedTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlEmbeddedImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createAttributeOverrideTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createAttributeOverrideTranslator() { - return new AttributeOverrideTranslator(ATTRIBUTE_OVERRIDE, ORM_PKG.getBaseXmlEmbedded_AttributeOverrides()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmptyTagBooleanTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmptyTagBooleanTranslator.java deleted file mode 100644 index b2bdee2c86..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EmptyTagBooleanTranslator.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.resource.orm.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 domNameAndPath, EStructuralFeature feature) { - super(domNameAndPath, feature, EMPTY_TAG | BOOLEAN_FEATURE); - } - - public EmptyTagBooleanTranslator(String domNameAndPath, EStructuralFeature aFeature, int style) { - super(domNameAndPath, aFeature, 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 == Boolean.TRUE) ? value : null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityListenerTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityListenerTranslator.java deleted file mode 100644 index f42801fb7a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityListenerTranslator.java +++ /dev/null @@ -1,78 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EntityListenerTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EntityListenerTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - private Translator[] createChildren() { - return new Translator[] { - createClassTranslator(), - createPrePersistTranslator(), - createPostPersistTranslator(), - createPreRemoveTranslator(), - createPostRemoveTranslator(), - createPreUpdateTranslator(), - createPostUpdateTranslator(), - createPostLoadTranslator() - }; - } - - private Translator createClassTranslator() { - return new Translator(CLASS, ORM_PKG.getEntityListener_ClassName()); - } - - private Translator createPrePersistTranslator() { - return new EventMethodTranslator(PRE_PERSIST, ORM_PKG.getEntityListener_PrePersist()); - } - - private Translator createPostPersistTranslator() { - return new EventMethodTranslator(POST_PERSIST, ORM_PKG.getEntityListener_PostPersist()); - } - - private Translator createPreRemoveTranslator() { - return new EventMethodTranslator(PRE_REMOVE, ORM_PKG.getEntityListener_PreRemove()); - } - - private Translator createPostRemoveTranslator() { - return new EventMethodTranslator(POST_REMOVE, ORM_PKG.getEntityListener_PostRemove()); - } - - private Translator createPreUpdateTranslator() { - return new EventMethodTranslator(PRE_UPDATE, ORM_PKG.getEntityListener_PreUpdate()); - } - - private Translator createPostUpdateTranslator() { - return new EventMethodTranslator(POST_UPDATE, ORM_PKG.getEntityListener_PostUpdate()); - } - - private Translator createPostLoadTranslator() { - return new EventMethodTranslator(POST_LOAD, ORM_PKG.getEntityListener_PostLoad()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityListenersTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityListenersTranslator.java deleted file mode 100644 index 959a660ea2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityListenersTranslator.java +++ /dev/null @@ -1,43 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EntityListenersTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EntityListenersTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - private Translator[] createChildren() { - return new Translator[] { - createEntityListenerTranslator() - }; - } - - private Translator createEntityListenerTranslator() { - return new EntityListenerTranslator(ENTITY_LISTENER, ORM_PKG.getEntityListeners_EntityListeners()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityMappingsTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityMappingsTranslator.java deleted file mode 100644 index 5e597752ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityMappingsTranslator.java +++ /dev/null @@ -1,118 +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.resource.orm.translators; - -import org.eclipse.wst.common.internal.emf.resource.ConstantAttributeTranslator; -import org.eclipse.wst.common.internal.emf.resource.RootTranslator; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EntityMappingsTranslator extends RootTranslator - implements OrmXmlMapper -{ - public static EntityMappingsTranslator INSTANCE = new EntityMappingsTranslator(); - - - private Translator[] children; - - - public EntityMappingsTranslator() { - super(ENTITY_MAPPINGS, ORM_PKG.getXmlEntityMappings()); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - private Translator[] createChildren() { - return new Translator[] { - new ConstantAttributeTranslator(XML_NS, PERSISTENCE_NS_URL), - new ConstantAttributeTranslator(XML_NS_XSI, XSI_NS_URL), - new ConstantAttributeTranslator(XSI_SCHEMA_LOCATION, PERSISTENCE_NS_URL + ' ' + ORM_SCHEMA_LOC_1_0), - createVersionTranslator(), - createDescriptionTranslator(), - createPersistenceUnitMetadataTranslator(), - createPackageTranslator(), - createSchemaTranslator(), - createCatalogTranslator(), - createAccessTranslator(), - createSequenceGeneratorTranslator(), - createTableGeneratorTranslator(), - createNamedQueryTranslator(), - createNamedNativeQueryTranslator(), - createSqlResultSetMappingTranslator(), - createMappedSuperclassTranslator(), - createEntityTranslator(), - createEmbeddableTranslator() - }; - } - - private Translator createVersionTranslator() { - return new Translator(VERSION, ORM_PKG.getXmlEntityMappings_Version(), DOM_ATTRIBUTE); - } - - private Translator createDescriptionTranslator() { - return new Translator(DESCRIPTION, ORM_PKG.getXmlEntityMappings_Description()); - } - - private Translator createPersistenceUnitMetadataTranslator() { - return new PersistenceUnitMetadataTranslator(PERSISTENCE_UNIT_METADATA, ORM_PKG.getXmlEntityMappings_PersistenceUnitMetadata()); - } - - private Translator createPackageTranslator() { - return new Translator(PACKAGE, ORM_PKG.getXmlEntityMappings_Package()); - } - - private Translator createSchemaTranslator() { - return new Translator(SCHEMA, ORM_PKG.getXmlEntityMappings_Schema()); - } - - private Translator createCatalogTranslator() { - return new Translator(CATALOG, ORM_PKG.getXmlEntityMappings_Catalog()); - } - - private Translator createAccessTranslator() { - return new Translator(ACCESS, ORM_PKG.getXmlEntityMappings_Access()); - } - - private Translator createSequenceGeneratorTranslator() { - return new SequenceGeneratorTranslator(SEQUENCE_GENERATOR, ORM_PKG.getXmlEntityMappings_SequenceGenerators()); - } - - private Translator createTableGeneratorTranslator() { - return new TableGeneratorTranslator(TABLE_GENERATOR, ORM_PKG.getXmlEntityMappings_TableGenerators()); - } - - private Translator createNamedQueryTranslator() { - return new NamedQueryTranslator(NAMED_QUERY, ORM_PKG.getXmlEntityMappings_NamedQueries()); - } - - private Translator createNamedNativeQueryTranslator() { - return new NamedNativeQueryTranslator(NAMED_NATIVE_QUERY, ORM_PKG.getXmlEntityMappings_NamedNativeQueries()); - } - - private Translator createSqlResultSetMappingTranslator() { - return new SqlResultSetMappingTranslator(SQL_RESULT_SET_MAPPING, ORM_PKG.getXmlEntityMappings_SqlResultSetMappings()); - } - - private Translator createMappedSuperclassTranslator() { - return new MappedSuperclassTranslator(MAPPED_SUPERCLASS, ORM_PKG.getXmlEntityMappings_MappedSuperclasses()); - } - - private Translator createEntityTranslator() { - return new EntityTranslator(ENTITY, ORM_PKG.getXmlEntityMappings_Entities()); - } - - private Translator createEmbeddableTranslator() { - return new EmbeddableTranslator(EMBEDDABLE, ORM_PKG.getXmlEntityMappings_Embeddables()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityResultTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityResultTranslator.java deleted file mode 100644 index f618d41413..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityResultTranslator.java +++ /dev/null @@ -1,53 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EntityResultTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EntityResultTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createEntityClassTranslator(), - createDiscriminatorColumnTranslator(), - createFieldResultTranslator() - }; - } - - private Translator createEntityClassTranslator() { - return new Translator(ENTITY_CLASS, ORM_PKG.getEntityResult_EntityClass(), DOM_ATTRIBUTE); - } - - private Translator createDiscriminatorColumnTranslator() { - return new Translator(DISCRIMINATOR_COLUMN, ORM_PKG.getEntityResult_DiscriminatorColumn(), DOM_ATTRIBUTE); - } - - private Translator createFieldResultTranslator() { - return new FieldResultTranslator(FIELD_RESULT, ORM_PKG.getEntityResult_FieldResults()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityTranslator.java deleted file mode 100644 index e44eaaa0c0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EntityTranslator.java +++ /dev/null @@ -1,186 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EntityTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EntityTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createClassTranslator(), - createAccessTranslator(), - createMetadataCompleteTranslator(), - createDescriptionTranslator(), - createTableTranslator(), - createSecondaryTableTranslator(), - createPrimaryKeyJoinColumnTranslator(), - createIdClassTranslator(), - createInheritanceTranslator(), - createDiscriminatorValueTranslator(), - createDiscriminatorColumnTranslator(), - createSequenceGeneratorTranslator(), - createTableGeneratorTranslator(), - createNamedQueryTranslator(), - createNamedNativeQueryTranslator(), - createSqlResultSetMappingTranslator(), - createExcludeDefaultListenersTranslator(), - createExcludeSuperclassListenersTranslator(), - createEntityListenersTranslator(), - createPrePersistTranslator(), - createPostPersistTranslator(), - createPreRemoveTranslator(), - createPostRemoveTranslator(), - createPreUpdateTranslator(), - createPostUpdateTranslator(), - createPostLoadTranslator(), - createAttributeOverrideTranslator(), - createAssociationOverrideTranslator(), - createAttributesTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlEntity_Name(), DOM_ATTRIBUTE); - } - - private Translator createClassTranslator() { - return new Translator(CLASS, ORM_PKG.getAbstractXmlTypeMapping_ClassName(), DOM_ATTRIBUTE); - } - - private Translator createAccessTranslator() { - return new Translator(ACCESS, ORM_PKG.getAbstractXmlTypeMapping_Access(), DOM_ATTRIBUTE); - } - - private Translator createMetadataCompleteTranslator() { - return new Translator(METADATA_COMPLETE, ORM_PKG.getAbstractXmlTypeMapping_MetadataComplete(), DOM_ATTRIBUTE); - } - - private Translator createDescriptionTranslator() { - return new Translator(DESCRIPTION, ORM_PKG.getAbstractXmlTypeMapping_Description()); - } - - private Translator createTableTranslator() { - return new TableTranslator(TABLE, ORM_PKG.getXmlEntity_Table()); - } - - private Translator createSecondaryTableTranslator() { - return new SecondaryTableTranslator(SECONDARY_TABLE, ORM_PKG.getXmlEntity_SecondaryTables()); - } - - private Translator createPrimaryKeyJoinColumnTranslator() { - return new PrimaryKeyJoinColumnTranslator(PRIMARY_KEY_JOIN_COLUMN, ORM_PKG.getXmlEntity_PrimaryKeyJoinColumns()); - } - - private Translator createIdClassTranslator() { - return new IdClassTranslator(ID_CLASS, ORM_PKG.getXmlEntity_IdClass()); - } - - private Translator createInheritanceTranslator() { - return new InheritanceTranslator(INHERITANCE, ORM_PKG.getXmlEntity_Inheritance()); - } - - private Translator createDiscriminatorValueTranslator() { - return new Translator(DISCRIMINATOR_VALUE, ORM_PKG.getXmlEntity_DiscriminatorValue()); - } - - private Translator createDiscriminatorColumnTranslator() { - return new DiscriminatorColumnTranslator(DISCRIMINATOR_COLUMN, ORM_PKG.getXmlEntity_DiscriminatorColumn()); - } - - private Translator createSequenceGeneratorTranslator() { - return new SequenceGeneratorTranslator(SEQUENCE_GENERATOR, ORM_PKG.getXmlEntity_SequenceGenerator()); - } - - private Translator createTableGeneratorTranslator() { - return new TableGeneratorTranslator(TABLE_GENERATOR, ORM_PKG.getXmlEntity_TableGenerator()); - } - - private Translator createNamedQueryTranslator() { - return new NamedQueryTranslator(NAMED_QUERY, ORM_PKG.getXmlEntity_NamedQueries()); - } - - private Translator createNamedNativeQueryTranslator() { - return new NamedNativeQueryTranslator(NAMED_NATIVE_QUERY, ORM_PKG.getXmlEntity_NamedNativeQueries()); - } - - private Translator createSqlResultSetMappingTranslator() { - return new SqlResultSetMappingTranslator(SQL_RESULT_SET_MAPPING, ORM_PKG.getXmlEntity_SqlResultSetMappings()); - } - - private Translator createExcludeDefaultListenersTranslator() { - return new EmptyTagBooleanTranslator(EXCLUDE_DEFAULT_LISTENERS, ORM_PKG.getXmlEntity_ExcludeDefaultListeners()); - } - - private Translator createExcludeSuperclassListenersTranslator() { - return new EmptyTagBooleanTranslator(EXCLUDE_SUPERCLASS_LISTENERS, ORM_PKG.getXmlEntity_ExcludeSuperclassListeners()); - } - - private Translator createEntityListenersTranslator() { - return new EntityListenersTranslator(ENTITY_LISTENERS, ORM_PKG.getXmlEntity_EntityListeners()); - } - - private Translator createPrePersistTranslator() { - return new EventMethodTranslator(PRE_PERSIST, ORM_PKG.getXmlEntity_PrePersist()); - } - - private Translator createPostPersistTranslator() { - return new EventMethodTranslator(POST_PERSIST, ORM_PKG.getXmlEntity_PostPersist()); - } - - private Translator createPreRemoveTranslator() { - return new EventMethodTranslator(PRE_REMOVE, ORM_PKG.getXmlEntity_PreRemove()); - } - - private Translator createPostRemoveTranslator() { - return new EventMethodTranslator(POST_REMOVE, ORM_PKG.getXmlEntity_PostRemove()); - } - - private Translator createPreUpdateTranslator() { - return new EventMethodTranslator(PRE_UPDATE, ORM_PKG.getXmlEntity_PreUpdate()); - } - - private Translator createPostUpdateTranslator() { - return new EventMethodTranslator(POST_UPDATE, ORM_PKG.getXmlEntity_PostUpdate()); - } - - private Translator createPostLoadTranslator() { - return new EventMethodTranslator(POST_LOAD, ORM_PKG.getXmlEntity_PostLoad()); - } - - private Translator createAttributeOverrideTranslator() { - return new AttributeOverrideTranslator(ATTRIBUTE_OVERRIDE, ORM_PKG.getXmlEntity_AttributeOverrides()); - } - - private Translator createAssociationOverrideTranslator() { - return new AssociationOverrideTranslator(ASSOCIATION_OVERRIDE, ORM_PKG.getXmlEntity_AssociationOverrides()); - } - - private Translator createAttributesTranslator() { - return new AttributesTranslator(ATTRIBUTES, ORM_PKG.getAbstractXmlTypeMapping_Attributes()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EventMethodTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EventMethodTranslator.java deleted file mode 100644 index 32b528a38d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/EventMethodTranslator.java +++ /dev/null @@ -1,43 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class EventMethodTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public EventMethodTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - private Translator[] createChildren() { - return new Translator[] { - createMethodNameTranslator() - }; - } - - private Translator createMethodNameTranslator() { - return new Translator(METHOD_NAME, ORM_PKG.getEventMethod_MethodName(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/FieldResultTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/FieldResultTranslator.java deleted file mode 100644 index 4667523cd5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/FieldResultTranslator.java +++ /dev/null @@ -1,48 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class FieldResultTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public FieldResultTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createColumnTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getFieldResult_Name(), DOM_ATTRIBUTE); - } - - private Translator createColumnTranslator() { - return new Translator(COLUMN, ORM_PKG.getFieldResult_Column(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/GeneratedValueTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/GeneratedValueTranslator.java deleted file mode 100644 index d0fde3d42f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/GeneratedValueTranslator.java +++ /dev/null @@ -1,53 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class GeneratedValueTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public GeneratedValueTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlGeneratedValueImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createStrategyTranslator(), - createGeneratorTranslator() - }; - } - - protected Translator createStrategyTranslator() { - return new Translator(STRATEGY, ORM_PKG.getXmlGeneratedValue_Strategy(), DOM_ATTRIBUTE); - } - - protected Translator createGeneratorTranslator() { - return new Translator(GENERATOR, ORM_PKG.getXmlGeneratedValue_Generator(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/IdClassTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/IdClassTranslator.java deleted file mode 100644 index b20a6efc61..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/IdClassTranslator.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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class IdClassTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public IdClassTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createClassTranslator() - }; - } - - protected Translator createClassTranslator() { - return new Translator(CLASS, ORM_PKG.getXmlIdClass_ClassName(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/IdTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/IdTranslator.java deleted file mode 100644 index db7e3bba39..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/IdTranslator.java +++ /dev/null @@ -1,73 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class IdTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public IdTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlIdImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createColumnTranslator(), - createGeneratedValueTranslator(), - createTemporalTranslator(), - createTableGeneratorTranslator(), - createSequenceGeneratorTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createColumnTranslator() { - return new ColumnTranslator(COLUMN, ORM_PKG.getColumnMapping_Column()); - } - - private Translator createGeneratedValueTranslator() { - return new GeneratedValueTranslator(GENERATED_VALUE, ORM_PKG.getXmlId_GeneratedValue()); - } - - private Translator createTemporalTranslator() { - return new Translator(TEMPORAL, ORM_PKG.getXmlId_Temporal()); - } - - private Translator createTableGeneratorTranslator() { - return new TableGeneratorTranslator(TABLE_GENERATOR, ORM_PKG.getXmlId_TableGenerator()); - } - - private Translator createSequenceGeneratorTranslator() { - return new SequenceGeneratorTranslator(SEQUENCE_GENERATOR, ORM_PKG.getXmlId_SequenceGenerator()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/InheritanceTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/InheritanceTranslator.java deleted file mode 100644 index 0387fb8b08..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/InheritanceTranslator.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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class InheritanceTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public InheritanceTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createStrategyTranslator(), - }; - } - - private Translator createStrategyTranslator() { - return new Translator(STRATEGY, ORM_PKG.getInheritance_Strategy(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/JoinColumnTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/JoinColumnTranslator.java deleted file mode 100644 index 1647c4cb66..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/JoinColumnTranslator.java +++ /dev/null @@ -1,85 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.internal.resource.common.translators.BooleanTranslator; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class JoinColumnTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public JoinColumnTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlJoinColumnImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createReferencedColumnNameTranslator(), - createUniqueTranslator(), - createNullableTranslator(), - createInsertableTranslator(), - createUpdatableTranslator(), - createColumnDefinitionTranslator(), - createTableTranslator(), - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlNamedColumn_Name(), DOM_ATTRIBUTE); - } - - private Translator createReferencedColumnNameTranslator() { - return new Translator(REFERENCED_COLUMN_NAME, ORM_PKG.getXmlJoinColumn_ReferencedColumnName(), DOM_ATTRIBUTE); - } - - private Translator createUniqueTranslator() { - return new BooleanTranslator(UNIQUE, ORM_PKG.getXmlAbstractColumn_Unique(), DOM_ATTRIBUTE); - } - - private Translator createNullableTranslator() { - return new BooleanTranslator(NULLABLE, ORM_PKG.getXmlAbstractColumn_Nullable(), DOM_ATTRIBUTE); - } - - private Translator createInsertableTranslator() { - return new BooleanTranslator(INSERTABLE, ORM_PKG.getXmlAbstractColumn_Insertable(), DOM_ATTRIBUTE); - } - - private Translator createUpdatableTranslator() { - return new BooleanTranslator(UPDATABLE, ORM_PKG.getXmlAbstractColumn_Updatable(), DOM_ATTRIBUTE); - } - - private Translator createColumnDefinitionTranslator() { - return new Translator(COLUMN_DEFINITION, ORM_PKG.getXmlNamedColumn_ColumnDefinition(), DOM_ATTRIBUTE); - } - - private Translator createTableTranslator() { - return new Translator(TABLE, ORM_PKG.getXmlAbstractColumn_Table(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/JoinTableTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/JoinTableTranslator.java deleted file mode 100644 index 3d0bbccb02..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/JoinTableTranslator.java +++ /dev/null @@ -1,73 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class JoinTableTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public JoinTableTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlJoinTableImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createCatalogTranslator(), - createSchemaTranslator(), - createJoinColumnTranslator(), - createInverseJoinColumnTranslator(), - createUniqueConstraintTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlBaseTable_Name(), DOM_ATTRIBUTE); - } - - private Translator createCatalogTranslator() { - return new Translator(CATALOG, ORM_PKG.getXmlBaseTable_Catalog(), DOM_ATTRIBUTE); - } - - private Translator createSchemaTranslator() { - return new Translator(SCHEMA, ORM_PKG.getXmlBaseTable_Schema(), DOM_ATTRIBUTE); - } - - private Translator createJoinColumnTranslator() { - return new JoinColumnTranslator(JOIN_COLUMN, ORM_PKG.getXmlJoinTable_JoinColumns()); - } - - private Translator createInverseJoinColumnTranslator() { - return new JoinColumnTranslator(INVERSE_JOIN_COLUMN, ORM_PKG.getXmlJoinTable_InverseJoinColumns()); - } - - private Translator createUniqueConstraintTranslator() { - return new UniqueConstraintTranslator(UNIQUE_CONSTRAINT, ORM_PKG.getXmlBaseTable_UniqueConstraints()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ManyToManyTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ManyToManyTranslator.java deleted file mode 100644 index 2056e81d13..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ManyToManyTranslator.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class ManyToManyTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public ManyToManyTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlManyToManyImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createTargetEntityTranslator(), - createFetchTranslator(), - createMappedByTranslator(), - createOrderByTranslator(), - createMapKeyTranslator(), - createJoinTableTranslator(), - createCascadeTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createTargetEntityTranslator() { - return new Translator(TARGET_ENTITY, ORM_PKG.getXmlRelationshipMapping_TargetEntity(), DOM_ATTRIBUTE); - } - - private Translator createFetchTranslator() { - return new Translator(FETCH, ORM_PKG.getXmlRelationshipMapping_Fetch(), DOM_ATTRIBUTE); - } - - private Translator createMappedByTranslator() { - return new Translator(MAPPED_BY, ORM_PKG.getXmlMultiRelationshipMapping_MappedBy(), DOM_ATTRIBUTE); - } - - private Translator createOrderByTranslator() { - return new Translator(ORDER_BY, ORM_PKG.getXmlMultiRelationshipMapping_OrderBy()); - } - - private Translator createMapKeyTranslator() { - return new MapKeyTranslator(MAP_KEY, ORM_PKG.getXmlMultiRelationshipMapping_MapKey()); - } - - private Translator createJoinTableTranslator() { - return new JoinTableTranslator(JOIN_TABLE, ORM_PKG.getXmlRelationshipMapping_JoinTable()); - } - - private Translator createCascadeTranslator() { - return new CascadeTypeTranslator(CASCADE, ORM_PKG.getXmlRelationshipMapping_Cascade()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ManyToOneTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ManyToOneTranslator.java deleted file mode 100644 index aebc86cbd9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/ManyToOneTranslator.java +++ /dev/null @@ -1,78 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class ManyToOneTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public ManyToOneTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlManyToOneImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createTargetEntityTranslator(), - createFetchTranslator(), - createOptionalTranslator(), - createJoinColumnTranslator(), - createJoinTableTranslator(), - createCascadeTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createTargetEntityTranslator() { - return new Translator(TARGET_ENTITY, ORM_PKG.getXmlRelationshipMapping_TargetEntity(), DOM_ATTRIBUTE); - } - - private Translator createFetchTranslator() { - return new Translator(FETCH, ORM_PKG.getXmlRelationshipMapping_Fetch(), DOM_ATTRIBUTE); - } - - private Translator createOptionalTranslator() { - return new Translator(OPTIONAL, ORM_PKG.getXmlSingleRelationshipMapping_Optional(), DOM_ATTRIBUTE); - } - - private Translator createJoinColumnTranslator() { - return new JoinColumnTranslator(JOIN_COLUMN, ORM_PKG.getXmlSingleRelationshipMapping_JoinColumns()); - } - - private Translator createJoinTableTranslator() { - return new JoinTableTranslator(JOIN_TABLE, ORM_PKG.getXmlRelationshipMapping_JoinTable()); - } - - private Translator createCascadeTranslator() { - return new CascadeTypeTranslator(CASCADE, ORM_PKG.getXmlRelationshipMapping_Cascade()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/MapKeyTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/MapKeyTranslator.java deleted file mode 100644 index e30517274b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/MapKeyTranslator.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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - - -public class MapKeyTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public MapKeyTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator() - }; - } - - protected Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getMapKey_Name(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/MappedSuperclassTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/MappedSuperclassTranslator.java deleted file mode 100644 index 4cfa4c6162..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/MappedSuperclassTranslator.java +++ /dev/null @@ -1,116 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class MappedSuperclassTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public MappedSuperclassTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createClassTranslator(), - createAccessTranslator(), - createMetadataCompleteTranslator(), - createDescriptionTranslator(), - createIdClassTranslator(), - createExcludeDefaultListenersTranslator(), - createExcludeSuperclassListenersTranslator(), - createEntityListenersTranslator(), - createPrePersistTranslator(), - createPostPersistTranslator(), - createPreRemoveTranslator(), - createPostRemoveTranslator(), - createPreUpdateTranslator(), - createPostUpdateTranslator(), - createPostLoadTranslator(), - createAttributesTranslator() - }; - } - - private Translator createClassTranslator() { - return new Translator(CLASS, ORM_PKG.getAbstractXmlTypeMapping_ClassName(), DOM_ATTRIBUTE); - } - - private Translator createAccessTranslator() { - return new Translator(ACCESS, ORM_PKG.getAbstractXmlTypeMapping_Access(), DOM_ATTRIBUTE); - } - - private Translator createMetadataCompleteTranslator() { - return new Translator(METADATA_COMPLETE, ORM_PKG.getAbstractXmlTypeMapping_MetadataComplete(), DOM_ATTRIBUTE); - } - - private Translator createDescriptionTranslator() { - return new Translator(DESCRIPTION, ORM_PKG.getAbstractXmlTypeMapping_Description()); - } - - private Translator createIdClassTranslator() { - return new IdClassTranslator(ID_CLASS, ORM_PKG.getXmlMappedSuperclass_IdClass()); - } - - private Translator createExcludeDefaultListenersTranslator() { - return new EmptyTagBooleanTranslator(EXCLUDE_DEFAULT_LISTENERS, ORM_PKG.getXmlMappedSuperclass_ExcludeDefaultListeners()); - } - - private Translator createExcludeSuperclassListenersTranslator() { - return new EmptyTagBooleanTranslator(EXCLUDE_SUPERCLASS_LISTENERS, ORM_PKG.getXmlMappedSuperclass_ExcludeSuperclassListeners()); - } - - private Translator createEntityListenersTranslator() { - return new EntityListenersTranslator(ENTITY_LISTENERS, ORM_PKG.getXmlMappedSuperclass_EntityListeners()); - } - - private Translator createPrePersistTranslator() { - return new EventMethodTranslator(PRE_PERSIST, ORM_PKG.getXmlMappedSuperclass_PrePersist()); - } - - private Translator createPostPersistTranslator() { - return new EventMethodTranslator(POST_PERSIST, ORM_PKG.getXmlMappedSuperclass_PostPersist()); - } - - private Translator createPreRemoveTranslator() { - return new EventMethodTranslator(PRE_REMOVE, ORM_PKG.getXmlMappedSuperclass_PreRemove()); - } - - private Translator createPostRemoveTranslator() { - return new EventMethodTranslator(POST_REMOVE, ORM_PKG.getXmlMappedSuperclass_PostRemove()); - } - - private Translator createPreUpdateTranslator() { - return new EventMethodTranslator(PRE_UPDATE, ORM_PKG.getXmlMappedSuperclass_PreUpdate()); - } - - private Translator createPostUpdateTranslator() { - return new EventMethodTranslator(POST_UPDATE, ORM_PKG.getXmlMappedSuperclass_PostUpdate()); - } - - private Translator createPostLoadTranslator() { - return new EventMethodTranslator(POST_LOAD, ORM_PKG.getXmlMappedSuperclass_PostLoad()); - } - - private Translator createAttributesTranslator() { - return new AttributesTranslator(ATTRIBUTES, ORM_PKG.getAbstractXmlTypeMapping_Attributes()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/NamedNativeQueryTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/NamedNativeQueryTranslator.java deleted file mode 100644 index ba758b9b33..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/NamedNativeQueryTranslator.java +++ /dev/null @@ -1,61 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class NamedNativeQueryTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public NamedNativeQueryTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createResultClassTranslator(), - createResultSetMappingTranslator(), - createQueryTranslator(), - createHintTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlQuery_Name(), DOM_ATTRIBUTE); - } - - private Translator createResultClassTranslator() { - return new Translator(RESULT_CLASS, ORM_PKG.getXmlNamedNativeQuery_ResultClass(), DOM_ATTRIBUTE); - } - - private Translator createResultSetMappingTranslator() { - return new Translator(RESULT_SET_MAPPING, ORM_PKG.getXmlNamedNativeQuery_ResultSetMapping(), DOM_ATTRIBUTE); - } - - private Translator createQueryTranslator() { - return new Translator(QUERY, ORM_PKG.getXmlQuery_Query()); - } - - private Translator createHintTranslator() { - return new QueryHintTranslator(HINT, ORM_PKG.getXmlQuery_Hints()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/NamedQueryTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/NamedQueryTranslator.java deleted file mode 100644 index 917645dc94..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/NamedQueryTranslator.java +++ /dev/null @@ -1,51 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class NamedQueryTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public NamedQueryTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createQueryTranslator(), - createHintTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlQuery_Name(), DOM_ATTRIBUTE); - } - - private Translator createQueryTranslator() { - return new Translator(QUERY, ORM_PKG.getXmlQuery_Query()); - } - - private Translator createHintTranslator() { - return new QueryHintTranslator(HINT, ORM_PKG.getXmlQuery_Hints()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OneToManyTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OneToManyTranslator.java deleted file mode 100644 index a0184df246..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OneToManyTranslator.java +++ /dev/null @@ -1,88 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class OneToManyTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public OneToManyTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlOneToManyImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createTargetEntityTranslator(), - createFetchTranslator(), - createMappedByTranslator(), - createOrderByTranslator(), - createMapKeyTranslator(), - createJoinTableTranslator(), - createJoinColumnTranslator(), - createCascadeTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createTargetEntityTranslator() { - return new Translator(TARGET_ENTITY, ORM_PKG.getXmlRelationshipMapping_TargetEntity(), DOM_ATTRIBUTE); - } - - private Translator createFetchTranslator() { - return new Translator(FETCH, ORM_PKG.getXmlRelationshipMapping_Fetch(), DOM_ATTRIBUTE); - } - - private Translator createMappedByTranslator() { - return new Translator(MAPPED_BY, ORM_PKG.getXmlMultiRelationshipMapping_MappedBy(), DOM_ATTRIBUTE); - } - - private Translator createOrderByTranslator() { - return new Translator(ORDER_BY, ORM_PKG.getXmlMultiRelationshipMapping_OrderBy()); - } - - private Translator createMapKeyTranslator() { - return new MapKeyTranslator(MAP_KEY, ORM_PKG.getXmlMultiRelationshipMapping_MapKey()); - } - - private Translator createJoinTableTranslator() { - return new JoinTableTranslator(JOIN_TABLE, ORM_PKG.getXmlRelationshipMapping_JoinTable()); - } - - private Translator createJoinColumnTranslator() { - return new JoinColumnTranslator(JOIN_COLUMN, ORM_PKG.getXmlOneToMany_JoinColumns()); - } - - private Translator createCascadeTranslator() { - return new CascadeTypeTranslator(CASCADE, ORM_PKG.getXmlRelationshipMapping_Cascade()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OneToOneTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OneToOneTranslator.java deleted file mode 100644 index 0b06c3ae23..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OneToOneTranslator.java +++ /dev/null @@ -1,90 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class OneToOneTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public OneToOneTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlOneToOneImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createTargetEntityTranslator(), - createFetchTranslator(), - createOptionalTranslator(), - createMappedByTranslator(), - createPrimaryKeyJoinColumnTranslator(), - createJoinColumnTranslator(), - createJoinTableTranslator(), - createCascadeTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createTargetEntityTranslator() { - return new Translator(TARGET_ENTITY, ORM_PKG.getXmlRelationshipMapping_TargetEntity(), DOM_ATTRIBUTE); - } - - private Translator createFetchTranslator() { - return new Translator(FETCH, ORM_PKG.getXmlRelationshipMapping_Fetch(), DOM_ATTRIBUTE); - } - - private Translator createOptionalTranslator() { - return new Translator(OPTIONAL, ORM_PKG.getXmlSingleRelationshipMapping_Optional(), DOM_ATTRIBUTE); - } - - private Translator createMappedByTranslator() { - return new Translator(MAPPED_BY, ORM_PKG.getXmlOneToOne_MappedBy(), DOM_ATTRIBUTE); - } - - private Translator createPrimaryKeyJoinColumnTranslator() { - return new PrimaryKeyJoinColumnTranslator(PRIMARY_KEY_JOIN_COLUMN, ORM_PKG.getXmlOneToOne_PrimaryKeyJoinColumns()); - } - - private Translator createJoinColumnTranslator() { - return new JoinColumnTranslator(JOIN_COLUMN, ORM_PKG.getXmlSingleRelationshipMapping_JoinColumns()); - } - - private Translator createJoinTableTranslator() { - return new JoinTableTranslator(JOIN_TABLE, ORM_PKG.getXmlRelationshipMapping_JoinTable()); - } - - private Translator createCascadeTranslator() { - return new CascadeTypeTranslator(CASCADE, ORM_PKG.getXmlRelationshipMapping_Cascade()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OrmXmlMapper.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OrmXmlMapper.java deleted file mode 100644 index 9b7a58c042..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/OrmXmlMapper.java +++ /dev/null @@ -1,126 +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.resource.orm.translators; - -import org.eclipse.jpt.core.resource.orm.OrmPackage; - -public interface OrmXmlMapper -{ - OrmPackage ORM_PKG = OrmPackage.eINSTANCE; - - String XML_NS = "xmlns"; //$NON-NLS-1$ - String XML_NS_XSI = "xmlns:xsi"; //$NON-NLS-1$ - String XSI_SCHEMA_LOCATION = "xsi:schemaLocation"; //$NON-NLS-1$ - String XSI_NS_URL = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - String PERSISTENCE_NS_URL = "http://java.sun.com/xml/ns/persistence/orm"; //$NON-NLS-1$ - String ORM_SCHEMA_LOC_1_0 = "http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"; //$NON-NLS-1$ - - - String ACCESS = "access"; //$NON-NLS-1$ - String ALLOCATION_SIZE = "allocation-size"; //$NON-NLS-1$ - String ASSOCIATION_OVERRIDE = "association-override"; //$NON-NLS-1$ - String ATTRIBUTE_OVERRIDE = "attribute-override"; //$NON-NLS-1$ - String ATTRIBUTES = "attributes"; //$NON-NLS-1$ - String BASIC = "basic"; //$NON-NLS-1$ - String CASCADE = "cascade"; //$NON-NLS-1$ - String CASCADE_ALL = "cascade-all"; //$NON-NLS-1$ - String CASCADE_MERGE = "cascade-merge"; //$NON-NLS-1$ - String CASCADE_PERSIST = "cascade-persist"; //$NON-NLS-1$ - String CASCADE_REFRESH = "cascade-refresh"; //$NON-NLS-1$ - String CASCADE_REMOVE = "cascade-remove"; //$NON-NLS-1$ - String CATALOG = "catalog"; //$NON-NLS-1$ - String CLASS = "class"; //$NON-NLS-1$ - String COLUMN = "column"; //$NON-NLS-1$ - String COLUMN_DEFINITION= "column-definition"; //$NON-NLS-1$ - String COLUMN_NAME = "column-name"; //$NON-NLS-1$ - String COLUMN_RESULT = "column-result"; //$NON-NLS-1$ - String DESCRIPTION = "description"; //$NON-NLS-1$ - String DISCRIMINATOR_COLUMN = "discriminator-column"; //$NON-NLS-1$ - String DISCRIMINATOR_TYPE = "discriminator-type"; //$NON-NLS-1$ - String DISCRIMINATOR_VALUE = "discriminator-value"; //$NON-NLS-1$ - String EMBEDDABLE = "embeddable"; //$NON-NLS-1$ - String EMBEDDED = "embedded"; //$NON-NLS-1$ - String EMBEDDED_ID = "embedded-id"; //$NON-NLS-1$ - String ENTITY = "entity"; //$NON-NLS-1$ - String ENTITY_CLASS = "entity-class"; //$NON-NLS-1$ - String ENTITY_LISTENER = "entity-listener"; //$NON-NLS-1$ - String ENTITY_LISTENERS = "entity-listeners"; //$NON-NLS-1$ - String ENTITY_MAPPINGS = "entity-mappings"; //$NON-NLS-1$ - String ENTITY_RESULT = "entity-result"; //$NON-NLS-1$ - String ENUMERATED = "enumerated"; //$NON-NLS-1$ - String EXCLUDE_DEFAULT_LISTENERS = "exclude-default-listeners"; //$NON-NLS-1$ - String EXCLUDE_SUPERCLASS_LISTENERS = "exclude-superclass-listeners"; //$NON-NLS-1$ - String FETCH = "fetch"; //$NON-NLS-1$ - String FIELD_RESULT = "field-result"; //$NON-NLS-1$ - String GENERATED_VALUE = "generated-value"; //$NON-NLS-1$ - String GENERATOR = "generator"; //$NON-NLS-1$ - String HINT = "hint"; //$NON-NLS-1$ - String ID = "id"; //$NON-NLS-1$ - String ID_CLASS = "id-class"; //$NON-NLS-1$ - String INHERITANCE = "inheritance"; //$NON-NLS-1$ - String INITIAL_VALUE = "initial-value"; //$NON-NLS-1$ - String INSERTABLE = "insertable"; //$NON-NLS-1$ - String INVERSE_JOIN_COLUMN = "inverse-join-column"; //$NON-NLS-1$ - String JOIN_COLUMN = "join-column"; //$NON-NLS-1$ - String JOIN_TABLE = "join-table"; //$NON-NLS-1$ - String LENGTH = "length"; //$NON-NLS-1$ - String LOB = "lob"; //$NON-NLS-1$ - String MANY_TO_MANY = "many-to-many"; //$NON-NLS-1$ - String MANY_TO_ONE = "many-to-one"; //$NON-NLS-1$ - String MAP_KEY = "map-key"; //$NON-NLS-1$ - String MAPPED_BY = "mapped-by"; //$NON-NLS-1$ - String MAPPED_SUPERCLASS = "mapped-superclass"; //$NON-NLS-1$ - String METADATA_COMPLETE = "metadata-complete"; //$NON-NLS-1$ - String METHOD_NAME = "method-name"; //$NON-NLS-1$ - String NAME = "name"; //$NON-NLS-1$ - String NAMED_NATIVE_QUERY = "named-native-query"; //$NON-NLS-1$ - String NAMED_QUERY = "named-query"; //$NON-NLS-1$ - String NULLABLE = "nullable"; //$NON-NLS-1$ - String ONE_TO_MANY = "one-to-many"; //$NON-NLS-1$ - String ONE_TO_ONE = "one-to-one"; //$NON-NLS-1$ - String OPTIONAL = "optional"; //$NON-NLS-1$ - String ORDER_BY = "order-by"; //$NON-NLS-1$ - String PACKAGE = "package"; //$NON-NLS-1$ - String PERSISTENCE_UNIT_DEFAULTS = "persistence-unit-defaults"; //$NON-NLS-1$ - String PERSISTENCE_UNIT_METADATA = "persistence-unit-metadata"; //$NON-NLS-1$ - String PK_COLUMN_NAME = "pk-column-name"; //$NON-NLS-1$ - String PK_COLUMN_VALUE = "pk-column-value"; //$NON-NLS-1$ - String POST_LOAD = "post-load"; //$NON-NLS-1$ - String POST_PERSIST = "post-persist"; //$NON-NLS-1$ - String POST_REMOVE = "post-remove"; //$NON-NLS-1$ - String POST_UPDATE = "post-update"; //$NON-NLS-1$ - String PRE_PERSIST = "pre-persist"; //$NON-NLS-1$ - String PRE_REMOVE = "pre-remove"; //$NON-NLS-1$ - String PRE_UPDATE = "pre-update"; //$NON-NLS-1$ - String PRECISION= "precision"; //$NON-NLS-1$ - String PRIMARY_KEY_JOIN_COLUMN = "primary-key-join-column"; //$NON-NLS-1$ - String QUERY = "query"; //$NON-NLS-1$ - String REFERENCED_COLUMN_NAME = "referenced-column-name"; //$NON-NLS-1$ - String RESULT_CLASS = "result-class"; //$NON-NLS-1$ - String RESULT_SET_MAPPING = "result-set-mapping"; //$NON-NLS-1$ - String SCALE= "scale"; //$NON-NLS-1$ - String SCHEMA = "schema"; //$NON-NLS-1$ - String SECONDARY_TABLE = "secondary-table"; //$NON-NLS-1$ - String SEQUENCE_GENERATOR = "sequence-generator"; //$NON-NLS-1$ - String SEQUENCE_NAME = "sequence-name"; //$NON-NLS-1$ - String SQL_RESULT_SET_MAPPING = "sql-result-set-mapping"; //$NON-NLS-1$ - String STRATEGY = "strategy"; //$NON-NLS-1$ - String TABLE = "table"; //$NON-NLS-1$ - String TABLE_GENERATOR = "table-generator"; //$NON-NLS-1$ - String TARGET_ENTITY = "target-entity"; //$NON-NLS-1$ - String TEMPORAL = "temporal"; //$NON-NLS-1$ - String TRANSIENT = "transient"; //$NON-NLS-1$ - String UNIQUE = "unique"; //$NON-NLS-1$ - String UNIQUE_CONSTRAINT = "unique-constraint"; //$NON-NLS-1$ - String UPDATABLE = "updatable"; //$NON-NLS-1$ - String VALUE = "value"; //$NON-NLS-1$ - String VALUE_COLUMN_NAME = "value-column-name"; //$NON-NLS-1$ - String VERSION = "version"; //$NON-NLS-1$ - String XML_MAPPING_METADATA_COMPLETE = "xml-mapping-metadata-complete"; //$NON-NLS-1$ -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PersistenceUnitDefaultsTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PersistenceUnitDefaultsTranslator.java deleted file mode 100644 index efccf07385..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PersistenceUnitDefaultsTranslator.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.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class PersistenceUnitDefaultsTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public PersistenceUnitDefaultsTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - private Translator[] createChildren() { - return new Translator[] { - createSchemaTranslator(), - createCatalogTranslator(), - createAccessTranslator(), - createCascadePersistTranslator(), - createEntityListenersTranslator() - }; - } - - private Translator createSchemaTranslator() { - return new Translator(SCHEMA, ORM_PKG.getXmlPersistenceUnitDefaults_Schema()); - } - - private Translator createCatalogTranslator() { - return new Translator(CATALOG, ORM_PKG.getXmlPersistenceUnitDefaults_Catalog()); - } - - private Translator createAccessTranslator() { - return new Translator(ACCESS, ORM_PKG.getXmlPersistenceUnitDefaults_Access()); - } - - private Translator createCascadePersistTranslator() { - return new EmptyTagBooleanTranslator(CASCADE_PERSIST, ORM_PKG.getXmlPersistenceUnitDefaults_CascadePersist()); - } - - private Translator createEntityListenersTranslator() { - return new EntityListenersTranslator(ENTITY_LISTENERS, ORM_PKG.getXmlPersistenceUnitDefaults_EntityListeners()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PersistenceUnitMetadataTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PersistenceUnitMetadataTranslator.java deleted file mode 100644 index 6dc94709cb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PersistenceUnitMetadataTranslator.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class PersistenceUnitMetadataTranslator extends Translator implements OrmXmlMapper -{ - private Translator[] children; - - - public PersistenceUnitMetadataTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - private Translator[] createChildren() { - return new Translator[] { - createXmlMappingMetadataCompleteTranslator(), - createPersistenceUnitDefaultsTranslator(), - }; - } - - private Translator createXmlMappingMetadataCompleteTranslator() { - return new EmptyTagBooleanTranslator(XML_MAPPING_METADATA_COMPLETE, ORM_PKG.getXmlPersistenceUnitMetadata_XmlMappingMetadataComplete()); - } - - private Translator createPersistenceUnitDefaultsTranslator() { - return new PersistenceUnitDefaultsTranslator(PERSISTENCE_UNIT_DEFAULTS, ORM_PKG.getXmlPersistenceUnitMetadata_PersistenceUnitDefaults()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PrimaryKeyJoinColumnTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PrimaryKeyJoinColumnTranslator.java deleted file mode 100644 index 47147b5fa9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/PrimaryKeyJoinColumnTranslator.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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class PrimaryKeyJoinColumnTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public PrimaryKeyJoinColumnTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createReferencedColumnNameTranslator(), - createColumnDefinitionTranslator(), - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlNamedColumn_Name(), DOM_ATTRIBUTE); - } - - private Translator createReferencedColumnNameTranslator() { - return new Translator(REFERENCED_COLUMN_NAME, ORM_PKG.getXmlPrimaryKeyJoinColumn_ReferencedColumnName(), DOM_ATTRIBUTE); - } - - private Translator createColumnDefinitionTranslator() { - return new Translator(COLUMN_DEFINITION, ORM_PKG.getXmlNamedColumn_ColumnDefinition(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/QueryHintTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/QueryHintTranslator.java deleted file mode 100644 index af4849679a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/QueryHintTranslator.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class QueryHintTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public QueryHintTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createValueTranslator(), - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlQueryHint_Name(), DOM_ATTRIBUTE); - } - - private Translator createValueTranslator() { - return new Translator(VALUE, ORM_PKG.getXmlQueryHint_Value(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SecondaryTableTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SecondaryTableTranslator.java deleted file mode 100644 index 8ee733a595..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SecondaryTableTranslator.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class SecondaryTableTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public SecondaryTableTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlSecondaryTableImpl(); - } - - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createCatalogTranslator(), - createSchemaTranslator(), - createPrimaryKeyJoinColumnsTranslator(), - createUniqueConstraintTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlBaseTable_Name(), DOM_ATTRIBUTE); - } - - private Translator createCatalogTranslator() { - return new Translator(CATALOG, ORM_PKG.getXmlBaseTable_Catalog(), DOM_ATTRIBUTE); - } - - private Translator createSchemaTranslator() { - return new Translator(SCHEMA, ORM_PKG.getXmlBaseTable_Schema(), DOM_ATTRIBUTE); - } - - protected Translator createPrimaryKeyJoinColumnsTranslator() { - return new PrimaryKeyJoinColumnTranslator(PRIMARY_KEY_JOIN_COLUMN, ORM_PKG.getXmlSecondaryTable_PrimaryKeyJoinColumns()); - } - - private Translator createUniqueConstraintTranslator() { - return new UniqueConstraintTranslator(UNIQUE_CONSTRAINT, ORM_PKG.getXmlBaseTable_UniqueConstraints()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SequenceGeneratorTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SequenceGeneratorTranslator.java deleted file mode 100644 index 520c046d6e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SequenceGeneratorTranslator.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class SequenceGeneratorTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public SequenceGeneratorTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createSequenceNameTranslator(), - createInitialValueTranslator(), - createAllocationSizeTranslator(), - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlGenerator_Name(), DOM_ATTRIBUTE); - } - - private Translator createSequenceNameTranslator() { - return new Translator(SEQUENCE_NAME, ORM_PKG.getXmlSequenceGenerator_SequenceName(), DOM_ATTRIBUTE); - } - - private Translator createInitialValueTranslator() { - return new Translator(INITIAL_VALUE, ORM_PKG.getXmlGenerator_InitialValue(), DOM_ATTRIBUTE); - } - - private Translator createAllocationSizeTranslator() { - return new Translator(ALLOCATION_SIZE, ORM_PKG.getXmlGenerator_AllocationSize(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SqlResultSetMappingTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SqlResultSetMappingTranslator.java deleted file mode 100644 index 4a53b3557e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/SqlResultSetMappingTranslator.java +++ /dev/null @@ -1,53 +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.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class SqlResultSetMappingTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public SqlResultSetMappingTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createEntityResultTranslator(), - createColumnResultTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getSqlResultSetMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createEntityResultTranslator() { - return new EntityResultTranslator(ENTITY_RESULT, ORM_PKG.getSqlResultSetMapping_EntityResults()); - } - - private Translator createColumnResultTranslator() { - return new ColumnResultTranslator(COLUMN_RESULT, ORM_PKG.getSqlResultSetMapping_ColumnResults()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TableGeneratorTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TableGeneratorTranslator.java deleted file mode 100644 index 5b97b365eb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TableGeneratorTranslator.java +++ /dev/null @@ -1,93 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class TableGeneratorTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public TableGeneratorTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createTableTranslator(), - createCatalogTranslator(), - createSchemaTranslator(), - createPkColumnNameTranslator(), - createValueColumnNameTranslator(), - createPkColumnValueTranslator(), - createInitialValueTranslator(), - createAllocationSizeTranslator(), - createUniqueConstraintTranslator(), - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlGenerator_Name(), DOM_ATTRIBUTE); - } - - private Translator createTableTranslator() { - return new Translator(TABLE, ORM_PKG.getXmlTableGenerator_Table(), DOM_ATTRIBUTE); - } - - private Translator createCatalogTranslator() { - return new Translator(CATALOG, ORM_PKG.getXmlTableGenerator_Catalog(), DOM_ATTRIBUTE); - } - - private Translator createSchemaTranslator() { - return new Translator(SCHEMA, ORM_PKG.getXmlTableGenerator_Schema(), DOM_ATTRIBUTE); - } - - private Translator createPkColumnNameTranslator() { - return new Translator(PK_COLUMN_NAME, ORM_PKG.getXmlTableGenerator_PkColumnName(), DOM_ATTRIBUTE); - } - - private Translator createValueColumnNameTranslator() { - return new Translator(VALUE_COLUMN_NAME, ORM_PKG.getXmlTableGenerator_ValueColumnName(), DOM_ATTRIBUTE); - } - - private Translator createPkColumnValueTranslator() { - return new Translator(PK_COLUMN_VALUE, ORM_PKG.getXmlTableGenerator_PkColumnValue(), DOM_ATTRIBUTE); - } - - private Translator createInitialValueTranslator() { - return new Translator(INITIAL_VALUE, ORM_PKG.getXmlGenerator_InitialValue(), DOM_ATTRIBUTE); - } - - private Translator createAllocationSizeTranslator() { - return new Translator(ALLOCATION_SIZE, ORM_PKG.getXmlGenerator_AllocationSize(), DOM_ATTRIBUTE); - } - - private Translator createUniqueConstraintTranslator() { - return new UniqueConstraintTranslator(UNIQUE_CONSTRAINT, ORM_PKG.getXmlTableGenerator_UniqueConstraints()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TableTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TableTranslator.java deleted file mode 100644 index c983fcabcc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TableTranslator.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.internal.resource.orm.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class TableTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public TableTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createCatalogTranslator(), - createSchemaTranslator(), - createUniqueConstraintTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlBaseTable_Name(), DOM_ATTRIBUTE); - } - - private Translator createCatalogTranslator() { - return new Translator(CATALOG, ORM_PKG.getXmlBaseTable_Catalog(), DOM_ATTRIBUTE); - } - - private Translator createSchemaTranslator() { - return new Translator(SCHEMA, ORM_PKG.getXmlBaseTable_Schema(), DOM_ATTRIBUTE); - } - - private Translator createUniqueConstraintTranslator() { - return new UniqueConstraintTranslator(UNIQUE_CONSTRAINT, ORM_PKG.getXmlBaseTable_UniqueConstraints()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TransientTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TransientTranslator.java deleted file mode 100644 index f830d2a0c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/TransientTranslator.java +++ /dev/null @@ -1,49 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class TransientTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public TransientTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlTransientImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/UniqueConstraintTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/UniqueConstraintTranslator.java deleted file mode 100644 index 38d8d3404e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/UniqueConstraintTranslator.java +++ /dev/null @@ -1,48 +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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class UniqueConstraintTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public UniqueConstraintTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createColumnNameTranslator(), - }; - } - - private Translator createColumnNameTranslator() { - return new Translator(COLUMN_NAME, ORM_PKG.getXmlUniqueConstraint_ColumnNames()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/VersionTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/VersionTranslator.java deleted file mode 100644 index b257fac57b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/translators/VersionTranslator.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.resource.orm.translators; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class VersionTranslator extends Translator - implements OrmXmlMapper -{ - private Translator[] children; - - - public VersionTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public EObject createEMFObject(String nodeName, String readAheadName) { - return OrmFactory.eINSTANCE.createXmlVersionImpl(); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (this.children == null) { - this.children = createChildren(); - } - return this.children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createColumnTranslator(), - createTemporalTranslator(), - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, ORM_PKG.getXmlAttributeMapping_Name(), DOM_ATTRIBUTE); - } - - private Translator createColumnTranslator() { - return new ColumnTranslator(COLUMN, ORM_PKG.getColumnMapping_Column()); - } - - private Translator createTemporalTranslator() { - return new Translator(TEMPORAL, ORM_PKG.getXmlVersion_Temporal()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/JavaClassRefTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/JavaClassRefTranslator.java deleted file mode 100644 index b16626bd3b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/JavaClassRefTranslator.java +++ /dev/null @@ -1,44 +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.resource.persistence.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.persistence.PersistencePackage; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class JavaClassRefTranslator extends Translator -{ - private static Translator[] children; - - - public JavaClassRefTranslator(String domNameAndPath, EStructuralFeature feature, int style) { - super(domNameAndPath, feature, style); - } - - public JavaClassRefTranslator(String domNameAndPath, EStructuralFeature feature) { - super(domNameAndPath, feature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (children == null) { - children = createChildren(); - } - return children; - } - - private static Translator[] createChildren() { - return new Translator[] { - new Translator(TEXT_ATTRIBUTE_VALUE, PersistencePackage.eINSTANCE.getXmlJavaClassRef_JavaClass()) - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/MappingFileTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/MappingFileTranslator.java deleted file mode 100644 index e2144e9272..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/MappingFileTranslator.java +++ /dev/null @@ -1,40 +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.resource.persistence.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.resource.persistence.PersistencePackage; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class MappingFileTranslator extends Translator -{ - private Translator[] children; - - - public MappingFileTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (children == null) { - children = createChildren(); - } - return children; - } - - protected Translator[] createChildren() { - return new Translator[] { - new Translator(TEXT_ATTRIBUTE_VALUE, PersistencePackage.eINSTANCE.getXmlMappingFileRef_FileName()) - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceTranslator.java deleted file mode 100644 index 4350a1f365..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceTranslator.java +++ /dev/null @@ -1,54 +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.resource.persistence.translators; - -import org.eclipse.wst.common.internal.emf.resource.ConstantAttributeTranslator; -import org.eclipse.wst.common.internal.emf.resource.RootTranslator; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class PersistenceTranslator extends RootTranslator - implements PersistenceXmlMapper -{ - public static PersistenceTranslator INSTANCE = new PersistenceTranslator(); - - private Translator[] children; - - - public PersistenceTranslator() { - super(PERSISTENCE, PERSISTENCE_PKG.getXmlPersistence()); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (children == null) { - children = createChildren(); - } - return children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createVersionTranslator(), - new ConstantAttributeTranslator(XML_NS, PERSISTENCE_NS_URL), - new ConstantAttributeTranslator(XML_NS_XSI, XSI_NS_URL), - new ConstantAttributeTranslator(XSI_SCHEMA_LOCATION, PERSISTENCE_NS_URL + ' ' + PERSISTENCE_SCHEMA_LOC_1_0), - createPersistenceUnitTranslator() - }; - } - - private Translator createVersionTranslator() { - return new Translator(VERSION, PERSISTENCE_PKG.getXmlPersistence_Version(), DOM_ATTRIBUTE); - } - - private Translator createPersistenceUnitTranslator() { - return new PersistenceUnitTranslator(PERSISTENCE_UNIT, PERSISTENCE_PKG.getXmlPersistence_PersistenceUnits()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceUnitTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceUnitTranslator.java deleted file mode 100644 index 3bdaae92ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceUnitTranslator.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.resource.persistence.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jpt.core.internal.resource.common.translators.BooleanTranslator; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class PersistenceUnitTranslator extends Translator - implements PersistenceXmlMapper -{ - private Translator[] children; - - - public PersistenceUnitTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (children == null) { - children = createChildren(); - } - return children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createTransactionTypeTranslator(), - createDescriptionTranslator(), - createProviderTranslator(), - createJtaDataSourceTranslator(), - createNonJtaDataSourceTranslator(), - createMappingFileTranslator(), - createJarFileTranslator(), - createClassTranslator(), - createExcludeUnlistedClassesTranslator(), - createPropertiesTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, PERSISTENCE_PKG.getXmlPersistenceUnit_Name(), DOM_ATTRIBUTE); - } - - private Translator createTransactionTypeTranslator() { - return new Translator(TRANSACTION_TYPE, PERSISTENCE_PKG.getXmlPersistenceUnit_TransactionType(), DOM_ATTRIBUTE | UNSET_IF_NULL); - } - - private Translator createDescriptionTranslator() { - return new Translator(DESCRIPTION, PERSISTENCE_PKG.getXmlPersistenceUnit_Description()); - } - - private Translator createProviderTranslator() { - return new Translator(PROVIDER, PERSISTENCE_PKG.getXmlPersistenceUnit_Provider()); - } - - private Translator createJtaDataSourceTranslator() { - return new Translator(JTA_DATA_SOURCE, PERSISTENCE_PKG.getXmlPersistenceUnit_JtaDataSource()); - } - - private Translator createNonJtaDataSourceTranslator() { - return new Translator(NON_JTA_DATA_SOURCE, PERSISTENCE_PKG.getXmlPersistenceUnit_NonJtaDataSource()); - } - - private Translator createMappingFileTranslator() { - return new MappingFileTranslator(MAPPING_FILE, PERSISTENCE_PKG.getXmlPersistenceUnit_MappingFiles()); - } - - private Translator createJarFileTranslator() { - return new Translator(JAR_FILE, PERSISTENCE_PKG.getXmlPersistenceUnit_JarFiles()); - } - - private Translator createClassTranslator() { - return new JavaClassRefTranslator(CLASS, PERSISTENCE_PKG.getXmlPersistenceUnit_Classes()); - } - - private Translator createExcludeUnlistedClassesTranslator() { - return new BooleanTranslator(EXCLUDE_UNLISTED_CLASSES, PERSISTENCE_PKG.getXmlPersistenceUnit_ExcludeUnlistedClasses()); - } - - private Translator createPropertiesTranslator() { - return new PropertiesTranslator(PROPERTIES, PERSISTENCE_PKG.getXmlPersistenceUnit_Properties()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceXmlMapper.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceXmlMapper.java deleted file mode 100644 index dfc4186d4e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PersistenceXmlMapper.java +++ /dev/null @@ -1,43 +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.resource.persistence.translators; - -import org.eclipse.jpt.core.resource.persistence.PersistencePackage; - -public interface PersistenceXmlMapper -{ - PersistencePackage PERSISTENCE_PKG = PersistencePackage.eINSTANCE; - - String XML_NS = "xmlns"; //$NON-NLS-1$ - String XML_NS_XSI = "xmlns:xsi"; //$NON-NLS-1$ - String XSI_SCHEMA_LOCATION = "xsi:schemaLocation"; //$NON-NLS-1$ - String XSI_NS_URL = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - String PERSISTENCE_NS_URL = "http://java.sun.com/xml/ns/persistence"; //$NON-NLS-1$ - String PERSISTENCE_SCHEMA_LOC_1_0 = "http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"; //$NON-NLS-1$ - - - String CLASS = "class"; //$NON-NLS-1$ - String DESCRIPTION = "description"; //$NON-NLS-1$ - String EXCLUDE_UNLISTED_CLASSES = "exclude-unlisted-classes"; //$NON-NLS-1$ - String JAR_FILE = "jar-file"; //$NON-NLS-1$ - String JTA_DATA_SOURCE = "jta-data-source"; //$NON-NLS-1$ - String MAPPING_FILE = "mapping-file"; //$NON-NLS-1$ - String NAME = "name"; //$NON-NLS-1$ - String NON_JTA_DATA_SOURCE = "non-jta-data-source"; //$NON-NLS-1$ - String PERSISTENCE = "persistence"; //$NON-NLS-1$ - String PERSISTENCE_UNIT = "persistence-unit"; //$NON-NLS-1$ - String PROPERTIES = "properties"; //$NON-NLS-1$ - String PROPERTY = "property"; //$NON-NLS-1$ - String PROVIDER = "provider"; //$NON-NLS-1$ - String TRANSACTION_TYPE = "transaction-type"; //$NON-NLS-1$ - String VALUE = "value"; //$NON-NLS-1$ - String VERSION = "version"; //$NON-NLS-1$ -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PropertiesTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PropertiesTranslator.java deleted file mode 100644 index 4e893572e7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PropertiesTranslator.java +++ /dev/null @@ -1,43 +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.persistence.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class PropertiesTranslator extends Translator - implements PersistenceXmlMapper -{ - private Translator[] children; - - - public PropertiesTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (children == null) { - children = createChildren(); - } - return children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createPropertyTranslator() - }; - } - - private Translator createPropertyTranslator() { - return new PropertyTranslator(PROPERTY, PERSISTENCE_PKG.getXmlProperties_Properties()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PropertyTranslator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PropertyTranslator.java deleted file mode 100644 index 07755b320a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/translators/PropertyTranslator.java +++ /dev/null @@ -1,48 +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.persistence.translators; - -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.wst.common.internal.emf.resource.Translator; - -public class PropertyTranslator extends Translator - implements PersistenceXmlMapper -{ - private Translator[] children; - - - public PropertyTranslator(String domNameAndPath, EStructuralFeature aFeature) { - super(domNameAndPath, aFeature, END_TAG_NO_INDENT); - } - - @Override - public Translator[] getChildren(Object target, int versionID) { - if (children == null) { - children = createChildren(); - } - return children; - } - - protected Translator[] createChildren() { - return new Translator[] { - createNameTranslator(), - createValueTranslator() - }; - } - - private Translator createNameTranslator() { - return new Translator(NAME, PERSISTENCE_PKG.getXmlProperty_Name(), DOM_ATTRIBUTE); - } - - private Translator createValueTranslator() { - return new Translator(VALUE, PERSISTENCE_PKG.getXmlProperty_Value(), DOM_ATTRIBUTE); - } -} 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 fbf88c16b5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/synch/SynchronizeClassesJob.java +++ /dev/null @@ -1,133 +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.synch; - -import java.io.IOException; -import java.util.Iterator; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.WorkspaceJob; -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.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.PersistenceArtifactEdit; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -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.utility.internal.CollectionTools; - -/** - * 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(IProgressMonitor monitor) throws CoreException { - monitor.beginTask(JptCoreMessages.SYNCHRONIZING_CLASSES_TASK, 200); - - if (monitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - - JpaProject jpaProject = JptCorePlugin.getJpaProject(this.persistenceXmlFile.getProject()); - - PersistenceArtifactEdit persistenceArtifactEdit = PersistenceArtifactEdit.getArtifactEditForWrite(this.persistenceXmlFile.getProject()); - PersistenceResource persistenceResource = persistenceArtifactEdit.getResource(this.persistenceXmlFile); - - monitor.worked(25); - - XmlPersistence persistence = persistenceResource.getPersistence(); - - if (persistence == null) { - persistence = PersistenceFactory.eINSTANCE.createXmlPersistence(); - persistenceResource.getContents().add(persistence); - } - - XmlPersistenceUnit persistenceUnitResource; - - if (persistence.getPersistenceUnits().size() > 0) { - persistenceUnitResource = persistence.getPersistenceUnits().get(0); - } - else { - persistenceUnitResource = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - persistenceUnitResource.setName(this.persistenceXmlFile.getProject().getName()); - persistence.getPersistenceUnits().add(persistenceUnitResource); - } - - persistenceUnitResource.getClasses().clear(); - - monitor.worked(25); - - for (Iterator<String> stream = jpaProject.annotatedClassNames(); stream.hasNext(); ) { - String fullyQualifiedTypeName = stream.next(); - if ( ! mappingFileContains(jpaProject, fullyQualifiedTypeName)) { - XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - classRef.setJavaClass(fullyQualifiedTypeName); - persistenceUnitResource.getClasses().add(classRef); - } - } - - monitor.worked(100); - - try { - persistenceResource.save(null); - } - catch (IOException ioe) { - return new Status(IStatus.ERROR, JptCorePlugin.PLUGIN_ID, JptCoreMessages.ERROR_WRITING_FILE, ioe); - } - finally { - persistenceArtifactEdit.dispose(); - monitor.done(); - } - - return Status.OK_STATUS; - } - - private boolean mappingFileContains(JpaProject jpaProject, String fullyQualifiedTypeName) { - PersistenceXml persistenceXml = jpaProject.getRootContext().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/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/emf/ComponentUtilities.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/ComponentUtilities.java deleted file mode 100644 index ecd26d1f84..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/ComponentUtilities.java +++ /dev/null @@ -1,76 +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.emf; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TreeIterator; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFile; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.componentcore.resources.IVirtualResource; - -public class ComponentUtilities -{ - /** - * Return the deployment path for the given source file. If there is no - * corresponding deployment file, null will be returned. - */ - public static IPath computeDeployPath(IFile sourceFile) { - // Unfortunately, the only current way to do this is to exhaustively - // search all deployment files and attempt to match to this file. - // Bug 202943 has been logged to track this issue. - for (IVirtualFile virtualFile : CollectionTools.iterable(allVirtualFiles(sourceFile.getProject()))) { - for (IFile underlyingFile : virtualFile.getUnderlyingFiles()) { - if (sourceFile.equals(underlyingFile)) { - return virtualFile.getRuntimePath(); - } - } - } - return null; - } - - private static Iterator<IVirtualFile> allVirtualFiles(IProject project) { - return new FilteringIterator<IVirtualResource, IVirtualFile>(allVirtualResources(project)) { - @Override - protected boolean accept(IVirtualResource o) { - return o.getType() == IVirtualResource.FILE; - } - }; - } - - private static Iterator<IVirtualResource> allVirtualResources(IProject project) { - IVirtualComponent virtualComponent = ComponentCore.createComponent(project); - - if (virtualComponent == null) { - return EmptyIterator.instance(); - } - - return new TreeIterator<IVirtualResource>(virtualComponent.getRootFolder()) { - @Override - protected Iterator<? extends IVirtualResource> children(IVirtualResource next) { - if (next.getType() == IVirtualResource.FOLDER) { - try { - return CollectionTools.iterator(((IVirtualFolder) next).members()); - } - catch (CoreException ce) { /* fall through, return default case */ } - } - return EmptyIterator.instance(); - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/DOMUtilities.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/DOMUtilities.java deleted file mode 100644 index b23a0f1343..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/DOMUtilities.java +++ /dev/null @@ -1,23 +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.emf; - -import org.w3c.dom.Node; - -public class DOMUtilities - extends org.eclipse.wst.common.internal.emf.utilities.DOMUtilities -{ - /** - * Get the attribute Node with the specified name - */ - static public Node childAttributeNode(Node node, String attributeName) { - return node.getAttributes().getNamedItem(attributeName); - } -} 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 e74866a42c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,140 +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) { - declaration.addImport(this.annotationName); - annotation.setTypeName(declaration.getAst().newName(this.shortAnnotationName())); - this.addAnnotation(declaration, annotation); - } - - @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 ********** - - 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 shortAnnotationName() { - return this.shortName(this.annotationName); - } - - protected String shortName(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 eb69e6457a..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(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 df8556f693..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/AbstractNestedDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,419 +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; - - - // ********** 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); - } - } - - - // ********** 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); - } - } - - /** - * 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, 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, 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, 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(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 2fbc8a715f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapter.java +++ /dev/null @@ -1,493 +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; - - - // ********** 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); - } - } - } - - - // ********** 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"); - } - 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); - } - 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); - } - - /** - * 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"); - } 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); - } - 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"; - } - }; - - 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"; - } - }; - - 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"; - } - }; - -} 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 cb39dec2d0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumArrayDeclarationAnnotationElementAdapter.java +++ /dev/null @@ -1,163 +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.convertToShortNames(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, 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, ModifiedDeclaration declaration) { - return new String[] {this.resolveEnum(enumExpression)}; - } - - protected String resolveEnum(Expression expression) { - return JDTTools.resolveEnum(expression); - } - - @SuppressWarnings("unchecked") - private List<Expression> expressions(ArrayInitializer arrayInitializer) { - return arrayInitializer.expressions(); - } - - /** - * convert the fully-qualified enums to static imports and short names; - * NB: the imports are added as a side-effect :-( - */ - protected String[] convertToShortNames(String[] enums, ModifiedDeclaration declaration) { - if (enums == null) { - return null; - } - int len = enums.length; - String[] shortNames = new String[len]; - for (int i = len; i-- > 0; ) { - declaration.addStaticImport(enums[i]); // e.g. "javax.persistence.CascadeType.REFRESH" - shortNames[i] = this.shortName(enums[i]); // e.g. "EAGER" - } - return shortNames; - } - - protected String shortTypeName(String name) { - return name.substring(0, name.lastIndexOf('.')); - } - - protected String shortName(String name) { - return name.substring(name.lastIndexOf('.') + 1); - } - -} 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 aefb96e39e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/EnumDeclarationAnnotationElementAdapter.java +++ /dev/null @@ -1,106 +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(this.convertToShortName(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 to a static import and its short name - */ - protected String convertToShortName(String string, ModifiedDeclaration declaration) { - if (string == null) { - return null; - } - declaration.addStaticImport(string); // e.g. "javax.persistence.FetchType.EAGER" - return this.shortName(string); // e.g. "EAGER" - } - - protected String shortTypeName(String name) { - return name.substring(0, name.lastIndexOf('.')); - } - - protected String shortName(String name) { - return name.substring(name.lastIndexOf('.') + 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 17fbd32797..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); - } - - 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(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); - } - } - - /** - * 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, 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, 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); - } - } - - protected void removeElementNoAnnotation(ModifiedDeclaration declaration) { - // the element is already gone (?) - } - - protected void removeElementMarkerAnnotation(MarkerAnnotation annotation, ModifiedDeclaration declaration) { - // the element is already gone (?) - } - - protected void removeElementSingleMemberAnnotation(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 e3753d1dda..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/GenericVisitor.java +++ /dev/null @@ -1,795 +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 -//deleted code to limit the number of classes I had to copy -public class GenericVisitor extends ASTVisitor { - - public GenericVisitor() { - super(); - } - - /** - * @param visitJavadocTags <code>true</code> if doc comment tags are - * to be visited by default, and <code>false</code> otherwise - * @see Javadoc#tags() - * @see #visit(Javadoc) - * @since 3.0 - */ - public GenericVisitor(boolean visitJavadocTags) { - super(visitJavadocTags); - } - - //---- Hooks for subclasses ------------------------------------------------- - - protected boolean visitNode(ASTNode node) { - return true; - } - - protected void endVisitNode(ASTNode node) { - // do nothing - } - - @Override - public boolean visit(AnonymousClassDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(ArrayAccess node) { - return visitNode(node); - } - @Override - public boolean visit(ArrayCreation node) { - return visitNode(node); - } - @Override - public boolean visit(ArrayInitializer node) { - return visitNode(node); - } - @Override - public boolean visit(ArrayType node) { - return visitNode(node); - } - @Override - public boolean visit(AssertStatement node) { - return visitNode(node); - } - @Override - public boolean visit(Assignment node) { - return visitNode(node); - } - @Override - public boolean visit(Block node) { - return visitNode(node); - } - @Override - public boolean visit(BooleanLiteral node) { - return visitNode(node); - } - @Override - public boolean visit(BreakStatement node) { - return visitNode(node); - } - @Override - public boolean visit(CastExpression node) { - return visitNode(node); - } - @Override - public boolean visit(CatchClause node) { - return visitNode(node); - } - @Override - public boolean visit(CharacterLiteral node) { - return visitNode(node); - } - @Override - public boolean visit(ClassInstanceCreation node) { - return visitNode(node); - } - @Override - public boolean visit(CompilationUnit node) { - return visitNode(node); - } - @Override - public boolean visit(ConditionalExpression node) { - return visitNode(node); - } - @Override - public boolean visit(ConstructorInvocation node) { - return visitNode(node); - } - @Override - public boolean visit(ContinueStatement node) { - return visitNode(node); - } - @Override - public boolean visit(DoStatement node) { - return visitNode(node); - } - @Override - public boolean visit(EmptyStatement node) { - return visitNode(node); - } - @Override - public boolean visit(ExpressionStatement node) { - return visitNode(node); - } - @Override - public boolean visit(FieldAccess node) { - return visitNode(node); - } - @Override - public boolean visit(FieldDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(ForStatement node) { - return visitNode(node); - } - @Override - public boolean visit(IfStatement node) { - return visitNode(node); - } - @Override - public boolean visit(ImportDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(InfixExpression node) { - return visitNode(node); - } - @Override - public boolean visit(InstanceofExpression node) { - return visitNode(node); - } - @Override - public boolean visit(Initializer node) { - return visitNode(node); - } - @Override - public boolean visit(Javadoc node) { - return (super.visit(node)) ? visitNode(node) : false; - } - @Override - public boolean visit(LabeledStatement node) { - return visitNode(node); - } - @Override - public boolean visit(MethodDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(MethodInvocation node) { - return visitNode(node); - } - @Override - public boolean visit(NullLiteral node) { - return visitNode(node); - } - @Override - public boolean visit(NumberLiteral node) { - return visitNode(node); - } - @Override - public boolean visit(PackageDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(ParenthesizedExpression node) { - return visitNode(node); - } - @Override - public boolean visit(PostfixExpression node) { - return visitNode(node); - } - @Override - public boolean visit(PrefixExpression node) { - return visitNode(node); - } - @Override - public boolean visit(PrimitiveType node) { - return visitNode(node); - } - @Override - public boolean visit(QualifiedName node) { - return visitNode(node); - } - @Override - public boolean visit(ReturnStatement node) { - return visitNode(node); - } - @Override - public boolean visit(SimpleName node) { - return visitNode(node); - } - @Override - public boolean visit(SimpleType node) { - return visitNode(node); - } - @Override - public boolean visit(StringLiteral node) { - return visitNode(node); - } - @Override - public boolean visit(SuperConstructorInvocation node) { - return visitNode(node); - } - @Override - public boolean visit(SuperFieldAccess node) { - return visitNode(node); - } - @Override - public boolean visit(SuperMethodInvocation node) { - return visitNode(node); - } - @Override - public boolean visit(SwitchCase node) { - return visitNode(node); - } - @Override - public boolean visit(SwitchStatement node) { - return visitNode(node); - } - @Override - public boolean visit(SynchronizedStatement node) { - return visitNode(node); - } - @Override - public boolean visit(ThisExpression node) { - return visitNode(node); - } - @Override - public boolean visit(ThrowStatement node) { - return visitNode(node); - } - @Override - public boolean visit(TryStatement node) { - return visitNode(node); - } - @Override - public boolean visit(TypeDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(TypeDeclarationStatement node) { - return visitNode(node); - } - @Override - public boolean visit(TypeLiteral node) { - return visitNode(node); - } - @Override - public boolean visit(SingleVariableDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(VariableDeclarationExpression node) { - return visitNode(node); - } - @Override - public boolean visit(VariableDeclarationStatement node) { - return visitNode(node); - } - @Override - public boolean visit(VariableDeclarationFragment node) { - return visitNode(node); - } - @Override - public boolean visit(WhileStatement node) { - return visitNode(node); - } - @Override - public boolean visit(AnnotationTypeDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(AnnotationTypeMemberDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(BlockComment node) { - return visitNode(node); - } - @Override - public boolean visit(EnhancedForStatement node) { - return visitNode(node); - } - @Override - public boolean visit(EnumConstantDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(EnumDeclaration node) { - return visitNode(node); - } - @Override - public boolean visit(LineComment node) { - return visitNode(node); - } - @Override - public boolean visit(MarkerAnnotation node) { - return visitNode(node); - } - @Override - public boolean visit(MemberRef node) { - return visitNode(node); - } - @Override - public boolean visit(MemberValuePair node) { - return visitNode(node); - } - @Override - public boolean visit(MethodRef node) { - return visitNode(node); - } - @Override - public boolean visit(MethodRefParameter node) { - return visitNode(node); - } - @Override - public boolean visit(Modifier node) { - return visitNode(node); - } - @Override - public boolean visit(NormalAnnotation node) { - return visitNode(node); - } - @Override - public boolean visit(ParameterizedType node) { - return visitNode(node); - } - @Override - public boolean visit(QualifiedType node) { - return visitNode(node); - } - @Override - public boolean visit(SingleMemberAnnotation node) { - return visitNode(node); - } - @Override - public boolean visit(TagElement node) { - return visitNode(node); - } - @Override - public boolean visit(TextElement node) { - return visitNode(node); - } - @Override - public boolean visit(TypeParameter node) { - return visitNode(node); - } - @Override - public boolean visit(WildcardType node) { - return visitNode(node); - } - - @Override - public void endVisit(AnonymousClassDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(ArrayAccess node) { - endVisitNode(node); - } - @Override - public void endVisit(ArrayCreation node) { - endVisitNode(node); - } - @Override - public void endVisit(ArrayInitializer node) { - endVisitNode(node); - } - @Override - public void endVisit(ArrayType node) { - endVisitNode(node); - } - @Override - public void endVisit(AssertStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(Assignment node) { - endVisitNode(node); - } - @Override - public void endVisit(Block node) { - endVisitNode(node); - } - @Override - public void endVisit(BooleanLiteral node) { - endVisitNode(node); - } - @Override - public void endVisit(BreakStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(CastExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(CatchClause node) { - endVisitNode(node); - } - @Override - public void endVisit(CharacterLiteral node) { - endVisitNode(node); - } - @Override - public void endVisit(ClassInstanceCreation node) { - endVisitNode(node); - } - @Override - public void endVisit(CompilationUnit node) { - endVisitNode(node); - } - @Override - public void endVisit(ConditionalExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(ConstructorInvocation node) { - endVisitNode(node); - } - @Override - public void endVisit(ContinueStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(DoStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(EmptyStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(ExpressionStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(FieldAccess node) { - endVisitNode(node); - } - @Override - public void endVisit(FieldDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(ForStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(IfStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(ImportDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(InfixExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(InstanceofExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(Initializer node) { - endVisitNode(node); - } - @Override - public void endVisit(Javadoc node) { - endVisitNode(node); - } - @Override - public void endVisit(LabeledStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(MethodDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(MethodInvocation node) { - endVisitNode(node); - } - @Override - public void endVisit(NullLiteral node) { - endVisitNode(node); - } - @Override - public void endVisit(NumberLiteral node) { - endVisitNode(node); - } - @Override - public void endVisit(PackageDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(ParenthesizedExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(PostfixExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(PrefixExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(PrimitiveType node) { - endVisitNode(node); - } - @Override - public void endVisit(QualifiedName node) { - endVisitNode(node); - } - @Override - public void endVisit(ReturnStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(SimpleName node) { - endVisitNode(node); - } - @Override - public void endVisit(SimpleType node) { - endVisitNode(node); - } - @Override - public void endVisit(StringLiteral node) { - endVisitNode(node); - } - @Override - public void endVisit(SuperConstructorInvocation node) { - endVisitNode(node); - } - @Override - public void endVisit(SuperFieldAccess node) { - endVisitNode(node); - } - @Override - public void endVisit(SuperMethodInvocation node) { - endVisitNode(node); - } - @Override - public void endVisit(SwitchCase node) { - endVisitNode(node); - } - @Override - public void endVisit(SwitchStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(SynchronizedStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(ThisExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(ThrowStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(TryStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(TypeDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(TypeDeclarationStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(TypeLiteral node) { - endVisitNode(node); - } - @Override - public void endVisit(SingleVariableDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(VariableDeclarationExpression node) { - endVisitNode(node); - } - @Override - public void endVisit(VariableDeclarationStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(VariableDeclarationFragment node) { - endVisitNode(node); - } - @Override - public void endVisit(WhileStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(AnnotationTypeDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(AnnotationTypeMemberDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(BlockComment node) { - endVisitNode(node); - } - @Override - public void endVisit(EnhancedForStatement node) { - endVisitNode(node); - } - @Override - public void endVisit(EnumConstantDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(EnumDeclaration node) { - endVisitNode(node); - } - @Override - public void endVisit(LineComment node) { - endVisitNode(node); - } - @Override - public void endVisit(MarkerAnnotation node) { - endVisitNode(node); - } - @Override - public void endVisit(MemberRef node) { - endVisitNode(node); - } - @Override - public void endVisit(MemberValuePair node) { - endVisitNode(node); - } - @Override - public void endVisit(MethodRef node) { - endVisitNode(node); - } - @Override - public void endVisit(MethodRefParameter node) { - endVisitNode(node); - } - @Override - public void endVisit(Modifier node) { - endVisitNode(node); - } - @Override - public void endVisit(NormalAnnotation node) { - endVisitNode(node); - } - @Override - public void endVisit(ParameterizedType node) { - endVisitNode(node); - } - @Override - public void endVisit(QualifiedType node) { - endVisitNode(node); - } - @Override - public void endVisit(SingleMemberAnnotation node) { - endVisitNode(node); - } - @Override - public void endVisit(TagElement node) { - endVisitNode(node); - } - @Override - public void endVisit(TextElement node) { - endVisitNode(node); - } - @Override - public void endVisit(TypeParameter node) { - endVisitNode(node); - } - @Override - public void endVisit(WildcardType node) { - endVisitNode(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 0de59055c8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTAttribute.java +++ /dev/null @@ -1,70 +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.CommandExecutorProvider; - -/** - * 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, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider) { - super(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider); - } - - protected JDTAttribute( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, annotationEditFormatter); - } - - - // ********** Member/Attribute implementation ********** - - public boolean isField() { - return false; - } - - public boolean isMethod() { - 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 bdcbec67db..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTFieldAttribute.java +++ /dev/null @@ -1,181 +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 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.CommandExecutorProvider; - -/** - * 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, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider) { - this(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, DefaultAnnotationEditFormatter.instance()); - } - - public JDTFieldAttribute( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, annotationEditFormatter); - } - - /** - * constructor for testing - */ - public JDTFieldAttribute(Type declaringType, String name, int occurrence, ICompilationUnit compilationUnit) { - this(declaringType, name, occurrence, compilationUnit, CommandExecutorProvider.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(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"; - } - @Override - public String toString() { - return "FIELD_DECLARATION_SELECTOR"; - } - }; - - 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"; - } - @Override - public String toString() { - return "VARIABLE_DECLARATION_FRAGMENT_SELECTOR"; - } - }; - -} 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 fec82d670a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMember.java +++ /dev/null @@ -1,236 +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.CommandExecutorProvider; -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 CommandExecutorProvider modifySharedDocumentCommandExecutorProvider; - - /** this will format the member's annotations a bit */ - private final AnnotationEditFormatter annotationEditFormatter; - - - // ********** constructors ********** - - protected JDTMember( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider) { - this(declaringType, name, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, DefaultAnnotationEditFormatter.instance()); - } - - protected JDTMember( - Type declaringType, - String name, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - super(); - this.declaringType = declaringType; - this.name = name; - this.occurrence = occurrence; - this.compilationUnit = compilationUnit; - this.modifySharedDocumentCommandExecutorProvider = modifySharedDocumentCommandExecutorProvider; - 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 headlessly, a "working copy" must be created - * (at least as far as I can tell ~kfm) - * - when editing via a plain text editor, make a working copy or else things are screwed - * up the second time you edit through the XmlPersistence XmlProperties View - */ - protected void edit_(Editor editor) throws JavaModelException, BadLocationException { - if ( ! this.compilationUnit.isWorkingCopy()) { - 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()); - - CompilationUnit astRoot = this.buildASTRoot(); - astRoot.recordModifications(); - - editor.edit(this.getModifiedDeclaration(astRoot)); - - TextEdit edits = astRoot.rewrite(doc, this.compilationUnit.getJavaProject().getOptions(true)); - if (sharedDocument) { - this.getModifySharedDocumentCommandExecutor().execute(new ModifySharedDocumentCommand(edits, doc)); - } else { - this.applyEdits(edits, doc); - } - - if ( ! sharedDocument) { - 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); - } - - protected CommandExecutor getModifySharedDocumentCommandExecutor() { - return this.modifySharedDocumentCommandExecutorProvider.getCommandExecutor(); - } - - - // ********** 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 d0844d6606..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTMethodAttribute.java +++ /dev/null @@ -1,188 +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 java.beans.Introspector; -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.CommandExecutorProvider; -import org.eclipse.jpt.utility.JavaType; -import org.eclipse.jpt.utility.MethodSignature; -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, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider) { - return newInstance(declaringType, signature, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, DefaultAnnotationEditFormatter.instance()); - } - - public static JDTMethodAttribute newInstance( - Type declaringType, - MethodSignature signature, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - return new JDTMethodAttribute(declaringType, signature, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, annotationEditFormatter); - } - - public JDTMethodAttribute( - Type declaringType, - MethodSignature methodSignature, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider) { - this(declaringType, methodSignature, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, DefaultAnnotationEditFormatter.instance()); - } - - public JDTMethodAttribute( - Type declaringType, - MethodSignature methodSignature, - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, methodSignature.getName(), occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, 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, CommandExecutorProvider.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(org.eclipse.jdt.core.dom.MethodDeclaration, int)."); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName()); - } - - /** - * return "foo" for a method named "getFoo" or "isFoo" - */ - public String getAttributeName() { - String name = this.getName_(); - int beginIndex = 0; - if (name.startsWith("get")) { - beginIndex = 3; - } else if (name.startsWith("is")) { - beginIndex = 2; - } - return Introspector.decapitalize(name.substring(beginIndex)); - } - - public ITypeBinding getTypeBinding(CompilationUnit astRoot) { - IMethodBinding methodBinding = getBodyDeclaration(astRoot).resolveBinding(); - if (methodBinding != null) { - return methodBinding.getReturnType(); - } - return null; - } - - @Override - public boolean isMethod() { - return true; - } - - public boolean isPersistable(CompilationUnit astRoot) { - IMethodBinding binding = this.getBinding(astRoot); - return (binding == null) ? false : JPTTools.methodIsPersistablePropertyGetter(binding); - } - - - // ********** internal ********** - - protected MethodDeclaration[] getDeclaringTypeMethodDeclarations(CompilationUnit astRoot) { - return this.getDeclaringTypeDeclaration(astRoot).getMethods(); - } - -} 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 266fa7c8a0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTModifiedDeclaration.java +++ /dev/null @@ -1,416 +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.ICompilationUnit; -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; - -/** - * - */ -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)); - } - - - // ********** public methods ********** - - public ASTNode getDeclaration() { - return this.adapter.declaration(); - } - - /** - * Return the declaration's list of modifiers. - * Element type: org.eclipse.jdt.core.dom.IExtendedModifier - */ - public List<IExtendedModifier> modifiers() { - return this.adapter.modifiers(); - } - - public AST getAst() { - return this.getDeclaration().getAST(); - } - - public CompilationUnit getCompilationUnit() { - return (CompilationUnit) this.getDeclaration().getRoot(); - } - - public ICompilationUnit getICompilationUnit() { - return (ICompilationUnit) this.getCompilationUnit().getJavaElement(); - } - - /** - * Return the declaration's annotations. - */ - public Iterator<Annotation> annotations() { - return new FilteringIterator<IExtendedModifier, Annotation>(this.modifiers().iterator()) { - @Override - protected boolean accept(IExtendedModifier next) { - return next.isAnnotation(); - } - }; - } - - 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; - } - - /** - * Return whether the declaration has an annotation with the specified name. - */ - public boolean containsAnnotationNamed(String annotationName) { - return this.getAnnotationNamed(annotationName) != null; - } - - /** - * Add the specified annotation to the declaration. - * By convention annotations precede the "standard" (JLS2) modifiers; - * though, technically, they can be interspersed. - */ - public void addAnnotation(Annotation annotation) { - List<IExtendedModifier> modifiers = this.modifiers(); - 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 - } - - public void removeAnnotationNamed(String annotationName) { - for (Iterator<IExtendedModifier> stream = this.modifiers().iterator(); stream.hasNext(); ) { - IExtendedModifier modifier = stream.next(); - if (modifier.isAnnotation()) { - if (this.annotationIsNamed((Annotation) modifier, annotationName)) { - stream.remove(); - break; - } - } - } - } - - /** - * Remove the specified annotation from the declaration. - */ - public void removeAnnotation(Annotation annotation) { - if ( ! this.modifiers().remove(annotation)) { - throw new IllegalArgumentException("invalid annotation: " + annotation); - } - } - - /** - * Replace the specified old annotation with the specified new annotation. - */ - public void replaceAnnotation(Annotation oldAnnotation, Annotation newAnnotation) { - for (ListIterator<IExtendedModifier> stream = this.modifiers().listIterator(); stream.hasNext(); ) { - if (stream.next().equals(oldAnnotation)) { - stream.set(newAnnotation); - return; - } - } - throw new IllegalArgumentException("invalid old annotation: " + oldAnnotation); - } - - public void replaceAnnotationNamed(String oldAnnotationName, Annotation newAnnotation) { - List<IExtendedModifier> modifiers = this.modifiers(); - 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); - } - - public void addImport(String importName) { - this.addImport(importName, false); - } - - public void addStaticImport(String importName) { - this.addImport(importName, true); - } - - public void addImport(String importName, boolean static_) { - if (importName.indexOf('.') != -1) { - this.addImportTo(this.getCompilationUnit(), importName, static_); - } - } - - public String getImportFor(String shortName) { - return this.getImportFor(shortName, false); - } - - public String getStaticImportFor(String shortName) { - return this.getImportFor(shortName, true); - } - - // TODO handle wildcards - public String getImportFor(String shortName, boolean static_) { - if (shortName.indexOf('.') != -1) { - return shortName; - } - List<ImportDeclaration> imports = this.imports(this.getCompilationUnit()); - for (ImportDeclaration importDeclaration : imports) { - if (this.importIsFor(importDeclaration, shortName, static_)) { - return importDeclaration.getName().getFullyQualifiedName(); - } - } - return null; - } - - protected boolean importIsFor(ImportDeclaration importDeclaration, String shortName, boolean static_) { - if (importDeclaration.isStatic() != static_) { - return false; - } - String importDeclarationName = importDeclaration.getName().getFullyQualifiedName(); - return importDeclarationName.endsWith(shortName); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.adapter.toString()); - } - - - // ********** internal methods ********** - - public boolean annotationIsNamed(Annotation annotation, String name) { - String qualifiedName = this.qualifiedName(annotation); - return (qualifiedName != null) && qualifiedName.equals(name); - } - - // TODO - private String qualifiedName(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... :-( - return this.getImportFor(annotation.getTypeName().getFullyQualifiedName()); // look for a matching import - - // OLD METHOD SOURCE: -// String name = annotation.getTypeName().getFullyQualifiedName(); -// if (name.indexOf('.') != -1) { -// return name; // name is already qualified -// } -// String resolvedName = JDTTools.resolve(name, this.type()); -// // 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... :-( -// return this.importFor(name); // look for a matching import - } - - /** - * Return whether the specified import was added without a collision. - */ - // TODO handle collisions (e.g. java.util.Date vs. java.sql.Date) - protected void addImportTo(CompilationUnit astRoot, String importName, boolean static_) { - List<ImportDeclaration> imports = this.imports(astRoot); - if (this.importsInclude(imports, importName, static_)) { - return; - } - AST ast = astRoot.getAST(); - ImportDeclaration import_ = ast.newImportDeclaration(); - import_.setName(ast.newName(importName)); - import_.setStatic(static_); - imports.add(import_); - } - - @SuppressWarnings("unchecked") - protected List<ImportDeclaration> imports(CompilationUnit astRoot) { - return astRoot.imports(); - } - - protected boolean importsInclude(List<ImportDeclaration> imports, String importName, boolean static_) { - for (ImportDeclaration importDeclaration : imports) { - if (this.importIncludes(importDeclaration, importName, static_)) { - return true; - } - } - return false; - } - - protected boolean importIncludes(ImportDeclaration importDeclaration, String importName, boolean static_) { - if (importDeclaration.isStatic() != static_) { - return false; - } - String importDeclarationName = importDeclaration.getName().getFullyQualifiedName(); - if (importName.equals(importDeclarationName)) { - return true; - } - if (importDeclaration.isOnDemand() - && this.onDemandNameFor(importName).equals(importDeclarationName)) { - return true; - } - return false; - } - - protected String onDemandNameFor(String importName) { - int lastPeriod = importName.lastIndexOf('.'); - return (lastPeriod == -1) ? "" : importName.substring(0, lastPeriod); - } - - - // ********** declaration adapter interface and implementations ********** - - /** - * Define common protocol among the various "declarations". - */ - public interface Adapter { - - /** - * Return the adapted "declaration". - */ - ASTNode declaration(); - - /** - * Return the "declaration"'s list of modifiers. - * Element type: org.eclipse.jdt.core.dom.IExtendedModifier - */ - List<IExtendedModifier> modifiers(); - - } - - public static class BodyDeclarationAdapter implements Adapter { - private final BodyDeclaration declaration; - public BodyDeclarationAdapter(BodyDeclaration declaration) { - super(); - this.declaration = declaration; - } - public ASTNode declaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> modifiers() { - 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 declaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> modifiers() { - 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 declaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> modifiers() { - 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 declaration() { - return this.declaration; - } - @SuppressWarnings("unchecked") - public List<IExtendedModifier> modifiers() { - 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 2050011ede..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTTools.java +++ /dev/null @@ -1,119 +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 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; - -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); - parser.setResolveBindings(true); - parser.setBindingsRecovery(true); // see bugs 196200, 222735 - return (CompilationUnit) parser.createAST(null); - } - - 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 why this is null sometimes - } - if (binding.getKind() != IBinding.VARIABLE) { - return null; - } - IVariableBinding variableBinding = (IVariableBinding) binding; - return variableBinding.getType().getQualifiedName() + "." + variableBinding.getName(); - } - - public static String resolveAnnotation(Annotation node) { - IAnnotationBinding annotationBinding = node.resolveAnnotationBinding(); - if (annotationBinding == null) { - return null; - } - ITypeBinding annotationTypeBinding = annotationBinding.getAnnotationType(); - if (annotationTypeBinding == null) { - return null; - } - return annotationTypeBinding.getQualifiedName(); - } - - public static String resolveFullyQualifiedName(Expression expression) { - if (expression.getNodeType() == ASTNode.TYPE_LITERAL) { - ITypeBinding resolvedTypeBinding = ((TypeLiteral) expression).getType().resolveBinding(); - if (resolvedTypeBinding != null) { - return resolvedTypeBinding.getQualifiedName(); - } - } - 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(); - } - -} 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 22ca6c302b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTType.java +++ /dev/null @@ -1,175 +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 java.util.List; - -import org.eclipse.jdt.core.ICompilationUnit; -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.CommandExecutorProvider; - -/** - * 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, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider) { - this(typeDeclaration, compilationUnit, modifySharedDocumentCommandExecutorProvider, DefaultAnnotationEditFormatter.instance()); - } - - /** - * constructor for the compilation unit's primary type - */ - public JDTType( - TypeDeclaration typeDeclaration, // exclude annotations and enums - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - this(null, typeDeclaration, 1, compilationUnit, modifySharedDocumentCommandExecutorProvider, annotationEditFormatter); - } - - /** - * constructor for nested types - */ - public JDTType( - Type declaringType, - TypeDeclaration typeDeclaration, // exclude annotations and enums - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider) { - this(declaringType, typeDeclaration, occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, DefaultAnnotationEditFormatter.instance()); - } - - /** - * constructor for nested types - */ - public JDTType( - Type declaringType, - TypeDeclaration typeDeclaration, // exclude annotations and enums - int occurrence, - ICompilationUnit compilationUnit, - CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, - AnnotationEditFormatter annotationEditFormatter) { - super(declaringType, typeDeclaration.getName().getFullyQualifiedName(), occurrence, compilationUnit, modifySharedDocumentCommandExecutorProvider, annotationEditFormatter); - } - - /** - * constructor for testing - */ - public JDTType(Type declaringType, String name, int occurrence, ICompilationUnit compilationUnit) { - super(declaringType, name, occurrence, compilationUnit, CommandExecutorProvider.Default.instance(), DefaultAnnotationEditFormatter.instance()); - } - - - // ********** Member/Type implementation ********** - - public ITypeBinding getBinding(CompilationUnit astRoot) { - return this.getBodyDeclaration(astRoot).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(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<TypeDeclaration> typeDeclarations) { - return this.getTypeDeclaration(typeDeclarations.toArray(new TypeDeclaration[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(TypeDeclaration[] typeDeclarations) { - String name = this.getName_(); - int occurrence = this.getOccurrence(); - int count = 0; - for (TypeDeclaration typeDeclaration : typeDeclarations) { - if (typeDeclaration.getName().getFullyQualifiedName().equals(name)) { - count++; - if (count == occurrence) { - return typeDeclaration; - } - } - } - // 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; - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - protected static List<TypeDeclaration> types(CompilationUnit astRoot) { - return astRoot.types(); - } - -} 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 dcaed04e05..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java +++ /dev/null @@ -1,182 +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.dom.IMethodBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.IVariableBinding; -import org.eclipse.jdt.core.dom.Modifier; - -public class JPTTools { - - /** - * 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(IVariableBinding field) { - int modifiers = field.getModifiers(); - if (Modifier.isStatic(modifiers)) { - return false; - } - if (Modifier.isTransient(modifiers)) { - return false; - } - return true; - } - - /** - * Return whether the specified method is a "getter" method that - * represents a property that may be "persisted". - */ - public static boolean methodIsPersistablePropertyGetter(IMethodBinding methodBinding) { - if (methodHasBadModifiers(methodBinding)) { - return false; - } - - ITypeBinding returnType = methodBinding.getReturnType(); - if (returnType == null) { - return false; - } - String returnTypeName = returnType.getQualifiedName(); - if (returnTypeName.equals("void")) { - return false; - } - if (methodBinding.getParameterTypes().length != 0) { - return false; - } - - String methodName = methodBinding.getName(); - int beginIndex = 0; - boolean booleanGetter = false; - if (methodName.startsWith("is")) { - if (returnTypeName.equals("boolean")) { - beginIndex = 2; - } else { - return false; - } - } else { - if (methodName.startsWith("get")) { - beginIndex = 3; - if (returnTypeName.equals("boolean")) { - booleanGetter = true; - } - } else { - return false; - } - } - - String capitalizedAttributeName = methodName.substring(beginIndex); - // if the type has both methods: - // boolean isProperty() - // boolean getProperty() - // then #isProperty() takes precedence and we ignore #getProperty() - // (see the JavaBeans spec 1.01) - if (booleanGetter) { - IMethodBinding isMethod = methodBindingNoParameters(methodBinding.getDeclaringClass(), "is" + capitalizedAttributeName); - if (isMethod == null) { - return false; - } - if (isMethod.getReturnType().getName().equals("boolean")) { - return false; - } - } - IMethodBinding setMethod = methodBindingOneParameter(methodBinding.getDeclaringClass(), "set" + capitalizedAttributeName, returnTypeName); - if (setMethod == null) { - return false; - } - if (methodHasBadModifiers(setMethod)) { - return false; - } - if ( ! setMethod.getReturnType().getName().equals("void")) { - return false; - } - return true; - } - - private static IMethodBinding methodBindingNoParameters(ITypeBinding typeBinding, String methodName) { - for (IMethodBinding method : typeBinding.getDeclaredMethods()) { - if (method.getName().equals(methodName)) { - if (method.getParameterTypes().length == 0) { - return method; - } - } - } - return null; - } - - private static IMethodBinding methodBindingOneParameter(ITypeBinding typeBinding, String methodName, String parameterTypeName) { - for (IMethodBinding method : typeBinding.getDeclaredMethods()) { - if (method.getName().equals(methodName)) { - if (method.getParameterTypes().length == 1) { - if (method.getParameterTypes()[0].getQualifiedName().equals(parameterTypeName)) { - return method; - } - } - } - } - return null; - } - - /** - * Return whether the specified method's modifiers prevent it - * from being a getter or setter for a "persistent" property. - */ - private static boolean methodHasBadModifiers(IMethodBinding methodBinding) { - if (methodBinding.isConstructor()) { - return true; - } - int modifiers = methodBinding.getModifiers(); - if (Modifier.isStatic(modifiers)) { - return true; - } - if (Modifier.isFinal(modifiers)) { - return true; - } - if ( ! (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers))) { - return true; - } - return false; - } - - /** - * Return whether the type may be "persisted", ie marked as Entity, MappedSuperclass, Embeddable - */ - //TODO should persistability be dependent on having a no-arg constructor or should that just be validation? - //seems like final, or a member type being static could be dealt with through validation instead of filtering them out. - public static boolean typeIsPersistable(ITypeBinding typeBinding) { - if (typeBinding.isInterface()) { - return false; - } - if (typeBinding.isAnnotation()) { - return false; - } - if (typeBinding.isEnum()) { - return false; - } - if (typeBinding.isLocal()) { - return false; - } - if (typeBinding.isAnonymous()) { - return false; - } - int modifiers = typeBinding.getModifiers(); - if (Modifier.isFinal(modifiers)) { - return false; - } - if (typeBinding.isMember()) { - if (!Modifier.isStatic(modifiers)) { - return false; - } - } - return true; - } - -} 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 7e03591179..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); - } - 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); - } - } - - /** - * 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"; - } - }; - - 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"; - } - }; - -} 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 17ad84b331..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 non-instantiability. - */ - 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 968658eea3..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(newValue); - } 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 1f6cc3881f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/ShortCircuitArrayAnnotationElementAdapter.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.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/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 b944542c64..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java +++ /dev/null @@ -1,77 +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; - -@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_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_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 GENERATOR_DUPLICATE_NAME = "GENERATOR_DUPLICATE_NAME"; - public static final String QUERY_DUPLICATE_NAME = "QUERY_DUPLICATE_NAME"; - public static final String ENTITY_MAPPINGS_MULTIPLE_METADATA = "ENTITY_MAPPINGS_MULTIPLE_METADATA"; - public static final String PERSISTENT_TYPE_UNSPECIFIED_CONTEXT = "PERSISTENT_TYPE_UNSPECIFIED_CONTEXT"; - 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 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_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_SCHEMA = "TABLE_UNRESOLVED_SCHEMA"; - public static final String TABLE_UNRESOLVED_NAME = "TABLE_UNRESOLVED_NAME"; - 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_SCHEMA = "JOIN_TABLE_UNRESOLVED_SCHEMA"; - 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 VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME"; - 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 VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME = "VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME"; - 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"; - -} 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 508c1d2615..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidator.java +++ /dev/null @@ -1,154 +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 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.resources.ResourcesPlugin; -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.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jpt.core.JpaModel; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.wst.validation.internal.core.ValidationException; -import org.eclipse.wst.validation.internal.operations.IWorkbenchContext; -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.IValidatorJob; - -/** - * This class is referenced in the JPA extension for the - * WTP validator extension point. - */ -public class JpaValidator implements IValidatorJob { - - - // ********** IValidator implementation ********** - - public void validate(IValidationContext context, IReporter reporter) throws ValidationException { - reporter.removeAllMessages(this); - - for (Iterator<IMessage> stream = this.validationMessages(context); stream.hasNext(); ) { - reporter.addMessage(this, stream.next()); - } - } - - private Iterator<IMessage> validationMessages(IValidationContext context) { - IProject project = ((IProjectValidationContext) context).getProject(); - return JptCorePlugin.getJpaProject(project).validationMessages(); - } - - public void cleanup(IReporter reporter) { - // nothing to do - } - - - // ********** IValidatorJob implementation ********** - - public ISchedulingRule getSchedulingRule(IValidationContext context) { - // don't know what to return here. my guess is that we want to return - // the resource that is possibly being changed during our validation, - // and since many resources in the project may be changed during this - // validation, returning the project makes the most sense. - return ((IWorkbenchContext) context).getProject(); - } - - public IStatus validateInJob(IValidationContext context, IReporter reporter) throws ValidationException { - if (reporter.isCancelled()) { - return Status.CANCEL_STATUS; - } - this.validate(context, reporter); - return OK_STATUS; - } - - - // ********** marker clean-up ********** - - private static final CollectionChangeListener JPA_MODEL_LISTENER = new LocalCollectionChangeListener(); - - static { - JptCorePlugin.getJpaModel().addCollectionChangeListener(JpaModel.JPA_PROJECTS_COLLECTION, JPA_MODEL_LISTENER); - } - - /** - * When a JPA project is removed this listener will schedule a job to - * remove all the markers associated with the JPA project. - */ - private static class LocalCollectionChangeListener implements CollectionChangeListener { - - LocalCollectionChangeListener() { - super(); - } - - public void itemsAdded(CollectionChangeEvent event) { - // ignore - } - - /** - * For now, we expect JPA projects to be removed one at a time. - */ - public void itemsRemoved(CollectionChangeEvent event) { - @SuppressWarnings("unchecked") - Iterator<JpaProject> items = (Iterator<JpaProject>) event.items(); - Job j = new DeleteMarkersJob(items.next()); - j.schedule(); - if (items.hasNext()) { - throw new UnsupportedOperationException("unexpected event"); - } - } - - public void collectionCleared(CollectionChangeEvent event) { - throw new UnsupportedOperationException("unexpected event"); - } - - public void collectionChanged(CollectionChangeEvent event) { - throw new UnsupportedOperationException("unexpected event"); - } - - } - - /** - * Delete all the markers associated with the specified JPA project. - */ - private static class DeleteMarkersJob extends Job { - private final JpaProject jpaProject; - - DeleteMarkersJob(JpaProject jpaProject) { - super("Delete Markers"); - this.jpaProject = jpaProject; - } - - @Override - protected IStatus run(IProgressMonitor monitor) { - IProject project = this.jpaProject.getProject(); - if (project.isOpen()) {//no need to remove markers if project has been closed - try { - IMarker[] markers = project.findMarkers(JptCorePlugin.VALIDATION_MARKER_ID, true, IResource.DEPTH_INFINITE); - ResourcesPlugin.getWorkspace().deleteMarkers(markers); - } catch (CoreException ex) { - JptCorePlugin.log(ex); // not much else we can do - } - } - return Status.OK_STATUS; - } - - } - -} |