You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/02/15 14:15:27 UTC
cayenne git commit: CAY-2229 NPE in Modeler find action
Repository: cayenne
Updated Branches:
refs/heads/master dd1745ca8 -> 03e7024fc
CAY-2229 NPE in Modeler find action
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/03e7024f
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/03e7024f
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/03e7024f
Branch: refs/heads/master
Commit: 03e7024fc2be8a31cf2052e2bdbae1f4bc50a07a
Parents: dd1745c
Author: Nikita Timofeev <st...@gmail.com>
Authored: Wed Feb 15 17:15:10 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Wed Feb 15 17:15:10 2017 +0300
----------------------------------------------------------------------
.../cayenne/modeler/action/FindAction.java | 38 +++++++++++++-------
1 file changed, 25 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/03e7024f/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
index 4c036a8..5470f30 100755
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
@@ -19,11 +19,13 @@
package org.apache.cayenne.modeler.action;
import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.dbsync.reverse.dbload.DbRelationshipDetected;
import org.apache.cayenne.map.Attribute;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.DetectedDbEntity;
import org.apache.cayenne.map.Embeddable;
import org.apache.cayenne.map.EmbeddableAttribute;
import org.apache.cayenne.map.Entity;
@@ -56,6 +58,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.regex.Pattern;
public class FindAction extends CayenneAction {
@@ -65,15 +68,17 @@ public class FindAction extends CayenneAction {
*/
private static final Map<Class<?>, Integer> PRIORITY_BY_TYPE = new HashMap<>();
static {
- PRIORITY_BY_TYPE.put(ObjEntity.class, 1);
- PRIORITY_BY_TYPE.put(DbEntity.class, 2);
- PRIORITY_BY_TYPE.put(ObjAttribute.class, 5);
- PRIORITY_BY_TYPE.put(DbAttribute.class, 6);
- PRIORITY_BY_TYPE.put(ObjRelationship.class, 7);
- PRIORITY_BY_TYPE.put(DbRelationship.class, 8);
- PRIORITY_BY_TYPE.put(QueryDescriptor.class, 9);
- PRIORITY_BY_TYPE.put(Embeddable.class, 10);
- PRIORITY_BY_TYPE.put(EmbeddableAttribute.class,11);
+ PRIORITY_BY_TYPE.put(ObjEntity.class, 1);
+ PRIORITY_BY_TYPE.put(DbEntity.class, 2);
+ PRIORITY_BY_TYPE.put(DetectedDbEntity.class, 2); // this one comes from db reverse engineering
+ PRIORITY_BY_TYPE.put(ObjAttribute.class, 5);
+ PRIORITY_BY_TYPE.put(DbAttribute.class, 6);
+ PRIORITY_BY_TYPE.put(ObjRelationship.class, 7);
+ PRIORITY_BY_TYPE.put(DbRelationship.class, 8);
+ PRIORITY_BY_TYPE.put(DbRelationshipDetected.class, 8); // this one comes from db reverse engineering
+ PRIORITY_BY_TYPE.put(QueryDescriptor.class, 9);
+ PRIORITY_BY_TYPE.put(Embeddable.class, 10);
+ PRIORITY_BY_TYPE.put(EmbeddableAttribute.class, 11);
}
public static String getActionName() {
@@ -322,8 +327,8 @@ public class FindAction extends CayenneAction {
private final String name;
public SearchResultEntry(Object object, String name) {
- this.object = object;
- this.name = name;
+ this.object = Objects.requireNonNull(object);
+ this.name = Objects.requireNonNull(name);
}
public String getName() {
@@ -349,10 +354,17 @@ public class FindAction extends CayenneAction {
return result;
}
+ private int getPriority() {
+ Integer priority = PRIORITY_BY_TYPE.get(object.getClass());
+ if(priority == null) {
+ throw new NullPointerException("Unknown type: " + object.getClass().getCanonicalName());
+ }
+ return priority;
+ }
+
@Override
public int compareTo(SearchResultEntry o) {
- int res = PRIORITY_BY_TYPE.get(getObject().getClass())
- - PRIORITY_BY_TYPE.get(o.getObject().getClass());
+ int res = getPriority() - o.getPriority();
if(res != 0) {
return res;
}