You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/05/04 00:54:35 UTC

svn commit: r399479 - in /beehive/trunk/system-controls: src/jdbc/org/apache/beehive/controls/system/jdbc/ test/jdbc/junitTests/ test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/

Author: ekoneil
Date: Wed May  3 15:54:32 2006
New Revision: 399479

URL: http://svn.apache.org/viewcvs?rev=399479&view=rev
Log:
Fix BEEHIVE-1107.  This change makes the the column name lookup case insensitive for a Map return type from the JdbcControl.  The following should hold true:

Map map = Map getCustomerById(int id);
assert true == map.get("foo").equals(map.get("FOO"));

The ResultSetHashMap implementation now correctly overrides the containsKey / get / remove methods that from the HashMap superclass.

This checkin makes two other changes:
- enabled debug symbols for compiled JdbcControl tests
- put the key canonicalization logic into a single private method in the ResultSetHashMap class.  Makes for easier maintenance.

BB: self
Test: system controls pass


Modified:
    beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/ResultSetHashMap.java
    beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToMapMapper.java
    beehive/trunk/system-controls/test/jdbc/junitTests/build.xml
    beehive/trunk/system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java

Modified: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/ResultSetHashMap.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/ResultSetHashMap.java?rev=399479&r1=399478&r2=399479&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/ResultSetHashMap.java (original)
+++ beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/ResultSetHashMap.java Wed May  3 15:54:32 2006
@@ -15,7 +15,6 @@
  *
  * $Header:$
  */
-
 package org.apache.beehive.controls.system.jdbc;
 
 import java.sql.ResultSet;
@@ -24,67 +23,76 @@
 import java.util.HashMap;
 
 /**
- * The ResultSetHashMap class extends a standard HashMap and
- * populates it with data derived from a JDBC ResultSet.
+ * The ResultSetHashMap class extends a standard HashMap and populates it with data derived from a JDBC ResultSet.
  * <p/>
- * Note: the keys are treated case-insensitively, and therefore requests
- * made on the map are case-insensitive.  Any direct access to the keys
- * will yield uppercase keys.
+ * Note: the keys are treated case-insensitively, and therefore requests made on the map are
+ * case-insensitive.  Any direct access to the keys will yield uppercase keys.
  * <p/>
- * Note: only the row associated with the current cursor position
- * is used.
+ * Note: only the row associated with the current cursor position is used.
  */
 public class ResultSetHashMap extends HashMap<String, Object> {
 
+    /**
+     * Default constructor.
+     */
     ResultSetHashMap() {
         super();
     }
 
+    /**
+     * Constructor that initializes the map to a specific size.
+     * @param size the size
+     */
     ResultSetHashMap(int size) {
         super(size);
     }
 
     /**
-     * This constructor is optimized for being called in a loop.
-     * Preserve the upper case column list for performance.
+     * This constructor is optimized for being called in a loop.  It also canonicalizes the
+     * column names into upper case so that values in a map can be looked up using either
+     * upper, lower, or mixed case strings.
+     *
+     * @param rs the ResultSet to map
+     * @param keys an array of key objects to store in the map
+     * @throws SQLException if an error occurs while reading from the ResultSet
      */
     ResultSetHashMap(ResultSet rs, String[] keys) throws SQLException {
-        super();
+        super(keys.length);
+
         assert keys.length == rs.getMetaData().getColumnCount() + 1;
 
         for (int i = 1; i < keys.length; i++) {
             assert keys[i].equals(keys[i].toUpperCase());
-            super.put(keys[i], rs.getObject(i));
+            put(keys[i], rs.getObject(i));
         }
     }
 
-
     ResultSetHashMap(ResultSet rs) throws SQLException {
         super();
         ResultSetMetaData md = rs.getMetaData();
         for (int i = 1; i <= md.getColumnCount(); i++) {
-            super.put(md.getColumnName(i).toUpperCase(), rs.getObject(i));
+            put(md.getColumnName(i), rs.getObject(i));
         }
     }
 
-
-    public boolean containsKey(String key) {
-        return super.containsKey(key.toUpperCase());
+    public boolean containsKey(Object key) {
+        return super.containsKey(canonicalizeKey(key));
     }
 
-
-    public Object get(String key) {
-        return super.get(key.toUpperCase());
+    public Object get(Object key) {
+        return super.get(canonicalizeKey(key));
     }
 
-
     public Object put(String key, Object value) {
-        return super.put(key.toUpperCase(), value);
+        return super.put(canonicalizeKey(key), value);
     }
 
+    public Object remove(Object key) {
+        return super.remove(canonicalizeKey(key));
+    }
 
-    public Object remove(String key) {
-        return super.remove(key.toUpperCase());
+    private String canonicalizeKey(Object object) {
+        return object == null ? null : object.toString().toUpperCase();
     }
 }
 

Modified: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToMapMapper.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToMapMapper.java?rev=399479&r1=399478&r2=399479&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToMapMapper.java (original)
+++ beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToMapMapper.java Wed May  3 15:54:32 2006
@@ -15,7 +15,6 @@
  *
  * $Header:$
  */
-
 package org.apache.beehive.controls.system.jdbc;
 
 import org.apache.beehive.controls.api.ControlException;

Modified: beehive/trunk/system-controls/test/jdbc/junitTests/build.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/test/jdbc/junitTests/build.xml?rev=399479&r1=399478&r2=399479&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/jdbc/junitTests/build.xml (original)
+++ beehive/trunk/system-controls/test/jdbc/junitTests/build.xml Wed May  3 15:54:32 2006
@@ -53,10 +53,8 @@
             gendir="${module.gensrc.dir}"
             classpathref="junit.classpath"
             compileByExtension="true"
-            debug="${compiler.debug}"
-            nowarn="${compiler.nowarn}"
-            srcExtensions="*.java">
-        </apt>
+            debug="true"
+            nowarn="${compiler.nowarn}"/>
 
         <control-jar destfile="${module.jar}" basedir="${module.classes.dir}"/>
     </target>

Modified: beehive/trunk/system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java?rev=399479&r1=399478&r2=399479&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java (original)
+++ beehive/trunk/system-controls/test/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java Wed May  3 15:54:32 2006
@@ -25,12 +25,12 @@
 import org.apache.beehive.controls.system.jdbc.test.results.ResultsTestCtrl;
 import org.apache.beehive.controls.test.junit.ControlTestCase;
 
-import javax.sql.RowSet;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.HashMap;
 import java.util.Iterator;
+import javax.sql.RowSet;
 
 /**
  * Tests for result sets which contain multiple rows.
@@ -38,7 +38,7 @@
 public class DBMultiRowResultsTest extends ControlTestCase {
 
     @Control
-    public ResultsTestCtrl testCtrl;
+    private ResultsTestCtrl testCtrl;
 
     public void setUp() throws Exception {
         super.setUp();
@@ -119,8 +119,12 @@
     public void testArrayHashMapReturnType() throws Exception {
         HashMap[] customerHashMap = testCtrl.getCustomerHashMapArray(22);
         assertTrue(customerHashMap.length > 0);
-        assertEquals(customerHashMap[0].get("FNAME"), "tester2");
-        assertEquals(customerHashMap[0].get("USERID"), 22);
+
+        assertEquals("tester2", customerHashMap[0].get("FNAME"));
+        assertEquals(22, customerHashMap[0].get("USERID"));
+
+        assertEquals("tester2", customerHashMap[0].get("fname"));
+        assertEquals(22, customerHashMap[0].get("userid"));
     }
 
     /**
@@ -221,8 +225,12 @@
         assertEquals(fnames[3], "tester4");
     }
 
-    public static Test suite() { return new TestSuite(DBMultiRowResultsTest.class); }
+    public static Test suite() { 
+	return new TestSuite(DBMultiRowResultsTest.class); 
+    }
 
-    public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+    public static void main(String[] args) { 
+	junit.textui.TestRunner.run(suite()); 
+    }
 }