Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Bind Variable. Show all posts
Showing posts with label Bind Variable. Show all posts

Monday 20 March 2017

ADF Basics: Tip for not showing record in dependent lov


Hello All

Recently I have seen a question on OTN forum - Question on cascading LOV

It was about cascading lovs in ADF
Suppose we have 2 dependent LOVs and requirement is that 2nd lov should not show any data until first one is selected , this is very simple and common use case but for beginners it's a tedious task

So I thought to write it here to help others

Thursday 3 November 2016

Use View Criteria Query Execution Mode for In-Memory filtering of rows


Hello All

Sometimes we need to filter uncommitted records and query based bind variable or setWhereClause method doesn't do the job in that case as it requeries viewObject and filters committed records only

So for this type of requirement we can use view criteria. View criteria works on basis of it's query execution mode

By default it is set to Database only and we can change it to Memory (In-Memory filtering only) and both (DB and In-Memory filtering)
Here In-Memory filtering means rows that are not commited yet also get filtered

Saturday 1 August 2015

ADF Baiscs: Define and remove named bind variable in viewObject at runtime programmatically

This post is about creating named bind variable in viewObject at run time and filter viewObject using this bind variable in WHERE Clause of ViewObject programmatically .

Defining WHERE Clause and Bind Variable name and default value -

        //Get ViewObject
        ViewObject vo = iter.getDepartments();

        //Apply desired WHERE Clause and declare bind variable name
        vo.setWhereClause("DEPARTMENT_NAME=:BindDepartmentName");

        //Define this variable as ViewObject Bind Variable , You can also set default value for this
        vo.defineNamedWhereClauseParam("BindDepartmentName", "Purchase", null);

        // Execute ViewObject to finally apply where clause
        vo.executeQuery();




Setting value of Bind Variable-


        //Setting Value of Bind Variable
        vo.setNamedWhereClauseParam("BindDepartmentName", "Finance");
        vo.executeQuery();


Getting value of Bind Variable-


        //Get value of Bind Variable
        vo.getNamedWhereClauseParam("BindDepartmentName");


Removing WHERE Clause and Bind Variable after use-


        //Remove where clause
        vo.setWhereClause(null);
        //Remove Bind Variable
        vo.removeNamedWhereClauseParam("BindDepartmentName");
        vo.executeQuery();

Cheers :) Happy Learning

Friday 16 January 2015

Setting view object bind variable (Override bindParametersForCollection, prepareRowSetForQuery, executeQueryForCollection )

Hello All,
This post is about a very basic question- How to set bind variable of a view object ?
and there are multiple posts about it that describes multiple ways to do this
Using setNamedWhereClause
Using VariableValueManager 
Using setter method in VOImpl class

But Sometimes we can not assign bind variable value in declarative way for first time execution as value source for bind variable is fixed but it's value may change at runtime from n number of events



So for this type of requirement we can set bind variable's value in such a way so that we need not to write code everywhere to set changed value.
See how can we do this -

  • Create a Fusion Web Application and prepare model using Departments table of HR Schema




  • Open Departments viewObject add a bind variable in it's query , this bind variable is further used to set value and filter result set





  • Create Java class for Department view object, goto java tab of Departments VO and click on edit icon of Java Classes and select "Generate ViewObject Class"





  • Now we can set bind variable's value by overriding 3 methods of DepartmentVOImpl class

1. Overriding bindParametersForCollection in ViewObject java class -

This method is used to set bind variable's value by framework, framework supplies an array of all bind variable to this method We can override this method to set value of bind variable ,
Open DepartmentVOImpl class and click on override methods icon on top of editor
It will open a window that consist all methods , search by name and click on ok



See the code in DepartmentVOImpl-


    /**@override Method to set bind variable's value at runtime (Framework Internal Method)
     * @param queryCollection
     * @param object
     * @param preparedStatement
     * @throws SQLException
     */
    protected void bindParametersForCollection(QueryCollection queryCollection, Object[] object,
                                               PreparedStatement preparedStatement) throws SQLException {
        for (Object bindVar : object) {
            // Iterate over bind variable set and find specific bind variable
            if (((Object[])bindVar)[0].toString().equals("BindDeptId")) {
                // set the bind variable's  value
                ((Object[])bindVar)[1] = 100;

            }
        }
        super.bindParametersForCollection(queryCollection, object, preparedStatement);

    }

2. Overriding prepareRowSetForQuery in ViewObject java class -

This method (introduce in 11.1.1.5 release) executes before bindParametersForCollection , same thing can also be done in this method 
Override method in Impl class 


See the Code in DepartmentsVOImpl-


    /**@override Method to prepare RowSet for execution(Framework Internal Method)
     * @param viewRowSetImpl
     */
     public void prepareRowSetForQuery(ViewRowSetImpl viewRowSetImpl) {
        //Set Bind Variable's value 
        viewRowSetImpl.ensureVariableManager().setVariableValue("BindDeptId", 100);
        super.prepareRowSetForQuery(viewRowSetImpl);
    } 

3. Overriding executeQueryForCollection in ViewObject java class -


This method invokes just before framework executes rowset , avoid setting bind varibale in this method because it is not called before some methods as getEstimatedRowCount(), So whenever you try to get rowcount it will return wrong values 
still it works and sets the bind varible value and executes rowset, again override method



See the Code in DepartmentsVOImpl-


    /**Method to excute viewObject rowSet(Framework Internal Method)
     * @param object
     * @param object2
     * @param i
     */
    protected void executeQueryForCollection(Object object, Object[] object2, int i) {
        for (Object bindVar : object2) {
            // Iterate over bind variable set and find specific bind variable
            if (((Object[])bindVar)[0].toString().equals("BindDeptId")) {
                // Set the bind variable value
                ((Object[])bindVar)[1] = 100;

            }
        }
        super.executeQueryForCollection(object, object2, i);
    }

Now use anyone of these methods to set bind variable value and run application module, check result
It is showing data for DepartmentId 100.

Thanks, Happy Learning :)

Wednesday 13 August 2014

Use View Link Accessor to call aggregate functions, set attribute value , set bind variables value (Oracle ADF)


Hello All

This post is about various usage of view link accessor  , when we create viewLink between two viewObjects , destination accessor is created by default in master viewObject, there is check box to create source accessor also at same time

We can use this view link accessor for calculating attribute's sum, setting value of attributes etc



here Departments is master viewObject and Employees is it's detail, after creating viewLink you can see in viewObject xml source there accessor is present

In Departments ViewObject- 




<ViewLinkAccessor
    Name="Employees"
    ViewLink="sample.model.view.link.DeptTOEmpVL"
    Type="oracle.jbo.RowIterator"
    IsUpdateable="false"/>

In EmployeesViewObject- 
 

<ViewLinkAccessor
    Name="Departments"
    ViewLink="sample.model.view.link.DeptTOEmpVL"
    Type="oracle.jbo.Row"
    Reversed="true"
    IsUpdateable="false"/>

So what is the use of these view link accessors ?
Master accessor in detail viewObject returns current Row of master viewObject, when you generate RowImpl class for detail viewObject , it also has a method for this accessor


    /**
     * Gets the associated <code>Row</code> using master-detail link Departments.
     */
    public Row getDepartments() {
        return (Row) getAttributeInternal(DEPARTMENTS);
    }

    /**
     * Sets the master-detail link Departments between this object and <code>value</code>.
     */
    public void setDepartments(Row value) {
        setAttributeInternal(DEPARTMENTS, value);
    }

Detail accessor in master viewObject returns a row set of all row of details viewObject that are currently referenced by master record

    /**
     * Gets the associated <code>RowIterator</code> using master-detail link Employees.
     */
    public RowIterator getEmployees() {
        return (RowIterator) getAttributeInternal(EMPLOYEES);
    }

Now see what we can do with viewLink Accessor

1. Get master attribute value in detail viewObject

suppose i have to get a attribute's value from Master viewObject (Departments) in a attribute of detail viewObject (Employee)
in this example i am getting managerId from Departments ViewObject so for this just write in expression of Employee's ManagerId field
viewLinkAccesorName.AttributeName


now run BC4J tester and check - create new record in Employee and see managerId from Departments is auto populated

 on creating new record-


2. Call aggregate function to calculate sum of an attribute of detail viewObject

suppose now i have to calculate total salary of a Department (sum of Employees salary of that department)
for this purpose just call sum function to calculate sum of all rows of detail RowSet 
take a transient attribute in Departments ViewObject and write in it's expression
viewLinkAccesorName.sum("AttributeName")


 Run ApplicationModule and see-


3. Set bind variable value as per master viewObject's attribute (pass value from master viewObject)

This  is tricky part as we can not set bind variable value through expression as it doesn't recognize view link accessor name.
created a viewCriteria and bind variable for managerId in Employee viewObject




applied this criteria to Employees viewObject instance in Application Module (Just Shuttle criteria to selected side)


now to set bind variable's value we have to override prepareRowSetForQuery method in Employees VOImpl class

this method gets the value of managerId from currentRow of master ViewObject (Departments)and sets in bind variable of Employees viewObject


    @Override
    public void prepareRowSetForQuery(ViewRowSetImpl viewRowSetImpl) {
        RowSetIterator[] masterRows = viewRowSetImpl.getMasterRowSetIterators();
        if (masterRows != null && masterRows.length > 0 && masterRows[0].getCurrentRow() != null &&
            masterRows[0].getCurrentRow().getAttribute("ManagerId") != null) {
            Integer managerId = (Integer) masterRows[0].getCurrentRow().getAttribute("ManagerId");
            viewRowSetImpl.ensureVariableManager().setVariableValue("BindManagerId", managerId);
            System.out.println("ManagerID in bind Var-" + managerId);

        }
        super.prepareRowSetForQuery(viewRowSetImpl);
    }

now run AM and check it-

Happy Learning :)

Wednesday 5 March 2014

Igonre null values in viewCriteria -Jdeveloper 12c (Not a bug but a change)

Hello All,
In jdev 12c there is some change in viewCriteria design window, there is a checkbox to ignore null values in criteria , in 11g release it was enabled for all values in criteria item

but in 12c it is disabled for all values of ViewCriteria bind variable


there is two different section for creating bind variable in 12c
1. ViewCriteria Bind Variable
2. Query Bind Variable(Required)
So when you create a bind var of string type in query variables.




and use it in viewCriteria , only then this 'ignore null values' checkbox will be enabled


and when you use viewCriteria bind varibles it is disabled  but sometimes you need to change it, so can change it using ViewObject xml source

  • Select ViewCriteria and go to source
  • Now change GenerateIsNullClauseForBindVars="false"  to true

 Cheers :-)

Tuesday 17 September 2013

Bug in ADF 11g R2- Transient and Bind Valiable of Timestamp type

This is a bug in ADF 11g R2, and sometimes so much annoying for developer.

Bug Is-

  • Suppose you have created business components for Employees table of HR Schema, there is HireDate in Employees table , see it in EntityObject-

  • Now go to source and see, it is of type oracle.jbo.domain.Timestamp (default java representation of Timestamp database data type )

  • Now go to Employees ViewObject and create a transient variable for DOB(Date Of Birth)  and select it as Timestamp
  •  Now after this if developer tries to get or set value of this transient variable, it shows a exception (java.sql.Timestamp can not be cast to oracle.jbo.domain.Timestamp)



  •  To solve this error go to Employees ViewObject and select transient attribute and go to source, se it is of type java.sql.Timestamp

  • Change it to oracle.jbo.domain.Timestamp  and then run it
  • So this is a bug when developer creates new Transient or Query bind variables of Timestamp type, ADF automatically assign it java.sql.Timestamp
Always check it when using Jdveloper 11gR2

Cheers... happy debugging

Wednesday 24 July 2013

Implementing custom search form in ADF programmatically (Without using af:query)

Sometimes we need to implement custom search instead of using adf query component.
To implement custom search form , i have used a quite beautiful way to handle search and reset functionality for a View Object.
In this post i am taking Employees Table (Default HR Schema) to search and reset af:table.

  • First create a Fusion Web Application and create model (EO,VO and AM) using Employees table
  • Now suppose we have to search on 4 fields (EmployeeId, FirstName, Email, Salary) , so for this i have created a new read only ViewObject from dual
  •  This VO from dual is created to be used as Search form on page
  •  Now to make search effective on Employees VO , i have created 4 bind variable for corresponding fields in Employees ViewObject



  •  Now i have created a ViewCriteria using these 4 bind variables to re-query ViewObject  data
  •  This ViewCriteria will be executed each time when value of bind variable is changed, now this is the time to set value of bind variables, so i have dragged dual vo as a form on page, and added 2 button for Search and Reset
  •  To View Search Result , Employees Table is there on page
  •  Now to get value from Form Field to bean , i have created binding for all 4 fields in bean
  •  Now i have created ActionListener for Search button- in this code i have get value from page using component bindings and passed in Employees ViewObject's bind variable in order to execute viewCriteria.

  •     public void searchButton(ActionEvent actionEvent) {
            searchAMImpl am = (searchAMImpl)resolvElDC("searchAMDataControl");
            ViewObject empVo = am.getEmployees1();
            empVo.setNamedWhereClauseParam("EmpIdBind", empIdPgBind.getValue());
            empVo.setNamedWhereClauseParam("FirstNmBind", firstNmPgBind.getValue());
            empVo.setNamedWhereClauseParam("EmailBind", emailPgBind.getValue());
            empVo.setNamedWhereClauseParam("SalaryBind", salaryPgBind.getValue());
            empVo.executeQuery();
        }
    

  • Once value is set in bind variable , view criteria is executed and Search result will be shown in resultant table- Run your application and see
  • To reset values in table and search form, see the managed bean code of Reset button

  •     public void resetButton(ActionEvent actionEvent) {
            searchAMImpl am = (searchAMImpl)resolvElDC("searchAMDataControl");
            ViewObject empVo = am.getEmployees1();
            ViewObject attrVo=am.getattr1();
            empVo.setNamedWhereClauseParam("EmpIdBind", null);
            empVo.setNamedWhereClauseParam("FirstNmBind", null);
            empVo.setNamedWhereClauseParam("EmailBind", null);
            empVo.setNamedWhereClauseParam("SalaryBind", null);
            empVo.executeQuery();
            attrVo.executeQuery();
          
        }
    

  • Click on reset button and page value are set to default

  • This is how we can implement custom search using ADF components, you can apply validations, auto suggest feature etc while using this custom search
          Cheers :-)  Download Sample App