From 0e80b193eca03a5a2342382c729b50967a18cb35 Mon Sep 17 00:00:00 2001 From: Nan Li Date: Wed, 15 May 2013 17:13:42 -0400 Subject: 404941, 305593 - improve sync class list for persistence.xml --- .../persistence/AbstractPersistenceUnit.java | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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 2a0155fd27..3677e647ba 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 @@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.internal.context.persistence; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -29,6 +30,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.emf.common.util.ECollections; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaModelException; @@ -2046,13 +2048,14 @@ public abstract class AbstractPersistenceUnit // ********** synchronize classes ********** public void synchronizeClasses(IProgressMonitor monitor) { - SubMonitor sm = SubMonitor.convert(monitor, 3); + SubMonitor sm = SubMonitor.convert(monitor, 4); - // calculate the refs to remove and add + // newTypes collection only includes those that are annotated HashSet newTypes = CollectionTools.set(this.getJpaProject().getPotentialJavaSourceTypes()); ArrayList deadClassRefs = new ArrayList(); HashSet mappingFileTypeNames = this.getMappingFileTypeNames(); + // collect those class refs that need to be removed from persistence.xml for (ClassRef classRef : this.getSpecifiedClassRefs()) { JavaManagedType specifiedJMT = classRef.getJavaManagedType(); if (specifiedJMT == null) { @@ -2069,6 +2072,14 @@ public abstract class AbstractPersistenceUnit } } } + + // if a type is included in a mapping file, remove it from the newTypes collection + for (java.util.Iterator iterator = newTypes.iterator(); iterator.hasNext();) { + JavaResourceAbstractType type = iterator.next(); + if (mappingFileTypeNames.contains(type.getTypeBinding().getQualifiedName())) { + iterator.remove(); + } + } if (sm.isCanceled()) { return; } @@ -2082,6 +2093,16 @@ public abstract class AbstractPersistenceUnit this.addSpecifiedClassRefs(newTypes); sm.worked(1); + + // sort the list of class refs within the persistence.xml + ECollections.sort(this.getXmlPersistenceUnit().getClasses(), new XmlJavaClassRefNameComp()); + sm.worked(1); + } + + public class XmlJavaClassRefNameComp implements Comparator{ + public int compare(XmlJavaClassRef xjcr1, XmlJavaClassRef xjcr2) { + return xjcr1.getJavaClass().compareTo(xjcr2.getJavaClass()); + } } /** -- cgit v1.2.3