summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-10-01 17:39:09 (EDT)
committerKaren Butzke2012-10-02 07:02:49 (EDT)
commit71034c9968af268b28423fa8d61c732ffa4ace5a (patch)
tree6ae23c7560bfa7593339280fd734d38ee99e19ce
parentc6290a0cce69b11191ea4a98fb707d53fbab50df (diff)
downloadwebtools.dali-71034c9968af268b28423fa8d61c732ffa4ace5a.zip
webtools.dali-71034c9968af268b28423fa8d61c732ffa4ace5a.tar.gz
webtools.dali-71034c9968af268b28423fa8d61c732ffa4ace5a.tar.bz2
bug 231872, bug 278838, bug 378370 - refactoring JPA root structure nodes to avoid unnecessary changes when an entity is listed in 2 locations
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java22
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java66
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaFile.java64
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java5
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java2
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java2
23 files changed, 230 insertions, 125 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java
index 993a020..2a245f3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java
@@ -66,7 +66,15 @@ public interface JpaFile
*/
JptResourceModel getResourceModel(IContentType contentType);
-
+ /**
+ * Update the collection of root structure nodes.
+ * This is called at the end of the project update.
+ *
+ * @see JpaStructureNode#gatherRootStructureNodes(JpaFile, java.util.Collection)
+ */
+ void updateRootStructureNodes();
+
+
// ********** root structure nodes **********
/**
@@ -81,28 +89,6 @@ public interface JpaFile
int getRootStructureNodesSize();
/**
- * Add a root structure node.
- * There is the potential for multiple root structure nodes
- * for a particular key. For example, a Java type can be listed
- * both as a {@code <class>} in the <code>persistence.xml</code> file
- * and as an {@code <entity>} in
- * an <code>orm.xml</code> file. In this case, the Jave type in
- * the <code>orm.xml</code> file must set
- * the root structure node <em>after</em> the Java type in the
- * <code>persistence.xml</code> file.
- * Last one in during project <em>update</em> wins.
- */
- void addRootStructureNode(Object key, JpaStructureNode rootStructureNode);
-
- /**
- * Remove the root structure node for the specified key if its current value
- * is the same as the specified node.
- *
- * @see #addRootStructureNode(Object, JpaStructureNode)
- */
- void removeRootStructureNode(Object key, JpaStructureNode rootStructureNode);
-
- /**
* Return the structure node best corresponding to the location in the file.
*/
JpaStructureNode getStructureNode(int textOffset);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java
index c40cb8c..f73985f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core;
+import java.util.Collection;
+
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.StringTools;
@@ -78,6 +80,13 @@ public interface JpaStructureNode
Class<? extends JpaStructureNode> getType();
/**
+ * Add the appropriate root structure nodes to the collection that
+ * correspond to the given JPA file.
+ * @see JpaFile#getRootStructureNodes()
+ */
+ void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes);
+
+ /**
* Dispose the structure node and its children.
* Typically this would be used to update the structure node's
* JPA file's root structure nodes.
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
index 3137375..7ba70e3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
@@ -2043,9 +2043,15 @@ public abstract class AbstractJpaProject
// TODO pass the monitor down
protected IStatus update(@SuppressWarnings("unused") IProgressMonitor monitor) {
this.rootContextNode.update();
+ this.updateRootStructureNodes();
return Status.OK_STATUS;
}
+ protected void updateRootStructureNodes() {
+ for (JpaFile jpaFile : this.getJpaFiles()) {
+ jpaFile.updateRootStructureNodes();
+ }
+ }
// ********** update command listener **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
index 786dfd4..18c0671 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.java;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jdt.core.IJavaElement;
@@ -25,6 +26,7 @@ import org.eclipse.jpt.common.utility.internal.ReflectionTools;
import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.CollectionMapping;
@@ -106,6 +108,11 @@ public abstract class AbstractJavaPersistentAttribute
this.updateMapping();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ throw new UnsupportedOperationException();
+ }
+
+
// ********** name **********
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
index 88e9124..1dcc75a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
@@ -117,7 +117,6 @@ public abstract class AbstractJavaPersistentType
this.setDefaultAccess(this.buildDefaultAccess());
this.mapping.update();
this.updateAttributes();
- this.registerRootStructureNode();
}
@@ -977,25 +976,14 @@ public abstract class AbstractJavaPersistentType
return this.resourceType.getNameTextRange();
}
- public void dispose() {
- this.unregisterRootStructureNode();
- }
-
- protected void registerRootStructureNode() {
- JpaFile jpaFile = this.getJpaFile();
- // the JPA file can be null if the resource type is "external"
- if (jpaFile != null) {
- jpaFile.addRootStructureNode(this.name, this);
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.getResource().equals(jpaFile.getFile())) {
+ rootStructureNodes.add(this);
}
}
- protected void unregisterRootStructureNode() {
- JpaFile jpaFile = this.getJpaFile();
- // the JPA file can be null if the .java file was deleted
- // or the resource type is "external"
- if (jpaFile != null) {
- jpaFile.removeRootStructureNode(this.name, this);
- }
+ public void dispose() {
+ //nothing
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
index 952fb6c..204a0d6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.jpa.core.internal.context.orm;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -34,6 +35,7 @@ import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AccessType;
@@ -173,6 +175,14 @@ public abstract class AbstractEntityMappings
this.queryContainer.update();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ for (PersistentType persistentType : this.getPersistentTypes()) {
+ persistentType.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ if (!rootStructureNodes.isEmpty()) { //short-circuit, first one wins
+ return;
+ }
+ }
+ }
// ********** overrides **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java
index fb641cc..749d57e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.orm;
+import java.util.Collection;
import java.util.List;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
@@ -22,6 +23,7 @@ import org.eclipse.jpt.common.core.utility.jdt.TypeBinding;
import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.CollectionMapping;
@@ -108,6 +110,10 @@ public abstract class SpecifiedOrmPersistentAttribute
}
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ throw new UnsupportedOperationException();
+ }
+
// ********** mapping **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java
index 30f5eda..35e0074 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java
@@ -43,6 +43,7 @@ import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.PersistentType;
@@ -145,6 +146,12 @@ public abstract class SpecifiedOrmPersistentType
this.setDeclaringTypeName(this.buildDeclaringTypeName());
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.javaPersistentType != null) {
+ this.javaPersistentType.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+ }
+
// ********** mapping **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java
index 4e0f7e5..ee08808 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.orm;
+import java.util.Collection;
import java.util.List;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
@@ -17,6 +18,7 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.TypeBinding;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.PersistentType;
@@ -309,6 +311,10 @@ public class VirtualOrmPersistentAttribute
return null;
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ throw new UnsupportedOperationException();
+ }
+
public void dispose() {
if (this.originalJavaAttribute != null) {
this.originalJavaAttribute.removeStateChangeListener(this.getOriginalJavaAttributeListener());
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java
index 7000456..1f0cd57 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.persistence;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -82,6 +83,11 @@ public abstract class AbstractJarFileRef
this.updateJarFile();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.jarFile != null) {
+ this.jarFile.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+ }
// ********** JpaStructureNode implementation **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
index b27bb6f..4485663 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.persistence;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -19,13 +20,13 @@ import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.Generator;
import org.eclipse.jpt.jpa.core.context.MappingFile;
import org.eclipse.jpt.jpa.core.context.MappingFilePersistenceUnitMetadata;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.Query;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
@@ -76,6 +77,12 @@ public abstract class AbstractMappingFileRef<MF extends MappingFile>
this.updateMappingFile();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.mappingFile != null) {
+ this.mappingFile.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+ }
+
// ********** file name **********
@@ -239,7 +246,7 @@ public abstract class AbstractMappingFileRef<MF extends MappingFile>
}
public Iterable<? extends PersistentType> getPersistentTypes() {
- return (this.mappingFile != null) ? this.mappingFile.getPersistentTypes() : EmptyIterable.<JavaPersistentType>instance();
+ return (this.mappingFile != null) ? this.mappingFile.getPersistentTypes() : EmptyIterable.<PersistentType>instance();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
index 588a98f..87fd7f8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
@@ -51,6 +51,7 @@ import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
@@ -296,6 +297,22 @@ public abstract class AbstractPersistenceUnit
this.setDefaultValidationMode(this.buildDefaultValidationMode());
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) {
+ mappingFileRef.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ if (!rootStructureNodes.isEmpty()) {//short-circuit so we only get one rootStructureNode
+ return;
+ }
+ }
+ //TODO if we decide to gather all rootStructureNodes then we need to only check specifiedClassRefs
+ //if we have already found a particular javaPersistentType listed in a mapping file.
+ for (ClassRef classRef : this.getClassRefs()) {
+ classRef.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+ for (JarFileRef jarFileRef : this.getJarFileRefs()) {
+ jarFileRef.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+ }
// ********** JpaContextNode implementation **********
@@ -487,8 +504,8 @@ public abstract class AbstractPersistenceUnit
protected ListIterable<MappingFileRef> getCombinedMappingFileRefs() {
return new CompositeListIterable<MappingFileRef>(
- this.getSpecifiedMappingFileRefs(),
- this.impliedMappingFileRef
+ this.impliedMappingFileRef,
+ this.getSpecifiedMappingFileRefs()
);
}
@@ -565,11 +582,8 @@ public abstract class AbstractPersistenceUnit
this.xmlPersistenceUnit.getMappingFiles().remove(index);
}
- /**
- * dispose the mapping file ref
- */
protected void removeSpecifiedMappingFileRef_(int index) {
- this.specifiedMappingFileRefContainer.removeContextElement(index).dispose();
+ this.specifiedMappingFileRefContainer.removeContextElement(index);
}
protected void syncSpecifiedMappingFileRefs() {
@@ -642,7 +656,6 @@ public abstract class AbstractPersistenceUnit
this.impliedMappingFileRef.update();
}
else if (this.impliedMappingFileRef != null) {
- //this is needed to unregister the root structure node
this.impliedMappingFileRef.dispose();
this.setImpliedMappingFileRef(null);
}
@@ -714,11 +727,8 @@ public abstract class AbstractPersistenceUnit
this.xmlPersistenceUnit.getJarFiles().remove(index);
}
- /**
- * dispose the JAR file ref
- */
protected void removeJarFileRef_(int index) {
- this.jarFileRefContainer.removeContextElement(index).dispose();
+ this.jarFileRefContainer.removeContextElement(index);
}
protected void syncJarFileRefs() {
@@ -758,6 +768,10 @@ public abstract class AbstractPersistenceUnit
protected XmlJarFileRef getResourceElement(JarFileRef contextElement) {
return contextElement.getXmlJarFileRef();
}
+ @Override
+ protected void disposeElement(JarFileRef element) {
+ element.dispose();
+ }
}
// ********** class refs **********
@@ -828,11 +842,8 @@ public abstract class AbstractPersistenceUnit
this.xmlPersistenceUnit.getClasses().remove(index);
}
- /**
- * dispose the class ref
- */
protected void removeSpecifiedClassRef_(int index) {
- this.specifiedClassRefContainer.removeContextElement(index).dispose();
+ this.specifiedClassRefContainer.removeContextElement(index);
}
public void removeSpecifiedClassRefs(Iterable<ClassRef> classRefs) {
@@ -841,9 +852,6 @@ public abstract class AbstractPersistenceUnit
xmlClassRefs.add(classRef.getXmlClassRef());
}
this.specifiedClassRefContainer.removeAll(classRefs);
- for (ClassRef classRef : classRefs) {
- classRef.dispose();
- }
this.xmlPersistenceUnit.getClasses().removeAll(xmlClassRefs);
}
@@ -1783,25 +1791,29 @@ public abstract class AbstractPersistenceUnit
protected void rebuildPersistentTypeMap() {
synchronized (this.persistentTypeMap) {
this.persistentTypeMap.clear();
-
- //order is significant - last in wins
- for (JarFileRef jarFileRef : this.getJarFileRefs()) {
- for (PersistentType persistentType : jarFileRef.getPersistentTypes()) {
+ for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) {
+ for (PersistentType persistentType : mappingFileRef.getPersistentTypes()) {
if (persistentType.getName() != null) {
- this.persistentTypeMap.put(persistentType.getName(), persistentType);
+ if (! this.persistentTypeMap.containsKey(persistentType.getName())) {
+ this.persistentTypeMap.put(persistentType.getName(), persistentType);
+ }
}
}
}
for (ClassRef classRef : this.getClassRefs()) {
PersistentType persistentType = classRef.getJavaPersistentType();
if (persistentType != null && persistentType.getName() != null) {
- this.persistentTypeMap.put(persistentType.getName(), persistentType);
+ if (! this.persistentTypeMap.containsKey(persistentType.getName())) {
+ this.persistentTypeMap.put(persistentType.getName(), persistentType);
+ }
}
}
- for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) {
- for (PersistentType persistentType : mappingFileRef.getPersistentTypes()) {
+ for (JarFileRef jarFileRef : this.getJarFileRefs()) {
+ for (PersistentType persistentType : jarFileRef.getPersistentTypes()) {
if (persistentType.getName() != null) {
- this.persistentTypeMap.put(persistentType.getName(), persistentType);
+ if (! this.persistentTypeMap.containsKey(persistentType.getName())) {
+ this.persistentTypeMap.put(persistentType.getName(), persistentType);
+ }
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaFile.java
index 0316462..c260e00 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaFile.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,16 +9,17 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1;
-import java.util.Hashtable;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jpt.common.core.JptResourceModel;
-import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
import org.eclipse.jpt.jpa.core.internal.AbstractJpaNode;
/**
@@ -51,7 +52,7 @@ public class GenericJpaFile
* the root structure (context model) nodes corresponding to the resource
* model
*/
- protected final Hashtable<Object, JpaStructureNode> rootStructureNodes = new Hashtable<Object, JpaStructureNode>();
+ protected final HashSet<JpaStructureNode> rootStructureNodes = new HashSet<JpaStructureNode>();
// ********** construction **********
@@ -66,9 +67,6 @@ public class GenericJpaFile
/**
* Changes to {@link #ROOT_STRUCTURE_NODES_COLLECTION} do not need to trigger a
* project update. Only the UI cares about the root structure nodes.
- * If a project update is allowed to happen, an infinite loop will result
- * if any Java class is specified in more than one location in the
- * persistence unit.
*/
@Override
protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) {
@@ -76,6 +74,11 @@ public class GenericJpaFile
nonUpdateAspectNames.add(ROOT_STRUCTURE_NODES_COLLECTION);
}
+ @Override
+ public JpaProject getParent() {
+ return (JpaProject) super.getParent();
+ }
+
// ********** file **********
@@ -99,27 +102,50 @@ public class GenericJpaFile
// ********** root structure nodes **********
public Iterable<JpaStructureNode> getRootStructureNodes() {
- return new LiveCloneIterable<JpaStructureNode>(this.rootStructureNodes.values());
+ return new LiveCloneIterable<JpaStructureNode>(this.rootStructureNodes);
}
public int getRootStructureNodesSize() {
return this.rootStructureNodes.size();
}
- public void addRootStructureNode(Object key, JpaStructureNode rootStructureNode) {
- JpaStructureNode old = this.rootStructureNodes.put(key, rootStructureNode);
- if (rootStructureNode != old) {
- if (old != null) {
- this.fireItemRemoved(ROOT_STRUCTURE_NODES_COLLECTION, old);
- }
- this.fireItemAdded(ROOT_STRUCTURE_NODES_COLLECTION, rootStructureNode);
- }
+ protected PersistenceXml getPersistenceXml() {
+ return this.getParent().getRootContextNode().getPersistenceXml();
}
- public void removeRootStructureNode(Object key, JpaStructureNode rootStructureNode) {
- if (Tools.valuesAreEqual(rootStructureNode, this.rootStructureNodes.get(key))) {
- this.fireItemRemoved(ROOT_STRUCTURE_NODES_COLLECTION, this.rootStructureNodes.remove(key));
+ /**
+ * <li>The JPA file for a persistence.xml will have one root structure node: Persistence
+ * <li>The JPA file for an orm xml file will have one root structure node: EntityMappings
+ * <li>The JPA file for a java file can have multiple root structure nodes only if there
+ * are inner classes. The top-level class and inner classes will be included only
+ * if they are either annotated or listed in the persistence.xml. The root structure
+ * node will be an instanceof JavaPersistentType
+ * <br><br>
+ * If a class is listed in both the persistence.xml and also in an orm.xml file
+ * the root structure node will be the JavaPersistentType that was built by the OrmPersistentType
+ * listed in the orm.xml file. Mapping files will take precendence over the class-ref
+ * in the persistence.xml, but you will currently only have 1 root structure node. There
+ * are validation warnings for these scenarios.
+ * <br><br>
+ * TODO we have discussed having a "primary root" node along with a collection of
+ * root structure nodes that includes all the JavaPersistentTypes as they are
+ * listed via the persistence.xml class-refs, any of the mapping-file-refs, or the jar-file-refs.
+ * <br><br>
+ * bug 390616 is about selection problems when there are static inner classes. When
+ * fixing this bug we need to make sure to handle the possibility that there will
+ * be an unannotated top-level class with an annotated static inner class. Would like
+ * to change the inner classes to not be root structure nodes, but instead be
+ * nested under the top-level class in the structure view.
+ */
+ public void updateRootStructureNodes() {
+ PersistenceXml persistenceXml = this.getPersistenceXml();
+ if (persistenceXml == null) {
+ this.clearCollection(this.rootStructureNodes, ROOT_STRUCTURE_NODES_COLLECTION);
+ return;
}
+ Collection<JpaStructureNode> newRootStructureNodes = new HashSet<JpaStructureNode>();
+ persistenceXml.gatherRootStructureNodes(this, newRootStructureNodes);
+ this.synchronizeCollection(newRootStructureNodes, this.rootStructureNodes, ROOT_STRUCTURE_NODES_COLLECTION);
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java
index e761fcc..08ba7ae 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -21,6 +22,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.PersistentType;
@@ -89,6 +91,15 @@ public class GenericJarFile
return null;
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ for (JavaPersistentType persistentType : this.getJavaPersistentTypes()) {
+ persistentType.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ if (!rootStructureNodes.isEmpty()) { //short-circuit
+ return;
+ }
+ }
+ }
+
public void dispose() {
// nothing yet
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
index cc19f5a..6ef3685 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -136,7 +137,6 @@ public class GenericOrmXml
this.valuesAreDifferent(this.resourceType, newResourceType)
) {
if (this.root != null) {
- this.unregisterRootStructureNode();
this.root.dispose();
this.setRoot(null);
}
@@ -155,8 +155,6 @@ public class GenericOrmXml
}
else {
this.root.update();
- // this will happen redundantly - need to hold JpaFile?
- this.registerRootStructureNode();
}
}
}
@@ -284,26 +282,23 @@ public class GenericOrmXml
return TextRange.Empty.instance();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.root == null) {
+ return;
+ }
+ if (this.getResource().equals(jpaFile.getFile())) {
+ rootStructureNodes.add(this.root);
+ return;
+ }
+ this.root.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+
public void dispose() {
if (this.root != null) {
- JpaFile jpaFile = this.getJpaFile();
- if (jpaFile != null) {
- this.unregisterRootStructureNode();
- }
this.root.dispose();
}
}
- // TODO hold the JpaFile?
- protected void registerRootStructureNode() {
- this.getJpaFile().addRootStructureNode(this.xmlResource, this.root);
- }
-
- protected void unregisterRootStructureNode() {
- this.getJpaFile().removeRootStructureNode(this.xmlResource, this.root);
- }
-
-
// ********** MappingFile implementation **********
public Object getResourceMappingFile() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java
index dcfcf41..6f54d82 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence;
+import java.util.Collection;
import java.util.List;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
@@ -19,6 +20,7 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
@@ -111,6 +113,12 @@ public class GenericClassRef
this.updateJavaPersistentType();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.javaPersistentType != null) {
+ this.javaPersistentType.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+ }
+
// ********** class name **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java
index bf298df..5959933 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -17,6 +18,7 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementListIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
@@ -69,6 +71,12 @@ public class GenericPersistence
this.updateNodes(this.getPersistenceUnits());
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.persistenceUnit != null) {
+ this.persistenceUnit.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+ }
+
// ********** persistence units **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
index 5429817..bfb4cf4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -120,7 +121,6 @@ public class GenericPersistenceXml
this.valuesAreDifferent(this.resourceType, newResourceType)
) {
if (this.root != null) {
- this.unregisterRootStructureNode();
this.root.dispose();
this.setRoot(null);
}
@@ -138,8 +138,6 @@ public class GenericPersistenceXml
}
else {
this.root.update();
- // this will happen redundantly - need to hold JpaFile?
- this.registerRootStructureNode();
}
}
}
@@ -243,25 +241,23 @@ public class GenericPersistenceXml
return TextRange.Empty.instance();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ if (this.root == null) {
+ return;
+ }
+ if (this.getResource().equals(jpaFile.getFile())) {
+ rootStructureNodes.add(this.root);
+ return;
+ }
+ this.root.gatherRootStructureNodes(jpaFile, rootStructureNodes);
+ }
+
public void dispose() {
if (this.root != null) {
- JpaFile jpaFile = this.getJpaFile();
- if (jpaFile != null) {
- this.unregisterRootStructureNode();
- }
this.root.dispose();
}
}
- // TODO hold the JpaFile?
- protected void registerRootStructureNode() {
- this.getJpaFile().addRootStructureNode(this.xmlResource, this.root);
- }
-
- protected void unregisterRootStructureNode() {
- this.getJpaFile().removeRootStructureNode(this.xmlResource, this.root);
- }
-
// ********** validation **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java
index ea43886..7af2f3f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java
@@ -276,7 +276,7 @@ public class EclipseLinkPersistenceUnit
public ListIterable<MappingFileRef> getMappingFileRefs() {
return (this.impliedEclipseLinkMappingFileRef == null) ?
super.getMappingFileRefs() :
- new CompositeListIterable<MappingFileRef>(super.getMappingFileRefs(), this.impliedEclipseLinkMappingFileRef);
+ new CompositeListIterable<MappingFileRef>(this.impliedEclipseLinkMappingFileRef, super.getMappingFileRefs());
}
@Override
@@ -318,7 +318,6 @@ public class EclipseLinkPersistenceUnit
this.impliedEclipseLinkMappingFileRef.update();
}
else if (this.impliedEclipseLinkMappingFileRef != null) {
- //this is needed to unregister the root structure node
this.impliedEclipseLinkMappingFileRef.dispose();
this.setImpliedEclipseLinkMappingFileRef(null);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java
index 56f88da..a09f1fb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.internal.context.orm;
+
+import java.util.Collection;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -19,6 +21,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.ClassName;
import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.CollectionMapping;
@@ -60,6 +63,10 @@ public class VirtualJavaPersistentAttribute
this.updateJpaContainerDefinition();
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ throw new UnsupportedOperationException();
+ }
+
public XmlAttributeMapping getXmlAttributeMapping() {
return this.xmlAttributeMapping;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java
index c87c430..87e359a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java
@@ -28,6 +28,7 @@ import org.eclipse.jpt.common.utility.internal.iterables.ChainIterable;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.PersistentType;
@@ -83,6 +84,10 @@ public class VirtualJavaPersistentType
this.setSuperPersistentType(this.buildSuperPersistentType());
}
+ public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) {
+ //none
+ }
+
// ********** name **********
diff --git a/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java
index 87887f5..6468ed5 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java
@@ -127,6 +127,6 @@ public abstract class EclipseLinkContextModelTestCase
@Override
protected EclipseLinkEntityMappings getEntityMappings() {
- return (EclipseLinkEntityMappings) super.getEntityMappings();
+ return (EclipseLinkEntityMappings) getPersistenceUnit().getSpecifiedMappingFileRefs().iterator().next().getMappingFile().getRoot();
}
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java b/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java
index 7bfbc26..16db3eb 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java
@@ -130,8 +130,8 @@ public class EclipseLinkPersistenceUnitTests
EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit();
ListIterator<MappingFileRef> mappingFileRefs = persistenceUnit.getMappingFileRefs().iterator();
- assertEquals(persistenceUnit.getImpliedMappingFileRef(), mappingFileRefs.next().getMappingFile().getParent());
assertEquals(persistenceUnit.getImpliedEclipseLinkMappingFileRef(), mappingFileRefs.next().getMappingFile().getParent());
+ assertEquals(persistenceUnit.getImpliedMappingFileRef(), mappingFileRefs.next().getMappingFile().getParent());
}
public void testMappingFileRefsSize() {