Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2012-04-05 14:18:11 -0400
committerkmoore2012-04-05 14:18:11 -0400
commitc522b5c2201faba0a34e4038d206c4cbf842e2c3 (patch)
treeb221c0ce84af9a6b3ac60ae9e9f6e6746122134d
parent91539e48623ada3fcb324e3d8a1eaa660f67d703 (diff)
downloadwebtools.dali-c522b5c2201faba0a34e4038d206c4cbf842e2c3.tar.gz
webtools.dali-c522b5c2201faba0a34e4038d206c4cbf842e2c3.tar.xz
webtools.dali-c522b5c2201faba0a34e4038d206c4cbf842e2c3.zip
Bug 375841 - root structure node leak when removing a class ref from the persistence.xml source
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java89
2 files changed, 121 insertions, 14 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java
index 0a8491bc83..c5b598ed08 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java
@@ -17,8 +17,8 @@ import java.util.Set;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.core.internal.utility.jdt.JDTModifiedDeclaration.Adapter;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
@@ -386,6 +386,10 @@ public abstract class AbstractJpaNode
protected abstract void moveContextElement(int index, C element);
+ protected void disposeElement(C element) {
+ //override if you need to dispose an element when it is removed
+ }
+
@Override
public String toString() {
return this.contextElements.toString();
@@ -512,13 +516,17 @@ public abstract class AbstractJpaNode
}
@Override
- public void removeContextElement(C element) {
- AbstractJpaNode.this.removeItemFromCollection(element, this.contextElements, this.getContextElementsPropertyName());
+ public void removeContextElement(C contextElement) {
+ AbstractJpaNode.this.removeItemFromCollection(contextElement, this.contextElements, this.getContextElementsPropertyName());
+ this.disposeElement(contextElement);
}
@Override
public void removeAll(Iterable<C> elements) {
AbstractJpaNode.this.removeItemsFromCollection(elements, this.contextElements, this.getContextElementsPropertyName());
+ for (C element : elements) {
+ this.disposeElement(element);
+ }
}
@Override
@@ -567,7 +575,7 @@ public abstract class AbstractJpaNode
}
@Override
- protected Iterable<C> addAll(int index, Iterable<C> elements) {
+ public Iterable<C> addAll(int index, Iterable<C> elements) {
AbstractJpaNode.this.addItemsToList(index, elements, this.contextElements, this.getContextElementsPropertyName());
return elements;
}
@@ -589,6 +597,9 @@ public abstract class AbstractJpaNode
* clear the list of context elements
*/
public void clearContextList() {
+ for (C element : this.contextElements) {
+ this.disposeElement(element);
+ }
AbstractJpaNode.this.clearList(this.contextElements, getContextElementsPropertyName());
}
@@ -596,17 +607,23 @@ public abstract class AbstractJpaNode
* Remove the context element at the specified index from the container.
*/
public C removeContextElement(int index) {
- return AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
+ C element = AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
+ this.disposeElement(element);
+ return element;
}
@Override
public void removeContextElement(C element) {
- this.removeContextElement(this.indexOfContextElement(element));
+ AbstractJpaNode.this.removeItemFromList(element, this.contextElements, this.getContextElementsPropertyName());
+ this.disposeElement(element);
}
@Override
public void removeAll(Iterable<C> elements) {
AbstractJpaNode.this.removeItemsFromList(elements, this.contextElements, this.getContextElementsPropertyName());
+ for (C element : elements) {
+ this.disposeElement(element);
+ }
}
}
@@ -670,19 +687,30 @@ public abstract class AbstractJpaNode
@Override
public void removeContextElement(C element) {
- this.removeContextElement(this.indexOfContextElement(element));
+ AbstractJpaNode.this.removeItemFromList(element, this.contextElements, this.getContextElementsPropertyName());
+ this.disposeElement(element);
}
/**
* Remove the context element at the specified index from the container.
*/
- public void removeContextElement(int index) {
- AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
+ public C removeContextElement(int index) {
+ C element = AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
+ this.disposeElement(element);
+ return element;
}
@Override
public void removeAll(Iterable<C> elements) {
AbstractJpaNode.this.removeItemsFromList(elements, this.contextElements, this.getContextElementsPropertyName());
+ for (C element : elements) {
+ this.disposeElement(element);
+ }
+ }
+
+ @Override
+ protected void disposeElement(C element) {
+ //override if you need to dispose an element when it is removed
}
public void synchronizeWithResourceModel() {
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 d70b2ec418..185f849b0c 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
@@ -69,6 +69,7 @@ import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
import org.eclipse.jpt.jpa.core.context.java.JavaGenerator;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaQuery;
+import org.eclipse.jpt.jpa.core.context.java.JavaTypeMappingDefinition;
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
import org.eclipse.jpt.jpa.core.context.orm.OrmEntity;
import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator;
@@ -863,6 +864,10 @@ public abstract class AbstractPersistenceUnit
protected XmlJavaClassRef getResourceElement(ClassRef contextElement) {
return contextElement.getXmlClassRef();
}
+ @Override
+ protected void disposeElement(ClassRef contextElement) {
+ contextElement.dispose();
+ }
}
@@ -956,9 +961,8 @@ public abstract class AbstractPersistenceUnit
return contextElement.getClassName();
}
@Override
- public void removeContextElement(ClassRef element) {
- super.removeContextElement(element);
- element.dispose();
+ protected void disposeElement(ClassRef contextElement) {
+ contextElement.dispose();
}
}
@@ -1241,8 +1245,7 @@ public abstract class AbstractPersistenceUnit
return contextElement;
}
@Override
- public void removeContextElement(Property contextElement) {
- super.removeContextElement(contextElement);
+ protected void disposeElement(Property contextElement) {
if (contextElement.getName() != null) {
propertyRemoved(contextElement.getName());
}
@@ -2045,7 +2048,77 @@ public abstract class AbstractPersistenceUnit
}
return result;
}
+
+ // ********** add persistent types - Make Persistent **********
+
+ //TODO add API - added this post-M6
+ /**
+ * Annotate the given types with the given mapping key
+ * Specify the types in the persistence.xml if listInPersistenceXml is true.
+ */
+ public void addPersistentTypes(AbstractPersistenceUnit.MappedType[] mappedTypes, boolean listInPersistenceXml, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, 10);
+ this.annotateClasses(mappedTypes, sm.newChild(6));
+ if (listInPersistenceXml) {
+ this.listInPersistenceXml(mappedTypes, sm.newChild(4));
+ }
+ else {
+ sm.subTask(JptCoreMessages.MAKE_PERSISTENT_UPDATING_JPA_MODEL);
+ //TODO have to call this since I am modifying only the Java resource model
+ //in the non-'list in persisistence.xml' case
+ this.getJpaProject().synchronizeContextModel();
+ sm.worked(4);
+ }
+ }
+
+ protected void annotateClasses(AbstractPersistenceUnit.MappedType[] mappedTypes, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, mappedTypes.length);
+ sm.setTaskName(JptCoreMessages.MAKE_PERSISTENT_PROCESSING_JAVA_CLASSES);
+ // TODO modify the context model - need to have API for creating a JavaPersistentType with a given mappingKey.
+ // be careful not to modify the context model in such a way that you end up with updates being run for
+ // every persistent type added.
+ for (AbstractPersistenceUnit.MappedType mappedType : mappedTypes) {
+ if (sm.isCanceled()) {
+ return;
+ }
+ String name = mappedType.getFullyQualifiedName();
+ sm.subTask(NLS.bind(JptCoreMessages.MAKE_PERSISTENT_ANNOTATING_CLASS, name));
+ JavaResourceAbstractType type = this.getJpaProject().getJavaResourceType(name);
+ type.addAnnotation(this.getJavaTypeMappingDefinition(mappedType.getMappingKey()).getAnnotationName());
+ sm.worked(1);
+ }
+ }
+ protected void listInPersistenceXml(AbstractPersistenceUnit.MappedType[] mappedTypes, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, 11);
+ sm.setTaskName(JptCoreMessages.MAKE_PERSISTENT_LISTING_IN_PERSISTENCE_XML);
+ Collection<XmlJavaClassRef> addedXmlClassRefs = new ArrayList<XmlJavaClassRef>();
+ Collection<ClassRef> addedClassRefs = new ArrayList<ClassRef>();
+ for (AbstractPersistenceUnit.MappedType mappedType : mappedTypes) {
+ String name = mappedType.getFullyQualifiedName();
+ XmlJavaClassRef xmlClassRef = this.buildXmlJavaClassRef(name);
+ addedXmlClassRefs.add(xmlClassRef);
+ addedClassRefs.add(this.buildClassRef(xmlClassRef));
+ }
+ if (sm.isCanceled()) {
+ return;
+ }
+ sm.worked(1);
+ sm.subTask(JptCoreMessages.MAKE_PERSISTENT_UPDATING_JPA_MODEL);
+ this.specifiedClassRefContainer.addAll(this.getSpecifiedClassRefsSize(), addedClassRefs);
+ sm.worked(5);
+ sm.subTask(JptCoreMessages.MAKE_PERSISTENT_ADD_TO_PERSISTENCE_XML_RESOURCE_MODEL);
+ this.xmlPersistenceUnit.getClasses().addAll(addedXmlClassRefs);
+ sm.worked(5);
+ }
+ protected JavaTypeMappingDefinition getJavaTypeMappingDefinition(String key) {
+ for (JavaTypeMappingDefinition definition : this.getJpaPlatform().getJavaTypeMappingDefinitions()) {
+ if (Tools.valuesAreEqual(definition.getKey(), key)) {
+ return definition;
+ }
+ }
+ throw new IllegalArgumentException("Illegal type mapping key: " + key); //$NON-NLS-1$
+ }
// ********** misc **********
@@ -2943,4 +3016,10 @@ public abstract class AbstractPersistenceUnit
this.metamodelSynchronizer.printBodySourceOn(pw, memberTypeTree);
}
}
+
+
+ public static interface MappedType {
+ String getFullyQualifiedName();
+ String getMappingKey();
+ }
}

Back to the top