Package fj.control.db

Class DB<A>

java.lang.Object
fj.control.db.DB<A>

public abstract class DB<A> extends Object
The DB monad represents a database action, or a value within the context of a database connection.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DB()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the callable-valued function projection of this database action.
    final <B> DB<B>
    bind(F<A,DB<B>> f)
    Binds the given action across the result of this database action.
    static <A> DB<A>
    db(F<Connection,A> f)
    Constructs a database action as a function from a database connection to a value.
    static <A> DB<A>
    Constructs a database action as a function from a database connection to a value.
    static <A> DB<A>
    join(DB<DB<A>> a)
    Removes one layer of monadic structure.
    static <A, B> F<DB<A>,DB<B>>
    liftM(F<A,B> f)
    Promotes any given function so that it transforms between values in the database.
    final <B> DB<B>
    map(F<A,B> f)
    Map a function over the result of this action.
    abstract A
    Executes the database action, given a database connection.
    static <A> DB<A>
    unit(A a)
    Constructs a database action that returns the given value completely intact.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DB

      public DB()
  • Method Details

    • run

      public abstract A run(Connection c) throws SQLException
      Executes the database action, given a database connection.
      Parameters:
      c - The connection against which to execute the action.
      Returns:
      The result of the action.
      Throws:
      SQLException - if a database error occurred.
    • db

      public static <A> DB<A> db(F<Connection,A> f)
      Constructs a database action as a function from a database connection to a value.
      Parameters:
      f - A function from a database connection to a value.
      Returns:
      A database action representing the given function.
    • db

      public static <A> DB<A> db(Try1<Connection,A,SQLException> t)
      Constructs a database action as a function from a database connection to a value.
      Parameters:
      t - A function from a database connection to a value allowed to throw SQLException
      Returns:
      A database action representing the given function.
    • asFunction

      public final F<Connection,Callable<A>> asFunction()
      Returns the callable-valued function projection of this database action.
      Returns:
      The callable-valued function which is isomorphic to this database action.
    • map

      public final <B> DB<B> map(F<A,B> f)
      Map a function over the result of this action.
      Parameters:
      f - The function to map over the result.
      Returns:
      A new database action that applies the given function to the result of this action.
    • liftM

      public static <A, B> F<DB<A>,DB<B>> liftM(F<A,B> f)
      Promotes any given function so that it transforms between values in the database.
      Parameters:
      f - The function to promote.
      Returns:
      A function equivalent to the given one, which operates on values in the database.
    • unit

      public static <A> DB<A> unit(A a)
      Constructs a database action that returns the given value completely intact.
      Parameters:
      a - A value to be wrapped in a database action.
      Returns:
      A new database action that returns the given value.
    • bind

      public final <B> DB<B> bind(F<A,DB<B>> f)
      Binds the given action across the result of this database action.
      Parameters:
      f - The function to bind across the result of this database action.
      Returns:
      A new database action equivalent to applying the given function to the result of this action.
    • join

      public static <A> DB<A> join(DB<DB<A>> a)
      Removes one layer of monadic structure.
      Parameters:
      a - A database action that results in another.
      Returns:
      A new database action equivalent to the result of the given action.