Thursday Jun 30, 2011

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.

Friday May 20, 2011

How to call a method defined in AppmoduleImpl using groovy expression?

Usecase Description:

Suppose we have a Transient attribute that stores the value returned by an Appmodule method,then the easy way to call this method in transient attribute would be using Groovy expression.

Consider a simple method in AppmoduleImpl java class that returns the Department name of the selected row of Emp table:

 public String getDeptName(Number dno)

    {
        if (dno == null)
            return null;
        else {
            ViewObject vo = findViewObject("DeptView1");

            try {
                Row row =
                    vo.findByKey(new Key(new Object[] { new oracle.jbo.domain.Number(dno) }),
                                 1)[0];

                if (row != null) {
                    Object name = row.getAttribute("Dname");
                    if (name != null)
                        return name.toString();
                    else
                        return null;
                } else
                    return "Specified dept does not exists";
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }

        }
    }
Create an Updatable Transient attribute in EmpView Object.Edit its value & provide a groovy expression "adf.object.applicationModule.getDeptName(Deptno)" to call the above method

Run the AppModule & note that the transient attribute returns the Department name corresponding to the selected row of Emp table.


How to call a method defined in ViewObjectImpl using groovy expression?

Usecase Description:

We can define a transient attribute that calls  ViewObjectImpl.java method using Groovy expression.

Consider a simple method in EmpViewImpl java class that returns the currentRowIndex:

 

  public Number returnCurrentRowIndex()
   {
    return this.getCurrentRowIndex();
   }


Create an Updatable Transient attribute in EmpView Object.Edit its value
& provide a groovy expression "adf.object.viewObject.returnCurrentRowIndex()
" to call the above method

Run the AppModule & note that the transient attribute returns the currentRowIndex of the selected row of Emp table.

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