You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Davide Rogora <dr...@unionefiduciaria.it> on 2006/03/23 12:16:36 UTC

Pattern for multiple database

Hi all,
my company is starting a new data-centric application that should be
database-indipendent (e.g. work with MySql, Oracle, SQL-Server, DB2 ecc.).
We don't want to use Hibernate because we used it in the past e we dont'
like it.
I've found iBATIS, read the documentation and I like it because it's a very
practical and flexible framework!

Now I need to understand how implement the database-independent
requirement...
I think that some sqlMap files could be in common (for example if the SQL
used in them is compatible with all the databases) and some other sqlMap
files could be specific of a single database.

The perfect for us is if we could put all the sqlMap files (commons and
database-specific) in the project, an then have a flag  that switch all the
application to use the correct sqlMap files for the underlined database.

Is there a pattern to achieve it?

Thanks in advance (and sorry for my english)
Davide.





Re: Pattern for multiple database

Posted by j-lists <ja...@gmail.com>.
A clever use of <sql id="foo"></sql> and <include refid="foo"/> where the
<sql> is in the ${dialect} file will give some pretty reasonable flexability
without the need to exploit any bugs. I have recently posted a JIRA feature
request precisely to help address key generation aspect of the cross-DB
compatability issue more easily using properties instead or replacing entire
statements:
http://issues.apache.org/jira/browse/IBATIS-277

-J

PS: I was pleased to have another closely related issue was addressed in
record time:
http://issues.apache.org/jira/browse/IBATIS-195
Thanks Clinton!

R: Pattern for multiple database

Posted by Davide Rogora <dr...@unionefiduciaria.it>.
Larry,
thank you very much for your reply.

I don't remember if  it's possible to load a SQL map xml files at runtime.
If yes, we could leave the sqlMapConfig file empty (with non sqlMap tags)
and then load the sqlMap files at runtime, looking before in the "dialect"
folder; if it's not present looking in the "common" folder.

Davide.

  -----Messaggio originale-----
  Da: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com]Per conto di
Larry Meadors
  Inviato: giovedì 23 marzo 2006 16.20
  A: user-java@ibatis.apache.org
  Oggetto: Re: Pattern for multiple database


  I would try a structure like this:

  Set up your SqlMapConfig.xml file to load a properties file, and in that
properties file specify the database dialect (i.e., dialect=mysql, or
dialect=oracle, etc...).

  Then, you can load the common sqlmaps from a common location, and the
dialect specific ones using that dialect as part of the resource path:

  <sqlMap resource="com/elm/system/dao/sqlmap/common/Employees.xml" />
  <sqlMap resource="com/elm/system/dao/sqlmap/${dialect}/Employees.xml" />

  Currently, I think there is a bug that will replace mapped statements that
are in common with any that are redefined in ${dialect} *IF THEY ARE IN THE
ORDER ABOVE*. Be warned that this behavior is considered a bug and may not
work in future releases.

  You may have to mess with it a bit, but I think it will work for you.

  When (and if) we fix that bug (and it may not be until iBATIS3 is real)
you may have to change your strategy a bit to use the fixed release - we
have talked about this functionality before, but have not had enough people
who needed it to address it. If we do fix it, we will most likely make a way
to define which mapped statement to use when there are duplicates.

  Larry



  On 3/23/06, Davide Rogora <dr...@unionefiduciaria.it> wrote:
    Hi all,
    my company is starting a new data-centric application that should be
database-indipendent (e.g. work with MySql, Oracle, SQL-Server, DB2 ecc.).
    We don't want to use Hibernate because we used it in the past e we dont'
like it.
    I've found iBATIS, read the documentation and I like it because it's a
very practical and flexible framework!

    Now I need to understand how implement the database-independent
requirement...
    I think that some sqlMap files could be in common (for example if the
SQL used in them is compatible with all the databases) and some other sqlMap
files could be specific of a single database.

    The perfect for us is if we could put all the sqlMap files (commons and
database-specific) in the project, an then have a flag  that switch all the
application to use the correct sqlMap files for the underlined database.

    Is there a pattern to achieve it?

    Thanks in advance (and sorry for my english)
    Davide.







Re: Pattern for multiple database

Posted by Larry Meadors <lm...@apache.org>.
I would try a structure like this:

Set up your SqlMapConfig.xml file to load a properties file, and in that
properties file specify the database dialect (i.e., dialect=mysql, or
dialect=oracle, etc...).

Then, you can load the common sqlmaps from a common location, and the
dialect specific ones using that dialect as part of the resource path:

<sqlMap resource="com/elm/system/dao/sqlmap/common/Employees.xml" />
<sqlMap resource="com/elm/system/dao/sqlmap/${dialect}/Employees.xml" />

Currently, I think there is a bug that will replace mapped statements that
are in common with any that are redefined in ${dialect} *IF THEY ARE IN THE
ORDER ABOVE*. Be warned that this behavior is considered a bug and may not
work in future releases.

You may have to mess with it a bit, but I think it will work for you.

When (and if) we fix that bug (and it may not be until iBATIS3 is real) you
may have to change your strategy a bit to use the fixed release - we have
talked about this functionality before, but have not had enough people who
needed it to address it. If we do fix it, we will most likely make a way to
define which mapped statement to use when there are duplicates.

Larry


On 3/23/06, Davide Rogora <dr...@unionefiduciaria.it> wrote:
>
> Hi all,
> my company is starting a new data-centric application that should be
> database-indipendent (e.g. work with MySql, Oracle, SQL-Server, DB2 ecc.).
> We don't want to use Hibernate because we used it in the past e we dont'
> like it.
> I've found iBATIS, read the documentation and I like it because it's a
> very practical and flexible framework!
>
> Now I need to understand how implement the database-independent
> requirement...
> I think that some sqlMap files could be in common (for example if the SQL
> used in them is compatible with all the databases) and some other sqlMap
> files could be specific of a single database.
>
> The perfect for us is if we could put all the sqlMap files (commons and
> database-specific) in the project, an then have a flag  that switch all the
> application to use the correct sqlMap files for the underlined database.
>
> Is there a pattern to achieve it?
>
> Thanks in advance (and sorry for my english)
> Davide.
>
>
>
>
>
>