In this tutorial you start to create the business services
for your application. Business services are the parts of the application that
are responsible for persisting the data in your application and implementing
business rules in the middle tier. There are different ways to do this. In this
tutorial, you use ADF Business Components for the middle tier business services.
Place the cursor over this icon to load and view all
the screenshots for this tutorial. (Caution: Because this action loads all screenshots
simultaneously, response time may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor
over each individual icon in the following steps to load and view only the screenshot
associated with that step.
Overview
As a Forms or Designer application developer, you should be
familiar with the concept of the data block. You can think of the data block
as a component or object that maps to an underlying database table and is responsible
for persisting data in the application before committing that data back to the
database. Similar functionality is available for developing Java applications
by using ADF Business Components: entity objects, view objects, and application
modules.
In this tutorial you create a number of entity objects and
view objects and add them all to a single application module.
Having identified the database tables on which to base
your application, and having established an idea of the basic flow of the user
interface, you now need to identify the actual business services to implement.
You need to specify the data that you want to manipulate from the database tables.
Below are rough sketches of the pages you create later
in this workshop. They are the browseCustomers, editCustomers and
browseCustomerOrders pages. From these sketches you can see that the
planned application manipulates data from the CUSTOMERS, ORDERS, ORDER_ITEMS,
and PRODUCT_INFORMATION tables. You can see that the pages vary slightly, not
all table columns are displayed, and some pages display data from multiple tables.
There are a number of approaches you can take to create
ADF Business Components. In this tutorial we use a combination of these.
First you create entity objects, which are data access
objects that are responsible for persisting and caching data, validation, and
encapsulating business rules. An entity object can be compared to a block's
record manager in Forms. Creating an entity object is similar to the Forms task
of choosing a table on which to base a data block.
In this first part of the tutorial we use a diagram.
To create entity objects on a business components diagram, perform the following
steps:
1.
In the OrderEntry application that you have been working
on, right-click the Model project and select
New from the context menu.
2.
In the New Gallery expand Business
Tier in the Categories list and select ADF Business
Components, then select Business Components Diagram
from the Items list.
Click OK.
3.
In the Create Business Components Diagram
dialog, enter the diagram name CustomerAppBC_Diagram and
set the package name to model.
Click OK.
4.
There are number of ways of creating entity objects on
the diagram. Possibly the easiest is to drag database tables directly
onto the diagram to create the entity objects.
With the CustomerAppBC_Diagram diagram open in the
editor, open the Connections Navigator.
Expand the Database node, the oeconn connection,
the OE schema, and the Tables node.
[Ctrl-click] to multi-select the CUSTOMERS,
ORDERS, ORDER_ITEMS and the PRODUCT_INFORMATION
tables and drag them onto the diagram.
5.
In the Create from Database Object dialog, you are presented
with the choice, based on the project technologies. Select Business
Component Entity Objects. Click OK to create
the entity objects.
6.
You should now have four entity objects on your diagram
linked by their associations, based on the tables and foreign keys on
the database.
Note: You will also get a few additional domain objects
created when you drag the tables from the database. These are created
because the CUSTOMERS table uses Oracle Object Types. You can ignore
these.
If you have time, you can work with the layout of these entity objects
in the same way you did with the tables in the previous session.
7.
Return to the Applications Navigator and expand Model
| Application Sources | model. You can now see the objects
that were created in your Model project when you dragged the tables
onto the ADF Business Components diagram.
8.
Click Save All
or select File | Save All to save your work.
Usually an entity object's attributes have a one to
one mapping to the columns in the database, and they are reused in a number
of view objects in the application. However, there may be circumstances when
you want to limit the attributes in the entity objects. In this example, we
remove an attribute from an entity object that is never used by the application.
1.
Select the Customers entity
object in the diagram. Right-click and select Properties...
from the context menu to invoke the Entity Object Editor.
2.
Selecting Attributes from
the tree on the left and the CustGeoLocation attribute
from the Entity Attributes panel on the right, remove the attribute.
Click OK.
Note: Alternatively you can delete the attribute from
the diagram. Be sure to delete just the attribute and not the whole
entity.
3.
Click Save All
or select File | Save All to save your work.
Now that you have created entity objects, you create
view objects.
View objects, which are based on entity objects and
represent the data you want to view and manipulate, are often referred to as
the query. Creating a view object in JDeveloper is roughly analogous to the
task in Forms of selecting columns to include on a Forms canvas when using the
Layout wizard.
In this section you create the view objects CustomersView,
OrdersView and OrderItemsView using a wizard. To create view objects using a
wizard, perform the following steps:
1.
With the Business Components diagram open,
select Customers, Orders and OrderItems,
right-click and select Generate | Default Data Model Components
from the context menu.
2.
For step one of the wizard, the Selected
panel now has CustomersView, OrdersView and
OrderItemsView listed. These form the basis for each of your
query objects. The view objects are related to each other through the
underlying relationships between the entity objects. You also need the
relationships between these queries, so add these by shuttling the OrderItemsOrderIdFkAssoc
and the OrdersCustomerIdFkAssoc across too. These become
the view links between the view objects.
Before you move to the next page, add .queries to
the package name. This will ensure the view objects go into their own
package.
Click Next.
3.
Step two of the wizard creates an application module
with all the view objects in it. You will create the application module
in the next section, so for now, uncheck the checkbox Application
Module.
Click Finish to complete the wizard.
4.
Notice how the Application Navigator now displays two
nodes. Expand the queries node to see the objects created.
5.
You can also review these objects on the diagram. Select
the 3 view objects, CustomersView, OrdersView and OrderItemsView
and drag them onto a blank area in the diagram. Notice the view links
between each of the view objects. These view links maintain the relationships
between the view objects.
You can lay the objects out as you please. A suggestion is shown below.
6.
As mentioned earlier, the view object is a query and
does not necessarily mirror all the attributes in the entity object.
Using the diagram, double-click OrdersView to invoke
the View Object Editor, and select the Attributes node. Select the PromotionId
and click Remove
to shuttle the attribute from the Selected list.
Click OK.
7.
Using the diagram, select the ProductInformation
entity object and drag it to the OrderItemsView view
object.
8.
The view object displayed in the diagram should now contain
two entity objects, OrderItems and ProductInformation, with their attributes
displayed to the left. You may need to resize the view object and move
the entity objects to see both of them, because they may initially be
stacked on top of one another.
You can right-click the view object and select Lay Out Internal
Shapes | Hierarchical (Bottom to Top)
9.
Double-click the OrderItemsView view
object on the diagram to open the View Object Editor.
Select the Entity Objects node in the tree on the left, then select
the ProductInformation1 in the Selected list.
Change the alias to ProductInformation.
Ensure that Updatable is not
checked and that Reference is checked. The reason
for doing this is because in the Order Items view, you will be displaying
information from the Product Information table, but you will not
be updating it. This is similar to using a post-query trigger in
Forms to retrieve information from another table into a non base
table display item in a block.
10.
Still in the View Object Editor, select the Attributes
node. You only need ProductId1, ProductName, and ProductDescription
from the ProductInformation entity object. [Shift-click]
all the other ProductInformation attributes in the Selected list below
those, to select them, and click Remove
to shuttle the attribute from the Selected list.
Click OK.
11.
Click Save All
or select File | Save All to save your work.
An ADF Business Components application module
is a service object that coordinates view objects for a specific task in the
same way that a form usually encapsulates a single user task. It contains only
the business services that the application requires, and can be compared to
a Forms module.
You can create an application module using the
same wizard you used in the previous section. The wizard add more pieces than
you require, so instead you'll create the application module visually. To create
the application module using the diagram, perform the following steps:
1.
Return to the business component diagram,
ensure that Business Components is selected in the
dropdown list at the top of the Component Palette.
Drag an Application Module onto the diagram.
2.
On the application module enter the name
CustomerOrdersBusinessService.
3.
Select the CustomersView and
OrdersView view objects and drag them onto the CustomerOrdersBusinessService
application module.
4.
In the same way, select the OrderItemsView
view object and drag it onto the CustomerOrdersBusinessService
application module below the other view objects.
5.
Notice how there is a view link between the CustomersView
and OrdersView view objects, but nothing linking them
to the OrderItemsView view object.
6.
Use the Component Palette and select View Link
Instance, click on OrdersView1 and then
OrderItemsView1 to add the view link.
7.
Double click the CustomerOrdersBusinessService
application module to invoke the dialog. Notice the hierarchical relationships
between the view objects.
8.
By using the diagram to create the application module
we did not get the opportunity of creating it in a separate project.
Projects are very useful for grouping logical pieces of work together.
In this last section, you move the application module into its own project,
by using refactoring.
Return to the Applications Navigator and expand Model | Application
Sources | model. Select the CustomerOrdersBusinessService
application module, right click and select Refactor | move...
9.
Enter model.services in the dialog that
appears.
Click OK. (Click Yes when asked if
you'd like to create the specified package.)
10.
Notice that you now have three project nodes under Application
Services and that the application module CustomerOrdersBusinessService
has been moved to the new project model.services.
11.
Click Save All
or select File | Save All to save your work.
In this tutorial you learned how to create entity objects
based on tables in the database and with the same names as those tables. Using
a wizard, you then created view objects that represent the data (specific columns)
that you plan to use in the application, and view links, which preserve a master-detail
relationship between the view objects. Finally you created an application module
to contain and coordinate the view objects and view links to be used for the
order entry task.