Using Groovy Aggregate Functions in ADF BC

This article explains how groovy aggregate functions(sum, count, min, max and avg) can be used in ADF Business components and demonstrates how these can be used at entity and view level

Let's consider EMP and DEPT tables and an usecase to track number of employees in each department

 

AGGREGATE_COUNT_FN_RT_NEW.png

Entity-Level

To use aggregate functions at entity level, we need to have association between entities representing master and child relationship and the destination accessor name is what we are going to use in our groovy

Syntax: <Accessor>.count(Groovyexpression)

- Note down the destination accessor name(EMP) in the association or AccessorAttribute name in source entity

DEPT_EMP_ASSOC_NEW.PNG

- Add a transient attribute in source entity with persistent property set to false and provide the groovy expression in the syntax provided above

ENTITY_TRANS_ATTR.PNG

- Finally, Add newly added attribute to view object

View-Level

To use aggregate functions at view level, we need to have a view link between viewobjects representing master and child relationship and the destination accessor name is what we are going to use in our groovy

Syntax: <ViewLinkAccessor>.count(Groovyexpression)

- Note down the destination accessor name(EmpView) in the view link or viewLinkAccessor name in source view

DEPT_EMP_VIEW_LINK.png
- Add a transient attribute in view object and provide a groovy aggregate function count as a value to it in the syntax provided above

VIEW_TRANS_ATTR_NEW.png

Now, If you run application module tester and execute DeptView / ViewLink, you should see employee count in EmpCount field 

In similar way, one can use other groovy aggregate functions sum, avg, min and max.

Comments:

I tried the same way to find count on my tables. I have three tables
LookupType
LookupCode
Book

So i tried to count number of books under each code value using the groovy statement BookVO.count("BookId")

I got an error. (oracle.jbo.expr.JIEvalException) JBO-25077: Name BookVO not found in the given object: ViewRow [oracle.jbo.Key[9 1 ]] when i ran the appmodule.

Posted by guest on December 20, 2011 at 05:53 AM IST #

Hi,

You seem to be having either no view link between LookupCodeVO and BookVO or no
Destination ViewAccessor generated in the view link.

To check this, open your LookupCodeVO in source view and check for
ViewLinkAccessor tag with Name property pointing to BookVO, if it is not
present, create/open the ViewLink, goto Relationship tab, edit Accessors and
check the first checkbox(In View Object: LookupCodeVO) under Destination
Accessor and then try running app module.

Hope this helps

Sireesha

Posted by Sireesha on December 21, 2011 at 04:17 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips and Tricks from Oracle's JDeveloper & ADF QA

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