Type Inheritance Support in Oracle9i JDBC Drivers
   

Type inheritance is an essential new feature in Oracle9i Object-Relational Technology. With type inheritance, a new user-defined type can be created by extending another user-defined type.  The new user-defined type is then a subtype of the supertype from which it extends. The subtype automatically inherits all the attributes and methods defined in the supertype. The subtype can add attributes and methods, and overload or override methods inherited from the supertype. Oracle supports this single type inheritance model, which closely aligns with the ANSI/OSI SQL99 standards.

Furthermore, Oracle provides tight integration between its Object-Relational features and its JDBC functionality, you can use a standard, generic JDBC type to map to Oracle objects, or you can customize the mapping by creating custom Java type definition classes. Custom object classes can implement either a JDBC standard SQLData interface or the Oracle extension ORAData and ORADataFactory interfaces to read and write data. Oracle supports type inheritance in JDBC drivers that conform to the JDBC 2.0 specification. 

JDBC materializes Oracle objects as instances of particular Java classes. Two main steps in using JDBC to access Oracle objects are: 1) creating the Java classes for the Oracle objects, and 2) populating these classes. If you have an inheritance hierarchy of object types, you may create a corresponding inheritance hierarchy of Java classes. For example, a type inheritance hierarchy with PERSON_T and STUDENT_T types can be created in the database as follows,

CREATE TYPE Person_T (SSN NUMBER, name VARCHAR2(30), address VARCHAR2(255)); 
CREATE TYPE Student_T UNDER Person_t (deptid NUMBER, major VARCHAR2(100)); 

A hierarchy of Java classes implementing the ORAData interface can mirror this database object type hierarchy as follows,

Person.java 
class Person implements ORAData, ORADataFactory 
{ 
  static final Person _personFactory = new Person(); 

  public NUMBER ssn; 
  public CHAR name; 
  public CHAR address; 

  public static ORADataFactory getORADataFactory() 

  { 
    return _personFactory; 
  } 

  public Person () {} 

  public Person(NUMBER ssn, CHAR name, CHAR address) 
  { 
    this.ssn = ssn; 
    this.name = name; 
    this.address = address; 
  } 

  ...
}
Student.java extending Person.java
class Student extends Person 
{ 
  static final Student _studentFactory = new Student (); 

  public NUMBER deptid; 
  public CHAR major; 


  public static ORADataFactory getORADataFactory() 
  { 
    return _studentFactory; 
  } 

  public Student () {} 

  public Student (NUMBER ssn, CHAR name, CHAR address, 
                  NUMBER deptid, CHAR major) 
  { 
    super (ssn, name, address); 
    this.deptid = deptid; 
    this.major = major; 

  } 
  ...
}

JPublisher Utility

Even though you can manually create customized classes that implement the SQLData, ORAData, and ORADataFactory interfaces, it is recommended that you use Oracle9i JPublisher to automatically generate these classes. The customized classes generated by JPublisher that implement the SQLData, ORAData, and ORADataFactory interfaces, can mirror the inheritance hierarchy.

Once you have created these custom Java classes, you can use them in a Java program to access and to manipulate supertype and subtype objects in an Oracle9i database.

More Info
Oracle9i Object-Relational Technology - Technical White Paper
Visit the OTN Discussion Forum that the Oracle Object-Relational team monitors
Oracle 9i Application Developer's Guide - Object-Relational Features
Oracle9i JDBC Developer's Guide and Reference
Oracle9i JPublisher User's Guide

Oracle9i Daily Features
Archives
   
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy