PL/SQL applications do not live on an island. Increasingly, applications need relate to the rest of the world. Either to make themselves and the services they provide accessible to external parties - that may not speak PL/SQL at all - or to access information or enlist help from external services. PL/SQL can do much more than invoke other PL/SQL applications or execute SQL as it provides many inbound and outbound channels for such interactions. This session demonstrates a number of channels and discusses when and why to use them and how to use them, including HTTP and WebServices for RSS, SOAP and REST, Java for JDBC, JMS, Email and Chat. The demos include PL/SQL responding to requests as well as pushing messages out to external consumers.
Push to the limit - rich and pro-active user interfaces with ADF
Visual appeal and desktop-like reaction to user input were key elements in Web 2.0, powered by AJAX. The next generation user interface is active - presenting data and events in real time, driven by server push technology. This session demonstrates how ADF Active Data Service (ADS) and the BAM Data Control are leveraged to create an active UI. Messages arriving on JMS, through HTTP, from Complex Event Processing and from email servers are pushed to the browser, updating charts, tables and even causing popups to open. The session demonstrates a Chat implementation integrated in a Fusion Web application. It also shows how Database Query Result Change Notification and ADS allow events to be pushed from database all the way to user interface.
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Reaching out from PL/SQL (Oracle Open World 2011)
1. Reaching Out from PL/SQL Lucas Jellema – AMIS (Nieuwegein, The Netherlands) Oracle Open World 2011
2. Ask what you can do for your country?! Do not ask what your country can do for you
3. and Also Ask what you (through PL/SQL & the Database) can do for your “environment”?! By all means, ask what the world around you can mean for your PL/SQL application
15. Java Stored Procedures Java Classes can be loaded into Oracle Database as Java Stored Procedures The “JSPs” are wrapped with a PL/SQL wrapper When invoked no different from normal PL/SQL units JSPs are in same session and transaction JSPs are static Java Stored Procedures can complement PL/SQL for example in dealings with O/S, Mail Server, Application Server, IM Server, TCP/IP, Embedded, Devices JMX is exposed by Java-in-Database to monitor
18. Other scenario with database as initiator of the dialog An Update of an Employee’s Salary takes place After Update Row level trigger fires creates job to send out an email to have someone approve the salary raise Sets the status of the salary to ‘awaiting approval’ Email is sent to approver Approvers sends an answer Decision and comments Answer is received & processed by database Status of salary record is updated
27. Database Reaching Out to Human partners DBMS_EPG (or good old mod_plsql) Expose HTML and RSS & Process HTTP requests XMLDB Expose and allow manipulation of resources through HTTP, FTP and WEBDAV Stored Java Procedures to Interact with Mail Server, Chat; leverage Process human file formats (PDF, Excel, images, …) Supplied packages: UTL_MAIL, UTL_FILE
28. Expose Stored Procedures via HTTP Stored Procedures and Packages can be configured to handle HTTP requests Using the supplied DBMS_EPG package They compose the HTTP response by writing strings to the HTP.P procedure Or return binary documents using wpg_docload Database infrastructure handles HTTP communication including security, headers, get/post parameters Embedded PLSQL Gateway – powering APEX and other PL/SQL based HTML UI Expose RESTful Web Services Publish RSS Feeds Asynchronous HTTP notifications
29. Publish package as http-based API using dbms_epg Hide database protocol Not its physical location nor the schema, and user authentication HTTP communication is truly cross technology Browser, Java, .Net, JavaScript & RIA clients, … Is also possibly remote, across networks, firewalls etc. easier than normal JDBC connections Can publish in various formats Text, HTML, CSV, JSON, XML, RSS Use case:cross-technology, internal no WS*/ESB http
32. Call for decoupling Minimize dependencies and maximize interoperability and reuse Through decoupling: Encapsulate functionality, legacy and complexity Interact through well defined interfaces Support standard protocols and cross technology facilities (XML, HTTP, JSON, SQL) Leverage asynchronous exchange whenever relevant Take care of the data(base) ‘No SQL’ approach: SQL is encapsulated inside database API (View and Package) SQL is not left to application developers or 3rd party frameworks Data integrity is enforced inside the database
33. Extreme Encapsulation View on top of table(collection) With instead of trigger handling DML Data queried from NUMBERS is produced in PL/SQL – no underlying table involved Data manipulated in NUMBERS is processed in memory View Numbers Package P
36. XML Relational/Oracle Type WebLogic Server Database Native DB WebService HTTP EPG http PL/SQL package ADF BC/SDO WS JSON/ CSV JDBC SOA Suite SDO XML XML & XSD WS JAX-WS Ref Cursor JPublisher WS DB Types & Coll XML AQ Types AQ View JMS Queue utl_file, BFILE, URITYPE JMS Oracle Service Bus Table EJB/JPA EJB Other (Email, FTP/File, XMPP/Chat) XMLDB File FTP UMS Chat/IM XMPP Server File/FTP Server Email Server
37. Be a good host Provide services Views for easy querying Stored Procedure based APIs For data retrieval and data manipulation Queues as way-in (publish) as well as way-out (allow subscription) for events Send change notifications Http based push messages Query Result Change Notification
39. Query Result Change Notification Continuous Query Notification: Send an event when the result set for a query changes Background process calls PL/SQL Handler or Java Listener or OCI client when thecommit has occurred Event contains rowidof changed rows Used for: Refreshing specificdata caches (middletier, global context) (custom) Replication Java Listener PL/SQL
40. Database to Middle Tier to Client notification through http Session cache Application Scope event handler D 4 3 9 C 5 A servlet servlet 1 8 2 HTTP B Proce-dure 7 UTL_HTTP EMP Job 6
41. Cross Tier Push Web Browser JEE Application Server evtlsnr servlet RDBMS job trg
42. More Interaction from & to the database Files into the database Database to leverage O/S Stored Java for non-human interactions WebServices – publish and consume Engage Middle Tier as ‘agent’
43. The browser in your databaseIntroducing UTL_HTTP ≈ select utl_http.request ( 'http://technology.amis.nl/blog/?feed=rss2' , null ) from dual
44. The database can ask the middle tier to access and provide services Get information from (or to) services on the intranet or internet Publish/Send information to the internet (RSS, email, chat) Can tell the middle tier Interesting events Alert about (im)pending issues, attempted rule violations, … The outcome of batch calculations DB vs. Middle Tier:Security, Functionality, Load Balance WebLogic Server 11g SOA Suite 11g Web App AQ
45. Happy Chatting – IM from the Database Database can call a middletier service using utl_httpor HTTPURITYPE Passing in the destinationand the message content This Service sends it onwards to the Google Talk Server WebLogic Server 11g Service Service CHAT_MGR
47. Chat Manager package create or replace package body chat_mgr as c_im_destination CONSTANT varchar2(100):= 'im_account'; c_im_service_base_url CONSTANT varchar2(100):= 'http://host/service?'; c_amp constant varchar2(5) := chr(38); procedure send_im_message( p_msg in varchar2) is l_response varchar2(32000); begin l_response:= utl_http.request ( c_im_service_base_url ||'imDestination='||c_im_destination ||c_amp||'msgBody='||replace(p_msg,' ', '%20') , null ); end send_im_message; end chat_mgr;
48. Emp Informer create or replace trigger mananager_sal_update_watcher before insert or update of sal on emp for each row when (new.job ='MANAGER' and new.sal > 4000 and new.sal > nvl(old.sal,0)) declare l_msg varchar2(32000); begin l_msg:= 'Selfenrichment ' ||'Salary of '||:new.ename ||' ( manager in Department '||:new.deptno||') ' ||'is changed to '||:new.sal ; chat_mgr.send_im_message ( p_msg => l_msg ); end;
49. The Talking Database Details on the Employee. Employee name is Smith, his job is Analyst. He works in department 20… EMP
50. The Talking Database audio/mpeg, binary data http PL/SQLexposed through dbms_epg
51.
52.
53. RESTfulWebServices Simple, stateless, light weight, http-based message exchange protocol Use standard get, put, post, delete operations Use URL to pass resource reference Small, easy-to-understand messages Typically XML or JSON based Not using SOAP, or the WS*-stack Often used directly from User Interface – (AJAX enabled) JavaScript RESTful services are primary communication mechanism for Mobile Apps
58. Consuming REST-ful services Invoking a REST-ful service is simply making an HTTP request to some URL Can be done through: utl_http httpuritype Stored Java Result can be processed as just a string or as XML, JSON or other format OSS Libraries can help with special formats, for example PL/JSON for JSON
59. SOAP WebServices All messages (input and output) are XML The message consists of two parts inside an envelope (a SOAP XML wrapper) The header with meta-data The body with the contents to be handled by or returned by the service The WebService Definition Language (WSDL) document describes the service An XML Schema Document (XSD) describes the structure of the XML messages XSD is like an ERD or Table Design
60. Calling ‘formal’ WS* andSOAP based Web Services Invoking a SOAP WS* service is making an HTTP request to some URL Can be done through: utl_http Stored Java utl_dbws Request and Responseare both SOAP-wrapped XML messages Using XMLDB functionality including XML Type these can easily by composed, transformed, validated and parsed
64. Session Plugging Sunday – Gold Nuggets in ADF (S32502)3.15-4.15, Moscone West-2000 Tuesday – Reaching Out from PL/SQL (S08625 )10.15-11.15, Mariott Marquis, Salon 7 Tuesday – (JavaOne) Cross Tier Push Architecture (Don’t call us, we’ll push you) (S24722)4.30-5.15 PM, Hotel Nikko, Monterey I/II Wednesday – Push to the Limit: Rich and Proactive User Interfaces with Oracle ADF (S08620)5-6 PM, Mariott Marquis, Golden Gate A Thursday –Instant Agility in Oracle Fusion Middleware through Design Time @ Run Time (S08623)4-5 PM, Moscone West – 2020
Notas del editor
PL/SQL applications do not live on an island. Increasingly, applications need relate to the rest of the world. Either to make themselves and the services they provide accessible to external parties - that may not speak PL/SQL at all - or to access information or enlist help from external services. PL/SQL can do much more than invoke other PL/SQL applications or execute SQL as it provides many inbound and outbound channels for such interactions. This session demonstrates a number of channels and discusses when and why to use them and how to use them, including HTTP and WebServices for RSS, SOAP and REST, Java for JDBC, JMS, Email and Chat. The demos include PL/SQL responding to requests as well as pushing messages out to external consumers.
By reaching out I help ensure that the (Oracle) database keeps its rightful place in the IT landscape of organizations ( as well as the database developers)
Screenshot:Frank sends email to Maggie – with a query on EmployeesAfter some time, a response is sent to this particular email – by the queue listener using the JSP to send(list of employee data, corresponding with “query”)
The job is scheduled to run every minuteIt calls upon the Java Stored Procedure to retrieve the newly arrived email-messages – in a specific accountFor each message, an email event is enqueue in the AQ Queue. The new email-messages are subsequently removed.A queue listener has been registered on the queue with email eventsEvery email (event) is dequeued and processedThe email can contain query statements – in some form – that the processor knows how to handleThe reply to the query is then sent in an email message that forms the response to the original email messageNote: other listeners could dequeue the email events and process them in other waysIncoming messages from other sources could be retrieved and processed in a similar way as email messages (VOIP, SMS, IM/Chat, Twitter)The database can both send and retrieve messages from such serversNote: Java is much better equipped than plain PL/SQL (that really only has utl_http, utl_tcp, utl_smtp) for customized, flexible, advanced interaction with a wide range of infrastructures and technologies.
Write functional JavaFor example in JDeveloperUsing the full richness of the IDE and of the Java Language (and libraries)Wrap with PL/SQL Map Java & PL/SQL data types Load into DatabaseCustom classes and libraries (JAR-files)Set appropriate privilegesInvoke JSP through a normal PL/SQL interface
Challenge:Link email sent out to response received (some identification is required)Structure of the answer: how to recognize the decision and comment
Java is much better equipped than plain PL/SQL (that really only has utl_http, utl_tcp, utl_smtp) for customized, flexible, advanced interaction with a wide range of infrastructures and technologies.Java libraries can help to generate PDF, create and/or read Word and Excel etc.Through JMS – external Java applications can be accessed in a decoupled way. For example: Complex Event Processor
Java is much better equipped than plain PL/SQL (that really only has utl_http, utl_tcp, utl_smtp) for customized, flexible, advanced interaction with a wide range of infrastructures and technologies.Java libraries can help to generate PDF, create and/or read Word and Excel etc.Through JMS – external Java applications can be accessed in a decoupled way. For example: Complex Event Processor
1.8.3.1 Continuous Query Notification EnhancementsContinuous Query Notification has been enhanced to provide notifications when the result set for a query changes on the server. These notifications can be registered at the row-level, rather than just at the table-level. Thus, alerts will only be sent when changes to the specific rows selected have been modified.Applications, such as Radio Frequency Identification (RFID), can now receive notifications directly from the database rather than build this functionality into the application.