db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r500943 - /db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java
Date Mon, 29 Jan 2007 05:50:38 GMT
Author: tomdz
Date: Sun Jan 28 21:50:38 2007
New Revision: 500943

URL: http://svn.apache.org/viewvc?view=rev&rev=500943
Log:
Enhanced support for foreign keys using primary key columns

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java

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?view=diff&rev=500943&r1=500942&r2=500943
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java Sun Jan 28
21:50:38 2007
@@ -637,18 +637,27 @@
      */
     protected void removeInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table
table, ForeignKey fk) throws SQLException
     {
-        List columnNames = new ArrayList();
+        List    columnNames  = new ArrayList();
+        boolean mustBeUnique = true;
 
         for (int columnIdx = 0; columnIdx < fk.getReferenceCount(); columnIdx++)
         {
-            columnNames.add(fk.getReference(columnIdx).getLocalColumnName());
+            String name        = fk.getReference(columnIdx).getLocalColumnName();
+            Column localColumn = table.findColumn(name,
+                                                  getPlatform().isDelimitedIdentifierModeOn());
+
+            if (!localColumn.isPrimaryKey())
+            {
+                mustBeUnique = false;
+            }
+            columnNames.add(name);
         }
 
         for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++)
         {
             Index index = table.getIndex(indexIdx);
 
-            if (!index.isUnique() && matches(index, columnNames) && 
+            if ((mustBeUnique == index.isUnique()) && matches(index, columnNames)
&& 
                 isInternalForeignKeyIndex(metaData, table, fk, index))
             {
                 fk.setAutoIndexPresent(true);



Mime
View raw message