|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dartra.standard.dao.jdbc.BaseDAO
Abstract base class for all standard data access objects using JDBC. This class provides utility methods for use in subclasses. It is a Layer Supertype [Fowler].
Users of DAOs extending this class should make sure they call the close() method on the DAO to release all resources. Normally the usage pattern will be:
MyDAO dao=someDAOFactory.createMyDAO();
Connection conn=myDataSource.getConnection();
try {
dao.init(conn);
... //use the DAO
conn.commit();
}
catch (DataAccessException e) {
conn.rollback();
}
finally {
dao.close();
}
conn.close(); //if no longer needed
Since DAOs extending this class are JDBC based, the init() method
expects a standard JDBC connection.
JDBCConnection| Field Summary | |
protected java.util.Map |
loadedObjects
This map serves as an Identity Map [Fowler] to make sure that each object is only loaded once. |
| Constructor Summary | |
protected |
BaseDAO(org.dartra.framework.dao.DAOFactory factory)
Constructor used by subclasses. |
| Method Summary | |
void |
close()
|
protected abstract org.dartra.framework.Persistent |
createPersistentObject(java.lang.Object id,
java.sql.ResultSet rs)
Create a persistent domain object with given id based on the data available in the current row of given result set. |
java.lang.Object |
executeQuery(PreparedStatementCreator psc)
Execute a query that returns a single result (so the result table has 1 row and 1 column). |
void |
executeQuery(PreparedStatementCreator psc,
ResultSetRowHandler rsrh)
Execute a query. |
java.lang.Object |
executeQuery(java.lang.String sql)
Execute a static query that returns a single result (so the result table has 1 row and 1 column). |
void |
executeQuery(java.lang.String sql,
ResultSetRowHandler rsrh)
Execute a static query, a query with no variable parameters. |
int |
executeUpdate(PreparedStatementCreator psc)
Execute an SQL update statement. |
org.dartra.framework.dao.Connection |
getConnection()
|
org.dartra.framework.dao.DAOFactory |
getDAOFactory()
|
protected java.lang.Object |
getPersistentObjectId(java.sql.ResultSet rs)
Get the persisten store id from the current row in given result set. |
void |
init(org.dartra.framework.dao.Connection conn)
|
protected org.dartra.framework.Persistent |
loadPersistentObject(java.sql.ResultSet rs)
Template method to load a persistent object from the current row in given result set. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.util.Map loadedObjects
This map serves as an Identity Map [Fowler] to make sure that each object is only loaded once.
| Constructor Detail |
protected BaseDAO(org.dartra.framework.dao.DAOFactory factory)
Constructor used by subclasses. This creates a new DAO, created by given DAO factory.
| Method Detail |
public void init(org.dartra.framework.dao.Connection conn)
throws org.dartra.framework.dao.DataAccessException
init in interface org.dartra.framework.dao.DataAccessObjectorg.dartra.framework.dao.DataAccessException
public void close()
throws org.dartra.framework.dao.DataAccessException
close in interface org.dartra.framework.dao.DataAccessObjectorg.dartra.framework.dao.DataAccessExceptionpublic org.dartra.framework.dao.DAOFactory getDAOFactory()
getDAOFactory in interface org.dartra.framework.dao.DataAccessObjectpublic org.dartra.framework.dao.Connection getConnection()
getConnection in interface org.dartra.framework.dao.DataAccessObject
protected org.dartra.framework.Persistent loadPersistentObject(java.sql.ResultSet rs)
throws java.sql.SQLException,
org.dartra.framework.dao.DataAccessException
Template method to load a persistent object from the current row in given result set. This method also manages the map of loaded objects.
Subclasses should redefine the getPersistentObjectId() and
createPersistentObject() methods to fill out this algorithm.
java.sql.SQLException
org.dartra.framework.dao.DataAccessException
protected java.lang.Object getPersistentObjectId(java.sql.ResultSet rs)
throws java.sql.SQLException,
org.dartra.framework.dao.DataAccessException
Get the persisten store id from the current row in given result set.
The default implementation of this method takes the field named "ID" from the current row. Override this if necessary.
java.sql.SQLException
org.dartra.framework.dao.DataAccessException
protected abstract org.dartra.framework.Persistent createPersistentObject(java.lang.Object id,
java.sql.ResultSet rs)
throws java.sql.SQLException,
org.dartra.framework.dao.DataAccessException
Create a persistent domain object with given id based on the data available in the current row of given result set.
java.sql.SQLException
org.dartra.framework.dao.DataAccessException
public int executeUpdate(PreparedStatementCreator psc)
throws org.dartra.framework.dao.DataAccessException
Execute an SQL update statement.
psc - The callback handler that will create the prepared statement for
the update.
org.dartra.framework.dao.DataAccessException
public java.lang.Object executeQuery(java.lang.String sql)
throws org.dartra.framework.dao.DataAccessException
Execute a static query that returns a single result (so the result table has 1 row and 1 column). If multiple rows are returned by the query, the value of the first column in the first row is returned.
sql - The SQL query string.
org.dartra.framework.dao.DataAccessException
public java.lang.Object executeQuery(PreparedStatementCreator psc)
throws org.dartra.framework.dao.DataAccessException
Execute a query that returns a single result (so the result table has 1 row and 1 column). If multiple rows are returned by the query, the value of the first column in the first row is returned.
psc - The callback handler that will create the prepared statement for
the query.
org.dartra.framework.dao.DataAccessException
public void executeQuery(java.lang.String sql,
ResultSetRowHandler rsrh)
throws org.dartra.framework.dao.DataAccessException
Execute a static query, a query with no variable parameters.
sql - The SQL query string.rsrh - The callback handler that process result rows for the query.
org.dartra.framework.dao.DataAccessException
public void executeQuery(PreparedStatementCreator psc,
ResultSetRowHandler rsrh)
throws org.dartra.framework.dao.DataAccessException
Execute a query.
psc - The callback handler that will create the prepared statement for
the query.rsrh - The callback handler that will process result rows for the query.
org.dartra.framework.dao.DataAccessException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||