org.exolab.castor.dtx

Class DTXQuery

public class DTXQuery extends Object

A single query that takes OQL query language, reads data from an RDBMS, and returns the results as SAX events. The query can be parameterized, and be re-used with different bound values. There are currently some severe limitations on the contents of the OQL query. The query needs to be a SELECT and must return a single class. However, it can handle multiple returned objects, which are sent to the DocumentHandler as multiple documents. DTXQuery's can't be created on their own; use the DTXEngine to prepare a new query. An additional note: the bind() methods take the parameters in order that they appear, NOT using the number value of the parameter name. So, if you have a query like:
... WHERE foo.id = $2 AND bar.name = $1 ... 
then the statement bind(1, 12) will bind the value 12 to the first parameter, even though it's named "$2." This may or may not be changed in future releases.

Version: $Revision: 1.1.1.1 $ $Date: 2003/03/03 07:08:05 $

Author: Evan Prodromou

Field Summary
protected HashMap_classes
protected ClassMapping_clsMapping
protected HashMap_cols
protected DTXEngine_eng
protected DocumentHandler_handler
protected ArrayList_ids
protected int_lastCol
protected PrintWriter_logWriter
protected String_objName
protected String_objType
protected PreparedStatement_stmt
Constructor Summary
DTXQuery()
Method Summary
voidbind(int param, Object value)
Binds an Object value to a parameter in the query.
voidbind(int param, String value)
Binds an String value to a parameter in the query.
voidbind(int param, int value)
Binds an integer value to a parameter in the query.
voidbind(int param, long value)
Binds a long integer value to a parameter in the query.
voidbind(int param, float value)
Binds a float value to a parameter in the query.
voidbind(int param, double value)
Binds a double value to a parameter in the query.
voidbind(int param, boolean value)
Binds a boolean value to a parameter in the query.
protected voidemitSaxEvents(ResultSet rs)
protected booleanemitSaxInt(ResultSet rs, int idIndex)
voidexecute()
This method executes the query.
protected voidinitQuery(ClassMapping clsMapping, QueryExpression expr)
protected StringparseOQL(String oql)
voidprepare(String oql)
voidsetEngine(DTXEngine eng)
voidsetHandler(DocumentHandler handler)
Set the DocumentHandler that will receive the results (as SAX events) for this query.
voidsetLogWriter(PrintWriter logWriter)
Set the DocumentHandler that will receive the results (as SAX events) for this query.

Field Detail

_classes

protected HashMap _classes

_clsMapping

protected ClassMapping _clsMapping

_cols

protected HashMap _cols

_eng

protected DTXEngine _eng

_handler

protected DocumentHandler _handler

_ids

protected ArrayList _ids

_lastCol

protected int _lastCol

_logWriter

protected PrintWriter _logWriter

_objName

protected String _objName

_objType

protected String _objType

_stmt

protected PreparedStatement _stmt

Constructor Detail

DTXQuery

DTXQuery()

Method Detail

bind

public void bind(int param, Object value)
Binds an Object value to a parameter in the query.

Parameters: param 1-based index of the param (see note above). value Object to bind.

bind

public void bind(int param, String value)
Binds an String value to a parameter in the query.

Parameters: param 1-based index of the param (see note above). value String to bind.

bind

public void bind(int param, int value)
Binds an integer value to a parameter in the query.

Parameters: param 1-based index of the param (see note above). value int to bind.

bind

public void bind(int param, long value)
Binds a long integer value to a parameter in the query.

Parameters: param 1-based index of the param (see note above). value long integer to bind.

bind

public void bind(int param, float value)
Binds a float value to a parameter in the query.

Parameters: param 1-based index of the param (see note above). value float to bind.

bind

public void bind(int param, double value)
Binds a double value to a parameter in the query.

Parameters: param 1-based index of the param (see note above). value double to bind.

bind

public void bind(int param, boolean value)
Binds a boolean value to a parameter in the query.

Parameters: param 1-based index of the param (see note above). value boolean to bind.

emitSaxEvents

protected void emitSaxEvents(ResultSet rs)

emitSaxInt

protected boolean emitSaxInt(ResultSet rs, int idIndex)

execute

public void execute()
This method executes the query. All results of the query are sent to the DocumentHandler specified by setHandler() as SAX events.

Parameters: handler The DocumentHandler to use.

initQuery

protected void initQuery(ClassMapping clsMapping, QueryExpression expr)

parseOQL

protected String parseOQL(String oql)

prepare

void prepare(String oql)

setEngine

void setEngine(DTXEngine eng)

setHandler

public void setHandler(DocumentHandler handler)
Set the DocumentHandler that will receive the results (as SAX events) for this query. By default, the query will use the document handler of its DTXEngine. Changing the DocumentHandler in the middle of a query is ill-advised.

Parameters: handler The DocumentHandler to use.

setLogWriter

public void setLogWriter(PrintWriter logWriter)
Set the DocumentHandler that will receive the results (as SAX events) for this query. By default, the query will use the document handler of its DTXEngine.

Parameters: handler The DocumentHandler to use.

Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com