iBatis API for fetching the sqlmap queries

View: New views
9 Messages — Rating Filter:   Alert me  

iBatis API for fetching the sqlmap queries

by Mahesh219 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, We are using iBatis 3 with Spring. We wish to provide our DAOs with both, Spring's JdbcTemplate and iBatis SqlMapClientTemplate facilities. Does iBatis provide a way to fetch the queries defined in one of the xmls using the id attribute programmatically? Any help is highly appreciated. Regards, Mahesh

Re: iBatis API for fetching the sqlmap queries

by Clinton Begin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, you can introspect on the full iBATIS configuration at runtime by grabbing the Configuration instance from the SqlSessionFactory.  It has lists and maps of various configuration components.

Clinton

On Sun, Nov 1, 2009 at 10:07 PM, Mahesh219 <maheshforjava@...> wrote:
Hi, We are using iBatis 3 with Spring. We wish to provide our DAOs with both, Spring's JdbcTemplate and iBatis SqlMapClientTemplate facilities. Does iBatis provide a way to fetch the queries defined in one of the xmls using the id attribute programmatically? Any help is highly appreciated. Regards, Mahesh

View this message in context: iBatis API for fetching the sqlmap queries
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


ibatis 3 petstore

by a b-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there a sample application written in ibatis 3 and spring such as petstore?

thanks


     

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...


ibatis 3 COUNT -> Boolean

by dbell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to do the following using beta 5 (this was working in beta 3)

@Select("SELECT COUNT(username) FROM record WHERE username =
#{username,jdbcType=VARCHAR}")
Boolean isExisting(String username);

I get a ClassCastException: java.lang.Long cannot be cast to
java.lang.Boolean which is understandable.

I thought adding a @Result(javaType = Boolean.class) would do it but I
still get the same error. Can I do anything short of changing the return
type to a Long and doing the conversion?

Thanks

-Doug

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...


Parent Message unknown Re: ibatis 3 COUNT -> Boolean

by jhking :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not sure about the iBatis piece, but that doesn't make sense as sql.
Count returns a number.  That number might be 0 or any other non-negative integer.
AFAIK java doesn't do the 0 = false, non-zero = true conversion you have in C/C++.

--- DBell@... wrote:

From: "Douglas Bell" <DBell@...>
To: <user-java@...>
Subject: ibatis 3 COUNT -> Boolean
Date: Wed, 4 Nov 2009 10:42:29 -0800

I'm trying to do the following using beta 5 (this was working in beta 3)

@Select("SELECT COUNT(username) FROM record WHERE username =
#{username,jdbcType=VARCHAR}")
Boolean isExisting(String username);

I get a ClassCastException: java.lang.Long cannot be cast to
java.lang.Boolean which is understandable.

I thought adding a @Result(javaType = Boolean.class) would do it but I
still get the same error. Can I do anything short of changing the return
type to a Long and doing the conversion?

Thanks

-Doug

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...




---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...


Re: ibatis 3 COUNT -> Boolean

by Johannes Klose-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You could just modify the query to return a boolean value to avoid  
conversion issues. For example:
        SELECT IF(COUNT(username)>0,true,false) FROM record WHERE ...


Am 04.11.2009, 19:42 Uhr, schrieb Douglas Bell <DBell@...>:

> I'm trying to do the following using beta 5 (this was working in beta 3)
>
> @Select("SELECT COUNT(username) FROM record WHERE username =
> #{username,jdbcType=VARCHAR}")
> Boolean isExisting(String username);
>
> I get a ClassCastException: java.lang.Long cannot be cast to
> java.lang.Boolean which is understandable.
>
> I thought adding a @Result(javaType = Boolean.class) would do it but I
> still get the same error. Can I do anything short of changing the return
> type to a Long and doing the conversion?
>
> Thanks
>
> -Doug
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@...
> For additional commands, e-mail: user-java-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...


Parent Message unknown Re: ibatis 3 COUNT -> Boolean

by jhking :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That may depend on the database.  In Oracle boolean is not a datatype so that wouldn't work.
WMMV.

--- lists@... wrote:

From: "Johannes Klose" <lists@...>
To: user-java@...
Subject: Re: ibatis 3 COUNT -> Boolean
Date: Wed, 04 Nov 2009 20:43:42 +0100

You could just modify the query to return a boolean value to avoid  
conversion issues. For example:
        SELECT IF(COUNT(username)>0,true,false) FROM record WHERE ...


Am 04.11.2009, 19:42 Uhr, schrieb Douglas Bell <DBell@...>:

> I'm trying to do the following using beta 5 (this was working in beta 3)
>
> @Select("SELECT COUNT(username) FROM record WHERE username =
> #{username,jdbcType=VARCHAR}")
> Boolean isExisting(String username);
>
> I get a ClassCastException: java.lang.Long cannot be cast to
> java.lang.Boolean which is understandable.
>
> I thought adding a @Result(javaType = Boolean.class) would do it but I
> still get the same error. Can I do anything short of changing the return
> type to a Long and doing the conversion?
>
> Thanks
>
> -Doug
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@...
> For additional commands, e-mail: user-java-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...




---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...


Re: ibatis 3 COUNT -> Boolean

by nmaves :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

here is the java doc for how the resultset implementation should handle this.  As long as your query will only return 0/1 you should be okay.  If not, then I would just wrap the count() in an if and return a 1 if count was more than 1.

I would also set both the jdbc type and the return type.  jdbcType to NUMBER and Boolean for the Result.

Nathan


getBoolean

boolean getBoolean(int columnIndex)
                   throws SQLException
Retrieves the value of the designated column in the current row of this ResultSet object as a boolean in the Java programming language.

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 0, a value of false is returned. If the designated column has a datatype of CHAR or VARCHAR and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT and contains a 1, a value of true is returned.



On Wed, Nov 4, 2009 at 12:42 PM, Douglas Bell <DBell@...> wrote:
I'm trying to do the following using beta 5 (this was working in beta 3)

@Select("SELECT COUNT(username) FROM record WHERE username =
#{username,jdbcType=VARCHAR}")
Boolean isExisting(String username);

I get a ClassCastException: java.lang.Long cannot be cast to
java.lang.Boolean which is understandable.

I thought adding a @Result(javaType = Boolean.class) would do it but I
still get the same error. Can I do anything short of changing the return
type to a Long and doing the conversion?

Thanks

-Doug

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...



Re: ibatis 3 petstore

by nmaves :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I started on one but got pulled away with real life :)  Guess I need a vacation to get some free time to code :)  Man that sounds like hell.

On Wed, Nov 4, 2009 at 11:45 AM, a b <eodnohj@...> wrote:
Is there a sample application written in ibatis 3 and spring such as petstore?

thanks




---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@...
For additional commands, e-mail: user-java-help@...