Tuesday, November 6, 2007

Customized Type Mapping:JAVA4

Effect of Transform Groups

Transform groups (SQL99) can be used to convert a user-defined SQL type into
predefined SQL types. This transformation is performed by the underlying data
source before it is returned to the JDBC driver.

If transform groups are used for a user-defined type, and the application has not
defined a mapping for that type to a Java class, then the ResultSetMetaData
method getColumnClass should return the Java class corresponding to the data
type produced by the transformation function (that is, String for a VARCHAR).
Note – This is consistent with the behaviour for DISTINCT types.

If transform groups are used for a UDT, and the application has defined a mapping
for that type to a Java class, then the SQLInput stream delivered by the JDBC driver
during an invocation of the method readSQL contains only a single value, that is,
the result produced by the transformation function. The same model holds for the
method writeSQL.

Generality of the Approach

Users have great flexibility in customizing the Java classes that represent SQL
structured and DISTINCT types. They control the mappings of built-in SQL attribute
types to Java field types. They control the mappings of SQL names (of types and
attributes) to Java names (of classes and fields). Users may add (to Java classes that
represent SQL types) fields and methods that implement domain-specific
functionality. Users can generate JavaBeans components as the classes that represent
SQL types.

A user can even map a single SQL type to different Java classes, depending on
arbitrary conditions. To do that, the user must customize the implementation of
SQLData.readSQL to construct and return objects of different classes under
different conditions.

Similarly, the user can map a single SQL value to a graph of Java objects. Again, that
is accomplished by customizing the implementation of the method
SQLData.readSQL to construct multiple objects and distribute the SQL attributes
into fields of those objects.

A customization of the SQLData.readSQL method could populate a connection’s
type map incrementally. This flexibility will allow users to map SQL types
appropriately for different kinds of applications.

NULL Data

An application uses the existing getObject and setObject mechanism to retrieve
and store SQLData values. We note that when the second parameter, x, of method
PreparedStatement.setObject has the value null, the driver executes the SQL
statement as if the SQL literal NULL had appeared in its place.
void setObject (int i, Object x) throws SQLException;

When parameter x is null, there is no enforcement that the corresponding
argument expression is of a Java type that could successfully be passed to that SQL
statement if its value were not null. The Java programming language null carries
no type information. For example, a null Java programming language variable of
class AntiMatter could be passed as an argument to an SQL statement that
requires a value of SQL type MATTER, and no error would result, even though the
relevant type map object did not permit the translation of MATTER to AntiMatter.

No comments: