cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [1/3] cayenne git commit: improvement of vertical inheritance
Date Wed, 27 Jul 2016 07:03:36 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master b1b216863 -> 8e6ba1940


improvement of vertical inheritance


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/cdf40e38
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/cdf40e38
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/cdf40e38

Branch: refs/heads/master
Commit: cdf40e386e7d50feb1653c7a204c65ebacae134a
Parents: 3579ecf
Author: olga <ollybondareva@gmail.com>
Authored: Thu Mar 31 17:14:14 2016 +0300
Committer: olga <ollybondareva@gmail.com>
Committed: Mon Apr 4 13:10:45 2016 +0300

----------------------------------------------------------------------
 .../java/org/apache/cayenne/map/DataMap.java    | 11 +++++
 .../apache/cayenne/util/EntityMergeSupport.java | 48 ++++++++++++++++----
 .../ObjEntityAttributeRelationshipTab.java      |  9 +++-
 .../editor/ObjEntityRelationshipPanel.java      |  7 +++
 4 files changed, 64 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/cdf40e38/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
index a570d66..c3ac20b 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
@@ -44,6 +44,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.HashMap;
 
 import static java.util.Collections.emptyList;
 
@@ -1400,6 +1401,16 @@ public class DataMap implements Serializable, ConfigurationNode, XMLSerializable
         return getNameWithPackage(defaultClientPackage, name);
     }
 
+    public Map<String, ObjEntity> getSubclassesForObjEntity(ObjEntity superEntity)
{
+        Map<String, ObjEntity> subObjectEntities = new HashMap(5);
+        for (ObjEntity objectEntity : objEntityMap.values()) {
+            if (superEntity.getName().equals(objectEntity.getSuperEntityName())) {
+                subObjectEntities.put(objectEntity.getName(), objectEntity);
+            }
+        }
+        return subObjectEntities;
+    }
+
     public ReverseEngineering getReverseEngineering() {
         return reverseEngineering;
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cdf40e38/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
b/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
index 7d38cd8..5bcccce 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/util/EntityMergeSupport.java
@@ -180,29 +180,59 @@ public class EntityMergeSupport {
                     createObjRelationship(entity, dr, mappedTarget.getName());
                 }
             } else {
-                LOG.warn("Can't find ObjEntity for " + dr.getTargetEntityName());
-                LOG.warn("Db Relationship (" + dr + ") will have GUESSED Obj Relationship
reflection. ");
-
                 if (targetEntity == null) {
                     targetEntity = new DbEntity(dr.getTargetEntityName());
                 }
-                createObjRelationship(entity, dr, nameGenerator.createObjEntityName(targetEntity));
+                if (dr.getTargetEntityName() != null) {
+                    boolean needGeneratedEntity = createObjRelationship(entity, dr, nameGenerator.createObjEntityName(targetEntity));
+                    if (needGeneratedEntity) {
+                        LOG.warn("Can't find ObjEntity for " + dr.getTargetEntityName());
+                        LOG.warn("Db Relationship (" + dr + ") will have GUESSED Obj Relationship
reflection. ");
+                    }
+                }
             }
         }
         return true;
     }
 
-    private void createObjRelationship(ObjEntity entity, DbRelationship dr, String targetEntityName)
{
+    private boolean createObjRelationship(ObjEntity entity, DbRelationship dr, String targetEntityName)
{
         String relationshipName = nameGenerator.createObjRelationshipName(dr);
         relationshipName = DefaultUniqueNameGenerator.generate(NameCheckers.objRelationship,
entity, relationshipName);
 
         ObjRelationship or = new ObjRelationship(relationshipName);
         or.addDbRelationship(dr);
-        or.setSourceEntity(entity);
-        or.setTargetEntityName(targetEntityName);
-        entity.addRelationship(or);
+        Map<String, ObjEntity> objEntities = entity.getDataMap().getSubclassesForObjEntity(entity);
+
+        boolean hasFlattingAttributes = false;
+        boolean needGeneratedEntity = true;
+
+        if (objEntities.containsKey(targetEntityName)) {
+            needGeneratedEntity = false;
+        }
+
+        for (ObjEntity subObjEntity : objEntities.values()) {
+            for (ObjAttribute objAttribute : subObjEntity.getAttributes()) {
+                String path = objAttribute.getDbAttributePath();
+                if (path != null) {
+                    if (path.startsWith(or.getDbRelationshipPath())) {
+                        hasFlattingAttributes = true;
+                        break;
+                    }
+                }
+            }
+        }
+
+        if (!hasFlattingAttributes) {
+            if (needGeneratedEntity) {
+                or.setTargetEntityName(targetEntityName);
+                or.setSourceEntity(entity);
+            }
+
+            entity.addRelationship(or);
+            fireRelationshipAdded(or);
+        }
 
-        fireRelationshipAdded(or);
+        return needGeneratedEntity;
     }
 
     private boolean addMissingAttributes(ObjEntity entity) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cdf40e38/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeRelationshipTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeRelationshipTab.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeRelationshipTab.java
index fcdf45d..9406cf8 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeRelationshipTab.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeRelationshipTab.java
@@ -61,6 +61,7 @@ public class ObjEntityAttributeRelationshipTab extends JPanel implements
ObjEnti
     private CutAttributeRelationshipAction cut;
     private RemoveAttributeRelationshipAction remove;
     private CopyAttributeRelationshipAction copy;
+    private JToolBar toolBar;
 
     public ObjEntityAttributeRelationshipTab(ProjectController mediator) {
         this.mediator = mediator;
@@ -95,7 +96,7 @@ public class ObjEntityAttributeRelationshipTab extends JPanel implements
ObjEnti
     }
 
     private void initToolBar() {
-        JToolBar toolBar = new JToolBar();
+        toolBar = new JToolBar();
         ActionManager actionManager = Application.getInstance().getActionManager();
 
         toolBar.add(actionManager.getAction(CreateAttributeAction.class).buildButton());
@@ -167,4 +168,8 @@ public class ObjEntityAttributeRelationshipTab extends JPanel implements
ObjEnti
         attributePanel.currentObjEntityChanged(e);
         relationshipPanel.currentObjEntityChanged(e);
     }
-}
\ No newline at end of file
+
+    public JToolBar getToolBar() {
+        return toolBar;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cdf40e38/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
index a9900c4..7a4c2af 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
@@ -225,6 +225,13 @@ public class ObjEntityRelationshipPanel extends JPanel implements ObjEntityDispl
         if (e.isUnselectAttributes()) {
             table.clearSelection();
         }
+
+        ObjEntity objEntity = (ObjEntity) e.getEntity();
+        if (objEntity.getSuperEntity() != null) {
+            parentPanel.getToolBar().getComponentAtIndex(2).setEnabled(false);
+        } else {
+            parentPanel.getToolBar().getComponentAtIndex(2).setEnabled(true);
+        }
     }
 
     /**


Mime
View raw message