cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r614546 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/
Date Wed, 23 Jan 2008 14:31:04 GMT
Author: torehalset
Date: Wed Jan 23 06:31:01 2008
New Revision: 614546

URL: http://svn.apache.org/viewvc?rev=614546&view=rev
Log:
CAY-978: Add getEntity/getColumn to AddColumnToDb
added for all relevant tokens

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToDbToken.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToModel.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToDbToken.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToDbToken.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToDbToken.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToDbToken.java
Wed Jan 23 06:31:01 2008
@@ -21,6 +21,8 @@
 import java.util.List;
 
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 
 /**
  * Common abstract superclass for all {@link MergerToken}s going from the model to the
@@ -29,7 +31,7 @@
  * @author halset
  */
 public abstract class AbstractToDbToken implements MergerToken {
-
+    
     public final MergeDirection getDirection() {
         return MergeDirection.TO_DB;
     }
@@ -52,5 +54,42 @@
     }
 
     public abstract List<String> createSql(DbAdapter adapter);
+    
+    abstract static class Entity extends AbstractToDbToken {
+        
+        private DbEntity entity;
+
+        public Entity(DbEntity entity) {
+            this.entity = entity;
+        }
+
+        public DbEntity getEntity() {
+            return entity;
+        }
+
+        public String getTokenValue() {
+            return getEntity().getName();
+        }
 
+    }
+
+    abstract static class EntityAndColumn extends Entity {
+        
+        private DbAttribute column;
+        
+        public EntityAndColumn(DbEntity entity, DbAttribute column) {
+            super(entity);
+            this.column = column;
+        }
+
+        public DbAttribute getColumn() {
+            return column;
+        }
+        
+        @Override
+        public String getTokenValue() {
+            return getEntity().getName() + "." + getColumn().getName();
+        }
+        
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java
Wed Jan 23 06:31:01 2008
@@ -22,6 +22,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.MappingNamespace;
@@ -36,7 +37,7 @@
  * @author halset
  */
 public abstract class AbstractToModelToken implements MergerToken {
-
+    
     public final MergeDirection getDirection() {
         return MergeDirection.TO_MODEL;
     }
@@ -95,5 +96,44 @@
         ts.append(getDirection());
         return ts.toString();
     }
+    
+    abstract static class Entity extends AbstractToModelToken {
+        
+        private DbEntity entity;
+
+        public Entity(DbEntity entity) {
+            this.entity = entity;
+        }
+
+        public DbEntity getEntity() {
+            return entity;
+        }
+        
+        public String getTokenValue() {
+            return getEntity().getName();
+        }
+        
+    }
+    
+    abstract static class EntityAndColumn extends Entity {
+        
+        private DbAttribute column;
+        
+        public EntityAndColumn(DbEntity entity, DbAttribute column) {
+            super(entity);
+            this.column = column;
+        }
+
+        public DbAttribute getColumn() {
+            return column;
+        }
+
+        @Override
+        public String getTokenValue() {
+            return getEntity().getName() + "." + getColumn().getName();
+        }
+        
+    }
+
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToDb.java
Wed Jan 23 06:31:01 2008
@@ -27,24 +27,20 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
-public class AddColumnToDb extends AbstractToDbToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class AddColumnToDb extends AbstractToDbToken.EntityAndColumn {
 
     public AddColumnToDb(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
-
+    
     /**
      * append the part of the token before the actual column data type
      */
     protected void appendPrefix(StringBuffer sqlBuffer) {
         sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(entity.getFullyQualifiedName());
+        sqlBuffer.append(getEntity().getFullyQualifiedName());
         sqlBuffer.append(" ADD COLUMN ");
-        sqlBuffer.append(column.getName());
+        sqlBuffer.append(getColumn().getName());
         sqlBuffer.append(" ");
     }
 
@@ -55,25 +51,25 @@
         appendPrefix(sqlBuffer);
 
         // copied from JdbcAdapter.createTableAppendColumn
-        String[] types = adapter.externalTypesForJdbcType(column.getType());
+        String[] types = adapter.externalTypesForJdbcType(getColumn().getType());
         if (types == null || types.length == 0) {
-            String entityName = column.getEntity() != null ? ((DbEntity) column
+            String entityName = getColumn().getEntity() != null ? ((DbEntity) getColumn()
                     .getEntity()).getFullyQualifiedName() : "<null>";
             throw new CayenneRuntimeException("Undefined type for attribute '"
                     + entityName
                     + "."
-                    + column.getName()
+                    + getColumn().getName()
                     + "': "
-                    + column.getType());
+                    + getColumn().getType());
         }
 
         String type = types[0];
         sqlBuffer.append(type);
 
         // append size and precision (if applicable)
-        if (TypesMapping.supportsLength(column.getType())) {
-            int len = column.getMaxLength();
-            int scale = TypesMapping.isDecimal(column.getType()) ? column.getScale() : -1;
+        if (TypesMapping.supportsLength(getColumn().getType())) {
+            int len = getColumn().getMaxLength();
+            int scale = TypesMapping.isDecimal(getColumn().getType()) ? getColumn().getScale()
: -1;
 
             // sanity check
             if (scale > len) {
@@ -101,12 +97,8 @@
         return "Add Column";
     }
 
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
-    }
-
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createDropColumToModel(entity, column);
+        return factory.createDropColumToModel(getEntity(), getColumn());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddColumnToModel.java
Wed Jan 23 06:31:01 2008
@@ -29,31 +29,23 @@
  * 
  * @author halset
  */
-public class AddColumnToModel extends AbstractToModelToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class AddColumnToModel extends AbstractToModelToken.EntityAndColumn {
 
     public AddColumnToModel(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createDropColumToDb(entity, column);
+        return factory.createDropColumToDb(getEntity(), getColumn());
     }
 
     public void execute(MergerContext mergerContext) {
-        entity.addAttribute(column);
-        synchronizeWithObjEntity(entity);
+        getEntity().addAttribute(getColumn());
+        synchronizeWithObjEntity(getEntity());
     }
 
     public String getTokenName() {
         return "Add Column";
-    }
-
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToDb.java
Wed Jan 23 06:31:01 2008
@@ -26,13 +26,12 @@
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 
-public class AddRelationshipToDb extends AbstractToDbToken {
+public class AddRelationshipToDb extends AbstractToDbToken.Entity {
 
-    private DbEntity entity;
     private DbRelationship rel;
 
     public AddRelationshipToDb(DbEntity entity, DbRelationship rel) {
-        this.entity = entity;
+        super(entity);
         this.rel = rel;
     }
 
@@ -53,13 +52,14 @@
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createDropRelationshipToModel(entity, rel);
+        return factory.createDropRelationshipToModel(getEntity(), rel);
     }
 
     public String getTokenName() {
         return "Add Relationship";
     }
 
+    @Override
     public String getTokenValue() {
         StringBuilder s = new StringBuilder();
         s.append(rel.getSourceEntity().getName());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AddRelationshipToModel.java
Wed Jan 23 06:31:01 2008
@@ -21,30 +21,30 @@
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 
-public class AddRelationshipToModel extends AbstractToModelToken {
+public class AddRelationshipToModel extends AbstractToModelToken.Entity {
 
-    private DbEntity entity;
     private DbRelationship rel;
 
     public AddRelationshipToModel(DbEntity entity, DbRelationship rel) {
-        this.entity = entity;
+        super(entity);
         this.rel = rel;
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createDropRelationshipToDb(entity, rel);
+        return factory.createDropRelationshipToDb(getEntity(), rel);
     }
 
     public void execute(MergerContext mergerContext) {
-        entity.addRelationship(rel);
+        getEntity().addRelationship(rel);
         // TODO: add reverse relationship as well if it does not exist
-        synchronizeWithObjEntity(entity);
+        synchronizeWithObjEntity(getEntity());
     }
 
     public String getTokenName() {
         return "Add Relationship";
     }
 
+    @Override
     public String getTokenValue() {
         StringBuilder s = new StringBuilder();
         s.append(rel.getSourceEntity().getName());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToDb.java
Wed Jan 23 06:31:01 2008
@@ -25,20 +25,18 @@
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.DbEntity;
 
-public class CreateTableToDb extends AbstractToDbToken {
-
-    private DbEntity entity;
+public class CreateTableToDb extends AbstractToDbToken.Entity {
 
     public CreateTableToDb(DbEntity entity) {
-        this.entity = entity;
+        super(entity);
     }
 
     @Override
     public List<String> createSql(DbAdapter adapter) {
         List<String> sqls = new ArrayList<String>();
         sqls.addAll(adapter.getPkGenerator().createAutoPkStatements(
-                Collections.singletonList(entity)));
-        sqls.add(adapter.createTable(entity));
+                Collections.singletonList(getEntity())));
+        sqls.add(adapter.createTable(getEntity()));
         return sqls;
     }
 
@@ -46,12 +44,8 @@
         return "Create Table";
     }
 
-    public String getTokenValue() {
-        return entity.getName();
-    }
-
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createDropTableToModel(entity);
+        return factory.createDropTableToModel(getEntity());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/CreateTableToModel.java
Wed Jan 23 06:31:01 2008
@@ -30,14 +30,12 @@
  * 
  * @author halset
  */
-public class CreateTableToModel extends AbstractToModelToken {
-
-    private DbEntity entity;
+public class CreateTableToModel extends AbstractToModelToken.Entity {
 
     private String objEntityClassName = CayenneDataObject.class.getName();
 
     public CreateTableToModel(DbEntity entity) {
-        this.entity = entity;
+        super(entity);
     }
 
     /**
@@ -53,10 +51,10 @@
 
     public void execute(MergerContext mergerContext) {
         DataMap map = mergerContext.getDataMap();
-        map.addDbEntity(entity);
+        map.addDbEntity(getEntity());
 
         // create a ObjEntity
-        String objEntityName = NameConverter.underscoredToJava(entity.getName(), true);
+        String objEntityName = NameConverter.underscoredToJava(getEntity().getName(), true);
         // this loop will terminate even if no valid name is found
         // to prevent loader from looping forever (though such case is very unlikely)
         String baseName = objEntityName;
@@ -65,7 +63,7 @@
         }
 
         ObjEntity objEntity = new ObjEntity(objEntityName);
-        objEntity.setDbEntity(entity);
+        objEntity.setDbEntity(getEntity());
 
         // try to find a class name for the ObjEntity
         String className = objEntityClassName;
@@ -84,19 +82,15 @@
         objEntity.setClassName(className);
         map.addObjEntity(objEntity);
 
-        synchronizeWithObjEntity(entity);
+        synchronizeWithObjEntity(getEntity());
     }
 
     public String getTokenName() {
         return "Create Table";
     }
 
-    public String getTokenValue() {
-        return entity.getName();
-    }
-
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createDropTableToDb(entity);
+        return factory.createDropTableToDb(getEntity());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToDb.java
Wed Jan 23 06:31:01 2008
@@ -25,14 +25,10 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
-public class DropColumnToDb extends AbstractToDbToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class DropColumnToDb extends AbstractToDbToken.EntityAndColumn {
 
     public DropColumnToDb(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
 
     @Override
@@ -40,9 +36,9 @@
         StringBuffer sqlBuffer = new StringBuffer();
 
         sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(entity.getFullyQualifiedName());
+        sqlBuffer.append(getEntity().getFullyQualifiedName());
         sqlBuffer.append(" DROP COLUMN ");
-        sqlBuffer.append(column.getName());
+        sqlBuffer.append(getColumn().getName());
 
         return Collections.singletonList(sqlBuffer.toString());
     }
@@ -51,12 +47,8 @@
         return "Drop Column";
     }
 
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
-    }
-
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createAddColumnToModel(entity, column);
+        return factory.createAddColumnToModel(getEntity(), getColumn());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropColumnToModel.java
Wed Jan 23 06:31:01 2008
@@ -33,37 +33,33 @@
  * 
  * @author halset
  */
-public class DropColumnToModel extends AbstractToModelToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class DropColumnToModel extends AbstractToModelToken.EntityAndColumn {
 
     public DropColumnToModel(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createAddColumnToDb(entity, column);
+        return factory.createAddColumnToDb(getEntity(), getColumn());
     }
 
     public void execute(MergerContext mergerContext) {
 
         // remove relationships mapped to column. duplicate List to prevent
         // ConcurrentModificationException
-        List<DbRelationship> dbRelationships = new ArrayList<DbRelationship>(entity
+        List<DbRelationship> dbRelationships = new ArrayList<DbRelationship>(getEntity()
                 .getRelationships());
         for (DbRelationship dbRelationship : dbRelationships) {
             for (DbJoin join : dbRelationship.getJoins()) {
-                if (join.getSource() == column || join.getTarget() == column) {
+                if (join.getSource() == getColumn() || join.getTarget() == getColumn()) {
                     remove(dbRelationship, true);
                 }
             }
         }
 
         // remove ObjAttribute mapped to same column
-        for (ObjEntity objEntity : objEntitiesMappedToDbEntity(entity)) {
-            ObjAttribute objAttribute = objEntity.getAttributeForDbAttribute(column);
+        for (ObjEntity objEntity : objEntitiesMappedToDbEntity(getEntity())) {
+            ObjAttribute objAttribute = objEntity.getAttributeForDbAttribute(getColumn());
             if (objAttribute != null) {
                 objEntity.removeAttribute(objAttribute.getName());
             }
@@ -71,15 +67,11 @@
         }
 
         // remove DbAttribute
-        entity.removeAttribute(column.getName());
+        getEntity().removeAttribute(getColumn().getName());
     }
 
     public String getTokenName() {
         return "Drop Column";
-    }
-
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToDb.java
Wed Jan 23 06:31:01 2008
@@ -26,13 +26,12 @@
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.DbRelationshipDetected;
 
-public class DropRelationshipToDb extends AbstractToDbToken {
+public class DropRelationshipToDb extends AbstractToDbToken.Entity {
 
-    private DbEntity entity;
     private DbRelationship rel;
 
     public DropRelationshipToDb(DbEntity entity, DbRelationship rel) {
-        this.entity = entity;
+        super(entity);
         this.rel = rel;
     }
     
@@ -53,7 +52,7 @@
 
         StringBuilder buf = new StringBuilder();
         buf.append("ALTER TABLE ");
-        buf.append(entity.getFullyQualifiedName());
+        buf.append(getEntity().getFullyQualifiedName());
         buf.append(" DROP CONSTRAINT ");
         buf.append(fkName);
 
@@ -61,13 +60,14 @@
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createAddRelationshipToModel(entity, rel);
+        return factory.createAddRelationshipToModel(getEntity(), rel);
     }
 
     public String getTokenName() {
         return "Drop Relationship";
     }
 
+    @Override
     public String getTokenValue() {
         StringBuilder s = new StringBuilder();
         s.append(rel.getSourceEntity().getName());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropRelationshipToModel.java
Wed Jan 23 06:31:01 2008
@@ -21,18 +21,17 @@
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 
-public class DropRelationshipToModel extends AbstractToModelToken {
+public class DropRelationshipToModel extends AbstractToModelToken.Entity {
 
-    private DbEntity entity;
     private DbRelationship rel;
 
     public DropRelationshipToModel(DbEntity entity, DbRelationship rel) {
-        this.entity = entity;
+        super(entity);
         this.rel = rel;
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createAddRelationshipToDb(entity, rel);
+        return factory.createAddRelationshipToDb(getEntity(), rel);
     }
 
     public void execute(MergerContext mergerContext) {
@@ -43,6 +42,7 @@
         return "Drop Relationship";
     }
 
+    @Override
     public String getTokenValue() {
         StringBuilder s = new StringBuilder();
         s.append(rel.getSourceEntity().getName());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToDb.java
Wed Jan 23 06:31:01 2008
@@ -24,12 +24,10 @@
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.DbEntity;
 
-public class DropTableToDb extends AbstractToDbToken {
-
-    private DbEntity entity;
+public class DropTableToDb extends AbstractToDbToken.Entity {
 
     public DropTableToDb(DbEntity entity) {
-        this.entity = entity;
+        super(entity);
     }
 
     @Override
@@ -40,7 +38,7 @@
         sqls.addAll(adapter.getPkGenerator().dropAutoPkStatements(
                 Collections.singletonList(entity)));
          */
-        sqls.addAll(adapter.dropTableStatements(entity));
+        sqls.addAll(adapter.dropTableStatements(getEntity()));
         return sqls;
     }
 
@@ -48,12 +46,8 @@
         return "Drop Table";
     }
 
-    public String getTokenValue() {
-        return entity.getName();
-    }
-
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createCreateTableToModel(entity);
+        return factory.createCreateTableToModel(getEntity());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/DropTableToModel.java
Wed Jan 23 06:31:01 2008
@@ -28,31 +28,25 @@
  * 
  * @author halset
  */
-public class DropTableToModel extends AbstractToModelToken {
-
-    private DbEntity entity;
+public class DropTableToModel extends AbstractToModelToken.Entity {
 
     public DropTableToModel(DbEntity entity) {
-        this.entity = entity;
+        super(entity);
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createCreateTableToDb(entity);
+        return factory.createCreateTableToDb(getEntity());
     }
 
     public void execute(MergerContext mergerContext) {
-        for (ObjEntity objEntity : objEntitiesMappedToDbEntity(entity)) {
+        for (ObjEntity objEntity : objEntitiesMappedToDbEntity(getEntity())) {
             objEntity.getDataMap().removeObjEntity(objEntity.getName(), true);
         }
-        entity.getDataMap().removeDbEntity(entity.getName(), true);
+        getEntity().getDataMap().removeDbEntity(getEntity().getName(), true);
     }
 
     public String getTokenName() {
         return "Drop Table";
-    }
-
-    public String getTokenValue() {
-        return entity.getName();
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
Wed Jan 23 06:31:01 2008
@@ -30,14 +30,10 @@
  * 
  * @author halset
  */
-public class SetAllowNullToDb extends AbstractToDbToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class SetAllowNullToDb extends AbstractToDbToken.EntityAndColumn {
 
     public SetAllowNullToDb(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
 
     @Override
@@ -45,9 +41,9 @@
         StringBuffer sqlBuffer = new StringBuffer();
 
         sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(entity.getFullyQualifiedName());
+        sqlBuffer.append(getEntity().getFullyQualifiedName());
         sqlBuffer.append(" ALTER COLUMN ");
-        sqlBuffer.append(column.getName());
+        sqlBuffer.append(getColumn().getName());
         sqlBuffer.append(" DROP NOT NULL");
 
         return Collections.singletonList(sqlBuffer.toString());
@@ -57,12 +53,8 @@
         return "Set Allow Null";
     }
 
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
-    }
-
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createSetNotNullToModel(entity, column);
+        return factory.createSetNotNullToModel(getEntity(), getColumn());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToModel.java
Wed Jan 23 06:31:01 2008
@@ -26,30 +26,22 @@
  * 
  * @author halset
  */
-public class SetAllowNullToModel extends AbstractToModelToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class SetAllowNullToModel extends AbstractToModelToken.EntityAndColumn {
 
     public SetAllowNullToModel(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createSetNotNullToDb(entity, column);
+        return factory.createSetNotNullToDb(getEntity(), getColumn());
     }
 
     public void execute(MergerContext mergerContext) {
-        column.setMandatory(false);
+        getColumn().setMandatory(false);
     }
 
     public String getTokenName() {
         return "Set Allow Null";
-    }
-
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
Wed Jan 23 06:31:01 2008
@@ -30,14 +30,13 @@
 /**
  * An {@link MergerToken} to use to set type, length and precision.
  */
-public class SetColumnTypeToDb extends AbstractToDbToken {
+public class SetColumnTypeToDb extends AbstractToDbToken.Entity {
 
-    private DbEntity entity;
     private DbAttribute columnOriginal;
     private DbAttribute columnNew;
 
     public SetColumnTypeToDb(DbEntity entity, DbAttribute columnOriginal, DbAttribute columnNew)
{
-        this.entity = entity;
+        super(entity);
         this.columnOriginal = columnOriginal;
         this.columnNew = columnNew;
     }
@@ -47,7 +46,7 @@
      */
     protected void appendPrefix(StringBuffer sqlBuffer) {
         sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(entity.getFullyQualifiedName());
+        sqlBuffer.append(getEntity().getFullyQualifiedName());
         sqlBuffer.append(" ALTER ");
         sqlBuffer.append(columnNew.getName());
         sqlBuffer.append(" TYPE ");
@@ -103,9 +102,10 @@
         return "Set Column Type";
     }
     
+    @Override
     public String getTokenValue() {
         StringBuffer sb = new StringBuffer();
-        sb.append(entity.getName());
+        sb.append(getEntity().getName());
         sb.append(".");
         sb.append(columnNew.getName());
 
@@ -141,7 +141,7 @@
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createSetColumnTypeToModel(entity, columnNew, columnOriginal);
+        return factory.createSetColumnTypeToModel(getEntity(), columnNew, columnOriginal);
     }
 
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java
Wed Jan 23 06:31:01 2008
@@ -29,21 +29,20 @@
  * 
  * @author halset
  */
-public class SetColumnTypeToModel extends AbstractToModelToken {
+public class SetColumnTypeToModel extends AbstractToModelToken.Entity {
 
-    private DbEntity entity;
     private DbAttribute columnOriginal;
     private DbAttribute columnNew;
 
     public SetColumnTypeToModel(DbEntity entity, DbAttribute columnOriginal,
             DbAttribute columnNew) {
-        this.entity = entity;
+        super(entity);
         this.columnOriginal = columnOriginal;
         this.columnNew = columnNew;
     }
 
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createSetColumnTypeToDb(entity, columnNew, columnOriginal);
+        return factory.createSetColumnTypeToDb(getEntity(), columnNew, columnOriginal);
     }
 
     public void execute(MergerContext mergerContext) {
@@ -57,9 +56,10 @@
         return "Set Column Type";
     }
 
+    @Override
     public String getTokenValue() {
         StringBuffer sb = new StringBuffer();
-        sb.append(entity.getName());
+        sb.append(getEntity().getName());
         sb.append(".");
         sb.append(columnNew.getName());
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToDb.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToDb.java
Wed Jan 23 06:31:01 2008
@@ -30,14 +30,10 @@
  * 
  * @author halset
  */
-public class SetNotNullToDb extends AbstractToDbToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class SetNotNullToDb extends AbstractToDbToken.EntityAndColumn {
 
     public SetNotNullToDb(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
 
     @Override
@@ -45,9 +41,9 @@
         StringBuffer sqlBuffer = new StringBuffer();
 
         sqlBuffer.append("ALTER TABLE ");
-        sqlBuffer.append(entity.getFullyQualifiedName());
+        sqlBuffer.append(getEntity().getFullyQualifiedName());
         sqlBuffer.append(" ALTER COLUMN ");
-        sqlBuffer.append(column.getName());
+        sqlBuffer.append(getColumn().getName());
         sqlBuffer.append(" SET NOT NULL");
 
         return Collections.singletonList(sqlBuffer.toString());
@@ -57,12 +53,8 @@
         return "Set Not Null";
     }
 
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
-    }
-
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createSetAllowNullToModel(entity, column);
+        return factory.createSetAllowNullToModel(getEntity(), getColumn());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToModel.java?rev=614546&r1=614545&r2=614546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/SetNotNullToModel.java
Wed Jan 23 06:31:01 2008
@@ -26,30 +26,22 @@
  * 
  * @author halset
  */
-public class SetNotNullToModel extends AbstractToModelToken {
-
-    private DbEntity entity;
-    private DbAttribute column;
+public class SetNotNullToModel extends AbstractToModelToken.EntityAndColumn {
 
     public SetNotNullToModel(DbEntity entity, DbAttribute column) {
-        this.entity = entity;
-        this.column = column;
+        super(entity, column);
     }
     
     public MergerToken createReverse(MergerFactory factory) {
-        return factory.createSetAllowNullToDb(entity, column);
+        return factory.createSetAllowNullToDb(getEntity(), getColumn());
     }
 
     public void execute(MergerContext mergerContext) {
-        column.setMandatory(true);
+        getColumn().setMandatory(true);
     }
 
     public String getTokenName() {
         return "Set Not Null";
-    }
-
-    public String getTokenValue() {
-        return entity.getName() + "." + column.getName();
     }
 
 }



Mime
View raw message