db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r506209 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/ java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/platform/hsqldb/ test/org/apache/ddlutils/io/
Date Mon, 12 Feb 2007 01:29:22 GMT
Author: tomdz
Date: Sun Feb 11 17:29:21 2007
New Revision: 506209

URL: http://svn.apache.org/viewvc?view=rev&rev=506209
Log:
Fixed system index support in the HsqlDb platform
Made complex model test more robust

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java?view=diff&rev=506209&r1=506208&r2=506209
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Sun Feb 11 17:29:21 2007
@@ -74,6 +74,10 @@
         reading a model from a database. */
     private boolean _systemIndicesReturned = true;
 
+    /** Whether system indices for foreign keys are always non-unique or can be
+        unique (i.e. if a primary key column is used to establish the foreign key). */
+    private boolean _systemForeignKeyIndicesAlwaysNonUnique = false;
+    
     /** Whether the database returns a synthetic default value for non-identity required
columns. */ 
     private boolean _syntheticDefaultValueForRequiredReturned = false;
 
@@ -391,6 +395,30 @@
     public void setSystemIndicesReturned(boolean returningSystemIndices)
     {
         _systemIndicesReturned = returningSystemIndices;
+    }
+
+    /**
+     * Determines whether system indices for foreign keys are always non-unique or can be
+     * unique (i.e. if a primary key column is used to establish the foreign key).
+     * 
+     * @return <code>true</code> if system foreign key indices are always non-unique;
+     *         default is <code>false</code>
+     */
+    public boolean isSystemForeignKeyIndicesAlwaysNonUnique()
+    {
+        return _systemForeignKeyIndicesAlwaysNonUnique;
+    }
+
+    /**
+     * Specifies whether system indices for foreign keys are always non-unique or can be
+     * unique (i.e. if a primary key column is used to establish the foreign key).
+     * 
+     * @param alwaysNonUnique <code>true</code> if system foreign key indices
are always
+     *                        non-unique
+     */
+    public void setSystemForeignKeyIndicesAlwaysNonUnique(boolean alwaysNonUnique)
+    {
+        _systemForeignKeyIndicesAlwaysNonUnique = alwaysNonUnique;
     }
 
     /**

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=506209&r1=506208&r2=506209
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/JdbcModelReader.java Sun Feb 11
17:29:21 2007
@@ -638,7 +638,7 @@
     protected void removeInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table
table, ForeignKey fk) throws SQLException
     {
         List    columnNames  = new ArrayList();
-        boolean mustBeUnique = true;
+        boolean mustBeUnique = !getPlatformInfo().isSystemForeignKeyIndicesAlwaysNonUnique();
 
         for (int columnIdx = 0; columnIdx < fk.getReferenceCount(); columnIdx++)
         {
@@ -646,7 +646,7 @@
             Column localColumn = table.findColumn(name,
                                                   getPlatform().isDelimitedIdentifierModeOn());
 
-            if (!localColumn.isPrimaryKey())
+            if (mustBeUnique && !localColumn.isPrimaryKey())
             {
                 mustBeUnique = false;
             }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java?view=diff&rev=506209&r1=506208&r2=506209
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
Sun Feb 11 17:29:21 2007
@@ -102,6 +102,6 @@
     {
         String name = index.getName();
 
-        return (name != null) && name.startsWith("SYS_PK_");
+        return (name != null) && (name.startsWith("SYS_PK_") || name.startsWith("SYS_IDX_"));
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java?view=diff&rev=506209&r1=506208&r2=506209
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java Sun
Feb 11 17:29:21 2007
@@ -51,6 +51,7 @@
 
         info.setNonPKIdentityColumnsSupported(false);
         info.setIdentityOverrideAllowed(false);
+        info.setSystemForeignKeyIndicesAlwaysNonUnique(true);
 
         info.addNativeTypeMapping(Types.ARRAY,       "LONGVARBINARY", Types.LONGVARBINARY);
         info.addNativeTypeMapping(Types.BLOB,        "LONGVARBINARY", Types.LONGVARBINARY);

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java?view=diff&rev=506209&r1=506208&r2=506209
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestMisc.java Sun Feb 11 17:29:21 2007
@@ -22,11 +22,14 @@
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
 
 import junit.framework.Test;
 
 import org.apache.commons.beanutils.DynaBean;
+import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform;
 import org.dom4j.Document;
 import org.dom4j.Element;
 import org.dom4j.io.SAXReader;
@@ -254,6 +257,12 @@
      */
     public void testSelfReferenceIdentityOverrideOff() throws Exception
     {
+        // Hsqldb does not allow rows to reference themselves
+        if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            return;
+        }
+
         final String modelXml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
@@ -662,27 +671,53 @@
             pkColumnName = pkColumnName.toUpperCase();
         }
         assertEquals("1", ((Element)rows.get(0)).attributeValue(pkColumnName));
+
+        // we cannot be sure of the order in which the database returns the rows
+        // per table (some return them in pk order, some in insertion order)
+        // so we don't assume an order in this test
+        HashSet pkValues       = new HashSet();
+        HashSet expectedValues = new HashSet(Arrays.asList(new String[] { "1", "2" }));
+
         assertEquals(uppercase ? "G" : "g", ((Element)rows.get(1)).getName());
-        assertEquals("1", ((Element)rows.get(1)).attributeValue(pkColumnName));
         assertEquals(uppercase ? "G" : "g", ((Element)rows.get(2)).getName());
-        assertEquals("2", ((Element)rows.get(2)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(1)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(2)).attributeValue(pkColumnName));
+        assertEquals(pkValues, expectedValues);
+
+        pkValues.clear();
+        
         assertEquals(uppercase ? "A" : "a", ((Element)rows.get(3)).getName());
-        assertEquals("2", ((Element)rows.get(3)).attributeValue(pkColumnName));
         assertEquals(uppercase ? "A" : "a", ((Element)rows.get(4)).getName());
-        assertEquals("1", ((Element)rows.get(4)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(3)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(4)).attributeValue(pkColumnName));
+        assertEquals(pkValues, expectedValues);
+
+        pkValues.clear();
 
         assertEquals(uppercase ? "B" : "b", ((Element)rows.get(5)).getName());
-        assertEquals("2", ((Element)rows.get(5)).attributeValue(pkColumnName));
         assertEquals(uppercase ? "B" : "b", ((Element)rows.get(6)).getName());
-        assertEquals("1", ((Element)rows.get(6)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(5)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(6)).attributeValue(pkColumnName));
+        assertEquals(pkValues, expectedValues);
+
+        pkValues.clear();
+
         assertEquals(uppercase ? "C" : "c", ((Element)rows.get(7)).getName());
-        assertEquals("2", ((Element)rows.get(7)).attributeValue(pkColumnName));
         assertEquals(uppercase ? "C" : "c", ((Element)rows.get(8)).getName());
-        assertEquals("1", ((Element)rows.get(8)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(7)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(8)).attributeValue(pkColumnName));
+        assertEquals(pkValues, expectedValues);
+
+        pkValues.clear();
+
         assertEquals(uppercase ? "D" : "d", ((Element)rows.get(9)).getName());
-        assertEquals("2", ((Element)rows.get(9)).attributeValue(pkColumnName));
         assertEquals(uppercase ? "D" : "d", ((Element)rows.get(10)).getName());
-        assertEquals("1", ((Element)rows.get(10)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(9)).attributeValue(pkColumnName));
+        pkValues.add(((Element)rows.get(10)).attributeValue(pkColumnName));
+        assertEquals(pkValues, expectedValues);
+
+        pkValues.clear();
+
         assertEquals(uppercase ? "F" : "f", ((Element)rows.get(11)).getName());
         assertEquals("1", ((Element)rows.get(11)).attributeValue(pkColumnName));
 



Mime
View raw message