Implementing Query pagination using EJB and ADF

With pagination, data is queried on demand instead of all –at-once and ad-hoc. It’s a desirable feature especially when working with large data sets to query, e.g. through scrolling in a table. ADF Code Corner (http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html) sample #37 explains how to enable query pagination for ADF models that are based on a POJO data model using the JavaBean Data Control. But how do you enable pagination for Enterprise JavaBean models that use the EJB Data Control? The good news is that you don't need to do anything if you started developing your EJB model and ADF applications with Oracle JDeveloper 11g release 11.1.1.3 (PS2) or later.

If you generated the EJB session façade with one of these Oracle JDeveloper, then the following method is automatically added:

public Object queryByRange(String jpqlStmt, int firstResult,
                           int maxResults) {               
  Query query = em.createQuery(jpqlStmt);
  if (firstResult > 0) {
    query = query.setFirstResult(firstResult);
  }
  if (maxResults > 0) {
    query = query.setMaxResults(maxResults);
  }
  return new ArrayList<Employees>(); query.getResultList();
}

Note This method is also defined in the EJB local and remote interface definition.

When generating the Oracle ADF Data Control configuration for the EJB session façade by right mouse clicking on the class in the JDeveloper Application Navigator and choosing Create Data Control from the context menu, the DataControls.dcx file gets created. The DataControls.dcx file describes the EJB session façade and its interfaces for the generic Data Control class to use. One information it contains is the definition of the DataControlHandler property:

DataControlHandler="oracle.adf.model.adapter.bean.jpa.JPQLDataFilterHandler"

The DataControlHander definition, if set to JPQLDataFilterHandler, ensures that the EJB access uses pagination of the ELB interfaces and the session façade contain the queryByRange method.

For existing, pre Oracle JDeveloper 11.1.13 or non-Oracle JDeveloper created EJB session facades, you can add pagination support by adding the JPQLDataFilterHandler configuration in the DataControls.dcx file and the queryByRange method entries in the EJB interfaces and session façade after upgrading to a recent version of Oracle JDeveloper.

Comments:

Post a Comment:
Comments are closed for this entry.
About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today