commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 31446] New: - Proposal for a set of new ResultSetHandlers.
Date Tue, 28 Sep 2004 04:07:26 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31446>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31446

Proposal for a set of new ResultSetHandlers. 

           Summary: Proposal for a set of new ResultSetHandlers.
           Product: Commons
           Version: 1.0 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: DbUtils
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: piotrl@cft-inc.net


Add set of ResultSetHandlers that return a Map instead of List.

For each row, key is determined (default is first column, user can specify
column index/name in constructor). Next the row is converted to scalar,
Array, Map or bean and stored in the Map under key. 

object            Array            Map            Bean
----------------- ---------------- -------------- ---------------
ColumnMapHandler  ArrayMapHandler  MapMapHandler  BeanListHandler

Examples:

  String; sql = "select user_id, user_name, last_login from passwd";
  Map users = (Map)run.query(
     "select user_id, user_name from passwd",
     new ColumnMapHandler());
  System.out.println(users.get("usr007")); 

  Map users = (Map)run.query(sql, new ArrayMapArray());
  System.out.println(users.get("usr007")[2]);

  Map users = (Map)run.query(sql, new MapMapArray());
  System.out.println(users.get("usr007").get("last_login"));

  Map users = (Map)run.query(sql, new MapBeanArray(TestBean.class));
  System.out.println(users.get("usr007").getLastLogin());

Implementation note:
Map implementation is LinkedHashMap. This class does preserve order of
insertions, thus, the sorting can be done in sql. However this
class is @since 1.4. 

Attached is source code (based on HEAD) and test cases.

---------------------------------------------------------------------
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