Tuesday, 1 February 2011

Showing Data Based on List Of Values And Bind Variables

 Create one Fusion Web Application with Model and View Controller projects.

Create ADF Businesss Components.

Like below I have created,

One HRApplication is created with HRModel and HRViewController projects.

Then created the entities(Employees, Departments) from Employees and Departments tables.



Then created the updatable view objects.(EmployeesViewObject,DepartmentsViewObject).



Then created the Application Module (HRAppModule)


Now click finish to complete the Business components.

Now I should create the view criteria to create the criteria and create the bind variable to pass the selected data from list of values.

First Create the List Of Values to be displayed in criteria.

I am creating it to show employees present in one department.

To do that

First open the EmployeesViewObject.xml in "Overview" mode.

Go to the Attributes page.

Only Employees entity's attributes are being shown there.

To display the Departments entity's attribute . Go to "Entity Objects" option. Add the Departments entity object on right side.


Now come to "Attributes" section again.

Right click the down arrow beside the green add button as shown in the picture.

Choose option Add Attribute From Entity



Chhose all the Deaprtments' Attributes.

Now Select the DepartmentName attribute.

Click the Green Add Button related to List Of Values:DepartmentName as shown in picture.



Choose the List Of Values properties.



Now go to "Query" portion to create the view criteria.



Now your business components are ready



Now Go to HRViewController project.

Create one jspx page from JSF> JSF Page


Now refresh the Data Control Pane.



Drag the EmployeesViewObjectCriteria in page's center region.

Choose Query> ADF Query Panel With Table

Now create the table with suitable attributes.

You will be able to see the page with LOV.
 The value selected in LOV is being passed to the Bind Variable created.




In this way List Of Values with input text can also be created.



 

Friday, 21 January 2011

Application Module - Optimistic Lock vs Pessimistic Lock

In Application Module the locking is by default pessimistic lock.

jbo.locking.mode is pessimistic by default.

But the practice should be optimistic locking.

How to change the locking mode.

We can easily change the locking mode by opening
"EDIT BUSINESS COMPONENT CONFIGURATION".



change the value to optimistic.

The pessimistic locking holds lock on database but optimistic does not hold lock on database.

So in case concurrent update

1> pessimistic locking - The second user for concurrent data update will stuck with error until first user saves or undo data change.
The second user will be forced to wait until first user will Save or Undo his changes in order to proceed with data commit. Another option for the second user - Undo his change in the current row and proceed with other rows editing. When the first user will close his transaction, the second one will be able to save his changes for previously locked record as well.

2> optimistic locking - The first user will not hold database lock and second user will be able to continue his work. At the same time, first user will be able to press Save button second time, and his data will be committed.

So for general optimistic locking is better to use.

By the way

There are three types of locking:
1. normal
2.optimistic
3.pessimistic



 

Thursday, 20 January 2011

Handling Stale Data

While using ADF one internal feature of ADF model is Data Caching. So for neseted application modules sometimes it makes problems like RowInconsistentException.

To remove that we can use setClearCacheOnCommit.
By default its value is false.

But if we make it true it will clear the previous cache on every commit. So the data updated by other users always get updated.

It can be done by two ways.

1. Open the ApplicationModule.xml in source mode. and set the ClearCacheOnCommit="true"


or
2. If AppModuleImpl.java is created use the following code there.

 this.getDBTransaction().setClearCacheOnCommit(true); in constructor.

This should solve the problems like Stale Data.

Use Server's Data Source In AM Instead Of Application Connection DataSource

Using Data Source instead of normal JDBC connection has lot of advantages. Major one is Data Source behaves dynamically. One can change the Data Source's Configurations also. While the deployed application will not be affected if Data Base Objects do not get altered.

But one problem I have found in industry is that how to configure different data sources in application module(Root Application Module) .

Normally for testing purpose we do not use Data Sources we use application modules jdbc connection.

To configure data sources we can choose two types of Data Sources(Based on Authentication)

1. Application
2. Container

As we are discussing here about using server's Data Source I will be going with Container based one.

To configure this I suppose I will be using "HRDataSource" as Data Source Name.

First I shall edit the Application Module Configuration to refer HRDataSource.

To do that I should follow these steps:

1. Right Click On AppliationModule.xml(MSService.xml in picture).
2. Click Configurations - It will open Manage Configurations wizard.
3. Now click on edit - and edit the DataSource as java:comp/env/jdbc/DataSourceName

Click save all


Now we have added the DataSource in AM. But if we deploy the application in server we may still get errors though jdbc/HRDataSource exists in server.

We have to configure the authentication to be of Container.

To do that we should edit the web.xml of View Controller project.

We should one Data Source Reference there of Authentication Container.

The configuration should be like below image. Data Source is of javax.sql.DataSource type.



Now if we deploy the application it should take HRDataSource for Data Base connection.

So If you need to modify the DataSource name , just modify bc4j.xcfg located in common folder and web.xml located within WEB-INF folder.

Here the Data Source is found out using context lookup.

as like below.

Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Look up our data source
DataSource ds = (DataSource)envCtx.lookup("jdbc/HRDataSource");

// Allocate and use a connection from the pool
Connection conn = ds.getConnection();
... use this connection to access the database ...
conn.close();


-------------------------------------------------------------------------------------------------------

The Data Source can be configured by directly and only in bc4j.xcfg file only. Without mentioning any reference in web.xml

just put the jndi name of the Servers Data Source in 'Custom JDBCDataSource="jdbc/HRDataSource" />' in bc4j.xcfg file deploy it in server.

It will run as expected.


--------------------------------------------------------------------------------------------------------



 

Friday, 24 December 2010

Installing Oracle JDeveloper with ADF

To install the JDeveloper you must have the JDeveloper with ADF studio for your operating system.
You can download the software from the link(Download from here).

After download is complete launch the software to install JDeveloper in your machine.
                                                          

First Screen

Second Screen

Third Screen
Choose to create a new middleware home. Mention the location where you want to install the software.
Click next and accept all in coming screens to install the software.

You will find that JDeveloper is installed in specified directory.
Launch installed Jdeveloper to verify the installation.

Start Voyage With ADF

ADF - Stands for Application Development Framework.
Oracle ADF mainly provides a rich commercial java framework for developing enterprise application, though it has many other features also.

License:
The Oracle Application Server licence includes a component for a licence fee for Oracle ADF. This means that all users who have purchased an Oracle Application Server licence may use Oracle ADF for free. Users who want to deploy ADF to a third-party application-server can purchase an ADF runtime licence at their local Oracle sales office. users can develop and test Oracle ADF applications free of charge declaratively within Oracle JDeveloper.
Oracle Corporation purchased Weblogic in June 2008, and thus no longer regards it as a third-party application-server, so ADF is included in every Weblogic license

Knowledge Required: To start with ADF one must have conceptual knowledge of JAVA. If not with JAVA at least concept of Object Oriented Programming is required.

Start With ADF:To start with Oracle ADF one must download latest version of JDeveloper from Oracle Technology Network. The link is http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html. The user should choose JDeveloper with ADF here.

The latest versions of JDeveloper come with Integrated Weblogic Server also. So the application developed with Jdeveloper can be tested here also.

The ADF developer guide can be found in the Documentation Tab of above link.