Previous Table of Contents Next


Different Ways That Java Can Package PL/SQL

Not only is it advantageous on the Java end of things to move SQL to the server, but it can be advantageous for the database logic to be packaged in specific Java structures that will allow it to be used as an object-oriented building block that many different developers can use. The two major methods for doing this are by using Interface Definition Language (IDL) or RMI.

The Language of Cartridges

IDL is based on the CORBA standard that Oracle embraces. The end product of an IDL is an Object Request Broker (ORB). Because ORBs are designed with this common standard, using them allows people to access your database logic embedded in your Java code in a standard way.

A typical IDL statement would first consist of the creation of a distributed object. For your airline application, it might look something like this:


module AirlineTicketSales

{

    interface flight_data

    {

        attribute    string flight_no,

        attribute string flight_date,

        attribute string origination,

        attribute string destination,

        attribute long frequent_flier_no,

        attribute string class_of_travel;



        void get_travel_info;

        void sell_ticket;

        void update_customer_info;

    };

};

By storing this file as airline.idl and then running idltojava -fclient -fserver airline.idl, source code for this template is generated. This includes stubs, classes, and helper and holder classes. These .java files then, of course, need to be compiled to .class files before the final implementation code is written so that testing can occur.

RMI—Distributed Computing Tool

RMI existed before the IDL interface and the CORBA standard. Because of this, RMI is more stable and has been used in older versions of Java. Using your airline database access methods, RMI splits your classes for information needed on both the client (the machine running the applet) and the server (the machine where our database is), as shown in Figure 29.2.


Figure 29.2.  RMI generates client and server Java code from your original Java file.

Roughly speaking, this is how RMI would treat a Java class describing airline travel:

1.  Split the class into two parts—one to hold data, and the other to implement the methods on the server.
2.  Define how remote access will occur. This will extend the java.rmi class.
3.  Develop an Airline Control RMI component for the server. This will extend the java.rmi.server class.
4.  Compile these classes, create stubs for coding, and create wrappers for remote methods.

Essentially, RMI breaks up your business Java class into a portion of information needed on the server and another portion needed on the client, and creates an interface between them.

The Future—J/SQL

Oracle and other vendors are working to build compilers that will recognize SQL directly within Java code without using the complicated methods in this chapter, which need to be reworked for each class that uses a database! Using PL/SQL Packages within Java cuts down on the amount of code you need to write, considering you only need to concern yourself with the input and output of these packages. Yet with J/SQL, much of this tedious JDBC will be eliminated. Hopefully, the major vendors will agree on a standard that is portable between database platforms and won’t frustrate us, as is the case with the current precompiler differences between vendors. With J/SQL, the database will become more object-oriented and the Java language will become more relational, thus evolving both technologies.

Summary

Because Microsoft appears to be in complete dominance of the computer world today, it might be tempting to snuggle up by a fireplace and just code database/Internet applications in ActiveX. Yet we must look back to the days when IBM was king and remember that on some days every emperor is wearing no clothes.

With this in mind, we should instead turn to the Java language which will survive the political upheavals of the computer world due to its flexibility. Yet, we cannot become enamored with Java alone; instead we must realize that Java, just like any programming language, needs to communicate with Relational Databases. With this in mind, we will find that Oracle offers many very powerful methods to give the Java language quick access to the Oracle8 Server. With these tools, we can transform the client/server paradigm so that our “client” can be anyone in the world that has access to the Internet, thus making Oracle8 the truly “universal server.”


Previous Table of Contents Next
Используются технологии uCoz