Quantcast

help: I've got aop in db

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

help: I've got aop in db

marzia
Hi, to all mybatis experts...
I have this 'aop in db' scenario: Pretty sized (from metadata
standpoint) db with over hundred tables and many of those have
following columns:
        created_by int,
        created_on timestamp,
        edited_by int,
        edited_on timestamp,
Is it possible to define 'created' and 'edited' resultMap's and reuse
them all-around inside my project ?
Yes I know, there is possibility to inherit from another resultMap,
but I would like to reuse two or more of them, is it possible ? If
not, how can I wrangle this problem in elegant/maintainable manner ?

P.S. feature-hint: 'extends' attribute of resultMap xml element
accepts comma-separated list of resultMaps as for java interfaces ?

Thank you all in advance
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: help: I've got aop in db

Dridi Boukelmoune
Hi,

Take a look at associations, I think this is what you're looking for.

Dridi

http://www.zenika.com

On Feb 14, 4:58 pm, marzia <[hidden email]> wrote:

> Hi, to all mybatis experts...
> I have this 'aop in db' scenario: Pretty sized (from metadata
> standpoint) db with over hundred tables and many of those have
> following columns:
>         created_by int,
>         created_on timestamp,
>         edited_by int,
>         edited_on timestamp,
> Is it possible to define 'created' and 'edited' resultMap's and reuse
> them all-around inside my project ?
> Yes I know, there is possibility to inherit from another resultMap,
> but I would like to reuse two or more of them, is it possible ? If
> not, how can I wrangle this problem in elegant/maintainable manner ?
>
> P.S. feature-hint: 'extends' attribute of resultMap xml element
> accepts comma-separated list of resultMaps as for java interfaces ?
>
> Thank you all in advance
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: help: I've got aop in db

marzia
Dirdi, thank you, but I am pretty sure that 'association' is not my
cup of tea...
I need multiple inheritance of resultMaps instead of single
inheritance currently present in mybatis...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: help: I've got aop in db

Dridi Boukelmoune
Hi,

On the project I am currently working on, I had the same exact pattern
you just described : those very four columns.
In order not to repeat the columns in each result map, I used an
association.

On the java side I had this (simplified version) :

class EditInfo {
  public String creatredBy;
  public Date creationTime;
  public String editedBy;
  public Date editionTime;
}

class SomeResult {
  public String someProperty;
  public EditInfo editInfo
}

This way I have been able not to repeat any of this across lots of
results on both Java and MyBatis sides.

Are you currently repeating the 4 fields in all your java classes ?

Dridi

http://www.zenika.com/

On Feb 15, 10:08 am, marzia <[hidden email]> wrote:
> Dirdi, thank you, but I am pretty sure that 'association' is not my
> cup of tea...
> I need multiple inheritance of resultMaps instead of single
> inheritance currently present in mybatis...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

how: multiple-inheritance of resultMaps

marzia
I also did what you described in your previous message so java part of
the puzzle is solved, but what about '.xml' part ? In some way I would
like to avoid repeating declarations of those 3-4 properties/columns
in many resultMaps, and that is currently possible with single
inheritance of resultMaps, but in my case I have 3 or more of those
fragments to combine in many resultMaps and what would need is
multiple-inheritance... Is there some way to achieve that ?

Thanks,
Marzia
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how: multiple-inheritance of resultMaps

Dridi Boukelmoune
On the mapper side:
- you define a result map with your four columns
- use the association tag for every result map that needs those
columns

This is inheritance vs composition.
If you can't achieve multiple inheritance you should then consider
using composition...

Dridi

http://www.zenika.com/

On Feb 17, 10:34 am, marzia <[hidden email]> wrote:

> I also did what you described in your previous message so java part of
> the puzzle is solved, but what about '.xml' part ? In some way I would
> like to avoid repeating declarations of those 3-4 properties/columns
> in many resultMaps, and that is currently possible with single
> inheritance of resultMaps, but in my case I have 3 or more of those
> fragments to combine in many resultMaps and what would need is
> multiple-inheritance... Is there some way to achieve that ?
>
> Thanks,
> Marzia
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how: multiple-inheritance of resultMaps

marzia
Hi Dridi, Sorry for the late response but I was 'offline' for a while, but today I tried what you had suggested and voila ;-) it works perfectly...
Thank you for your time and patience...
Loading...