Class 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, and Utc.

    By default, the outcome throws SQLException if no records are found in the ResultSet. You can change this behavior by using a two-arguments constructor (null will be returned if ResultSet is 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
    • 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 to
        slnt - 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 to
        mps - The mappings
        slnt - Silently return NULL if there is no row
    • Method Detail

      • handle

        public T handle​(ResultSet rset,
                        Statement stmt)
                 throws SQLException
        Description copied from interface: Outcome
        Process the result set and return some value.
        Specified by:
        handle in interface Outcome<T>
        Parameters:
        rset - The result set to process
        stmt - The statement used in the run
        Returns:
        The result
        Throws:
        SQLException - If something goes wrong inside