The Oracle Application Development Framework (ADF) is a mature J2EE application development framework, well supported by Oracle JDeveloper. By using ADF, a developer can minimize the coding effort to build an application's infrastructure and will be able to concentrate more on implementing the complex business logic of the application. In this article I will discuss the Oracle ADF application development process.
Oracle ADF is based on the Model View Controller design pattern. It offers an integrated solution that captures all the layers of the MVC architecture. Oracle ADF allows a developer to create user interfaces by empoloying the drag and drop mechanism. This has two benefits:
- Faster development
- The developer can concentrate in implementing the complex business logic.
Oracle ADF work flow components
As mentioned above, Oracle follows the Model View Controller (MVC) design pattern. As you probably know, an MVC application is separated into:
- A model layer that is used to handle the interaction with different data-sources and executes the business logic.
- A view layer that handles the user interface of the application.
- A controller that act as manager to manage the application flow and acts as an interface between the model layer and the view layer.
Implementing these layers eases the maintenance of the application and reuse of components across applications. This separation of one layer from others results in a loosely coupled, Service Oriented Architecture or SOA.
Oracle ADF not only implements the MVC design pattern but it also separates the model layer from the business services to enable service oriented development of applications. Oracle ADF architecture is based on following four layers:
- Business Service Layer - This layer provides access to data from different sources and also contains the business logic
- Model layer - This layer provides an abstraction on top of the business service layer. Thus this layer enables the view and the controller layers to respond to different implementations of business services in a uniform way.
- Controller layer - This layer controls the flow of the application.
- View Layer - This provides the user interface of the application.
Figure 1: Oracle ADF works flow.
We will now see how to develop a sample application using JDeveloper 12c (Version 188.8.131.52.0) on a Windows platform. This software can be downloaded from http://www.oracle.com. The software comes in to form of a single executable binary file. Installation on Wndows 7 should be carried out as an administrator. Once installed, JDeveloper can be started by selecting Start > All Programs > Oracle > Oracle Home > Oracle JDeveloper Studio > Oracle JDeveloper Studio. Select the role 'Studio Developer (All Features)' and then hit the 'Ok' button. Click on the 'New Application' as shown:
Figure 2: Creating new application The following screen should come out:
Figure 3: Showing option selection
Now we have a process of six steps as shown below:
Step 1: Provide the application name
Step 2: Provide the project name for the model
Step 3: Specify the following java settings for the model project
- Default Package
- Source path
- Output directory
Step 4: Provide the project name for the view controller
Step 5: Specify the following java settings for the model project
- Default Package
- Source path
- Output directory
Step 6: Specify the build tool. You can have your own ant or maven script but it is advised to use the default JDeveloper build tool.
Now click on the 'Finish' button:
Once the project is created successfully, we get the following screen:
As we see here, we get following two projects created:
Now to start with, let us consider an example of a simple application where we have two tables: MEMBER and CATEGORY_MASTER. The SQL to create these two tables are as under:
CREATE TABLE MEMBER"
( "MEMBER_ID" NUMBER NOT NULL ENABLE,
"MEMBER_FNAME" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"MEMBER_LNAME" VARCHAR2(20 BYTE),
"MEMBER_DOB" DATE NOT NULL ENABLE,
"MEMBER_CATEGORY_ID" VARCHAR2(20 BYTE) NOT NULL ENABLE,
CONSTRAINT "MEMBER_PK" PRIMARY KEY ("MEMBER_ID")),
CONSTRAINT "MEMBER_CATEGORY_ID" FOREIGN KEY ("MEMBER_ID")
REFERENCES "CATEGORY_MASTER" ("CATEGORY_ID") ON DELETE CASCADE ENABLE
CREATE TABLE "CATEGORY_MASTER"
( "CATEGORY_ID" NUMBER NOT NULL ENABLE,
"CATEGORY_NAME" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"CATEGORY_DESCRIPTION" VARCHAR2(200 BYTE)
CONSTRAINT "CATEGORY_MASTER_PK" PRIMARY KEY ("CATEGORY_ID")
As we see here the table CATEGORY_MASTER is used as a master table to store the different categories of the members and the table MEMBER stores the information about the members.
Now let's build the persistence model for member and category master using Enterprise Java Beans 3.0 standard entity beans. In the Application window, right-click on the project ModelPrj. Select New and then From Gallery. The screen shot is shown below.
The following screen should appear:
Click on Business Tier > EJB > Entities from Tables
Now click on Ok. The following screen should appear:
Select JPA 2.0 and then click on Next. The next screen mentions the persistence unit. Click on Next on this screen. This screen asks for the credentials to connect to the database. Provide the necessary data on this screen and hit the Ok button. You can also test your connection first and then finally connect to it. Once connected, the next screen shows the database connection parameters. Select your tables from the database and then click on the Next button. The following screen should appear:
Keep clicking the Next button until you get the following screen:
Click on 'Finish' button on this screen. The following screen should appear after successful completion.
Once this is done lets create the EJB diagram using: Right click on ModelPrj > Select New > From Gallery > EJB Diagram (JPA/EPA 3.x).
In the component window select EJB Component and open the EJB Nodes > Session bean. Create a session bean with name - MemberEJB. Provide the relevant details and click on the Finish button on the following screen:
The application window and the diagram should look like the following.
Now create the EJB data control. This is a five step process. Keep clicking on the Next until you get the Finish button. Click on the 'Finish' button. The data control gets created. Once created, the following screen should appear:
Right click on the DataControls > memberEntityFindAll > Provide the UI Hints and the Validation rules Now create the ViewController Project. Right click on the ViewControllerPrj > New > From Gallery > Webtier > Jsf facets. Select Page as item and then click on Ok. Provide the file name as member.jsf.
On the next screen select the layout of your choice as under and then hit 'OK' button.
Once you specify the input fields and provide the mapping with the EJB your application is ready to use.
This article has concentrated more on the practical part of Oracle ADF application development. Oracle ADF is a very good tool for a Java developer who wants rapid development of an application that can be easily integrated with an Oracle database. The ease of UI development allows the developer to focus primarily on the business logic.
About the Author
Kaushik Pal is a technical architect with 15 years of experience in enterprise application and product development. He has expertise in web technologies, architecture/design, java/j2ee, Open source and big data technologies. You can find more of his work at www.techalpine.com and you can email him here.