Top Description Fields Constructors Methods
com.ziclix.python.sql

public Class DataHandler

extends Object
Class Inheritance
Known Direct Subclasses
com.ziclix.python.sql.FilterDataHandler, com.ziclix.python.sql.Jython22DataHandler
Imports
java.io.BufferedReader, .ByteArrayOutputStream, .IOException, .InputStream, .Reader, .StringReader, java.lang.reflect.Constructor, java.math.BigDecimal, .BigInteger, java.sql.Blob, .CallableStatement, .Clob, .Date, .PreparedStatement, .ResultSet, .SQLException, .Statement, .Time, .Timestamp, .Types, org.python.core.Py, .PyFile, .PyList, .PyObject

The DataHandler is responsible mapping the JDBC data type to a Jython object. Depending on the version of the JDBC implementation and the particulars of the driver, the type mapping can be significantly different. This interface can also be used to change the behaviour of the default mappings provided by the cursor. This might be useful in handling more complicated data types such as BLOBs, CLOBs and Arrays.
Author
brian zimmer

Field Summary

Modifier and TypeField and Description
private static final int
INITIAL_SIZE

Default size for buffers.

private static final String[]

Constructor Summary

AccessConstructor and Description
public
DataHandler()

Handle most generic Java data types.

Method Summary

Modifier and TypeMethod and Description
public PyObject

Returns:

a list of datahandlers
__chain__
()

Returns a list of datahandlers chained together through the use of delegation.

public static final boolean

Returns:

true if the object is null and was set on the statement, false otherwise
checkNull
(PreparedStatement stmt, int index, PyObject object, int type)

Handles checking if the object is null or None and setting it on the statement.

protected final SQLException
public String
getMetaDataName(PyObject name)

Some database vendors are case sensitive on calls to DatabaseMetaData, most notably Oracle.

public Procedure

Returns:

an instance of a Procedure
getProcedure
(PyCursor
an open cursor
cursor
,
PyObject
the name of the procedure to invoke
name
)

A factory method for determing the correct procedure class to use per the cursor type.

public PyObject
getPyObject(ResultSet
the current ResultSet set to the current row
set
,
int
the column number (adjusted properly for JDBC)
col
,
int
the column type
type
)

Given a ResultSet, column and type, return the appropriate Jython object.

public PyObject
getPyObject(CallableStatement
the CallableStatement
stmt
,
int
the column number (adjusted properly for JDBC)
col
,
int
the column type
type
)

Given a CallableStatement, column and type, return the appropriate Jython object.

public PyObject

Returns:

the row id of the last executed statement or None
getRowId
(Statement
the current statement
stmt
)

Returns the row id of the last executed statement.

public static final DataHandler

Returns:

a DataHandler configured for the VM version
getSystemDataHandler
()

Build the DataHandler chain depending on the VM.

public void
postExecute(Statement stmt)

A callback after successfully executing the statement.

public void
preExecute(Statement stmt)

A callback prior to each execution of the statement.

public static final byte[]

Returns:

the contents of the InputStream a byte[]
read
(InputStream stream)

Consume the InputStream into an byte array and close the InputStream.

public static String

Returns:

the contents of the Reader as a String
read
(Reader reader)

Consume the Reader into a String and close the Reader.

public void
registerOut(CallableStatement statement, int
the JDBC offset column number
index
,
int
the column as from DatabaseMetaData (eg, procedureColumnOut)
colType
,
int
the JDBC datatype from Types
dataType
,
String
the JDBC datatype name
dataTypeName
)

Called when a stored procedure or function is executed and OUT parameters need to be registered with the statement.

public void
setJDBCObject(PreparedStatement
the current PreparedStatement
stmt
,
int
the index for which this object is bound
index
,
PyObject
the PyObject in question
object
)

Any .execute() which uses prepared statements will receive a callback for deciding how to map the PyObject to the appropriate JDBC type.

public void
setJDBCObject(PreparedStatement
the current PreparedStatement
stmt
,
int
the index for which this object is bound
index
,
PyObject
the PyObject in question
object
,
int
the java.sql.Types for which this PyObject should be bound
type
)

Any .execute() which uses prepared statements will receive a callback for deciding how to map the PyObject to the appropriate JDBC type.

public String
toString()

Overrides java.lang.Object.toString.

Returns the classname of this datahandler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

INITIAL_SIZEback to summary
private static final int INITIAL_SIZE

Default size for buffers.

SYSTEM_DATAHANDLERSback to summary
private static final String[] SYSTEM_DATAHANDLERS

Constructor Detail

DataHandlerback to summary
public DataHandler()

Handle most generic Java data types.

Method Detail

__chain__back to summary
public PyObject __chain__()

Returns a list of datahandlers chained together through the use of delegation.

Returns:PyObject

a list of datahandlers

checkNullback to summary
public static final boolean checkNull(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException

Handles checking if the object is null or None and setting it on the statement.

Returns:boolean

true if the object is null and was set on the statement, false otherwise

createUnsupportedTypeSQLExceptionback to summary
protected final SQLException createUnsupportedTypeSQLException(Object type, int col)
getMetaDataNameback to summary
public String getMetaDataName(PyObject name)

Some database vendors are case sensitive on calls to DatabaseMetaData, most notably Oracle. This callback allows a DataHandler to affect the name.

getProcedureback to summary
public Procedure getProcedure(PyCursor cursor, PyObject name) throws SQLException

A factory method for determing the correct procedure class to use per the cursor type.

Parameters
cursor:PyCursor

an open cursor

name:PyObject

the name of the procedure to invoke

Returns:Procedure

an instance of a Procedure

getPyObjectback to summary
public PyObject getPyObject(ResultSet set, int col, int type) throws SQLException

Given a ResultSet, column and type, return the appropriate Jython object.

Note

DO NOT iterate the ResultSet.

Parameters
set:ResultSet

the current ResultSet set to the current row

col:int

the column number (adjusted properly for JDBC)

type:int

the column type

Exceptions
SQLException:
if the type is unmappable
getPyObjectback to summary
public PyObject getPyObject(CallableStatement stmt, int col, int type) throws SQLException

Given a CallableStatement, column and type, return the appropriate Jython object.

Parameters
stmt:CallableStatement

the CallableStatement

col:int

the column number (adjusted properly for JDBC)

type:int

the column type

Exceptions
SQLException:
if the type is unmappable
getRowIdback to summary
public PyObject getRowId(Statement stmt) throws SQLException

Returns the row id of the last executed statement.

Parameters
stmt:Statement

the current statement

Returns:PyObject

the row id of the last executed statement or None

Exceptions
SQLException:
thrown if an exception occurs

getSystemDataHandlerback to summary
public static final DataHandler getSystemDataHandler()

Build the DataHandler chain depending on the VM. This guarentees a DataHandler but might additionally chain a JDBC2.0 or JDBC3.0 implementation.

Returns:DataHandler

a DataHandler configured for the VM version

postExecuteback to summary
public void postExecute(Statement stmt) throws SQLException

A callback after successfully executing the statement.

preExecuteback to summary
public void preExecute(Statement stmt) throws SQLException

A callback prior to each execution of the statement. If the statement is a PreparedStatement, all the parameters will have been set.

readback to summary
public static final byte[] read(InputStream stream)

Consume the InputStream into an byte array and close the InputStream.

Returns:byte[]

the contents of the InputStream a byte[]

readback to summary
public static String read(Reader reader)

Consume the Reader into a String and close the Reader.

Returns:String

the contents of the Reader as a String

registerOutback to summary
public void registerOut(CallableStatement statement, int index, int colType, int dataType, String dataTypeName) throws SQLException

Called when a stored procedure or function is executed and OUT parameters need to be registered with the statement.

Parameters
index:int

the JDBC offset column number

colType:int

the column as from DatabaseMetaData (eg, procedureColumnOut)

dataType:int

the JDBC datatype from Types

dataTypeName:String

the JDBC datatype name

setJDBCObjectback to summary
public void setJDBCObject(PreparedStatement stmt, int index, PyObject object) throws SQLException

Any .execute() which uses prepared statements will receive a callback for deciding how to map the PyObject to the appropriate JDBC type.

Parameters
stmt:PreparedStatement

the current PreparedStatement

index:int

the index for which this object is bound

object:PyObject

the PyObject in question

setJDBCObjectback to summary
public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException

Any .execute() which uses prepared statements will receive a callback for deciding how to map the PyObject to the appropriate JDBC type. The type is the JDBC type as obtained from java.sql.Types.

Parameters
stmt:PreparedStatement

the current PreparedStatement

index:int

the index for which this object is bound

object:PyObject

the PyObject in question

type:int

the java.sql.Types for which this PyObject should be bound

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the classname of this datahandler.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override