Reaching out from PL/SQL (Oracle Open World 2011)

3,199 views
3,018 views

Published on

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.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,199
On SlideShare
0
From Embeds
0
Number of Embeds
670
Actions
Shares
0
Downloads
65
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • 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
  • http://tylermuth.wordpress.com/2008/02/04/image-caching-in-plsql-applications/
  • 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.
  • http://technology.amis.nl/blog/?p=2498
  • http://technology.amis.nl/blog/?p=2498
  • Reaching out from PL/SQL (Oracle Open World 2011)

    1. 1. Reaching Out from PL/SQL<br />Lucas Jellema – AMIS (Nieuwegein, The Netherlands)<br />Oracle Open World 2011<br />
    2. 2. Ask what you can do for your country?!<br />Do not ask what your country can do for you<br />
    3. 3. and Also Ask what you (through PL/SQL & the Database) can do for your “environment”?!<br />By all means, ask what the world around you can mean for your PL/SQL application<br />
    4. 4. Database<br />(SQL & PL/SQL)<br />
    5. 5. SOA<br />Database<br />(SQL & PL/SQL)<br />
    6. 6. JDBC, SQL Net, DB Link<br />RSS<br />File <br />(Excel, PDF,…)<br />File, O/S<br />Email<br />Queue<br />Database<br />(SQL & PL/SQL)<br />Chat (IM)<br />WebService<br />User Interface<br />REST<br />
    7. 7. The Human Side of Things<br />
    8. 8. EMP<br />
    9. 9. Challenges<br />
    10. 10. EMP<br />
    11. 11.
    12. 12.
    13. 13. Q<br />
    14. 14. Job<br />receiveMailsendEmail<br />retrieve_emails<br />JSP_WRAPPER<br />`<br />EMAILS<br />Mail Server<br />AQ<br />Process_email<br />notify_email_event<br />EMP<br />
    15. 15. Java Stored Procedures<br />Java Classes can be loaded into Oracle Database as Java Stored Procedures<br />The “JSPs” are wrapped with a PL/SQL wrapper<br />When invoked no different from normal PL/SQL units<br />JSPs are in same session and transaction<br />JSPs are static<br />Java Stored Procedures can complement PL/SQL<br />for example in dealings with O/S, Mail Server, Application Server, IM Server, TCP/IP, Embedded, Devices<br />JMX is exposed by Java-in-Database to monitor <br />
    16. 16. Java Stored Procedures – Java behind PL/SQL wrapper<br />
    17. 17. 1<br /><ul><li>Write Functional Java</li></ul>2<br /><ul><li>Wrap with PL/SQL</li></ul>3<br /><ul><li>Load into Database</li></ul>4<br /><ul><li>Set appropriate Privs</li></ul>5<br /><ul><li>Invoke JSP via PL/SQL Interface</li></li></ul><li>The ultimate outreach…<br />
    18. 18. Other scenario with database as initiator of the dialog<br />An Update of an Employee’s Salary takes place<br />After Update Row level trigger fires<br />creates job to send out an email to have someone approve the salary raise<br />Sets the status of the salary to ‘awaiting approval’<br />Email is sent to approver<br />Approvers sends an answer<br />Decision and comments<br />Answer is received & processed by database<br />Status of salary record is updated<br />
    19. 19.
    20. 20. Libraries for:<br /><ul><li> Graphical Manipulation
    21. 21. Translation,
    22. 22. Calculation,
    23. 23. Encryption,
    24. 24. …</li></ul>Email<br />CommunicationProtocols: http, ftp, tcpip, sms, grid, JDBC, JDBC-ODBC, .Net, …<br />JMS<br />Operating System& File System<br />EJB<br />
    25. 25. http<br />http<br />ftp<br />webdav<br />dbms_epg<br />(mod_plsql)<br />XMLDB<br />utl_mail<br />external<br />table<br />utl_file<br />
    26. 26. APEX<br />The Ultimate Database User Interface<br />dbms_epg<br />(mod_plsql)<br />
    27. 27. Database Reaching Out to Human partners<br />DBMS_EPG (or good old mod_plsql)<br />Expose HTML and RSS & Process HTTP requests<br />XMLDB<br />Expose and allow manipulation of resources through HTTP, FTP and WEBDAV<br />Stored Java Procedures to<br />Interact with Mail Server, Chat; leverage <br />Process human file formats (PDF, Excel, images, …)<br />Supplied packages: UTL_MAIL, UTL_FILE<br />
    28. 28. Expose Stored Procedures via HTTP<br />Stored Procedures and Packages can be configured to handle HTTP requests<br />Using the supplied DBMS_EPG package<br />They compose the HTTP response by writing strings to the HTP.P procedure<br />Or return binary documents using wpg_docload<br />Database infrastructure handles HTTP communication <br />including security, headers, get/post parameters<br />Embedded PLSQL Gateway – powering<br />APEX and other PL/SQL based HTML UI<br />Expose RESTful Web Services<br />Publish RSS Feeds<br />Asynchronous HTTP notifications<br />
    29. 29. Publish package as http-based API using dbms_epg<br />Hide database protocol<br />Not its physical location nor the schema, and user authentication<br />HTTP communication is truly cross technology<br />Browser, Java, .Net, JavaScript & RIA clients, …<br />Is also possibly remote, across networks, firewalls etc. <br />easier than normal JDBC connections<br />Can publish in various formats<br />Text, HTML, CSV, JSON, XML, RSS<br />Use case:cross-technology, internal no WS*/ESB<br />http<br />
    30. 30. Simple DBMS_EPG example<br />sys<br />scott<br />scott<br />
    31. 31. Machinations<br />
    32. 32. Call for decoupling<br />Minimize dependencies and maximize interoperability and reuse<br />Through decoupling:<br />Encapsulate functionality, legacy and complexity<br />Interact through well defined interfaces<br />Support standard protocols and cross technology facilities (XML, HTTP, JSON, SQL)<br />Leverage asynchronous exchange whenever relevant<br />Take care of the data(base)<br />‘No SQL’ approach: SQL is encapsulated inside database API (View and Package)<br />SQL is not left to application developers or 3rd party frameworks<br />Data integrity is enforced inside the database<br />
    33. 33. Extreme Encapsulation<br />View on top of table(collection)<br />With instead of trigger handling DML<br />Data queried from NUMBERS is produced in PL/SQL – no underlying table involved<br />Data manipulated in NUMBERS is processed in memory<br />View Numbers<br />Package P<br />
    34. 34. Extreme Encapsulation<br />
    35. 35. JDBC, SQL Net, DB Link<br />Chat (IM)<br />RSS<br />Email<br />File, O/S<br />http<br />http<br />AQjms<br />http<br />ftp<br />webdav<br />Queue<br />utl_http<br />(httpuritype)<br />dbms_epg<br />(mod_plsql)<br />AdvancedQueuing<br />Database<br />(SQL & PL/SQL)<br />XMLDB<br />WebService<br />JDBC/ODBCOCI, DB Link<br />REST<br />utl_mail<br />external<br />table<br />utl_tcp<br />utl_file<br />native<br />dbws<br />
    36. 36. XML<br />Relational/Oracle Type<br />WebLogic Server<br />Database<br />Native DB WebService<br />HTTP<br />EPG<br />http<br />PL/SQL package<br />ADF BC/SDO WS<br />JSON/ CSV<br />JDBC<br />SOA Suite<br />SDO<br />XML<br />XML & XSD<br />WS<br />JAX-WS<br />Ref Cursor<br />JPublisher WS<br />DB<br />Types & Coll<br />XML<br />AQ<br />Types<br />AQ<br />View<br />JMS Queue<br />utl_file, BFILE, URITYPE<br />JMS<br />Oracle Service Bus<br />Table<br />EJB/JPA<br />EJB<br />Other<br />(Email, FTP/File, XMPP/Chat)<br />XMLDB<br />File<br />FTP<br />UMS<br />Chat/IM XMPP Server<br />File/FTP Server<br />Email Server<br />
    37. 37. Be a good host<br />Provide services<br />Views for easy querying<br />Stored Procedure based APIs<br />For data retrieval and data manipulation<br />Queues as way-in (publish) as well as way-out (allow subscription) for events<br />Send change notifications<br />Http based push messages<br />Query Result Change Notification<br />
    38. 38. The Super Host<br />Query Result Change Notification<br />
    39. 39. Query Result Change Notification<br />Continuous Query Notification:<br />Send an event when the result set for a query changes<br />Background process calls PL/SQL Handler or Java Listener or OCI client when thecommit has occurred<br />Event contains rowidof changed rows<br />Used for:<br />Refreshing specificdata caches (middletier, global context)<br />(custom) Replication<br />Java Listener<br />PL/SQL<br />
    40. 40. Database to Middle Tier to Client notification through http<br />Session cache<br />Application Scope <br />event handler<br />D<br />4<br />3<br />9<br />C<br />5<br />A<br />servlet<br />servlet<br />1<br />8<br />2<br />HTTP<br />B<br />Proce-dure<br />7<br />UTL_HTTP<br />EMP<br />Job<br />6<br />
    41. 41. Cross Tier Push<br />Web Browser<br />JEE Application Server<br />evtlsnr<br />servlet<br />RDBMS<br />job<br />trg<br />
    42. 42. More Interaction from & to the database<br />Files into the database<br />Database to leverage O/S<br />Stored Java for non-human interactions<br />WebServices – publish and consume<br />Engage Middle Tier as ‘agent’ <br />
    43. 43. The browser in your databaseIntroducing UTL_HTTP<br />≈<br />select utl_http.request<br /> ( 'http://technology.amis.nl/blog/?feed=rss2'<br /> , null<br /> )<br />from dual<br />
    44. 44. The database can ask the middle tier to access and provide services<br />Get information from (or to) services on the intranet or internet <br />Publish/Send information to the internet (RSS, email, chat)<br />Can tell the middle tier<br />Interesting events <br />Alert about (im)pending issues, attempted rule violations, …<br />The outcome of batch calculations<br />DB vs. Middle Tier:Security, Functionality, Load Balance<br />WebLogic Server 11g<br />SOA Suite 11g<br />Web App<br />AQ<br />
    45. 45. Happy Chatting – IM from the Database<br />Database can call a middletier service using utl_httpor HTTPURITYPE<br />Passing in the destinationand the message content<br />This Service sends it onwards to the Google Talk Server<br />WebLogic Server 11g<br />Service<br />Service<br />CHAT_MGR<br />
    46. 46. Database actively informs on events<br />WebLogic Server 11g<br />Service<br />Service<br />CHAT_MGR<br />EMP<br />
    47. 47. Chat Manager package<br />create or replace package body chat_mgr<br />as<br />c_im_destination CONSTANT varchar2(100):= 'im_account'; <br />c_im_service_base_url CONSTANT varchar2(100):= 'http://host/service?'; <br />c_amp constant varchar2(5) := chr(38);<br />procedure send_im_message( p_msg in varchar2) is<br /> l_response varchar2(32000);<br />begin<br /> l_response:= utl_http.request<br /> ( c_im_service_base_url ||'imDestination='||c_im_destination ||c_amp||'msgBody='||replace(p_msg,' ', '%20')<br /> , null<br /> );<br />end send_im_message;<br />end chat_mgr;<br />
    48. 48. Emp Informer<br />create or replace trigger mananager_sal_update_watcher<br />before insert or update of sal<br />on emp<br />for each row<br />when (new.job ='MANAGER' and new.sal > 4000 and new.sal > nvl(old.sal,0))<br />declare<br /> l_msg varchar2(32000);<br />begin<br /> l_msg:= 'Selfenrichment '<br /> ||'Salary of '||:new.ename<br /> ||' ( manager in Department '||:new.deptno||') '<br /> ||'is changed to '||:new.sal<br /> ;<br /> chat_mgr.send_im_message<br /> ( p_msg => l_msg<br /> );<br />end;<br />
    49. 49. The Talking Database<br />Details on the Employee. Employee name is Smith, his job is Analyst. He works in department 20…<br />EMP<br />
    50. 50. The Talking Database<br />audio/mpeg, binary data<br />http<br />PL/SQLexposed through dbms_epg<br />
    51. 51.
    52. 52.
    53. 53. RESTfulWebServices<br />Simple, stateless, light weight, http-based message exchange protocol<br />Use standard get, put, post, delete operations<br />Use URL to pass resource reference<br />Small, easy-to-understand messages<br />Typically XML or JSON based<br />Not using SOAP, or the WS*-stack<br />Often used directly from User Interface – (AJAX enabled) JavaScript<br />RESTful services are primary communication mechanism for Mobile Apps<br />
    54. 54. RESTful architecture<br />http<br />http<br />RESTful PL/SQL APIexposed through dbms_epg<br />
    55. 55. RESTful resource navigation<br />
    56. 56. Publish REST-ful HTTP API – directly on top of the RDBMS<br />
    57. 57. Publish REST-ful HTTP API – directly on top of the RDBMS<br />
    58. 58. Consuming REST-ful services<br />Invoking a REST-ful service is simply making an HTTP request to some URL<br />Can be done through:<br />utl_http<br />httpuritype<br />Stored Java<br />Result can be processed as just a string or as XML, JSON or other format<br />OSS Libraries can help with special formats, for example PL/JSON for JSON<br />
    59. 59. SOAP WebServices<br />All messages (input and output) are XML<br />The message consists of two parts inside an envelope (a SOAP XML wrapper)<br />The header with meta-data<br />The body with the contents to be handled by or returned by the service<br />The WebService Definition Language (WSDL) document describes the service<br />An XML Schema Document (XSD) describes the structure of the XML messages<br />XSD is like an ERD or Table Design<br />
    60. 60. Calling ‘formal’ WS* andSOAP based Web Services<br />Invoking a SOAP WS* service is making an HTTP request to some URL<br />Can be done through:<br />utl_http<br />Stored Java<br />utl_dbws<br />Request and Responseare both SOAP-wrapped XML messages<br />Using XMLDB functionality including XML Type these can easily by composed, transformed, validated and parsed<br />
    61. 61. Oracle RDBMS 11g – Native Database WebServices<br />Database Schema can be published through native database web services<br />Each package corresponds with a WSDL<br />With an operation for each Procedure or Function<br />Auto-mapping from PL/SQL input and output parameters to WSDL (XSD) Types<br />WSDL and XSD are dynamically generated<br />A generic Query Service (across schema) is exposed<br />To execute user defined queries<br />With support for pagination and some formatting<br /><ul><li>http and https is supported
    62. 62. Limited control over WSDL & XSD
    63. 63. Use case: internal, cross technology, WS enabled client, no ESB or Application Server available</li></li></ul><li>Summary<br />
    64. 64. Session Plugging<br />Sunday – Gold Nuggets in ADF (S32502)3.15-4.15, Moscone West-2000<br />Tuesday – Reaching Out from PL/SQL (S08625 )10.15-11.15, Mariott Marquis, Salon 7<br />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<br />Wednesday – Push to the Limit: Rich and Proactive User Interfaces with Oracle ADF (S08620)5-6 PM, Mariott Marquis, Golden Gate A<br />Thursday –Instant Agility in Oracle Fusion Middleware through Design Time @ Run Time (S08623)4-5 PM, Moscone West – 2020<br />

    ×