10.07.2015 Views

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

JDBC Developer's Guide - Supra - Cincom

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Controlling when custom mapping occursOnce your Java application has a database object reference, there are severalmethods to materialize the referenced database object as an instance of thecustom mapped class:The java.sql.ResultSet.getObject method♦♦The ordbObject.getObject methodThe getAttributes method of the java.sql.Struct interfaceUsing the java.sql.ResultSet.getObject MethodThe generic <strong>JDBC</strong> way to request custom mapping is to use the getObjectmethod of the java.sql.ResultSet interface.The <strong>Cincom</strong> ORDB <strong>JDBC</strong> driver performs custom mapping when the getObject()method invokes the ResultSet column that contains an object reference. Usethe getRef() method if you do not want custom mapping performed.The following example assumes that the default type map associates thedatabase class “seashore” with the java class jseashore:...ResultSet rset = stmt.executeQuery ("SELECT name,beach FROM resortWHERE beach IS NOT NULL");// get the beach as an instance of the custom mapped class// jseashore.javajseashore beach = null;while (rset.next ()) {beach = (jseashore)rset.getObject(2));// Internally the <strong>JDBC</strong> Driver performs these actions:// 1. If the database value is NOT an oid, then// generate a java object of appropriate type and// return.// 2. The database value is an oid, what we really have is// an instance of the ordbObject class.// 3. Check the type map (default or passed as parm) to see// if the database class has a custom java class.// If there is no custom class, return the ordbObject// to application as a (by casting to) java.sql.Struct// 4. If there is a custom map, instantiate an instance of the<strong>JDBC</strong> <strong>Developer's</strong> <strong>Guide</strong>, P25-9504-03 Page 50Chapter: 4. <strong>Cincom</strong> ORDB ExtensionsSection: Creating custom Java classes for <strong>Cincom</strong> ORDB objects

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!