Page 1224
This delineation makes sense when dealing with the restrictions of the Internet such as bandwidth. Following are some other driving reasons to applying server-side functionality:
Most cartridges are developed to reside on the server side.
A server-side cartridge maintains a lifetime that can span many client-side screens. The cartridge has the capability to apply locks on shared resources and allocate and free private memory. The client processing has the capability to return to the persistent cartridge through a handle to that specific context. An example of this is found in a typical update to a database row. Rather than simply apply an update to a given row, a user wants a lock so that other users cannot affect the same row at the same approximate time. One browser-based screen allows the user to apply the lock. If the lock succeeds, the next screen returns the information to be edited. That screen then allows the user to either cancel the operation or apply the update. The key value for the locked row is stored in private memory of the cartridge. This approach has several advantages:
Page 1225
An example can illustrate how state information is saved and used to support several different requests from the client. Suppose an application is used to let a user retrieve information from an Oracle table and save modifications. The following steps show how the server cartridge can be used to maintain session information between client requests :
Oracle offers several language options for cartridge development. Currently supported languages include Java, PL/SQL, Perl, and C. C is the most powerful of the supported languages. C offers full access to the Web Request Broker (WRB) API. The other languages are interpreted by Oracle's supplied cartridges. This means that they have some limitations as well as performance degradation. This chapter focuses on creating cartridges in C.
All cartridges have common elements. It is this makeup that enables the WRB to interact with the cartridge. Following are some of the most common elements of a cartridge:
Entry point: This function is called by the WRB engine when the cartridge is first loaded. The entry point function can be called any valid function name . The main purpose of this function is to set the callbacks of the remaining standard functions. Initialize: This standard callback serves to perform any initialization steps for the cartridge. Typical use of this routine is to allocate any memory and set initial values to be shared with other cartridge functions.
Page 1226
Exec: The exec function is the handler routine called by the WRB dispatcher. This function typically parses the requested URL and maintains a state machine, which determines what to do with a given request. Shutdown: This function is called by the WRB engine upon preparing the cartridge to exit. The function needs to perform any resource deallocating, such as freeing memory.
Authorize: This function is called by the WRB to determine whether the client is authorized to process a given request. This function is optional. Other more sophisticated mechanisms offer more restrictive security.
The WRB standard functions return one of the following return values to the Web Request Broker:
WRB_DONE | The function was successful. |
WRB_ERROR | The function did not complete successfully. Error during execution. |
WRB_ABORT | An unrecoverable error occurred. You need to terminate the application. |
As mentioned previously, the Web Application Server has a prepackaged cartridge that allows a developer to write an application in PL/SQL. This cartridge acts a bridge between the Web server and the PL/SQL code stored within the database. For simple transactions to the Oracle database, interacting with the PL/SQL cartridge is a fast and easy way to build dynamic Web pages.
The Web Application Server comes with many building blocks. Several Oracle-developed packages are available to perform a variety of processing within user-developed PL/SQL.
Oracle implemented a set of methods that abstract the HTML tag language for the PL/SQL programmer. The programmer must learn how to use these packaged methods to create output in the form of HTML pages, and a basic understanding of HTML is necessary. The Hypertext Procedures (HTP) and Hypertext Functions (HTF) packages are useful for creating dynamic Web pages with 100 percent of the source code developed using PL/SQL. The idea is that PL/SQL is already good at processing information and interacting with the RDBMS. Now, PL/SQL can use this database-originated information and easily create a dynamic Web page.