Wednesday, August 19, 2009

Oracle ADF, dust under the carpet

Jdeveloper version usedin this post is:=10.1.3
When you create a component in ADF , whether its Entity object or a view object in the model layer, or drag and drop view object on the jsf page, there are many xml files and other files which are created by Jdeveloper. And developers gets crazy as, why so many files are created and what are they for. Specially beginners/ADF newbies gets confused with so many xml files which getting created, and that gives them one reason to run way from learning ADF. In this post I will try to explain these xml and other files which you should know as a developer when you do development using ADF.

When you create an application in Jdeveloper with “JSF , ADF BC” as template, two project gets created “Model” and “ViewController”. And a file
1) .jws which is used for storing the projects added in the workspace(check your workspace on disk).

Under the Model and ViewController projects two files gets created as “Model.jpr” and “ViewController.jpr”.
2) .jpr file is used to store the project related information like java files created in the project etc.

Once you start creating the Entity or View object under the Model, one more file gets created under the Model/src/Model.jpx.
3) Model.jpx file contains all the application modules defined in your Model project. And other configuration details such as database connection used in model layer. Some times during development, if you get “JBO 30003” or database error, then check the “_NamedConnection” parameter in the same file, if it is pointing to the correct database connection name.
Entity object is the Java object representation of the database table row from which it is created. Once your create an Entity object(say EmpEO), two files which gets created.
4)EntityName.xml (for EmpEO, it is EmpEO.xml):- This file contains the name of the database table from which the entity object is created, name and data type of each attribute in eneity object, and the corresponding column to which that attribute represents. For example in the following figure, attribute “EmployeeId” is driven from the column name “Employee_ID”, with type as number and other attributes such as primary key etc:-

5) EntityNameImpl.java(for EmpEO, it is EmpEoImpl.java):- though it is not required to generate this file, as default option it is created. It has getter and setter methods for the entity object attributes. This file can be used to add custom code, such as in the setter method of commission of the employee, commission can be first calculated based on the employee salary, hire date or other conditions.

View object fetch the result set from the database based on the query on which it is based. Once you create view object whether entity based or read only,two files are created:-
6) ViewObjectName.xml(for EmpVO, it is EmpVO.xml):-which specifies the entity object on which this view object is dependent, query of the view object which will fetch the desired resultset and the attributes which are there in view object.View object is created at run time based on this .xml file.
7)ViewObjectNameImpl.java(For EmpVO, it is EmpVOImpl.java):- When ever you create a new row in the view object, and you want to provide some custom behavior when a new row is created, you can overwrite create() method in same class. Similarly remove() and other methods.

An Application module which acts a container for view objects and take care of transaction handling. When you create an application module, two files are create:-
8) ApplicationModuleName .xml(for EmpAM, its EmpAM.xml):- It has name of the application module, the application module class path, and all view objects which are added in the application module. This information is used to create the view objects at runtime.
9)ApplicationModuleName Impl.java(For EmpAM, its EmpAMImpl.java):- In this java class you will write methods like:-
→ iterating two or more view objects result set added in same application module to perform some business logic.
→ calling a pl/sql code.
→ writing a method and later on exposing it by adding it in client interface, so that it can be called from view layer.
10) Bc4j.xcfg:- it has different configuration properties of the application module, as such , the name of the database connection, type of DB connection etc.

Once you create your jspx page with drag and drop any view object from data control palette, page definition file and DataBindings.cpx file gets created.
11) DataBindings.cpx:- This file is created for the first time and only once when you drag and drop any view object or method from data control palette to the jspx page. This page contains information about page definition file corresponding to your jspx page, the data controls used by your application. Ya ya, I know you are now thinking of what is data control and data bindings. Thats actually what I am thinking of my next blog post topic :). Check the following figure, it shows the contents of the DataBindings.cpx file, when I drag and dropped the EmpVO from the data control palette to ViewEmpDetails.jspx page as ADF read only table. It shows how ViewEmpDetails.jspx file is linked to its page definition file ViewEmpDetailsPageDef.xml:-


Created DataBindings.cpx file is created under the view controller project → Application Sources → view .
12) PageDef.xml(for ViewEmpDetails.jspx, its ViewEmpDetailsPageDef.xml):- Page definition file created for each jspx page,when you drop a particular component from data control palette to your jspx page. This is the file which actually wries your UI components to the corresponding attributes in the view object. This file mainly contains following elements(tags):-
12.1 ) executables:- which defines various result sets(specified as iterator tag) to be executed when the page is loaded. Or defines the methods exposed from application module in client tier(specified as methodIterator tag) to be executed.
12.2) bindings:- it specifies the attributes which will be contained in the result set pointed by the iterator tag. Or the details of method to be executed pointed by the methodIterator tag.
Check the following figure, in which iterator EmpVO1Iterator specifies the employee details to be fetched when page is loaded. And under bindings it specifies all attributes which will be available in the result set to be shown in UI.
If you check the source of the ViewEmpDetails.jspx page, it will be clear to you that how it is wired to the elements present in the page definition.

And at last two files which are created by Jdeveloper itself under web-inf folder in ViewController project once you have create an application with “JSF , ADF BC” as template are:-
13)faces-config.xml:- which acts as a controller by storing the navigations rules. And in addition to that it stores the configuration details about managed beans.
14)Web.xml :- which is the standard j2ee deployment description file and provide application level configuration details.