org.skife.jdbi.v2
Class Query<ResultType>

java.lang.Object
  extended by org.skife.jdbi.v2.SQLStatement<Query<ResultType>>
      extended by org.skife.jdbi.v2.Query<ResultType>
All Implemented Interfaces:
Iterable<ResultType>, ResultBearing<ResultType>

public class Query<ResultType>
extends SQLStatement<Query<ResultType>>
implements ResultBearing<ResultType>

Statement providing convenience result handling for SQL queries.


Method Summary
protected  void addCleanable(Cleanable cleanable)
           
protected  void addCustomizer(StatementCustomizer customizer)
           
protected  void addCustomizers(Collection<StatementCustomizer> customizers)
           
protected  void afterExecution(PreparedStatement stmt)
           
protected  void beforeExecution(PreparedStatement stmt)
           
protected  void cleanup()
           
 Query<ResultType> fetchForward()
          Specify that the fetch order should be forward, uses the underlying Statement.setFetchDirection(int)
 Query<ResultType> fetchReverse()
          Specify that the fetch order should be reversed, uses the underlying Statement.setFetchDirection(int)
 ResultType first()
          Executes the select.
<T> T
first(Class<T> containerType)
           
<AccumulatorType>
AccumulatorType
fold(AccumulatorType accumulator, Folder2<AccumulatorType> folder)
          Used to execute the query and traverse the result set with a accumulator.
<AccumulatorType>
AccumulatorType
fold(AccumulatorType accumulator, Folder3<AccumulatorType,ResultType> folder)
           
protected  ConcreteStatementContext getConcreteContext()
           
 StatementContext getContext()
          Obtain the statement context associated with this statement
protected  org.skife.jdbi.v2.Foreman getForeman()
           
protected  Collection<StatementCustomizer> getStatementCustomizers()
           
 ResultIterator<ResultType> iterator()
          Obtain a forward-only result set iterator.
 List<ResultType> list()
          Executes the select

Will eagerly load all results

<ContainerType>
ContainerType
list(Class<ContainerType> containerType)
           
 List<ResultType> list(int maxRows)
          Executes the select

Will eagerly load all results up to a maximum of maxRows

<Type> Query<Type>
map(Class<Type> resultType)
          Provide basic JavaBean mapping capabilities.
<T> Query<T>
map(ResultSetMapper<T> mapper)
           
<T> Query<T>
mapTo(Class<T> resultType)
          Makes use of registered mappers to map the result set to the desired type.
 void registerMapper(ResultSetMapper m)
           
 void registerMapper(ResultSetMapperFactory m)
           
 Query<ResultType> setFetchSize(int fetchSize)
          Specify the fetch size for the query.
 Query<ResultType> setMaxFieldSize(int maxFields)
          Specify the maimum field size in the result set.
 Query<ResultType> setMaxRows(int maxRows)
          Specify the maimum number of rows the query is to return.
 
Methods inherited from class org.skife.jdbi.v2.SQLStatement
addStatementCustomizer, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bindASCIIStream, bindASCIIStream, bindAsInt, bindAsInt, bindAsInt, bindAsInt, bindBinaryStream, bindBinaryStream, bindBySqlType, bindBySqlType, bindFromMap, bindFromProperties, bindNamedArgumentFinder, bindNull, bindNull, cleanupHandle, cleanupHandle, define, define, getContainerMapperRegistry, getHandle, getLog, getParameters, getParams, getRewriter, getSql, getStatementBuilder, getStatementLocator, getTimingCollector, internalExecute, registerArgumentFactory, registerContainerFactory, setFetchDirection, setFetchDirection2, setQueryTimeout, setStatementLocator, setStatementLocator2, setStatementRewriter, setStatementRewriter2
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fetchForward

public Query<ResultType> fetchForward()
Specify that the fetch order should be forward, uses the underlying Statement.setFetchDirection(int)

Returns:
the modified query

fetchReverse

public Query<ResultType> fetchReverse()
Specify that the fetch order should be reversed, uses the underlying Statement.setFetchDirection(int)

Returns:
the modified query

first

public ResultType first()
Executes the select.

Specifies a maximum of one result on the JDBC statement, and map that one result as the return value, or return null if there is nothing in the results

Specified by:
first in interface ResultBearing<ResultType>
Returns:
first result, mapped, or null if there is no first result

first

public <T> T first(Class<T> containerType)
Specified by:
first in interface ResultBearing<ResultType>

fold

public <AccumulatorType> AccumulatorType fold(AccumulatorType accumulator,
                                              Folder2<AccumulatorType> folder)
Used to execute the query and traverse the result set with a accumulator. Folding over the result involves invoking a callback for each row, passing into the callback the return value from the previous function invocation.

Parameters:
accumulator - The initial accumulator value
folder - Defines the function which will fold over the result set.
Returns:
The return value from the last invocation of Folder.fold(Object, java.sql.ResultSet)
See Also:
Folder

fold

public <AccumulatorType> AccumulatorType fold(AccumulatorType accumulator,
                                              Folder3<AccumulatorType,ResultType> folder)

iterator

public ResultIterator<ResultType> iterator()
Obtain a forward-only result set iterator. Note that you must explicitely close the iterator to close the underlying resources.

Specified by:
iterator in interface Iterable<ResultType>
Specified by:
iterator in interface ResultBearing<ResultType>

list

public List<ResultType> list()
Executes the select

Will eagerly load all results

Specified by:
list in interface ResultBearing<ResultType>
Throws:
UnableToCreateStatementException - if there is an error creating the statement
UnableToExecuteStatementException - if there is an error executing the statement
ResultSetException - if there is an error dealing with the result set

list

public <ContainerType> ContainerType list(Class<ContainerType> containerType)
Specified by:
list in interface ResultBearing<ResultType>

list

public List<ResultType> list(int maxRows)
Executes the select

Will eagerly load all results up to a maximum of maxRows

Specified by:
list in interface ResultBearing<ResultType>
Parameters:
maxRows - The maximum number of results to include in the result, any rows in the result set beyond this number will be ignored.
Throws:
UnableToCreateStatementException - if there is an error creating the statement
UnableToExecuteStatementException - if there is an error executing the statement
ResultSetException - if there is an error dealing with the result set

map

public <Type> Query<Type> map(Class<Type> resultType)
Provide basic JavaBean mapping capabilities. Will instantiate an instance of resultType for each row and set the JavaBean properties which match fields in the result set.

Parameters:
resultType - JavaBean class to map result set fields into the properties of, by name
Returns:
a Query which provides the bean property mapping

map

public <T> Query<T> map(ResultSetMapper<T> mapper)

mapTo

public <T> Query<T> mapTo(Class<T> resultType)
Makes use of registered mappers to map the result set to the desired type.

Parameters:
resultType - the type to map the query results to
Returns:
a new query instance which will map to the desired type
See Also:
DBI.registerMapper(org.skife.jdbi.v2.tweak.ResultSetMapper), DBI.registerMapper(ResultSetMapperFactory), Handle.registerMapper(ResultSetMapperFactory), Handle.registerMapper(org.skife.jdbi.v2.tweak.ResultSetMapper)

registerMapper

public void registerMapper(ResultSetMapper m)

registerMapper

public void registerMapper(ResultSetMapperFactory m)

setFetchSize

public Query<ResultType> setFetchSize(int fetchSize)
Specify the fetch size for the query. This should cause the results to be fetched from the underlying RDBMS in groups of rows equal to the number passed. This is useful for doing chunked streaming of results when exhausting memory could be a problem.

Parameters:
i - the number of rows to fetch in a bunch
Returns:
the modified query

setMaxFieldSize

public Query<ResultType> setMaxFieldSize(int maxFields)
Specify the maimum field size in the result set. This uses the underlying JDBC Statement.setMaxFieldSize(int)

Parameters:
i - maximum field size
Returns:
modified query

setMaxRows

public Query<ResultType> setMaxRows(int maxRows)
Specify the maimum number of rows the query is to return. This uses the underlying JDBC Statement.setMaxRows(int)}.

Parameters:
i - maximum number of rows to return
Returns:
modified query

addCleanable

protected void addCleanable(Cleanable cleanable)

addCustomizer

protected void addCustomizer(StatementCustomizer customizer)

addCustomizers

protected void addCustomizers(Collection<StatementCustomizer> customizers)

afterExecution

protected final void afterExecution(PreparedStatement stmt)

beforeExecution

protected final void beforeExecution(PreparedStatement stmt)

cleanup

protected final void cleanup()

getConcreteContext

protected final ConcreteStatementContext getConcreteContext()

getContext

public final StatementContext getContext()
Obtain the statement context associated with this statement


getForeman

protected final org.skife.jdbi.v2.Foreman getForeman()

getStatementCustomizers

protected Collection<StatementCustomizer> getStatementCustomizers()


Copyright © 2013. All Rights Reserved.