Hi,
I'm trying to write an SQL Object that returns a Query object so that I can later perform a fold over the result set. Unfortunately, when I write an SQL Object that returns a Query the underlying connection is always closed which means I am unable to use any of the methods such as first, list, map, fold etc.
Here's what I have so far:
public interface FooDAO
{
@SqlQuery("select foo from bar")
Query<String> getValues();
}
public class FooController
{
private final FooDAO fooDAO;
public FooController(FooDAO fooDAO)
{
this.fooDAO = fooDAO;
}
private String getFirstFoo()
{
return fooDAO.getValues().first();
}
}
The error I get is:
! org.skife.jdbi.v2.exceptions.UnableToCreateStatementException: java.sql.SQLException: Connection is closed. [statement:"select foo from bar", arguments:{ positional:{}, named:{}, finder:[]}]
! at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1280) ~[jdbi-2.43.jar:na]
! at org.skife.jdbi.v2.Query.fold(Query.java:172) ~[jdbi-2.43.jar:na]
! at org.skife.jdbi.v2.Query.first(Query.java:267) ~[jdbi-2.43.jar:na]
! at org.skife.jdbi.v2.Query.first(Query.java:259) ~[jdbi-2.43.jar:na]
! at com.myapp.FooController.getFirstFoo(FooController.java:13) ~[classes/:na]
...
! at java.lang.Thread.run(Thread.java:680) [na:1.6.0_37]
Caused by: ! java.sql.SQLException: Connection is closed.
! at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen(PoolingDataSource.java:185) ~[tomcat-dbcp-7.0.37.jar:7.0.37]
! at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:312) ~[tomcat-dbcp-7.0.37.jar:7.0.37]
! at org.skife.jdbi.v2.DefaultStatementBuilder.create(DefaultStatementBuilder.java:48) ~[jdbi-2.43.jar:na]
! at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1276) ~[jdbi-2.43.jar:na]
!... 54 common frames omitted
Note here I'm just getting the first result from the Query which I could do by having getValues() return a List but this is just a contrived example to demonstrate the problem - in my actual project I need to use the Query fold method. Also note the FooDAO instance is created by calling onDemand(FooDAO.class).
Any ideas what I'm doing wrong?
Alex