ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrey (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Commented: (IBATIS-333) Patch which allow to subsititute property with column name from ResultMap in dynamic sql
Date Sun, 08 Oct 2006 09:12:20 GMT
    [ http://issues.apache.org/jira/browse/IBATIS-333?page=comments#action_12440742 ] 
Andrey commented on IBATIS-333:

One more proposal. 

How about more flexible way: "meta-properties".

Consider example:

         <meta-property name="sort" value="#column_name#"/> <!-- this line declares,
that any request for "sort" metaproperty return column_name metaproperty -->
         <meta-property name="display_tag" value="#column_name#_tag"/> <!-- this
line declares, that any request for "display-tag" metaproperty return column_name metaproperty
fix tag suffix -->
         <meta-property name="some_restricted" explicit="true"/>  <!-- prohibit autogenerated
property, thow excetpion -->

    <resultMap id="salaryReportResult" class="testdomain.SalaryReport">
        <result column="ACC_ID" property="id">
             <meta-property name="column_name">ACC_ID</meta-property> <!--
This property can be implicitly generated by iBatis-->
             <meta-property name="sort">ACC_ID desc</meta-property> <!-- This
property is user defined, but if no specifed, will be generated from meta-generator -->
             <meta-property name="display_tag">account-id-tag</meta-property>
<!-- This property is name from .properties to display in grid -->
        <result column="ACC_FIRST_NAME" property="firstName"/>
        <result column="ACC_SALARY_PCT" property="salaryPct"/>
             <meta-property name="sort">SALARY * 0.5</meta-property> <!-- some
wierd usage, where we can't use column alias, but full expression needed (like in group by)

Later we can refer to this properties by special syntax or by more simple syntax, f.e.
1. Special:

2. Like property

3. Any other way which developers will perefer.

If this proposal is interesting, I'll create new JIRA and try to implement this.

PS: this will add flexibility to iBatis and no need to depend strictly on property names in
allow to define many things in one place, define database specific things in sqlmap, not in
calling classes, etc.

> Patch which allow to subsititute property with column name from ResultMap in dynamic
> ----------------------------------------------------------------------------------------
>                 Key: IBATIS-333
>                 URL: http://issues.apache.org/jira/browse/IBATIS-333
>             Project: iBatis for Java
>          Issue Type: New Feature
>          Components: SQL Maps
>    Affects Versions: 2.2.0
>            Reporter: Andrey
>         Attachments: insertColumnName.patch
> 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_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_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.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message