Package com.jcabi.jdbc
Class SingleOutcome<T>
- java.lang.Object
-
- com.jcabi.jdbc.SingleOutcome<T>
-
- Type Parameters:
T- Type of items
- All Implemented Interfaces:
Outcome<T>
public final class SingleOutcome<T> extends Object implements Outcome<T>
Outcome that returns first column in the first row.Use it when you need the first column in the first row:
Long id = new JdbcSession(source) .sql("SELECT id FROM user WHERE name = ?") .set("Jeff Lebowski") .select(new SingleOutcome<Long>(Long.class));Supported types are:
String,Long,Boolean,Byte,Date,UUID, andUtc.By default, the outcome throws
SQLExceptionif no records are found in theResultSet. You can change this behavior by using a two-arguments constructor (nullwill be returned ifResultSetis empty):String name = new JdbcSession(source) .sql("SELECT name FROM user WHERE id = ?") .set(555) .select(new SingleOutcome<Long>(Long.class), true); if (name == null) { // such a record wasn't found in the database }- Since:
- 0.1.8
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.jcabi.jdbc.Outcome
Outcome.Mapping<T>, Outcome.Mappings
-
-
Field Summary
-
Fields inherited from interface com.jcabi.jdbc.Outcome
DEFAULT_MAPPINGS, LAST_INSERT_ID, NOT_EMPTY, UPDATE_COUNT, VOID
-
-
Constructor Summary
Constructors Constructor Description SingleOutcome(Class<T> tpe)Public ctor.SingleOutcome(Class<T> tpe, boolean slnt)Public ctor.SingleOutcome(Class<T> tpe, Outcome.Mappings mps, boolean slnt)Public ctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Thandle(ResultSet rset, Statement stmt)Process the result set and return some value.
-
-
-
Constructor Detail
-
SingleOutcome
public SingleOutcome(Class<T> tpe)
Public ctor.- Parameters:
tpe- The type to convert to
-
SingleOutcome
public SingleOutcome(Class<T> tpe, boolean slnt)
Public ctor.- Parameters:
tpe- The type to convert toslnt- Silently return NULL if there is no row
-
SingleOutcome
public SingleOutcome(Class<T> tpe, Outcome.Mappings mps, boolean slnt)
Public ctor.- Parameters:
tpe- The type to convert tomps- The mappingsslnt- Silently return NULL if there is no row
-
-
Method Detail
-
handle
public T handle(ResultSet rset, Statement stmt) throws SQLException
Description copied from interface:OutcomeProcess the result set and return some value.- Specified by:
handlein interfaceOutcome<T>- Parameters:
rset- The result set to processstmt- The statement used in the run- Returns:
- The result
- Throws:
SQLException- If something goes wrong inside
-
-