db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r422992 - in /db/ddlutils/trunk/src: doc/src/documentation/content/xdocs/ java/org/apache/ddlutils/ java/org/apache/ddlutils/model/ java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/task/
Date Tue, 18 Jul 2006 06:59:26 GMT
Author: tomdz
Date: Mon Jul 17 23:59:26 2006
New Revision: 422992

URL: http://svn.apache.org/viewvc?rev=422992&view=rev
Log:
Fix for DDLUTILS-89

Modified:
    db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml
    db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java

Modified: db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml?rev=422992&r1=422991&r2=422992&view=diff
==============================================================================
--- db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml (original)
+++ db/ddlutils/trunk/src/doc/src/documentation/content/xdocs/ant-tasks.xml Mon Jul 17 23:59:26
2006
@@ -150,6 +150,18 @@
           </td>
         </tr>
         <tr>
+          <td>sortForeignKeys</td>
+          <td>no</td>
+          <td>true, false</td>
+          <td>false</td>
+          <td>
+            Whether DdlUtils shall sort (alphabetically) the foreign keys of a table read
from a live
+            database or leave them in the order that they are returned by the database. Note
that
+            the sort is case sensitive only if delimied identifier mode is on (useDelimitedSqlIdentifiers
+            is set to <code>true</code>).
+          </td>
+        </tr>
+        <tr>
           <td>useDelimitedSqlIdentifiers</td>
           <td>no</td>
           <td>true, false</td>
@@ -732,6 +744,18 @@
             The pattern is that of
             <a href="ext:java/api/databaseMetaData-getTables">java.sql.DatabaseMetaData#getTables</a>.
             The special pattern '%' indicates that every table schema shall be used.
+          </td>
+        </tr>
+        <tr>
+          <td>sortForeignKeys</td>
+          <td>no</td>
+          <td>true, false</td>
+          <td>false</td>
+          <td>
+            Whether DdlUtils shall sort (alphabetically) the foreign keys of a table read
from a live
+            database or leave them in the order that they are returned by the database. Note
that
+            the sort is case sensitive only if delimied identifier mode is on (useDelimitedSqlIdentifiers
+            is set to <code>true</code>).
           </td>
         </tr>
         <tr>

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java?rev=422992&r1=422991&r2=422992&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java Mon Jul 17 23:59:26 2006
@@ -143,6 +143,22 @@
      */
     public void setSqlCommentsOn(boolean sqlCommentsOn);
 
+    /**
+     * Determines whether foreign keys of a table read from a live database
+     * are alphabetically sorted.
+     *
+     * @return <code>true</code> if read foreign keys are sorted
+     */
+    public boolean isForeignKeysSorted();
+
+    /**
+     * Specifies whether foreign keys read from a live database, shall be
+     * alphabetically sorted.
+     *
+     * @param foreignKeysSorted <code>true</code> if read foreign keys shall
be sorted
+     */
+    public void setForeignKeysSorted(boolean foreignKeysSorted);
+
     // functionality
     
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java?rev=422992&r1=422991&r2=422992&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java Mon Jul 17 23:59:26 2006
@@ -17,7 +17,10 @@
  */
 
 import java.io.Serializable;
+import java.text.Collator;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Collection;
@@ -700,6 +703,34 @@
         return (Column[])autoIncrColumns.toArray(new Column[autoIncrColumns.size()]);
     }
 
+    /**
+     * Sorts the foreign keys alphabetically.
+     * 
+     * @param caseSensitive Whether case matters
+     */
+    public void sortForeignKeys(final boolean caseSensitive)
+    {
+        if (!_foreignKeys.isEmpty())
+        {
+            final Collator collator = Collator.getInstance();
+    
+            Collections.sort(_foreignKeys, new Comparator() {
+                public int compare(Object obj1, Object obj2)
+                {
+                    String fk1Name = ((ForeignKey)obj1).getName();
+                    String fk2Name = ((ForeignKey)obj2).getName();
+
+                    if (!caseSensitive)
+                    {
+                        fk1Name = (fk1Name != null ? fk1Name.toLowerCase() : null);
+                        fk2Name = (fk2Name != null ? fk2Name.toLowerCase() : null);
+                    }
+                    return collator.compare(fk1Name, fk2Name);
+                }
+            });
+        }
+    }
+    
     /**
      * {@inheritDoc}
      */

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java?rev=422992&r1=422991&r2=422992&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java Mon Jul 17
23:59:26 2006
@@ -469,6 +469,12 @@
         {
             _connection = connection;
             db.addTables(readTables(catalog, schema, tableTypes));
+            // Note that we do this here instead of in readTable since platforms may redefine
the
+            // readTable method whereas it is highly unlikely that this method gets redefined
+            if (getPlatform().isForeignKeysSorted())
+            {
+                sortForeignKeys(db);
+            }
         }
         finally
         {
@@ -1057,6 +1063,19 @@
         }
     }
 
+    /**
+     * Sorts the foreign keys in the tables of the model.
+     * 
+     * @param model The model
+     */
+    protected void sortForeignKeys(Database model)
+    {
+        for (int tableIdx = 0; tableIdx < model.getTableCount(); tableIdx++)
+        {
+            model.getTable(tableIdx).sortForeignKeys(getPlatform().isDelimitedIdentifierModeOn());
+        }
+    }
+    
     /**
      * Replaces a specific character sequence in the given text with the character sequence
      * whose escaped version it is.

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?rev=422992&r1=422991&r2=422992&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Mon Jul
17 23:59:26 2006
@@ -82,6 +82,8 @@
     private boolean _sqlCommentsOn = true;
     /** Whether delimited identifiers are used or not. */
     private boolean _delimitedIdentifierModeOn = false;
+    /** Whether read foreign keys shall be sorted alphabetically. */
+    private boolean _foreignKeysSorted = false;
 
     /**
      * {@inheritDoc}
@@ -169,6 +171,22 @@
             throw new DdlUtilsException("Platform " + getName() + " does not support delimited
identifier");
         }
         _delimitedIdentifierModeOn = delimitedIdentifierModeOn;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isForeignKeysSorted()
+    {
+        return _foreignKeysSorted;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setForeignKeysSorted(boolean foreignKeysSorted)
+    {
+        _foreignKeysSorted = foreignKeysSorted;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java?rev=422992&r1=422991&r2=422992&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java Mon Jul 17 23:59:26
2006
@@ -130,6 +130,28 @@
     }
 
     /**
+     * Determines whether a table's foreign keys read from a live database
+     * shall be sorted alphabetically. Is <code>false</code> by default.
+     *
+     * @return <code>true</code> if the foreign keys shall be sorted
+     */
+    public boolean isSortForeignKeys()
+    {
+        return _platformConf.isSortForeignKeys();
+    }
+
+    /**
+     * Specifies whether a table's foreign keys read from a live database
+     * shall be sorted alphabetically.
+     *
+     * @param sortForeignKeys <code>true</code> if the foreign keys shall be
sorted
+     */
+    public void setSortForeignKeys(boolean sortForeignKeys)
+    {
+        _platformConf.setSortForeignKeys(sortForeignKeys);
+    }
+
+    /**
      * Determines whether the database shall be shut down after the task has finished.
      *
      * @return <code>true</code> if the database shall be shut down

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java?rev=422992&r1=422991&r2=422992&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java Mon Jul
17 23:59:26 2006
@@ -36,8 +36,10 @@
     private BasicDataSource _dataSource;
     /** Whether to use delimited SQL identifiers. */
     private boolean _useDelimitedSqlIdentifiers;
+    /** Whether read foreign keys shall be sorted. */
+    private boolean _sortForeignKeys;
     /** Whether to shutdown the database after the task has finished. */
-    private boolean _shutdownDatabase = false;
+    private boolean _shutdownDatabase;
     /** The catalog pattern. */
     private String _catalogPattern;
     /** The schema pattern. */
@@ -144,6 +146,28 @@
     }
 
     /**
+     * Determines whether a table's foreign keys read from a live database
+     * shall be sorted alphabetically. Is <code>false</code> by default.
+     *
+     * @return <code>true</code> if the foreign keys shall be sorted
+     */
+    public boolean isSortForeignKeys()
+    {
+        return _sortForeignKeys;
+    }
+
+    /**
+     * Specifies whether a table's foreign keys read from a live database
+     * shall be sorted alphabetically.
+     *
+     * @param sortForeignKeys <code>true</code> if the foreign keys shall be
sorted
+     */
+    public void setSortForeignKeys(boolean sortForeignKeys)
+    {
+        _sortForeignKeys = sortForeignKeys;
+    }
+
+    /**
      * Determines whether the database shall be shut down after the task has finished.
      *
      * @return <code>true</code> if the database shall be shut down
@@ -202,6 +226,7 @@
         }
         platform.setDataSource(_dataSource);
         platform.setDelimitedIdentifierModeOn(isUseDelimitedSqlIdentifiers());
+        platform.setForeignKeysSorted(isSortForeignKeys());
 
         return platform;
     }



Mime
View raw message