Anda di halaman 1dari 34

Querying and Persisting Data

Copyright 2008, Oracle. All rights reserved.


Objectives

After completing this lesson, you should be able to do the


following:
Describe the characteristics of an ADF BC view object
Create ADF BC view objects that can be used for data
queries in a Web application
Modify SQL statements in view objects
Explain how entity objects relate to database tables
Describe the persistence mechanism of entity objects
Create entity objects from database tables
Create associations between entity objects
Create updatable view objects based on entity objects
Link view objects to one another
Refactor business components

5-2 Copyright 2008, Oracle. All rights reserved.


Using View Objects
Updatable
View Object
CustomerStatus

ID
Name
Status

CustomerStatusRO

5-3 Copyright 2008, Oracle. All rights reserved.


Characteristics of a View Object (VO)

View objects:
Represent a query
Are used for joining, filtering, projecting, and sorting
business data
Enable you to have a view of data that is specific to one
part of your application
Can be constructed from a SQL statement, static values,
or populated programmatically
Can also be based on any number of entity objects

View Reusable
Query Components
objects
PriorityOrderVO ItemListVO

5-4 Copyright 2008, Oracle. All rights reserved.


Creating View Objects for Queries

1 Invoke the Create View Object


Wizard. Initialize project for
2
Business Components.

5-5 Copyright 2008, Oracle. All rights reserved.


Creating View Objects for Queries

3 Specify package, name, and kind of data.

5-6 Copyright 2008, Oracle. All rights reserved.


Creating View Objects for Queries

Enter the SQL query,


4
or use Query Builder.

5-7 Copyright 2008, Oracle. All rights reserved.


Creating View Objects for Queries

Create bind variables


5
and set attribute
properties as needed.

5-8 Copyright 2008, Oracle. All rights reserved.


Creating View Objects for Queries

Optionally, create Java


6
classes (if adding
programmatic business
logic).

Optionally, create a new


7
application module or
add to an existing one.

5-9 Copyright 2008, Oracle. All rights reserved.


Testing View Objects with the Business
Components Browser

1 Run the application module.

Provide
2 connection
details.

Double-click the
3 view object
instance.

5 - 10 Copyright 2008, Oracle. All rights reserved.


Characteristics of an Entity Object (EO)

Entity objects:
Represent a row in a database table or other data source
Handle database caching
Contain attributes representing the database columns
Encapsulate attribute-level and entity-level validation logic
Can contain custom business methods

CustomerEO OrderEO

5 - 11 Copyright 2008, Oracle. All rights reserved.


Using Entity Objects to Persist Data

Entity
object CustomerEO

Id
Name
Attributes
Status Status List Validation
Email (Gold Silver Platinum) rule

CUSTOMERS
Database
ID NAME STATUS Email
table
201 Steve Gold msmith@company.com
202 Mike Silver dgonzales@company.com

5 - 12 Copyright 2008, Oracle. All rights reserved.


Creating Entity Objects

The Create Entity Object Wizard:


Attributes page

Name page

Attribute Settings page

5 - 13 Copyright 2008, Oracle. All rights reserved.


Creating Entity Objects
from Tables, Views, or Synonyms

When you create an entity object, JDeveloper:


Interrogates the data dictionary for information
Infers primary key, or creates one from RowID
Creates implicit validators for database constraints
Creates the XML component definition file
(<EO_name>.xml)
Creates optional Java files if selected, such as entity object
class <EO_name>Impl.java
Generates associations based on foreign keys, if
applicable (<Association_name>FkAS.xml)

5 - 15 Copyright 2008, Oracle. All rights reserved.


Synchronizing an Entity Object
with Changes to Its Database Table

ALTER TABLE USERS


ADD (security_question VARCHAR2(60));

5 - 16 Copyright 2008, Oracle. All rights reserved.


Generating Database Tables from Entity Objects

Right-click package and In Create Database Objects


select Create Database dialog box, select objects to
Objects. create.

Use with caution!

5 - 17 Copyright 2008, Oracle. All rights reserved.


Characteristics of Associations

Define a relationship between EOs


Facilitate access to data
in related entity objects
May be based on database
constraints
May be independent of database
constraints
Are used in defining
validations and LOV metadata
Consist of a source (master)
and a destination (detail) entity

PersonEO OrdersPersonsFkAS OrderEO

Source Association Destination

5 - 18 Copyright 2008, Oracle. All rights reserved.


Creating Associations

Use the Create Association Wizard:


Association Properties page
Name page

Entity Object page

Association Query page

5 - 19 Copyright 2008, Oracle. All rights reserved.


Association Types
Association
Entities are related but not
completely dependent.
Either end of the association can
exist without the other.
Either can be deleted without Customer Order
deleting the other.
Composition
Destination entity is completely
dependent on source entity.
Source entity owns destination Order Order Item
entity.
No destination entity can be
created without the owning entity
existing first.
Source entity cannot be deleted
without deleting all its associated
destination entities.
5 - 20 Copyright 2008, Oracle. All rights reserved.
Characteristics of
Updatable View Objects
Entity Object View Object
CustomerEO CustomerStatusVO

ID select name, status


Name from customers
Status order by name
Name Status
Email
Mike Silver
Steve Gold

ID NAME STATUS EMAIL


201 Steve Gold Steve@abc.com Database
202 Mike Silver Mike@abc.com
Table

5 - 21 Copyright 2008, Oracle. All rights reserved.


Creating Updatable View Objects

Use the Create View Object Wizard:

Name page

Entity Objects page

5 - 22 Copyright 2008, Oracle. All rights reserved.


Creating Updatable View Objects:
Attributes and Settings

Attributes page

Attribute Settings page

5 - 23 Copyright 2008, Oracle. All rights reserved.


Creating Updatable View Objects:
Query

5 - 25 Copyright 2008, Oracle. All rights reserved.


Creating Updatable View Objects:
Additional Settings

5 - 27 Copyright 2008, Oracle. All rights reserved.


Interaction Between Views and
Entities: Retrieving Data

The view object queries the database directly.


Data retrieved by the query is saved to the entity objects
cache. EO VO

Select

Nonpersistent attributes are stored and retrieved from the


view objects cache. VO

Select
(12*monthly_sal)

5 - 28 Copyright 2008, Oracle. All rights reserved.


Interaction Between Views and
Entities: Updating Data

The view object updates the entity objects cache.


The entity object commits to the database.

EO VO
Commit Update

5 - 29 Copyright 2008, Oracle. All rights reserved.


Creating a Join View Object

Join is based on
association
between
entities.

5 - 30 Copyright 2008, Oracle. All rights reserved.


Including Reference Entities
in Join View Objects

1 2

5 - 31 Copyright 2008, Oracle. All rights reserved.


Creating MasterDetail Relationships
with View Objects

Different types of masterdetail relationships are


supported.

Master to Single Master to Multiple Cascading Master


Detail Details Detail to Any Depth

5 - 32 Copyright 2008, Oracle. All rights reserved.


Linking View Objects

Use the Create View Link


Wizard to create a view link
between CustomerVO and
OrderVO view objects.

Joined queries and view links


display information differently.

5 - 33 Copyright 2008, Oracle. All rights reserved.


Comparing Join View Queries with View Links

Join view queries:


Contain all attributes from main and referenced entities in
a single row
WHERE clause relates key from main table with foreign key
in referenced tables
View link queries:
Use a bind variable to relate detail records to key for
selected master record
Append WHERE clause with bind variable to the base SQL
query for the source or destination view object

5 - 34 Copyright 2008, Oracle. All rights reserved.


Refactoring Objects

With refactoring you can:


Rename objects, such as
associations and view links
Move objects or packages
to a different package
Change all references
throughout the application

5 - 35 Copyright 2008, Oracle. All rights reserved.


Summary

In this lesson, you should have learned how to:


Describe the characteristics of an ADF BC view object
Create ADF BC view objects that can be used for data
queries in a Web application
Modify SQL statements in view objects
Explain how entity objects relate to database tables
Describe the persistence mechanism of entity objects
Create entity objects from database tables
Create associations between entity objects
Create updatable view objects based on entity objects
Link view objects to one another
Refactor to move and rename associations and links

5 - 36 Copyright 2008, Oracle. All rights reserved.


Practice 5 Overview:
Creating Entity Objects and View Objects

This practice covers the following topics:


Creating read-only view objects to support LOVs
Creating entity objects for tables that need to be updated
in the application
Creating associations
Creating updatable view objects
Creating view links
Refactoring associations and links

5 - 37 Copyright 2008, Oracle. All rights reserved.

Anda mungkin juga menyukai