Package org.exolab.castor.jdo.engine
Class SQLQuery
- java.lang.Object
-
- org.exolab.castor.jdo.engine.SQLQuery
-
- All Implemented Interfaces:
PersistenceQuery
public final class SQLQuery extends java.lang.Object implements PersistenceQuery
- Since:
- 1.0
- Version:
- $Revision: 8104 $ $Date: 2006-04-11 15:26:07 -0600 (Tue, 11 Apr 2006) $
- Author:
- Assaf Arkin, Thomas Yip, Bruce Snyder, Werner Guttmann, Ralf Joachim
-
-
Constructor Summary
Constructors Constructor Description SQLQuery(SQLEngine engine, PersistenceFactory factory, java.lang.String sql, java.lang.Class[] types, boolean isCallSql)
Creates an instance of SQLQuery.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
absolute(int row)
Move to an absolute position within a ResultSet.void
close()
Close the query and release all resources held by the query.void
execute(java.lang.Object conn, AccessMode accessMode, boolean scrollable)
Execute the query with the give connection and lock type.void
fetch(ProposedEntity proposedObject)
Loades the object.java.lang.Class
getResultType()
Returns the type of object returned by this query.Identity
nextIdentity(Identity identity)
Returns the identity of the next object to be returned.void
setParameter(int index, java.lang.Object value)
Sets the value of a paramter.int
size()
Uses the underlying db's cursors to move to the last row in the result set, get the row number via getRow(), then move back to where ever the user was positioned in the resultset.
-
-
-
Constructor Detail
-
SQLQuery
SQLQuery(SQLEngine engine, PersistenceFactory factory, java.lang.String sql, java.lang.Class[] types, boolean isCallSql)
Creates an instance of SQLQuery.- Parameters:
engine
- SQLEngine instancesql
- The SQL statement to executetypes
- Types of the class used.isCallSql
- true if the SQL is issued as part of a CALL SQL statement.
-
-
Method Detail
-
setParameter
public void setParameter(int index, java.lang.Object value) throws java.lang.ArrayIndexOutOfBoundsException, java.lang.IllegalArgumentException
Description copied from interface:PersistenceQuery
Sets the value of a paramter. Will complain if the parameter is not of the specified type.- Specified by:
setParameter
in interfacePersistenceQuery
- Parameters:
index
- The parameter indexvalue
- The parameter value- Throws:
java.lang.ArrayIndexOutOfBoundsException
java.lang.IllegalArgumentException
-
getResultType
public java.lang.Class getResultType()
Description copied from interface:PersistenceQuery
Returns the type of object returned by this query.- Specified by:
getResultType
in interfacePersistenceQuery
- Returns:
- The type of object returned by this query
-
absolute
public boolean absolute(int row) throws PersistenceException
Move to an absolute position within a ResultSet. use the jdbc 2.0 method to move to an absolute position in the resultset.- Specified by:
absolute
in interfacePersistenceQuery
- Parameters:
row
- The row to move to- Returns:
- True if the move was successful.
- Throws:
PersistenceException
- Indicates a problem in moving to an absolute position.
-
size
public int size() throws PersistenceException
Uses the underlying db's cursors to move to the last row in the result set, get the row number via getRow(), then move back to where ever the user was positioned in the resultset.- Specified by:
size
in interfacePersistenceQuery
- Returns:
- The size of the current result set.
- Throws:
PersistenceException
- If the excution of this method failed.
-
execute
public void execute(java.lang.Object conn, AccessMode accessMode, boolean scrollable) throws PersistenceException
Description copied from interface:PersistenceQuery
Execute the query with the give connection and lock type. After a successful return the query results will be returned by callingPersistenceQuery.nextIdentity(org.exolab.castor.persist.spi.Identity)
andPersistenceQuery.fetch(org.castor.persist.ProposedEntity)
. The query parameters will be reset. A new query may be issued by providing new query parameters and callingPersistenceQuery.execute(Object, AccessMode, boolean)
.- Specified by:
execute
in interfacePersistenceQuery
- Parameters:
conn
- An open connectionaccessMode
- The access mode (null equals shared)scrollable
- The db cursor mode.- Throws:
PersistenceException
- An invalid query or an error reported by the persistence engine.
-
nextIdentity
public Identity nextIdentity(Identity identity) throws PersistenceException
Description copied from interface:PersistenceQuery
Returns the identity of the next object to be returned. Calling this method multiple time will skip objects. When the result set has been exhuasted, this method will return null.- Specified by:
nextIdentity
in interfacePersistenceQuery
- Parameters:
identity
- The identity of the previous object, null if this method is called for the first time- Returns:
- The identity of the next object, null if the result set has been exhausted
- Throws:
PersistenceException
- An error reported by the persistence engine
-
close
public void close()
Description copied from interface:PersistenceQuery
Close the query and release all resources held by the query.- Specified by:
close
in interfacePersistenceQuery
-
fetch
public void fetch(ProposedEntity proposedObject) throws PersistenceException
Description copied from interface:PersistenceQuery
Loades the object. This method must be called immediately afterPersistenceQuery.nextIdentity(org.exolab.castor.persist.spi.Identity)
with the same identity.If the object is locked by another transaction this method will block until the lock is released, or a timeout occured. If a timeout occurs or the object has been deleted by the other transaction, this method will report an
ObjectNotFoundException
. The query may proceed to the next identity.This method is equivalent to
Persistence.load(java.lang.Object, org.castor.persist.ProposedEntity, org.exolab.castor.persist.spi.Identity, org.exolab.castor.mapping.AccessMode)
with a known cache engine and access mode and acts on the query results rather than issuing a new query to load the object.- Specified by:
fetch
in interfacePersistenceQuery
- Parameters:
proposedObject
- The fields to load into- Throws:
PersistenceException
- The object was not found in persistent storage or any other persistence error occured.- See Also:
PersistenceQuery.fetch( org.castor.persist.ProposedEntity)
-
-