Monday, April 21, 2014

ADF Business Components

When building service-oriented Java EE applications, you implement your core business logic as one or more business services. These backend services provide clients with a way to query, insert, update, and delete business data as required while enforcing appropriate business rules. ADF Business Components are prebuilt application objects that accelerate the job of delivering and maintaining high-performance, richly functional, database-centric services. They provide you with a ready-to-use implementation of Java EE design patterns and best practices.

Oracle ADF provides the following key components to simplify building database-centric business services:

Entity object
An entity object represents a row in a database table and simplifies modifying its data by handling all data manipulation language (DML) operations for you. It can encapsulate business logic to ensure that your business rules are consistently enforced. You associate an entity object with others to reflect relationships in the underlying database schema to create a layer of business domain objects to reuse in multiple applications.

View object
A view object represents a SQL query and simplifies working with its results. You use the SQL language to join, filter, sort, and aggregate data into the shape required by the end-user task being represented in the user interface. This includes the ability to link a view object with other view objects to create master-detail hierarchies of any complexity. When end users modify data in the user interface, your view objects collaborate with entity objects to consistently validate and save the changes.

Application module
An application module is the transactional component that UI clients use to work with application data. It defines an updateable data model along with top-level procedures and functions (called service methods) related to a logical unit of work related to an end-user task.

Oracle ADF Architecture

Fusion web technology stack achieve a clean separation of business logic, page navigation, and user interface by adhering to a model-view-controller architecture. As shown in figure in an MVC architecture.

■ The model layer represents the data values related to the current page
■ The view layer contains the UI pages used to view or modify that data
■ The controller layer processes user input and determines page navigation
■ The business service layer handles data access and encapsulates business logic



ADF VO Methods

clearCache

Clears the View Object cache. This method can be called for resource conservation. Calling this method also forces an automatic reexecution of the query for all RowSets, which refreshes the cache from the database.

reset

Resets the iterator. This method delegates to the default RowSetIterator. The iterator is positioned to the slot before the first row, the state of a newly-executed row set.

createRow

Creates a new view row. The new row is not placed in the entity cache until its primary key is initialized. It is inserted into the database when changes are posted to database and the transaction is committed.
Note that the constituent entities will be added to the entity-cache if the primary key of these entites are populated/set when the relevant entity's create() method is called. PrimaryKey attributes of Bc4J generated ID types (like RowID, DBSequence, etc) are defaulted before Entity.create and thus entities with such types as Primary Key attribute will be placed in the entity cache during create.

notifyRowInserted

This method is invoked by the framework when inserts are made to the given ViewRowSet for this ViewObject. This method can be overridden to perform calculations in a subclass or to cache a list of new rows for some other reason.

notifyRowDeleted

This method is invoked by the framework when a row is deleted from the given ViewRowSet for this ViewObject. This method can be overridden to perform calculations in a subclass or to cache a list of deleted rows for some other reason.

notifyRowUpdated

This method is invoked by the framework when updates are made to any attribute for rows in the given ViewRowSet for this ViewObject. This method can be overridden to perform calculations in a subclass if a particular attribute changes. Also, if the sub-class wants to block event-propogation to some/all rowsets of this viewobject, this method could be used to perform such filtering.

AccessMode

  • SCROLLABLE - if this RowSet should fetch rows and cache the ViewRows in a collection. This is the most flexible mode for accessing rows and working with a RowSet.
  • FORWARD_ONLY - if this RowSet should only provide sequential access to Rows in its collection. The iterators on this RowSet will not allow scrolling back.
  • RANGE_PAGING - if this RowSet should fetch rows in ranges (set using setRangeSize() - the default range size is -1 to fetch all rows), such that on scroll to the the next range or to fetch a row that's not in the current range, it's fetched back from the database using ROWNUM query and the row at the desired index is placed as the first row in the current range. New rows inserted in this mode will be inserted at the beginning of the rowset to maintain their row indices.
    If an attempt is made to get a row outside of the range when a new row is inserted or a row is removed in the current range, then an InvalidOperException is raised as the current set of changes needs to be posted to recalculate the right ROWNUM.
  • RANGE_PAGING_AUTO_POST - if this rowset should also post any changes in this transaction to access a row out of the current range.

writeXML

Renders data in a canonical XML-format. The classes ViewObjectImpl and ViewRowImpl implement this method to render data in XML.
Use this method whenever data is required in XML format, either to present a UI (after converting XML data into some HTTP format using a stylesheet) or to pass the data as payload for messages via JMS.

Source: http://docs.oracle.com/cd/B14099_19/web.1012/b14022/oracle/jbo/server/ViewObjectImpl.html#createRow__

ADF: VO getRowCount

Counts the total number of rows in this row set.
This method retrieves all rows from the View Object by executing the View Object's query and then calling next() until the last row is retrieved. Thus, since it iterates through the View Object one record at a time, this method may be slow.
If you are working with a large number of rows, or if your application demands a fast response, use getEstimatedRowCount to obtain a quicker count.

ADF: VO getFetchedRowCount

Counts the number of rows fetched from the JDBC result set.

This method delegates to the default RowSetIterator.

This method can be used to determine whether the View Object has read all the rows from the cursor. For example, getEstimatedRowCount returns an equivalent of count(*) on the View Object. The getFetchedRowCount() method returns the count of rows already fetched. If getFetchedRowCount() returns a value less than getEstimatedRowCount(), then the View Object has not read all rows from the cursor.

ADF: VO Method getEstimatedRowCount

This method estimates the number of rows in the row count by calling getQueryHitCount (which performs a SELECT COUNT (*) FROM table). Internal logic in Business Components for Java keeps the EstimatedRowCount up-to-date as rows are inserted and removed. Thus, after the first call to this method, it can return the estimated count quickly.
For example:
 // Get the rowcount again because of deleted or inserted row   
rowCount = (int) iter.getRowSet().getEstimatedRowCount();     
If you are working with a large number of rows, or if your application demands a fast response, use this method instead of getRowCount.
Note however, that this method might not be as accurate as getRowCount(). To test whether the View Object has read all the rows from the cursor, you can use getEstimatedRowCount() in conjunction with getFetchedRowCount(). For example, getEstimatedRowCount() returns an equivalent of count(*) on the View Object. The getFetchedRowCount method returns the count of rows already fetched. If getFetchedRowCount() returns a value less than getEstimatedRowCount(), then the View Object has not read all rows from the cursor.
Source: http://docs.oracle.com/cd/B14099_19/web.1012/b14022/oracle/jbo/server/ViewObjectImpl.html#getEstimatedRowCount__
Related Posts Plugin for WordPress, Blogger...