Submitting a Job The Event-Driven Publishing API

Using Event-Driven Publishing 21-7 IF :new.ExpStat = DONE THEN myPlist := SRW_PARAMLISTSRW_PARAMETER,; SRW.ADD_PARAMETERmyPlist,GATEWAY,http:…; SRW.ADD_PARAMETERmyPlist,SERVER,fooSVR; SRW.ADD_PARAMETERmyPlist,CMDKEY,keyvalue; SRW.ADD_PARAMETERmyPlist,ExpenseID,:new.ExpID; myIdent := SRW.RUN_REPORTmyPlist; END IF; END; Additionally, if you have defined an advanced distribution model through a distribution XML file, you can specify that file with the DESTINATION parameter. For example: CREATE TRIGGER EXP_REP_TRG AFTER INSERT OR UPDATE on EXP_REP FOR EACH ROW myPlist SRW_PARAMLIST; myIdent SRW.JOB_IDENT; BEGIN IF :new.ExpStat = DONE THEN myPlist := SRW_PARAMLISTSRW_PARAMETER,; SRW.ADD_PARAMETERmyPlist,GATEWAY,http:…; SRW.ADD_PARAMETERmyPlist,SERVER,fooSVR; SRW.ADD_PARAMETERmyPlist,REPORT,foo.RDF; SRW.ADD_PARAMETERmyPlist,USERID,foobar; SRW.ADD_PARAMETERmyPlist,DISTRIBUTE,YES; SRW.ADD_PARAMETERmyPlist,DESTINATION,filename.xml; SRW.ADD_PARAMETERmyPlist,ExpenseID,:new.ExpID; myIdent := SRW.RUN_REPORTmyPlist; END IF; END; This is one way to move this kind of logic from your application into the database and use the database as a central storage for business processes.

21.4 Integrating with Oracle Advanced Queuing

Oracle Advanced Queuing is a means for building an asynchronous requestresponse mechanism around a so-called queue and two processes: ENQUEUE, which puts MESSAGES into a queue, and DEQUEUE, which reads the queue. Advanced queuing provides sophisticated mechanisms for distributing messages across queues and for queue subscription. These mechanisms are all built on top of these basic elements ENQUEUE, DEQUEUE, and MESSAGES. With the Event-Driven Publishing API you can use these queues to store and transmit report jobs. You can even build your own queuing mechanism if the one provided with Oracle Reports Services does not fit your needs.

21.4.1 Creating a Queue That Holds Messages of Type SRW_PARAMLIST

A queue is a table in the database that holds, along with several administrative columns, an object column that represents a message. In our case the message is the parameter list. Note: Youll find additional examples of the Event-Driven Publishing API in action in the demo script srw_test.sql, included with your Oracle Reports Services installation. 21-8 Publishing Reports to the Web with Oracle Reports Services The dbms_AQadm package, provided with Advanced Queuing, contains all the administrative functions required for setting up an advanced queuing system. Use dbms_AQadm.Create_Queue_Table to create the physical table in the database. You must pass it a name for the table and a name for the object type that will define the message for this queue. For example: … execute dbms_AQadm.Create_Queue_Table queue_Table=queuename._tab, queue_Payload_Type=SRW_PARAMLIST_OBJECT, compatible=9.0; In earlier examples, we created the object type SRW_PARAMLIST_OBJECT that encapsulates the SRW_PARAMLIST type in object notation so it can be used as a message. After creating the queue table, you must create the queue with dbms_ AQadm.Create_Queue and start the queue with dbms_AQadm.Start_Queue. For example: … execute dbms_AQadm.Create_Queue Queue_Name=queuename,Queue_Table=queuename._tab; prompt … starting queue execute dbms_AQadm.Start_Queue Queue_Name=queuename; … Having created and started the queue, what you need now is a procedure that creates a message in this queue and a procedure that reads out the queue and submits the job to the server. These are discussed in the following sections. 21.4.2 Creating the Enqueuing Procedure The enqueuing procedure is responsible for putting a message into the queue. This procedure can be part of your application, called by a database-trigger, or provided through an external mechanism. In this section, we will provide an example of creating a stored procedure that puts a simple message in this queue. Because our message is the parameter list itself, the procedure is fairly easy. We use the same code we used in earlier sections to create a parameter list. In addition to the variables we used, we define an object variable to hold the message we will put into the queue. … plist_object SRW_ParamList_Object; … After creating the parameter list we create the actual message object using the object constructor. … Note: Youll find a complete example for setting up, creating, and starting a simple queue in the demo file srwAQsetup.sql, included with your Oracle Reports Services installation.