ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: checking that a statement exists
Date Wed, 09 Aug 2006 16:27:42 GMT
Hmm, I am sitting here reading this wondering why?

If the statement doesn't exist, you want to throw an exception before
one gets thrown by the sqlmap client?

Oh well. ;-)

Yes, you can do that..the sqlmap client is an interface that is
implemented by the SqlMapClientImpl class. That class has a public
member named delegate that is an instance of the
SqlMapExecutorDelegate class, which has a getMappedStatement(String
id) method. Calling that method will either return a mapped statement
or throw a SqlMapException telling you that it does not exist.

You can also get an Iterator of all of the mapped statements by
calling the getMappedStatementNames() method and then look in it (or
add the names to a Set or Map that you could query later). I think
this is what I'd do, then

Have fun. ;-)

Larry


On 8/9/06, Reuben Firmin <Reuben.Firmin@copart.com> wrote:
>
>
> Hello, is there any way to ask the SqlMapClient object whether a given
> statement exists?
>
> I am thinking of a pattern like this:
>
> enum StatementName
> {
>       GET_FOO("getFoo");
>       GET_BAH("getBah");
> }
>
> ...
>
> sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
> for (StatementName statement: StatementName.values())
> {
>      if (!sqlMap.statementExists(statement))
>      {
>          throw ProgrammerErrorException(....)
>      }
> }
>
> ...
>
> sqlMap.queryForList(StatementName.GET_FOO, ...)
>
> Thanks
> Reuben

Mime
View raw message