Revision: 3706
Author: [email protected]
Date: Fri Jul  9 11:47:49 2010
Log: The DDL generation of check constraints no longer attempt to create unique check constraint names. The reason for this is because the generated check constraint name may be too long and the database platform may reject the create table statement.

In the future, it would be desirable to prevent the user from entering duplicate check constraint names in the UI, ensuring that all check constraint names are unique over all columns and tables.
http://code.google.com/p/power-architect/source/detail?r=3706

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/H2DDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/HSQLDBDDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Thu Jul 8 14:18:26 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Fri Jul 9 11:47:49 2010
@@ -767,12 +767,16 @@
      * should override this method if it does not follow the SQL-92 check
      * constraint standard.
      *
+ * XXX Note that many platforms require unique check constraint names not + * only across all columns, but also all tables. It would be desirable to + * not allow the user to enter duplicate check constraint names in the UI.
+     *
      * @param c
      *            The {...@link SQLColumn} the check constraint applies to.
      * @param checkConstraint
* The {...@link String} of check constraints that may use variables - * defined by the {...@link SQLCheckConstraintVariable} enum and can be - * resolved by the {...@link SQLCheckConstraintVariableResolver}. + * defined by the {...@link SQLCheckConstraintVariable} enum and can + * be resolved by the {...@link SQLCheckConstraintVariableResolver}.
      * @return The generated SQL DDL snippet for defining column check
      *         constraints.
      */
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/H2DDLGenerator.java Fri Jul 9 08:00:06 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/H2DDLGenerator.java Fri Jul 9 11:47:49 2010
@@ -253,9 +253,7 @@

     /**
      * Overridden because check constraints can only be added to the table
- * level. Each constraint clause is delimited by a comma. Each constraint
-     * name is also prepended by the column name the check constraint is
-     * actually being applied to. e.g. col_<column-name>_<constraint-name>.
+     * level. Each constraint clause is delimited by a comma.
      */
     @Override
protected String columnCheckConstraint(SQLColumn c, List<SQLCheckConstraint> checkConstraints) {
@@ -276,8 +274,7 @@
                 sb.append(",\n");
             }
             sb.append("                ");
-            sb.append(String.format("CONSTRAINT col_%s_%s CHECK (%s)",
-                    c.getPhysicalName(),
+            sb.append(String.format("CONSTRAINT %s CHECK (%s)",
                     constraint.getName(),
                     helper.substitute(constraint.getConstraint())));
         }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/HSQLDBDDLGenerator.java Fri Jul 9 09:41:20 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/HSQLDBDDLGenerator.java Fri Jul 9 11:47:49 2010
@@ -24,20 +24,15 @@
 import java.sql.Types;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;

 import ca.sqlpower.architect.ddl.DDLStatement.StatementType;
-import ca.sqlpower.object.SPResolverRegistry;
-import ca.sqlpower.object.SPVariableHelper;
-import ca.sqlpower.object.SPVariableResolver;
-import ca.sqlpower.sqlobject.SQLCheckConstraint;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLObject;
 import ca.sqlpower.sqlobject.SQLRelationship;
-import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.sqlobject.SQLRelationship.Deferrability;
 import ca.sqlpower.sqlobject.SQLRelationship.UpdateDeleteRule;
+import ca.sqlpower.sqlobject.SQLTable;

 /**
* Implements the quirks required for successful DDL generation that targets
@@ -226,40 +221,5 @@
                print(createPhysicalName(colNameMap, newCol));
                endStatement(StatementType.ALTER, newCol);
     }
-
-    /**
- * Overridden because check constraints must have unique names regardless of - * which level it is applied on. Each constraint name is prepended by the
-     * column name the check constraint is actually being applied to. e.g.
-     * col_<column-name>_<constraint-name>.
-     */
-    @Override
- protected String columnCheckConstraint(SQLColumn c, List<SQLCheckConstraint> checkConstraints) {
-        if (!supportsCheckConstraint() ||
-                c == null ||
-                checkConstraints == null ||
-                checkConstraints.isEmpty()) {
-            return "";
-        }
-
-        SPVariableResolver resolver = c.getVariableResolver();
-        SPVariableHelper helper = new SPVariableHelper(c);
-        SPResolverRegistry.register(c, resolver);
-
-        StringBuilder sb = new StringBuilder();
-        for (SQLCheckConstraint constraint : checkConstraints) {
-            if (sb.length() > 0) {
-                sb.append(" ");
-            }
-            sb.append(String.format("CONSTRAINT col_%s_%s CHECK (%s)",
-                    c.getPhysicalName(),
-                    constraint.getName(),
-                    helper.substitute(constraint.getConstraint())));
-        }
-
-        SPResolverRegistry.deregister(c, resolver);
-
-        return sb.toString();
-    }

 }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java Wed Jul 7 11:16:36 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java Fri Jul 9 11:47:49 2010
@@ -30,13 +30,13 @@
 import ca.sqlpower.architect.ddl.DDLStatement.StatementType;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLIndex;
+import ca.sqlpower.sqlobject.SQLIndex.AscendDescend;
 import ca.sqlpower.sqlobject.SQLObject;
 import ca.sqlpower.sqlobject.SQLObjectException;
 import ca.sqlpower.sqlobject.SQLRelationship;
+import ca.sqlpower.sqlobject.SQLRelationship.UpdateDeleteRule;
 import ca.sqlpower.sqlobject.SQLSequence;
 import ca.sqlpower.sqlobject.SQLTable;
-import ca.sqlpower.sqlobject.SQLIndex.AscendDescend;
-import ca.sqlpower.sqlobject.SQLRelationship.UpdateDeleteRule;

 /**
* The base class for version-specific Oracle DDL generators. This class exists
@@ -470,4 +470,5 @@
     public boolean supportsRollback() {
         return false;
     }
-}
+
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java Fri Jul 9 08:00:06 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java Fri Jul 9 11:47:49 2010
@@ -699,9 +699,7 @@

     /**
      * Overridden because check constraints can only be added to the table
- * level. Each constraint clause is delimited by a comma. Each constraint
-     * name is also prepended by the column name the check constraint is
-     * actually being applied to. e.g. col_<column-name>_<constraint-name>.
+     * level. Each constraint clause is delimited by a comma.
      */
        @Override
protected String columnCheckConstraint(SQLColumn c, List<SQLCheckConstraint> checkConstraints) {
@@ -722,8 +720,7 @@
                 sb.append(",\n");
             }
             sb.append("                ");
-            sb.append(String.format("CONSTRAINT col_%s_%s CHECK (%s)",
-                    c.getPhysicalName(),
+            sb.append(String.format("CONSTRAINT %s CHECK (%s)",
                     constraint.getName(),
                     helper.substitute(constraint.getConstraint())));
         }

Reply via email to