Page 1113
The AIS Web Development Suite provides a number of tools and utilities, including the Database Application Support and Object Interface Generator, Server Configuration Manager, Repository and Replication Manager, Security Manager, and Client Configuration Manager.
The Database Application Support and Object Interface Generator greatly simplifies the development process of online transaction processing (OLTP) and online analytical processing (OLAP) applications by producing IDL, object implementations, and client interfaces that encapsulate communication between implementations and data sources; it also supports interaction between client objects and the ORB. You can use this feature to generate application support for Oracle databases as well.
To understand the power of the AIS Web Development Suite, take a look at the famous scott/tiger Oracle schema. The suite supports full OLTP application interface over the Web or an intranet by generating four files that are the key links between your RDBMS applications and your new Web-based objects.
The following four files would be created if you used this tool with the scott/tiger database:
deptpack.sql: A script to create a view, sequence, and package used to access dept data
dept.idl: An IDL submitted to JavaIDL to generate helpers, holders, and so on
Page 1114
DeptController.java: A server implementation of an object to manipulate dept data
DeptClient.java: A client wrapper to operate on DeptController references
Listing 50.1 shows the declarations the generated package specification would contain.
Listing 50.1. PL/SQL package containing functions for OLTP processing.
CREATE OR REPLACE PACKAGE DeptPack AS FUNCTION DeleteRow( deptnoIn IN NUMBER) RETURN NUMBER; FUNCTION InsertRow( dnameIn IN CHAR, locIn IN CHAR, deptnoOut OUT NUMBER) RETURN NUMBER; FUNCTION LockRow( deptnoIn IN NUMBER, dnameOut OUT CHAR, locOut OUT CHAR) RETURN NUMBER; FUNCTION UpdateRow( deptnoIn IN NUMBER, nameIn IN CHAR, locIn IN CHAR) RETURN NUMBER; PROCEDURE ReleaseLock; END DeptPack; /
For performance reasons, as well as ease of use, the Database Application Support and Object Interface Generator separates data from operations. This separation enables applications to construct and manipulate the objects that contain the data directly and to access the ORB only when necessary. Listing 50.2 demonstrates this feature by showing the IDL generated for the DEPT interface.
Listing 50.2. Generated IDL for the DEPT transactions.
#include "aisoci.idl" module DEPT { struct DeptData { long deptno; string dname; string loc; }; const long BLOCK_SIZE = 5;
Page 1115
struct DeptBlock{ DeptData vals[BLOCK_SIZE]; long numvals; }; enum FilterType {LIKE, EQUALS}; interface DeptControl { DeptData openList(in DeptData filter, in FilterType mode) raises(AISOCI::AISOCIException); DeptData fetchNext() raises(AISOCI::AISOCIException); DeptBlock fetchBlock() raises(AISOCI::AISOCIException); void closeList() raises(AISOCI::AISOCIException); void insert(in DeptData dept) raises(AISOCI::AISOCIException); void lockRow(in long deptno) raises(AISOCI::AISOCIException); void delete(in long deptno) raises(AISOCI::AISOCIException); void update(in DeptData dept) raises(AISOCI::AISOCIException); void releaseLock() raises(AISOCI::AISOCIException); }; };
Although this code looks complicated, it is generated for you and then is passed to the idltojava compiler to generate the supporting classes and interfaces. The Database Application Support and Object Interface Generator anticipates the output of idltojava and creates the object implementations and client wrappers appropriately. Suddenly, scott/tiger is a Web-enabled environment!
The source code in DeptController.java would contain the object implementation that communicates with the generated package. Listing 50.3 shows a portion of this class.
Listing 50.3. Java application code fragment that calls an Oracle package to lock a row.
protected static final int OP_LOCK = 1; . . . protected static final int EMPNO_COL = 0; protected static final int ENAME_COL = 1; protected static final int JOB_COL = 2; . . . protected static final String LOCK_FUNC = "DeptPack.LockRow"; . . . public synchronized DeptModel lockRow(int deptno) throws AISOCI.AISOCIException { Vector args = new Vector(); Vector isOutput = new Vector(); Vector quotes = new Vector(); Vector outParms = new Vector(); DeptModel DeptOut = new DeptModel();
continues
Page 1116
Listing 50.3. continued
try { AddAllArgs(OP_LOCK, args, isOutput, quotes, DeptOut); outParms = DBConn.callFuncWithOutput(LOCK_FUNC, args, isOutput, quotes); DeptOut.deptno = Integer.parseInt((String)outParms.elementAt(DEPTNO_COL)); DeptOut.dname = (String)outParms.elementAt(DNAME_COL); DeptOut.loc = (String)outParms.elementAt(LOC_COL); } catch (DBException e1) { HandleDBException(e1); throw new AISOCIException(e1.getErrorCode(), e1.getErrorText()); } catch (Exception e2) { HandleJavaException(e2); throw new AISOCIException(0, e2.getMessage()); } return DeptOut; } . . .
The client wrapper to communicate with the server object is the only object that client applications use to communicate with the server implementation. This feature prevents developers from having to repeatedly perform tasks associated with accessing the ORB to obtain object references. All they need to do is ask once by using a few simple program calls. Listing 50.4, from the generated DeptClient.java class definition, demonstrates this point.
Page 1117
Listing 50.4. Using simple program calls.
public class DeptClient { protected final static String CName = "DeptClient"; protected final static String CType = "DeptClient"; protected DEPT.DeptControl ControlRef = null; protected int CRefID = 0; public DeptClient( AISORBClient Session) throws AISOCIException, Exception { try { ControlRef = Session.getObjectRef(Cname, Ctype, CRefID); } catch (AISORBException e1) { throw e1; } catch (Exception e2) { throw e2; } }