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 2019/10/18 08:32:18 UTC
[cayenne] 02/02: CAY-2633 Modeler: attribute sorting logic in cgen
can corrupt model
This is an automated email from the ASF dual-hosted git repository.
ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 52f4cfdef7f78be2ffb242e555e6199acf66f286
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Fri Oct 18 11:19:54 2019 +0300
CAY-2633 Modeler: attribute sorting logic in cgen can corrupt model
---
RELEASE-NOTES.txt | 1 +
.../org/apache/cayenne/gen/EntityArtifact.java | 23 ++++++++++++----------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index dd5c68d..3c254e1 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -103,6 +103,7 @@ CAY-2627 Modeler: ObjRelationship creation dialog ignores delete rule
CAY-2628 dbimport: unable to add several relationships to existing entity
CAY-2631 Can no longer use "byte[]" as root of scalar SQLSelect
CAY-2632 Modeler: issue saving cgen path for maven project
+CAY-2633 Modeler: attribute sorting logic in cgen can corrupt model
----------------------------------
Release: 4.1.B1
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityArtifact.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityArtifact.java
index c0d3a82..1940bda 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityArtifact.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/EntityArtifact.java
@@ -18,8 +18,9 @@
****************************************************************/
package org.apache.cayenne.gen;
-import java.util.Map;
-import java.util.TreeMap;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
import org.apache.cayenne.BaseDataObject;
import org.apache.cayenne.map.ObjAttribute;
@@ -104,18 +105,20 @@ public class EntityArtifact implements Artifact {
}
private void sortAttributes() {
- Map<String, ObjAttribute> attributeMap = new TreeMap<>(entity.getAttributeMap());
- for(Map.Entry<String, ObjAttribute> entry : attributeMap.entrySet()) {
- entity.removeAttribute(entry.getKey());
- entity.addAttribute(entry.getValue());
+ List<ObjAttribute> objAttributes = new ArrayList<>(entity.getDeclaredAttributes());
+ objAttributes.sort(Comparator.comparing(ObjAttribute::getName));
+ for(ObjAttribute attribute : objAttributes) {
+ entity.removeAttribute(attribute.getName());
+ entity.addAttribute(attribute);
}
}
private void sortRelationships() {
- Map<String, ObjRelationship> relationshipMap = new TreeMap<>(entity.getRelationshipMap());
- for(Map.Entry<String, ObjRelationship> entry : relationshipMap.entrySet()) {
- entity.removeRelationship(entry.getKey());
- entity.addRelationship(entry.getValue());
+ List<ObjRelationship> relationships = new ArrayList<>(entity.getDeclaredRelationships());
+ relationships.sort(Comparator.comparing(ObjRelationship::getName));
+ for(ObjRelationship relationship : relationships) {
+ entity.removeRelationship(relationship.getName());
+ entity.addRelationship(relationship);
}
}
}