org.skife.jdbi.v2
Class GeneratedKeys<Type>

java.lang.Object
  extended by org.skife.jdbi.v2.GeneratedKeys<Type>
Type Parameters:
Type - the key type returned

public class GeneratedKeys<Type>
extends Object

Wrapper object for generated keys as returned by the Statement.getGeneratedKeys()


Constructor Summary
GeneratedKeys(ResultSetMapper<Type> mapper, SQLStatement<?> jdbiStatement, Statement stmt, StatementContext context)
          Creates a new wrapper object for generated keys as returned by the Statement.getGeneratedKeys() method for update and insert statement for drivers that support this function.
 
Method Summary
 Type first()
          Returns the first generated key.
<AccumulatorType>
AccumulatorType
fold(AccumulatorType accumulator, Folder2<AccumulatorType> folder)
          Used to execute the query and traverse the generated keys with a accumulator.
 ResultIterator<Type> iterator()
          Returns a iterator over all generated keys.
 List<Type> list()
          Returns a list of all generated keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneratedKeys

public GeneratedKeys(ResultSetMapper<Type> mapper,
                     SQLStatement<?> jdbiStatement,
                     Statement stmt,
                     StatementContext context)
              throws SQLException
Creates a new wrapper object for generated keys as returned by the Statement.getGeneratedKeys() method for update and insert statement for drivers that support this function.

Parameters:
mapper - Maps the generated keys result set to an object
jdbiStatement - The original jDBI statement
stmt - The corresponding sql statement
context - The statement context
Throws:
SQLException
Method Detail

first

public Type first()
Returns the first generated key.

Returns:
The key or null if no keys were returned

fold

public <AccumulatorType> AccumulatorType fold(AccumulatorType accumulator,
                                              Folder2<AccumulatorType> folder)
Used to execute the query and traverse the generated keys with a accumulator. Folding over the keys 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

iterator

public ResultIterator<Type> iterator()
Returns a iterator over all generated keys.

Returns:
The key iterator

list

public List<Type> list()
Returns a list of all generated keys.

Returns:
The list of keys or an empty list if no keys were returned


Copyright © 2011. All Rights Reserved.