Revision: 3699
Author: [email protected]
Date: Thu Jul  8 14:18:26 2010
Log: Fixed the column definition DDL generation in the MySqlDDLGenerator. An ENUM type is an actual data type, and not from the data type. e.g. A MySQL VARCHAR with constraint type enumeration would have a data type of ENUM instead of VARCHAR.

Also, fixed documentation in the AddCheckConstraintTableRowAction.
http://code.google.com/p/power-architect/source/detail?r=3699

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/AddCheckConstraintTableRowAction.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Wed Jul 7 11:16:36 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Thu Jul 8 14:18:26 2010
@@ -812,13 +812,13 @@
      *
      * @param c
      *            The {...@link SQLColumn} the enumeration applies to.
-     * @param enumeration
+     * @param enumerations
      *            The {...@link List} of enumerated values.
* @return The generated SQL DDL snippet for defining column enumerations.
      */
- protected String columnEnumeration(SQLColumn c, List<SQLEnumeration> enumeration) { + protected String columnEnumeration(SQLColumn c, List<SQLEnumeration> enumerations) {
         if (supportsCheckConstraint()) {
-            return columnEnumToCheckConstraint(c, enumeration);
+            return columnEnumToCheckConstraint(c, enumerations);
         } else {
             return "";
         }
@@ -835,22 +835,22 @@
      *
      * @param c
      *            The {...@link SQLColumn} the enumeration applies to.
-     * @param enumeration
+     * @param enumerations
      *            The {...@link String} array of enumerated types
      * @return The generated SQL DDL snippet for using check constraints to
      *         define column enumerations.
      */
- protected String columnEnumToCheckConstraint(SQLColumn c, List<SQLEnumeration> enumeration) {
-        if (c == null || enumeration == null || enumeration.isEmpty()) {
+ protected String columnEnumToCheckConstraint(SQLColumn c, List<SQLEnumeration> enumerations) {
+        if (c == null || enumerations == null || enumerations.isEmpty()) {
             return "";
         }

         StringBuilder sb = new StringBuilder();
-        for (SQLEnumeration e : enumeration) {
+        for (SQLEnumeration enumeration : enumerations) {
             if (sb.length() > 0) {
                 sb.append(", ");
             }
-            sb.append("'" + e.getName() + "'");
+            sb.append("'" + enumeration.getName() + "'");
         }

         return "CHECK (" + c.getPhysicalName() + " IN (" +
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java Wed Jul 7 11:16:36 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java Thu Jul 8 14:18:26 2010
@@ -42,6 +42,7 @@
 import ca.sqlpower.sqlobject.SQLRelationship.UpdateDeleteRule;
 import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.sqlobject.SQLTypePhysicalProperties.SQLTypeConstraint;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;

 public class MySqlDDLGenerator extends GenericDDLGenerator {

@@ -453,6 +454,28 @@
         print(r.getName());
         endStatement(StatementType.DROP, r);
     }
+
+    @Override
+ protected String columnDefinition(SQLColumn c, Map<String, SQLObject> colNameMap) {
+        StringBuffer def = new StringBuffer();
+
+        // Column name
+        def.append(createPhysicalName(colNameMap, c));
+
+        def.append(" ");
+        def.append(columnType(c));
+
+        UserDefinedSQLType type = c.getUserDefinedSQLType();
+        String defaultValue = type.getDefaultValue(getPlatformName());
+        if ( defaultValue != null && !defaultValue.equals("")) {
+            def.append(" ");
+            def.append("DEFAULT ");
+            def.append(defaultValue);
+        }
+
+        def.append(columnNullability(c));
+        return def.toString();
+    }

     /**
      * Adds support for the MySQL auto_increment feature.
@@ -461,8 +484,9 @@
     @Override
     public String columnType(SQLColumn c) {
         String type;
-        if (c.getConstraintType() == SQLTypeConstraint.ENUM) {
-            type = columnEnumeration(c, c.getEnumerations());
+        UserDefinedSQLType udt = c.getUserDefinedSQLType();
+ if (udt.getConstraintType(getPlatformName()) == SQLTypeConstraint.ENUM) { + type = columnEnumeration(c, udt.getEnumerations(getPlatformName()));
         } else {
             type = super.columnType(c);
         }
@@ -474,17 +498,17 @@
     }

     @Override
- protected String columnEnumeration(SQLColumn c, List<SQLEnumeration> enumeration) {
-        if (enumeration == null || enumeration.isEmpty()) {
+ protected String columnEnumeration(SQLColumn c, List<SQLEnumeration> enumerations) {
+        if (enumerations == null || enumerations.isEmpty()) {
             return "";
         }

         StringBuilder sb = new StringBuilder();
-        for (SQLEnumeration e : enumeration) {
+        for (SQLEnumeration enumeration : enumerations) {
             if (sb.length() > 0) {
-                sb.append(", ");
-            }
-            sb.append(e.getName());
+                sb.append(",");
+            }
+            sb.append("'" + enumeration.getName() + "'");
         }

         return "ENUM(" + sb.toString() + ")";
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/action/AddCheckConstraintTableRowAction.java Thu Jul 8 08:33:18 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/action/AddCheckConstraintTableRowAction.java Thu Jul 8 14:18:26 2010
@@ -32,9 +32,8 @@
 /**
* This {...@link Action} adds a new row to a {...@link CheckConstraintTable} after
  * prompting the user to enter in a {...@link SQLCheckConstraint} name and
- * constraint condition, and selects the row in the table. If either the name or - * constraint condition exists, no rows are added and the row with the duplicate
- * entry is selected.
+ * constraint condition, and selects the row in the table. If name already
+ * exists, no rows are added and the duplicate row is selected.
  */
 public class AddCheckConstraintTableRowAction extends AbstractAction {

Reply via email to