In this tutorial you build a simple Oracle Forms 11g application with an event object and integrate it with a database queue that you create. You then use a more complex chat application in Oracle Forms 11g that demonstrates the asynchronous events feature in an Oracle database.
Approximately 2 hours
Oracle Advanced Queuing (AQ) mechanisms enable messages to be exchanged between different programs. AQ functionality is implemented by using the following interfaces, which are PL/SQL packages: DBMS_AQ, DBMS_AQADM, and DBMS_AQELM. See the Resources section of this tutorial for more information about Oracle Advanced Queuing.
In the simple application that you build, you create an Event object in Forms Builder, subscribe to a database queue that you set up, and perform some action when the event occurs. The more complex application that you demonstrate in this tutorial is a chat application that also integrates Advanced Queuing. Both applications show how Oracle Forms 11g can handle external events, such as asynchronous events, by using the database queue.
Here are some screenshots of the chat application:
After the user logs in, the application looks like this:
After the user opens a chat window, it looks like this:
Before starting this tutorial, you should:
1. |
Have access to or have installed Oracle Forms version 11.1.1. |
---|---|
2. |
Have access to or have installed a supported Oracle database; see the certification matrix accessible here. Please note that you must use a database that supports Advanced Queuing and XML. |
3. |
Have access to the SYS user account. |
Both of the applications in this tutorial are accessed by a user named chat. To set up the chat user and objects, perform the following steps:
1. |
Extract the zip file to a temporary location; by default, unzipping it creates a subdirectory called \chat.
|
---|---|
2. |
Set up the CHAT user:
Do not disconnect from SQL*Plus.
|
3. |
Create the CHAT user's tables, procedures, and queues, and start the created queues.
|
1. |
From the \Forms subdirectory of the \chat directory where you extracted the zip file, copy the .fmb and .mmb files to a directory of your choice.
|
---|---|
2. |
Set the FORMS_PATH variable in the default.env file to include the directory containing the .fmb and .mmb files, and then save and close the file.
|
3. |
Create a directory named oracle/forms/demos under $ORACLE_HOME/forms/java/ and copy the RoundedButton.class file there .
|
1. |
In the formsweb.cfg file create a named configuration, [chat], for the chat application . Add the form, userid , and separateframe parameters to the configuration. The form to run is chat_mainnew, to be run in a separate window, and the user id and password are chat/chat. To complete the connection (userid) parameter, add your database information. The parameters should look similar to the following:
|
---|---|
2. |
The Forms Server is notified of asynchronous events without polling, and it responds to the event by firing a WHEN-EVENT-RAISED trigger. However, because of the request/response paradigm of the HTTP protocol, it does not fire this trigger until it receives a request from the Forms Client. There is a new parameter, MaxEventWait, that governs how many milliseconds the application should wait before checking for an event. Set MaxEventWait to 2000 milliseconds.
|
3. |
Create another named configuration, [title_test], for running the simple form that you build in this tutorial. The new named configuration should be a duplicate of what you have defined so far for the [chat] configuration, except that the form name is title: |
1. |
From the \WebUtil subdirectory of the \chat directory where you extracted the zip file, copy the jacob.jar file to $ORACLE_HOME/forms/java.
|
---|---|
2. |
Copy jacob.dll to the $ORACLE_HOME\forms\webutil directory.
|
3. |
Make the following changes in webutil.cfg to enable WebUtil functions, and then save and close the file: transfer.database.enabled=TRUE
|
4. |
Set up the WebUtil database objects:
|
5. |
Add the following WebUtil parameters to the [chat] named configuration in the formsweb.cfg file, and then save and close the file:
|
6 . |
The jacob.jar file must be signed, but first you must edit the batch file for signing JAR files. This batch file (sign_webutil.bat or sign_webutil.sh ) is located in the <Oracle_Instance>\bin directory. Edit the batch file to specify:
Save the modified file.
|
7 . |
Sign the jacob.jar file.
|
In order to be able to run the applications, you need to start WebLogic Server if it is not already running. You do not need the Admin server just to run a Forms application, but only the managed WebLogic Server for Forms. To start it, perform the following steps:
1 . |
Start the WLS_FORMS managed server on Windows by executing the appropriate batch file, startManagedWebLogic.cmd, located in the user_projects\domains\ClassicDomain\bin subdirectory of the Fusion Middleware home directory. You must pass SERVER_NAME and ADMIN_URL command-line arguments to these scripts; for example: Alternatively, you can call this batch file from the Windows Start menu:
|
---|---|
2 . |
You will need to input the user name and password for starting the Oracle WebLogic Server, which were specified at the time of installation.You can minimize, but do not close, the command window. The characters of the password are not visible as you type them.
|
3 . |
You can minimize, but do not close, the command window. |
The Create_Required_tables.sql script that you ran earlier created some objects for the user CHAT. Now you examine some of these objects by performing the following steps:
1 . |
Open Forms Builder and connect to the database as the user chat. Then in the Object Navigator, expand the Database Objects Node. Expand the CHAT user and the Types node. Double-click OBJTITLE_TYP2 (Object Type) to see the definition of the data type. You need an abstract data type to manage the message payload. In AQ you can use either a RAW data type or an abstract data type (ADT) for the message payload. The RAW data type is suitable for streams and multimedia and not so suitable for payloads. Because AQ has no support for simple data types, such as VARCHAR2 and NUMBER, the Create_Required_tables.sql script created the objtitle_typ2 ADT that encapsulates the data type you need for the payload, which is VARCHAR2.
|
---|---|
2. |
The script also created a queue table based on that ADT. The code in the script that created the table is: To view the table in the Object Navigator, under the CHAT user expand Tables> OBJ_TITLE_TABLE > Columns > USER_DATA (OBJTITLE_TYP2). You can see that the USER_DATA column is based on the objtitle_typ2 ADT:
|
3. |
The script created a procedure that accepts values for title, F1, and F2, adds these values to the message payload, and places a message on the queue. To view the code, under the CHAT user expand PL/SQL Stored Program Units and double-click NEW_OBJ_ENQUEUE2(Procedure). The code is: The script granted the EXECUTE privilege on this procedure to PUBLIC. |
4. |
The script also created a database trigger that automatically calls the procedure when an INSERT is done on the Title table. To view the code, under the CHAT user expand Tables > Title > Triggers, and then double-click TITLE_INSERT_TRIGGER (After Each Row Insert). The code that created the table is: There are additional queue related objects shown in the Object Navigator of Forms Builder that you may examine if you like.
|
5. |
In addition to what you can see in the Object Navigator, the Create_Required_tables.sql script performed some additional actions:
|
So far you have set up and started the database queue, added a subscriber, and created a procedure that enqueues an event whenever a record is added to the Title table. The payload of the event contains the new values that were inserted into the Title table.
Now you create a form that retrieves the payload from the queued message and displays its values. In Forms 11g there is new EVENT object that you can create in the Object navigator. A new WHEN-EVENT-RAISED trigger is introduced to handle the event for the EVENT object. You can use the new GET_EVENT_OBJECT_PROPERTY() built-in to retrieve the PAYLOAD.
Perform the following steps to create the form that is integrated with the queue that you have set up:
1 . |
In Forms Builder, select the Events node and click Create (or select Edit > Create) to create a new Event object. Name this event Event2.
|
---|---|
2. |
The form must subscribe to a queue in order to get event messages and payloads. To subscribe to a queue:
|
3. |
For the Event object, create a WHEN-EVENT-RAISED trigger to code the action that should be initiated when a message is received in the subscribed queue. In this case, to simply demonstrate that the payload was received, you can use the MESSAGE() built-in to display the payload values. Enter the following trigger code: Note the use of the new GET_EVENT_OBJECT_PROPERTY() built-in to retrieve the payload from the event that was raised when a message was placed on the queue to which the form is subscribed.
|
4. |
Inserting a record in the Title table is the action that initiates the event. To make it possible to insert a record, create a data block in the form that is based on the Title table, using all columns from the table.
|
5. |
Save the form with the name title.fmb, and then generate the form. Be sure to save it to the directory that you earlier added to FORMS_PATH.
|
6. |
Run the form by entering a URL in the browser similar to the following, using your own host name:
|
7. |
The form opens in a separate window. Enter and commit a record.
|
8. |
Inserting a record initiates the following sequence of actions:
You can that the message shows the XML payload containing the values that you entered into the form. Exit the form and the browser. |
To run the application and demonstrate its functionality, perform the following steps:
1. |
Open the demonstration application .fmb and .mmb files in Forms Builder; generate the forms and compile the menu modules. Note: If you get compilation errors, ensure that you are using a supported database with Advanced Queuing and XML support, as stated in the Prerequisites.
|
||||||||
---|---|---|---|---|---|---|---|---|---|
2. |
Run the application in your browser by issuing the following URL: http://localhost:9001/forms/frmservlet?config=chat When prompted, log in as the CHAT user. Note: If the runtime session crashes with FRM-93652, do the following:
|
||||||||
3. |
Click Get new user ID to create a user id... ---and enter information to register yourself as a new user (Userid should be 8 characters): Click Continue, and then click OK to acknowledge the confirmation message.
|
||||||||
4. |
Log in with the user id that you created. Once you are logged in, a buddy list of other users who are logged in to the chat Application is displayed in a tree. Initially there are no other users, so the buddy list is blank.
|
||||||||
5. |
Leaving the first buddy list open, open a second browser window. Following steps 2-4 above, run the application to create a second user and log in. The buddy list for the second user shows that the first user is already logged in:
Now return to the first user's buddy window – you should see that the second user has been added to the buddy list.
|
||||||||
6. |
To send a message to another logged-in user, select the user from the list, and then right-click and select Send IM from the context menu.
|
||||||||
7. |
A new chat window opens. Type in a message and click Send.
|
||||||||
8 . |
Return to the second user's window. You can see the message sent by the first user, and you can send a message back. The first user's window shows the return message. Note: There is an unresolved bug in the application. Occasionally a message, especially the first message sent, does not appear in one of the message windows (sometimes the sender's and other times the receiver's message window.) If this happens, you can send the message again and it should appear in both windows.
|
||||||||
9 . |
You can upload Images of particular user. In the first user's chat window, click Browse to select the image file, and then click Upload to save it in the database. (This is functionality of WebUtil, not the asynchronous event integration with Advanced Queuing.)
|
||||||||
10 . |
The next time another user opens a chat window to chat with the first user, the picture appears. |
In this tutorial, you built a simple form that retrieves the payload from an AQ queue that you set up. You then ran the chat application to demonstrate how it integrates with Advanced Queuing to send and receive messages.