0

For some reason i can not use BindIn but have to use BindBeans to pass in a list of string values for in clause. I have below, but seems can not pass the Types as i wanted. Any advise please?

*MyFilter {
private final String Types; 
private final Timestamp Date;
 public MyFilter (){
    this.Types = "A','B"
    THIS.Date = now();
 }

}
@SqlQuery("select * from table where type in (:Types) and date = :Date  ")
public abstract List<xx> get(@BindBean MyFilter filter);*
chloes
  • 25
  • 4

2 Answers2

1

You should be able to do this with @BindIn:

@SqlQuery("select * from table where type in (<types>) and date = :Date")
public abstract List<xx> get(@BindIn List<String> filter);

For @BindIn to work, you will also need to add @UseStringTemplate3StatementLocator to your access class. JDBI needs this to

You will likely also need to add this dependency:

<dependency>
    <groupId>org.antlr</groupId>
    <artifactId>stringtemplate</artifactId>
    <version>3.2.1</version>
</dependency>

Here's a somewhat related post:

https://stackoverflow.com/a/19200912/2108024

Community
  • 1
  • 1
Sperr
  • 569
  • 1
  • 10
  • 18
  • Thanks, mentioned before that i can not use BindIn as i need to put all params in one bean. So will have to use BindBean. Any suggestion ? – chloes Aug 03 '16 at 08:00
  • I don't believe it is possible to use BindBean in this fashion. I think you're going to need to use BindIn somehow - by getting the list in the java layer, or having MyFilter implement iterable (which would allow you to use it in BindIn) – Sperr Aug 03 '16 at 20:11
0

If you want some dynamic part(s) of SQL you can use stringtemplates.

@UseStringTemplate3StatementLocator
public abstract class MyDAO {

    @SqlQuery("select * from table where type in (<types>) and date = :Date  ")
    public abstract List<xx> get(@Define("types") String types);

....

You will need to add this dependency:

 <dependency>
       <groupId>org.antlr</groupId>
       <artifactId>stringtemplate</artifactId>
       <version>3.2</version>
 </dependency>

In my case, it was very useful for dynamic sorting. Hope this helps.

Ivan Marjanovic
  • 979
  • 1
  • 9
  • 15