java - Optional jDBI parameter -
java - Optional jDBI parameter -
is possible have optional (null) parameters jdbi queries? i'm attempting optional parameters working in database query. working dropwizard.
@sqlquery("select * \n" + "from posts \n" + "where (:authorid null or :authorid = author_id)") public list<post> findall(@bind("authorid") optional<long> authorid);
the query works when authorid passed, gives me error when null:
org.postgresql.util.psqlexception: error: not determine info type of parameter $1
this resource route calling from:
@get public arraylist<post> getposts(@queryparam("authorid") long authorid) { homecoming (arraylist<post>)postdao.findall(optional.fromnullable(authorid)); }
from i've read, possible do, i'm guessing missing or have obvious mistake. help appreciated!
fyi - have tried without guava optional (which supported dropwizard) -- sending authorid long null. works long it's not null.
you need utilize java8 version of dbifactory
on application class. provides java 8 optional back upwards joda localdatetime.
gradle dependency: (convert maven, if you're using maven)
compile 'io.dropwizard.modules:dropwizard-java8-jdbi:0.7.1
'
and create sure import io.dropwizard.java8.jdbi.dbifactory
on applicaiton class , utilize under run.
public void run(t configuration, environment environment) throws exception { final dbifactory mill = new dbifactory(); final dbi jdbi = factory.build(environment, configuration.getdatabase(), "database"); ... ... }
java dropwizard jdbi
Comments
Post a Comment