Wednesday, October 20, 2010

Tutorial 1: ADF Business Components


In this post we’ll go through the business services part of ADF architecture i.e., ADF business components (ADF BC). Let’s see what they can do, what all ADF BC consists and later how we develop them. We’ll also create sample ADF BC components.
In a typical application a developer have to take care of all the following when dealing with data.
-> Establishing a connection to database.
-> Retrieving data and buffering the data.
-> Locking the data for DML operations.
-> Managing the transactions across multi user environments.
Imagine with ADF BC libraries and JDeveloper you can do all these without writing a single piece of code!
Apart from those you can achieve the following with very less coding.
-> Build and enforce business logic across application at a single point.
-> Trim the database views to do only specific tasks.
-> You can simply modify and maintain the business functionality directly on ADF BC instead of modifying the already built application.
-> Provide updatable views from a desktop, mobile, browser and web service clients.
-> You can also verify and test all the business validations/functionality before you actually build the application.
To be simple, ADF BC is like a wrapper on top of the database which provides additional functionality.

ADF BC Components:
The following are the core business components.
1) Entity Objects (EO) – Represents a row in a database table. Entity objects hold the business validation logic and also handle DML operations. It can be built on a single table/ view / synonym.
2) View Objects (VO) – Represents a SQL query. They generally focus is on how we present data to client.
3) Application Module (AM) – Provides single point of access to all VO’s to achieve a task. Its job is to maintain all transactions.
          Apart from the above we have Entity Associations and View Links. Entity associations are used to depict the relation between two Entity Objects (such as foreign key relation) just like the database tables are related. View Links represents the relations between two View Object result sets such as master detail relation.


Creating and testing ADF BC using wizard:

         In this tutorial we create ADF BC components for Employee and Department tables using the wizard and do test them by performing DML operations through them.


Step 1: Start the Jdeveloper and choose ‘Default role’ when prompted.


Step 2:  Select ‘New Application’, give application name as ‘ProjectADF’, Application Package Prefix as ‘sdadi.oracle.apps.hr’, select Fusion Web Application (ADF) as application template and click ‘Finish’.
 The general naming convention is <com>.<your company>.<your app>.<your module> and sub packages if any.

Jdeveloper creates two projects ‘Model’ and ‘View Controller’. The model part deals with the ADF Business Components and ‘View Controller’ deals with UI and control parts of the application. In this tutorial we focus only on the Model.


Step 3: Right Click on ‘Model’ and select ‘New’

Step 4:  Select Business Tier > ADF Business Components >> Business Components From Tables and click OK.


Step 5: Click on the ‘+’ to create a new database connection. Provide the connection details (hr/hr) as in the figure. Verify connection details by clicking ‘Test Connection’. Click OK after verifying the connection is 'Success!'
I am assuming that oracle DB is already installed and HR schema is unlocked as given in the earlier post.


Step 6:  Set the package as ‘sdadi.oracle.apps.hr.schema.server’. This is just to ensure that all the Entity objects are created under this folder. Set Name Filter to ‘%’ and Click on ‘Query’ to see all objects (Tables, Views and Synonyms) under HR schema.
                Shuffle ‘Employees’ and ‘Departments’ and change the Entity names to EmployeeEO and DepartmentEO. This is just a naming convention for ease of use in future.


Step 7:  Set the package as ‘sdadi.oracle.apps.hr.server’ and shuffle both the entity objects. Rename the view object names to EmployeeVO and DepartmentVO.


Step 8: We are not planning to create any read only view objects in this so just click on next. (Read Only view objects are similar to read only views in the DB, you cannot use them to do DML operations)
Step 9: Provide package as ‘sdadi.oracle.apps.hr.server’ and name as ‘EmpDeptAM’ and click finish.


Step 10: All the required ADF business components are created automatically by JDeveloper and ready to use. You observe that the required Entity Associations and View Links are created based on the database constraints.



Step 11: Test the created ADF BC by right clicking on ‘EmpDeptAM’ > Run. This will open a window with all the view objects and view links included in the AM.



Step 12: You verify by double clicking the view objects and view links and see that rows are fetched accordingly. You can insert a record, delete a record, commit the database, modify a record or simply navigate between records.



Wednesday, September 29, 2010

Getting Ready!

In this post I’ll list down the tools and set ups required to start building ADF Applications.
We will be using the Oracle JDeveloper as IDE and Oracle 10g XE as our database in all our further developments.  All Oracle products are free to download and use for individual learning purpose. You can download these products from Oracle site.

JDeveloper: 
                JDeveloper is an IDE which makes the life of a developer easy with visual editors. You can simply develop an application with very less coding or no coding at all! Go to the below link and download the latest 11g version of Jdeveloper studio edition.
                Here are the system requirements for windows.

                                CPU Speed         2 GHz or faster
                                Memory             2 GB RAM
                                Disk Space         2.5 GB
                                JDK                     JDK 6.0 Update 11

                Set the Environment variable JDEV_USER_DIR, JDEV_USER_HOME to directory where you would like your source code to be placed. You can cross verify that variable is set by executing  'Set JDEV_USER_DIR' command in the command prompt.     
      You can get the JDev installation guide here.

Oracle 10g Express Edition Database:
                Oracle 10g XE is a light weight DB and occupies very less space in your system. You can download it from the below link.
       During the install It’ll ask you to provide a default password for SYS and SYSTEM, provide a password and remember it. Once the installation is done go to command prompt and execute the following steps.
1. At command prompt type ‘sqlplus system’. It’ll then ask for password. Give the password you entered during the installation.
2. Type the following command in the SQL> prompt ‘alter user hr identified by hr account unlock;’ - this will unlock the HR schema.
3. Exit the command prompt.
 The HR schema contains Employees, Departments, Jobs, Countries and other tables. We use these tables for our further excercises.
                 Now we have the IDE & DB ready, We can start the tutorials!

Wednesday, September 22, 2010

Breaking the ground.

Welcome to my blog 'Project ADF'. The main intention behind this blog is to share my learning experience and make others learn ADF simple. In the intial posts I'll give a background of ADF. Then a few tutorials to make you ready to build strong ADF applications. Later I'll be posting my learnings and solutions to some common tasks in ADF.

In this post I’ll tell you what is a design pattern and a framework. I’ll take you through how the main design pattern, Model View Controller (MVC) is used in ADF architecture and in what all technologies you can develop an application using ADF.


Design Patterns:
There are many ways to solve a problem, but a few will be to best address it. The best way to achieve a particular task is called a design pattern. Design pattern is nothing but a way, a template to achieve a common problem, not a readymade code. It’s up to you to decide which language you implement them in. We have many design patterns each addressing problems like how to establish and Maintain database connections, Handle multiple DB operations without compromising on its integrity, Handle several user requests at same time, Maintain multiple sessions, Maintain multiple databases, Encapsulate database details from application, To decrease the number of trips from server to db their by transactional cost and lot more. There are many design patterns around, just google.
Framework is way to develop an application. It is a skeleton on which you build up. It’s a collection of methods called API’s, set to achieve a common target. Most of them are developed based on one or more design patterns. You can simply say framework is a collection of design patterns and API’s which are set to achieve a bigger target.

Model View Controller (MVC):
You already know it! You just need to observe a little more to realize that it is Model View Controller architecture (MVC).
Let’s recollect how you came to this blog. Your friend sent a link for it. No? Ok, you googled and found it?  Naa?.. ok it doesn’t matter.  Whatever you got a pointer, clicking a link or entering address and pressing ‘Go’ brought you here. It means some program recognize that click and arrange the necessary content and informed your browser where to go. Your browser fetched the content and refreshes UI. The program that identified click is controller, the content is model and presenting appropriate content in user interface is view.  The controller handles all the events and arranges/changes content appropriately. The model is nothing but the data, which can be changed by the controller. The view uses the content/data and shows it in UI.
Here is how it happens...
1. User interacts with UI, generating an event by pressing a mouse or keyboard button.
2. The Controller handles the event, determines page navigation and finds appropriate view.
3. The Controller also notifies the model about user action and even sometimes changes the model state accordingly.
4. The view queries the contents of a model and specifies how that data should be presented. The view will be notified by model if there is a change of state which requires a refresh.
5. The UI waits for user to generate another event, which restarts the cycle.

MVC Architecture


ADF Architecture:
Here is the ADF architecture. You can clearly see how MVC is incorporated in it.

ADF Architecture

You can use any technology given in the above figure for different layers of MVC. Here you see one extra level i.e., Business services. These are used to perform various operations like connecting to database, retrieving data, locking the db records, managing transactions. ADF BC can be used to address all these with help of built in libraries.
In the upcoming topics we narrow our learning only to the following in which most percent of the Fusion applications is built upon.