Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

docu sql object methods which return Query instances

  • Loading branch information...
commit 1e9cdd2a8924a4e28f34f55c54f3527a7c2946e1 1 parent 0546703
Brian McCallister authored

Showing 1 changed file with 7 additions and 0 deletions. Show diff stats Hide diff stats

  1. +7 0 _posts/0500-12-15-sql_object_api_queries.md
7 _posts/0500-12-15-sql_object_api_queries.md
Source Rendered
@@ -16,6 +16,10 @@ public interface SomeQueries
16 16
17 17 @SqlQuery("select name from something")
18 18 Iterator<String> findAllNames();
  19 +
  20 + @SqlQuery("select name from something where id = :id")
  21 + Query<String> queryById(@Bind("id") int id);
  22 +
19 23 }
20 24 {% endhighlight %}
21 25
@@ -25,6 +29,8 @@ The second method, <code>findNamesBetween</code> will again infer that we are lo
25 29
26 30 The third method, <code>findAllNames</code> does the same String extraction from each row, but because the method returns a <code>java.util.Iterator</code> it loads results lazily, only traversing the result set as <code>Iterator#next</code> or <code>Iterator#hasNext</code> is called. The iterator returned is actually a [ResultIterator](/maven_site/apidocs/org/skife/jdbi/v2/ResultIterator.html). The underlying result set will be closed when the <code>ResultIterator#close</code> method is invoked, or when the end of the result set is reached.
27 31
  32 +The final method, <code>queryById</code> returns a [Query](/maven_site/apidocs/org/skife/jdbi/v2/Query.html) instance mapped to a string. This form binds what it knows about, applies customizers, and returns the [fluent-api query](/fluent_queries/) instance which has not yet been executed.
  33 +
28 34 As with String, mappings for singular primitive types in the first position of the result set are provided out of the box by JDBI. For more sophisticated mappings you can register [ResultSetMapper](/maven_site/apidocs/org/skife/jdbi/v2/tweak/ResultSetMapper.html) or [ResultSetMapperFactory](/maven_site/apidocs/org/skife/jdbi/v2/ResultSetMapperFactory.html) instances with either the DBI, the Handle, or on the sql object or individual method. Take for example the following result set mapper and class it maps to:
29 35
30 36 {% highlight java %}
@@ -96,3 +102,4 @@ public interface YetAnotherQuery
96 102 {% endhighlight %}
97 103
98 104 You can also register result set mappers on the <code>DBI</code> or <code>Handle</code> instance the sql object is attached to.
  105 +

0 comments on commit 1e9cdd2

Please sign in to comment.
Something went wrong with that request. Please try again.