Arch4J 1.1

org.arch4j.dataaccess
Class DatabaseManager

java.lang.Object
  |
  +--org.arch4j.dataaccess.DatabaseManager
Direct Known Subclasses:
TransactionalDatabaseManager

public class DatabaseManager
extends Object

This class is used to communicate with the data server. It's job is to execute SQL and invoke the processNextRow method on the listener.

Version:
1.0
Author:
Arch4J Team
See Also:
ResultSetVisitor

Field Summary
protected  org.arch4j.dataaccess.ConnectionManager connectionManager
           
protected static LoggingCategory loggingCategory
          The logging category.
 
Constructor Summary
protected DatabaseManager()
          Default constructor
 
Method Summary
protected  Connection beginDatabaseAction()
          Attempts to establish a connection to the database.
protected  PreparedStatement buildStatement(Connection connection, String sql, List parameters)
          Creates a PreparedStatement object and populates it with the given parameters.
 int delete(String sql, List parameters)
          Executes a SQL DELETE statement containing zero or more question-marked parameters and returns the number of rows affected.
protected  void endDatabaseAction(ResultSet jdbcResultSet, Statement statement, Connection aConnection)
          Releases the JDBC resources.
 int execUpdate(String sql, List parameters)
          Executes a SQL DELETE statement containing zero or more question-marked parameters and returns the number of rows affected.
 void execUpdate(String sql, List parameters, ResultSetVisitor aListener)
          Executes a SQL INSERT, UPDATE or DELETE statement containing zero or more question-marked parameters and returns the number of rows affected.
 void execute(Query query, ResultSetVisitor aListener)
          This method executes a query that could be SELECT, INSERT, DELETE or UPDATE
 void execute(String sql, List parameters, ResultSetVisitor aListener)
          Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement containing zero or more question-marked parameters.
 void execute(String sql, ResultSetVisitor aListener)
          Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement containing no parameters.
 void execute(String domain, String propertyName, List parameters, ResultSetVisitor aListener)
          Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement specified by the given property name in the given property domain.
 void execute(String domain, String propertyName, ResultSetVisitor aListener)
          Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement specified by the given property name in the given property domain.
 BatchResult executeBatch(BatchQuery batchQuery)
          Note that the JDBC specification does not specify if a BatchQuery will execute as an atomic operation or not.
 int insert(String sql, List parameters)
          Executes a SQL INSERT statement containing zero or more question-marked parameters and returns the number of rows affected.
protected  void notifyListener(ResultSet jdbcResultSet, ResultSetVisitor aListener)
          Loop through the result set notifying the listener as each row is processed.
 void select(String sql, List parameters, ResultSetVisitor aListener)
          Executes a SQL SELECT query containing no parameters.
 void select(String sql, ResultSetVisitor aListener)
          Executes a SQL SELECT query containing no parameters.
 int update(String sql, List parameters)
          Executes a SQL UPDATE statement containing zero or more question-marked parameters and returns the number of rows affected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loggingCategory

protected static LoggingCategory loggingCategory
The logging category.


connectionManager

protected org.arch4j.dataaccess.ConnectionManager connectionManager
Constructor Detail

DatabaseManager

protected DatabaseManager()
Default constructor

Method Detail

execute

public void execute(Query query,
                    ResultSetVisitor aListener)
             throws DataAccessException
This method executes a query that could be SELECT, INSERT, DELETE or UPDATE

Parameters:
query - A query Object that has both the SQL and the values filled in
aListener - The call back listener that needs to be called
Throws:
DataAccessException

execute

public void execute(String domain,
                    String propertyName,
                    List parameters,
                    ResultSetVisitor aListener)
             throws SQLException
Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement specified by the given property name in the given property domain. The statement may contain zero or more question-marked parameters.

Parameters:
domain - The property file to use.
propertyName - The property whose value is a SQL statement.
parameters - The parameters to substitute for question marks.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

execute

public void execute(String domain,
                    String propertyName,
                    ResultSetVisitor aListener)
             throws SQLException
Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement specified by the given property name in the given property domain.

Parameters:
domain - The property file to use.
propertyName - The property whose value is a SQL statement.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

execute

public void execute(String sql,
                    List parameters,
                    ResultSetVisitor aListener)
             throws SQLException
Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement containing zero or more question-marked parameters.

Parameters:
sql - The SQL statement to execute.
parameters - The parameters to substitute for question marks.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

execute

public void execute(String sql,
                    ResultSetVisitor aListener)
             throws SQLException
Executes a SQL SELECT, INSERT, UPDATE, or DELETE statement containing no parameters.

Parameters:
sql - The SQL statement to execute.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

select

public void select(String sql,
                   ResultSetVisitor aListener)
            throws SQLException
Executes a SQL SELECT query containing no parameters.

Parameters:
sql - The SQL SELECT statement to execute.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

select

public void select(String sql,
                   List parameters,
                   ResultSetVisitor aListener)
            throws SQLException
Executes a SQL SELECT query containing no parameters.

Parameters:
sql - The SQL SELECT statement to execute.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

insert

public int insert(String sql,
                  List parameters)
           throws SQLException
Executes a SQL INSERT statement containing zero or more question-marked parameters and returns the number of rows affected.

Parameters:
sql - The SQL INSERT statement to execute.
parameters - The parameters to substitute for question marks.
Throws:
SQLException - If a database error occurs.

update

public int update(String sql,
                  List parameters)
           throws SQLException
Executes a SQL UPDATE statement containing zero or more question-marked parameters and returns the number of rows affected.

Parameters:
sql - The SQL UPDATE statement to execute.
parameters - The parameters to substitute for question marks.
Throws:
SQLException - If a database error occurs.

delete

public int delete(String sql,
                  List parameters)
           throws SQLException
Executes a SQL DELETE statement containing zero or more question-marked parameters and returns the number of rows affected.

Parameters:
sql - The SQL DELETE statement to execute.
parameters - The parameters to substitute for question marks.
Throws:
SQLException - If a database error occurs.

execUpdate

public int execUpdate(String sql,
                      List parameters)
               throws SQLException
Executes a SQL DELETE statement containing zero or more question-marked parameters and returns the number of rows affected.

Parameters:
sql - The SQL DELETE statement to execute.
parameters - The parameters to substitute for question marks.
Throws:
SQLException - If a database error occurs.

execUpdate

public void execUpdate(String sql,
                       List parameters,
                       ResultSetVisitor aListener)
                throws SQLException
Executes a SQL INSERT, UPDATE or DELETE statement containing zero or more question-marked parameters and returns the number of rows affected.

Parameters:
sql - The SQL statement to execute.
parameters - The parameters to substitute for question marks.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

buildStatement

protected PreparedStatement buildStatement(Connection connection,
                                           String sql,
                                           List parameters)
                                    throws SQLException
Creates a PreparedStatement object and populates it with the given parameters.

Parameters:
connection - The database connection.
sql - The SQL statement to start with.
parameters - The parameters to substitute for question marks.
Returns:
A new PreparedStatement object containing the pre-compiled statement
Throws:
SQLException - If a database error occurs.

notifyListener

protected void notifyListener(ResultSet jdbcResultSet,
                              ResultSetVisitor aListener)
                       throws SQLException
Loop through the result set notifying the listener as each row is processed.

Parameters:
jdbcResultSet - The data produced by a query.
aListener - An object that will process the result set.
Throws:
SQLException - If a database error occurs.

executeBatch

public BatchResult executeBatch(BatchQuery batchQuery)
                         throws DataAccessException
Note that the JDBC specification does not specify if a BatchQuery will execute as an atomic operation or not. If a single statement fails, it is up to the implementation whether or not to continue with remaining statements. Executes the statements added to the batch query. All queries are submitted in a batch. Do not add select statements to the bactch as they not valid in a JDBC 2.0 batch call

Returns:
A result object that contains the result of each query and an overall status
Throws:
DataAccessException - If a database error occurs.

beginDatabaseAction

protected Connection beginDatabaseAction()
                                  throws SQLException
Attempts to establish a connection to the database.

Returns:
A connection to the URL.
Throws:
SQLException - If unable to connect or no more connections available.

endDatabaseAction

protected void endDatabaseAction(ResultSet jdbcResultSet,
                                 Statement statement,
                                 Connection aConnection)
Releases the JDBC resources.

Parameters:
jdbcResultSet - The data produced by a query.
statement - The pre-compiled SQL statement.

Arch4J 1.1

Copyright © 2000-2004 SpiderLogic, a service of Wipfli Ullrich Bertelson LLP.