Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.control.db
Class DB<A>

java.lang.Object
  extended by 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
DB()
           
 
Method Summary
 F<Connection,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<Connection,A> f)
          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(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(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.

asFunction

public 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 <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 <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.

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.