org.opensubsystems.core.persist.db
Class DatabaseReadMultipleOperation
java.lang.Object
org.opensubsystems.core.persist.db.DatabaseOperation
org.opensubsystems.core.persist.db.DatabaseReadOperation
org.opensubsystems.core.persist.db.DatabaseReadMultipleOperation
- All Implemented Interfaces:
- DatabaseOperations
public abstract class DatabaseReadMultipleOperation
- extends DatabaseReadOperation
Adapter to simplify writing of database reads which read multiple items,
which takes care of requesting and returning connections, transaction
management, query preparation and exception handling. To use this adapter you
just need to define anonymous class and override method performOperation to
provide the actual database read. Optionally you may want to override one of
the handleXXX methods to provide custom error handling.
This class is optimized for preparing queries, which need to retrieve multiple
items from the database.
Example of method in factory which reads data using query produced by its schema
public int[] getActualIds(
final int iDomainId,
String strIds,
SimpleRule listSecurityData
) throws OSSException
{
int[] arrActual = null;
DatabaseReadOperation dbop = new DatabaseReadMultipleOperation(
this, m_schema.getSelectActualIds(strIds, listSecurityData),
m_schema, dataType)
{
protected Object performOperation(
DatabaseFactoryImpl dbfactory,
Connection cntConnection,
PreparedStatement pstmQuery
) throws OSSException,
SQLException
{
pstmQuery.setInt(1, iDomainId);
return DatabaseUtils.loadMultipleIntsAsArray(pstmQuery);
}
};
arrActual = (int[])dbop.executeRead();
return arrActual;
}
- Version:
- $Id: DatabaseReadMultipleOperation.java,v 1.7 2007/01/28 06:54:42 bastafidli Exp $
- Author:
- Miro Halas
- Code reviewer:
- Miro Halas
- Code reviewed:
- 1.2 2005/10/25 05:17:37 bastafidli
|
Method Summary |
protected java.sql.PreparedStatement |
prepareQuery(DatabaseFactoryImpl dbfactory,
java.sql.Connection cntConnection,
java.lang.String strQuery)
Prepare the query if it was specified using the provided connection. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DatabaseReadMultipleOperation
public DatabaseReadMultipleOperation(DatabaseFactoryImpl factory)
- Constructor to use when the database read doesn't require any
prepared statement.
- Parameters:
factory - - factory which is executing this operation
DatabaseReadMultipleOperation
public DatabaseReadMultipleOperation(DatabaseFactoryImpl factory,
java.lang.String strQueryToPrepare,
DatabaseSchema schema)
- Constructor to use when database read doesn't require any prepared
statement.
- Parameters:
factory - - factory which is executing this operationstrQueryToPrepare - - query which should be used to construct prepared
statement which will be passed in to executeUpdateschema - - database schema used with this operation
prepareQuery
protected java.sql.PreparedStatement prepareQuery(DatabaseFactoryImpl dbfactory,
java.sql.Connection cntConnection,
java.lang.String strQuery)
throws OSSException,
java.sql.SQLException
- Prepare the query if it was specified using the provided connection.
- Overrides:
prepareQuery in class DatabaseReadOperation
- Parameters:
dbfactory - - database factory executing this operationcntConnection - - ready to use connection to perform the database
operation. No need to return this connection.strQuery - - query to prepare, might be null or empty if there is
nothing to prepare
- Returns:
- PreparedStatement - prepared statement for query passed in as a
parameter to the constructor. If no query was
passed into constructor, this will be null.
- Throws:
OSSException - - an error has occured
java.sql.SQLException - - an error has occured
Copyright © 2003 - 2006 OpenSubsystems s.r.o.