官术网_书友最值得收藏!

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.

Tip

In a real application, it's always a good practice to establish a uniform naming convention for your business components, such as suffixes and package names, which can be found by navigating to Tools | Preferences | ADF Business Components | Object Naming and Packages.

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:

  1. 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.

    Tip

    You can expand substeps in the Business Service checklist item and create each of them separately if you want; it'll be a good practice for you as well.

  2. 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.
  3. 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.
  4. 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 be Employees.
    How to do it…
  5. 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.

  6. 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.
  7. Make sure that the package name follows the best practice by adding the views suffix; the package name will be com.adffaces.chapter2.helloadf.model.views. Also, make sure you follow the best practice by having a suffix for your view objects instances by adding the View suffix, which in this case should be EmployeesView.
    How to do it…
  8. Click on Next.
  9. Skip Query-based View Objects as we don't have any of these in this simple application; then click on Next.
  10. Create an Application Module and naming it HrAppModule, which follows the best practice of adding the AppModule suffix at the end of the name and appending services to the package name. So, in this case, it should be com.adffaces.chapter2.helloadf.model.services.
    How to do it…
  11. 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:
    How to do it…
  12. 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.

Tip

A Data Control can be created for Java objects, web services, and more; however, it is created automatically with every application module you create inside your Business Service Layer.

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.

Tip

If you want to make sure that everything is correct with your Business Service, you can start the Oracle ADF Model Tester by right-clicking on the HrModule application module and then clicking on Run.

Now you are ready to define your application flow and Finish Step 4 in the Application Overview checklist.

主站蜘蛛池模板: 宣汉县| 扬州市| 汝城县| 台前县| 长春市| 澄迈县| 荃湾区| 胶南市| 汉沽区| 东莞市| 崇信县| 锡林郭勒盟| 荥经县| 宜兰市| 临漳县| 高密市| 德格县| 会宁县| 阆中市| 临猗县| 来凤县| 阿拉尔市| 金沙县| 阿拉尔市| 奉贤区| 长岛县| 雷波县| 丽水市| 临沂市| 肇庆市| 文安县| 揭阳市| 廉江市| 龙江县| 遵化市| 彭水| 平南县| 富阳市| 温泉县| 扎鲁特旗| 金塔县|