Simple Result Handler implementation problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple Result Handler implementation problem

konbonwa
Hi all,

I am coming from iBATIS 2.3 and I'm trying to get a simple batch
result handler implmentation to work with Java bean that previously
worked in ibatis 2.3 (FtpEndpoint below).

Here's my simple as possible result handler implementation:

<code>
// imports omitted..
public class TestResultHandler implements ResultHandler {

    @Override
        public void handleResult( ResultContext rc ) {

        FtpEndpoint ife = (FtpEndpoint) rc.getResultObject();
        System.out.println( "[ResultObject] ==> " + ife );

    }

}
<code/>

I then set this result handler up in my test main method in another
class as so:

<code>
public static void main(String[] args) throws IOException {
..
SqlSessionFactory iFactory =
     new
SqlSessionFactoryBuilder().build( Resources.getResourceAsReader(
           "com/boeing/siai/ibatis3/test/map/
InputFtpEndpointSqlMapConfig.xml" ) );

iSession = iFactory.openSession();
..

..
TestResultHandler trh = new TestResultHandler();
System.out.println( "==> Constructed TestResultHandler, calling
iSession.select()" );
iSession.select( "InputFtpEndpoint.findAllFtpEndpoints", null, trh );
..
// No printed output from my result handler here.
..

<code/>

I have tested my named select statement above
(InputFtpEndpoint.findAllFtpEndpoints)  using selectList() and I am
able to get all the rows in my table into a list and print them out.
So, I know the query works and my config files work.

But, there is no printed output from my result handler using the same
query and schema. What am I doing wrong?

TIA,

john
Reply | Threaded
Open this post in threaded view
|

Re: Simple Result Handler implementation problem

konbonwa
I managed to figure out how to get my ResultHandler to run, but I
still don't know why it does.

In my previous post below, I omitted the fact that I call the same
SqlSession with a selectList() call before I do a select() with my
Result Handler because it did not seem like that would affect any
subsequent database accesses.

But this weekend, on a hunch, I commented out my selectList() call and
just ran the select() with my ResultHandler by itself, which then did
work and did print out all the database rows matched by my query.

That surprised me. Now I want to know, why did my previous
selectList() call interfere with my later select() call with a
ResultHandler???

Is there some kind of caching going on that I need to know about?

Thanks,

~ john

On Oct 8, 3:24 pm, konbonwa <[hidden email]> wrote:

> Hi all,
>
> I am coming from iBATIS 2.3 and I'm trying to get a simple batch
> result handler implmentation to work with Java bean that previously
> worked in ibatis 2.3 (FtpEndpoint below).
>
> Here's my simple as possible result handler implementation:
>
> <code>
> // imports omitted..
> public class TestResultHandler implements ResultHandler {
>
>     @Override
>         public void handleResult( ResultContext rc ) {
>
>         FtpEndpoint ife = (FtpEndpoint) rc.getResultObject();
>         System.out.println( "[ResultObject] ==> " + ife );
>
>     }
>
> }
>
> <code/>
>
> I then set this result handler up in my test main method in another
> class as so:
>
> <code>
> public static void main(String[] args) throws IOException {
> ..
> SqlSessionFactory iFactory =
>      new
> SqlSessionFactoryBuilder().build( Resources.getResourceAsReader(
>            "com/boeing/siai/ibatis3/test/map/
> InputFtpEndpointSqlMapConfig.xml" ) );
>
> iSession = iFactory.openSession();
> ..
>
> ..
> TestResultHandler trh = new TestResultHandler();
> System.out.println( "==> Constructed TestResultHandler, calling
> iSession.select()" );
> iSession.select( "InputFtpEndpoint.findAllFtpEndpoints", null, trh );
> ..
> // No printed output from my result handler here.
> ..
>
> <code/>
>
> I have tested my named select statement above
> (InputFtpEndpoint.findAllFtpEndpoints)  using selectList() and I am
> able to get all the rows in my table into a list and print them out.
> So, I know the query works and my config files work.
>
> But, there is no printed output from my result handler using the same
> query and schema. What am I doing wrong?
>
> TIA,
>
> john
Reply | Threaded
Open this post in threaded view
|

Re: Simple Result Handler implementation problem

Clinton Begin
Administrator
Possibly caching... especially if it's the same statement with the same params.

You can call clearCache against the session to try that hypothesis out.

On Mon, Oct 11, 2010 at 2:41 PM, konbonwa <[hidden email]> wrote:
I managed to figure out how to get my ResultHandler to run, but I
still don't know why it does.

In my previous post below, I omitted the fact that I call the same
SqlSession with a selectList() call before I do a select() with my
Result Handler because it did not seem like that would affect any
subsequent database accesses.

But this weekend, on a hunch, I commented out my selectList() call and
just ran the select() with my ResultHandler by itself, which then did
work and did print out all the database rows matched by my query.

That surprised me. Now I want to know, why did my previous
selectList() call interfere with my later select() call with a
ResultHandler???

Is there some kind of caching going on that I need to know about?

Thanks,

~ john

On Oct 8, 3:24 pm, konbonwa <[hidden email]> wrote:
> Hi all,
>
> I am coming from iBATIS 2.3 and I'm trying to get a simple batch
> result handler implmentation to work with Java bean that previously
> worked in ibatis 2.3 (FtpEndpoint below).
>
> Here's my simple as possible result handler implementation:
>
> <code>
> // imports omitted..
> public class TestResultHandler implements ResultHandler {
>
>     @Override
>         public void handleResult( ResultContext rc ) {
>
>         FtpEndpoint ife = (FtpEndpoint) rc.getResultObject();
>         System.out.println( "[ResultObject] ==> " + ife );
>
>     }
>
> }
>
> <code/>
>
> I then set this result handler up in my test main method in another
> class as so:
>
> <code>
> public static void main(String[] args) throws IOException {
> ..
> SqlSessionFactory iFactory =
>      new
> SqlSessionFactoryBuilder().build( Resources.getResourceAsReader(
>            "com/boeing/siai/ibatis3/test/map/
> InputFtpEndpointSqlMapConfig.xml" ) );
>
> iSession = iFactory.openSession();
> ..
>
> ..
> TestResultHandler trh = new TestResultHandler();
> System.out.println( "==> Constructed TestResultHandler, calling
> iSession.select()" );
> iSession.select( "InputFtpEndpoint.findAllFtpEndpoints", null, trh );
> ..
> // No printed output from my result handler here.
> ..
>
> <code/>
>
> I have tested my named select statement above
> (InputFtpEndpoint.findAllFtpEndpoints)  using selectList() and I am
> able to get all the rows in my table into a list and print them out.
> So, I know the query works and my config files work.
>
> But, there is no printed output from my result handler using the same
> query and schema. What am I doing wrong?
>
> TIA,
>
> john

Reply | Threaded
Open this post in threaded view
|

Re: Simple Result Handler implementation problem

konbonwa
Yes, I was calling exactly the same SQL select statement each time
with the same parameters, so I would suppose that those calls would be
ideal candidates for caching.

I did call clearCache() and it did allow my test program to run as
expected. Thanks for the tip.

So now I have a new question: I have an existing version 2.3 batching
RowHandler that I want to convert over to a version 3.0 ResultHandler.
Other than the obvious API changes, can I assume that the clearCache()
call will directly replace my calls to startBatch() and executeBatch()
as they were used in version 2.3?

Also, if my previous results are in the local cache, why would my
ResultHandler just silently return from the select() call to Mybatis?
If the results are in the local cache, why not just hand them back
again to a subsequent select() call with the same select statement
with the same parameters?

Thanks,

~ john

On Oct 11, 8:13 pm, Clinton Begin <[hidden email]> wrote:

> Possibly caching... especially if it's the same statement with the same
> params.
>
> You can call clearCache against the session to try that hypothesis out.
>
> On Mon, Oct 11, 2010 at 2:41 PM, konbonwa <[hidden email]> wrote:
> > I managed to figure out how to get my ResultHandler to run, but I
> > still don't know why it does.
>
> > In my previous post below, I omitted the fact that I call the same
> > SqlSession with a selectList() call before I do a select() with my
> > Result Handler because it did not seem like that would affect any
> > subsequent database accesses.
>
> > But this weekend, on a hunch, I commented out my selectList() call and
> > just ran the select() with my ResultHandler by itself, which then did
> > work and did print out all the database rows matched by my query.
>
> > That surprised me. Now I want to know, why did my previous
> > selectList() call interfere with my later select() call with a
> > ResultHandler???
>
> > Is there some kind of caching going on that I need to know about?
>
> > Thanks,
>
> > ~ john
>
> > On Oct 8, 3:24 pm, konbonwa <[hidden email]> wrote:
> > > Hi all,
>
> > > I am coming from iBATIS 2.3 and I'm trying to get a simple batch
> > > result handler implmentation to work with Java bean that previously
> > > worked in ibatis 2.3 (FtpEndpoint below).
>
> > > Here's my simple as possible result handler implementation:
>
> > > <code>
> > > // imports omitted..
> > > public class TestResultHandler implements ResultHandler {
>
> > >     @Override
> > >         public void handleResult( ResultContext rc ) {
>
> > >         FtpEndpoint ife = (FtpEndpoint) rc.getResultObject();
> > >         System.out.println( "[ResultObject] ==> " + ife );
>
> > >     }
>
> > > }
>
> > > <code/>
>
> > > I then set this result handler up in my test main method in another
> > > class as so:
>
> > > <code>
> > > public static void main(String[] args) throws IOException {
> > > ..
> > > SqlSessionFactory iFactory =
> > >      new
> > > SqlSessionFactoryBuilder().build( Resources.getResourceAsReader(
> > >            "com/boeing/siai/ibatis3/test/map/
> > > InputFtpEndpointSqlMapConfig.xml" ) );
>
> > > iSession = iFactory.openSession();
> > > ..
>
> > > ..
> > > TestResultHandler trh = new TestResultHandler();
> > > System.out.println( "==> Constructed TestResultHandler, calling
> > > iSession.select()" );
> > > iSession.select( "InputFtpEndpoint.findAllFtpEndpoints", null, trh );
> > > ..
> > > // No printed output from my result handler here.
> > > ..
>
> > > <code/>
>
> > > I have tested my named select statement above
> > > (InputFtpEndpoint.findAllFtpEndpoints)  using selectList() and I am
> > > able to get all the rows in my table into a list and print them out.
> > > So, I know the query works and my config files work.
>
> > > But, there is no printed output from my result handler using the same
> > > query and schema. What am I doing wrong?
>
> > > TIA,
>
> > > john
Reply | Threaded
Open this post in threaded view
|

Re: Simple Result Handler implementation problem

Clinton Begin
Administrator
Thanks for confirming.  I think select() using cached results in the presence of a ResultHandler should be considered a bug, as it makes no sense..

Can you log this issue in the issue tracker? (you can use this email as the body)

I'll review your other questions later today, as I'm off to a meeting.

Clinton



On Tue, Oct 12, 2010 at 12:20 PM, konbonwa <[hidden email]> wrote:
Yes, I was calling exactly the same SQL select statement each time
with the same parameters, so I would suppose that those calls would be
ideal candidates for caching.

I did call clearCache() and it did allow my test program to run as
expected. Thanks for the tip.

So now I have a new question: I have an existing version 2.3 batching
RowHandler that I want to convert over to a version 3.0 ResultHandler.
Other than the obvious API changes, can I assume that the clearCache()
call will directly replace my calls to startBatch() and executeBatch()
as they were used in version 2.3?

Also, if my previous results are in the local cache, why would my
ResultHandler just silently return from the select() call to Mybatis?
If the results are in the local cache, why not just hand them back
again to a subsequent select() call with the same select statement
with the same parameters?

Thanks,

~ john

On Oct 11, 8:13 pm, Clinton Begin <[hidden email]> wrote:
> Possibly caching... especially if it's the same statement with the same
> params.
>
> You can call clearCache against the session to try that hypothesis out.
>
> On Mon, Oct 11, 2010 at 2:41 PM, konbonwa <[hidden email]> wrote:
> > I managed to figure out how to get my ResultHandler to run, but I
> > still don't know why it does.
>
> > In my previous post below, I omitted the fact that I call the same
> > SqlSession with a selectList() call before I do a select() with my
> > Result Handler because it did not seem like that would affect any
> > subsequent database accesses.
>
> > But this weekend, on a hunch, I commented out my selectList() call and
> > just ran the select() with my ResultHandler by itself, which then did
> > work and did print out all the database rows matched by my query.
>
> > That surprised me. Now I want to know, why did my previous
> > selectList() call interfere with my later select() call with a
> > ResultHandler???
>
> > Is there some kind of caching going on that I need to know about?
>
> > Thanks,
>
> > ~ john
>
> > On Oct 8, 3:24 pm, konbonwa <[hidden email]> wrote:
> > > Hi all,
>
> > > I am coming from iBATIS 2.3 and I'm trying to get a simple batch
> > > result handler implmentation to work with Java bean that previously
> > > worked in ibatis 2.3 (FtpEndpoint below).
>
> > > Here's my simple as possible result handler implementation:
>
> > > <code>
> > > // imports omitted..
> > > public class TestResultHandler implements ResultHandler {
>
> > >     @Override
> > >         public void handleResult( ResultContext rc ) {
>
> > >         FtpEndpoint ife = (FtpEndpoint) rc.getResultObject();
> > >         System.out.println( "[ResultObject] ==> " + ife );
>
> > >     }
>
> > > }
>
> > > <code/>
>
> > > I then set this result handler up in my test main method in another
> > > class as so:
>
> > > <code>
> > > public static void main(String[] args) throws IOException {
> > > ..
> > > SqlSessionFactory iFactory =
> > >      new
> > > SqlSessionFactoryBuilder().build( Resources.getResourceAsReader(
> > >            "com/boeing/siai/ibatis3/test/map/
> > > InputFtpEndpointSqlMapConfig.xml" ) );
>
> > > iSession = iFactory.openSession();
> > > ..
>
> > > ..
> > > TestResultHandler trh = new TestResultHandler();
> > > System.out.println( "==> Constructed TestResultHandler, calling
> > > iSession.select()" );
> > > iSession.select( "InputFtpEndpoint.findAllFtpEndpoints", null, trh );
> > > ..
> > > // No printed output from my result handler here.
> > > ..
>
> > > <code/>
>
> > > I have tested my named select statement above
> > > (InputFtpEndpoint.findAllFtpEndpoints)  using selectList() and I am
> > > able to get all the rows in my table into a list and print them out.
> > > So, I know the query works and my config files work.
>
> > > But, there is no printed output from my result handler using the same
> > > query and schema. What am I doing wrong?
>
> > > TIA,
>
> > > john

Reply | Threaded
Open this post in threaded view
|

Re: Simple Result Handler implementation problem

konbonwa
Did it. It's issue 139:

http://code.google.com/p/mybatis/issues/detail?id=139

On Oct 12, 11:48 am, Clinton Begin <[hidden email]> wrote:

> Thanks for confirming.  I think select() using cached results in the
> presence of a ResultHandler should be considered a bug, as it makes no
> sense..
>
> Can you log this issue in the issue tracker? (you can use this email as the
> body)
>
> I'll review your other questions later today, as I'm off to a meeting.
>
> Clinton
>
> On Tue, Oct 12, 2010 at 12:20 PM, konbonwa <[hidden email]> wrote:
> > Yes, I was calling exactly the same SQL select statement each time
> > with the same parameters, so I would suppose that those calls would be
> > ideal candidates for caching.
>
> > I did call clearCache() and it did allow my test program to run as
> > expected. Thanks for the tip.
>
> > So now I have a new question: I have an existing version 2.3 batching
> > RowHandler that I want to convert over to a version 3.0 ResultHandler.
> > Other than the obvious API changes, can I assume that the clearCache()
> > call will directly replace my calls to startBatch() and executeBatch()
> > as they were used in version 2.3?
>
> > Also, if my previous results are in the local cache, why would my
> > ResultHandler just silently return from the select() call to Mybatis?
> > If the results are in the local cache, why not just hand them back
> > again to a subsequent select() call with the same select statement
> > with the same parameters?
>
> > Thanks,
>
> > ~ john
>
> > On Oct 11, 8:13 pm, Clinton Begin <[hidden email]> wrote:
> > > Possibly caching... especially if it's the same statement with the same
> > > params.
>
> > > You can call clearCache against the session to try that hypothesis out.
>
> > > On Mon, Oct 11, 2010 at 2:41 PM, konbonwa <[hidden email]> wrote:
> > > > I managed to figure out how to get my ResultHandler to run, but I
> > > > still don't know why it does.
>
> > > > In my previous post below, I omitted the fact that I call the same
> > > > SqlSession with a selectList() call before I do a select() with my
> > > > Result Handler because it did not seem like that would affect any
> > > > subsequent database accesses.
>
> > > > But this weekend, on a hunch, I commented out my selectList() call and
> > > > just ran the select() with my ResultHandler by itself, which then did
> > > > work and did print out all the database rows matched by my query.
>
> > > > That surprised me. Now I want to know, why did my previous
> > > > selectList() call interfere with my later select() call with a
> > > > ResultHandler???
>
> > > > Is there some kind of caching going on that I need to know about?
>
> > > > Thanks,
>
> > > > ~ john
>
> > > > On Oct 8, 3:24 pm, konbonwa <[hidden email]> wrote:
> > > > > Hi all,
>
> > > > > I am coming from iBATIS 2.3 and I'm trying to get a simple batch
> > > > > result handler implmentation to work with Java bean that previously
> > > > > worked in ibatis 2.3 (FtpEndpoint below).
>
> > > > > Here's my simple as possible result handler implementation:
>
> > > > > <code>
> > > > > // imports omitted..
> > > > > public class TestResultHandler implements ResultHandler {
>
> > > > >     @Override
> > > > >         public void handleResult( ResultContext rc ) {
>
> > > > >         FtpEndpoint ife = (FtpEndpoint) rc.getResultObject();
> > > > >         System.out.println( "[ResultObject] ==> " + ife );
>
> > > > >     }
>
> > > > > }
>
> > > > > <code/>
>
> > > > > I then set this result handler up in my test main method in another
> > > > > class as so:
>
> > > > > <code>
> > > > > public static void main(String[] args) throws IOException {
> > > > > ..
> > > > > SqlSessionFactory iFactory =
> > > > >      new
> > > > > SqlSessionFactoryBuilder().build( Resources.getResourceAsReader(
> > > > >            "com/boeing/siai/ibatis3/test/map/
> > > > > InputFtpEndpointSqlMapConfig.xml" ) );
>
> > > > > iSession = iFactory.openSession();
> > > > > ..
>
> > > > > ..
> > > > > TestResultHandler trh = new TestResultHandler();
> > > > > System.out.println( "==> Constructed TestResultHandler, calling
> > > > > iSession.select()" );
> > > > > iSession.select( "InputFtpEndpoint.findAllFtpEndpoints", null, trh );
> > > > > ..
> > > > > // No printed output from my result handler here.
> > > > > ..
>
> > > > > <code/>
>
> > > > > I have tested my named select statement above
> > > > > (InputFtpEndpoint.findAllFtpEndpoints)  using selectList() and I am
> > > > > able to get all the rows in my table into a list and print them out.
> > > > > So, I know the query works and my config files work.
>
> > > > > But, there is no printed output from my result handler using the same
> > > > > query and schema. What am I doing wrong?
>
> > > > > TIA,
>
> > > > > john