net.wgen.op.db
Class DatabaseCall

java.lang.Object
  extended bynet.wgen.op.db.DatabaseCall
All Implemented Interfaces:
java.io.Serializable

public class DatabaseCall
extends java.lang.Object
implements java.io.Serializable

Represents a call to the database. This class handles Parameterized Queries, Procedures, and Functions, and contains information about what application and what Op initiated it, and information about the execution of it.

Version:
$Id: DatabaseCall.html,v 1.2 2007/01/28 04:09:36 paulfeuer Exp $
Author:
Paul Feuer, Wireless Generation, Inc.
See Also:
Serialized Form

Field Summary
private  java.lang.String _callText
          The text of the call which could be a parameterized query, or the name of a procedure or function.
private  int _callType
          The type of call this is QUERY, PROCEDURE, or FUNCTION.
private  java.lang.String _dataSourceName
          The datasource against which to execute the call.
private  CallExecutionInfo _executionInfo
          Information about the execution of this call.
private  java.util.Map _idxToParameter
          The map of parameter index to Parameter for this call.
private  org.apache.log4j.Logger _logger
          The logger to use when executing this call.
private  Op _opOwner
          The Op that is making this call.
private  java.util.Map _options
          HandlingOptions for this call.
private  java.util.Map _rsIdxToResults
          Result Sets returned by Statement getResults method.
private static java.lang.Integer DEFAULT_TRUNCATE_AT_LENGTH_IN_CALL_TO_STRING
          When constructing the string representation of the call, use this value as default for truncating long values.
static int TYPE_FUNCTION
          Identifier for a function.
static int TYPE_PROCEDURE
          Identifier for a stored procedure.
static int TYPE_QUERY
          Identifier for a parameterized query.
 
Constructor Summary
DatabaseCall(java.lang.String callText, Op opOwner, int callType)
           
 
Method Summary
 java.lang.String getCallText()
          If the call is a query, this is the parameterized text of the query, and if this is a callable statement, it can simply be the function or procedure name.
 int getCallType()
          The JDBC call type.
 java.lang.String getDataSourceName()
           
 CallExecutionInfo getExecutionInfo()
          Information about the execution of the call.
 java.util.Map getIdxToParameter()
          A map of parameter index to Parameter object, starting at 1.
 org.apache.log4j.Logger getLogger()
           
 Op getOpOwner()
          The Op which instantiated this call.
 java.util.Map getOptions()
           
 Parameter getParameter(int idx)
          Get a parameter using its index.
 java.lang.String getParametersAsString()
          A string representation of the parameter set.
 java.util.Map getResultSetIdxToResults()
          For ResultSets returned in the getResultSet methods in Statement, one-based index to Collections representing the transformed ResultSets.
 java.util.Collection getReturnedResults(int idx)
          Transformed ResultSets returned thru the Statement getResultSet methods.
 void setDataSourceName(java.lang.String dataSourceName)
          The name of the data source against which the call will be executed.
 void setParameters(int returnJdbcType, java.lang.Object[] parameters)
          Set the parameters of the call.
 void setParameters(java.lang.Object[] parameters)
          Set the parameters of the call.
 void setParameters(Parameter returnParameter, java.lang.Object[] parameters)
          Set the parameters of the call.
 java.lang.String toString()
           
 java.lang.String toValuePopulatedString()
          A string representation of the statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_TRUNCATE_AT_LENGTH_IN_CALL_TO_STRING

private static final java.lang.Integer DEFAULT_TRUNCATE_AT_LENGTH_IN_CALL_TO_STRING
When constructing the string representation of the call, use this value as default for truncating long values.


TYPE_QUERY

public static final int TYPE_QUERY
Identifier for a parameterized query.

See Also:
Constant Field Values

TYPE_PROCEDURE

public static final int TYPE_PROCEDURE
Identifier for a stored procedure.

See Also:
Constant Field Values

TYPE_FUNCTION

public static final int TYPE_FUNCTION
Identifier for a function.

See Also:
Constant Field Values

_callText

private final java.lang.String _callText
The text of the call which could be a parameterized query, or the name of a procedure or function.


_opOwner

private final Op _opOwner
The Op that is making this call.


_callType

private final int _callType
The type of call this is QUERY, PROCEDURE, or FUNCTION.


_idxToParameter

private final java.util.Map _idxToParameter
The map of parameter index to Parameter for this call.


_rsIdxToResults

private final java.util.Map _rsIdxToResults
Result Sets returned by Statement getResults method.


_logger

private final transient org.apache.log4j.Logger _logger
The logger to use when executing this call.


_executionInfo

private final CallExecutionInfo _executionInfo
Information about the execution of this call.


_dataSourceName

private java.lang.String _dataSourceName
The datasource against which to execute the call.


_options

private java.util.Map _options
HandlingOptions for this call.

See Also:
HandlingOption
Constructor Detail

DatabaseCall

public DatabaseCall(java.lang.String callText,
                    Op opOwner,
                    int callType)
Method Detail

getLogger

public org.apache.log4j.Logger getLogger()

getCallText

public java.lang.String getCallText()
If the call is a query, this is the parameterized text of the query, and if this is a callable statement, it can simply be the function or procedure name. The question marks in a callable statement will be filled automatically in based on the number of inputs and outputs.


getOpOwner

public Op getOpOwner()
The Op which instantiated this call.


getCallType

public int getCallType()
The JDBC call type.


getDataSourceName

public java.lang.String getDataSourceName()

setDataSourceName

public void setDataSourceName(java.lang.String dataSourceName)
The name of the data source against which the call will be executed.

Parameters:
dataSourceName -

getOptions

public java.util.Map getOptions()

getExecutionInfo

public CallExecutionInfo getExecutionInfo()
Information about the execution of the call.

Returns:
information about the execution of the call

getIdxToParameter

public java.util.Map getIdxToParameter()
A map of parameter index to Parameter object, starting at 1.

Returns:
a map of parameter index to Parameter object, starting at 1

getParameter

public Parameter getParameter(int idx)
Get a parameter using its index.

Parameters:
idx - the index of the parameter, should be 1 based.
Returns:
the Parameter
Throws:
java.lang.NullPointerException - if the parameter is not found at the index

getReturnedResults

public java.util.Collection getReturnedResults(int idx)
Transformed ResultSets returned thru the Statement getResultSet methods.

Parameters:
idx - the one-based index of the returned results
Returns:
the ResultSet transformed into a Collection

getResultSetIdxToResults

public java.util.Map getResultSetIdxToResults()
For ResultSets returned in the getResultSet methods in Statement, one-based index to Collections representing the transformed ResultSets.


setParameters

public final void setParameters(java.lang.Object[] parameters)
Set the parameters of the call. The parameter array can be a mix of Objects and Parameters. If a member of the array is NOT a Paramter, a Parameter is constructed using the one-argument Object constructor, which considers the value an input and will try and look up the jdbcType. For more complicated parameters, or INOUT parameters, you need to use a proper Parameter object. Nullable input parameters should be sent in as full parameters, since the class will not be able to determine a type. If one does send in a null, you'll see a warning logged about it and you'll get a NullPointerException. For null Parameters, either use one of the Parameter constructors, or use one of the static nullable* methods on the Parameter class.

Parameters:
parameters - the parameter set to be applied starting at index 1
Throws:
java.lang.NullPointerException - if one of the parameters is null, since it will not have enough information to determine the jdbc type.
See Also:
Parameter.Parameter(Object)

setParameters

public final void setParameters(Parameter returnParameter,
                                java.lang.Object[] parameters)
Set the parameters of the call. The returnParameter is applied at index 1 and the remaining parameters are applied starting at index 2. This should really only be used for FUNCTION calls.

Parameters:
returnParameter - the call's return Parameter
parameters - the remaining parameters of the call
See Also:
setParameters(Object[])

setParameters

public final void setParameters(int returnJdbcType,
                                java.lang.Object[] parameters)
Set the parameters of the call. The returnJdbcType is used as an implicit OUT Parameter at index 1, and the remaining parameters are applied starting at index 2. This should really only be used for FUNCTION calls.

Parameters:
returnJdbcType - the type of the call's return
parameters - the remaining parameters of the call
See Also:
setParameters(Object[])

toString

public java.lang.String toString()

getParametersAsString

public java.lang.String getParametersAsString()
A string representation of the parameter set.

Returns:
A string representation of the parameter set

toValuePopulatedString

public java.lang.String toValuePopulatedString()
A string representation of the statement. The call text is turned into a parameterized string if it's not one already. Long string values are truncated either at the DEFAULT_TRUNCATE_AT_LENGTH_IN_CALL_TO_STRING in this class, or at the position stored in the calls options at key HandlingOption.PROP_TRUNCATE_AT_LENGTH_IN_CALL_TO_STRING. Byte arrays appear simply as "byte[]" and ArrayParameters are printed out using the List.toString(), but replacing square braces with round parens.

Returns:
the string representation of the statement