Sunday, December 24, 2006

External Transaction Service in Oracle TopLink

I have developed sample application, in order to demonstrate how to use External Transaction Service (ETS), when Oracle TopLink is used in Model layer. The business logic of this sample is to update employee salary and commission points without making explicit commit operation in EJB Session Bean. When ETS is used, Application Server thinks about when to use commit operation, not a developer. sample application is based on standard HR schema, Employees table. When developing this sample, at first I have generated TopLink entity object from Employees table. The second step was to create OC4JServerPlatformConfig class, this class will configure the session's server platform. The third step was to configure sessions.xml:
  1. Open sessions.xml in JDeveloper dialog window
  2. In General tab select check box for External Transaction Controller and enter following class name - oracle.toplink.transaction.oc4j.Oc4jTransactionController. For Session Event Listeners add - lt.andrejusb.persistence.OC4JServerPlatformConfig class name
  3. In Login tab select General tab and choose Data Source option for Data Source Location. Enter data source name in Data Source field, for example - jdbc/HrDS. Clear all other checkboxes in this tab
  4. In Login tab select Options tab and set True for External Connection Pool and External Transaction Controller
The fourth step was to generate EJB Session Bean and add custom updateSalary(Employees) method into it. Do not create any Core Facade Methods, when generating EJB Session Bean.

There is no explicit commit operation in updateSalary(Employees). UnitOfWork is acquired from session.getActiveUnitOfWork(), however if there is no active UnitOfWork session.acquireUnitOfWork() is used. Salary and commission points are updated using Employees clone object.

In the View layer, two JSF pages are used - view.jspx and edit.jspx. In view.jspx user can browse through available emploees data, and in edit.jspx update salary of the selected employee. Update button of ADF Faces Form in edit.jspx is binded to updateSalary(Employees) method.

Merry Christmas everyone! :)

Thursday, December 21, 2006

JDev/ADF samples list

This week, Steve Muench on his examples page have added a link to my JDev/ADF samples list. Thanks, I'm very proud of this - it is cool, to be a part of Oracle community! Hope, those samples will be useful for people who are working with Oracle/J2EE, I will post new samples routinely. See you!

Sunday, December 17, 2006

Creating new row using CreateInsert operation

Sample application -, demonstrates how to create editable table with 'create new row' functionality in ADF BC.

We will use Jobs entity, generated from standard HR schema Jobs table. When view object and application module are generated, it is time to drag and drop Jobs table in View layer. Drag and drop it as ADF Table (not read-only). When table is created, expand Operations group and select Create operation.

Drag and drop selected Create operation to the 'actions' facet of the table and create ADF Command Button. However, it is not enough just to drag and drop. Additionally, select created button with right mouse click and choose Edit Binding. In the opened dialog choose CreateInsert instead of Insert as an action for JobsView1.

Now, drag and drop Commit operation to the 'actions' facet of the table and create second ADF Command Button. Finally, we have implemented editable table with 'create new row' feature.

Dropdown list in each row (J2EE track)

If someone wants to implement dropdown list in each row of the table, and he is using ADF BC in Model layer, there is no problem - just use ADF screencast available in Steve Muench blog. But, if TopLink and EJB are used in Model layer, then implementation will be little bit different. Below I describe how to implement this using TopLink and EJB.

Let us use standard HR schema entities - Employees and Departments. The main trick is to add getter and setter methods into Employees entity bean for the departmentId (this will enable us to use departmentId in Employees entity). Below are main steps you need to follow when developing View layer:
  1. In the page definition file define methodAction for findAllDepartments. Define a methodIterator binded to findAllDepartments method definition and a table with two items - departmentId and departmentName
  2. Create af:selectOneChoice in af:column component as it is described in Steve Muench screencast
So, the main differences are to modify entity bean and to define some additional elements in page definition file.

Sample application -

Wednesday, December 13, 2006

Displaying all columns in ADF table (TopLink entity)

If you are using ADF Faces table, that is based on TopLink entity bean and is generated from Data Control, by default you can not show columns involved into primary-foreign key relationship. It is because, Data Control generated based on Session Facade does not allow to display columns of ValueHolderInterface type, only data types (String, Integer, etc.) are allowed. For example, if we have Regions(regionId, regionName) and Countries(countryId, countryName, regionId) tables, by default it will not be possible to generate such ADF Faces table - Table(countryId, countryName, regionName).

How to show all columns? I have solved this, by adding one getter method to Countries TopLink entity bean:

public String getRegionName() {
return this.getRegions().getRegionName();

You can download sample application I have developed to solve this issue - (JDeveloper Application description:
  1. As a datasource, standard HR schema is used
  2. Two entity objects are generated - Regions and Countries
  3. Getter for regionName is added into Countries TopLink entity bean
  4. Session Facade and Data Control are created
  5. To countries.jspx page, Countries Method Return is dragged and dropped from Data Control Pallete.
Generated Data Control, regionName involved into primary-foreign key relationship is available:

Data displayed on countries.jspx page:

Monday, December 11, 2006

JDeveloper Users map

While browsing through Frappr community maps, I have found one map that is really interesting for me - JDeveloper Users map. I'm on this map now, because I like JDeveloper tool! And, what about you?

Saturday, December 9, 2006

Oracle Spatial and Network Data Model

During this week, a student from university where I'm achieving my master degree - Vincent, have asked me how to create SDO network data model in Oracle Spatial. Before asking me, he has already developed his own network model, but validation error was generated when using SDO_NET.VALIDATE_NETWORK function. When reviewing his data model definition, I have found that network metadata was declared incorrectly.

I have developed a short tutorial, which may be useful when working with Oracle Spatial Network Data Model. Scripts developed for SDO network data model definition - Contents of the archive are:
  1. nodes.sql - creates empty table to store network nodes;
  2. nodes_data.sql - data to be stored in nodes table;
  3. links.sql - creates empty table to store network links;
  4. links_data.sql - data to be stored in links table;
  5. path.sql - creates empty table to store paths data;
  6. path_links - creates empty table to store path links data;
  7. medata.sql - defines metadata for nodes, links and paths spatial columns and metadata for spatial network;
  8. indexes.sql - creates indexes for nodes, links and paths spatial columns;
  9. validate.sql - performs test for network validity, result should be TRUE
When defining SDO network data model, ensure that you have stored correct spatial information in nodes, links and paths tables. And, do not forget to define metadata correctly.

Resources for Oracle Spatial technology:

Monday, December 4, 2006

Oracle ADF - between 4GL and J2EE is only one step

According to ADF architecture described in Oracle JDeveloper 10g (10.1.3) Developer's Guide Section 1.1.1 - Framework Architecture and Supported Technologies, it is possible to use both Business Services - EJB+TopLink (J2EE track) and ADF Business Components (4GL track) in the same View layer. ADF Faces components used in View layer should access separate Business Services through unified ADF Controller layer. However, I have never tested it in practice. To test it, I have created sample application -, where two JSF pages are used - one to create data, another to view it.

For database schema I'm using standard HR schema and one table from it - LOCATIONS. Application contains three projects - DataModelJ2EE (for EJB+TopLink), DataModelBC (for ADF Business Components) and UserInterface (for ADF Faces). As you see, I'm using the same view layer for both Business Services.

View layer contains two pages - create.jspx and view.jspx. JSF page create.jspx contains ADF Creation Form generated from BC application module data control. When new record is created, view.jspx page is opened. JSF page view.jspx contains two ADF Tables, each table contains data from the same LOCATIONS table. First table is generated using EJB Facade data control, second using BC application module data control. There are two JSF navigation cases - from view.jspx to create.jspx and otherwise.

Application View layer, based on EJB+TopLink and BC works correctly, just do not forget to add refresh condition for table generated using EJB Facade data control. All definitions for both tables are stored in the same page definition file. Let us explore page definition file in more detail.

For table generated using EJB Facade data control we have:

1. Method iterator

2. Invoke action for table refresh

3. Method action

4. Table

For table generated using BC application module data control we have:

1. Iterator

2. Table

All of these definitions are in the same file and are used by the same JSF page. So, there are two tracks - J2EE and 4GL, but you can integrate them perfectly in View layer, using the same ADF Faces components.

Why I'm here?

Oracle for me is more then technology, it is a way how I think. So, I'm creating this blog in order to express my knowledge in Oracle Fusion Middleware and Oracle DB. Since I came into Oracle world through Oracle Spatial technology, I will post about Oracle Spatial as well. I hope, that shared knowledge will be useful.