ADF_BC

download ADF_BC

of 45

Transcript of ADF_BC

  • 8/11/2019 ADF_BC

    1/45

    JDeveloper 10g and Oracle ADFBusiness ComponentsGetting the Most Out of Your Data

    Avrom Roy-FadermanSenior Programmer

    November, 2005

  • 8/11/2019 ADF_BC

    2/45

    Agenda

    J2EE, ADF, and JDeveloper

    Why Business Components?

    Reading Data Changing Data

    Transactions

    Demo Q&A

  • 8/11/2019 ADF_BC

    3/45

    What Is J2EE?

    Java platform for multi-tierapplications

    Open

    Scalable

    Traditionally difficult to use 3GL

    Much time spent on applicationplumbing

  • 8/11/2019 ADF_BC

    4/45

    Frameworks

    Library of classes Handle plumbing automatically

    XML files provide customization

    Can make Java more like a 4GL

  • 8/11/2019 ADF_BC

    5/45

    ADF and MVC

    Business Services

    View (Web and

    Wireless Clients)

    View and Controller

    (Desktop Clients)

    Model

    Controller (Web and

    Wireless Clients)

    Oracle ADF is a frameworkbased on MVC architecture

  • 8/11/2019 ADF_BC

    6/45

    ADF and MVC

    ADF Business Components

    ADF UIXADF Swing

    ADF Data Bindings

    Struts +

    ADF Extensions

    Oracle ADF is a frameworkbased on MVC architecture

  • 8/11/2019 ADF_BC

    7/45

    Agenda

    J2EE, ADF, and JDeveloper

    Why Business Components?

    Reading Data Changing Data

    Transactions

    Demo Q&A

  • 8/11/2019 ADF_BC

    8/45

    Impedence Mismatch

    SQL

    Tables, rows

    Primary keys

    Foreign keys

    TransactionsGB, TB

    Java

    Classes, instances

    Memory references

    Object members

    Shared heap100s of MB

  • 8/11/2019 ADF_BC

    9/45

    ADF BC Bridges the Gap

    SQL

    Tables, rows

    Primary keys

    Foreign keys

    TransactionsGB, TB

    Java

    Classes, instances

    Memory references

    Object members

    Shared heap100s of MB

  • 8/11/2019 ADF_BC

    10/45

    ADF BC Functionality

    Reading data

    Caching data

    Writing data

    Managing relationships

    Managing transactions

  • 8/11/2019 ADF_BC

    11/45

    What they Dont Do

    Create user interface (view)

    Organize the flow of theapplication (controller)

  • 8/11/2019 ADF_BC

    12/45

    Agenda

    J2EE, ADF, and JDeveloper

    Why Business Components?

    Reading Data Changing Data

    Transactions

    Demo Q&A

  • 8/11/2019 ADF_BC

    13/45

    Reading Data

    ADF View Objects

    ADF View Links

  • 8/11/2019 ADF_BC

    14/45

  • 8/11/2019 ADF_BC

    15/45

    ADF View Objects

    Each view object instance canexecute the SQL query andcache the results

    Database

    View objectinstance

    DataData

    DataDataData

    rows

    DataData

    DataDataView

    rows

    SQL query

    Data retrieval

  • 8/11/2019 ADF_BC

    16/45

    View Object Attributes

    Every query column maps toa view object attribute

    Those attributes are visibleto the application

    SELECT E.EMPLOYEE_ID,E.LAST_NAME,D.DEPARTMENT_ID,D.DEPARTMENT_NAME

    FROM EMPLOYEES E, DEPARTMENTS DWHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID

    EmployeeId

    LastName

    DepartmentId

    DepartmentName

  • 8/11/2019 ADF_BC

    17/45

    View Objects Dont Write!

    Classes to do DML are tooheavyweight if not needed

    Some query columns hard tomap backwards

  • 8/11/2019 ADF_BC

    18/45

    Reading Data

    ADF View Objects

    ADF View Links

  • 8/11/2019 ADF_BC

    19/45

    ADF View Links

    View link definitions relate

    a pair of view object

    definitions

    View link definitions specify

    master/detail relationships

    between the SQL queries

  • 8/11/2019 ADF_BC

    20/45

    ADF View Links

    View link definitions have

    Source and Destination

    attributes

    These attributes specify the

    master-detail relationship

    Just like foreign key and primary key attributesspecify a foreign key relationship

  • 8/11/2019 ADF_BC

    21/45

    ADF View Links

    A view link definition works like anadditional WHERE clause applied tothe detail

    SELECT E.EMPLOYEE_ID,

    E.LAST_NAMEFROM EMPLOYEES E

    EmployeesView(Master)

    SELECT D.DEPARTMENT_ID,D.DEPARTMENT_NAME,D.MANAGER_ID

    FROM DEPARTMENTS D

    DepartmentsView(Detail)

    WHERE D.MANAGER_ID =:1

    Source attribute

    Destination attribute

  • 8/11/2019 ADF_BC

    22/45

    Agenda

    J2EE, ADF, and JDeveloper

    Why Business Components?

    Reading Data Changing Data

    Transactions

    Demo Q&A

  • 8/11/2019 ADF_BC

    23/45

    Changing Data

    ADF Entity Objects

    View and Entity Attributes

  • 8/11/2019 ADF_BC

    24/45

    ADF Entity Objects

    Entity object definitionscorrespond to databasetables.

    Entity object definitions aretemplates for entity objectinstances, which

    correspond to table rows.

  • 8/11/2019 ADF_BC

    25/45

    View Objects and Entity Objects

    Instead of caching datathemselves, view objectinstances can store data in

    entity object instances

    Database

    View objectinstance

    DataDataDataDatarows

    DataDataDataViewrows

    SQL query

    DataDataDataEntity objectinstances

    Data retrieval

  • 8/11/2019 ADF_BC

    26/45

    View Objects and Entity Objects

    The entity object instances canwrite back to the database

    Entity object definitions can

    specify validation rules

    Database

    View objectinstance

    DataDataDataDatarows

    DataDataDataViewrows

    DataDataDataEntity objectinstances

    DML

  • 8/11/2019 ADF_BC

    27/45

    Entity Object Attributes

    Every table column maps toan entity object attribute

    EmployeeIdFirstName

    LastName

    Salary

    EMPLOYEE_ID FIRST_NAME LAST_NAME SALARY ...

  • 8/11/2019 ADF_BC

    28/45

    Changing Data

    ADF Entity Objects

    View and Entity Attributes

  • 8/11/2019 ADF_BC

    29/45

    View and Entity Attributes

    Every view object attributecan map to an entityattribute

    EmployeeId

    FirstName

    LastName

    DepartmentId

    EmployeeIdLastName

    DepartmentId

    DepartmentName

  • 8/11/2019 ADF_BC

    30/45

    One View, Many Entities

    One view object definitioncan map to multiple entityobject definitions

    EmployeeId

    FirstName

    LastName

    DepartmentId

    EmployeeId

    LastName

    DepartmentId

    DepartmentName

    DepartmentId

    DepartmentName

    ManagerId

    LocationId

    Employees

    DepartmentsEmpDeptView

  • 8/11/2019 ADF_BC

    31/45

    One View, Many Entities

    Then each view row willmap to multiple entityobject instances

    DataDataDataDataViewrows

    DataDataDataDataEntity objectinstances

    DataDataDataDataEntity objectinstances

    Employees

    Departments

  • 8/11/2019 ADF_BC

    32/45

    One Entity, Many Views

    Multiple view objectdefinitions can map to asingle entity object

    definition

    EmployeeId

    LastName

    DepartmentIdDepartmentName

    DepartmentId

    DepartmentName

    ManagerId

    LocationId

    EmpDeptView

    DepartmentId

    DepartmentName

    LocationId

    LocationName

    DeptLocView

  • 8/11/2019 ADF_BC

    33/45

    One Entity, Many Views

    Then different view objectinstances can share data

    DataDataData

    DataViewrows

    DataData

    DataDataEntity object

    instances

    EmpDeptViewinstance

    DataDataData

    DataViewrows

    DeptLocViewinstance

  • 8/11/2019 ADF_BC

    34/45

    SQL-Only View Attributes

    View attributes dont needto map to entity attributesat all

    Then they must be read-only

    E.g.: Caclulated querycolumns

  • 8/11/2019 ADF_BC

    35/45

    Read-Only View Objects

    Have only SQL-Onlyattributes

    Do not use entity objects atall

    Read-only access to data

    But

  • 8/11/2019 ADF_BC

    36/45

    Agenda

    J2EE, ADF, and JDeveloper

    Why Business Components?

    Reading Data Changing Data

    Transactions

    Demo Q&A

  • 8/11/2019 ADF_BC

    37/45

    Application Modules

    Application modules package up

    the data and present it to the

    rest of the application

    The application always talks to

    the business components

    through the application module

  • 8/11/2019 ADF_BC

    38/45

    Application Module Instances

    Each instance (user) of the

    application will get its own application

    module instance

    The application module instance

    contains view object instances

    View object instances use entity

    object instances to write

  • 8/11/2019 ADF_BC

    39/45

    The Data Model

    The view object instances inan application moduleinstance are joined in

    master-detail relationshipsby view link instances

    The resulting tree is called

    the data model

  • 8/11/2019 ADF_BC

    40/45

  • 8/11/2019 ADF_BC

    41/45

    A More Complex Data Model

    MasterInstance of

    EmployeesView

    DetailInstance of

    DepartmentsView

    DetailInstance of

    EmployeesView

    IndependentInstance of

    DepartmentsView

  • 8/11/2019 ADF_BC

    42/45

    Application Module Definitions

    Templates for application

    module instances

    Specify which view object

    and view link instances

    should go in the data model

  • 8/11/2019 ADF_BC

    43/45

    Data Consistency

    Each application moduleinstance has its own set of viewand entity caches

    Two locking mode choices Pessimistic locks (the default) acquired on DB

    rows as soon as data is changed in the cache

    Optimistic locks acquired just before executing

    DML

  • 8/11/2019 ADF_BC

    44/45

    Demo

  • 8/11/2019 ADF_BC

    45/45

    Q & A