Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-333

Patch which allow to subsititute property with column name from ResultMap in dynamic sql

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.2.0
    • None
    • Core
    • None

    Description

      In situtation, when i need to implement sorting, I need to create such monster, like abator creates for me. But
      if i only need sorting, here should be mapping beetween columns and properties (if they specified explicitly
      in ResultMap). In this case, i can write

      <resultMap id="dynamicAccountResult" class="testdomain.Account">
      <result column="ACC_ID" property="id"/>
      <result column="ACC_FIRST_NAME" property="firstName"/>
      <result column="ACC_LAST_NAME" property="lastName"/>
      <result column="ACC_EMAIL" property="emailAddress"/>
      </resultMap>

      <select id="dynamicInsertColumnName"
      parameterClass="string"
      resultMap="dynamicAccountResult">
      select
      ACC_ID,
      ACC_FIRST_NAME,
      ACC_LAST_NAME,
      ACC_EMAIL
      from ACCOUNT
      <dynamic>
      <insertColumnName prepend="where"> = 1</insertColumnName> <!-- ibatis replace this with column mapped for "id" passed as unnamed property -->
      <insertColumnName prepend="order by"/>
      </dynamic>
      </select>

      public void testInsertColumnName() throws SQLException

      { List list = sqlMap.queryForList("dynamicInsertColumnName", "id"); // Here we pass our property name assertEquals(1, list.size()); }

      SQL will be

      select
      ACC_ID,
      ACC_FIRST_NAME,
      ACC_LAST_NAME,
      ACC_EMAIL
      from ACCOUNT
      where ACC_ID = 1
      order by ACC_ID

      In any case, we can pass some AccountCriteria which will hold a list with soring properties names and we can iterate in dynamic sql
      and get multiply field "order by" clause

      PS: Not all things tested yet. No errors thrown. This is alpha of this feature. This is proof of conecpt (due of little amount of structural
      changes in other ibatis classes). If developers wan't this feature and agree with my decisions, I'll implement all other bells and whishes
      like error checking, tests and may be other extensions for this tag.

      Attachments

        Activity

          People

            Unassigned Unassigned
            aka50 Andrey
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: