Commons DbUtils
  1. Commons DbUtils
  2. DBUTILS-25

[dbutils] Proposal for a set of new ResultSetHandlers

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      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.

        Activity

        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Henri Yandell made changes -
        Fix Version/s 1.1 [ 12311973 ]
        Henri Yandell made changes -
        Affects Version/s 1.0 Final [ 12311724 ]
        Henri Yandell made changes -
        Affects Version/s 1.0 Final [ 12311651 ]
        Key COM-1605 DBUTILS-25
        Component/s DbUtils [ 12311110 ]
        Project Commons [ 12310458 ] Commons DbUtils [ 12310470 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 31446 12341757
        Piotr Lakomy created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Piotr Lakomy
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development