Package fj.control.db

Class DB<A>


  • public abstract class DB<A>
    extends java.lang.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

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      F<java.sql.Connection,​java.util.concurrent.Callable<A>> asFunction()
      Returns the callable-valued function projection of this database action.
      <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<java.sql.Connection,​A> f)
      Constructs a database action as a function from a database connection to a value.
      static <A> DB<A> db​(Try1<java.sql.Connection,​A,​java.sql.SQLException> t)
      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.
      <B> DB<B> map​(F<A,​B> f)
      Map a function over the result of this action.
      abstract A run​(java.sql.Connection c)
      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 Detail

      • DB

        public DB()
    • Method Detail

      • run

        public abstract A run​(java.sql.Connection c)
                       throws java.sql.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:
        java.sql.SQLException - if a database error occurred.
      • db

        public static <A> DB<A> db​(F<java.sql.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<java.sql.Connection,​A,​java.sql.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<java.sql.Connection,​java.util.concurrent.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.