db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r711686 - in /db/ddlutils/trunk/src: main/java/org/apache/ddlutils/platform/ModelBasedResultSetIterator.java test/java/org/apache/ddlutils/io/TestMisc.java
Date Wed, 05 Nov 2008 20:28:48 GMT
Author: tomdz
Date: Wed Nov  5 12:28:43 2008
New Revision: 711686

URL: http://svn.apache.org/viewvc?rev=711686&view=rev
Log:
Fix and test for DDLUTILS-227: NullPointerException in ModelBasedResultSetIterator

Modified:
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/ModelBasedResultSetIterator.java
    db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/ModelBasedResultSetIterator.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/ModelBasedResultSetIterator.java?rev=711686&r1=711685&r2=711686&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/ModelBasedResultSetIterator.java
(original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/ModelBasedResultSetIterator.java
Wed Nov  5 12:28:43 2008
@@ -135,7 +135,7 @@
                 // the JDBC driver gave us enough meta data info
                 table = model.findTable(tableOfColumn, _caseSensitive);
             }
-            else
+            if (table == null)
             {
                 // not enough info in the meta data of the result set, lets try the
                 // user-supplied query hints

Modified: db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java?rev=711686&r1=711685&r2=711686&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java (original)
+++ db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestMisc.java Wed Nov  5 12:28:43
2008
@@ -34,7 +34,12 @@
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.ddlutils.TestAgainstLiveDatabaseBase;
 import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.platform.derby.DerbyPlatform;
 import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform;
+import org.apache.ddlutils.platform.mysql.MySql50Platform;
+import org.apache.ddlutils.platform.mysql.MySqlPlatform;
+import org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform;
 import org.apache.ddlutils.platform.sybase.SybasePlatform;
 import org.dom4j.Document;
 import org.dom4j.Element;
@@ -1215,4 +1220,72 @@
         assertEquals(new Integer(2), beans2.get(0), "pk1");
         assertEquals((Object)"bar",  beans2.get(0), "pk2");
     }
+
+    /**
+     * Test for DDLUTILS-227.
+     */
+    public void testDdlUtils227() throws Exception
+    {
+        final String modelXml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
+            "  <table name='Roundtrip'>\n"+
+            "    <column name='Pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='Avalue' type='VARCHAR'/>\n"+
+            "  </table>\n"+
+            "</database>";
+
+        createDatabase(modelXml);
+
+        Database readModel = readModelFromDatabase("roundtriptest");
+        
+        assertEquals(getAdjustedModel(),
+                     readModel);
+
+        insertRow("Roundtrip", new Object[] { new Integer(1), "foo" });
+
+        List beans = getRows("Roundtrip");
+
+        assertEquals(1, beans.size());
+        assertEquals(new Integer(1), beans.get(0), "Pk");
+        assertEquals((Object)"foo",  beans.get(0), "Avalue");
+
+        Table        table = getModel().findTable("Roundtrip", getPlatform().isDelimitedIdentifierModeOn());
+        StringBuffer query = new StringBuffer();
+
+        query.append("SELECT * FROM (SELECT * FROM ");
+        if (getPlatform().isDelimitedIdentifierModeOn())
+        {
+            query.append(getPlatformInfo().getDelimiterToken());
+        }
+        query.append(table.getName());
+        if (getPlatform().isDelimitedIdentifierModeOn())
+        {
+            query.append(getPlatformInfo().getDelimiterToken());
+        }
+        query.append(")");
+        // Some JDBC drivers do not allow us to perform the query without an explicit alias

+        if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            MySql50Platform.DATABASENAME.equals(getPlatform().getName()) ||
+            PostgreSqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            DerbyPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            query.append(" AS ");
+            if (getPlatform().isDelimitedIdentifierModeOn())
+            {
+                query.append(getPlatformInfo().getDelimiterToken());
+            }
+            query.append(table.getName());
+            if (getPlatform().isDelimitedIdentifierModeOn())
+            {
+                query.append(getPlatformInfo().getDelimiterToken());
+            }
+        }
+
+        beans = getPlatform().fetch(getModel(), query.toString(), new Table[] { table });
+
+        assertEquals(1, beans.size());
+        assertEquals(new Integer(1), beans.get(0), "Pk");
+        assertEquals((Object)"foo",  beans.get(0), "Avalue");
+    }
 }



Mime
View raw message