• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Odtug2011 adf developers make the database work for you
 

Odtug2011 adf developers make the database work for you

on

  • 1,837 views

 

Statistics

Views

Total Views
1,837
Views on SlideShare
1,837
Embed Views
0

Actions

Likes
2
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Process
  • http://technology.amis.nl/blog/4162/dynamic-and-conditional-grouping-in-sql-queries-for-flexible-results-from-single-query-oh-and-a-useful-case-for-the-cube-operator
  • http://technology.amis.nl/blog/4191/adf-11g-treetable-with-sub-totals-how-the-sql-query-can-make-life-easier-for-the-view-developer
  • select ename, sal, deptno, job, rank() over (partition by deptno order by saldesc) sal_rank_in_dept, rank() over (partition by job order by saldesc) sal_rank_in_job, lag(sal,1) over (partition by deptno order by saldesc) diff_with_next_higher_in_dept, listagg(ename, ',') within group (order by ename) over (partition by deptno) colleaguesfrom emporderby deptno, saldesc
  • http://technology.amis.nl/blog/3255/integrating-flashback-in-adf-web-applications-providing-the-historic-perspectivehttp://technology.amis.nl/documents/technology/dvt.pdf
  • Cache – spreekuit: kasjeKastjesBrowser: Client (browser, cookie or Java Script memory; HTML 5 offers persistent, cross session local db like storage)App Server : Edge (WebServer)JVM (and cluster)Cross cluster shared cachedb or memory gridDatabase (not requery at least)
  • 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”)

Odtug2011 adf developers make the database work for you Odtug2011 adf developers make the database work for you Presentation Transcript

  • ADF Developers – make the database work for you
    ODTUG Kaleidoscope 2011 – Long Beach, California
    Luc Bors, AMIS, The Netherlands
  • Desktop
    Browser-Based
    Metadata Services (MDS)
    Oracle ADF – Role of the Database
    JSF
    JSP
    Office
    ADFSwing
    Mobile
    View
    ADF Faces
    JSF
    Struts
    ADF Controller
    Controller
    ADF Binding
    Model
    Business Services
    EJB
    BAM
    ADFbc
    Portlets
    BI
    BPEL
    Web Services
    Java
    Data Services
    Database
    Web Services
    Legacy Systems
    Apps Unlimited
  • “We could also do that in the database”
    in the database? Huh?
    RDBMS

  • Design & team that combines strengths of all technologies…
    • Ease and Elegance of Implementation
    • Functionality (in an affordable way)
    • Productivity
    • Performance
    ADF Controller/
    ADF Faces
    ADF Model
    ADF BC/JPA/WS*
    Oracle RDBMS
  • Database Strengths
    Integrity
    Fine grained (data) security and auditing
    Data Retrieval
    joining tables together, leveraging indexes
    hierarchical, network-like traversals
    advanced analytics, historical queries, mining
    Aggregation and Sorting
    Complex & Massive Data Manipulation
  • RDBMS not always exclusively accessed through one Java API
    SOA, ESB, WebServices
    Database
    Batch Bulk Processes
    Standard Applications
    LegacyApplications
    Data Replication & Synchronization
  • Database Triggers – decorating Data Manipulation
    Triggers execute before or after Insert, Update or Delete of database records
    insert, update, delete
    Before Insert trigger: sal=…
    Employees
  • Purpose of triggers
    Set default values on new records
    if :new.job=‘SALESMAN’ then :new.comm = 1000
    Calculate & Derive values upon insert, update or delete
    Notify third parties of data manipulation
    Perform complex validation on the data changes applied by the transaction
    Per Department: Max Salary < 1.8 * Average
    Per Manager: #subordinates < 15
  • ADF BC refreshing Entity Objects after triggers have applied new values
    Entity Object Employee
    (leveraging: returning <column> into : bind)
    post
    Before Insert trigger: sal=…
    Employees
  • Aggregation & Rollup
    Data for reporting purposes can be prepared by database queries
    Including aggregations(max/min/avg/count/sum)
    and Sub Totals
    and Grand Total
    and String Aggregation
  • Dynamic Aggregation through Non-conventional use of bind parameters
    Bind parameters are typically used in the WHERE clause of a SQL query
    However: they can also be used in the SELECT, ORDER BY and GROUP BY sections
    A combination of CASE and bind parameters in the GROUP BY can provide interesting options
    DynamicAggregation
  • Query for dynamic aggregation
  • Sub and Grandtotals with Rollup
    Rollup instructs databaseto aggregate at every levelstarting from the right
    deptno, job
    deptno
    (grand total)
    Also see:
    Cube
    GroupingSets
  • Leveraging SQL Aggregation to make life easier for the UI developer
  • Analytical Functions – spreadsheet-style row processing
    Analytical Functions allow SQL queries to perform inter-row comparison & aggregation
    For example: in a single query, for each employee
    show salary rank in department and job
    show salary difference with colleague next higher in rank (on the list per department)
    show average salary in the department
    show csv list of colleagues in department
  • Analytical Functions - example
  • Flashback Query
    select emp.*, dept.dname
    from emp AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '1' DAY)
    , deptwhere emp.deptno = dept.deptno
  • Show historic situation for selected records
  • Flashback Versions
    Retrieve all states each record has been in
    Every transaction that touched a row left a version of the record
    Pseudocolumns: xid, operation, start time, end time
    Use constants minvalueand maxvalueto retrieve all versions
    Flashback versions make journaling tables redundant
  • Employee Version-history with Flashback Query
  • Show change history for a record based on Flashback versions
  • Embedding Historic Data in ADF Application
    Where Clause in (read only) ViewObject can include FLASHBACK operators
    AS OF and VERSIONS BETWEEN
    Bind parameters can be used to set the point in time or the historic time interval
    A time selector can be used to visually set the interval
    Scalar subqueries can be used for ‘in line comparison to a certain point in time’
    “How much higher/lower is the salary than at the selected date?”
  • Trees
  • Trees
  • ADF Model & Tree Data Binding
    Create hierarchical relation between multiple ViewObject or (POJO) Collection Bindings
    Tree Data Retrieval retrieves collections in several steps i.e. multiple queries
    Data is cached
    Data is only queried when required (given the expansion level of the tree)
    Alternatively: have the database do the heavy tree lifting: Database has optimized tree algorithms
    Starting at any node in the tree or network
    Drilling down to the specified number of levels
    Order siblings within parent
    Indicate leaf and parent nodes; detect cycles
  • Retrieving Hierarchical data sets with single SQL statements
    Database has optimized algorithms
    Starting at any node in the tree or network
    Drilling down to the specified number of levels
    Order siblings within parent
    Indicate leaf and parent nodes; detect cycles
    EMPID ENAME MGR DEPTNO LEVEL
    --------------- ---------- ---------- ---------- ----------
    7839 KING 10 1
    7698 BLAKE 7839 30 2
    7499 ALLEN 7698 30 3
    7900 JAMES 7698 30 3
    7654 MARTIN 7698 30 3
    7844 TURNER 7698 30 3
    7521 WARD 7698 30 3
    7782 CLARK 7839 10 2
    7934 MILLER 7782 10 3
  • Oracle 11g and ANSI SQL for hierarchical query
    with employees (empno, name, mgr, hierlevel, path) as
    ( select empno, ename, mgr, 1, ename
    from emp
    where mgr is null
    union all
    select e.empno, e.ename
    , e.mgr, m.hierlevel + 1
    , m.path||'/'||e.ename
    from emp e
    join
    employees m
    on (m.empno = e.mgr)
    )
    select *
    from employees
  • Filter-driven querying
    FilteredEmp
  • Steps for filter driven querying
    Determine the values to filter on
    Create a query to retrieve for all filters
    Every individual value and the # occurrences
    The where-clause to apply on the real VO
    The label for the filter
    Create a managed bean to apply selected filtersto ViewObject
    Create page that displays filters and selected dataand handles filter “clicks”
  • Encapsulate Database specific SQL in a View API
    Views – for encapsulation of data model, multi-table join, (advanced) SQL hiding, authorization rules
    Note: a view looks like a table to the client
    View
  • The read-only cursor API
    A Cursor is a reference to a query result set
    Database can open a cursor for a SQL query
    And return it to the application to fetch the rows from
    Cursor == JDBCResultSet
    A cursor can be nested: containdetails …
    JDBC ResultSet
    while rs.next { … }
    cursor
    Stored Procedure
    Departments
    SQL
    Employees
  • Cursor for Master-Detail resultset
    Stored Procedure
  • Using Complex Views for Hiding Legacy Data Models
  • Providing a ‘business object’ API
    DML API: a View – aided by an Instead Of trigger
    Insert of one new row inUSERS_VW (e.g. a JPApersist operation) can actually be four new records
    USER, PERSON, EMAIL_TYPEEMAIL_ADDRESS
    USERS
    USERS
    EMAIL_TYPE
    Instead Of DML trigger
    *
    *
    PERSONS
    EMAIL_ADDRESSES
    *
    *
  • Instead of Insert Trigger on USERS_VW (1/2)
    create or replace trigger handle_insert_users_trg
    instead of insert on users_vw
    for each row
    declare
    l_psn_id persons.id%type;
    begin
    insert into persons
    ( id, first_name, last_name, address, ...)
    values
    ( nvl(:new.id, central_seq.nextval),:new.first_name , :new.last_name, :new.address, ...)
    returning id into l_psn_id;
    insert into user_accounts
    ( id, psn_id, username, password)
    values
    ( central_seq.nextval ,l_psn_id , :new.username , :new.password);
  • Instead of Insert Trigger on USERS_VW (2/2)
    ...
    insert into email_addresses
    ( id, psn_id, ete_id, address)
    values
    ( central_seq.nextval , l_psn_id
    , ( select id
    from email_types ete
    where ete.address_type = :new.primary_email_type ) , :new.primary_email)
    ;
    end handle_insert_users_trg;
  • Creating a new user
    User Administration
    USERS
    First Name
    Last Name
    Molly
    Warhol
    Username
    Password
    mwarhol
    ******
    USERS
    EMAIL_TYPE
    Instead Of DML trigger
    Address
    City
    1 Slickroad
    Las Vegas
    Telephone
    Mobile
    5551212
    43219876
    *
    Email
    Email type
    mw@un.org
    Business
    PERSONS
    EMAIL_ADDRESSES
    Activation
    24-may-2008
    *
    *
  • ADF BC and Complex Views with Instead of Triggers
    Override the lock method in the ViewObjectImpl
    Default implementation will attempt select … from <view> for update ofWhich is not allowed on Views with an instead of trigger
  • Do not do it…More often than required
    Save on network trips, context switches and tiers to cross
    Save on ‘reproducing’ same results
    Web Browser
    • JS data (memory)
    • Cookies
    • HTML 5 db
    Edge Cache
    JEE Application Server
    Cache
    Cluster Fail-Over
    (Session State)
    Result Store
    Write Behind
    Client Result Cache
    RDBMS
    Result Cache
    Materialized View
  • The Hollywood Principle: Query ResultSet Change Notification
    POJO / ADF BC
  • Cache Refresh triggered by DB
    Oracle RDBMS invokes Java Listener with event details
    POJO / ADF BC
    Register DatabaseChangeNotification
    SQL query
    PL/SQL
  • Shared Application Modules
    Normal Application Module instances are session level – i.e. not shared across (web) sessions
    Shared Application Module instances are shared across sessions like an Application Scope Managed Bean
    Used for Static Data Sets: Look Up Data and Reference Tables
    Sessions can reuse the data from a shared Application Module without having to access the database
    And loading the same data in session level memory scope
    View Accessors can be used to access data in the Shared Application Module’s VOs
    For example for use in LOVs or Validation Rules
  • Shared Application Module Instance
  • Auto Refresh for ViewObjects
    ViewObjects in a Shared Application Module can be registered for auto refresh
    Typically such application wide VOs are near-static
    Whenever the underlying data set changes (in the database), the VO rowset should be refreshed
    By setting Auto Refresh (to true) for the ViewObject, the VO will be refreshed whenever the database is changed
    ADF registers the VO query with the Database (11g) Result Set Change Notification mechanism through JDBC
    Note: the VO should not have an Order By clause nor select a Date column
  • Steps for auto refresh enabling
    Create Shared Application Module
    New application module that is added to list of Application Level instances in the Project properties
    Create the ViewObject that queries the ‘static data’ and add to Shared Application Module
    Set the Auto Refresh property to true for VO instance
    Database must be 11g (and have parameter compatible set to 11.1.0 or above)
    database user must have the Change Notification privilege
    To piggyback changes to page, set changeEventPolicy to autoPPR on data binding
  • Set Auto Refresh for ViewObject
    Set Auto Refresh for ViewObject
    Grant Change Notification todatabase user
  • Demo
    DBQRCN
  • Reaching out from the database
    Database
  • Email conversations
  • Database receiving and sending emails – from people or applications
  • RESTful resource navigation
  • RESTful architecture
    http
    http
    http
    RESTful PL/SQL APIexposed through dbms_epg
  • JEE Application Server
    Enterprise Service Bus
    ADF Application
    Web Service
    ?
    Database informing and leveraging the middle tier
    HTTP calls using the UTL_HTTP package
  • Asynchronous processing
    Execute stored procedures or command scripts (O/S) in the background – using a job
    Free up the synchronous thread
    Return control to invoking Java application
    Ideal for Fire-and-Forget (one way) calls
    Results can be returned asynchronously
    Via Queue, Table, Database Query Result Change Notification, HTTP call, Email,…
    Create a Job in the Oracle Database using:
    package dbms_scheduler
  • Other Database Features worth investigating
    Virtual Private Database & Fine Grained Authorization
    XMLType, XMLDB & FTP/HTTP/WEBDAV server
    Object Types and Collections
    Data type Interval & Time Zone support
    Fine Grained Auditing
    System Triggers, for example “after logon”
    (Global) Application Context
    Autonomous Transaction
    Advanced Queuing (& JMS interaction)
    Creating advanced job execution schedules
    Edition Based Redefinition (versioning of database objects)
    Statistics and Data Mining
    Scalar Subqueries
  • Summary & Conclusions
    Databases can do much more than
    ADF applications can benefit!
    Strike the right balance:
    Leverage database forwhat it can do best
    Make ADF and Database work together in a smooth way