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 Julio Faerman <jf...@gmail.com> on 2008/06/18 17:25:01 UTC

Check if query exists before executing

Hello,

I would like to know if is it possible to check if a query exists
before executing it.
For example, if i am using oracle and have a optimezed query for
oracle, i would like to run:

sqlMapClient.queryForList("myQuery.oracle");

if there is no special query for oracle, i would like to run just the
standard query:

sqlMapClient.queryForList("myQuery");

is it possible to do something like "sqlMapClient.exists/contais(query)" ?

Thank you,
Julio

Re: Check if query exists before executing

Posted by Gwyn Evans <gw...@gmail.com>.
Only way I know of would be to try then catch the resulting SqlMapException
- Just a shame that it's not a specific exception rather than the general
one...

/Gwyn

On Wed, Jun 18, 2008 at 4:25 PM, Julio Faerman <jf...@gmail.com> wrote:

> Hello,
>
> I would like to know if is it possible to check if a query exists
> before executing it.
> For example, if i am using oracle and have a optimezed query for
> oracle, i would like to run:
>
> sqlMapClient.queryForList("myQuery.oracle");
>
> if there is no special query for oracle, i would like to run just the
> standard query:
>
> sqlMapClient.queryForList("myQuery");
>
> is it possible to do something like "sqlMapClient.exists/contais(query)" ?
>
> Thank you,
> Julio
>

Re: Check if query exists before executing

Posted by Julio Faerman <jf...@gmail.com>.
Dedecting de database is fine... the probem is checking if the query
is mapped before running it.
The problem with catching the exception is that in case of and
update/delete query, it may have consequences (partial updates or at
least a rollback). I really needed to check.

On Wed, Jun 18, 2008 at 1:23 PM, Christopher Lamey
<cl...@localmatters.com> wrote:
> You could look at the database metadata through the Connection:
>
>    sqlMapClient.getCurrentConnection().getMetaData().getDatabaseXXX()
>
> And then use that to call either the Oracle or generic sql.
>
> I personally wouldn't go that route because Oracle might change their
> metadata so it'd break your code.
>
> I'd probably go with some kind of application config that's defined along
> with the DataSource (JNDI, Spring, properties file, whatever):
>
> database.vendor=Oracle
>
> And then specifically look for that in my code.
>
> On 6/18/08 9:25 AM, "Julio Faerman" <jf...@gmail.com> wrote:
>
>> Hello,
>>
>> I would like to know if is it possible to check if a query exists
>> before executing it.
>> For example, if i am using oracle and have a optimezed query for
>> oracle, i would like to run:
>>
>> sqlMapClient.queryForList("myQuery.oracle");
>>
>> if there is no special query for oracle, i would like to run just the
>> standard query:
>>
>> sqlMapClient.queryForList("myQuery");
>>
>> is it possible to do something like "sqlMapClient.exists/contais(query)" ?
>>
>> Thank you,
>> Julio
>
>

Re: Check if query exists before executing

Posted by Christopher Lamey <cl...@localmatters.com>.
You could look at the database metadata through the Connection:

    sqlMapClient.getCurrentConnection().getMetaData().getDatabaseXXX()

And then use that to call either the Oracle or generic sql.

I personally wouldn't go that route because Oracle might change their
metadata so it'd break your code.

I'd probably go with some kind of application config that's defined along
with the DataSource (JNDI, Spring, properties file, whatever):

database.vendor=Oracle

And then specifically look for that in my code.

On 6/18/08 9:25 AM, "Julio Faerman" <jf...@gmail.com> wrote:

> Hello,
> 
> I would like to know if is it possible to check if a query exists
> before executing it.
> For example, if i am using oracle and have a optimezed query for
> oracle, i would like to run:
> 
> sqlMapClient.queryForList("myQuery.oracle");
> 
> if there is no special query for oracle, i would like to run just the
> standard query:
> 
> sqlMapClient.queryForList("myQuery");
> 
> is it possible to do something like "sqlMapClient.exists/contais(query)" ?
> 
> Thank you,
> Julio