You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Nils Winkler (JIRA)" <ib...@incubator.apache.org> on 2006/02/21 09:00:26 UTC

[jira] Created: (IBATIS-264) Include with parameter

Include with parameter
----------------------

         Key: IBATIS-264
         URL: http://issues.apache.org/jira/browse/IBATIS-264
     Project: iBatis for Java
        Type: Improvement
  Components: SQL Maps  
    Versions: 2.1.7    
    Reporter: Nils Winkler
    Priority: Minor


I have the following problem: I include the same SQL snippet from
multiple select statements, some of them for completely unrelated
tables. This is done because these tables contain quite a few columns
with the same names in both tables.

<sql id="inc">
    name,
    value,
    foo,
    bar
</sql>

<select id="loadA">
    select id,
    <include refid="inc" />
    from A
</select>

<select id="loadB">
    select id,
    <include refid="inc" />
    from B
</select>

When including the list of columns, it would be quite handy to add a
parameter to the include, for example to set a table alias in case I
have a join between tables:

<select id="loadA">
    select a.id, b.id,
    <include refid="inc" />
    from A a
    inner join B b on (b.id = a.id)
    where b.baz = #baz#
</select>

In the above query, "name", "value" etc are no longer unique in the
query, most of the time you end up with the wrong values.

It would be great if I would be able to pass in a parameter to the
include, e.g.:

<select id="loadA">
    select a.id, b.id,
    <include refid="inc" param="a."/>
    from A a
    inner join B b on (b.id = a.id)
    where b.baz = #baz#
</select>

so I could have the SQL snippet defined like this:

<sql id="inc">
    $param$name,
    $param$value,
    $param$foo,
    $param$bar
</sql>

This way, all of the statements would still work and I could make sure
that the correct columns are used in each case.


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


[jira] Commented: (IBATIS-264) Include with parameter

Posted by "sph (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12718040#action_12718040 ] 

sph commented on IBATIS-264:
----------------------------

It will be of really useful to have parameterized include 
because it will result in more reusability of queries in a large scale applications.


> Include with parameter
> ----------------------
>
>                 Key: IBATIS-264
>                 URL: https://issues.apache.org/jira/browse/IBATIS-264
>             Project: iBatis for Java
>          Issue Type: Improvement
>          Components: SQL Maps
>    Affects Versions: 2.1.7
>            Reporter: Nils Winkler
>            Priority: Minor
>
> I have the following problem: I include the same SQL snippet from
> multiple select statements, some of them for completely unrelated
> tables. This is done because these tables contain quite a few columns
> with the same names in both tables.
> <sql id="inc">
>     name,
>     value,
>     foo,
>     bar
> </sql>
> <select id="loadA">
>     select id,
>     <include refid="inc" />
>     from A
> </select>
> <select id="loadB">
>     select id,
>     <include refid="inc" />
>     from B
> </select>
> When including the list of columns, it would be quite handy to add a
> parameter to the include, for example to set a table alias in case I
> have a join between tables:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" />
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> In the above query, "name", "value" etc are no longer unique in the
> query, most of the time you end up with the wrong values.
> It would be great if I would be able to pass in a parameter to the
> include, e.g.:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" param="a."/>
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> so I could have the SQL snippet defined like this:
> <sql id="inc">
>     $param$name,
>     $param$value,
>     $param$foo,
>     $param$bar
> </sql>
> This way, all of the statements would still work and I could make sure
> that the correct columns are used in each case.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Commented: (IBATIS-264) Include with parameter

Posted by Sven Boden <li...@pandora.be>.
Thanks for the explanation, personally I like the property functionality 
actually better than the extension to <sql>. But that would raise some 
other issues... duplicates, namespaces....

Regards,
Sven

Nils Winkler (JIRA) wrote:

>    [ http://issues.apache.org/jira/browse/IBATIS-264?page=comments#action_12367195 ] 
>
>Nils Winkler commented on IBATIS-264:
>-------------------------------------
>
>I pretty much agree with your reasoning, that's why I categorized it as a minor improvement.
>
>Our current use case looks like this: We're using inheritance in the conceptual data model to include a certain set of columns in pretty much every table, e.g. for auditing (last update user, last update timestamp, etc.). Because of this, I easily end up with the same columns from two tables in the query.
>
>I currently add an attribute "tableAlias" in my DAO to the parameter map, which I then use in the sql snippet:
>
><sql id="inc">
>    $tableAlias$name,
>    $tableAlias$value,
>    $tableAlias$foo,
>    $tableAlias$bar
></sql> 
>
>, but this is ugly, since I have to know the table alias in the DAO, while the rest of the SQL is in the XML mapping file.
>
>Another option for getting rid of our hack would be to make it possible to set a property in the mapping file, e.g. before including the sql snippet:
>
><setProperty name="tableAlias" value="a" />
><include refid="inc" />
>
>How's about that?
>
>  
>


[jira] Commented: (IBATIS-264) Include with parameter

Posted by "Nils Winkler (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-264?page=comments#action_12367195 ] 

Nils Winkler commented on IBATIS-264:
-------------------------------------

I pretty much agree with your reasoning, that's why I categorized it as a minor improvement.

Our current use case looks like this: We're using inheritance in the conceptual data model to include a certain set of columns in pretty much every table, e.g. for auditing (last update user, last update timestamp, etc.). Because of this, I easily end up with the same columns from two tables in the query.

I currently add an attribute "tableAlias" in my DAO to the parameter map, which I then use in the sql snippet:

<sql id="inc">
    $tableAlias$name,
    $tableAlias$value,
    $tableAlias$foo,
    $tableAlias$bar
</sql> 

, but this is ugly, since I have to know the table alias in the DAO, while the rest of the SQL is in the XML mapping file.

Another option for getting rid of our hack would be to make it possible to set a property in the mapping file, e.g. before including the sql snippet:

<setProperty name="tableAlias" value="a" />
<include refid="inc" />

How's about that?


> Include with parameter
> ----------------------
>
>          Key: IBATIS-264
>          URL: http://issues.apache.org/jira/browse/IBATIS-264
>      Project: iBatis for Java
>         Type: Improvement
>   Components: SQL Maps
>     Versions: 2.1.7
>     Reporter: Nils Winkler
>     Priority: Minor

>
> I have the following problem: I include the same SQL snippet from
> multiple select statements, some of them for completely unrelated
> tables. This is done because these tables contain quite a few columns
> with the same names in both tables.
> <sql id="inc">
>     name,
>     value,
>     foo,
>     bar
> </sql>
> <select id="loadA">
>     select id,
>     <include refid="inc" />
>     from A
> </select>
> <select id="loadB">
>     select id,
>     <include refid="inc" />
>     from B
> </select>
> When including the list of columns, it would be quite handy to add a
> parameter to the include, for example to set a table alias in case I
> have a join between tables:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" />
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> In the above query, "name", "value" etc are no longer unique in the
> query, most of the time you end up with the wrong values.
> It would be great if I would be able to pass in a parameter to the
> include, e.g.:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" param="a."/>
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> so I could have the SQL snippet defined like this:
> <sql id="inc">
>     $param$name,
>     $param$value,
>     $param$foo,
>     $param$bar
> </sql>
> This way, all of the statements would still work and I could make sure
> that the correct columns are used in each case.

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


[jira] Commented: (IBATIS-264) Include with parameter

Posted by "Sven Boden (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-264?page=comments#action_12367175 ] 

Sven Boden commented on IBATIS-264:
-----------------------------------

Currently the sql/include are pretty "static", so it's not really a peanut change. Your proposal takes care of 1 argument, how would you handle multiple arguments?

Personally I don't see a huge benefit in the proposal the way I use includes now:
1) When including columns you can chose your table aliases so you can make sure different queries using the same columns use the same table aliases (in the <select> and in the <sql> snippet). And how many times are you going to have a situation in which you have the same columns in 2 different tables using different aliases.
2) When putting a query starting from the from part in an <sql> include and having different columns in different <select>s but including the same base query I also don't see a huge benefit for arguments.



> Include with parameter
> ----------------------
>
>          Key: IBATIS-264
>          URL: http://issues.apache.org/jira/browse/IBATIS-264
>      Project: iBatis for Java
>         Type: Improvement
>   Components: SQL Maps
>     Versions: 2.1.7
>     Reporter: Nils Winkler
>     Priority: Minor

>
> I have the following problem: I include the same SQL snippet from
> multiple select statements, some of them for completely unrelated
> tables. This is done because these tables contain quite a few columns
> with the same names in both tables.
> <sql id="inc">
>     name,
>     value,
>     foo,
>     bar
> </sql>
> <select id="loadA">
>     select id,
>     <include refid="inc" />
>     from A
> </select>
> <select id="loadB">
>     select id,
>     <include refid="inc" />
>     from B
> </select>
> When including the list of columns, it would be quite handy to add a
> parameter to the include, for example to set a table alias in case I
> have a join between tables:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" />
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> In the above query, "name", "value" etc are no longer unique in the
> query, most of the time you end up with the wrong values.
> It would be great if I would be able to pass in a parameter to the
> include, e.g.:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" param="a."/>
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> so I could have the SQL snippet defined like this:
> <sql id="inc">
>     $param$name,
>     $param$value,
>     $param$foo,
>     $param$bar
> </sql>
> This way, all of the statements would still work and I could make sure
> that the correct columns are used in each case.

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


[jira] Commented: (IBATIS-264) Include with parameter

Posted by "Diego Trombetta (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-264?page=comments#action_12417112 ] 

Diego Trombetta commented on IBATIS-264:
----------------------------------------

I'm facing the same problem.
My use case looks like this: I need to build a tree that represents the Bill of Materials of an item.
Each time that I perform an inquiry to obtain the components of the current item I need also to know
if the components are "final" components (leaves of the tree) or intermedate components (nodes in the tree);
therefore I need to join the table of the components with itself (!) repeating the filter clause on the same
columns but using different aliases.

I don't think this is a minor improvement....

Any news about it?

> Include with parameter
> ----------------------
>
>          Key: IBATIS-264
>          URL: http://issues.apache.org/jira/browse/IBATIS-264
>      Project: iBatis for Java
>         Type: Improvement

>   Components: SQL Maps
>     Versions: 2.1.7
>     Reporter: Nils Winkler
>     Priority: Minor

>
> I have the following problem: I include the same SQL snippet from
> multiple select statements, some of them for completely unrelated
> tables. This is done because these tables contain quite a few columns
> with the same names in both tables.
> <sql id="inc">
>     name,
>     value,
>     foo,
>     bar
> </sql>
> <select id="loadA">
>     select id,
>     <include refid="inc" />
>     from A
> </select>
> <select id="loadB">
>     select id,
>     <include refid="inc" />
>     from B
> </select>
> When including the list of columns, it would be quite handy to add a
> parameter to the include, for example to set a table alias in case I
> have a join between tables:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" />
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> In the above query, "name", "value" etc are no longer unique in the
> query, most of the time you end up with the wrong values.
> It would be great if I would be able to pass in a parameter to the
> include, e.g.:
> <select id="loadA">
>     select a.id, b.id,
>     <include refid="inc" param="a."/>
>     from A a
>     inner join B b on (b.id = a.id)
>     where b.baz = #baz#
> </select>
> so I could have the SQL snippet defined like this:
> <sql id="inc">
>     $param$name,
>     $param$value,
>     $param$foo,
>     $param$bar
> </sql>
> This way, all of the statements would still work and I could make sure
> that the correct columns are used in each case.

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