org.exolab.castor.dtx
Class DTXQuery

java.lang.Object
  extended by org.exolab.castor.dtx.DTXQuery

public class DTXQuery
extends java.lang.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.2 $ $Date: 2005/03/05 13:41:49 $
Author:
Evan Prodromou

Field Summary
protected  java.util.HashMap _classes
           
protected  ClassMapping _clsMapping
           
protected  java.util.HashMap _cols
           
protected  DTXEngine _eng
           
protected  org.xml.sax.DocumentHandler _handler
           
protected  java.util.ArrayList _ids
           
protected  int _lastCol
           
protected  java.io.PrintWriter _logWriter
           
protected  java.lang.String _objName
           
protected  java.lang.String _objType
           
protected  java.sql.PreparedStatement _stmt
           
 
Constructor Summary
DTXQuery()
           
 
Method Summary
 void bind(int param, boolean value)
          Binds a boolean value to a parameter in the query.
 void bind(int param, double value)
          Binds a double value to a parameter in the query.
 void bind(int param, float value)
          Binds a float value to a parameter in the query.
 void bind(int param, int value)
          Binds an integer value to a parameter in the query.
 void bind(int param, long value)
          Binds a long integer value to a parameter in the query.
 void bind(int param, java.lang.Object value)
          Binds an Object value to a parameter in the query.
 void bind(int param, java.lang.String value)
          Binds an String value to a parameter in the query.
protected  void emitSaxEvents(java.sql.ResultSet rs)
           
protected  boolean emitSaxInt(java.sql.ResultSet rs, int idIndex)
           
 void execute()
          This method executes the query.
protected  void initQuery(ClassMapping clsMapping, QueryExpression expr)
           
protected  java.lang.String parseOQL(java.lang.String oql)
           
(package private)  void prepare(java.lang.String oql)
           
(package private)  void setEngine(DTXEngine eng)
           
 void setHandler(org.xml.sax.DocumentHandler handler)
          Set the DocumentHandler that will receive the results (as SAX events) for this query.
 void setLogWriter(java.io.PrintWriter logWriter)
          Set the log writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_eng

protected DTXEngine _eng

_handler

protected org.xml.sax.DocumentHandler _handler

_logWriter

protected java.io.PrintWriter _logWriter

_stmt

protected java.sql.PreparedStatement _stmt

_objName

protected java.lang.String _objName

_objType

protected java.lang.String _objType

_clsMapping

protected ClassMapping _clsMapping

_ids

protected java.util.ArrayList _ids

_lastCol

protected int _lastCol

_cols

protected java.util.HashMap _cols

_classes

protected java.util.HashMap _classes
Constructor Detail

DTXQuery

DTXQuery()
Method Detail

setHandler

public void setHandler(org.xml.sax.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(java.io.PrintWriter logWriter)
Set the log writer.

Parameters:
logWriter - The log writer to use.

bind

public void bind(int param,
                 java.lang.Object value)
          throws DTXException
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.
Throws:
DTXException

bind

public void bind(int param,
                 java.lang.String value)
          throws DTXException
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.
Throws:
DTXException

bind

public void bind(int param,
                 int value)
          throws DTXException
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.
Throws:
DTXException

bind

public void bind(int param,
                 long value)
          throws DTXException
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.
Throws:
DTXException

bind

public void bind(int param,
                 float value)
          throws DTXException
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.
Throws:
DTXException

bind

public void bind(int param,
                 double value)
          throws DTXException
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.
Throws:
DTXException

bind

public void bind(int param,
                 boolean value)
          throws DTXException
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.
Throws:
DTXException

execute

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

Throws:
DTXException

setEngine

void setEngine(DTXEngine eng)

prepare

void prepare(java.lang.String oql)
       throws DTXException
Throws:
DTXException

emitSaxEvents

protected void emitSaxEvents(java.sql.ResultSet rs)
                      throws DTXException
Throws:
DTXException

emitSaxInt

protected boolean emitSaxInt(java.sql.ResultSet rs,
                             int idIndex)
                      throws DTXException
Throws:
DTXException

parseOQL

protected java.lang.String parseOQL(java.lang.String oql)
                             throws DTXException
Throws:
DTXException

initQuery

protected void initQuery(ClassMapping clsMapping,
                         QueryExpression expr)
                  throws DTXException
Throws:
DTXException


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