Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2008-04-09 15:26:59 -0400
committerkmoore2008-04-09 15:26:59 -0400
commit828b50f87e48b255fd70ae3d541f9a2228e2279f (patch)
tree41e13ebb06d3f75686c89d77dec5a53f366a5ac5
parent3a98162d5b4f4a14bb8221c84b82ee361db626c8 (diff)
downloadwebtools.dali-828b50f87e48b255fd70ae3d541f9a2228e2279f.tar.gz
webtools.dali-828b50f87e48b255fd70ae3d541f9a2228e2279f.tar.xz
webtools.dali-828b50f87e48b255fd70ae3d541f9a2228e2279f.zip
225642 - added back validation messages for unmapped class listed in the persistence.xml and redundant class listed in the persistence.xml and an orm.xml file
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties3
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceUnit.java45
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java2
5 files changed, 66 insertions, 44 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
index cb73bbeda2..8d6a10ea7b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
+++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties
@@ -22,8 +22,9 @@ PERSISTENCE_UNIT_INVALID_MAPPING_FILE=Mapping file \"{0}\" does not have ORM con
PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE=Duplicate mapping file \"{0}\"
PERSISTENCE_UNIT_UNSPECIFIED_CLASS=Unspecified class
PERSISTENCE_UNIT_NONEXISTENT_CLASS=Class \"{0}\" cannot be resolved
-PERSISTENCE_UNIT_INVALID_CLASS=Class \"{0}\" is not annotated as a persistent class
+PERSISTENCE_UNIT_INVALID_CLASS=Class \"{0}\" is listed in the persistence.xml file but not annotated as a persistent class
PERSISTENCE_UNIT_DUPLICATE_CLASS=Duplicate class \"{0}\"
+PERSISTENCE_UNIT_REDUNDANT_CLASS=Class \"{0}\" is already specified in mapping file \"{1}\"
GENERATOR_DUPLICATE_NAME=Duplicate generator named \"{0}\" defined in this persistence unit
QUERY_DUPLICATE_NAME=Duplicate query named \"{0}\" defined in this persistence unit
ENTITY_MAPPINGS_MULTIPLE_METADATA=Metadata for persistence unit \"{0}\" specified in multiple mapping files
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
index bf5b3735fd..741e25037c 100644
--- 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
@@ -14,6 +14,9 @@ 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;
@@ -42,6 +45,20 @@ public class JavaNullTypeMapping extends AbstractJavaTypeMapping
@Override
public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) {
- // no-op, nothing to really add
+ //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/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java
index 068e771b5c..84b01c1c41 100644
--- 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
@@ -14,6 +14,7 @@ import java.util.List;
import org.eclipse.jpt.core.JpaStructureNode;
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;
@@ -21,6 +22,7 @@ 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;
@@ -62,7 +64,7 @@ public class GenericClassRef extends AbstractPersistenceJpaContextNode
}
public boolean isVirtual() {
- return xmlJavaClassRef == null;
+ return this.xmlJavaClassRef == null;
}
@@ -160,10 +162,7 @@ public class GenericClassRef extends AbstractPersistenceJpaContextNode
super.addToMessages(messages);
addUnspecifiedClassMessage(messages);
addUnresolvedClassMessage(messages);
- //classRef might have been empty
- if(getJavaPersistentType() != null){
- getJavaPersistentType().addToMessages(messages);
- }
+ addJavaPersistentTypeMessages(messages);
}
protected void addUnspecifiedClassMessage(List<IMessage> messages) {
@@ -189,6 +188,38 @@ public class GenericClassRef extends AbstractPersistenceJpaContextNode
);
}
}
+
+ 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 {
+ //bug 190062 - only add java validation messages if this class is not listed in a mapping file
+ getJavaPersistentType().addToMessages(messages);
+ }
+ }
+ }
+
+ //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;
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
index 4d4d439c3a..f20b1721d2 100644
--- 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
@@ -816,7 +816,7 @@ public class GenericPersistenceUnit extends AbstractPersistenceJpaContextNode
protected void updateMappingFileRefs(XmlPersistenceUnit persistenceUnit) {
Iterator<MappingFileRef> stream = specifiedMappingFileRefs();
- Iterator<XmlMappingFileRef> stream2 = persistenceUnit.getMappingFiles().iterator();
+ Iterator<XmlMappingFileRef> stream2 = new CloneIterator<XmlMappingFileRef>(persistenceUnit.getMappingFiles());//prevent ConcurrentModificiationException
while (stream.hasNext()) {
MappingFileRef mappingFileRef = stream.next();
@@ -876,7 +876,7 @@ public class GenericPersistenceUnit extends AbstractPersistenceJpaContextNode
protected void updateClassRefs(XmlPersistenceUnit persistenceUnit) {
Iterator<ClassRef> stream = specifiedClassRefs();
- Iterator<XmlJavaClassRef> stream2 = new CloneIterator<XmlJavaClassRef>(persistenceUnit.getClasses());
+ Iterator<XmlJavaClassRef> stream2 = new CloneIterator<XmlJavaClassRef>(persistenceUnit.getClasses());//prevent ConcurrentModificiationException
while (stream.hasNext()) {
ClassRef classRef = stream.next();
@@ -1089,57 +1089,28 @@ public class GenericPersistenceUnit extends AbstractPersistenceJpaContextNode
}
)
);
- for (MappingFileRef mappingFileRef : CollectionTools.collection(this.mappingFileRefs())) {
+ 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.validationTextRange()*/)
+ mappingFileRef,
+ mappingFileRef.getValidationTextRange())
);
}
}
}
protected void addClassMessages(List<IMessage> messages) {
-// addInvalidOrRedundantClassMessages(messages);
addDuplicateClassMessages(messages);
- for (ClassRef classRef : CollectionTools.collection(classRefs())) {
- classRef.addToMessages(messages);
+ for (ClassRef classRef : CollectionTools.iterable(classRefs())) {
+ classRef.addToMessages(messages);
}
}
-// protected void addInvalidOrRedundantClassMessages(List<IMessage> messages) {
-// for (IClassRef javaClassRef : CollectionTools.collection(this.classRefs())) {
-// IJavaPersistentType javaPersistentType = javaClassRef.getJavaPersistentType();
-// //*****leaving this test out for now********
-// //first test for a redundant entry in any of the mapping files
-//// if (mappingFilesContainPersistentTypeFor(jdtType)){
-//// //Uncomment below code to add info message about redundant entry.
-//// /* messages.add(JpaValidationMessages.buildMessage(
-//// IMessage.LOW_SEVERITY,
-//// IJpaValidationMessages.PERSISTENCE_UNIT_REDUNDANT_CLASS,
-//// new String[] { javaClassRef.getJavaClass() },
-//// javaClassRef, javaClassRef.validationTextRange())); */
-//// //if not redundant, check to see if it is an invalid entry
-//// } else if(!StringTools.stringIsEmpty(javaClass)
-// } if (!StringTools.stringIsEmpty(javaClass)
-// && jdtType != null
-// && (javaPersistentTypeFor(javaClassRef) == null || javaPersistentTypeFor(
-// javaClassRef).getMappingKey() == IMappingKeys.NULL_TYPE_MAPPING_KEY)){
-// messages.add(JpaValidationMessages.buildMessage(
-// IMessage.HIGH_SEVERITY,
-// IJpaValidationMessages.PERSISTENCE_UNIT_INVALID_CLASS,
-// new String[] { javaClassRef.getJavaClass() }, javaClassRef,
-// javaClassRef.validationTextRange()));
-// }
-// }
-// }
-
-
protected void addDuplicateClassMessages(List<IMessage> messages) {
HashBag<String> classNameBag = new HashBag<String>(
CollectionTools.collection(
@@ -1151,7 +1122,7 @@ public class GenericPersistenceUnit extends AbstractPersistenceJpaContextNode
}
)
);
- for (ClassRef javaClassRef : CollectionTools.collection(this.classRefs())) {
+ for (ClassRef javaClassRef : CollectionTools.iterable(this.classRefs())) {
if (javaClassRef.getClassName() != null
&& classNameBag.count(javaClassRef.getClassName()) > 1) {
messages.add(
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
index e5b1201371..08cadc9ad0 100644
--- 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
@@ -44,6 +44,8 @@ public interface JpaValidationMessages
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";

Back to the top