Building Business Service
In this recipe, we are going to build our Business Service Layer, which consists of one entity object based on the EMPLOYEES
table, one view object based on the entity object, and one application module to host the latest view object.
This will be the only recipe that talks about Business Service in brief in this book. If you want to know more about building Business Service, check the official documentation at http://docs.oracle.com/middleware/1212/adf/ADFFD/partpage2.htm#ADFFD20093.
How to do it…
In order to build your Business Service, follow the ensuing steps:
- Right-click on the Model project node from the Applications navigator pane and navigate to New | Business Components from tables...; by doing this, you are able to create all the three objects in one wizard instead of creating everything separately.
- If this is the first time you're dealing with business components in this application, a dialog will pop up asking you to initialize the business components project. It also asks about database connection. If you only create one database connection, it should appear preselected; if not, you should select it from the drop-down list or create a new one using the green plus icon; once this is done, click on OK to proceed. The Create Business Components from Tables dialog should pop up.
- Then, you define Entity Objects; click on the Query button to query all tables in the HR schema, select the
EMPLOYEES
table, and shuttle it into the selected panel. - Make sure that Entity Objects is created in the right Java package, which should exist in
com.adffaces.chapter2.helloadf.model.entities
based on the best practices of ADF BC. Also, it should not be mixed with application modules and view objects, so the result should beEmployees
. - Click on Next.
Tip
To know more about ADF conventions and best practices, check the official PDF guide at http://www.oracle.com/technetwork/developer-tools/adf/learnmore/adf-naming-layout-guidelines-v1-00-1897849.pdf.
- Create Entity-based View Objects that are traditionally known as updatable view objects; you should shuttle the
Employees
table from the left to the right panel. - Make sure that the package name follows the best practice by adding the
views
suffix; the package name will becom.adffaces.chapter2.helloadf.model.views
. Also, make sure you follow the best practice by having a suffix for your view objects instances by adding theView
suffix, which in this case should beEmployeesView
. - Click on Next.
- Skip Query-based View Objects as we don't have any of these in this simple application; then click on Next.
- Create an Application Module and naming it
HrAppModule
, which follows the best practice of adding theAppModule
suffix at the end of the name and appendingservices
to the package name. So, in this case, it should becom.adffaces.chapter2.helloadf.model.services
. - Click on Finish to close the dialog box. You should end up with the following structure in your Applications pane if you have followed the best practices in the ADF guide:
- Place a tick on the third item of the checklist to indicate it is done.
How it works…
In order to build a proper Business Service, you need to create ADF business components from your database tables, which will require you to create the following:
- Entity object(s): These are like one-to-one mappings with database tables so the structure of the entity bean should match the database table structure along with the added value of validations.
- View object(s): These are like
select
statements. It's the data that users can see and is based on the Entity object that makes this view object support the Update, Add, and Delete row operations; alternatively, it can be based on a SQL statement, which means it'll be read-only. - Application module(s): The application module is the window of your Business Service to the user interface. You can expose view objects or other application modules inside of it, and it'll be available to the ADF Binding layer, where it can be dragged to the user interface inside JSF pages, using the drag-and-drop feature.
After you create your entity object, view object, and application module, your Business Service is in place, and with your HrAppModule
, you automatically created your first Data Control.
You can see the created Data Control by expanding Data Control from the Applications pane; you will find the HrAppModuleDataControl
, and by expanding it, you will find EmployeesView1
underneath it, which represents your view object.
Now you are ready to define your application flow and Finish Step 4 in the Application Overview checklist.