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 Scott Zhu <sc...@gmail.com> on 2005/03/03 21:07:19 UTC
check to see if a statement exists
I post a few question in the last few days. I'm at the final stage of
evaluting iBatis for our application. This is probably one of the last
issues we need to settle now.
We want to support vendor specific queries. Again, it's being defined
at runtime. So the current thought is, we include them in the same
file, say in Item.xml, we have "getItemsByOrderID" query, and late we
decide we need a db2 specific query, we add a "getItemsByOderID_DB2"
query in there. In our DAO code, when the statement is being executed,
we do a two-step lookup. We have knowledge on the database type then,
so we first check to see if there's a $statement_$databaseType
statement in the map, if not, fall back to use just $statement (kind
like how resource look up works). My questions are:
1. I don't know if this is the best/clean way to deal with this kind
of problems.
2. In iBatis, is there a way to check if a given statement exists in
the current map?
Thanks.
Re: check to see if a statement exists
Posted by Scott Zhu <sc...@gmail.com>.
Thanks Brandon. I liked the namespace idea. However, I don't want to
do this on a query base. Basically, I want to do this for all
statement just in case they have a vendor specific query, if not, I
will then use the generic one. So I need a way to do an isExist()
checking.
One solution I found (from someone else' hint) was to do something like this:
String dbSpecifiedStatementName = statementName + "_DB2";
SqlMapExecutorDelegate delegate = ((ExtendedSqlMapClient)sqlMap).getDelegate();
try
{
delegate.getMappedStatement(dbSpecifiedStatementName);
}
catch (SqlMapException sme)
{
// the statement does not exist
}
But I was hoping there's some easy way for this.
On Thu, 3 Mar 2005 14:40:49 -0700, Brandon Goodin
<br...@gmail.com> wrote:
> You could separate your sql files into databae dependent sqlmaps and
> universal sql maps. Then you could pass a database appropriate
> namespace for those that are database specific. Then in you sqlmap
> calls you can substitute a value.
>
> Ex.
>
> customer.xml (for universal sql)
> --------------------------
> <sqlMap namespace="Customer">
> ...
> </sqlMap>
>
> db2_customer.xml (for db specific sql)
> --------------------------
> <sqlMap namespace="DB2_Customer">
> ...
> </sqlMap>
>
> CustomerDaoImpl.java
> --------------------------
>
> ...
> return queryForList(dbSpecificNameSpacePrefix +
> "Customer.getCustomerByPurchaseRatio",null);
> ...
>
> ...
> return queryForList("Customer.getAll",null);
> ...
>
> database_environment.properties
> --------------------------
>
> dbSpecificNameSpacePrefix=DB2_
>
> Hope that helps,
>
> Brandon
>
>
> On Thu, 3 Mar 2005 15:07:19 -0500, Scott Zhu <sc...@gmail.com> wrote:
> > I post a few question in the last few days. I'm at the final stage of
> > evaluting iBatis for our application. This is probably one of the last
> > issues we need to settle now.
> >
> > We want to support vendor specific queries. Again, it's being defined
> > at runtime. So the current thought is, we include them in the same
> > file, say in Item.xml, we have "getItemsByOrderID" query, and late we
> > decide we need a db2 specific query, we add a "getItemsByOderID_DB2"
> > query in there. In our DAO code, when the statement is being executed,
> > we do a two-step lookup. We have knowledge on the database type then,
> > so we first check to see if there's a $statement_$databaseType
> > statement in the map, if not, fall back to use just $statement (kind
> > like how resource look up works). My questions are:
> >
> > 1. I don't know if this is the best/clean way to deal with this kind
> > of problems.
> > 2. In iBatis, is there a way to check if a given statement exists in
> > the current map?
> >
> > Thanks.
> >
>
Re: check to see if a statement exists
Posted by Brandon Goodin <br...@gmail.com>.
You could separate your sql files into databae dependent sqlmaps and
universal sql maps. Then you could pass a database appropriate
namespace for those that are database specific. Then in you sqlmap
calls you can substitute a value.
Ex.
customer.xml (for universal sql)
--------------------------
<sqlMap namespace="Customer">
...
</sqlMap>
db2_customer.xml (for db specific sql)
--------------------------
<sqlMap namespace="DB2_Customer">
...
</sqlMap>
CustomerDaoImpl.java
--------------------------
...
return queryForList(dbSpecificNameSpacePrefix +
"Customer.getCustomerByPurchaseRatio",null);
...
...
return queryForList("Customer.getAll",null);
...
database_environment.properties
--------------------------
dbSpecificNameSpacePrefix=DB2_
Hope that helps,
Brandon
On Thu, 3 Mar 2005 15:07:19 -0500, Scott Zhu <sc...@gmail.com> wrote:
> I post a few question in the last few days. I'm at the final stage of
> evaluting iBatis for our application. This is probably one of the last
> issues we need to settle now.
>
> We want to support vendor specific queries. Again, it's being defined
> at runtime. So the current thought is, we include them in the same
> file, say in Item.xml, we have "getItemsByOrderID" query, and late we
> decide we need a db2 specific query, we add a "getItemsByOderID_DB2"
> query in there. In our DAO code, when the statement is being executed,
> we do a two-step lookup. We have knowledge on the database type then,
> so we first check to see if there's a $statement_$databaseType
> statement in the map, if not, fall back to use just $statement (kind
> like how resource look up works). My questions are:
>
> 1. I don't know if this is the best/clean way to deal with this kind
> of problems.
> 2. In iBatis, is there a way to check if a given statement exists in
> the current map?
>
> Thanks.
>