Oracle’s CustomDatum Interface

In this section, you will learn how to use Oracle’s CustomDatum interface classes to manipulate database objects. However, since we covered the SQLData interface in great detail, and there are minimal differences between the CustomDatum classes and the SQLData classes, I won’t get into nearly as much detail as I did with SQLData.

Oracle’s CustomDatum interface classes created by JPublisher are for one-stop shopping. When you use JPublisher with the option -usertypes=oracle, it creates custom classes for all the database data types you specify, including references and collections, and also creates wrapper methods for static and member type methods. In addition, if you use CustomDatum, no type map is required.

If you specify methods=true or methods=named, JPublisher generates .sqlj files instead of .java files. The .sqlj files then need to be compiled using SQLJ to create the corresponding .java files. The default constructor for the generated classes uses the SQLJ default Context for a connection -- you don’t want to use this. Instead, use one of the alternate constructors, that is, one that takes a Connection as an argument. Let’s go ahead and start generating CustomDatum classes. Our first concern will be creating an appropriate input file.

Creating an Input File for CustomDatum

The mapping input file for generating CustomDatum classes is different from the one we used for SQLData. First, since JPublisher can generate the methods for us, we no longer ...

Get Java Programming with Oracle JDBC now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.