Repository: cayenne
Updated Branches:
  refs/heads/master 413c72045 -> 39b70d1bf


CAY-2116 Split schema synchronization code in a separate module

* naming classes cleanup and docs


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

Branch: refs/heads/master
Commit: 39b70d1bfa3cec6f91f0889df0da347f0c851485
Parents: 413c720
Author: Andrus Adamchik <[email protected]>
Authored: Sun Oct 2 16:04:12 2016 +0300
Committer: Andrus Adamchik <[email protected]>
Committed: Sun Oct 2 21:50:13 2016 +0300

----------------------------------------------------------------------
 .../dbsync/naming/DeduplicationVisitor.java     | 36 ++++++++++----------
 .../cayenne/dbsync/naming/NameBuilder.java      | 22 +++++++-----
 2 files changed, 31 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/39b70d1b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/DeduplicationVisitor.java
----------------------------------------------------------------------
diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/DeduplicationVisitor.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/DeduplicationVisitor.java
index f809fd3..09d2d97 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/DeduplicationVisitor.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/DeduplicationVisitor.java
@@ -44,12 +44,12 @@ import java.util.Objects;
 // TODO: swap inner classes for lambdas when we are on java 8
 class DeduplicationVisitor implements ConfigurationNodeVisitor<String> {
 
-    private ConfigurationNode namingContext;
+    private ConfigurationNode parent;
     private String baseName;
     private String dupesPattern;
 
-    DeduplicationVisitor(ConfigurationNode context, String baseName, String 
dupesPattern) {
-        this.namingContext = context;
+    DeduplicationVisitor(ConfigurationNode parent, String baseName, String 
dupesPattern) {
+        this.parent = parent;
         this.baseName = Objects.requireNonNull(baseName);
         this.dupesPattern = Objects.requireNonNull(dupesPattern);
     }
@@ -66,7 +66,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
             @Override
             public boolean isNameInUse(String name) {
 
-                DataChannelDescriptor dataChannelDescriptor = 
(DataChannelDescriptor) namingContext;
+                DataChannelDescriptor dataChannelDescriptor = 
(DataChannelDescriptor) parent;
                 for (DataNodeDescriptor dataNodeDescriptor : 
dataChannelDescriptor.getNodeDescriptors()) {
                     if (dataNodeDescriptor.getName().equals(name)) {
                         return true;
@@ -86,12 +86,12 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
 
                 // null context is a situation when DataMap is a
                 // top level object of the project
-                if (namingContext == null) {
+                if (parent == null) {
                     return false;
                 }
 
-                if (namingContext instanceof DataChannelDescriptor) {
-                    DataChannelDescriptor domain = (DataChannelDescriptor) 
namingContext;
+                if (parent instanceof DataChannelDescriptor) {
+                    DataChannelDescriptor domain = (DataChannelDescriptor) 
parent;
                     return domain.getDataMap(name) != null;
                 }
                 return false;
@@ -104,7 +104,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
         return resolve(new Predicate() {
             @Override
             public boolean isNameInUse(String name) {
-                DataMap map = (DataMap) namingContext;
+                DataMap map = (DataMap) parent;
                 return map.getObjEntity(name) != null;
             }
         });
@@ -115,7 +115,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
         return resolve(new Predicate() {
             @Override
             public boolean isNameInUse(String name) {
-                DataMap map = (DataMap) namingContext;
+                DataMap map = (DataMap) parent;
                 return map.getDbEntity(name) != null;
             }
         });
@@ -126,7 +126,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
         return resolve(new Predicate() {
             @Override
             public boolean isNameInUse(String name) {
-                DataMap map = (DataMap) namingContext;
+                DataMap map = (DataMap) parent;
                 return map.getEmbeddable(map.getNameWithDefaultPackage(name)) 
!= null;
             }
         });
@@ -137,7 +137,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
         return resolve(new Predicate() {
             @Override
             public boolean isNameInUse(String name) {
-                Embeddable emb = (Embeddable) namingContext;
+                Embeddable emb = (Embeddable) parent;
                 return emb.getAttribute(name) != null;
             }
         });
@@ -168,7 +168,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
         return resolve(new Predicate() {
             @Override
             public boolean isNameInUse(String name) {
-                DataMap map = (DataMap) namingContext;
+                DataMap map = (DataMap) parent;
                 return map.getProcedure(name) != null;
             }
         });
@@ -183,7 +183,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
                 // it doesn't matter if we create a parameter with a duplicate 
name.. parameters are positional anyway..
                 // still try to use unique names for visual consistency
 
-                Procedure procedure = (Procedure) namingContext;
+                Procedure procedure = (Procedure) parent;
                 for (ProcedureParameter parameter : 
procedure.getCallParameters()) {
                     if (name.equals(parameter.getName())) {
                         return true;
@@ -200,7 +200,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
         return resolve(new Predicate() {
             @Override
             public boolean isNameInUse(String name) {
-                DataMap map = (DataMap) namingContext;
+                DataMap map = (DataMap) parent;
                 return map.getQueryDescriptor(name) != null;
             }
         });
@@ -212,11 +212,11 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
             @Override
             public boolean isNameInUse(String name) {
 
-                if (namingContext == null) {
+                if (parent == null) {
                     return false;
                 }
 
-                DataChannelDescriptor dataChannelDescriptor = 
(DataChannelDescriptor) namingContext;
+                DataChannelDescriptor dataChannelDescriptor = 
(DataChannelDescriptor) parent;
                 for (DataMap dataMap : dataChannelDescriptor.getDataMaps()) {
                     if (dataMap != null && dataMap.getReverseEngineering() != 
null &&
                             dataMap.getReverseEngineering().getName() != null
@@ -244,7 +244,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
             @Override
             public boolean isNameInUse(String name) {
 
-                DbEntity entity = (DbEntity) namingContext;
+                DbEntity entity = (DbEntity) parent;
 
                 // check if either attribute or relationship name matches...
                 return entity.getAttribute(name) != null || 
entity.getRelationship(name) != null;
@@ -257,7 +257,7 @@ class DeduplicationVisitor implements 
ConfigurationNodeVisitor<String> {
             @Override
             public boolean isNameInUse(String name) {
 
-                ObjEntity entity = (ObjEntity) namingContext;
+                ObjEntity entity = (ObjEntity) parent;
 
                 // check if either attribute or relationship name matches...
                 if (entity.getAttribute(name) != null || 
entity.getRelationship(name) != null) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/39b70d1b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameBuilder.java
----------------------------------------------------------------------
diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameBuilder.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameBuilder.java
index c791cbc..b52fded 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameBuilder.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/naming/NameBuilder.java
@@ -24,14 +24,18 @@ import org.apache.cayenne.map.ObjEntity;
 import java.util.Objects;
 
 /**
- * A
+ * A builder of names for model objects. Ensures that newly generated names do 
not conflict with the names of siblings
+ * under the same parent node. Name generation can be performed based on 
default base names for each model object type,
+ * or with a user-provided base name. Used standalone or in conjunction with 
{@link ObjectNameGenerator} that implements
+ * DB-to-object name mapping conversions. Names generated by {@link 
ObjectNameGenerator} can be used as "base names" for
+ * {@link NameBuilder}.
  *
  * @since 4.0
  */
 public class NameBuilder {
 
     protected ConfigurationNode nodeToName;
-    protected ConfigurationNode namingContext;
+    protected ConfigurationNode parent;
     protected String dupesPattern;
     protected String baseName;
 
@@ -44,8 +48,8 @@ public class NameBuilder {
         return new NameBuilder(node);
     }
 
-    public static NameBuilder builder(ConfigurationNode node, 
ConfigurationNode namingContext) {
-        return new NameBuilder(node).in(namingContext);
+    public static NameBuilder builder(ConfigurationNode node, 
ConfigurationNode parent) {
+        return new NameBuilder(node).in(parent);
     }
 
     /**
@@ -54,12 +58,12 @@ public class NameBuilder {
      */
     // TODO: fold CallbackMethod to org.apache.cayenne.map package and make it 
a ConfigurationNode
     // then we can use normal API for it... for now have to keep a special 
one-off method...
-    public static NameBuilder builderForCallbackMethod(ObjEntity 
namingContext) {
-        return new CallbackNameBuilder().in(namingContext);
+    public static NameBuilder builderForCallbackMethod(ObjEntity parent) {
+        return new CallbackNameBuilder().in(parent);
     }
 
-    public NameBuilder in(ConfigurationNode namingContext) {
-        this.namingContext = Objects.requireNonNull(namingContext);
+    public NameBuilder in(ConfigurationNode parent) {
+        this.parent = Objects.requireNonNull(parent);
         return this;
     }
 
@@ -79,6 +83,6 @@ public class NameBuilder {
                 : nodeToName.acceptVisitor(DefaultBaseNameVisitor.INSTANCE);
 
         String normalizedBaseName = nodeToName.acceptVisitor(new 
NormalizationVisitor(baseName));
-        return nodeToName.acceptVisitor(new 
DeduplicationVisitor(namingContext, normalizedBaseName, dupesPattern));
+        return nodeToName.acceptVisitor(new DeduplicationVisitor(parent, 
normalizedBaseName, dupesPattern));
     }
 }

Reply via email to