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 "Hemant.Kamatgi" <He...@target.com> on 2007/10/12 19:46:55 UTC

how tp pass schema name in a query

Hello,

We are using iBATIS in our project and have different schema(database schema) in each of our environments (dev,test etc). However, we don't have public synonyms created and hence we have to add the schema name to the entity while querying it. Now, we are maintaining different map files for each environment (we are changing the schema name appropriate for that environment but everything else is the same). Is there a way where I can pass the schema name from out side as a parameter so that we can maintain only one map file I mean, say for a query ,  'select * from <schema>.employee' where <schema> is a place holder for a value that can be configured.

Please reply,

Regards
Hemant




RE: how tp pass schema name in a query

Posted by "Hemant.Kamatgi" <He...@target.com>.
Thanks indeed!

-----Original Message-----
From: Ole Trenner [mailto:ole.trenner@googlemail.com]
Sent: Friday, October 12, 2007 1:24 PM
To: user-java@ibatis.apache.org
Subject: Re: how tp pass schema name in a query

Hemant.Kamatgi wrote:
> Is there a way
> where I can pass the schema name from out side as a parameter so that we
> can maintain only one map file I mean, say for a query ,  'select * from
> <schema>.employee' where <schema> is a place holder for a value that can
> be configured.


In fact there is. In your sqlmap-config.xml you can define a properties
file:

<properties resource="sqlmapconfig.properties" />


sqlmapconfig.properties looks like this:

schema1=foo
schema2=bar


Then you can use named properties everywhere in your sql mappings:

<select id="sampleSelect" parameterClass="..." resultClass="...">
    select * from ${schema1}.tablename
</select>


Cheers,
Ole.

Re: how tp pass schema name in a query

Posted by Ole Trenner <ol...@googlemail.com>.
Hemant.Kamatgi wrote:
> Is there a way
> where I can pass the schema name from out side as a parameter so that we
> can maintain only one map file I mean, say for a query ,  ‘select * from
> <schema>.employee’ where <schema> is a place holder for a value that can
> be configured.


In fact there is. In your sqlmap-config.xml you can define a properties
file:

<properties resource="sqlmapconfig.properties" />


sqlmapconfig.properties looks like this:

schema1=foo
schema2=bar


Then you can use named properties everywhere in your sql mappings:

<select id="sampleSelect" parameterClass="..." resultClass="...">
    select * from ${schema1}.tablename
</select>


Cheers,
Ole.