db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r359530 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils/platform: MSSqlBuilder.java SqlBuilder.java SybaseBuilder.java
Date Wed, 28 Dec 2005 14:03:14 GMT
Author: tomdz
Date: Wed Dec 28 06:03:08 2005
New Revision: 359530

URL: http://svn.apache.org/viewcvs?rev=359530&view=rev
Log:
Fixed bug with delimiter length for foreign key names

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SybaseBuilder.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlBuilder.java?rev=359530&r1=359529&r2=359530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MSSqlBuilder.java Wed Dec 28 06:03:08
2005
@@ -122,18 +122,6 @@
     /**
      * {@inheritDoc}
      */
-    protected boolean shouldGeneratePrimaryKeys(Column[] primaryKeyColumns)
-    {
-        /*
-         * requires primary key indication for autoincrement key columns
-         * I'm not sure why the default skips the pk statement if all are identity
-         */
-        return primaryKeyColumns.length > 0;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
     {
         print("DROP INDEX ");
@@ -159,7 +147,7 @@
      */
     protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey) throws
IOException
     {
-        String constraintName = foreignKey.getName() == null ? getConstraintName(null, table,
"FK", getForeignKeyName(foreignKey)) : foreignKey.getName();
+        String constraintName = getForeignKeyName(table, foreignKey);
 
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = ");
         printAlwaysSingleQuotedIdentifier(constraintName);

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java?rev=359530&r1=359529&r2=359530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Wed Dec 28 06:03:08
2005
@@ -1326,24 +1326,31 @@
     }
 
     /**
-     * Determines a unique name for the given foreign key.
+     * Returns the name to be used for the given foreign key. If the foreign key has no
+     * specified name, this method determines a unique name for it. The name will also
+     * be shortened to honor the maximum identifier length imposed by the platform.
      * 
-     * @param fk The foreign key
+     * @param table The table for whith the foreign key is defined
+     * @param fk    The foreign key
      * @return The name
      */
-    protected String getForeignKeyName(ForeignKey fk)
+    public String getForeignKeyName(Table table, ForeignKey fk)
     {
-        //table and local column should be sufficient - is it possible for one
-        //column to reference multiple tables
-        StringBuffer name = new StringBuffer();
+        String fkName = fk.getName();
 
-        for (int idx = 0; idx < fk.getReferenceCount(); idx++)
+        if ((fkName == null) || (fkName.length() == 0))
         {
-            name.append(fk.getReference(idx).getLocalColumnName());
-            name.append("_");
+            StringBuffer name = new StringBuffer();
+    
+            for (int idx = 0; idx < fk.getReferenceCount(); idx++)
+            {
+                name.append(fk.getReference(idx).getLocalColumnName());
+                name.append("_");
+            }
+            name.append(fk.getForeignTableName());
+            fkName = getConstraintName(null, table, "FK", name.toString());
         }
-        name.append(fk.getForeignTableName());
-        return name.toString();
+        return shortenName(fkName, getPlatformInfo().getMaxIdentifierLength());
     }
 
     /**
@@ -1416,15 +1423,15 @@
 
     /**
      * Determines whether we should generate a primary key constraint for the given
-     * primary key columns. By default if there are no primary keys or the column(s) are

-     * all auto increment (identity) columns then there is no need to generate a primary
key 
-     * constraint.
+     * primary key columns.
      * 
      * @param primaryKeyColumns The pk columns
      * @return <code>true</code> if a pk statement should be generated for the
columns
      */
     protected boolean shouldGeneratePrimaryKeys(Column[] primaryKeyColumns)
     {
+        return true;
+/*
         for (int idx = 0; idx < primaryKeyColumns.length; idx++)
         {
             if (!primaryKeyColumns[idx].isAutoIncrement())
@@ -1433,6 +1440,7 @@
             }
         }
         return false;
+*/
     }
 
     /**
@@ -1584,7 +1592,7 @@
                 if (getPlatformInfo().isEmbeddedForeignKeysNamed())
                 {
                     print("CONSTRAINT ");
-                    printIdentifier(getConstraintName(null, table, "FK", Integer.toString(idx)));
+                    printIdentifier(getForeignKeyName(table, key));
                     print(" ");
                 }
                 print("FOREIGN KEY (");
@@ -1616,7 +1624,7 @@
             writeTableAlterStmt(table);
 
             print("ADD CONSTRAINT ");
-            printIdentifier(key.getName() == null ? getConstraintName(null, table, "FK",
getForeignKeyName(key)) : key.getName());
+            printIdentifier(getForeignKeyName(table, key));
             print(" FOREIGN KEY (");
             writeLocalReferences(key);
             print(") REFERENCES ");
@@ -1673,7 +1681,7 @@
     {
         writeTableAlterStmt(table);
         print("DROP CONSTRAINT ");
-        printIdentifier(foreignKey.getName() == null ? getConstraintName(null, table, "FK",
getForeignKeyName(foreignKey)) : foreignKey.getName());
+        printIdentifier(getForeignKeyName(table, foreignKey));
         printEndOfStatement();
     }
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SybaseBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SybaseBuilder.java?rev=359530&r1=359529&r2=359530&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SybaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SybaseBuilder.java Wed Dec 28
06:03:08 2005
@@ -83,7 +83,7 @@
      */
     protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey) throws
IOException
     {
-        String constraintName = foreignKey.getName() == null ? getConstraintName(null, table,
"FK", getForeignKeyName(foreignKey)) : foreignKey.getName();
+        String constraintName = getForeignKeyName(table, foreignKey);
 
         print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'RI' AND name = ");
         printAlwaysSingleQuotedIdentifier(constraintName);



Mime
View raw message