Your SlideShare is downloading. ×
0
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Modern Database Development Oow2008 Lucas Jellema

1,814

Published on

Presentation from Oracle Open World 2008 on actual Database Development considering 10g/11g features and trends outside the database.

Presentation from Oracle Open World 2008 on actual Database Development considering 10g/11g features and trends outside the database.

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

No Downloads
Views
Total Views
1,814
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
89
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • This presentation goes into the many--relatively unknown--features in the recent Oracle Database releases that can help complex Web application development. You can do so much more in the database than most Java developers realize. The session shows some useful tricks for leveraging the database, such as view and IOT, PL/SQL collections and table function/MULTISET, application context, factored (inline) queries, outer joins.
  • Transcript

    • 1. Optimal Use of Oracle Database 10g and Oracle Database 11g for Modern Application Development Lucas Jellema AMIS, The Netherlands Oracle Open World, San Francisco September 2008
    • 2. What is Modern ? SOA (operational) Analytics event XML SAAS S-Ox/Audit Service MultiMedia Tera Byte 24/7 Global Asynchronous Fuzzy I18n (internationalization) Business Rules Data Integrity Share/Collaboration Enterprise 2.0 Message OO Decoupling Security Personalization Scalability B2B
    • 3. What is Modern ? <ul><li>What becomes possible </li></ul><ul><ul><li>New functionality in software, new facilities in infrastructure </li></ul></ul><ul><ul><li>Support for Cloud Computing, Database Accelerator </li></ul></ul><ul><li>What becomes affordable </li></ul><ul><ul><li>Promotion of features from Extra Cost Option to EE to SE </li></ul></ul><ul><li>What becomes desirable </li></ul><ul><ul><li>Encapsulation of SQL, Service Orientation, Active Database </li></ul></ul><ul><li>What becomes inevitable </li></ul><ul><ul><li>Sarbanes Oxley, 24/7 & global </li></ul></ul><ul><li>What becomes visible </li></ul><ul><ul><li>Subquery Factoring, Instead of Trigger, Ref Cursors, Flashback </li></ul></ul>
    • 4. Some valuable 11g examples <ul><li>‘ Total recall’ – Flashback Data Archive </li></ul><ul><ul><li>Makes Historical Data reliably available, which in turn puts Flashback in the hands of application developers </li></ul></ul><ul><li>Virtual Columns – organized redundancy and PL/SQL expression based constraints and indexes </li></ul><ul><li>Compound Trigger – clean work-around for mutating table violation </li></ul><ul><li>Result Cache – declarative caching of calculated results </li></ul><ul><ul><li>SQL Query Result Cache & PL/SQL Function Result Cache </li></ul></ul><ul><li>DBMS_COMPARISON – compare and merge records </li></ul><ul><li>Continuous Query Notification – alert listeners (PL/SQL and external) of relevant data changes </li></ul>
    • 5. Several often neglected features <ul><li>Large Volume, Batch Processing </li></ul><ul><ul><li>Single SQL statement bulk DML/ETL: Multi Table Insert, Merge, (pipelined) Table Functions </li></ul></ul><ul><ul><li>DML error logging </li></ul></ul><ul><li>Analytical functions </li></ul><ul><ul><li>Compare between rows (look forward: lead, look back: lag) </li></ul></ul><ul><ul><li>Aggregation along several axes and levels in a single query </li></ul></ul><ul><li>Sub-query factoring </li></ul><ul><ul><li>Implementing complex query requirements using clear, managable and reusable pieces </li></ul></ul><ul><li>Case Expression </li></ul><ul><ul><li>Real If-Then-Else in SQL and PL/SQL (forget DECODE) </li></ul></ul>
    • 6. Several often neglected features <ul><li>‘ new’ join syntax and outer join functionality </li></ul><ul><ul><li>Readability, functionality, standardization </li></ul></ul><ul><li>‘ Hierarchical Queries’ (especially with sys_connect_by_path and connect_by_root) </li></ul><ul><ul><li>traverse any network data structure </li></ul></ul><ul><li>Object Types and Collections </li></ul><ul><ul><li>Improved integration between SQL and PL/SQL through Bulk Operations, Table & Multiset operators </li></ul></ul><ul><li>Ref Cursors </li></ul><ul><ul><li>Make query results available without revealing the SQL </li></ul></ul><ul><ul><li>for virtually any client (PL/SQL, C, .Net, Java, Ruby, PHP, …) </li></ul></ul><ul><li>Instead-Of triggers on Views </li></ul><ul><ul><li>Decouple DML from database design </li></ul></ul>
    • 7. Other gems worth mentioning <ul><li>Virtual Private Database – foundation for SaaS </li></ul><ul><li>Database Event Triggers (logon, create/drop/alter, …) </li></ul><ul><li>COLLECT operator – aggregate into collections </li></ul><ul><li>dbms_job – key to asynchronous processing </li></ul><ul><li>Application Context – context sensitive bind-parameter injection in frequently used queries </li></ul><ul><li>DBMS_APPLICATION_INFO – for instrumentation </li></ul><ul><li>dbms_epg – publish PL/SQL package through URL </li></ul><ul><li>Unpivot – turn multiple columns into multiple rows to untangle unfortunate database design </li></ul><ul><li>Rollup – aggregate at multiple levels in a single query </li></ul>
    • 8. Statements with regard to Database <ul><li>Database is nothing but a filing cabinet: </li></ul><ul><ul><li>Data goes in, data comes out; that’s it </li></ul></ul><ul><li>We should strive for database independence </li></ul><ul><ul><li>We may want to replace the (relational) database with ‘another data store’ </li></ul></ul><ul><li>Database portability must be maintained at any cost (vendor independence) </li></ul><ul><ul><li>We must be able to switch to another database vendor </li></ul></ul><ul><ul><li>Therefore we should only use functionality that is available in all (mainstream) database products </li></ul></ul>
    • 9. Trends in the world… <ul><li>Global – multi-timezone, multi-lingual </li></ul><ul><li>Multi-tier – web user <> database user </li></ul><ul><li>Resuable functionality available through services </li></ul><ul><li>SaaS – Software as a Service </li></ul><ul><ul><li>Single instance of application and database </li></ul></ul><ul><ul><li>Multiple remote organizations, many remote users </li></ul></ul><ul><li>Operational BI – analytics on the fly </li></ul><ul><li>Fading Application boundaries vs. Enterprise Data </li></ul><ul><li>Standardization – XML, SQL </li></ul><ul><li>Design Patterns – OO, Encapsulation, Decoupling, Asynchronous, Dependency Injection, Reuse, … </li></ul>
    • 10. Typical Architecture J(2)EE Application Server Batch Batch Batch Client Enterprise Service Bus DWH ?
    • 11. What goes where? <ul><li>What is the best place to do things? </li></ul><ul><ul><li>And what the very worst! </li></ul></ul><ul><li>Criteria: </li></ul><ul><ul><li>Functionality </li></ul></ul><ul><ul><li>Robustness </li></ul></ul><ul><ul><li>Performance </li></ul></ul><ul><ul><li>Ease of implementation and maintenance </li></ul></ul><ul><ul><li>Required skills </li></ul></ul><ul><ul><li>Agility </li></ul></ul><ul><ul><li>(License) Costs </li></ul></ul>
    • 12. Some proposed guidelines… <ul><li>No SQL in application </li></ul><ul><ul><li>Or at the very least centralized </li></ul></ul><ul><li>No HTML rendering in the database </li></ul><ul><li>No Data stored on the file system </li></ul><ul><ul><li>Or anywhere outside the database </li></ul></ul><ul><ul><ul><li>Except certain application meta-data </li></ul></ul></ul><ul><li>Database handles data access authorization </li></ul><ul><li>Client sets user identity, locale, time and date </li></ul><ul><li>Database is not accessed from outside the firewall </li></ul><ul><li>Bulk data manipulation in the database </li></ul>SQL ?
    • 13. Developing in the Oracle Database <ul><li>Prepare to be reused, e.g. from web-applications, the SOA environment, batch programs and other clients </li></ul><ul><ul><li>Hide implementation details (shield from change) </li></ul></ul><ul><ul><li>Publish reusable APIs </li></ul></ul><ul><ul><ul><li>Consider REF Cursor and XML </li></ul></ul></ul><ul><li>Leverage services offered outside the database </li></ul><ul><li>Guarantee data integrity in the database </li></ul><ul><ul><li>Do not rely on the clients to implement data rules </li></ul></ul><ul><li>Instrument – indicate what is going on (and where) </li></ul><ul><li>Avoid hard coded references and dependencies </li></ul><ul><ul><li>Including SYSDATE and USER and references to supplied packages – use configurable parameters and wrappers </li></ul></ul>
    • 14. The client is always right <ul><li>What time is it </li></ul><ul><ul><li>or at least what is the client’s timezone </li></ul></ul><ul><li>What locale is it </li></ul><ul><ul><li>which language/regional settings apply </li></ul></ul><ul><li>Where is it located </li></ul><ul><ul><li>what is the geographical location </li></ul></ul><ul><li>Who is it </li></ul><ul><ul><li>web user’s identity <> any database user </li></ul></ul><ul><li>Note: The database can only serve! </li></ul><ul><ul><li>Following the client’s lead </li></ul></ul>
    • 15. Single schema, light weight users <ul><li>End user authenticates through Client with the Mid-tier </li></ul><ul><li>Mid-tier connects to RDBMS through pooled connections to fixed application schema </li></ul><ul><li>Mid-tier informs the database of the ‘client identifier’: </li></ul><ul><ul><li>the light-weight client-user-identity, to be read with SYS_CONTEXT('USERENV‘ ,'CLIENT_IDENTIFIER') </li></ul></ul>J(2)EE Application Server Client LDAP APPLICATION_ SCHEMA USERENV
    • 16. Set Client Identifier with Light Weight User <ul><li>In Java using Oracle JDBC Driver </li></ul><ul><li>In PL/SQL </li></ul><ul><li>Or use a logon trigger to derive the client identifier </li></ul>conn. setClientIdentifier(&quot;john.doe&quot;) DBMS_SESSION.SET_IDENTIFIER( 'john.doe'); CREATE OR REPLACE TRIGGER logon_trigger AFTER LOGON ON DATABASE DECLARE  uid  VARCHAR2(64); BEGIN   SELECT ora_login_user ||':' ||SYS_CONTEXT('USERENV', 'OS_USER')   INTO uid   FROM dual;   dbms_session.set_identifier(uid); END logon_trigger;
    • 17. Set Client Identifier with Light Weight User <ul><li>In the database – SQL or PL/SQL – the current client identifier can be read like this: </li></ul><ul><li>The Client Identifier is also available in V$SESSION as well as V$SQLAREA </li></ul><ul><li>DBMS_MONITOR. CLIENT_ID_TRACE_ENABLE allows for tracing all activity of a CLIENT_I DENTIIER aka light-weight user </li></ul><ul><ul><li>Note: Oracle standard auditing does not use CLIENT_IDENTIFIER </li></ul></ul>SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') SELECT sid, client_identifier, service_name FROM v_$session;
    • 18. Current User Context <ul><li>Client can set applicable Locale, Organization Id, Timezone in a similar way in an Application Context </li></ul><ul><ul><li>Or have them derived from the user’s profile that is linked to the user identity </li></ul></ul><ul><li>The overall user context is potentially used in many ways </li></ul><ul><ul><li>Set audit columns (no more USER) </li></ul></ul><ul><ul><li>Set database (session) timezone </li></ul></ul><ul><ul><li>Return messages in appropriate language </li></ul></ul><ul><ul><li>Enforce data authorization </li></ul></ul><ul><ul><li>Expose Virtual Private Database </li></ul></ul>Attribute Value OrgId 14 Locale fr_ca Timezone +2.00 UserId ljellema
    • 19. Virtual Private Database and SaaS <ul><li>SaaS applications (pka ASP) have a single application & database instance, used by many remote users </li></ul><ul><li>Users share the application and the database, yet: </li></ul><ul><ul><li>Do not share (all) data </li></ul></ul><ul><ul><li>May have specific application customizations </li></ul></ul><ul><ul><li>Can define personal translations/renditions of boilerplate </li></ul></ul><ul><ul><li>Have their own set of user preferences or settings </li></ul></ul><ul><li>When asked for data from such tables as USER_PREFERENCES, FLEX_ITEMS and MESSAGES </li></ul><ul><ul><li>the database should apply the current user context to return the appropriate slice of the data </li></ul></ul>
    • 20. SAAS – MultiOrg - Authorization J(2)EE Application Server A B C Customer C Customer B Customer C setClientIdentifier ORG USER Web Application blindly queries a table for ‘all’ records Based on User Identifier, (in current context) determine Organization Only return records associated with that organization
    • 21. Implementing ‘Context Awareness’ <ul><li>Oracle Enterprise Edition: Virtual Private Database </li></ul><ul><ul><li>aka Fine Grained Access Control and Row Level Security </li></ul></ul><ul><ul><li>define policy and policy function to dynamically add to where </li></ul></ul><ul><li>Poor man’s VPD (Standard Edition/Express) </li></ul><ul><ul><li>Create a view for every context aware table </li></ul></ul><ul><ul><ul><li>Add where clause that filters based on context </li></ul></ul></ul><ul><ul><ul><li>Have the applications access data through views </li></ul></ul></ul><ul><ul><li>Create DML triggers on each context aware table that </li></ul></ul><ul><ul><ul><li>raise access violation exception when DML occurs outside of the current user context (e.g. delete data owned by other organization) </li></ul></ul></ul><ul><ul><ul><li>set context specific columns on newly inserted record – such as USER_ID and/or ORGANIZATION_ID </li></ul></ul></ul>
    • 22.  
    • 23. Fuzzy Search - From = to ≈ <ul><li>Many searches do not require only exact matches </li></ul><ul><li>For example: we are looking for employees who earn approximately 1500 and started in 1982 or thereabouts </li></ul><ul><ul><li>Exact match: select * from emp where salary = 1500 AND extract (year from hiredate) = 1982 </li></ul></ul><ul><ul><li>Everything in a bandwidth matches: where salary between 1000 and 2000 AND extract (year from hiredate) between 1981 and 1983 </li></ul></ul><ul><ul><li>However: the closer the better </li></ul></ul><ul><li>Example: Oracle Text (score) and Google </li></ul>
    • 24. Fuzzy Search - From = to ≈ <ul><li>Our criteria are: </li></ul><ul><ul><li>Say the salary should be as close as possible to 1500 and be at least between 1000 and 2000 </li></ul></ul><ul><ul><li>The hiredate should ideally be in 1982; however, 1983 is somewhat acceptable (half the score for 1982) </li></ul></ul><ul><ul><li>We value a match on salary higher than one on hiredate (twice as important) </li></ul></ul><ul><ul><li>We want the top 5 scoring Employees </li></ul></ul>score salary 1500 0 1 1000 2000
    • 25. Scoring on Salary
    • 26. Scoring on Hiredate
    • 27. Left Outer Join <ul><li>Left Outer Join is used to state that: </li></ul><ul><ul><li>After taking every record from EMP </li></ul></ul><ul><ul><li>Optionally add the sal_around_1500 score </li></ul></ul><ul><ul><li>Optionally add the emp_hiredate_1982 score </li></ul></ul><ul><li>Note how the ISO/ANSI SQL (Oracle 9i) join syntax allows continuous joining to multiple sources </li></ul><ul><ul><li>We can throw in right outer join and full outer join as well </li></ul></ul><ul><ul><li>Separate the Join condition and the Where clause </li></ul></ul>
    • 28. The top 5 of best matching records <ul><li>select * </li></ul><ul><li>from ( select ename, score, ... </li></ul><ul><li>order </li></ul><ul><li>by score desc </li></ul><ul><li>) </li></ul><ul><li>where rownum < 6 </li></ul>
    • 29. Using the number_range_score function
    • 30. Add the analysis of the score… <ul><li>We appreciate the top5 list of scores </li></ul><ul><li>However, we would like to see why each employee scores as it does </li></ul><ul><ul><li>How are the scores of 2.2 and 2 for Miller and Turner composed? </li></ul></ul><ul><ul><li>What if we change the relative weights of the search criteria? </li></ul></ul>
    • 31. Collecting Employee’s score per criteria <ul><li>For every employee record, we will have multiple scores – one for each search criterium </li></ul><ul><li>To collect multiple records per single record in one query, we can use the COLLECT aggregator </li></ul><ul><ul><li>Collecting OBJECT TYPES into a TABLE OF OBJECT TYPE </li></ul></ul>
    • 32. Collecting Employee’s score per criteria
    • 33. Slightly nicer layout
    • 34. Search results – top scoring employees
    • 35. Add a new search criteria <ul><li>We would prefer CLERKS but can live with ANALYSTS (60%) and SALESMEN (40%) </li></ul><ul><ul><li>This criteria weighs 1.5 compared </li></ul></ul><ul><li>Query to add: </li></ul>
    • 36. Fuzzy Search outcome with 3 criteria - Salary close to 1500 and within 1000-2000 - Hiredate 1982 (or less desirable) 1983 - Job is CLERK, or ANALYST or SALESMAN
    • 37. Some features used <ul><li>Scalar Subquery </li></ul><ul><ul><li>select x, (select from) from </li></ul></ul><ul><li>Collection of Object Type and Cast operator </li></ul><ul><li>Collect Aggregator </li></ul><ul><li>Left outer join </li></ul><ul><li>In-line subquery: </li></ul><ul><ul><li>select x, from (select x from order by) where … </li></ul></ul>
    • 38. RSS feeds are used to publish “events”
    • 39. RSS Aggregator Archive <ul><li>Access RSS Feed on the internet </li></ul><ul><li>Interpret and transform the XML data </li></ul><ul><li>Publish the RSS Feed as queryable view in the database </li></ul><ul><li>Combine multiple RSS Feeds </li></ul><ul><li>Archive the RSS Feeds in a central table – updating changed items, inserting new ones </li></ul><ul><li>Periodically scan RSS Feeds and update archive </li></ul><ul><li>Complete transaction even in the face of constraint violations </li></ul>
    • 40. The browser in your database Introducing UTL_HTTP ≈ select utl_http.request ( 'http://technology.amis.nl/blog/?feed=rss2' , null ) from dual
    • 41. Whatever the browser recives from a URL, the UTL_HTTP receives too
    • 42. Example UTL_HTTP code: processing response SET serveroutput ON SIZE 40000 DECLARE pieces utl_http.html_pieces; n number default 0; resp utl_http.resp; BEGIN pieces := utl_http.request_pieces ( url => 'www.someurl.com' , max_pieces => 9999 , proxy => null ); for i in 1..pieces.count loop loop exit when pieces(i) is null; dbms_output.put_line(substr(pieces(i),1,255)); pieces(i):= substr(pieces(i),256); END LOOP; end loop; END;
    • 43. Database can call out through UTL_HTTP <ul><li>Application Server </li></ul><ul><ul><li>Servlet </li></ul></ul><ul><ul><li>(intranet) WebService </li></ul></ul><ul><ul><li>BPEL Process </li></ul></ul><ul><ul><li>ESB Service </li></ul></ul><ul><ul><li>These services in turn can do many things, such as </li></ul></ul><ul><ul><ul><li>Send email, send chat-message, access database, call external WebService, read/write file system, access EJB or .NET based services, contact FTP server, deal with SAP </li></ul></ul></ul><ul><li>Internet (though that is not a decoupled thing to do) </li></ul><ul><ul><li>RSS feed </li></ul></ul><ul><ul><li>WebService </li></ul></ul><ul><ul><li>Web Site </li></ul></ul><ul><li>Note: HTTP Get requests can also be performed by: </li></ul><ul><li>dbms_xmlparser.parse(url) </li></ul><ul><li>HTTPURITYPE(url) </li></ul><ul><li>Oracle Text (index external docs) </li></ul><ul><li>utl_tcp, stored Java </li></ul>
    • 44. Publish RSS as “view” inside database create view AMIS_WEBLOG_FEED as select title , link , author , to_date(substr(publication_date,6,20) ,'dd mon yyyy hh24:mi:ss') timest from xmltable ( XMLNAMESPACES('http://purl.org/dc/elements/1.1/' AS &quot;dc&quot;) , 'for $i in //item return <Article>{$i/title}{$i/dc:creator} {$i/pubDate}{$i/link} </Article> ' passing httpuritype('http://technology.amis.nl/blog/?feed=rss2').getXML() COLUMNS title varchar2(100) path 'title' , link varchar2(100) path 'link' , author varchar2(100) path 'dc:creator' , publication_date varchar2(100) path 'pubDate' )
    • 45. Publish RSS as “view” inside database create view AMIS_WEBLOG_FEED as select title , link , author , to_date(substr(publication_date,6,20) ,'dd mon yyyy hh24:mi:ss') timest from xmltable ( XMLNAMESPACES('http://purl.org/dc/elements/1.1/' AS &quot;dc&quot;) , 'for $i in //item return <Article>{$i/title}{$i/dc:creator} {$i/pubDate}{$i/link} </Article> ' passing httpuritype('http://technology.amis.nl/blog/?feed=rss2').getXML() COLUMNS title varchar2(100) path 'title' , link varchar2(100) path 'link' , author varchar2(100) path 'dc:creator' , publication_date varchar2(100) path 'pubDate' )
    • 46. Aggregating Feeds into Central Archive <ul><li>Central table to archive all RSS News Items </li></ul><ul><ul><li>Keep items available after RSS feed ‘has moved on’ </li></ul></ul>RSS_ARCHIVE
    • 47. Aggregating Feeds into Central Archive <ul><li>New(s) items must be inserted, existing can be updated </li></ul><ul><ul><li>Source is join between RSS_FEEDS and XMLTable based on external RSS feed </li></ul></ul>
    • 48. Aggregating Feeds into Central Archive Run a job – scheduled, in the background <ul><li>Create Schedule – when to trigger execution </li></ul><ul><li>Create stored procedure SCAN_RSS_FEEDS that executes the MERGE statement and commits </li></ul><ul><li>Create Program – what action to take </li></ul>
    • 49. Aggregating Feeds into Central Archive Run a job – scheduled, in the background <ul><li>Create Job – link Schedule (when) and Program (what) </li></ul><ul><li>Sit back and relax (and perhaps check on job) </li></ul>
    • 50. Please, no more stories on … <ul><li>Create a check constraint on the RSS_ARCHIVE: </li></ul><ul><ul><li>No stories with Palin, Biden, Obama or McCain in the title! </li></ul></ul><ul><li>However, the background job issues a single MERGE statement to refresh the archive table </li></ul><ul><ul><li>That will fail as long as the collective feeds contain only one article that violates the CHECK CONSTRAINT </li></ul></ul><ul><ul><li>Surely that is not what you would want to happen? </li></ul></ul>
    • 51. Complete DML statement – log errors <ul><li>Oracle 10gR2 introduced ‘DML Error log’ </li></ul><ul><ul><li>Create an error log table </li></ul></ul><ul><ul><li>Indicate for a DML statement that exceptions should be logged to the table while the statement may continue and complete successfully </li></ul></ul>
    • 52. RSS Archive – Features Used <ul><li>UTL_HTTP, httpuritype </li></ul><ul><li>XMLDB: XMLTable, XQuery </li></ul><ul><li>DBMS_SCHEDULER </li></ul><ul><li>Regular Expression in Check Constraint (REGEXP_LIKE) </li></ul><ul><li>MERGE </li></ul><ul><li>DML ERROR LOG </li></ul>
    • 53. Expose recent HRM Data Changes <ul><li>Several parties are interested in all changes in the area of Human Resources (table EMP & DEPT) </li></ul><ul><ul><li>We have received a request to make an overview of all recent changes available, preferably in XML format </li></ul></ul>
    • 54. Our first thought – using triggers <ul><li>After Insert/Update/Delete trigger for each row </li></ul><ul><ul><li>Record change in table EMP_CHANGE_LOG </li></ul></ul><ul><ul><li>Part of the same transaction as the change(s) </li></ul></ul><ul><li>However: </li></ul><ul><ul><li>Adds overhead to the DML operation </li></ul></ul><ul><ul><li>Requires a trigger on every table for which changes must be exposed </li></ul></ul><ul><ul><ul><li>And if a trigger is disabled, changes are not logged </li></ul></ul></ul><ul><ul><li>Requires an additional (log) table for each table </li></ul></ul><ul><li>And it can be done much more elegantly…. </li></ul>
    • 55. Flashback Versions <ul><li>Retrieve all states each record has been in </li></ul><ul><ul><li>Every transaction that touched a row left a version of it </li></ul></ul><ul><ul><li>Pseudocolumns: xid, operation, starttime, endtime </li></ul></ul><ul><ul><li>Note: depends on the availability of UNDO or Flashback data; using 11g Flashback Archive is a way to ensure that on a per table basis </li></ul></ul>
    • 56. Example of Employee Versions
    • 57. Finding the biggest salary raise ever <ul><li>Analytical Function LEAD (looks to the next row) </li></ul><ul><ul><li>Get SALARY in the version that comes after the current row (when sorted by starttime descending) </li></ul></ul>
    • 58. Expose HRM Changes in XML document <ul><li>Create package HRM_CHANGE_HISTORY </li></ul><ul><ul><li>Containing procedure EMP_HISTORY that writes an XML document to htp.p with Employee change records </li></ul></ul><ul><li>Using DBMS_EPG </li></ul><ul><ul><li>Create DAD hrmhistory on path /hrm/* </li></ul></ul><ul><ul><li>Authorize DAD hrmhistory for schema SCOTT </li></ul></ul><ul><li>Access URL http://localhost:2100/hrm/scott. hrm_change_history.emp_history </li></ul>J(2)EE Application Server http://host/../emp_history
    • 59. Pull EMP change overview from browser
    • 60. Pull model: DBMS_EPG/Web Toolkit <ul><li>Pull model means create on request </li></ul><ul><ul><li>Always the most fresh data </li></ul></ul><ul><ul><li>Potentially large load on the database as for every request the XML document is recreated </li></ul></ul><ul><ul><li>Document is retrieved through a download by an HTTP client </li></ul></ul><ul><li>Alternative: push (publish) model </li></ul><ul><ul><li>Periodically create the XML document </li></ul></ul><ul><ul><li>Make it available to various clients </li></ul></ul><ul><ul><ul><li>On the file system, on the web </li></ul></ul></ul>J(2)EE Application Server XDB Folder <ul><li>WEBDAV </li></ul><ul><li>FTP </li></ul><ul><li>HTTP </li></ul><ul><li>PL/SQL </li></ul><ul><li>SQL </li></ul>
    • 61. Periodically publish XML Report <ul><li>Create XML DB Folder </li></ul><ul><ul><li>Is also a ‘directory page’ via HTTP </li></ul></ul><ul><ul><li>And a WEBDAV folder </li></ul></ul><ul><ul><li>And an FTP directory </li></ul></ul><ul><li>Schedule Job to Create Resource in the XDB Folder </li></ul><ul><ul><li>Based on XMLType: the result of a query that collects the desired data </li></ul></ul><ul><li>To access: </li></ul><ul><ul><li>Go to URL & open in browser </li></ul></ul><ul><ul><li>Map Network Drive via WEBDAV </li></ul></ul><ul><ul><li>Open FTP session </li></ul></ul>J(2)EE Application Server XDB Folder <ul><li>WEBDAV </li></ul><ul><li>FTP </li></ul><ul><li>HTTP </li></ul><ul><li>PL/SQL </li></ul><ul><li>SQL </li></ul>
    • 62. Create XML Resource DECLARE CURSOR xmlcur IS SELECT xmlelement(&quot;EMPHISTORY&quot;, ... l_xml_dir VARCHAR2(30) := '/public/hrmData'; l_doc_name VARCHAR2(30) := 'EmpChangeHistory.xml'; l_emp xmltype; l_res boolean BEGIN IF dbms_xdb.CreateFolder(l_xml_dir) THEN ... some ACL setting up END IF; open xmlcur; fetch xmlcur into l_emp; close xmlcur; l_res := dbms_xdb.createResource ( abspath=> l_xml_dir||l_doc_name , data=> l_emp ); COMMIT; end;
    • 63. HRM Report via WEBDAV, SQL & HTTP
    • 64. Viewing&Editing XDB Resource in Excel
    • 65. Uploading data from file to database
    • 66. Some features used <ul><li>Flashback Versions </li></ul><ul><li>Analytical Functions </li></ul><ul><li>SQL/XML and XMLType </li></ul><ul><li>Publish database service on the web: DBMS_EPG </li></ul><ul><li>XML DB </li></ul><ul><ul><li>Publish (FTP/WebDav/HTTP) Resource </li></ul></ul><ul><ul><li>Access XMLDB resource through SQL, PL/SQL, WebDAV (Excel, Windows Explorer) and HTML (Browser) </li></ul></ul>
    • 67. Summary <ul><li>Modern is determined by what you can do, can afford, have a need or demand for and consider best practice </li></ul><ul><li>Main trend: Service or Interface orientation </li></ul><ul><ul><li>Clear, reusable interface </li></ul></ul><ul><ul><li>Hide implementation details </li></ul></ul><ul><ul><li>Loose coupling, reduced dependency </li></ul></ul><ul><ul><li>Standardized contract, communication </li></ul></ul><ul><ul><li>Cater for various client technologies & protocols </li></ul></ul><ul><ul><ul><li>SQL/PLSQL, .NET, Java/JDBC, XML, HTTP, WebDAV, </li></ul></ul></ul><ul><ul><li>Inside database, benefit from external services through HTTP </li></ul></ul><ul><ul><li>Make database context aware (who, when, where) </li></ul></ul><ul><li>Continually appreciate the power and richness of SQL </li></ul>
    • 68. Want to know more? <ul><li>Find this presentation and all scripts </li></ul><ul><ul><li>Or read our articles at </li></ul></ul><ul><ul><li>Oracle Database, SQL & PL/SQL </li></ul></ul><ul><ul><li>ADF </li></ul></ul><ul><ul><li>APEX </li></ul></ul><ul><ul><li>SOA Suite: BPEL, EBS, BAM, … </li></ul></ul><ul><ul><li>and many other Oracle related topics… </li></ul></ul>
    • 69.  

    ×