db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r231122 - in /db/ddlutils/trunk/src/test/org/apache/ddlutils: TestDatabaseWriterBase.java dynabean/TestDynaSqlQueries.java
Date Tue, 09 Aug 2005 21:48:35 GMT
Author: tomdz
Date: Tue Aug  9 14:48:26 2005
New Revision: 231122

URL: http://svn.apache.org/viewcvs?rev=231122&view=rev
Log:
Enhanced the dynasql tests for caseSensitive databases

Modified:
    db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java?rev=231122&r1=231121&r2=231122&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java Tue Aug  9
14:48:26 2005
@@ -25,6 +25,8 @@
 import javax.sql.DataSource;
 
 import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.DynaProperty;
 import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.ddlutils.builder.BuilderUtils;
 import org.apache.ddlutils.dynabean.DynaSqlException;
@@ -218,6 +220,35 @@
         catch (Exception ex)
         {
             throw new DynaSqlException(ex);
+        }
+    }
+
+    /**
+     * Determines the value of the bean's property that has the given name. Depending on
the
+     * case-setting of the current builder, the case of teh name is considered or not. 
+     * 
+     * @param bean     The bean
+     * @param propName The name of the property
+     * @return The value
+     */
+    protected Object getPropertyValue(DynaBean bean, String propName)
+    {
+        if (getBuilder().isCaseSensitive())
+        {
+            return bean.get(propName);
+        }
+        else
+        {
+            DynaProperty[] props = bean.getDynaClass().getDynaProperties();
+    
+            for (int idx = 0; idx < props.length; idx++)
+            {
+                if (propName.equalsIgnoreCase(props[idx].getName()))
+                {
+                    return bean.get(props[idx].getName());
+                }
+            }
+            throw new IllegalArgumentException("The bean has no property with the name "+propName);
         }
     }
 }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java?rev=231122&r1=231121&r2=231122&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java Tue Aug
 9 14:48:26 2005
@@ -12,22 +12,22 @@
         createDatabase(
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='ddlutils'>\n"+
-            "  <table name='testtable'>\n"+
-            "    <column name='id'   type='INTEGER' primaryKey='true'/>\n"+
-            "    <column name='text' type='VARCHAR' size='15'/>\n"+
+            "  <table name='TestTable'>\n"+
+            "    <column name='Id'   type='INTEGER' primaryKey='true'/>\n"+
+            "    <column name='Text' type='VARCHAR' size='15'/>\n"+
             "  </table>\n"+
             "</database>");
 
         insertData(
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<data>\n"+
-            "  <testtable id='1' text='Text 1'/>\n"+
-            "  <testtable id='2' text='Text 2'/>\n"+
-            "  <testtable id='3' text='Text 3'/>"+
+            "  <TestTable Id='1' Text='Text 1'/>\n"+
+            "  <TestTable Id='2' Text='Text 2'/>\n"+
+            "  <TestTable Id='3' Text='Text 3'/>"+
             "</data>");
 
         DynaSql         dynaSql = new DynaSql(getBuilder(), getDataSource(), getModel());
-        DynaSqlIterator it      = (DynaSqlIterator)dynaSql.query("SELECT * FROM testtable");
+        DynaSqlIterator it      = (DynaSqlIterator)dynaSql.query("SELECT * FROM TestTable");
         DynaBean        bean    = null;
 
         assertTrue(it.hasNext());
@@ -37,27 +37,27 @@
         bean = (DynaBean)it.next();
 
         assertEquals(new Integer(1),
-                     bean.get("id"));
+                     getPropertyValue(bean, "Id"));
         assertEquals("Text 1",
-                     bean.get("text"));
+                     getPropertyValue(bean, "Text"));
         
         assertTrue(it.hasNext());
 
         bean = (DynaBean)it.next();
 
         assertEquals(new Integer(2),
-                     bean.get("id"));
+                     getPropertyValue(bean, "Id"));
         assertEquals("Text 2",
-                     bean.get("text"));
+                     getPropertyValue(bean, "Text"));
 
         assertTrue(it.hasNext());
 
         bean = (DynaBean)it.next();
 
         assertEquals(new Integer(3),
-                     bean.get("id"));
+                     getPropertyValue(bean, "Id"));
         assertEquals("Text 3",
-                     bean.get("text"));
+                     getPropertyValue(bean, "Text"));
 
         assertFalse(it.hasNext());
         assertFalse(it.isConnectionOpen());
@@ -68,22 +68,22 @@
         createDatabase(
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='ddlutils'>\n"+
-            "  <table name='testtable'>\n"+
-            "    <column name='id'   type='INTEGER' primaryKey='true'/>\n"+
-            "    <column name='text' type='VARCHAR' size='15'/>\n"+
+            "  <table name='TestTable'>\n"+
+            "    <column name='Id'   type='INTEGER' primaryKey='true'/>\n"+
+            "    <column name='Text' type='VARCHAR' size='15'/>\n"+
             "  </table>\n"+
             "</database>");
 
         insertData(
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<data>\n"+
-            "  <testtable id='1' text='Text 1'/>\n"+
-            "  <testtable id='2' text='Text 2'/>\n"+
-            "  <testtable id='3' text='Text 3'/>"+
+            "  <TestTable Id='1' Text='Text 1'/>\n"+
+            "  <TestTable Id='2' Text='Text 2'/>\n"+
+            "  <TestTable Id='3' Text='Text 3'/>"+
             "</data>");
 
         DynaSql  dynaSql = new DynaSql(getBuilder(), getDataSource(), getModel());
-        List     beans   = dynaSql.fetch("SELECT * FROM testtable");
+        List     beans   = dynaSql.fetch("SELECT * FROM TestTable");
 
         assertEquals(3,
                      beans.size());
@@ -91,23 +91,23 @@
         DynaBean bean = (DynaBean)beans.get(0);
 
         assertEquals(new Integer(1),
-                     bean.get("id"));
+                     getPropertyValue(bean, "Id"));
         assertEquals("Text 1",
-                     bean.get("text"));
+                     getPropertyValue(bean, "Text"));
         
         bean = (DynaBean)beans.get(1);
 
         assertEquals(new Integer(2),
-                     bean.get("id"));
+                     getPropertyValue(bean, "Id"));
         assertEquals("Text 2",
-                     bean.get("text"));
+                     getPropertyValue(bean, "Text"));
 
         bean = (DynaBean)beans.get(2);
 
         assertEquals(new Integer(3),
-                     bean.get("id"));
+                     getPropertyValue(bean, "Id"));
         assertEquals("Text 3",
-                     bean.get("text"));
+                     getPropertyValue(bean, "Text"));
     }
 
     public void testJoinQuery() throws Exception
@@ -115,28 +115,28 @@
         createDatabase(
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='ddlutils'>\n"+
-            "  <table name='testtable1'>\n"+
-            "    <column name='id1' type='INTEGER' primaryKey='true'/>\n"+
-            "    <column name='id2' type='INTEGER'/>\n"+
+            "  <table name='TestTable1'>\n"+
+            "    <column name='Id1' type='INTEGER' primaryKey='true'/>\n"+
+            "    <column name='Id2' type='INTEGER'/>\n"+
             "  </table>\n"+
-            "  <table name='testtable2'>\n"+
-            "    <column name='id'   type='INTEGER' primaryKey='true'/>\n"+
-            "    <column name='text' type='VARCHAR' size='15'/>\n"+
+            "  <table name='TestTable2'>\n"+
+            "    <column name='Id'   type='INTEGER' primaryKey='true'/>\n"+
+            "    <column name='Text' type='VARCHAR' size='15'/>\n"+
             "  </table>\n"+
             "</database>");
 
         insertData(
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<data>\n"+
-            "  <testtable1 id1='1'/>\n"+
-            "  <testtable1 id1='2' id2='3'/>\n"+
-            "  <testtable2 id='1' text='Text 1'/>\n"+
-            "  <testtable2 id='2' text='Text 2'/>\n"+
-            "  <testtable2 id='3' text='Text 3'/>"+
+            "  <TestTable1 Id1='1'/>\n"+
+            "  <TestTable1 Id1='2' Id2='3'/>\n"+
+            "  <TestTable2 Id='1' Text='Text 1'/>\n"+
+            "  <TestTable2 Id='2' Text='Text 2'/>\n"+
+            "  <TestTable2 Id='3' Text='Text 3'/>"+
             "</data>");
 
         DynaSql         dynaSql = new DynaSql(getBuilder(), getDataSource(), getModel());
-        DynaSqlIterator it      = (DynaSqlIterator)dynaSql.query("SELECT id1, text FROM testtable1,
testtable2 WHERE id2 = id");
+        DynaSqlIterator it      = (DynaSqlIterator)dynaSql.query("SELECT Id1, Text FROM TestTable1,
TestTable2 WHERE Id2 = Id");
         DynaBean        bean    = null;
 
         assertTrue(it.hasNext());
@@ -144,9 +144,9 @@
         bean = (DynaBean)it.next();
 
         assertEquals(new Integer(2),
-                     bean.get("id1"));
+                     getPropertyValue(bean, "Id1"));
         assertEquals("Text 3",
-                     bean.get("text"));
+                     getPropertyValue(bean, "Text"));
 
         assertFalse(it.hasNext());
         assertFalse(it.isConnectionOpen());



Mime
View raw message