! ADF #694 - Redstone Content Solutions

translatoryazooInternet and Web Development

Nov 12, 2013 (3 years and 6 months ago)

70 views

Insert track name here
1 Session #694
D
D
O
O
N
N


T
T


L
L
E
E
T
T


D
D
A
A
T
T
A
A


P
P
U
U
S
S
H
H


Y
Y
O
O
U
U


A
A
R
R
O
O
U
U
N
N
D
D
!
!




























































































A
A
N
N


I
I
N
N
T
T
R
R
O
O
D
D
U
U
C
C
T
T
I
I
O
O
N
N


T
T
O
O


A
A
D
D
F
F


A
A
C
C
T
T
I
I
V
V
E
E


D
D
A
A
T
T
A
A


















































































S
S
E
E
S
S
S
S
I
I
O
O
N
N


#
#
6
6
9
9
4
4


Adam Stortz, Redstone Content Solutions
ABSTRACT
Learn how to raise events in the model tier and have those changes shown to the user without the user doing anything. This
paper will discuss the tools required to accomplish this feat and walk through the steps required to implement it. A working
prototype will be produced as a result of working through this document


TARGET AUDIENCE
This white paper is targeted at advanced Oracle Application Development Framework (ADF) Developers.

EXECUTIVE SUMMARY
This White Paper will describe the different approaches for using Oracle ADF Active Data and will focus on implementing
only one of a number of possible approaches for using Active Data. Learner will be able to:

· Identify the different approaches to ADF Active Data and articulate the differences
· Describe the steps to implement the ADF Active Data Proxy
· Have a working sample of ADF Active Data Proxy

BACKGROUND
Real-time visibility is essential in some situations, like shipment tracking, system availability, and Business Intelligence (BI)
dashboards. In most of today’s situations this requires one of two things:

1. The user has to refresh their browser repeatedly, or
2. The application has to constantly poll the server for updates

A push-based approach can greatly improve the usability and efficiency of an application.

Architectures around the world use polling every day. This technique did not come about due to their efficiency. It does not
matter if you are maintaining a popular endpoint (Twitter or Facebook) or trying to get near real-time news from your favorite
site like CNN or MSNBC through RSS, neither side benefits from this architecture. Over the years customers and consultants
have built a number of crutches in the form of Cache headers, ETags and various accelerators.

In the end, none of these solutions have fundamentally solved the problem. The end-client remains 'dumb' with the primary
burden remaining on the server. That is where PUSH architectures come in.
Insert track name here
2 Session #694

PUSH and PULL are architectures. They are not technologies. Meaning, PULL is not the fault of Microsoft .NET or Oracle
ADF. PUSH is not a savior offered from one of these companies. PUSH is a different architecture that is then implemented
by your technology of choice.

PUSH architectures, are nothing more than a means to push information to the end-device without the end-device having to
maintain a persistent connection with the server. This lowers the bandwidth and resources of the solution. Applications
residing on the server have some awareness of end-points and a methodology of delivering data and/or messages out to those
end-devices.

Oracle ADF Active Data is a PUSH architecture.

TECHNICAL DISCUSSIONS AND EXAMPLES
Oracle ADF has a technology called the Active Data Service to solve this problem in a push-based approach. This can be
implemented in a variety of ways that fall into one of two groups:

· BAM with SOA Suite
· Active Data Proxy

The approach using Business Activity Monitoring (BAM) and the Service Oriented Architecture (SOA) Suite can be
significantly more complex. However, this approach offers the most flexibility and is the most Enterprise capable.

For smaller solutions the Active Data Proxy is a much simpler while still retaining enough of the same benefits to perhaps
help you get by for now. This paper works with this approach to allow you avoiding the setup and complexity of BAM and
SOA Suite to simply explore what this architecture can offer you.

ACTIVE DATA PROXY IMPLEMENTATION
The sample implementation provided in this White Paper makes use of the sample HR Schema that is shipped with all
editions of Oracle Database (Express Edition, Standard Edition and Enterprise Edition.

NOTE: You may need to unlock the user in the database to make use of the HR Schema.

This implementation has 2 simple pages:

1. Departments.jsf – this has a read-only table of the departments.
2. EditDepartment.jsf – is a simple edit form with a submit button and navigational (First, Last, Next, Previous)
buttons.




Extend the ActiveCollectionModelDecorator to implement the Active Data contract:
Insert track name here
3 Session #694
public class DeptModel extends ActiveCollectionModelDecorator {
public DeptModel() {
super();
}

@Override
public ActiveDataModel getActiveDataModel() {
return _activeDataModel;
}

// Handles raising an event on the Active Data Model
public void triggerDataChange(MyActiveDataModel l, Key key, String newName) throws
Exception {
l.bumpChangeCount();
ActiveDataUpdateEvent event = ActiveDataEventUtil.buildActiveDataUpdateEvent(

ActiveDataEntry.ChangeType.UPDATE, l.getCurrentChangeCount()

JboActiveDataEventUtil.convertJboKeyToKeyPath(key),
null, new String[] { "DepartmentName" },
new Object[] { newName });
l.dataChanged(event);
}

private MyActiveDataModel _activeDataModel = new MyActiveDataModel();

private CollectionModel _model = null;

// Get the collection model from the bindings
@Override
public CollectionModel getCollectionModel() {
if (_model == null) {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext el = fc.getELContext();

// This is EL to avoid typecasting to an Internal class.
ValueExpression ve = elFactory.createValueExpression(el,
"#{bindings.DepartmentsView1.collectionModel}", Object.class);

// Now GET the collectionModel
_model = (CollectionModel)ve.getValue(el);
}
return _model;
}
}

Insert track name here
4 Session #694

Extend BaseActiveDataModel to be referenced by the proxy:
public class MyActiveDataModel extends BaseActiveDataModel {
protected void startActiveData(Collection<Object> rowKeys, int startChangeCount) {
_listenerCount.incrementAndGet();
}

protected void stopActiveData(Collection<Object> rowKeys) {
_listenerCount.decrementAndGet();
if (_listenerCount.get() == 0) {
System.out.println("tear down");
}
}

public int getCurrentChangeCount() {
return _currEventId.get();
}

public void bumpChangeCount() {
_currEventId.incrementAndGet();
}

public void dataChanged(ActiveDataUpdateEvent event) {
fireActiveDataUpdate(event);
}

private final AtomicInteger _listenerCount = new AtomicInteger(0);
private final AtomicInteger _currEventId = new AtomicInteger();
}


Add the following as a handler for the Edit Department page Submit button:
public void handleSubmit(ActionEvent actionEvent) {
try {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext el = fc.getELContext();
ValueExpression ve =
elFactory.createValueExpression(el, "#{departmentModel}",
DeptModel.class);
DeptModel model = (DeptModel)ve.getValue(el);
DCBindingContainer bc =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
Insert track name here
5 Session #694
DCIteratorBinding iterator =
bc.findIteratorBinding("DepartmentsView1Iterator");
Row r = iterator.getCurrentRow();
String newName = (String)r.getAttribute("DepartmentName");
model.triggerDataChange(model._activeDataModel, r.getKey(), newName);
} catch (Exception e) {
e.printStackTrace();
}
}

This will get the current row and pull the department name and fire an event with the updated data.

Now update the table in Departments.jsf to point to a new Application scoped managed bean of type DeptModel. This will
allow it to use the new Active Data Proxy instead of directly using the bound iterator.
Insert track name here
6 Session #694
REFERENCES
Oracle Documentation:
http://docs.oracle.com/cd/E23943_01/web.1111/b31974/adv_ads.htm


Matthias Wessendorf:
http://matthiaswessendorf.wordpress.com/2009/12/05/adf-faces-and-server-side-push/


Edwin Biemond:
http://biemond.blogspot.com/2009/12/adf-data-push-with-active-data-service.html


ADF Code Corner (Frank Nimphius):
http://www.oracle.com/technetwork/developer-tools/jdev/learnmore/65-activedataservicestwittersample-191314.pdf


Build a Google Talk Client Using Oracle ADF Faces Rich Client and the Active Data Service
http://www.oracle.com/technetwork/articles/jellema-googletalk-094343.html


Building a Real Time Twitter Client with Oracle ADF
https://blogs.oracle.com/adffun/entry/building_a_real_time_twitter_client_with_adf