ADF Business Components: How to Apply Where Clause to New Rows

If you have multiple ADF BC View Objects that are defined on the same Entity Object, and one of the View Objects has a where clause defined in the SQL query, then this article might be interesting for you.

Problem: View Object A shows a limited set of the available rows in the database table. View Object B is used to insert a new row into the same database table. The new row appears in the set of View Object A, even if the criteria applied to limit the rows in A do not apply to the new row!
By the way, this problem only occurs if ViewLink Consistency applies. For more details, see the article Consciously Choosing to Use the New ViewLink Consistent Behavior in 9.0.3.3 by Steve Muench.

Example Problem: Suppose you have an Entity Object 'Emp' based on the SCOTT.EMP table. Now suppose you have 2 View Objects: EmpWithCommission and EmpWithoutCommission. They are both based on the same Entity Object 'Emp', but use different where clauses. EmpWithoutCommission queries 'where comm = 0 or comm IS NULL' and EmpWithCommission queries 'where comm > 0'.

You can use the ADF BC Tester (right-click the Application Module and choose Test) to query the rows in EmpWithoutCommission. Now insert a new row in EmpWithCommission, and give the new Emp a Commission. If you go back to EmpWithoutCommission, you will also see the new Emp row that does have a Commission!

Solution: Use oracle.jbo.RowMatch (JDeveloper 10.1.3) or oracle.jbo.server.RowQualifier (earlier JDeveloper versions) to apply a condition to the new rows.
They can be used to apply in-memory filtering of the View Object rows. You express the condition in terms of VO attribute names, which means that you can also use transient attributes. On the other hand, you cannot use all the same constructs as in SQL. You can use bind variables. See the Javadoc of RowMatch in JDeveloper 10.1.3 for more information.
Set a RowMatch or RowQualifier on the ViewObjectImpl in the constructor of the View Object Class, similar to the where clause of the query.

Example Solution: In the constructor of EmpWithCommissionImpl, call setRowMatch(new RowMatch("Comm > 0")); and in the constructor of EmpWithoutCommissionImpl, call setRowMatch(new RowMatch("Comm = 0"));
For JDeveloper 10.1.2 or earlier, use setRowQualifier(new RowQualifier("<expression>"));

References: The article Using the RowQualifies() Method to Fine Tune View Link Consistency Behavior" by Steve Muench explains another way to influence if new rows are added to a View Object or not. It does not apply to this particular problem, but it might help you with other related problems.

Written by Sandra Muller, last updated on May 12, 2006

Powered by
Movable Type and Oracle