commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils BasicResultSetConverter.java
Date Fri, 17 Oct 2003 23:48:58 GMT
dgraham     2003/10/17 16:48:58

  Modified:    dbutils/src/java/org/apache/commons/dbutils
                        BasicResultSetConverter.java
  Log:
  Added CaseInsensitiveHashMap inner class for the toMap() 
  implementation to use.  Databases don't handle column name
  casing the same so we normalize all names to lowercase strings.
  
  Revision  Changes    Path
  1.6       +39 -4     jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BasicResultSetConverter.java
  
  Index: BasicResultSetConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BasicResultSetConverter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BasicResultSetConverter.java	17 Oct 2003 23:37:57 -0000	1.5
  +++ BasicResultSetConverter.java	17 Oct 2003 23:48:58 -0000	1.6
  @@ -72,6 +72,7 @@
   import java.sql.SQLException;
   import java.util.ArrayList;
   import java.util.HashMap;
  +import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   
  @@ -230,7 +231,7 @@
   
       // See interface for javadoc.
       public Map toMap(ResultSet rs) throws SQLException {
  -        Map result = new HashMap();
  +        Map result = new CaseInsensitiveHashMap();
           ResultSetMetaData rsmd = rs.getMetaData();
           int cols = rsmd.getColumnCount();
   
  @@ -311,6 +312,40 @@
           }
   
           return beanInfo.getPropertyDescriptors();
  +    }
  +    
  +    /**
  +     * A Map that converts all keys to lowercase Strings for case insensitive
  +     * lookups.  This is needed for the toMap() implementation because 
  +     * databases don't consistenly handle the casing of column names. 
  +     */
  +    private static class CaseInsensitiveHashMap extends HashMap {
  +
  +        public boolean containsKey(Object key) {
  +            return super.containsKey(key.toString().toLowerCase());
  +        }
  +
  +        public Object get(Object key) {
  +            return super.get(key.toString().toLowerCase());
  +        }
  +
  +        public Object put(Object key, Object value) {
  +            return super.put(key.toString().toLowerCase(), value);
  +        }
  +
  +        public void putAll(Map m) {
  +            Iterator iter = m.keySet().iterator();
  +            while (iter.hasNext()) {
  +                Object key = iter.next();
  +                Object value = m.get(key);
  +                this.put(key, value);
  +            }
  +        }
  +
  +        public Object remove(Object key) {
  +            return super.remove(key.toString().toLowerCase());
  +        }
  +
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message