cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [12/16] cayenne git commit: CAY-2169 - split Tokens to model and db packages - all tests are passing - fix SQL syntax for HSQLDB allow column NULL value - fix some problems with tokens sort, but still it's far from perfect (see CAY-2170)
Date Wed, 14 Dec 2016 19:12:48 GMT
CAY-2169
 - split Tokens to model and db packages
 - all tests are passing
 - fix SQL syntax for HSQLDB allow column NULL value
 - fix some problems with tokens sort, but still it's far from perfect (see CAY-2170)


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

Branch: refs/heads/master
Commit: 725e6ae94edf35a6d0340ecd5d09a91da4904dfc
Parents: d5707c7
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Mon Dec 12 17:35:43 2016 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Mon Dec 12 17:35:43 2016 +0300

----------------------------------------------------------------------
 .../cayenne/dbsync/merge/DataMapMerger.java     |   2 +-
 .../cayenne/dbsync/merge/DbAttributeMerger.java |   8 +-
 .../dbsync/merge/DbEntityDictionary.java        |   3 +-
 .../cayenne/dbsync/merge/DbEntityMerger.java    |  11 +-
 .../merge/factory/DB2MergerTokenFactory.java    |   2 +-
 .../factory/DefaultMergerTokenFactory.java      |  42 ++--
 .../merge/factory/DerbyMergerTokenFactory.java  |   6 +-
 .../factory/FirebirdMergerTokenFactory.java     |   8 +-
 .../merge/factory/H2MergerTokenFactory.java     |   6 +-
 .../merge/factory/HSQLMergerTokenFactory.java   |   8 +-
 .../merge/factory/IngresMergerTokenFactory.java |  12 +-
 .../merge/factory/MySQLMergerTokenFactory.java  |  10 +-
 .../factory/OpenBaseMergerTokenFactory.java     |  10 +-
 .../merge/factory/OracleMergerTokenFactory.java |   8 +-
 .../factory/PostgresMergerTokenFactory.java     |   4 +-
 .../factory/SQLServerMergerTokenFactory.java    |   8 +-
 .../merge/factory/SybaseMergerTokenFactory.java |  10 +-
 .../dbsync/merge/token/AbstractToDbToken.java   | 133 -----------
 .../merge/token/AbstractToModelToken.java       | 128 ----------
 .../dbsync/merge/token/AddColumnToDb.java       |  74 ------
 .../dbsync/merge/token/AddColumnToModel.java    |  55 -----
 .../dbsync/merge/token/AddRelationshipToDb.java |  88 -------
 .../merge/token/AddRelationshipToModel.java     |  91 -------
 .../dbsync/merge/token/CreateTableToDb.java     |  88 -------
 .../dbsync/merge/token/CreateTableToModel.java  | 100 --------
 .../dbsync/merge/token/DropColumnToDb.java      |  62 -----
 .../dbsync/merge/token/DropColumnToModel.java   |  79 ------
 .../merge/token/DropRelationshipToDb.java       |  84 -------
 .../merge/token/DropRelationshipToModel.java    |  51 ----
 .../dbsync/merge/token/DropTableToDb.java       |  52 ----
 .../dbsync/merge/token/DropTableToModel.java    |  53 -----
 .../dbsync/merge/token/DummyReverseToken.java   |   2 +-
 .../dbsync/merge/token/SetAllowNullToDb.java    |  59 -----
 .../dbsync/merge/token/SetAllowNullToModel.java |  47 ----
 .../dbsync/merge/token/SetColumnTypeToDb.java   | 112 ---------
 .../merge/token/SetColumnTypeToModel.java       |  97 --------
 .../dbsync/merge/token/SetNotNullToDb.java      |  53 -----
 .../dbsync/merge/token/SetNotNullToModel.java   |  47 ----
 .../dbsync/merge/token/SetPrimaryKeyToDb.java   |  88 -------
 .../merge/token/SetPrimaryKeyToModel.java       |  82 -------
 .../dbsync/merge/token/SetValueForNullToDb.java |  49 ----
 .../dbsync/merge/token/TokenComparator.java     |  14 +-
 .../merge/token/db/AbstractToDbToken.java       | 134 +++++++++++
 .../dbsync/merge/token/db/AddColumnToDb.java    |  76 ++++++
 .../merge/token/db/AddRelationshipToDb.java     |  84 +++++++
 .../dbsync/merge/token/db/CreateTableToDb.java  |  89 +++++++
 .../dbsync/merge/token/db/DropColumnToDb.java   |  63 +++++
 .../merge/token/db/DropRelationshipToDb.java    |  85 +++++++
 .../dbsync/merge/token/db/DropTableToDb.java    |  53 +++++
 .../dbsync/merge/token/db/SetAllowNullToDb.java |  60 +++++
 .../merge/token/db/SetColumnTypeToDb.java       | 113 +++++++++
 .../dbsync/merge/token/db/SetNotNullToDb.java   |  54 +++++
 .../merge/token/db/SetPrimaryKeyToDb.java       |  89 +++++++
 .../merge/token/db/SetValueForNullToDb.java     |  52 ++++
 .../merge/token/model/AbstractToModelToken.java | 129 ++++++++++
 .../merge/token/model/AddColumnToModel.java     |  56 +++++
 .../token/model/AddRelationshipToModel.java     |  92 +++++++
 .../merge/token/model/CreateTableToModel.java   | 101 ++++++++
 .../merge/token/model/DropColumnToModel.java    |  80 +++++++
 .../token/model/DropRelationshipToModel.java    |  52 ++++
 .../merge/token/model/DropTableToModel.java     |  54 +++++
 .../merge/token/model/SetAllowNullToModel.java  |  48 ++++
 .../merge/token/model/SetColumnTypeToModel.java |  98 ++++++++
 .../merge/token/model/SetNotNullToModel.java    |  48 ++++
 .../merge/token/model/SetPrimaryKeyToModel.java |  83 +++++++
 .../dbsync/merge/AddColumnToModelIT.java        | 100 --------
 .../dbsync/merge/CreateTableToModelIT.java      | 100 --------
 .../cayenne/dbsync/merge/DataMapMergerTest.java |   2 +-
 .../dbsync/merge/DropColumnToModelIT.java       | 238 -------------------
 .../dbsync/merge/DropRelationshipToModelIT.java | 193 ---------------
 .../dbsync/merge/DropTableToModelIT.java        |  96 --------
 .../apache/cayenne/dbsync/merge/MergeCase.java  |   6 +-
 .../dbsync/merge/SetAllowNullToDbIT.java        |  66 -----
 .../cayenne/dbsync/merge/SetNotNullToDbIT.java  |  62 -----
 .../dbsync/merge/SetPrimaryKeyToDbIT.java       |  58 -----
 .../dbsync/merge/TokenComparatorTest.java       | 115 ---------
 .../cayenne/dbsync/merge/TokensReverseTest.java |  91 -------
 .../merge/TokensToModelExecutionTest.java       |  81 -------
 .../cayenne/dbsync/merge/ValueForNullIT.java    | 127 ----------
 .../dbsync/merge/token/TokenComparatorTest.java | 113 +++++++++
 .../dbsync/merge/token/TokensReverseTest.java   |  90 +++++++
 .../merge/token/TokensToModelExecutionTest.java |  82 +++++++
 .../dbsync/merge/token/ValueForNullIT.java      | 129 ++++++++++
 .../merge/token/db/SetAllowNullToDbIT.java      |  68 ++++++
 .../dbsync/merge/token/db/SetNotNullToDbIT.java |  64 +++++
 .../merge/token/db/SetPrimaryKeyToDbIT.java     |  60 +++++
 .../merge/token/model/AddColumnToModelIT.java   | 101 ++++++++
 .../merge/token/model/CreateTableToModelIT.java | 100 ++++++++
 .../merge/token/model/DropColumnToModelIT.java  | 238 +++++++++++++++++++
 .../token/model/DropRelationshipToModelIT.java  | 192 +++++++++++++++
 .../merge/token/model/DropTableToModelIT.java   |  97 ++++++++
 .../tools/dbimport/DefaultDbImportAction.java   |   2 +-
 .../dbimport/DefaultDbImportActionTest.java     |  12 +-
 .../modeler/dialog/db/MergerOptions.java        |   2 +-
 94 files changed, 3240 insertions(+), 3184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java
index ce49565..a4dac01 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DataMapMerger.java
@@ -60,8 +60,8 @@ public class DataMapMerger implements Merger<DataMap> {
         prepare(original, importedFromDb);
 
         createDbEntityMerger(original, importedFromDb);
-        createAttributeMerger(original, importedFromDb);
         createRelationshipMerger(original, importedFromDb);
+        createAttributeMerger(original, importedFromDb);
 
         return createTokens();
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java
index caee8e4..5c37489 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbAttributeMerger.java
@@ -19,6 +19,7 @@
 
 package org.apache.cayenne.dbsync.merge;
 
+import java.sql.Types;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
@@ -125,7 +126,12 @@ class DbAttributeMerger extends AbstractMerger<DbEntity, DbAttribute> {
         }
 
         if(original.getMaxLength() != imported.getMaxLength()) {
-            return true;
+            int[] typesWithMaxLength = {Types.NCHAR, Types.NVARCHAR, Types.CHAR, Types.VARCHAR};
+            for(int type : typesWithMaxLength) {
+                if(original.getType() == type) {
+                    return true;
+                }
+            }
         }
 
         if(original.getScale() != imported.getScale()) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityDictionary.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityDictionary.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityDictionary.java
index 8f2068b..82b6a61 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityDictionary.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityDictionary.java
@@ -40,7 +40,8 @@ class DbEntityDictionary extends MergerDictionary<DbEntity> {
 
     @Override
     String getName(DbEntity entity) {
-        return entity.getFullyQualifiedName();
+//        return entity.getFullyQualifiedName();
+        return entity.getName();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityMerger.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityMerger.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityMerger.java
index e6a0247..9f7a7c6 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityMerger.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/DbEntityMerger.java
@@ -22,6 +22,7 @@ package org.apache.cayenne.dbsync.merge;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
 
@@ -32,6 +33,7 @@ import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.DetectedDbEntity;
 
 class DbEntityMerger extends AbstractMerger<DataMap, DbEntity> {
@@ -74,7 +76,14 @@ class DbEntityMerger extends AbstractMerger<DataMap, DbEntity> {
      */
     @Override
     Collection<MergerToken> createTokensForMissingImported(DbEntity original) {
-        return Collections.singleton(getTokenFactory().createCreateTableToDb(original));
+        Collection<MergerToken> tokens = new LinkedList<>();
+        // add entity
+        tokens.add(getTokenFactory().createCreateTableToDb(original));
+        // add it's relationships
+        for (DbRelationship rel : original.getRelationships()) {
+            tokens.add(getTokenFactory().createAddRelationshipToDb(original, rel));
+        }
+        return tokens;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DB2MergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DB2MergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DB2MergerTokenFactory.java
index 5100184..04669f0 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DB2MergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DB2MergerTokenFactory.java
@@ -20,7 +20,7 @@ package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DefaultMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DefaultMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DefaultMergerTokenFactory.java
index 80121fe..54132f1 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DefaultMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DefaultMergerTokenFactory.java
@@ -18,29 +18,29 @@
  ****************************************************************/
 package org.apache.cayenne.dbsync.merge.factory;
 
-import org.apache.cayenne.dbsync.merge.token.AddColumnToDb;
-import org.apache.cayenne.dbsync.merge.token.AddColumnToModel;
-import org.apache.cayenne.dbsync.merge.token.AddRelationshipToDb;
-import org.apache.cayenne.dbsync.merge.token.AddRelationshipToModel;
-import org.apache.cayenne.dbsync.merge.token.CreateTableToDb;
-import org.apache.cayenne.dbsync.merge.token.CreateTableToModel;
-import org.apache.cayenne.dbsync.merge.token.DropColumnToDb;
-import org.apache.cayenne.dbsync.merge.token.DropColumnToModel;
-import org.apache.cayenne.dbsync.merge.token.DropRelationshipToDb;
-import org.apache.cayenne.dbsync.merge.token.DropRelationshipToModel;
-import org.apache.cayenne.dbsync.merge.token.DropTableToDb;
-import org.apache.cayenne.dbsync.merge.token.DropTableToModel;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToModel;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToModel;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToModel;
-import org.apache.cayenne.dbsync.merge.token.SetPrimaryKeyToDb;
-import org.apache.cayenne.dbsync.merge.token.SetPrimaryKeyToModel;
-import org.apache.cayenne.dbsync.merge.token.SetValueForNullToDb;
 import org.apache.cayenne.dbsync.merge.token.ValueForNullProvider;
+import org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.AddRelationshipToDb;
+import org.apache.cayenne.dbsync.merge.token.db.CreateTableToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropTableToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetPrimaryKeyToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetValueForNullToDb;
+import org.apache.cayenne.dbsync.merge.token.model.AddColumnToModel;
+import org.apache.cayenne.dbsync.merge.token.model.AddRelationshipToModel;
+import org.apache.cayenne.dbsync.merge.token.model.CreateTableToModel;
+import org.apache.cayenne.dbsync.merge.token.model.DropColumnToModel;
+import org.apache.cayenne.dbsync.merge.token.model.DropRelationshipToModel;
+import org.apache.cayenne.dbsync.merge.token.model.DropTableToModel;
+import org.apache.cayenne.dbsync.merge.token.model.SetAllowNullToModel;
+import org.apache.cayenne.dbsync.merge.token.model.SetColumnTypeToModel;
+import org.apache.cayenne.dbsync.merge.token.model.SetNotNullToModel;
+import org.apache.cayenne.dbsync.merge.token.model.SetPrimaryKeyToModel;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DerbyMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DerbyMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DerbyMergerTokenFactory.java
index 8979fa0..b91234d 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DerbyMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/DerbyMergerTokenFactory.java
@@ -21,9 +21,9 @@ package org.apache.cayenne.dbsync.merge.factory;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/FirebirdMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/FirebirdMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/FirebirdMergerTokenFactory.java
index ce94ba0..fe36898 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/FirebirdMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/FirebirdMergerTokenFactory.java
@@ -21,11 +21,11 @@ package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.token.AddColumnToDb;
-import org.apache.cayenne.dbsync.merge.token.DropColumnToDb;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/H2MergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/H2MergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/H2MergerTokenFactory.java
index 803921c..c2d0e5f 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/H2MergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/H2MergerTokenFactory.java
@@ -22,9 +22,9 @@ package org.apache.cayenne.dbsync.merge.factory;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetPrimaryKeyToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetPrimaryKeyToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/HSQLMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/HSQLMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/HSQLMergerTokenFactory.java
index d168118..5816871 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/HSQLMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/HSQLMergerTokenFactory.java
@@ -21,9 +21,9 @@ package org.apache.cayenne.dbsync.merge.factory;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetPrimaryKeyToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetPrimaryKeyToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
@@ -59,7 +59,7 @@ public class HSQLMergerTokenFactory extends DefaultMergerTokenFactory {
                 QuotingStrategy context = adapter.getQuotingStrategy();
 
                 return Collections.singletonList("ALTER TABLE " + context.quotedFullyQualifiedName(getEntity())
-                        + " ALTER COLUMN " + context.quotedName(getColumn()) + " NULL");
+                        + " ALTER COLUMN " + context.quotedName(getColumn()) + " SET NULL");
             }
 
         };

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/IngresMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/IngresMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/IngresMergerTokenFactory.java
index 4dc715e..89e329b 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/IngresMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/IngresMergerTokenFactory.java
@@ -20,13 +20,13 @@ package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.token.AddRelationshipToDb;
-import org.apache.cayenne.dbsync.merge.token.DropColumnToDb;
-import org.apache.cayenne.dbsync.merge.token.DropRelationshipToDb;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.AddRelationshipToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/MySQLMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/MySQLMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/MySQLMergerTokenFactory.java
index 1d4ab9f..ad49bc0 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/MySQLMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/MySQLMergerTokenFactory.java
@@ -20,12 +20,12 @@ package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.token.DropRelationshipToDb;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetPrimaryKeyToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetPrimaryKeyToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OpenBaseMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OpenBaseMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OpenBaseMergerTokenFactory.java
index 19fa0b9..88a3eb0 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OpenBaseMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OpenBaseMergerTokenFactory.java
@@ -19,12 +19,12 @@
 package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.token.CreateTableToDb;
-import org.apache.cayenne.dbsync.merge.token.DropRelationshipToDb;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.CreateTableToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OracleMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OracleMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OracleMergerTokenFactory.java
index 865e5a7..26236ad 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OracleMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/OracleMergerTokenFactory.java
@@ -20,11 +20,11 @@ package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.token.AddColumnToDb;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/PostgresMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/PostgresMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/PostgresMergerTokenFactory.java
index a14b99d..c85cfdf 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/PostgresMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/PostgresMergerTokenFactory.java
@@ -19,10 +19,10 @@
 package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dbsync.merge.token.MergerToken;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
 
 public class PostgresMergerTokenFactory extends DefaultMergerTokenFactory {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SQLServerMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SQLServerMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SQLServerMergerTokenFactory.java
index 00673ad..a15558d 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SQLServerMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SQLServerMergerTokenFactory.java
@@ -20,11 +20,11 @@ package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.token.AddColumnToDb;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SybaseMergerTokenFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SybaseMergerTokenFactory.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SybaseMergerTokenFactory.java
index 48b5a22..14238ad 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SybaseMergerTokenFactory.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/factory/SybaseMergerTokenFactory.java
@@ -20,12 +20,12 @@ package org.apache.cayenne.dbsync.merge.factory;
 
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.token.AddColumnToDb;
-import org.apache.cayenne.dbsync.merge.token.DropColumnToDb;
 import org.apache.cayenne.dbsync.merge.token.MergerToken;
-import org.apache.cayenne.dbsync.merge.token.SetAllowNullToDb;
-import org.apache.cayenne.dbsync.merge.token.SetColumnTypeToDb;
-import org.apache.cayenne.dbsync.merge.token.SetNotNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb;
+import org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToDbToken.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToDbToken.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToDbToken.java
deleted file mode 100644
index b054ddb..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToDbToken.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.context.MergeDirection;
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.log.JdbcEventLogger;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.validation.SimpleValidationFailure;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.List;
-
-/**
- * Common abstract superclass for all {@link MergerToken}s going from the model
- * to the database.
- */
-public abstract class AbstractToDbToken implements MergerToken, Comparable<MergerToken> {
-
-	private final String tokenName;
-
-	protected AbstractToDbToken(String tokenName) {
-		this.tokenName = tokenName;
-	}
-
-	@Override
-	public final String getTokenName() {
-		return tokenName;
-	}
-
-	@Override
-	public final MergeDirection getDirection() {
-		return MergeDirection.TO_DB;
-	}
-
-	@Override
-	public void execute(MergerContext mergerContext) {
-		for (String sql : createSql(mergerContext.getDataNode().getAdapter())) {
-			executeSql(mergerContext, sql);
-		}
-	}
-
-	protected void executeSql(MergerContext mergerContext, String sql) {
-		JdbcEventLogger logger = mergerContext.getDataNode().getJdbcEventLogger();
-		logger.log(sql);
-
-		try (Connection conn = mergerContext.getDataNode().getDataSource().getConnection();) {
-
-			try (Statement st = conn.createStatement();) {
-				st.execute(sql);
-			}
-		} catch (SQLException e) {
-			mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(sql, e.getMessage()));
-			logger.logQueryError(e);
-		}
-	}
-
-	@Override
-	public String toString() {
-		return getTokenName() + ' ' + getTokenValue() + ' ' + getDirection();
-	}
-
-	public boolean isEmpty() {
-		return false;
-	}
-
-	public abstract List<String> createSql(DbAdapter adapter);
-
-	abstract static class Entity extends AbstractToDbToken {
-
-		private DbEntity entity;
-
-		public Entity(String tokenName, DbEntity entity) {
-			super(tokenName);
-			this.entity = entity;
-		}
-
-		public DbEntity getEntity() {
-			return entity;
-		}
-
-		public String getTokenValue() {
-			return getEntity().getName();
-		}
-
-		public int compareTo(MergerToken o) {
-			// default order as tokens are created
-			return 0;
-		}
-
-	}
-
-	abstract static class EntityAndColumn extends Entity {
-
-		private DbAttribute column;
-
-		public EntityAndColumn(String tokenName, DbEntity entity, DbAttribute column) {
-			super(tokenName, entity);
-			this.column = column;
-		}
-
-		public DbAttribute getColumn() {
-			return column;
-		}
-
-		@Override
-		public String getTokenValue() {
-			return getEntity().getName() + "." + getColumn().getName();
-		}
-
-	}
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToModelToken.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToModelToken.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToModelToken.java
deleted file mode 100644
index f61067e..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AbstractToModelToken.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dbsync.merge.context.MergeDirection;
-import org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-
-/**
- * Common abstract superclass for all {@link MergerToken}s going from the database to the
- * model.
- */
-public abstract class AbstractToModelToken implements MergerToken {
-
-    private final String tokenName;
-
-    protected AbstractToModelToken(String tokenName) {
-        this.tokenName = tokenName;
-    }
-
-    protected static void remove(ModelMergeDelegate mergerContext, DbRelationship rel, boolean reverse) {
-        if (rel == null) {
-            return;
-        }
-        if (reverse) {
-            remove(mergerContext, rel.getReverseRelationship(), false);
-        }
-
-        DbEntity dbEntity = rel.getSourceEntity();
-        for (ObjEntity objEntity : dbEntity.mappedObjEntities()) {
-            remove(mergerContext, objEntity.getRelationshipForDbRelationship(rel), true);
-        }
-
-        rel.getSourceEntity().removeRelationship(rel.getName());
-        mergerContext.dbRelationshipRemoved(rel);
-    }
-
-    protected static void remove(ModelMergeDelegate mergerContext, ObjRelationship rel, boolean reverse) {
-        if (rel == null) {
-            return;
-        }
-        if (reverse) {
-            remove(mergerContext, rel.getReverseRelationship(), false);
-        }
-        rel.getSourceEntity().removeRelationship(rel.getName());
-        mergerContext.objRelationshipRemoved(rel);
-    }
-
-    @Override
-    public final String getTokenName() {
-        return tokenName;
-    }
-
-    @Override
-    public final MergeDirection getDirection() {
-        return MergeDirection.TO_MODEL;
-    }
-
-    @Override
-    public String toString() {
-        return getTokenName() + ' ' + getTokenValue() + ' ' + getDirection();
-    }
-
-    public boolean isEmpty() {
-        return false;
-    }
-
-    abstract static class Entity extends AbstractToModelToken {
-
-        private final DbEntity entity;
-
-        protected Entity(String tokenName, DbEntity entity) {
-            super(tokenName);
-            this.entity = entity;
-        }
-
-        public DbEntity getEntity() {
-            return entity;
-        }
-
-        public String getTokenValue() {
-            return getEntity().getName();
-        }
-
-    }
-
-    abstract static class EntityAndColumn extends Entity {
-
-        private final DbAttribute column;
-
-        protected EntityAndColumn(String tokenName, DbEntity entity, DbAttribute column) {
-            super(tokenName, entity);
-            this.column = column;
-        }
-
-        public DbAttribute getColumn() {
-            return column;
-        }
-
-        @Override
-        public String getTokenValue() {
-            return getEntity().getName() + "." + getColumn().getName();
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToDb.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToDb.java
deleted file mode 100644
index 19ac1ce..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToDb.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.JdbcAdapter;
-import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-
-import java.util.Collections;
-import java.util.List;
-
-public class AddColumnToDb extends AbstractToDbToken.EntityAndColumn {
-
-    public AddColumnToDb(DbEntity entity, DbAttribute column) {
-        super("Add Column", entity, column);
-    }
-
-    /**
-     * append the part of the token before the actual column data type
-     */
-    protected void appendPrefix(StringBuffer sqlBuffer, QuotingStrategy context) {
-
-        sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(context.quotedFullyQualifiedName(getEntity()));
-        sqlBuffer.append(" ADD COLUMN ");
-        sqlBuffer.append(context.quotedName(getColumn()));
-        sqlBuffer.append(" ");
-    }
-
-    @Override
-    public List<String> createSql(DbAdapter adapter) {
-        StringBuffer sqlBuffer = new StringBuffer();
-        QuotingStrategy context = adapter.getQuotingStrategy();
-        appendPrefix(sqlBuffer, context);
-
-        sqlBuffer.append(JdbcAdapter.getType(adapter, getColumn()));
-        sqlBuffer.append(JdbcAdapter.sizeAndPrecision(adapter, getColumn()));
-
-        return Collections.singletonList(sqlBuffer.toString());
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createDropColumnToModel(getEntity(), getColumn());
-    }
-
-    @Override
-    public int compareTo(MergerToken o) {
-        // add all AddRelationshipToDb to the end.
-        if (o instanceof AddRelationshipToDb) {
-            return -1;
-        }
-        return super.compareTo(o);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToModel.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToModel.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToModel.java
deleted file mode 100644
index e68d271..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddColumnToModel.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dbsync.merge.context.EntityMergeSupport;
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjEntity;
-
-/**
- * A {@link MergerToken} to add a {@link DbAttribute} to a {@link DbEntity}. The
- * {@link EntityMergeSupport} will be used to update the mapped {@link ObjEntity}
- */
-public class AddColumnToModel extends AbstractToModelToken.EntityAndColumn {
-
-    public AddColumnToModel(DbEntity entity, DbAttribute column) {
-        super("Add Column", entity, column);
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createDropColumnToDb(getEntity(), getColumn());
-    }
-
-    @Override
-    public void execute(MergerContext mergerContext) {
-        getEntity().addAttribute(getColumn());
-
-        for (ObjEntity e : getEntity().mappedObjEntities()) {
-            mergerContext.getEntityMergeSupport().synchronizeOnDbAttributeAdded(e, getColumn());
-        }
-
-        mergerContext.getDelegate().dbAttributeAdded(getColumn());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToDb.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToDb.java
deleted file mode 100644
index 2d19422..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToDb.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.access.DbGenerator;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbRelationship;
-
-import java.util.Collections;
-import java.util.List;
-
-public class AddRelationshipToDb extends AbstractToDbToken.Entity {
-
-    private DbRelationship relationship;
-
-    public AddRelationshipToDb(DbEntity entity, DbRelationship relationship) {
-        super("Add foreign key", entity);
-        this.relationship = relationship;
-    }
-
-    /**
-     * @see DbGenerator#createConstraintsQueries(org.apache.cayenne.map.DbEntity)
-     */
-    @Override
-    public List<String> createSql(DbAdapter adapter) {
-        // TODO: skip FK to a different DB
-        if (!this.isEmpty()) {
-            String fksql = adapter.createFkConstraint(relationship);
-            if (fksql != null) {
-                return Collections.singletonList(fksql);
-            }
-        }
-        return Collections.emptyList();
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createDropRelationshipToModel(getEntity(), relationship);
-    }
-
-    @Override
-    public String getTokenValue() {
-        if (!this.isEmpty()) {
-            return relationship.getSourceEntity().getName() + "->" + relationship.getTargetEntityName();
-        } else {
-            return "Skip. No sql representation.";
-        }
-    }
-
-    @Override
-    public boolean isEmpty() {
-        // Method DbRelationship.isSourceIndependentFromTargetChange() looks same
-        return relationship.isSourceIndependentFromTargetChange();
-        /*return relationship.isToMany()
-                || relationship.isToDependentPK()
-                || !relationship.isToPK(); // TODO it is not necessary primary key it can be unique index
-        */
-    }
-
-    @Override
-    public int compareTo(MergerToken o) {
-        // add all AddRelationshipToDb to the end.
-        if (o instanceof AddRelationshipToDb) {
-            return super.compareTo(o);
-        }
-        return 1;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToModel.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToModel.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToModel.java
deleted file mode 100644
index c132bbc..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/AddRelationshipToModel.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbJoin;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.ObjEntity;
-
-public class AddRelationshipToModel extends AbstractToModelToken.Entity {
-
-    public static final String COMMA_SEPARATOR = ", ";
-    public static final int COMMA_SEPARATOR_LENGTH = COMMA_SEPARATOR.length();
-
-    private DbRelationship relationship;
-
-    public AddRelationshipToModel(DbEntity entity, DbRelationship relationship) {
-        super("Add Relationship", entity);
-        this.relationship = relationship;
-    }
-
-    public static String getTokenValue(DbRelationship rel) {
-        String attributes = "";
-        if (rel.getJoins().size() == 1) {
-            attributes = rel.getJoins().get(0).getTargetName();
-        } else {
-            for (DbJoin dbJoin : rel.getJoins()) {
-                attributes += dbJoin.getTargetName() + COMMA_SEPARATOR;
-            }
-
-            attributes = "{" + attributes.substring(0, attributes.length() - COMMA_SEPARATOR_LENGTH) + "}";
-        }
-
-        return rel.getName() + " " + rel.getSourceEntity().getName() + "->" + rel.getTargetEntityName() + "." + attributes;
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createDropRelationshipToDb(getEntity(), relationship);
-    }
-
-    @Override
-    public void execute(MergerContext context) {
-        // Set name to relationship if it was created without it, e.g. in createReverse() action
-        if(relationship.getName() == null) {
-            relationship.setName(context.getNameGenerator().relationshipName(relationship));
-        }
-
-        getEntity().addRelationship(relationship);
-        for (ObjEntity e : getEntity().mappedObjEntities()) {
-            context.getEntityMergeSupport().synchronizeOnDbRelationshipAdded(e, relationship);
-        }
-
-        context.getDelegate().dbRelationshipAdded(relationship);
-    }
-
-    @Override
-    public String getTokenValue() {
-        String attributes = "";
-        if (relationship.getJoins().size() == 1) {
-            attributes = relationship.getJoins().get(0).getTargetName();
-        } else {
-            for (DbJoin dbJoin : relationship.getJoins()) {
-                attributes += dbJoin.getTargetName() + COMMA_SEPARATOR;
-            }
-
-            attributes = "{" + attributes.substring(0, attributes.length() - COMMA_SEPARATOR_LENGTH) + "}";
-        }
-
-        return relationship.getName() + " " + relationship.getSourceEntity().getName() + "->" + relationship.getTargetEntityName() + "." + attributes;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToDb.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToDb.java
deleted file mode 100644
index 6774b89..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToDb.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.validation.SimpleValidationFailure;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class CreateTableToDb extends AbstractToDbToken.Entity {
-
-    public CreateTableToDb(DbEntity entity) {
-        super("Create Table", entity);
-    }
-
-    @Override
-    public List<String> createSql(DbAdapter adapter) {
-        List<String> sqls = new ArrayList<String>();
-        if(needAutoPkSupport()) {
-            sqls.addAll(adapter.getPkGenerator().createAutoPkStatements(
-                    Collections.singletonList(getEntity())));
-        }
-        sqls.add(adapter.createTable(getEntity()));
-        return sqls;
-    }
-
-    @Override
-    public void execute(MergerContext mergerContext) {
-        try {
-            DataNode node = mergerContext.getDataNode();
-            DbAdapter adapter = node.getAdapter();
-            if(needAutoPkSupport()) {
-                adapter.getPkGenerator().createAutoPk(
-                        node,
-                        Collections.singletonList(getEntity()));
-            }
-            executeSql(mergerContext, adapter.createTable(getEntity()));
-        }
-        catch (Exception e) {
-            mergerContext.getValidationResult().addFailure(
-                    new SimpleValidationFailure(this, e.getMessage()));
-        }
-    }
-
-    private boolean needAutoPkSupport() {
-        DbEntity entity = getEntity();
-        if(entity.getPrimaryKeyGenerator() != null) {
-            return false;
-        }
-
-        for(DbAttribute attribute : entity.getPrimaryKeys()) {
-            if(attribute.isGenerated()) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createDropTableToModel(getEntity());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToModel.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToModel.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToModel.java
deleted file mode 100644
index 38f710f..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/CreateTableToModel.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.dbsync.naming.NameBuilder;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjEntity;
-
-/**
- * A {@link MergerToken} to add a {@link DbEntity} to a {@link DataMap}
- */
-public class CreateTableToModel extends AbstractToModelToken.Entity {
-
-    /**
-     * className if {@link ObjEntity} should be generated with a
-     * special class name.
-     * Setting this to <code>null</code>, because by default class name should be generated
-     */
-    private String objEntityClassName;
-
-    public CreateTableToModel(DbEntity entity) {
-        super("Create Table", entity);
-    }
-
-    /**
-     * Set the {@link ObjEntity} className if {@link ObjEntity} should be generated with a
-     * special class name. Set to null if the {@link ObjEntity} should be created with a
-     * name based on {@link DataMap#getDefaultPackage()} and {@link ObjEntity#getName()}
-     * <p>
-     * The default value is <code>null</code>
-     */
-    public void setObjEntityClassName(String n) {
-        objEntityClassName = n;
-    }
-
-    @Override
-    public void execute(MergerContext context) {
-        DbEntity dbEntity = getEntity();
-
-        DataMap map = context.getDataMap();
-        map.addDbEntity(dbEntity);
-
-        // create a ObjEntity
-        ObjEntity objEntity = new ObjEntity();
-
-        objEntity.setName(NameBuilder
-                .builder(objEntity, dbEntity.getDataMap())
-                .baseName(context.getNameGenerator().objEntityName(dbEntity))
-                .name());
-        objEntity.setDbEntity(getEntity());
-
-        // try to find a class name for the ObjEntity
-        String className = objEntityClassName;
-        if (className == null) {
-            // generate a className based on the objEntityName
-            className = map.getNameWithDefaultPackage(objEntity.getName());
-        }
-
-        objEntity.setClassName(className);
-        objEntity.setSuperClassName(map.getDefaultSuperclass());
-
-        if (map.isClientSupported()) {
-            objEntity.setClientClassName(map.getNameWithDefaultClientPackage(objEntity.getName()));
-            objEntity.setClientSuperClassName(map.getDefaultClientSuperclass());
-        }
-
-        map.addObjEntity(objEntity);
-
-        // presumably there are no other ObjEntities pointing to this DbEntity, so syncing just this one...
-        context.getEntityMergeSupport().synchronizeWithDbEntity(objEntity);
-
-        context.getDelegate().dbEntityAdded(getEntity());
-        context.getDelegate().objEntityAdded(objEntity);
-    }
-
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createDropTableToDb(getEntity());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToDb.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToDb.java
deleted file mode 100644
index ecdb970..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToDb.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-
-public class DropColumnToDb extends AbstractToDbToken.EntityAndColumn {
-
-    public DropColumnToDb(DbEntity entity, DbAttribute column) {
-        super("Drop Column", entity, column);
-    }
-
-    @Override
-    public List<String> createSql(DbAdapter adapter) {
-        StringBuilder sqlBuffer = new StringBuilder();
-        QuotingStrategy context = adapter.getQuotingStrategy();
-        sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(context.quotedFullyQualifiedName(getEntity()));
-        sqlBuffer.append(" DROP COLUMN ");
-        sqlBuffer.append(context.quotedName(getColumn()));
-
-        return Collections.singletonList(sqlBuffer.toString());
-    }
-
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createAddColumnToModel(getEntity(), getColumn());
-    }
-
-    @Override
-    public int compareTo(MergerToken o) {
-        // add all AddRelationshipToDb to the end.
-        if (o instanceof DropRelationshipToDb) {
-            return 1;
-        }
-        return super.compareTo(o);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToModel.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToModel.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToModel.java
deleted file mode 100644
index 6c9b09c..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropColumnToModel.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbJoin;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A {@link MergerToken} to remove a {@link DbAttribute} from a {@link DbEntity}.
- * 
- */
-public class DropColumnToModel extends AbstractToModelToken.EntityAndColumn {
-
-    public DropColumnToModel(DbEntity entity, DbAttribute column) {
-        super("Drop Column", entity, column);
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createAddColumnToDb(getEntity(), getColumn());
-    }
-
-    @Override
-    public void execute(MergerContext mergerContext) {
-
-        // remove relationships mapped to column. duplicate List to prevent
-        // ConcurrentModificationException
-        List<DbRelationship> dbRelationships = new ArrayList<DbRelationship>(getEntity()
-                .getRelationships());
-        for (DbRelationship dbRelationship : dbRelationships) {
-            for (DbJoin join : dbRelationship.getJoins()) {
-                if (join.getSource() == getColumn() || join.getTarget() == getColumn()) {
-                    remove(mergerContext.getDelegate(), dbRelationship, true);
-                }
-            }
-        }
-
-        // remove ObjAttribute mapped to same column
-        for (ObjEntity objEntity : getEntity().mappedObjEntities()) {
-            ObjAttribute objAttribute = objEntity.getAttributeForDbAttribute(getColumn());
-            if (objAttribute != null) {
-                objEntity.removeAttribute(objAttribute.getName());
-                mergerContext.getDelegate().objAttributeRemoved(objAttribute);
-            }
-
-        }
-
-        // remove DbAttribute
-        getEntity().removeAttribute(getColumn().getName());
-
-        mergerContext.getDelegate().dbAttributeRemoved(getColumn());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToDb.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToDb.java
deleted file mode 100644
index dce2b81..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToDb.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.dbsync.reverse.db.DbRelationshipDetected;
-
-import java.util.Collections;
-import java.util.List;
-
-public class DropRelationshipToDb extends AbstractToDbToken.Entity {
-
-    private DbRelationship relationship;
-
-    public DropRelationshipToDb(DbEntity entity, DbRelationship relationship) {
-        super("Drop foreign key", entity);
-        this.relationship = relationship;
-    }
-    
-    public String getFkName() {
-        if (relationship instanceof DbRelationshipDetected) {
-            return ((DbRelationshipDetected) relationship).getFkName();
-        }
-        return null;
-    }
-
-    @Override
-    public List<String> createSql(DbAdapter adapter) {
-        if (isEmpty()) {
-            return Collections.emptyList();
-        }
-
-        QuotingStrategy context = adapter.getQuotingStrategy();
-        return Collections.singletonList(
-                "ALTER TABLE " + context.quotedFullyQualifiedName(getEntity()) + " DROP CONSTRAINT " + getFkName());
-    }
-
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createAddRelationshipToModel(getEntity(), relationship);
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return getFkName() == null || relationship.isToMany();
-    }
-
-    @Override
-    public String getTokenValue() {
-        if(relationship.isToMany()) {
-            return "Skip. No sql representation.";
-        }
-        return relationship.getSourceEntity().getName() + "->" + relationship.getTargetEntityName();
-    }
-
-    @Override
-    public int compareTo(MergerToken o) {
-        // add all AddRelationshipToDb to the end.
-        if (o instanceof DropRelationshipToDb) {
-            return super.compareTo(o);
-        }
-        return -1;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToModel.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToModel.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToModel.java
deleted file mode 100644
index d30355d..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropRelationshipToModel.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbRelationship;
-
-public class DropRelationshipToModel extends AbstractToModelToken.Entity {
-
-    private final DbRelationship relationship;
-
-    public DropRelationshipToModel(DbEntity entity, DbRelationship relationship) {
-        super("Drop db-relationship ", entity);
-        this.relationship = relationship;
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createAddRelationshipToDb(getEntity(), relationship);
-    }
-
-    @Override
-    public void execute(MergerContext mergerContext) {
-        remove(mergerContext.getDelegate(), relationship, true);
-    }
-
-    @Override
-    public String getTokenValue() {
-        return AddRelationshipToModel.getTokenValue(relationship);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToDb.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToDb.java
deleted file mode 100644
index d5dd161..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToDb.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbEntity;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class DropTableToDb extends AbstractToDbToken.Entity {
-
-    public DropTableToDb(DbEntity entity) {
-        super("Drop Table", entity);
-    }
-
-    @Override
-    public List<String> createSql(DbAdapter adapter) {
-        List<String> sqls = new ArrayList<>();
-        // TODO: fix. some adapters drop the complete AUTO_PK_SUPPORT here
-        /*
-        sqls.addAll(adapter.getPkGenerator().dropAutoPkStatements(
-                Collections.singletonList(entity)));
-         */
-        sqls.addAll(adapter.dropTableStatements(getEntity()));
-        return sqls;
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createCreateTableToModel(getEntity());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToModel.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToModel.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToModel.java
deleted file mode 100644
index 1773ec6..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DropTableToModel.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dbsync.merge.context.MergerContext;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjEntity;
-
-/**
- * A {@link MergerToken} to remove a {@link DbEntity} from a {@link DataMap}. Any
- * {@link ObjEntity} mapped to the {@link DbEntity} will also be removed.
- * 
- */
-public class DropTableToModel extends AbstractToModelToken.Entity {
-
-    public DropTableToModel(DbEntity entity) {
-        super("Drop Table", entity);
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createCreateTableToDb(getEntity());
-    }
-
-    @Override
-    public void execute(MergerContext mergerContext) {
-        for (ObjEntity objEntity : getEntity().mappedObjEntities()) {
-            objEntity.getDataMap().removeObjEntity(objEntity.getName(), true);
-            mergerContext.getDelegate().objEntityRemoved(objEntity);
-        }
-        getEntity().getDataMap().removeDbEntity(getEntity().getName(), true);
-        mergerContext.getDelegate().dbEntityRemoved(getEntity());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DummyReverseToken.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DummyReverseToken.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DummyReverseToken.java
index 6bdb4d9..e8dc4cb 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DummyReverseToken.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/DummyReverseToken.java
@@ -28,7 +28,7 @@ import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
  * any thing, but {@link #createReverse(MergerTokenFactory)} will get back the reverse that
  * this was made from.
  */
-class DummyReverseToken implements MergerToken {
+public class DummyReverseToken implements MergerToken {
 
     private MergerToken reverse;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/725e6ae9/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/SetAllowNullToDb.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/SetAllowNullToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/SetAllowNullToDb.java
deleted file mode 100644
index f155680..0000000
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/SetAllowNullToDb.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.dbsync.merge.token;
-
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * A {@link MergerToken} to add a "allow null" clause to a column.
- * 
- */
-public class SetAllowNullToDb extends AbstractToDbToken.EntityAndColumn {
-
-    public SetAllowNullToDb(DbEntity entity, DbAttribute column) {
-        super("Set Allow Null", entity, column);
-    }
-
-    @Override
-    public List<String> createSql(DbAdapter adapter) {
-        StringBuilder sqlBuffer = new StringBuilder();
-        QuotingStrategy context = adapter.getQuotingStrategy();
-        sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(context.quotedFullyQualifiedName(getEntity()));
-        sqlBuffer.append(" ALTER COLUMN ");
-        sqlBuffer.append(context.quotedName(getColumn()));
-        sqlBuffer.append(" DROP NOT NULL");
-
-        return Collections.singletonList(sqlBuffer.toString());
-    }
-
-    @Override
-    public MergerToken createReverse(MergerTokenFactory factory) {
-        return factory.createSetNotNullToModel(getEntity(), getColumn());
-    }
-
-}


Mime
View raw message