Interface SQLData
-
public interface SQLDataAn interface for the custom mapping of an SQL User Defined Type (UDT) to a Java class. The Java class object is added to the connection's type map paired with the SQL name of the corresponding UDT.Usually within an implementation of
SQLData, there is a corresponding field for every attribute of an SQL type, but only one field, if the type is SQLDISTINCT. When the UDT is returned within aResultSet, it is accessed with theResultSet.getObject(int)method and is returned as an object which is an instance of the class defined by theSQLDatamapping. The application can use this object just like any other Java object and can store changes back into the database using thePreparedStatement.setObject(int, java.lang.Object)method which performs the reverse mapping into the SQLUDT.Normally the implementation of a custom mapping is generated by a tool requiring the name of the SQL
UDT, the name of the class which it is going to be mapped to, and the field names to which the UDT attributes are mapped. The tool can then implement theSQLData,readSQL, andwriteSQLmethods.readSQLreads attributes from anSQLInputobject, andwriteSQLwrites them. This is done viaSQLInputandSQLOutputmethod calls respectively.Ordinarily an application would not call
SQLDatamethods directly. SimilarlySQLInputandSQLOutputmethods are not usually called directly.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StringgetSQLTypeName()Gets the SQL name of the User Defined Type (UDT) that this object represents.voidreadSQL(SQLInput stream, String typeName)Reads data from the database into this object.voidwriteSQL(SQLOutput stream)Writes the object to a suppliedSQLOutputdata stream, writing it out as an SQL value to the data source.
-
-
-
Method Detail
-
getSQLTypeName
String getSQLTypeName() throws SQLException
Gets the SQL name of the User Defined Type (UDT) that this object represents. This method, usually invoked by the JDBC driver, retrieves the name of the UDT instance associated with thisSQLDataobject.- Returns:
- a string with UDT type name for this object mapping, passed to
readSQLwhen the object was created. - Throws:
SQLException- if a database error occurs.
-
readSQL
void readSQL(SQLInput stream, String typeName) throws SQLException
Reads data from the database into this object. This method follows these steps:- Utilize the passed input stream to read the attributes or entries of the SQL type
- This is carried out by reading each entry from the input stream, ordered as they are in the SQL definition.
- Assign the data to the appropriate fields or elements. This is done
by calling the relevant reader method for the type involved (e.g.
SQLInput.readString,SQLInputreadBigDecimal). If the type is distinct, then read its only data entry. For structured types, read every entry.
The supplied input stream is typically initialized by the calling JDBC driver with the type map before
readSQLis called.- Parameters:
stream- theSQLInputstream from which the type map data is read for the custom mapping.typeName- the SQL type name for the type which is being mapped.- Throws:
SQLException- if a database error occurs.- See Also:
SQLInput
-
writeSQL
void writeSQL(SQLOutput stream) throws SQLException
Writes the object to a suppliedSQLOutputdata stream, writing it out as an SQL value to the data source.This method follows the following steps:
- Write each attribute of the SQL type to the output stream.
- Write each item by calling a method on the output stream, in the
order they appear in the SQL definition of the type. Use the appropriate
SQLOutputmethods (e.g.writeInt,writeString). Write a single data element for a distinct type. For a structured type, write a value for each attribute of the the SQL type.
- Parameters:
stream- theSQLOutputstream to use to write out the data for the custom mapping.- Throws:
SQLException- if a database error occurs.- See Also:
SQLOutput
-
-