com.pow2.dao
Class AbstractDAO

java.lang.Object
  extended bycom.pow2.dao.AbstractDAO
Direct Known Subclasses:
DAO, DBUserDAO, HTMLDAO, IdGenerator, QueryDAO, ResultSetDataListImpl

public abstract class AbstractDAO
extends Object

Abstract Data access object.

Version:
$Id: AbstractDAO.java,v 1.1.1.1 2004/08/31 20:22:46 foxat Exp $
Author:
Luca Fossato

Field Summary
protected static org.apache.log4j.Category cat
          Log4J category.
 
Constructor Summary
protected AbstractDAO()
          Protected default constructor.
 
Method Summary
 boolean assertion(String tableName, String condition)
          Apply the input condition on the input table.
protected  void closeResources(Connection con, boolean commit)
          Commit or rollback any uncommitted transaction and close the input connection.
protected  void closeResources(ResultSet rs, Statement st, Connection con, boolean commit)
          Close the JDBC resultSet and statement objects, commit or rollback any uncommitted transaction and close the input connection.
protected  void closeResources(Statement st, Connection con, boolean commit)
          Close the JDBC statement object, commit or rollback any uncommitted transaction and close the input connection.
 long count(String tableName)
          Get the number of records from the input table.
 long count(String tableName, String condition)
          Get the number of records from the input table
 void delete(String tableName, String condition)
          Delete records from the input table, using the input condition.
 void delete(String tableName, String condition, Connection con)
          Delete records from the input table, using the input condition.
protected  String encode(String statement)
          Encode the input statement string, replacing all the "'" characters with "''" string.
 Connection getConnection()
          Return a JDBC Connection.
 Connection getConnection(int isolationLevel)
          Open a new transaction and return a JDBC Connection set with the input isolation level.
 long getNewKey()
          Get a new unique key value.
 boolean isDebugEnabled()
          Get the debug status.
protected  void populate(Object bean, ResultSet resultSet)
          Transfer a record data into the input value object bean.
protected  String setLike(String value)
          set a SQL LIKE statement
protected  String setLike(String value, boolean upperCase, int likeMode)
          set a SQL LIKE statement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cat

protected static org.apache.log4j.Category cat
Log4J category.

Constructor Detail

AbstractDAO

protected AbstractDAO()
Protected default constructor.

Method Detail

isDebugEnabled

public boolean isDebugEnabled()
Get the debug status.

Returns:
the debug status. True means that all the logging requests of priority DEBUG are enabled; false means that that logging requests are are disabled

assertion

public boolean assertion(String tableName,
                         String condition)
                  throws Exception
Apply the input condition on the input table.

Parameters:
tableName - the name of the table where to apply the input condition
condition - the where condition string
Returns:
true if the input condition retrieves at least one record from the input table; false otherwise
Throws:
Exception - if any error occurs

count

public long count(String tableName)
           throws Exception
Get the number of records from the input table.

Parameters:
tableName - the name of the table where to retrieve the records number
Returns:
the number of records of the input table
Throws:
Exception - if any error occurs

count

public long count(String tableName,
                  String condition)
           throws Exception
Get the number of records from the input table

Parameters:
tableName - the name of the table where to retrieve the records number
condition - the where condition string, or null (stands for "no condition")
Returns:
the records number of the input table
Throws:
Exception - if any error occurs

getNewKey

public long getNewKey()
               throws Exception
Get a new unique key value.

Returns:
a new unique key value
Throws:
Exception - Description of the Exception

delete

public void delete(String tableName,
                   String condition)
            throws Exception
Delete records from the input table, using the input condition.
This method supports the READ_COMMITTED isolation level to prevent dirty reads.

Parameters:
condition - the query string.
tableName - Description of the Parameter
Throws:
Exception - Description of the Exception

delete

public void delete(String tableName,
                   String condition,
                   Connection con)
            throws Exception
Delete records from the input table, using the input condition.
This method is useful for DbForms interceptor classes, because it doesn't close the connection object; the connection management is left to the application developer.

Parameters:
tableName - the name of the database table
condition - the query condition (a SQL 'where' clause without the 'WHERE' word);
con - the JDBC Connection object.
Throws:
Exception - if any error occurs

getConnection

public Connection getConnection()
                         throws Exception
Return a JDBC Connection.
note: should
NOT
be public !!

Returns:
a JDBC Connection
Throws:
Exception - Exception if any error occurs

getConnection

public Connection getConnection(int isolationLevel)
                         throws Exception
Open a new transaction and return a JDBC Connection set with the input isolation level.

Parameters:
isolationLevel - the isolation level to set the connection to
Returns:
the new "transactional" connection object
Throws:
Exception - if any error occurs

setLike

protected String setLike(String value)
set a SQL LIKE statement

Parameters:
value - the value to bound to the LIKE statement
Returns:
the LIKE statement

setLike

protected String setLike(String value,
                         boolean upperCase,
                         int likeMode)
set a SQL LIKE statement

Parameters:
value - the value to bound to the LIKE statement
upperCase - true to upper all the characters of the the input value string
likeMode - 0 stands for "contains": LIKE %${value}% 1 stands for "starts with": LIKE ${value}%
Returns:
the LIKE statement

encode

protected String encode(String statement)
Encode the input statement string, replacing all the "'" characters with "''" string.

Parameters:
statement - the SQL statement string to encode
Returns:
the encoded statement string

populate

protected void populate(Object bean,
                        ResultSet resultSet)
                 throws SQLException
Transfer a record data into the input value object bean.
The bean must simply have one or more accessors that match column names in the Map object generated from the input resultSet.
The columns that have a matching accessor will be used to populate the beans. Other accessors and columns are ignored.

Parameters:
bean - the value object to populate with the data retrieved from the input resultSet
resultSet - the resultSet used to retrieve the record data from
Throws:
SQLException - if any error occurs

closeResources

protected void closeResources(Connection con,
                              boolean commit)
                       throws SQLException
Commit or rollback any uncommitted transaction and close the input connection.
Call this method into a finally() clause.

Parameters:
con - the Connection object to close
commit - true to commit the transaction, false to rollback it
Throws:
SQLException - if any error occurs

closeResources

protected void closeResources(Statement st,
                              Connection con,
                              boolean commit)
                       throws SQLException
Close the JDBC statement object, commit or rollback any uncommitted transaction and close the input connection.
Call this method into a finally() clause.

Parameters:
st - the Statement object to close
con - the Connection object to close
commit - true to commit the transaction, false to rollback it
Throws:
SQLException - if any error occurs

closeResources

protected void closeResources(ResultSet rs,
                              Statement st,
                              Connection con,
                              boolean commit)
                       throws SQLException
Close the JDBC resultSet and statement objects, commit or rollback any uncommitted transaction and close the input connection.
Call this method into a finally() clause.

Parameters:
rs - the recordSet object to close
con - the Connection object to close
st - the statement object to close
commit - true to commit the connection, false to rollback it
Throws:
SQLException - if any error occurs


Copyright © 2002-2004 Power Of Two S.R.L. All Rights Reserved.