cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/3] cayenne git commit: CAY-2116 Split schema synchronization code in a separate module
Date Sun, 02 Oct 2016 18:31:31 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java
index 5ee3c0e..5b1841d 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java
@@ -19,11 +19,10 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
@@ -36,8 +35,6 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.event.AttributeEvent;
 import org.apache.cayenne.map.event.EmbeddableAttributeEvent;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
@@ -46,19 +43,60 @@ import org.apache.cayenne.modeler.undo.CreateAttributeUndoableEdit;
 import org.apache.cayenne.modeler.undo.CreateEmbAttributeUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 
+import java.awt.event.ActionEvent;
+
 /**
  */
 public class CreateAttributeAction extends CayenneAction {
 
+    /**
+     * Constructor for CreateAttributeAction.
+     */
+    public CreateAttributeAction(Application application) {
+        super(getActionName(), application);
+    }
+
     public static String getActionName() {
         return "Create Attribute";
     }
 
+    static void fireEmbeddableAttributeEvent(Object src, ProjectController mediator, Embeddable embeddable,
+                                             EmbeddableAttribute attr) {
+
+        mediator.fireEmbeddableAttributeEvent(new EmbeddableAttributeEvent(src, attr, embeddable, MapEvent.ADD));
+
+        EmbeddableAttributeDisplayEvent e = new EmbeddableAttributeDisplayEvent(src, embeddable, attr,
+                mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
+
+        mediator.fireEmbeddableAttributeDisplayEvent(e);
+    }
+
     /**
-     * Constructor for CreateAttributeAction.
+     * Fires events when an obj attribute was added
      */
-    public CreateAttributeAction(Application application) {
-        super(getActionName(), application);
+    static void fireObjAttributeEvent(Object src, ProjectController mediator, DataMap map, ObjEntity objEntity,
+                                      ObjAttribute attr) {
+
+        mediator.fireObjAttributeEvent(new AttributeEvent(src, attr, objEntity, MapEvent.ADD));
+
+        DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
+
+        AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, objEntity, map, domain);
+
+        mediator.fireObjAttributeDisplayEvent(ade);
+    }
+
+    /**
+     * Fires events when a db attribute was added
+     */
+    static void fireDbAttributeEvent(Object src, ProjectController mediator, DataMap map, DbEntity dbEntity,
+                                     DbAttribute attr) {
+        mediator.fireDbAttributeEvent(new AttributeEvent(src, attr, dbEntity, MapEvent.ADD));
+
+        AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, dbEntity, map,
+                (DataChannelDescriptor) mediator.getProject().getRootNode());
+
+        mediator.fireDbAttributeDisplayEvent(ade);
     }
 
     @Override
@@ -77,19 +115,22 @@ public class CreateAttributeAction extends CayenneAction {
             Embeddable embeddable = mediator.getCurrentEmbeddable();
 
             EmbeddableAttribute attr = new EmbeddableAttribute();
-            attr.setName(DuplicateNameResolver.resolve(NameCheckers.embeddableAttribute, embeddable));
+            attr.setName(NameBuilder
+                    .builder(attr, embeddable)
+                    .name());
 
             createEmbAttribute(embeddable, attr);
 
             application.getUndoManager().addEdit(
-                    new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[] { attr }));
+                    new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[]{attr}));
         }
 
         if (getProjectController().getCurrentObjEntity() != null) {
 
             ObjEntity objEntity = mediator.getCurrentObjEntity();
 
-            ObjAttribute attr = new ObjAttribute(DuplicateNameResolver.resolve(NameCheckers.objAttribute, objEntity), null, objEntity);
+            ObjAttribute attr = new ObjAttribute();
+            attr.setName(NameBuilder.builder(attr, objEntity).name());
 
             createObjAttribute(mediator.getCurrentDataMap(), objEntity, attr);
 
@@ -99,8 +140,10 @@ public class CreateAttributeAction extends CayenneAction {
         } else if (getProjectController().getCurrentDbEntity() != null) {
             DbEntity dbEntity = getProjectController().getCurrentDbEntity();
 
-            DbAttribute attr = new DbAttribute(DuplicateNameResolver.resolve(NameCheckers.dbAttribute, dbEntity),
-                    TypesMapping.NOT_DEFINED, dbEntity);
+            DbAttribute attr = new DbAttribute();
+            attr.setName(NameBuilder.builder(attr, dbEntity).name());
+            attr.setType(TypesMapping.NOT_DEFINED);
+            attr.setEntity(dbEntity);
 
             createDbAttribute(mediator.getCurrentDataMap(), dbEntity, attr);
 
@@ -116,17 +159,6 @@ public class CreateAttributeAction extends CayenneAction {
         fireEmbeddableAttributeEvent(this, mediator, embeddable, attr);
     }
 
-    static void fireEmbeddableAttributeEvent(Object src, ProjectController mediator, Embeddable embeddable,
-            EmbeddableAttribute attr) {
-
-        mediator.fireEmbeddableAttributeEvent(new EmbeddableAttributeEvent(src, attr, embeddable, MapEvent.ADD));
-
-        EmbeddableAttributeDisplayEvent e = new EmbeddableAttributeDisplayEvent(src, embeddable, attr,
-                mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
-
-        mediator.fireEmbeddableAttributeDisplayEvent(e);
-    }
-
     public void createObjAttribute(DataMap map, ObjEntity objEntity, ObjAttribute attr) {
 
         ProjectController mediator = getProjectController();
@@ -134,21 +166,6 @@ public class CreateAttributeAction extends CayenneAction {
         fireObjAttributeEvent(this, mediator, map, objEntity, attr);
     }
 
-    /**
-     * Fires events when an obj attribute was added
-     */
-    static void fireObjAttributeEvent(Object src, ProjectController mediator, DataMap map, ObjEntity objEntity,
-            ObjAttribute attr) {
-
-        mediator.fireObjAttributeEvent(new AttributeEvent(src, attr, objEntity, MapEvent.ADD));
-
-        DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
-
-        AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, objEntity, map, domain);
-
-        mediator.fireObjAttributeDisplayEvent(ade);
-    }
-
     public void createDbAttribute(DataMap map, DbEntity dbEntity, DbAttribute attr) {
         dbEntity.addAttribute(attr);
         ProjectController mediator = getProjectController();
@@ -156,19 +173,6 @@ public class CreateAttributeAction extends CayenneAction {
     }
 
     /**
-     * Fires events when a db attribute was added
-     */
-    static void fireDbAttributeEvent(Object src, ProjectController mediator, DataMap map, DbEntity dbEntity,
-            DbAttribute attr) {
-        mediator.fireDbAttributeEvent(new AttributeEvent(src, attr, dbEntity, MapEvent.ADD));
-
-        AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, dbEntity, map,
-                (DataChannelDescriptor) mediator.getProject().getRootNode());
-
-        mediator.fireDbAttributeDisplayEvent(ade);
-    }
-
-    /**
      * Returns <code>true</code> if path contains an Entity object.
      */
     @Override

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateCallbackMethodAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateCallbackMethodAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateCallbackMethodAction.java
index cc37948..a3b5507 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateCallbackMethodAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateCallbackMethodAction.java
@@ -18,8 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.action;
 
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.CallbackMap;
 import org.apache.cayenne.map.LifecycleEvent;
 import org.apache.cayenne.map.event.MapEvent;
@@ -34,11 +33,9 @@ import java.awt.event.ActionEvent;
 
 /**
  * Action class for creating callback methods on ObjEntity
- *
- * @version 1.0 Oct 30, 2007
  */
 public class CreateCallbackMethodAction extends CayenneAction {
-    
+
     /**
      * unique action name
      */
@@ -46,8 +43,8 @@ public class CreateCallbackMethodAction extends CayenneAction {
 
     /**
      * Constructor.
-     * 
-     * @param actionName unique action name
+     *
+     * @param actionName  unique action name
      * @param application Application instance
      */
     public CreateCallbackMethodAction(String actionName, Application application) {
@@ -55,12 +52,25 @@ public class CreateCallbackMethodAction extends CayenneAction {
     }
 
     /**
+     * Constructor.
+     *
+     * @param application Application instance
+     */
+    public CreateCallbackMethodAction(Application application) {
+        super(ACTION_NAME, application);
+    }
+
+    public static String getActionName() {
+        return ACTION_NAME;
+    }
+
+    /**
      * @return CallbackMap instance where to create a method
      */
     public CallbackMap getCallbackMap() {
         return getProjectController().getCurrentObjEntity().getCallbackMap();
     }
-    
+
     /**
      * @return icon file name for button
      */
@@ -70,14 +80,16 @@ public class CreateCallbackMethodAction extends CayenneAction {
 
     /**
      * performs adding new callback method
-     * 
+     *
      * @param e event
      */
     public final void performAction(ActionEvent e) {
         CallbackType callbackType = getProjectController().getCurrentCallbackType();
 
-        String methodNamePrefix = toMethodName(callbackType.getType());
-        String methodName = DuplicateNameResolver.resolve(NameCheckers.objCallbackMethod, getProjectController().getCurrentObjEntity(), methodNamePrefix);
+        String methodName = NameBuilder
+                .builderForCallbackMethod(getProjectController().getCurrentObjEntity())
+                .baseName(toMethodName(callbackType.getType()))
+                .name();
 
         createCallbackMethod(callbackType, methodName);
         application.getUndoManager().addEdit(
@@ -103,18 +115,5 @@ public class CreateCallbackMethodAction extends CayenneAction {
     private String toMethodName(LifecycleEvent event) {
         return "on" + Util.underscoredToJava(event.name(), true);
     }
-    
-    public static String getActionName() {
-        return ACTION_NAME;
-    }
-    
-    /**
-     * Constructor.
-     *
-     * @param application Application instance
-     */
-    public CreateCallbackMethodAction(Application application) {
-        super(ACTION_NAME, application);
-    }
 }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapAction.java
index 8403cb7..66dbae7 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapAction.java
@@ -22,9 +22,8 @@ package org.apache.cayenne.modeler.action;
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.undo.CreateDataMapUndoableEdit;
@@ -34,7 +33,6 @@ import java.awt.event.ActionEvent;
 
 /**
  * Action that creates new DataMap in the project.
- * 
  */
 public class CreateDataMapAction extends CayenneAction {
 
@@ -59,16 +57,15 @@ public class CreateDataMapAction extends CayenneAction {
     public void performAction(ActionEvent e) {
         ProjectController mediator = getProjectController();
 
-        DataChannelDescriptor currentDomain = (DataChannelDescriptor) mediator
+        DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) mediator
                 .getProject()
                 .getRootNode();
 
-        DataMap map = new DataMap(DuplicateNameResolver.resolve(NameCheckers.dataMap, currentDomain));
-
+        DataMap map = new DataMap();
+        map.setName(NameBuilder.builder(map, dataChannelDescriptor).name());
         createDataMap(map);
 
-        application.getUndoManager().addEdit(
-                new CreateDataMapUndoableEdit(currentDomain, map));
+        application.getUndoManager().addEdit(new CreateDataMapUndoableEdit(dataChannelDescriptor, map));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDbEntityAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDbEntityAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDbEntityAction.java
index abeaee3..1117bf1 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDbEntityAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDbEntityAction.java
@@ -19,88 +19,84 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.event.EntityEvent;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.undo.CreateDbEntityUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 
-public class CreateDbEntityAction extends CayenneAction {
+import java.awt.event.ActionEvent;
 
-	public static String getActionName() {
-		return "Create DbEntity";
-	}
+public class CreateDbEntityAction extends CayenneAction {
 
-	/**
-	 * Constructor for CreateDbEntityAction.
-	 */
-	public CreateDbEntityAction(Application application) {
-		super(getActionName(), application);
-	}
+    /**
+     * Constructor for CreateDbEntityAction.
+     */
+    public CreateDbEntityAction(Application application) {
+        super(getActionName(), application);
+    }
 
-	public String getIconName() {
-		return "icon-dbentity.gif";
-	}
+    public static String getActionName() {
+        return "Create DbEntity";
+    }
 
-	/**
-	 * Creates new DbEntity, adds it to the current DataMap, fires DbEntityEvent
-	 * and DbEntityDisplayEvent.
-	 * 
-	 * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
-	 */
-	public void performAction(ActionEvent e) {
-		ProjectController mediator = getProjectController();
+    /**
+     * Fires events when a db entity was added
+     */
+    static void fireDbEntityEvent(Object src, ProjectController mediator, DbEntity entity) {
+        mediator.fireDbEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
+        EntityDisplayEvent displayEvent = new EntityDisplayEvent(src, entity, mediator.getCurrentDataMap(),
+                mediator.getCurrentDataNode(), (DataChannelDescriptor) mediator.getProject().getRootNode());
+        displayEvent.setMainTabFocus(true);
+        mediator.fireDbEntityDisplayEvent(displayEvent);
+    }
 
-		DataMap map = mediator.getCurrentDataMap();
-		DbEntity entity = new DbEntity(DuplicateNameResolver.resolve(NameCheckers.dbEntity, map));
+    public String getIconName() {
+        return "icon-dbentity.gif";
+    }
 
-		createEntity(map, entity);
+    /**
+     * Creates new DbEntity, adds it to the current DataMap, fires DbEntityEvent and DbEntityDisplayEvent.
+     */
+    public void performAction(ActionEvent e) {
+        ProjectController mediator = getProjectController();
 
-		application.getUndoManager().addEdit(new CreateDbEntityUndoableEdit(map, entity));
-	}
+        DataMap map = mediator.getCurrentDataMap();
+        DbEntity entity = new DbEntity();
+        entity.setName(NameBuilder.builder(entity, map).name());
+        createEntity(map, entity);
 
-	/**
-	 * Fires events when a db entity was added
-	 */
-	static void fireDbEntityEvent(Object src, ProjectController mediator, DbEntity entity) {
-		mediator.fireDbEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
-		EntityDisplayEvent displayEvent = new EntityDisplayEvent(src, entity, mediator.getCurrentDataMap(),
-				mediator.getCurrentDataNode(), (DataChannelDescriptor) mediator.getProject().getRootNode());
-		displayEvent.setMainTabFocus(true);
-		mediator.fireDbEntityDisplayEvent(displayEvent);
-	}
+        application.getUndoManager().addEdit(new CreateDbEntityUndoableEdit(map, entity));
+    }
 
-	/**
-	 * Constructs and returns a new DbEntity. Entity returned is added to the
-	 * DataMap.
-	 */
-	public void createEntity(DataMap map, DbEntity entity) {
-		ProjectController mediator = getProjectController();
-		entity.setCatalog(map.getDefaultCatalog());
-		entity.setSchema(map.getDefaultSchema());
-		map.addDbEntity(entity);
-		fireDbEntityEvent(this, mediator, entity);
-	}
+    /**
+     * Constructs and returns a new DbEntity. Entity returned is added to the
+     * DataMap.
+     */
+    public void createEntity(DataMap map, DbEntity entity) {
+        ProjectController mediator = getProjectController();
+        entity.setCatalog(map.getDefaultCatalog());
+        entity.setSchema(map.getDefaultSchema());
+        map.addDbEntity(entity);
+        fireDbEntityEvent(this, mediator, entity);
+    }
 
-	/**
-	 * Returns <code>true</code> if path contains a DataMap object.
-	 */
-	public boolean enableForPath(ConfigurationNode object) {
-		if (object == null) {
-			return false;
-		}
+    /**
+     * Returns <code>true</code> if path contains a DataMap object.
+     */
+    public boolean enableForPath(ConfigurationNode object) {
+        if (object == null) {
+            return false;
+        }
 
-		return ((Entity) object).getDataMap() != null;
-	}
+        return ((Entity) object).getDataMap() != null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateEmbeddableAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateEmbeddableAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateEmbeddableAction.java
index 7fea640..fe073ec 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateEmbeddableAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateEmbeddableAction.java
@@ -18,23 +18,22 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Embeddable;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.event.EmbeddableEvent;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.EmbeddableDisplayEvent;
 import org.apache.cayenne.modeler.undo.CreateEmbeddableUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 
+import java.awt.event.ActionEvent;
+
 public class CreateEmbeddableAction extends CayenneAction {
 
     public static String getActionName() {
@@ -56,11 +55,11 @@ public class CreateEmbeddableAction extends CayenneAction {
 
         DataMap dataMap = mediator.getCurrentDataMap();
 
-        Embeddable embeddable = new Embeddable(DuplicateNameResolver.resolve(NameCheckers.embeddable, mediator.getCurrentDataMap()));
+        Embeddable embeddable = new Embeddable();
+        embeddable.setClassName(NameBuilder.builder(embeddable, dataMap).name());
         createEmbeddable(dataMap, embeddable);
 
-        application.getUndoManager().addEdit(
-                new CreateEmbeddableUndoableEdit(dataMap, embeddable));
+        application.getUndoManager().addEdit(new CreateEmbeddableUndoableEdit(dataMap, embeddable));
     }
 
     public void createEmbeddable(DataMap dataMap, Embeddable embeddable) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
index eb0fbf9..56a0437 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
@@ -19,8 +19,6 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
-
 import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
@@ -28,86 +26,86 @@ import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.event.DataNodeEvent;
 import org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory;
 import org.apache.cayenne.conn.DataSourceInfo;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.DataNodeDisplayEvent;
 import org.apache.cayenne.modeler.undo.CreateNodeUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 
+import java.awt.event.ActionEvent;
+
 public class CreateNodeAction extends CayenneAction {
 
-	public static String getActionName() {
-		return "Create DataNode";
-	}
-
-	/**
-	 * Constructor for CreateNodeAction.
-	 * 
-	 * @param application
-	 */
-	public CreateNodeAction(Application application) {
-		super(getActionName(), application);
-	}
-
-	public String getIconName() {
-		return "icon-node.gif";
-	}
-
-	/**
-	 * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
-	 */
-	public void performAction(ActionEvent e) {
-		DataNodeDescriptor node = buildDataNode();
-		createDataNode(node);
-		application.getUndoManager().addEdit(new CreateNodeUndoableEdit(application, node));
-	}
-
-	public void createDataNode(DataNodeDescriptor node) {
-		DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject().getRootNode();
-		domain.getNodeDescriptors().add(node);
-		getProjectController().fireDataNodeEvent(new DataNodeEvent(this, node, MapEvent.ADD));
-		getProjectController().fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this, domain, node));
-	}
-
-	/**
-	 * Returns <code>true</code> if path contains a DataDomain object.
-	 */
-	public boolean enableForPath(ConfigurationNode object) {
-		return object != null && ((DataNodeDescriptor) object).getDataChannelDescriptor() != null;
-
-	}
-
-	/**
-	 * Creates a new DataNode, adding to the current domain, but doesn't send
-	 * any events.
-	 */
-	public DataNodeDescriptor buildDataNode() {
-		ProjectController mediator = getProjectController();
-		DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
-
-		DataNodeDescriptor node = buildDataNode(domain);
-
-		DataSourceInfo src = new DataSourceInfo();
-		node.setDataSourceDescriptor(src);
-
-		// by default create JDBC Node
-		node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
-		node.setSchemaUpdateStrategyType(SkipSchemaUpdateStrategy.class.getName());
-
-		return node;
-	}
-
-	/**
-	 * A factory method that makes a new DataNode.
-	 */
-	DataNodeDescriptor buildDataNode(DataChannelDescriptor domain) {
-		DataNodeDescriptor node = new DataNodeDescriptor(DuplicateNameResolver.resolve(
-				NameCheckers.dataNodeDescriptor, domain));
-		node.setDataChannelDescriptor(domain);
-
-		return node;
-	}
+    /**
+     * Constructor for CreateNodeAction.
+     *
+     * @param application
+     */
+    public CreateNodeAction(Application application) {
+        super(getActionName(), application);
+    }
+
+    public static String getActionName() {
+        return "Create DataNode";
+    }
+
+    @Override
+    public String getIconName() {
+        return "icon-node.gif";
+    }
+
+    @Override
+    public void performAction(ActionEvent e) {
+        DataNodeDescriptor node = buildDataNode();
+        createDataNode(node);
+        application.getUndoManager().addEdit(new CreateNodeUndoableEdit(application, node));
+    }
+
+    public void createDataNode(DataNodeDescriptor node) {
+        DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject().getRootNode();
+        domain.getNodeDescriptors().add(node);
+        getProjectController().fireDataNodeEvent(new DataNodeEvent(this, node, MapEvent.ADD));
+        getProjectController().fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this, domain, node));
+    }
+
+    /**
+     * Returns <code>true</code> if path contains a DataDomain object.
+     */
+    public boolean enableForPath(ConfigurationNode object) {
+        return object != null && ((DataNodeDescriptor) object).getDataChannelDescriptor() != null;
+
+    }
+
+    /**
+     * Creates a new DataNode, adding to the current domain, but doesn't send
+     * any events.
+     */
+    public DataNodeDescriptor buildDataNode() {
+        ProjectController mediator = getProjectController();
+        DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
+
+        DataNodeDescriptor node = buildDataNode(domain);
+
+        DataSourceInfo src = new DataSourceInfo();
+        node.setDataSourceDescriptor(src);
+
+        // by default create JDBC Node
+        node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
+        node.setSchemaUpdateStrategyType(SkipSchemaUpdateStrategy.class.getName());
+
+        return node;
+    }
+
+    /**
+     * A factory method that makes a new DataNode.
+     */
+    DataNodeDescriptor buildDataNode(DataChannelDescriptor dataChannelDescriptor) {
+        DataNodeDescriptor node = new DataNodeDescriptor();
+        node.setName(NameBuilder.builder(node, dataChannelDescriptor).name());
+        node.setDataChannelDescriptor(dataChannelDescriptor);
+
+        return node;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
index 8a2bd4b..8569697 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityAction.java
@@ -22,8 +22,7 @@ package org.apache.cayenne.modeler.action;
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.dbsync.merge.EntityMergeSupport;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.dbsync.reverse.naming.DefaultObjectNameGenerator;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
@@ -36,16 +35,11 @@ import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.undo.CreateObjEntityUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.util.DeleteRuleUpdater;
-import org.apache.cayenne.util.Util;
 
 import java.awt.event.ActionEvent;
 
 public class CreateObjEntityAction extends CayenneAction {
 
-    public static String getActionName() {
-        return "Create ObjEntity";
-    }
-
     /**
      * Constructor for CreateObjEntityAction.
      */
@@ -53,14 +47,32 @@ public class CreateObjEntityAction extends CayenneAction {
         super(getActionName(), application);
     }
 
+    public static String getActionName() {
+        return "Create ObjEntity";
+    }
+
+
+    static void fireObjEntityEvent(
+            Object src,
+            ProjectController mediator,
+            DataMap dataMap,
+            ObjEntity entity) {
+        mediator.fireObjEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
+        EntityDisplayEvent displayEvent = new EntityDisplayEvent(
+                src,
+                entity,
+                dataMap,
+                mediator.getCurrentDataNode(),
+                (DataChannelDescriptor) mediator.getProject().getRootNode());
+        displayEvent.setMainTabFocus(true);
+        mediator.fireObjEntityDisplayEvent(displayEvent);
+    }
+
     @Override
     public String getIconName() {
         return "icon-new_objentity.gif";
     }
 
-    /**
-     * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
-     */
     @Override
     public void performAction(ActionEvent e) {
         createObjEntity();
@@ -70,7 +82,10 @@ public class CreateObjEntityAction extends CayenneAction {
         ProjectController mediator = getProjectController();
 
         DataMap dataMap = mediator.getCurrentDataMap();
-        ObjEntity entity = new ObjEntity(DuplicateNameResolver.resolve(NameCheckers.objEntity, dataMap));
+        ObjEntity entity = new ObjEntity();
+        entity.setName(NameBuilder
+                .builder(entity, dataMap)
+                .name());
 
         // init defaults
         entity.setSuperClassName(dataMap.getDefaultSuperclass());
@@ -79,8 +94,13 @@ public class CreateObjEntityAction extends CayenneAction {
         DbEntity dbEntity = mediator.getCurrentDbEntity();
         if (dbEntity != null) {
             entity.setDbEntity(dbEntity);
-            String baseName = Util.underscoredToJava(dbEntity.getName(), true);
-            entity.setName(DuplicateNameResolver.resolve(NameCheckers.objEntity, dbEntity.getDataMap(), baseName));
+
+            // TODO: use injectable name generator
+            String baseName = new DefaultObjectNameGenerator().createObjEntityName(dbEntity);
+            entity.setName(NameBuilder
+                    .builder(entity, dbEntity.getDataMap())
+                    .baseName(baseName)
+                    .name());
         }
 
         entity.setClassName(dataMap.getNameWithDefaultPackage(entity.getName()));
@@ -110,25 +130,6 @@ public class CreateObjEntityAction extends CayenneAction {
     }
 
     /**
-     * Fires events when a obj entity was added
-     */
-    static void fireObjEntityEvent(
-            Object src,
-            ProjectController mediator,
-            DataMap dataMap,
-            ObjEntity entity) {
-        mediator.fireObjEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
-        EntityDisplayEvent displayEvent = new EntityDisplayEvent(
-                src,
-                entity,
-                dataMap,
-                mediator.getCurrentDataNode(),
-                (DataChannelDescriptor) mediator.getProject().getRootNode());
-        displayEvent.setMainTabFocus(true);
-        mediator.fireObjEntityDisplayEvent(displayEvent);
-    }
-
-    /**
      * Returns <code>true</code> if path contains a DataMap object.
      */
     @Override

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureAction.java
index 7787abc..3dbdaa4 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureAction.java
@@ -19,75 +19,74 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.event.ProcedureEvent;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.ProcedureDisplayEvent;
 import org.apache.cayenne.modeler.undo.CreateProcedureUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 
+import java.awt.event.ActionEvent;
+
 /**
  * Action class to create a new stored procedure mapping.
  */
 public class CreateProcedureAction extends CayenneAction {
 
-	public static String getActionName() {
-		return "Create Stored Procedure";
-	}
-
-	public CreateProcedureAction(Application application) {
-		super(getActionName(), application);
-	}
+    public CreateProcedureAction(Application application) {
+        super(getActionName(), application);
+    }
 
-	public void performAction(ActionEvent e) {
-		ProjectController mediator = getProjectController();
-		DataMap map = mediator.getCurrentDataMap();
+    public static String getActionName() {
+        return "Create Stored Procedure";
+    }
 
-		Procedure procedure = new Procedure(DuplicateNameResolver.resolve(NameCheckers.procedure, map));
+    /**
+     * Fires events when a procedure was added
+     */
+    static void fireProcedureEvent(Object src, ProjectController mediator, DataMap dataMap, Procedure procedure) {
+        mediator.fireProcedureEvent(new ProcedureEvent(src, procedure, MapEvent.ADD));
+        mediator.fireProcedureDisplayEvent(new ProcedureDisplayEvent(src, procedure, mediator.getCurrentDataMap(),
+                (DataChannelDescriptor) mediator.getProject().getRootNode()));
+    }
 
-		createProcedure(map, procedure);
+    public void performAction(ActionEvent e) {
+        ProjectController mediator = getProjectController();
+        DataMap map = mediator.getCurrentDataMap();
 
-		application.getUndoManager().addEdit(new CreateProcedureUndoableEdit(map, procedure));
-	}
+        Procedure procedure = new Procedure();
+        procedure.setName(NameBuilder.builder(procedure, map).name());
+        createProcedure(map, procedure);
 
-	/**
-	 * Fires events when a procedure was added
-	 */
-	static void fireProcedureEvent(Object src, ProjectController mediator, DataMap dataMap, Procedure procedure) {
-		mediator.fireProcedureEvent(new ProcedureEvent(src, procedure, MapEvent.ADD));
-		mediator.fireProcedureDisplayEvent(new ProcedureDisplayEvent(src, procedure, mediator.getCurrentDataMap(),
-				(DataChannelDescriptor) mediator.getProject().getRootNode()));
-	}
+        application.getUndoManager().addEdit(new CreateProcedureUndoableEdit(map, procedure));
+    }
 
-	public void createProcedure(DataMap map, Procedure procedure) {
-		ProjectController mediator = getProjectController();
-		procedure.setSchema(map.getDefaultSchema());
-		procedure.setCatalog(map.getDefaultCatalog());
-		map.addProcedure(procedure);
-		fireProcedureEvent(this, mediator, map, procedure);
-	}
+    public void createProcedure(DataMap map, Procedure procedure) {
+        ProjectController mediator = getProjectController();
+        procedure.setSchema(map.getDefaultSchema());
+        procedure.setCatalog(map.getDefaultCatalog());
+        map.addProcedure(procedure);
+        fireProcedureEvent(this, mediator, map, procedure);
+    }
 
-	/**
-	 * Returns <code>true</code> if path contains a DataMap object.
-	 */
-	public boolean enableForPath(ConfigurationNode object) {
-		if (object == null) {
-			return false;
-		}
+    /**
+     * Returns <code>true</code> if path contains a DataMap object.
+     */
+    public boolean enableForPath(ConfigurationNode object) {
+        if (object == null) {
+            return false;
+        }
 
-		return ((Procedure) object).getDataMap() != null;
-	}
+        return ((Procedure) object).getDataMap() != null;
+    }
 
-	public String getIconName() {
-		return "icon-stored-procedure.gif";
-	}
+    public String getIconName() {
+        return "icon-stored-procedure.gif";
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureParameterAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureParameterAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureParameterAction.java
index e939f86..67c19c5 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureParameterAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateProcedureParameterAction.java
@@ -19,78 +19,78 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.event.ProcedureParameterEvent;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.ProcedureParameterDisplayEvent;
 import org.apache.cayenne.modeler.util.CayenneAction;
 
+import java.awt.event.ActionEvent;
+
 public class CreateProcedureParameterAction extends CayenneAction {
 
-	public static String getActionName() {
-		return "Create Parameter";
-	}
+    /**
+     * Constructor for CreateProcedureParameterAction.
+     */
+    public CreateProcedureParameterAction(Application application) {
+        super(getActionName(), application);
+    }
 
-	/**
-	 * Constructor for CreateProcedureParameterAction.
-	 * 
-	 */
-	public CreateProcedureParameterAction(Application application) {
-		super(getActionName(), application);
-	}
+    public static String getActionName() {
+        return "Create Parameter";
+    }
 
-	public String getIconName() {
-		return "icon-plus.gif";
-	}
+    /**
+     * Fires events when an proc parameter was added
+     */
+    static void fireProcedureParameterEvent(Object src, ProjectController mediator, Procedure procedure,
+                                            ProcedureParameter parameter) {
+        mediator.fireProcedureParameterEvent(new ProcedureParameterEvent(src, parameter, MapEvent.ADD));
 
-	/**
-	 * Creates ProcedureParameter depending on context.
-	 */
-	public void performAction(ActionEvent e) {
-		if (getProjectController().getCurrentProcedure() != null) {
-			createProcedureParameter();
-		}
-	}
+        mediator.fireProcedureParameterDisplayEvent(new ProcedureParameterDisplayEvent(src, parameter, procedure,
+                mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
+    }
 
-	public void createProcedureParameter() {
-		Procedure procedure = getProjectController().getCurrentProcedure();
+    @Override
+    public String getIconName() {
+        return "icon-plus.gif";
+    }
 
-		ProcedureParameter parameter = new ProcedureParameter(DuplicateNameResolver.resolve(
-				NameCheckers.procedureParameter, procedure));
-		procedure.addCallParameter(parameter);
+    /**
+     * Creates ProcedureParameter depending on context.
+     */
+    @Override
+    public void performAction(ActionEvent e) {
+        if (getProjectController().getCurrentProcedure() != null) {
+            createProcedureParameter();
+        }
+    }
 
-		ProjectController mediator = getProjectController();
-		fireProcedureParameterEvent(this, mediator, procedure, parameter);
-	}
+    public void createProcedureParameter() {
+        Procedure procedure = getProjectController().getCurrentProcedure();
 
-	/**
-	 * Fires events when an proc parameter was added
-	 */
-	static void fireProcedureParameterEvent(Object src, ProjectController mediator, Procedure procedure,
-			ProcedureParameter parameter) {
-		mediator.fireProcedureParameterEvent(new ProcedureParameterEvent(src, parameter, MapEvent.ADD));
+        ProcedureParameter parameter = new ProcedureParameter();
+        parameter.setName(NameBuilder.builder(parameter, procedure).name());
+        procedure.addCallParameter(parameter);
 
-		mediator.fireProcedureParameterDisplayEvent(new ProcedureParameterDisplayEvent(src, parameter, procedure,
-				mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
-	}
+        ProjectController mediator = getProjectController();
+        fireProcedureParameterEvent(this, mediator, procedure, parameter);
+    }
 
-	/**
-	 * Returns <code>true</code> if path contains a Procedure object.
-	 */
-	public boolean enableForPath(ConfigurationNode object) {
-		if (object == null) {
-			return false;
-		}
+    /**
+     * Returns <code>true</code> if path contains a Procedure object.
+     */
+    public boolean enableForPath(ConfigurationNode object) {
+        if (object == null) {
+            return false;
+        }
 
-		return ((ProcedureParameter) object).getProcedure() != null;
-	}
+        return ((ProcedureParameter) object).getProcedure() != null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateRelationshipAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateRelationshipAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateRelationshipAction.java
index 8abec0c..ec3a42d 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateRelationshipAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateRelationshipAction.java
@@ -19,10 +19,9 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.Entity;
@@ -31,8 +30,6 @@ import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Relationship;
 import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.map.event.RelationshipEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.RelationshipDisplayEvent;
@@ -40,111 +37,113 @@ import org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.util.DeleteRuleUpdater;
 
+import java.awt.event.ActionEvent;
+
 public class CreateRelationshipAction extends CayenneAction {
 
-	public static String getActionName() {
-		return "Create Relationship";
-	}
-
-	/**
-	 * Constructor for CreateRelationshipAction.
-	 */
-	public CreateRelationshipAction(Application application) {
-		super(getActionName(), application);
-	}
-
-	@Override
-	public String getIconName() {
-		return "icon-relationship.gif";
-	}
-
-	/**
-	 * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
-	 */
-	@Override
-	public void performAction(ActionEvent e) {
-		ObjEntity objEnt = getProjectController().getCurrentObjEntity();
-		if (objEnt != null) {
-
-			ObjRelationship rel = new ObjRelationship(DuplicateNameResolver.resolve(NameCheckers.objRelationship,
-					objEnt));
-			createObjRelationship(objEnt, rel);
-
-			application.getUndoManager().addEdit(
-					new CreateRelationshipUndoableEdit(objEnt, new ObjRelationship[] { rel }));
-		} else {
-			DbEntity dbEnt = getProjectController().getCurrentDbEntity();
-			if (dbEnt != null) {
-
-				DbRelationship rel = new DbRelationship(DuplicateNameResolver.resolve(
-						NameCheckers.dbRelationship, dbEnt));
-				createDbRelationship(dbEnt, rel);
-
-				application.getUndoManager().addEdit(
-						new CreateRelationshipUndoableEdit(dbEnt, new DbRelationship[] { rel }));
-			}
-		}
-	}
-
-	public void createObjRelationship(ObjEntity objEntity, ObjRelationship rel) {
-		ProjectController mediator = getProjectController();
-
-		rel.setSourceEntity(objEntity);
-		DeleteRuleUpdater.updateObjRelationship(rel);
-
-		objEntity.addRelationship(rel);
-		fireObjRelationshipEvent(this, mediator, objEntity, rel);
-	}
-
-	/**
-	 * Fires events when a obj rel was added
-	 */
-	static void fireObjRelationshipEvent(Object src, ProjectController mediator, ObjEntity objEntity,
-			ObjRelationship rel) {
-
-		mediator.fireObjRelationshipEvent(new RelationshipEvent(src, rel, objEntity, MapEvent.ADD));
-
-		RelationshipDisplayEvent rde = new RelationshipDisplayEvent(src, rel, objEntity, mediator.getCurrentDataMap(),
-				(DataChannelDescriptor) mediator.getProject().getRootNode());
-
-		mediator.fireObjRelationshipDisplayEvent(rde);
-	}
-
-	public void createDbRelationship(DbEntity dbEntity, DbRelationship rel) {
-		ProjectController mediator = getProjectController();
-
-		rel.setSourceEntity(dbEntity);
-		dbEntity.addRelationship(rel);
-
-		fireDbRelationshipEvent(this, mediator, dbEntity, rel);
-	}
-
-	/**
-	 * Fires events when a db rel was added
-	 */
-	static void fireDbRelationshipEvent(Object src, ProjectController mediator, DbEntity dbEntity, DbRelationship rel) {
-
-		mediator.fireDbRelationshipEvent(new RelationshipEvent(src, rel, dbEntity, MapEvent.ADD));
-
-		RelationshipDisplayEvent rde = new RelationshipDisplayEvent(src, rel, dbEntity, mediator.getCurrentDataMap(),
-				(DataChannelDescriptor) mediator.getProject().getRootNode());
-
-		mediator.fireDbRelationshipDisplayEvent(rde);
-	}
-
-	/**
-	 * Returns <code>true</code> if path contains an Entity object.
-	 */
-	@Override
-	public boolean enableForPath(ConfigurationNode object) {
-		if (object == null) {
-			return false;
-		}
-
-		if (object instanceof Relationship) {
-			return ((Relationship) object).getParent() != null && ((Relationship) object).getParent() instanceof Entity;
-		}
-
-		return false;
-	}
+    /**
+     * Constructor for CreateRelationshipAction.
+     */
+    public CreateRelationshipAction(Application application) {
+        super(getActionName(), application);
+    }
+
+    public static String getActionName() {
+        return "Create Relationship";
+    }
+
+    /**
+     * Fires events when a obj rel was added
+     */
+    static void fireObjRelationshipEvent(Object src, ProjectController mediator, ObjEntity objEntity,
+                                         ObjRelationship rel) {
+
+        mediator.fireObjRelationshipEvent(new RelationshipEvent(src, rel, objEntity, MapEvent.ADD));
+
+        RelationshipDisplayEvent rde = new RelationshipDisplayEvent(src, rel, objEntity, mediator.getCurrentDataMap(),
+                (DataChannelDescriptor) mediator.getProject().getRootNode());
+
+        mediator.fireObjRelationshipDisplayEvent(rde);
+    }
+
+    /**
+     * Fires events when a db rel was added
+     */
+    static void fireDbRelationshipEvent(Object src, ProjectController mediator, DbEntity dbEntity, DbRelationship rel) {
+
+        mediator.fireDbRelationshipEvent(new RelationshipEvent(src, rel, dbEntity, MapEvent.ADD));
+
+        RelationshipDisplayEvent rde = new RelationshipDisplayEvent(src, rel, dbEntity, mediator.getCurrentDataMap(),
+                (DataChannelDescriptor) mediator.getProject().getRootNode());
+
+        mediator.fireDbRelationshipDisplayEvent(rde);
+    }
+
+    @Override
+    public String getIconName() {
+        return "icon-relationship.gif";
+    }
+
+    /**
+     * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
+     */
+    @Override
+    public void performAction(ActionEvent e) {
+        ObjEntity objEnt = getProjectController().getCurrentObjEntity();
+        if (objEnt != null) {
+
+            ObjRelationship rel = new ObjRelationship();
+            rel.setName(NameBuilder.builder(rel, objEnt).name());
+            createObjRelationship(objEnt, rel);
+
+            application.getUndoManager().addEdit(
+                    new CreateRelationshipUndoableEdit(objEnt, new ObjRelationship[]{rel}));
+        } else {
+            DbEntity dbEnt = getProjectController().getCurrentDbEntity();
+            if (dbEnt != null) {
+
+                DbRelationship rel = new DbRelationship();
+                rel.setName(NameBuilder.builder(rel, dbEnt).name());
+                createDbRelationship(dbEnt, rel);
+
+                application.getUndoManager().addEdit(
+                        new CreateRelationshipUndoableEdit(dbEnt, new DbRelationship[]{rel}));
+            }
+        }
+    }
+
+    public void createObjRelationship(ObjEntity objEntity, ObjRelationship rel) {
+        ProjectController mediator = getProjectController();
+
+        rel.setSourceEntity(objEntity);
+        DeleteRuleUpdater.updateObjRelationship(rel);
+
+        objEntity.addRelationship(rel);
+        fireObjRelationshipEvent(this, mediator, objEntity, rel);
+    }
+
+    public void createDbRelationship(DbEntity dbEntity, DbRelationship rel) {
+        ProjectController mediator = getProjectController();
+
+        rel.setSourceEntity(dbEntity);
+        dbEntity.addRelationship(rel);
+
+        fireDbRelationshipEvent(this, mediator, dbEntity, rel);
+    }
+
+    /**
+     * Returns <code>true</code> if path contains an Entity object.
+     */
+    @Override
+    public boolean enableForPath(ConfigurationNode object) {
+        if (object == null) {
+            return false;
+        }
+
+        if (object instanceof Relationship) {
+            return ((Relationship) object).getParent() != null && ((Relationship) object).getParent() instanceof Entity;
+        }
+
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDataMapAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDataMapAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDataMapAction.java
index 3158e90..732963d 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDataMapAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDataMapAction.java
@@ -19,20 +19,11 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.Frame;
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-
-import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
-
+import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.pref.FSPath;
 import org.apache.cayenne.modeler.util.CayenneAction;
@@ -42,91 +33,95 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.InputSource;
 
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
 /**
  * Modeler action that imports a DataMap into a project from an arbitrary
  * location.
- * 
+ *
  * @since 1.1
  */
 public class ImportDataMapAction extends CayenneAction {
 
-	private static Log logObj = LogFactory.getLog(ImportDataMapAction.class);
-
-	public static String getActionName() {
-		return "Import DataMap";
-	}
-
-	public ImportDataMapAction(Application application) {
-		super(getActionName(), application);
-	}
+    private static Log logObj = LogFactory.getLog(ImportDataMapAction.class);
 
-	public void performAction(ActionEvent e) {
-		importDataMap();
-	}
+    public ImportDataMapAction(Application application) {
+        super(getActionName(), application);
+    }
 
-	protected void importDataMap() {
-		File dataMapFile = selectDataMap(Application.getFrame());
-		if (dataMapFile == null) {
-			return;
-		}
+    public static String getActionName() {
+        return "Import DataMap";
+    }
 
-		DataMap newMap;
+    public void performAction(ActionEvent e) {
+        importDataMap();
+    }
 
-		try {
+    protected void importDataMap() {
+        File dataMapFile = selectDataMap(Application.getFrame());
+        if (dataMapFile == null) {
+            return;
+        }
 
-			URL url = dataMapFile.toURI().toURL();
+        DataMap newMap;
 
-			try (InputStream in = url.openStream();) {
-				InputSource inSrc = new InputSource(in);
-				inSrc.setSystemId(dataMapFile.getAbsolutePath());
-				newMap = new MapLoader().loadDataMap(inSrc);
-			}
+        try {
+            URL url = dataMapFile.toURI().toURL();
 
-			DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject().getRootNode();
+            try (InputStream in = url.openStream();) {
+                InputSource inSrc = new InputSource(in);
+                inSrc.setSystemId(dataMapFile.getAbsolutePath());
+                newMap = new MapLoader().loadDataMap(inSrc);
+            }
 
-			if (newMap.getName() != null) {
-				newMap.setName(DuplicateNameResolver.resolve(NameCheckers.dataMap, domain, newMap.getName()));
-			} else {
-				newMap.setName(DuplicateNameResolver.resolve(NameCheckers.dataMap, domain));
-			}
+            ConfigurationNode root = getProjectController().getProject().getRootNode();
+            newMap.setName(NameBuilder
+                    .builder(newMap, root)
+                    .baseName(newMap.getName())
+                    .name());
 
-			Resource baseResource = domain.getConfigurationSource();
+            Resource baseResource = ((DataChannelDescriptor) root).getConfigurationSource();
 
-			if (baseResource != null) {
-				Resource dataMapResource = baseResource.getRelativeResource(newMap.getName());
-				newMap.setConfigurationSource(dataMapResource);
-			}
+            if (baseResource != null) {
+                Resource dataMapResource = baseResource.getRelativeResource(newMap.getName());
+                newMap.setConfigurationSource(dataMapResource);
+            }
 
-			getProjectController().addDataMap(this, newMap);
-		} catch (Exception ex) {
-			logObj.info("Error importing DataMap.", ex);
-			JOptionPane.showMessageDialog(Application.getFrame(), "Error reading DataMap: " + ex.getMessage(),
-					"Can't Open DataMap", JOptionPane.OK_OPTION);
-		}
-	}
+            getProjectController().addDataMap(this, newMap);
+        } catch (Exception ex) {
+            logObj.info("Error importing DataMap.", ex);
+            JOptionPane.showMessageDialog(Application.getFrame(), "Error reading DataMap: " + ex.getMessage(),
+                    "Can't Open DataMap", JOptionPane.OK_OPTION);
+        }
+    }
 
-	protected File selectDataMap(Frame f) {
+    protected File selectDataMap(Frame f) {
 
-		// find start directory in preferences
-		FSPath lastDir = getApplication().getFrameController().getLastDirectory();
+        // find start directory in preferences
+        FSPath lastDir = getApplication().getFrameController().getLastDirectory();
 
-		// configure dialog
-		JFileChooser chooser = new JFileChooser();
-		chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
-		lastDir.updateChooser(chooser);
+        // configure dialog
+        JFileChooser chooser = new JFileChooser();
+        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+        lastDir.updateChooser(chooser);
 
-		chooser.addChoosableFileFilter(FileFilters.getDataMapFilter());
+        chooser.addChoosableFileFilter(FileFilters.getDataMapFilter());
 
-		int status = chooser.showDialog(f, "Select DataMap");
-		if (status == JFileChooser.APPROVE_OPTION) {
-			File file = chooser.getSelectedFile();
+        int status = chooser.showDialog(f, "Select DataMap");
+        if (status == JFileChooser.APPROVE_OPTION) {
+            File file = chooser.getSelectedFile();
 
-			// save to preferences...
-			lastDir.updateFromChooser(chooser);
+            // save to preferences...
+            lastDir.updateFromChooser(chooser);
 
-			return file;
-		}
+            return file;
+        }
 
-		return null;
-	}
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java
index 8c5f1c6..75290c6 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportEOModelAction.java
@@ -19,20 +19,7 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.Component;
-import java.awt.HeadlessException;
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.swing.JDialog;
-import javax.swing.JFileChooser;
-import javax.swing.filechooser.FileFilter;
-
+import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.event.DataNodeEvent;
@@ -41,12 +28,12 @@ import org.apache.cayenne.configuration.server.JNDIDataSourceFactory;
 import org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory;
 import org.apache.cayenne.conn.DataSourceInfo;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.map.event.EntityEvent;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
@@ -56,12 +43,22 @@ import org.apache.cayenne.modeler.pref.FSPath;
 import org.apache.cayenne.modeler.util.AdapterMapping;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.modeler.util.FileFilters;
-import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.wocompat.EOModelProcessor;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.swing.*;
+import javax.swing.filechooser.FileFilter;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
 /**
  * Action handler for WebObjects EOModel import function.
  * 
@@ -301,8 +298,11 @@ public class ImportEOModelAction extends CayenneAction {
         }
         else {
             // fix DataMap name, as there maybe a map with the same name already
-            DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
-            map.setName(DuplicateNameResolver.resolve(NameCheckers.dataMap, domain, map.getName()));
+            ConfigurationNode root = (DataChannelDescriptor) mediator.getProject().getRootNode();
+            map.setName(NameBuilder
+                    .builder(map, root)
+                    .baseName(map.getName())
+                    .name());
 
             // side effect of this operation is that if a node was created, this DataMap
             // will be linked with it...

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/NewProjectAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/NewProjectAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/NewProjectAction.java
index 468ff1d..b5bbbc5 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/NewProjectAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/NewProjectAction.java
@@ -19,23 +19,19 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.Toolkit;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-
-import javax.swing.KeyStroke;
-
 import org.apache.cayenne.configuration.ConfigurationTree;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.CayenneModelerController;
 import org.apache.cayenne.modeler.event.DomainDisplayEvent;
 import org.apache.cayenne.project.Project;
 
-/**
- */
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
 public class NewProjectAction extends ProjectAction {
 
     public static String getActionName() {
@@ -66,17 +62,18 @@ public class NewProjectAction extends ProjectAction {
             return;
         }
 
-        DataChannelDescriptor domain = new DataChannelDescriptor();
+        DataChannelDescriptor dataChannelDescriptor = new DataChannelDescriptor();
 
-        domain.setName(DuplicateNameResolver.resolve(NameCheckers.dataChannelDescriptor, domain));
+        dataChannelDescriptor.setName(NameBuilder
+                .builder(dataChannelDescriptor)
+                .name());
 
         Project project = new Project(
-                new ConfigurationTree<DataChannelDescriptor>(domain));
+                new ConfigurationTree<DataChannelDescriptor>(dataChannelDescriptor));
 
         controller.projectOpenedAction(project);
 
         // select default domain
-        getProjectController().fireDomainDisplayEvent(
-                new DomainDisplayEvent(this, domain));
+        getProjectController().fireDomainDisplayEvent(new DomainDisplayEvent(this, dataChannelDescriptor));
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/38e4e7fd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java
index a146307..cf835ef 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java
@@ -21,6 +21,7 @@ package org.apache.cayenne.modeler.action;
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
+import org.apache.cayenne.dbsync.naming.NameBuilder;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -34,9 +35,8 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.dbsync.naming.DuplicateNameResolver;
-import org.apache.cayenne.dbsync.naming.NameCheckers;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
@@ -48,11 +48,10 @@ import org.apache.cayenne.modeler.undo.PasteUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.modeler.util.CayenneTransferable;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.map.QueryDescriptor;
 
-import javax.swing.KeyStroke;
+import javax.swing.*;
 import javax.swing.undo.UndoableEdit;
-import java.awt.Toolkit;
+import java.awt.*;
 import java.awt.datatransfer.FlavorEvent;
 import java.awt.datatransfer.FlavorListener;
 import java.awt.datatransfer.UnsupportedFlavorException;
@@ -69,10 +68,6 @@ public class PasteAction extends CayenneAction implements FlavorListener {
 
     private static final String COPY_PATTERN = "Copy of %s (%d)";
 
-    public static String getActionName() {
-        return "Paste";
-    }
-
     /**
      * Constructor for PasteAction
      */
@@ -84,6 +79,10 @@ public class PasteAction extends CayenneAction implements FlavorListener {
         Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(this);
     }
 
+    public static String getActionName() {
+        return "Paste";
+    }
+
     @Override
     public String getIconName() {
         return "icon-paste.gif";
@@ -125,19 +124,16 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                                 currentObject,
                                 o));
                     }
-                }
-                else {
+                } else {
                     paste(currentObject, content);
                     undoableEdit = new PasteUndoableEdit(domain, map, currentObject, content);
                 }
 
                 application.getUndoManager().addEdit(undoableEdit);
             }
-        }
-        catch (UnsupportedFlavorException ufe) {
+        } catch (UnsupportedFlavorException ufe) {
             // do nothing
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             ErrorDebugDialog.guiException(ex);
         }
     }
@@ -154,7 +150,7 @@ public class PasteAction extends CayenneAction implements FlavorListener {
     public void paste(
             Object where,
             Object content,
-            DataChannelDescriptor domain,
+            DataChannelDescriptor dataChannelDescriptor,
             DataMap map) {
         final ProjectController mediator = getProjectController();
 
@@ -171,7 +167,11 @@ public class PasteAction extends CayenneAction implements FlavorListener {
             // paste DataMap to DataDomain or DataNode
             DataMap dataMap = ((DataMap) content);
 
-            dataMap.setName(DuplicateNameResolver.resolve(NameCheckers.dataMap, COPY_PATTERN, domain, dataMap.getName()));
+            dataMap.setName(NameBuilder
+                    .builder(dataMap, dataChannelDescriptor)
+                    .baseName(dataMap.getName())
+                    .dupesPattern(COPY_PATTERN)
+                    .name());
 
             /**
              * Update all names in the new DataMap, so that they would not conflict with
@@ -182,20 +182,28 @@ public class PasteAction extends CayenneAction implements FlavorListener {
             // to it as well
             Map<String, String> renamedDbEntities = new HashMap<>();
             Map<String, String> renamedObjEntities = new HashMap<>();
-
             Map<String, String> renamedEmbeddables = new HashMap<>();
 
             for (DbEntity dbEntity : dataMap.getDbEntities()) {
                 String oldName = dbEntity.getName();
-                dbEntity.setName(DuplicateNameResolver.resolve(NameCheckers.dbEntity, COPY_PATTERN, dataMap, dbEntity.getName()));
+                dbEntity.setName(NameBuilder
+                        .builder(dbEntity, dataMap)
+                        .baseName(dbEntity.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 if (!oldName.equals(dbEntity.getName())) {
                     renamedDbEntities.put(oldName, dbEntity.getName());
                 }
             }
+
             for (ObjEntity objEntity : dataMap.getObjEntities()) {
                 String oldName = objEntity.getName();
-                objEntity.setName(DuplicateNameResolver.resolve(NameCheckers.objEntity, COPY_PATTERN, dataMap, objEntity.getName()));
+                objEntity.setName(NameBuilder
+                        .builder(objEntity, dataMap)
+                        .baseName(objEntity.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 if (!oldName.equals(objEntity.getName())) {
                     renamedObjEntities.put(oldName, objEntity.getName());
@@ -204,7 +212,11 @@ public class PasteAction extends CayenneAction implements FlavorListener {
 
             for (Embeddable embeddable : dataMap.getEmbeddables()) {
                 String oldName = embeddable.getClassName();
-                embeddable.setClassName(DuplicateNameResolver.resolve(NameCheckers.embeddable, COPY_PATTERN, dataMap, embeddable.getClassName()));
+                embeddable.setClassName(NameBuilder
+                        .builder(embeddable, dataMap)
+                        .baseName(embeddable.getClassName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 if (!oldName.equals(embeddable.getClassName())) {
                     renamedEmbeddables.put(oldName, embeddable.getClassName());
@@ -212,10 +224,18 @@ public class PasteAction extends CayenneAction implements FlavorListener {
             }
 
             for (Procedure procedure : dataMap.getProcedures()) {
-                procedure.setName(DuplicateNameResolver.resolve(NameCheckers.procedure, COPY_PATTERN, dataMap, procedure.getName()));
+                procedure.setName(NameBuilder
+                        .builder(procedure, dataMap)
+                        .baseName(procedure.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
             }
+
             for (QueryDescriptor query : dataMap.getQueryDescriptors()) {
-                query.setName(DuplicateNameResolver.resolve(NameCheckers.query, COPY_PATTERN, dataMap, query.getName()));
+                query.setName(NameBuilder.builder(query, dataMap)
+                        .baseName(query.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
             }
 
             // if an entity was renamed, we rename all links to it too
@@ -247,8 +267,7 @@ public class PasteAction extends CayenneAction implements FlavorListener {
             }
 
             mediator.addDataMap(this, dataMap);
-        }
-        else if (where instanceof DataMap) {
+        } else if (where instanceof DataMap) {
             // paste DbEntity to DataMap
             final DataMap dataMap = ((DataMap) where);
 
@@ -257,15 +276,21 @@ public class PasteAction extends CayenneAction implements FlavorListener {
 
             if (content instanceof DbEntity) {
                 DbEntity dbEntity = (DbEntity) content;
-                dbEntity.setName(DuplicateNameResolver.resolve(NameCheckers.dbEntity, COPY_PATTERN, dataMap, dbEntity.getName()));
+                dbEntity.setName(NameBuilder
+                        .builder(dbEntity, dataMap)
+                        .baseName(dbEntity.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 dataMap.addDbEntity(dbEntity);
                 CreateDbEntityAction.fireDbEntityEvent(this, mediator, dbEntity);
-            }
-            else if (content instanceof ObjEntity) {
+            } else if (content instanceof ObjEntity) {
                 // paste ObjEntity to DataMap
                 ObjEntity objEntity = (ObjEntity) content;
-                objEntity.setName(DuplicateNameResolver.resolve(NameCheckers.objEntity, COPY_PATTERN, dataMap, objEntity.getName()));
+                objEntity.setName(NameBuilder.builder(objEntity, dataMap)
+                        .baseName(objEntity.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 dataMap.addObjEntity(objEntity);
                 CreateObjEntityAction.fireObjEntityEvent(
@@ -273,11 +298,14 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                         mediator,
                         dataMap,
                         objEntity);
-            }
-            else if (content instanceof Embeddable) {
+            } else if (content instanceof Embeddable) {
                 // paste Embeddable to DataMap
                 Embeddable embeddable = (Embeddable) content;
-                embeddable.setClassName(DuplicateNameResolver.resolve(NameCheckers.embeddable, COPY_PATTERN, dataMap, embeddable.getClassName()));
+                embeddable.setClassName(NameBuilder
+                        .builder(embeddable, dataMap)
+                        .baseName(embeddable.getClassName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 dataMap.addEmbeddable(embeddable);
                 CreateEmbeddableAction.fireEmbeddableEvent(
@@ -285,20 +313,26 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                         mediator,
                         dataMap,
                         embeddable);
-            }
-            else if (content instanceof QueryDescriptor) {
+            } else if (content instanceof QueryDescriptor) {
                 QueryDescriptor query = (QueryDescriptor) content;
 
-                query.setName(DuplicateNameResolver.resolve(NameCheckers.query, COPY_PATTERN, dataMap, query.getName()));
+                query.setName(NameBuilder
+                        .builder(query, dataMap)
+                        .dupesPattern(COPY_PATTERN)
+                        .baseName(query.getName())
+                        .name());
                 query.setDataMap(dataMap);
 
                 dataMap.addQueryDescriptor(query);
                 QueryType.fireQueryEvent(this, mediator, dataMap, query);
-            }
-            else if (content instanceof Procedure) {
+            } else if (content instanceof Procedure) {
                 // paste Procedure to DataMap
                 Procedure procedure = (Procedure) content;
-                procedure.setName(DuplicateNameResolver.resolve(NameCheckers.procedure, COPY_PATTERN, dataMap, procedure.getName()));
+                procedure.setName(NameBuilder
+                        .builder(procedure, dataMap)
+                        .dupesPattern(COPY_PATTERN)
+                        .baseName(procedure.getName())
+                        .name());
 
                 dataMap.addProcedure(procedure);
                 CreateProcedureAction.fireProcedureEvent(
@@ -307,21 +341,27 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                         dataMap,
                         procedure);
             }
-        }
-        else if (where instanceof DbEntity) {
+        } else if (where instanceof DbEntity) {
             final DbEntity dbEntity = (DbEntity) where;
 
             if (content instanceof DbAttribute) {
                 DbAttribute attr = (DbAttribute) content;
-                attr.setName(DuplicateNameResolver.resolve(NameCheckers.dbAttribute, COPY_PATTERN, dbEntity, attr.getName()));
+                attr.setName(NameBuilder
+                        .builder(attr, dbEntity)
+                        .dupesPattern(COPY_PATTERN)
+                        .baseName(attr.getName())
+                        .name());
 
                 dbEntity.addAttribute(attr);
                 CreateAttributeAction.fireDbAttributeEvent(this, mediator, mediator
                         .getCurrentDataMap(), dbEntity, attr);
-            }
-            else if (content instanceof DbRelationship) {
+            } else if (content instanceof DbRelationship) {
                 DbRelationship rel = (DbRelationship) content;
-                rel.setName(DuplicateNameResolver.resolve(NameCheckers.dbRelationship, COPY_PATTERN, dbEntity, rel.getName()));
+                rel.setName(NameBuilder
+                        .builder(rel, dbEntity)
+                        .baseName(rel.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 dbEntity.addRelationship(rel);
                 CreateRelationshipAction.fireDbRelationshipEvent(
@@ -330,22 +370,27 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                         dbEntity,
                         rel);
             }
-        }
-        else if (where instanceof ObjEntity) {
-            final ObjEntity objEntity = (ObjEntity) where;
-
+        } else if (where instanceof ObjEntity) {
+            ObjEntity objEntity = (ObjEntity) where;
 
             if (content instanceof ObjAttribute) {
                 ObjAttribute attr = (ObjAttribute) content;
-                attr.setName(DuplicateNameResolver.resolve(NameCheckers.objAttribute, COPY_PATTERN, objEntity, attr.getName()));
+                attr.setName(NameBuilder
+                        .builder(attr, objEntity)
+                        .baseName(attr.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 objEntity.addAttribute(attr);
                 CreateAttributeAction.fireObjAttributeEvent(this, mediator, mediator
                         .getCurrentDataMap(), objEntity, attr);
-            }
-            else if (content instanceof ObjRelationship) {
+            } else if (content instanceof ObjRelationship) {
                 ObjRelationship rel = (ObjRelationship) content;
-                rel.setName(DuplicateNameResolver.resolve(NameCheckers.objRelationship, COPY_PATTERN, objEntity, rel.getName()));
+                rel.setName(NameBuilder
+                        .builder(rel, objEntity)
+                        .baseName(rel.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 objEntity.addRelationship(rel);
                 CreateRelationshipAction.fireObjRelationshipEvent(
@@ -353,13 +398,18 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                         mediator,
                         objEntity,
                         rel);
-            }
-            else if(content instanceof ObjCallbackMethod) {
+            } else if (content instanceof ObjCallbackMethod) {
                 ObjCallbackMethod method = (ObjCallbackMethod) content;
 
-                method.setName(DuplicateNameResolver.resolve(NameCheckers.objCallbackMethod, COPY_PATTERN, objEntity, method.getName()));
-                
-                objEntity.getCallbackMap().getCallbackDescriptor(mediator.getCurrentCallbackType().getType()).addCallbackMethod(method.getName());
+                method.setName(NameBuilder
+                        .builderForCallbackMethod(objEntity)
+                        .baseName(method.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
+
+                objEntity.getCallbackMap()
+                        .getCallbackDescriptor(mediator.getCurrentCallbackType().getType())
+                        .addCallbackMethod(method.getName());
 
                 CallbackMethodEvent ce = new CallbackMethodEvent(
                         this,
@@ -369,14 +419,16 @@ public class PasteAction extends CayenneAction implements FlavorListener {
 
                 getProjectController().fireCallbackMethodEvent(ce);
             }
-        }
-
-        else if (where instanceof Embeddable) {
+        } else if (where instanceof Embeddable) {
             final Embeddable embeddable = (Embeddable) where;
 
             if (content instanceof EmbeddableAttribute) {
                 EmbeddableAttribute attr = (EmbeddableAttribute) content;
-                attr.setName(DuplicateNameResolver.resolve(NameCheckers.embeddableAttribute, COPY_PATTERN, embeddable, attr.getName()));
+                attr.setName(NameBuilder
+                        .builder(attr, embeddable)
+                        .baseName(attr.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 embeddable.addAttribute(attr);
                 CreateAttributeAction.fireEmbeddableAttributeEvent(
@@ -386,16 +438,18 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                         attr);
             }
 
-        }
-
-        else if (where instanceof Procedure) {
+        } else if (where instanceof Procedure) {
             // paste param to procedure
             final Procedure procedure = (Procedure) where;
 
             if (content instanceof ProcedureParameter) {
                 ProcedureParameter param = (ProcedureParameter) content;
 
-                param.setName(DuplicateNameResolver.resolve(NameCheckers.procedureParameter, COPY_PATTERN, procedure, param.getName()));
+                param.setName(NameBuilder
+                        .builder(param, procedure)
+                        .baseName(param.getName())
+                        .dupesPattern(COPY_PATTERN)
+                        .name());
 
                 procedure.addCallParameter(param);
                 CreateProcedureParameterAction.fireProcedureParameterEvent(
@@ -476,9 +530,8 @@ public class PasteAction extends CayenneAction implements FlavorListener {
                     (currentObject instanceof Procedure
                             && (content instanceof ProcedureParameter || isTreeLeaf(content)) ||
 
-                    (currentObject instanceof Query && isTreeLeaf(content)));
-        }
-        catch (Exception ex) {
+                            (currentObject instanceof Query && isTreeLeaf(content)));
+        } catch (Exception ex) {
             return false;
         }
     }


Mime
View raw message