I thought I knew everything about UDT and JDBC until someone from /qaru.site / ... indicated some details of the Javadoc java.sql.SQLInput and java.sql.SQLData JavaDoc for me. The essence of this hint was (from SQLInput):
An input stream containing a stream of values ββrepresenting an instance of a structured SQL type or SQL of a different type. This interface, used only for user mapping, is used by the driver behind the scenes, and the programmer never directly calls SQLInput Methods.
This is the exact opposite of what I use (which is also used and stable on productive systems when used with the Oracle JDBC driver): SQLData and provide this implementation in a custom mapping
ResultSet.getObject(int index, Map mapping)
The JDBC driver will then access my custom type using
SQLData.readSQL(SQLInput stream, String typeName)
method. I implement this method and read each field from the SQLInput stream. In the end, getObject() will return a properly initialized instance of my SQLData implementation containing all the data from the UDT.
For me, this seems like the perfect way to implement such a custom mapping. Good reasons for this:
- I can use the standard API, instead of using vendor specific classes like
oracle.sql.STRUCT etc. - I can generate source code from my UDTs, with corresponding getters / seters and other properties
My questions are :
- What do you think of my approach implementing
SQLData ? Is it viable even if Javadoc states otherwise? - What other ways to read UDT in Java do you know? For example. what does spring do? what does hibernate do? What does JPA do? What are you doing?
Adding
UDT support and integration with stored procedures are one of the main functions of jOOQ . jOOQ seeks to hide the more complex "JDBC facts" from client code without hiding the underlying database architecture. If you have similar questions as above, jOOQ can provide you with an answer.
java jdbc user-defined-types
Lukas Eder
source share