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 2018/10/01 15:03:59 UTC
[4/6] cayenne git commit: Fix NPE
Fix NPE
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/50668a4b
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/50668a4b
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/50668a4b
Branch: refs/heads/STABLE-4.0
Commit: 50668a4b85127f3199cfb16949b6980c10c1b092
Parents: 3645943
Author: Nikita Timofeev <st...@gmail.com>
Authored: Thu Sep 20 17:03:45 2018 +0300
Committer: Arseni Bulatski <an...@gmail.com>
Committed: Tue Sep 25 12:41:04 2018 +0300
----------------------------------------------------------------------
.../util/DbRelationshipPathComboBoxEditor.java | 32 ++++++++++++++------
1 file changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/50668a4b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/DbRelationshipPathComboBoxEditor.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/DbRelationshipPathComboBoxEditor.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/DbRelationshipPathComboBoxEditor.java
index a3e6935..b79e68d 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/DbRelationshipPathComboBoxEditor.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/DbRelationshipPathComboBoxEditor.java
@@ -22,9 +22,11 @@ package org.apache.cayenne.modeler.util;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.DbRelationship;
import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.Application;
import org.apache.cayenne.modeler.editor.ObjRelationshipTableModel;
import javax.swing.JLabel;
+import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.text.JTextComponent;
import java.awt.Component;
@@ -98,12 +100,14 @@ public class DbRelationshipPathComboBoxEditor extends PathChooserComboBoxCellEdi
//we need object target to save it in model
DbEntity lastEntity = ((DbRelationship) currentNode).getTargetEntity();
- Collection<ObjEntity> objEntities = ((DbRelationship) currentNode).getTargetEntity().
- getDataMap().getMappedEntities(lastEntity);
- ObjEntity objectTarget = objEntities.isEmpty() ? null : objEntities.iterator().next();
- model.getRelationship(row).setTargetEntityName(objectTarget);
- model.setUpdatedValueAt(dbRelationshipPath, row, REL_TARGET_PATH_COLUMN);
- model.getRelationship(row).setDbRelationshipPath(dbRelationshipPath);
+ if(lastEntity == null) {
+ Collection<ObjEntity> objEntities = ((DbRelationship) currentNode).getTargetEntity().
+ getDataMap().getMappedEntities(lastEntity);
+ ObjEntity objectTarget = objEntities.isEmpty() ? null : objEntities.iterator().next();
+ model.getRelationship(row).setTargetEntityName(objectTarget);
+ model.setUpdatedValueAt(dbRelationshipPath, row, REL_TARGET_PATH_COLUMN);
+ model.getRelationship(row).setDbRelationshipPath(dbRelationshipPath);
+ }
model.getRelationship(row).setMapKey(null);
}
table.repaint();
@@ -154,17 +158,21 @@ public class DbRelationshipPathComboBoxEditor extends PathChooserComboBoxCellEdi
return pathString.replaceAll(lastStringInPath + '$', "");
}
- private void changeObjEntity(String path){
+ private boolean changeObjEntity(String path){
Object currentNode = getCurrentNode(path);
if (currentNode instanceof DbEntity){
- return;
+ return false;
}
DbEntity lastEntity = ((DbRelationship) currentNode).getTargetEntity();
+ if(lastEntity == null) {
+ return false;
+ }
Collection<ObjEntity> objEntities = ((DbRelationship) currentNode).getTargetEntity().
getDataMap().getMappedEntities(lastEntity);
ObjEntity objectTarget = objEntities.isEmpty() ? null : objEntities.iterator().next();
model.getRelationship(row).setTargetEntityName(objectTarget);
table.repaint();
+ return true;
}
@Override
@@ -174,6 +182,12 @@ public class DbRelationshipPathComboBoxEditor extends PathChooserComboBoxCellEdi
@Override
public void focusLost(FocusEvent focusEvent) {
String path = model.getRelationship(row).getDbRelationshipPath();
- changeObjEntity(path);
+ if(!changeObjEntity(path)) {
+ JOptionPane.showMessageDialog(
+ Application.getFrame(),
+ "Can't set dbAttribute path. At first set target entity in dbEntity.",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
}
}