Sample Illustrating Object Type Inheritance support in Oracle9i SQLJ

Table Of Contents 

Overview of the Sample Application 

Back To Top

SQLJ enables applications programmers to embed SQL operations in Java code. A SQLJ program is a Java program containing embedded SQL statements that comply with the ISO standard SQLJ Language Reference syntax.

SQLJ consists of a translator and a runtime component (translator.jar/zip and runtime12ee.jar/zip) and is smoothly integrated into the development environment. The translation, compilation, and customization take place in a single step when the front-end utility sqlj is run. The translation process replaces embedded SQL with calls to the SQLJ runtime, which implements the SQL operations. When the end user runs the SQLJ application, the runtime is invoked to handle the SQL operations.

SQLJ runs on top of JDBC. To access an Oracle database, you would typically use an Oracle JDBC driver. In order to run SQLJ programs, apart from SQLJ classes, JDBC classes should be present in the system CLASSPATH. SQLJ code is written and saved in *.sqlj files and should be translated to *.java files before compiling using the front-end utility sqlj.

Object-type inheritance feature allows a new object type to be created by extending another object type. The new object type is then a subtype of the object type 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.

Sample Application Scenario

The sample simulates a Residential University where the major players are Students, Teachers and Part-time Students. The model has four new object types. Person is a super type and its attributes are that which are common to all persons. It has two sub types Student and Teacher. Student has a sub-type Part-time student.

This sample illustrates the following

  1. Overloading Methods: Here the method getPersonDetails() is overloaded. When invoked on Student Object, this method returns the courses taken, grade etc. information apart from Name and Address information. When invoked on Teacher Object, this method returns the information like courses taught, Salary, Department apart from Name and Address.
  2. Dynamic Method Dispatch: This is nothing but run-time polymorphism. When you invoke an overridden method, the implementation of the methods is searched in the current type and then upwards in the type hierarchy (type and super types of the type). In other words, if setAddress() is invoked from a Student Object, then method in Person Object is invoked, since there is no implementation of setAddress() in Student Object, but if the same method is called from a Teacher object the implementation in the Teacher Object is called.
  3. Substituting Types in a Type Hierarchy: A base object type can hold any of its sub-types object i.e. Person is the base type and it can hold either a Student, Teacher or a Part-time Student object which are sub-types of Person.

Notations used

The following notations are used through out this document

Notation

Description

<SAMPLE_HOME>

Folder where the ObjectTypeInheritanceSample.jar is unzipped.

<JAVA_HOME>

Folder where JAVA is installed.

<JDBC_LIB>

Folder where the Oracle JDBC driver exists.

<SQLJ_LIB>

Folder where the Oracle SQLJ translator and runtime files exist.

<SQLJ_EXE_HOME>

Folder where the SQLJ executable exists.


Required Software

Back To Top

  • Oracle9i JDeveloper ( Note: Oracle9i JDeveloper is Oracle's Visual Java Development Tool and can be downloaded from here )
    or
    JDK1.3.x or above This can be downloaded from here .
  • Oracle9i Database or higher running SQL*Net TCP/IP listener. This can be downloaded from OTN site.
  • Oracle9i v9.0.2 or higher SQLJ translators and runtime, downloadable from OTN site.
  • Oracle9i v9.0.2 or higher JDBC Drivers, downloadable from OTN site. When downloading JDBC driver make sure to download nls_charset12.jar/zip.
    Note : If Oracle9i client is already installed on your system then this driver need not be downloaded separately.

Application Set-up and Configuration

Back To Top

  • For setting up the environment variables in different platforms, please refer environment set up document.

  • Unjar the provided ObjectTypeInheritanceSample.jar using the following command 
    > jar xvf ObjectTypeInheritanceSample.jar

    Note: You will find jar.exe in <JAVA_HOME>\bin. Ensure <JAVA_HOME>\bin is present in your system path. 
    This creates a folder ObjectTypeInheritanceSample with all the source files.

  • Database Setup
    This sample application makes use of tables, objects, collections and stored procedures that need to be created. To set up the database, run SQL*Plus as scott/tiger and execute the ObjectTypeInheritance.sql script which is available at ObjectTypeInheritanceSample\config directory
  • SQL> @<SAMPLE_HOME>\ObjectTypeInheritanceSample\config\ObjectTypeInheritance.sql

  • Edit ObjectTypeInheritanceSample\Connection.properties file in your favorite editor. Change the sqlj.url value to connect to your own database.

    sqlj.url

    =

    jdbc:oracle:thin:@localhost:1521:ORCL

    sqlj.user

    =

    scott

    sqlj.password

    =

    tiger

 

Running the application - From command line

Back To Top

          This section describes the steps to run the application from console using JDK(version 1.3 or above) for Windows and Linux (Tested on Redhat Linux Advanced Server version 2.1). This application can be run either manually or using a script file.

Run the application using script file :

<

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