org.qi4j.library.sql.common
Class Databases

java.lang.Object
  extended by org.qi4j.library.sql.common.Databases

public class Databases
extends java.lang.Object

Utility methods for performing SQL calls wrapping a given DataSource.


Nested Class Summary
static interface Databases.ResultSetVisitor
          Visitor for the ResultSet.
static interface Databases.StatementVisitor
          Visitor for PreparedStatements.
 
Constructor Summary
Databases(javax.sql.DataSource source)
          Create a new Databases wrapper for a given DataSource.
 
Method Summary
 Input<java.sql.ResultSet,java.sql.SQLException> query(java.lang.String sql)
          Perform SQL query and provide results as an Input.
 void query(java.lang.String sql, Databases.ResultSetVisitor visitor)
          Perform SQL query and let visitor handle results.
 Input<java.sql.ResultSet,java.sql.SQLException> query(java.lang.String sql, Databases.StatementVisitor visitor)
          Perform SQL query and provide results as an Input.
 void query(java.lang.String sql, Databases.StatementVisitor statement, Databases.ResultSetVisitor resultsetVisitor)
          Perform SQL query and let visitor handle results.
 int update(java.lang.String sql)
          Perform SQL update statement.
 int update(java.lang.String sql, Databases.StatementVisitor visitor)
          Perform SQL update statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Databases

public Databases(javax.sql.DataSource source)
Create a new Databases wrapper for a given DataSource.

Method Detail

update

public int update(java.lang.String sql)
           throws java.sql.SQLException
Perform SQL update statement.

Throws:
java.sql.SQLException

update

public int update(java.lang.String sql,
                  Databases.StatementVisitor visitor)
           throws java.sql.SQLException
Perform SQL update statement. If the SQL string contains ? placeholders, use the StatementVisitor to update the PreparedStatement with actual values.

Throws:
java.sql.SQLException

query

public void query(java.lang.String sql,
                  Databases.ResultSetVisitor visitor)
           throws java.sql.SQLException
Perform SQL query and let visitor handle results.

Throws:
java.sql.SQLException

query

public void query(java.lang.String sql,
                  Databases.StatementVisitor statement,
                  Databases.ResultSetVisitor resultsetVisitor)
           throws java.sql.SQLException
Perform SQL query and let visitor handle results. If the SQL string contains ? placeholders, use the StatementVisitor to update the PreparedStatement with actual values.

Throws:
java.sql.SQLException

query

public Input<java.sql.ResultSet,java.sql.SQLException> query(java.lang.String sql)
Perform SQL query and provide results as an Input. This makes it possible to combine SQL data with the I/O API.


query

public Input<java.sql.ResultSet,java.sql.SQLException> query(java.lang.String sql,
                                                             Databases.StatementVisitor visitor)
Perform SQL query and provide results as an Input. This makes it possible to combine SQL data with the I/O API. If the SQL string contains ? placeholders, use the StatementVisitor to update the PreparedStatement with actual values.