feature request: column prefix in association

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

feature request: column prefix in association

Paweł P.
My idea is to add parameter "column-prefix" to association tag.
Value of this param should be added to each column element in
resultMap pointed in association.

Thanks to it, we could resolve problem of two associations to object
of the same class (eg person with two fixed addresses).
Now we need to create almost identical resultMaps. There is only one
difference between them: column names.

Best regards
Paweł
Reply | Threaded
Open this post in threaded view
|

Re: feature request: column prefix in association

asherwin
I agree.

Another alternative would be to specify the table alias (e.g.
Currency1 vs Currency2) and just alias the selects, would be even
better if you could re-use a result map and specify its table alias
inline each time you include it

On Sep 28, 3:26 am, Paweł P. <[hidden email]> wrote:

> My idea is to add parameter "column-prefix" to association tag.
> Value of this param should be added to each column element in
> resultMap pointed in association.
>
> Thanks to it, we could resolve problem of two associations to object
> of the same class (eg person with two fixed addresses).
> Now we need to create almost identical resultMaps. There is only one
> difference between them: column names.
>
> Best regards
> Paweł
Reply | Threaded
Open this post in threaded view
|

Re: feature request: column prefix in association

Clinton Begin
Administrator
This is a good suggestion.  Can one of you create an issue in the tracker?

On 2010-09-28, asherwin <[hidden email]> wrote:

> I agree.
>
> Another alternative would be to specify the table alias (e.g.
> Currency1 vs Currency2) and just alias the selects, would be even
> better if you could re-use a result map and specify its table alias
> inline each time you include it
>
> On Sep 28, 3:26 am, Paweł P. <[hidden email]> wrote:
>> My idea is to add parameter "column-prefix" to association tag.
>> Value of this param should be added to each column element in
>> resultMap pointed in association.
>>
>> Thanks to it, we could resolve problem of two associations to object
>> of the same class (eg person with two fixed addresses).
>> Now we need to create almost identical resultMaps. There is only one
>> difference between them: column names.
>>
>> Best regards
>> Paweł

--
Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: feature request: column prefix in association

Paweł P.
I wasn't sure about "asherwin" concept so I added only my idea.
Issue link: http://code.google.com/p/mybatis/issues/detail?id=123


> This is a good suggestion.  Can one of you create an issue in the tracker?
>
> On 2010-09-28, asherwin <[hidden email]> wrote:
>
>
>
> > I agree.
>
> > Another alternative would be to specify the table alias (e.g.
> > Currency1 vs Currency2) and just alias the selects, would be even
> > better if you could re-use a result map and specify its table alias
> > inline each time you include it
>
> > On Sep 28, 3:26 am, Paweł P. <[hidden email]> wrote:
> >> My idea is to add parameter "column-prefix" to association tag.
> >> Value of this param should be added to each column element in
> >> resultMap pointed in association.
>
> >> Thanks to it, we could resolve problem of two associations to object
> >> of the same class (eg person with two fixed addresses).
> >> Now we need to create almost identical resultMaps. There is only one
> >> difference between them: column names.
>
> >> Best regards
> >> Paweł
>
> --
> Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: feature request: column prefix in association

asherwin
The reason for my suggestion is...  If you use a column prefix, your
queries look like this:

select
  a_col1, a_col2, a_col3, a_col4,
  b_col1, b_col2, b_col3, b_col4,
  c_col1, c_col2, c_col3, c_col4
  ... etc for many joins

left outer join b on a.x=b.x
left outer join c on b.x=c.x

from a

Which requires maintenance of both the SQL and the ResultMap to have
matching column models

While specifying a table alias, you can simplify the SQL:

select
  a.*, b.*, c.*
  ... etc for many joins

left outer join btable as b on a.x=b.x
left outer join ctable as c on b.x=c.x

from atable as a

And now you write the ResultMap once and just specify the alias,
making it about half the effort to maintain

For the way we're using iBATIS in our custom ORM layer, this would be
MUCH more efficient the the current paradigm, or individual aliasing
of columns.. we often do deep selects up to 12 tables deep and
populate object graphs with that data

On Sep 28, 11:23 am, Paweł P. <[hidden email]> wrote:

> I wasn't sure about "asherwin" concept so I added only my idea.
> Issue link:http://code.google.com/p/mybatis/issues/detail?id=123
>
>
>
> > This is a good suggestion.  Can one of you create an issue in the tracker?
>
> > On 2010-09-28, asherwin <[hidden email]> wrote:
>
> > > I agree.
>
> > > Another alternative would be to specify the table alias (e.g.
> > > Currency1 vs Currency2) and just alias the selects, would be even
> > > better if you could re-use a result map and specify its table alias
> > > inline each time you include it
>
> > > On Sep 28, 3:26 am, Paweł P. <[hidden email]> wrote:
> > >> My idea is to add parameter "column-prefix" to association tag.
> > >> Value of this param should be added to each column element in
> > >> resultMap pointed in association.
>
> > >> Thanks to it, we could resolve problem of two associations to object
> > >> of the same class (eg person with two fixed addresses).
> > >> Now we need to create almost identical resultMaps. There is only one
> > >> difference between them: column names.
>
> > >> Best regards
> > >> Paweł
>
> > --
> > Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: feature request: column prefix in association

Paweł P.
Maybe I'm wrong, but I see one problem.
Ibatis use resultMap on query result (resultSet) to match columns to
object properties.
I think it is not possible to use (retrieve) aliases on this.
In resultset you have columns and their names (each name you can
assign using "as" phrase in your sql query).

If I'm wrong maybe try to write full example to clear it.

Paweł

> The reason for my suggestion is...  If you use a column prefix, your
> queries look like this:
>
> select
>   a_col1, a_col2, a_col3, a_col4,
>   b_col1, b_col2, b_col3, b_col4,
>   c_col1, c_col2, c_col3, c_col4
>   ... etc for many joins
>
> left outer join b on a.x=b.x
> left outer join c on b.x=c.x
>
> from a
>
> Which requires maintenance of both the SQL and the ResultMap to have
> matching column models
>
> While specifying a table alias, you can simplify the SQL:
>
> select
>   a.*, b.*, c.*
>   ... etc for many joins
>
> left outer join btable as b on a.x=b.x
> left outer join ctable as c on b.x=c.x
>
> from atable as a
>
> And now you write the ResultMap once and just specify the alias,
> making it about half the effort to maintain
>
> For the way we're using iBATIS in our custom ORM layer, this would be
> MUCH more efficient the the current paradigm, or individual aliasing
> of columns.. we often do deep selects up to 12 tables deep and
> populate object graphs with that data
>
> On Sep 28, 11:23 am, Paweł P. <[hidden email]> wrote:
>
> > I wasn't sure about "asherwin" concept so I added only my idea.
> > Issue link:http://code.google.com/p/mybatis/issues/detail?id=123
>
> > > This is a good suggestion.  Can one of you create an issue in the tracker?
>
> > > On 2010-09-28, asherwin <[hidden email]> wrote:
>
> > > > I agree.
>
> > > > Another alternative would be to specify the table alias (e.g.
> > > > Currency1 vs Currency2) and just alias the selects, would be even
> > > > better if you could re-use a result map and specify its table alias
> > > > inline each time you include it
>
> > > > On Sep 28, 3:26 am, Paweł P. <[hidden email]> wrote:
> > > >> My idea is to add parameter "column-prefix" to association tag.
> > > >> Value of this param should be added to each column element in
> > > >> resultMap pointed in association.
>
> > > >> Thanks to it, we could resolve problem of two associations to object
> > > >> of the same class (eg person with two fixed addresses).
> > > >> Now we need to create almost identical resultMaps. There is only one
> > > >> difference between them: column names.
>
> > > >> Best regards
> > > >> Paweł
>
> > > --
> > > Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: feature request: column prefix in association

Paweł P.
I think I eventually understood your idea :)
Correct me if not.
You want to prevent of copy-paste parts of your sql's.
So it could look like this:

<sql id="selectFragment">
    #{alias}.address.street as #{alias}_street,
    #{alias}.address.city    as #{alias}_city
</sql>

<select id="person" resultMap="xxx">
    SELECT
                   person.id,
                   person.name,
                   <include refid="selectFragment"
alias="forwardaddress">
                   <include refid="selectFragment"
alias="standingaddress">
    FROM .....
    JOIN forwardaddress .....
    JOIN standingaddress .....
</select>

Then as a next step you could use "my" column_prefix to eliminate copy-
paste of mapping.
Of course "#{alias}" in sql fragment could be automaticly added.
Maybe to avoid too long column names (eg Oracle) we should add
"shortAlias" parameter, then it could look like this:
...
<include refid="selectFragment" alias="f">
....
<sql id="selectFragment">
    #{alias}.address.street as #{shortAlias}_street,
    #{alias}.address.city    as #{shortAlias}_city
</sql>


Best regards
Paweł

> Maybe I'm wrong, but I see one problem.
> Ibatis use resultMap on query result (resultSet) to match columns to
> object properties.
> I think it is not possible to use (retrieve) aliases on this.
> In resultset you have columns and their names (each name you can
> assign using "as" phrase in your sql query).
>
> If I'm wrong maybe try to write full example to clear it.
>
> Paweł
>
> > The reason for my suggestion is...  If you use a column prefix, your
> > queries look like this:
>
> > select
> >   a_col1, a_col2, a_col3, a_col4,
> >   b_col1, b_col2, b_col3, b_col4,
> >   c_col1, c_col2, c_col3, c_col4
> >   ... etc for many joins
>
> > left outer join b on a.x=b.x
> > left outer join c on b.x=c.x
>
> > from a
>
> > Which requires maintenance of both the SQL and the ResultMap to have
> > matching column models
>
> > While specifying a table alias, you can simplify the SQL:
>
> > select
> >   a.*, b.*, c.*
> >   ... etc for many joins
>
> > left outer join btable as b on a.x=b.x
> > left outer join ctable as c on b.x=c.x
>
> > from atable as a
>
> > And now you write the ResultMap once and just specify the alias,
> > making it about half the effort to maintain
>
> > For the way we're using iBATIS in our custom ORM layer, this would be
> > MUCH more efficient the the current paradigm, or individual aliasing
> > of columns.. we often do deep selects up to 12 tables deep and
> > populate object graphs with that data
>
> > On Sep 28, 11:23 am, Paweł P. <[hidden email]> wrote:
>
> > > I wasn't sure about "asherwin" concept so I added only my idea.
> > > Issue link:http://code.google.com/p/mybatis/issues/detail?id=123
>
> > > > This is a good suggestion.  Can one of you create an issue in the tracker?
>
> > > > On 2010-09-28, asherwin <[hidden email]> wrote:
>
> > > > > I agree.
>
> > > > > Another alternative would be to specify the table alias (e.g.
> > > > > Currency1 vs Currency2) and just alias the selects, would be even
> > > > > better if you could re-use a result map and specify its table alias
> > > > > inline each time you include it
>
> > > > > On Sep 28, 3:26 am, Paweł P. <[hidden email]> wrote:
> > > > >> My idea is to add parameter "column-prefix" to association tag.
> > > > >> Value of this param should be added to each column element in
> > > > >> resultMap pointed in association.
>
> > > > >> Thanks to it, we could resolve problem of two associations to object
> > > > >> of the same class (eg person with two fixed addresses).
> > > > >> Now we need to create almost identical resultMaps. There is only one
> > > > >> difference between them: column names.
>
> > > > >> Best regards
> > > > >> Paweł
>
> > > > --
> > > > Sent from my mobile device