cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r587025 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge: MergerFactory.java SetAllowNullToDb.java SetColumnTypeToDb.java SetColumnTypeToModel.java
Date Mon, 22 Oct 2007 07:57:31 GMT
Author: torehalset
Date: Mon Oct 22 00:57:31 2007
New Revision: 587025

URL: http://svn.apache.org/viewvc?rev=587025&view=rev
Log:
CAY-885: merge changes between model and db
 * improved tokenValue for column type
 * javadoc

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/MergerFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/MergerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/MergerFactory.java?rev=587025&r1=587024&r2=587025&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/MergerFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/MergerFactory.java
Mon Oct 22 00:57:31 2007
@@ -23,7 +23,9 @@
 import org.apache.cayenne.map.DbEntity;
 
 /**
- * A way to create {@link MergerToken}s that work for a specific {@link DbAdapter}
+ * All {@link MergerToken}s should be created from a {@link MergerFactory} obtained from
+ * {@link DbAdapter#mergerFactory()} so that the {@link DbAdapter} are able to provide
+ * {@link MergerToken} subclasses.
  * 
  * @see DbAdapter#mergerFactory()
  */
@@ -61,9 +63,7 @@
         return new DropColumnToDb(entity, column);
     }
 
-    public MergerToken createSetNotNullToModel(
-
-    DbEntity entity, DbAttribute column) {
+    public MergerToken createSetNotNullToModel(DbEntity entity, DbAttribute column) {
         return new SetNotNullToModel(entity, column);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java?rev=587025&r1=587024&r2=587025&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetAllowNullToDb.java
Mon Oct 22 00:57:31 2007
@@ -22,6 +22,11 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
+/**
+ * A {@link MergerToken} to add a "allow null" clause to a column.
+ * 
+ * @author halset
+ */
 public class SetAllowNullToDb extends AbstractToDbToken {
 
     private DbEntity entity;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java?rev=587025&r1=587024&r2=587025&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToDb.java
Mon Oct 22 00:57:31 2007
@@ -100,8 +100,40 @@
     }
     
     public String getTokenValue() {
-        // TODO: ..varchar(100)
-        return entity.getName() + "." + columnNew.getName();
+        StringBuffer sb = new StringBuffer();
+        sb.append(entity.getName());
+        sb.append(".");
+        sb.append(columnNew.getName());
+
+        if (columnOriginal.getType() != columnNew.getType()) {
+            sb.append(" type: ");
+            sb.append(TypesMapping.getSqlNameByType(columnOriginal.getType()));
+            sb.append(" -> ");
+            sb.append(TypesMapping.getSqlNameByType(columnNew.getType()));
+        }
+
+        if (columnOriginal.getMaxLength() != columnNew.getMaxLength()) {
+            sb.append(" maxLength: ");
+            sb.append(columnOriginal.getMaxLength());
+            sb.append(" -> ");
+            sb.append(columnNew.getMaxLength());
+        }
+
+        if (columnOriginal.getAttributePrecision() != columnNew.getAttributePrecision())
{
+            sb.append(" precision: ");
+            sb.append(columnOriginal.getAttributePrecision());
+            sb.append(" -> ");
+            sb.append(columnNew.getAttributePrecision());
+        }
+
+        if (columnOriginal.getScale() != columnNew.getScale()) {
+            sb.append(" scale: ");
+            sb.append(columnOriginal.getScale());
+            sb.append(" -> ");
+            sb.append(columnNew.getScale());
+        }
+
+        return sb.toString();
     }
 
     public MergerToken createReverse(MergerFactory factory) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java?rev=587025&r1=587024&r2=587025&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/merge/SetColumnTypeToModel.java
Mon Oct 22 00:57:31 2007
@@ -18,9 +18,17 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
+/**
+ * A {@link MergerToken} that modifies one original {@link DbAttribute} to match another
+ * new {@link DbAttribute}s type, maxLength and precision. The name and mandatory fields
+ * are not modified by this token.
+ * 
+ * @author halset
+ */
 public class SetColumnTypeToModel extends AbstractToModelToken {
 
     private DbEntity entity;
@@ -39,17 +47,51 @@
     }
 
     public void execute(MergerContext mergerContext) {
-        // TODO: implement
-        throw new UnsupportedOperationException();
+        columnOriginal.setType(columnNew.getType());
+        columnOriginal.setMaxLength(columnNew.getMaxLength());
+        columnOriginal.setAttributePrecision(columnNew.getAttributePrecision());
+        columnOriginal.setScale(columnNew.getScale());
     }
 
     public String getTokenName() {
         return "Set Column Type";
     }
-    
+
     public String getTokenValue() {
-        // TODO: ..varchar(100)
-        return entity.getName() + "." + columnNew.getName();
+        StringBuffer sb = new StringBuffer();
+        sb.append(entity.getName());
+        sb.append(".");
+        sb.append(columnNew.getName());
+
+        if (columnOriginal.getType() != columnNew.getType()) {
+            sb.append(" type: ");
+            sb.append(TypesMapping.getSqlNameByType(columnOriginal.getType()));
+            sb.append(" -> ");
+            sb.append(TypesMapping.getSqlNameByType(columnNew.getType()));
+        }
+
+        if (columnOriginal.getMaxLength() != columnNew.getMaxLength()) {
+            sb.append(" maxLength: ");
+            sb.append(columnOriginal.getMaxLength());
+            sb.append(" -> ");
+            sb.append(columnNew.getMaxLength());
+        }
+
+        if (columnOriginal.getAttributePrecision() != columnNew.getAttributePrecision())
{
+            sb.append(" precision: ");
+            sb.append(columnOriginal.getAttributePrecision());
+            sb.append(" -> ");
+            sb.append(columnNew.getAttributePrecision());
+        }
+
+        if (columnOriginal.getScale() != columnNew.getScale()) {
+            sb.append(" scale: ");
+            sb.append(columnOriginal.getScale());
+            sb.append(" -> ");
+            sb.append(columnNew.getScale());
+        }
+
+        return sb.toString();
     }
 
 }



Mime
View raw message