org.skife.jdbi.unstable.decorator
Class BaseHandleDecorator

java.lang.Object
  extended by org.skife.jdbi.unstable.decorator.BaseHandleDecorator
All Implemented Interfaces:
Handle, Unstable

public class BaseHandleDecorator
extends java.lang.Object
implements Handle, Unstable

Convenience class implementing Handle which delegates all method calls to the Handle instance passed into its constructor. This is provided to allow decorator instances to only override the bahavior of things they need to.


Constructor Summary
BaseHandleDecorator(Handle handle)
           
 
Method Summary
 Batch batch()
          Create a new Batch instance which can be used to queue up and execute statements in a single batch.
 void begin()
          start a transaction
 void clearStatementCache()
          Clear this handle's cache of prepared statements.
 void close()
          Close the connection
 void commit()
          Commit transaction in progress
 void execute(java.lang.String sql)
          Execute an sql statement which does not return any results.
 void execute(java.lang.String statement, java.util.Collection args)
          Execute an sql statement which does not return any results.
 void execute(java.lang.String statement, java.util.Map args)
          Execute an sql statement which does not return any results.
 void execute(java.lang.String statement, java.lang.Object bean)
          Execute a statement with named parameters pulling values from a JavaBean
 void execute(java.lang.String statement, java.lang.Object[] args)
          Execute an sql statement which does not return any results.
 java.util.Map first(java.lang.String statement)
          Returns the first row matched by the query
 java.util.Map first(java.lang.String statement, java.util.Collection params)
          Returns the first row matched by the query
 java.util.Map first(java.lang.String statement, java.util.Map args)
          Returns the first row matched by the query
 java.util.Map first(java.lang.String statement, java.lang.Object bean)
          Returns the first row matched by the query
 java.util.Map first(java.lang.String statement, java.lang.Object[] params)
          Returns the first row matched by the query
 java.sql.Connection getConnection()
          Obtain the JDBC connection used by this handle
 java.util.Map getGlobalParameters()
          Obtain a map containing globally set named parameter values.
 void inTransaction(TransactionCallback callback)
          Execute transactionCallback in a transaction, cleaning up as necesary around it
 boolean isInTransaction()
          Has a transaction been started?
 boolean isOpen()
          Checks to make sure the connection is live
 void load(java.lang.String name)
          Eagerly load a named query from the filesystem.
 void name(java.lang.String name, java.lang.String sql)
          Prepared a named sql statement
 PreparedBatch prepareBatch(java.lang.String statement)
          Create a new PreparedBatch instance from arbitrary SQL or a named statement
 java.util.List query(java.lang.String query)
          Retrieve a collection of map instances from a query.
 java.util.List query(java.lang.String statement, java.util.Collection args)
          Execute statement with positional arguments
 java.util.List query(java.lang.String statement, java.util.Map args)
          Execute query using name parameters of the form: select id, name from something where id = :something and the key to the params map is "something"
 void query(java.lang.String statement, java.util.Map args, RowCallback callback)
          Iterate (once) over a resultset in order calling the callback for each row processed
 java.util.List query(java.lang.String statement, java.lang.Object param)
          Execute statement with JavaBean mapped named parameter
 java.util.List query(java.lang.String statement, java.lang.Object[] args)
          Execute statement with positional arguments
 void query(java.lang.String statement, java.lang.Object[] args, RowCallback callback)
          Iterate (once) over a resultset in order calling the callback for each row processed
 void query(java.lang.String statement, RowCallback callback)
          Iterate (once) over a resultset in order calling the callback for each row processed
 void rollback()
          Rollback a transaction in progress
 void script(java.lang.String name)
          Find and execute the sql script name.
 int update(java.lang.String statement)
          Execute a statement of the form update foo set bar = foo_id
 int update(java.lang.String statement, java.util.Collection args)
          Execute a statement of the form update foo set bar = foo_id
 int update(java.lang.String statement, java.util.Map args)
          Execute a statement of the form update foo set bar = foo_id
 int update(java.lang.String statement, java.lang.Object bean)
          Execute an update with named parameters pulling values from a JavaBean
 int update(java.lang.String statement, java.lang.Object[] args)
          Execute a statement of the form update foo set bar = foo_id
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseHandleDecorator

public BaseHandleDecorator(Handle handle)
Method Detail

getConnection

public java.sql.Connection getConnection()
Description copied from interface: Handle
Obtain the JDBC connection used by this handle

Specified by:
getConnection in interface Handle

begin

public void begin()
           throws DBIException
Description copied from interface: Handle
start a transaction

Specified by:
begin in interface Handle
Throws:
DBIException

close

public void close()
Description copied from interface: Handle
Close the connection

Specified by:
close in interface Handle

clearStatementCache

public void clearStatementCache()
Description copied from interface: Handle
Clear this handle's cache of prepared statements. Will be called automatically prior to closing the handle, or can be cleared manually at any point.

Specified by:
clearStatementCache in interface Handle

commit

public void commit()
            throws DBIException
Description copied from interface: Handle
Commit transaction in progress

Specified by:
commit in interface Handle
Throws:
DBIException

rollback

public void rollback()
              throws DBIException
Description copied from interface: Handle
Rollback a transaction in progress

Specified by:
rollback in interface Handle
Throws:
DBIException - if the rollback fails

inTransaction

public void inTransaction(TransactionCallback callback)
                   throws DBIException
Description copied from interface: Handle
Execute transactionCallback in a transaction, cleaning up as necesary around it

Specified by:
inTransaction in interface Handle
Throws:
DBIException

isInTransaction

public boolean isInTransaction()
Description copied from interface: Handle
Has a transaction been started?

Specified by:
isInTransaction in interface Handle

execute

public void execute(java.lang.String sql)
             throws DBIException
Description copied from interface: Handle
Execute an sql statement which does not return any results. This can also be used to execute stored procedures ("call foo()")

Specified by:
execute in interface Handle
Parameters:
sql - insert/update/create/delete/call statement
Throws:
DBIException

execute

public void execute(java.lang.String statement,
                    java.lang.Object[] args)
             throws DBIException
Description copied from interface: Handle
Execute an sql statement which does not return any results. This can also be used to execute stored procedures ("call foo()")

Specified by:
execute in interface Handle
Parameters:
statement - insert/update/create/delete/call statement
args - positional arguments to be bound to statement
Throws:
DBIException

execute

public void execute(java.lang.String statement,
                    java.util.Collection args)
             throws DBIException
Description copied from interface: Handle
Execute an sql statement which does not return any results. This can also be used to execute stored procedures ("call foo()")

Specified by:
execute in interface Handle
Parameters:
statement - insert/update/create/delete/call statement
args - positional arguments to be bound to statement
Throws:
DBIException

execute

public void execute(java.lang.String statement,
                    java.util.Map args)
             throws DBIException
Description copied from interface: Handle
Execute an sql statement which does not return any results. This can also be used to execute stored procedures ("call foo()")

Specified by:
execute in interface Handle
Parameters:
statement - insert/update/create/delete/call statement
args - named arguments to be bound to statement
Throws:
DBIException

execute

public void execute(java.lang.String statement,
                    java.lang.Object bean)
             throws DBIException
Description copied from interface: Handle
Execute a statement with named parameters pulling values from a JavaBean

Specified by:
execute in interface Handle
Parameters:
statement - SQL statement with named parameters
bean - JavaBean with properties to be de-referenced for named parameter substitution
Throws:
DBIException

update

public int update(java.lang.String statement)
           throws DBIException
Description copied from interface: Handle
Execute a statement of the form update foo set bar = foo_id

Specified by:
update in interface Handle
Parameters:
statement - sql statement or named statement
Returns:
number of modified rows
Throws:
DBIException - if anything goes wrong

update

public int update(java.lang.String statement,
                  java.lang.Object[] args)
           throws DBIException
Description copied from interface: Handle
Execute a statement of the form update foo set bar = foo_id

Specified by:
update in interface Handle
Parameters:
statement - sql statement or named statement
args - positional args to bind to statement
Returns:
number of modified rows
Throws:
DBIException - if anything goes wrong

update

public int update(java.lang.String statement,
                  java.util.Collection args)
           throws DBIException
Description copied from interface: Handle
Execute a statement of the form update foo set bar = foo_id

Specified by:
update in interface Handle
Parameters:
statement - sql statement or named statement
args - positional args to bind to statement
Returns:
number of modified rows
Throws:
DBIException - if anything goes wrong

update

public int update(java.lang.String statement,
                  java.util.Map args)
           throws DBIException
Description copied from interface: Handle
Execute a statement of the form update foo set bar = foo_id

Specified by:
update in interface Handle
Parameters:
statement - sql statement or named statement
args - named args to bind to statement
Returns:
number of modified rows
Throws:
DBIException - if anything goes wrong

update

public int update(java.lang.String statement,
                  java.lang.Object bean)
           throws DBIException
Description copied from interface: Handle
Execute an update with named parameters pulling values from a JavaBean

Specified by:
update in interface Handle
Parameters:
statement - sql named statement or direct sql
bean - JavaBean whose properties
Returns:
number of rows modified
Throws:
DBIException

query

public java.util.List query(java.lang.String query)
                     throws DBIException
Description copied from interface: Handle
Retrieve a collection of map instances from a query. This is an eagerly loaded collection.

Specified by:
query in interface Handle
Parameters:
query - select statement
Returns:
collection of Map instances
Throws:
DBIException

query

public void query(java.lang.String statement,
                  RowCallback callback)
           throws DBIException
Description copied from interface: Handle
Iterate (once) over a resultset in order calling the callback for each row processed

Specified by:
query in interface Handle
Parameters:
statement - sql select statement
callback - receive callbacks for each row in result
Throws:
DBIException

query

public void query(java.lang.String statement,
                  java.lang.Object[] args,
                  RowCallback callback)
           throws DBIException
Description copied from interface: Handle
Iterate (once) over a resultset in order calling the callback for each row processed

Specified by:
query in interface Handle
Parameters:
statement - sql select statement
args - position arguments to the statement
callback - receive callbacks for each row in result
Throws:
DBIException

query

public void query(java.lang.String statement,
                  java.util.Map args,
                  RowCallback callback)
           throws DBIException
Description copied from interface: Handle
Iterate (once) over a resultset in order calling the callback for each row processed

Named parameters are matched via \s+(:\w+) outside of quotes, so basically :id, :foo_id, or :id1 type constructions.

Specified by:
query in interface Handle
Parameters:
statement - sql select statement
args - named arguments to the statement
callback - receive callbacks for each row in result
Throws:
DBIException

query

public java.util.List query(java.lang.String statement,
                            java.util.Map args)
                     throws DBIException
Description copied from interface: Handle
Execute query using name parameters of the form: select id, name from something where id = :something and the key to the params map is "something"

Named parameters are matched via \s+(:\w+) outside of quotes, so basically :id, :foo_id, or :id1 type constructions.

Specified by:
query in interface Handle
Parameters:
statement - sql statement
args - map of named parameters
Returns:
collection of Map instances with results
Throws:
DBIException

query

public java.util.List query(java.lang.String statement,
                            java.lang.Object param)
                     throws DBIException
Description copied from interface: Handle
Execute statement with JavaBean mapped named parameter

Specified by:
query in interface Handle
Parameters:
statement - sql or named statement with named paramaters
param - JavaBean whose properties will be used to populate named parameters
Returns:
results
Throws:
DBIException

query

public java.util.List query(java.lang.String statement,
                            java.lang.Object[] args)
                     throws DBIException
Description copied from interface: Handle
Execute statement with positional arguments

Specified by:
query in interface Handle
Parameters:
statement - sql or named statement
args - positional parameters
Returns:
results
Throws:
DBIException

query

public java.util.List query(java.lang.String statement,
                            java.util.Collection args)
                     throws DBIException
Description copied from interface: Handle
Execute statement with positional arguments

Specified by:
query in interface Handle
Parameters:
statement - sql or named statement
args - positional parameters, bound in iteration order
Returns:
results
Throws:
DBIException

first

public java.util.Map first(java.lang.String statement)
                    throws DBIException
Description copied from interface: Handle
Returns the first row matched by the query

Specified by:
first in interface Handle
Parameters:
statement - select statement or named query
Returns:
first row
Throws:
DBIException

first

public java.util.Map first(java.lang.String statement,
                           java.lang.Object bean)
                    throws DBIException
Description copied from interface: Handle
Returns the first row matched by the query

Specified by:
first in interface Handle
Parameters:
statement - select statement or named query
bean - JavaBean whose properties will be used to populate named parameters
Returns:
first row
Throws:
DBIException

first

public java.util.Map first(java.lang.String statement,
                           java.util.Map args)
                    throws DBIException
Description copied from interface: Handle
Returns the first row matched by the query

Specified by:
first in interface Handle
Parameters:
statement - select statement or named query
args - map of named parameters
Returns:
first row
Throws:
DBIException

first

public java.util.Map first(java.lang.String statement,
                           java.lang.Object[] params)
                    throws DBIException
Description copied from interface: Handle
Returns the first row matched by the query

Specified by:
first in interface Handle
Parameters:
statement - select statement or named query
params - positional parameters
Returns:
first row
Throws:
DBIException

first

public java.util.Map first(java.lang.String statement,
                           java.util.Collection params)
                    throws DBIException
Description copied from interface: Handle
Returns the first row matched by the query

Specified by:
first in interface Handle
Parameters:
statement - select statement or named query
params - positional parameters
Returns:
first row
Throws:
DBIException

isOpen

public boolean isOpen()
               throws DBIException
Description copied from interface: Handle
Checks to make sure the connection is live

Specified by:
isOpen in interface Handle
Throws:
DBIException

script

public void script(java.lang.String name)
            throws DBIException,
                   java.io.IOException
Description copied from interface: Handle
Find and execute the sql script name. First it will be search for name.sql, or, if that is not found, name will be loaded directly.

Scripts should seperate statements with a semicolon, for example:


 create table wombats (
  wombat_id integer primary key,
  name varchar(50)
 );

 insert into wombats (wombat_id, name) values (1, 'Muggie');

 call wiggles(1, 2, 3);
 

Specified by:
script in interface Handle
Throws:
DBIException
java.io.IOException

name

public void name(java.lang.String name,
                 java.lang.String sql)
          throws DBIException
Description copied from interface: Handle
Prepared a named sql statement

Specified by:
name in interface Handle
Parameters:
name - name to issue query under
sql - sql string to use as query
Throws:
DBIException - if there is a problem preparing the statement

load

public void load(java.lang.String name)
          throws java.io.IOException,
                 DBIException
Description copied from interface: Handle
Eagerly load a named query from the filesystem. The name will be name and it will look for a file named [name].sql in the classpath which contains a single sql statement.

Specified by:
load in interface Handle
Parameters:
name - name of query to load, such as "foo" which will be store din foo.sql
Throws:
java.io.IOException
DBIException

batch

public Batch batch()
Description copied from interface: Handle
Create a new Batch instance which can be used to queue up and execute statements in a single batch.

Specified by:
batch in interface Handle

prepareBatch

public PreparedBatch prepareBatch(java.lang.String statement)
Description copied from interface: Handle
Create a new PreparedBatch instance from arbitrary SQL or a named statement

Specified by:
prepareBatch in interface Handle

getGlobalParameters

public java.util.Map getGlobalParameters()
Description copied from interface: Handle
Obtain a map containing globally set named parameter values. All statements with named parameters will be able to make use of the global named params. Parameters passed in will overlay global params.

Handles create a local copy of global parameters specified on the DBI instance used to create the handle. Global parameters added to the Handle will not be added to the DBI instance's globals, however.

Specified by:
getGlobalParameters in interface Handle