Imagine that you have two view objects AllDepartments and DepartmentsLessThan. Furthermore, assume that your DepartmentsLessThan view object has a WHERE clause of:
deptno < :0
If at runtime you programmatically set the zero-th WHERE clause param on your instance of DepartmentsLessThan to a value like 3...
myDeptsLessThan.setWhereClauseParam(0, new Number(3));
then of course, if you re-execute the query you will only retrieve departments whose Deptno attribute value is less than 3.
The reason that you would turn on the view link consistency flag for a view object instance is that you want NEW rows created through any other (in this case) Dept-entity-based view object to automatically show up in rowsets based on that view link consistent view object instance. In this case, if we call setAssociationConsistent(true) on the myDeptsLessThan VO instance, it would mean that a Dept-entity-based row inserted into a rowset based on the Departments view object would automatically show up in any rowsets based on the DepartmentsLessThan view object, too.
If you insert a department with Deptno 4 into the Departments view, since you've set the bind variable on DepartmentsLessThan to the value of 3, you might reasonably expect that this new department row would NOT show up in this restricted view, since a Deptno value of 4 is not less than 3. However, in practice you need to understand that BC4J does not have an in-memory SQL predicate evaluation engine running to try and duplicate the filtering prowess of the database. So, to achieve this desired behavior, we need a little help from you, the programmer.
We provide you with the ViewObjectImpl method:
protected boolean rowQualifies(ViewRowImpl vr)
Which you can override to give us the additional application-specific knowledge that we need to properly filter in Java in the same logical way that your (potentially very complicated!) SQL WHERE clause implements.
/** * Return false for new rows that are candidates to be added * to a rowset based on this view object if their Deptno value * is not less than the current value of the bind variable * from this view object's WHERE clause of: * * WHERE deptno < :0 * * Assume that rows that are not status NEW qualify since they will * have been queried from the database. */ protected boolean rowQualifies(ViewRowImpl vr) { if (vr.getEntity(0).getPostState() == Entity.STATUS_NEW) { Number bindVar = (Number)vr.getQueryCollection(null).getRowFilter().getParamValues()[0]; Number deptNo = (Number)vr.getAttribute("Deptno"); return deptNo != null && deptNo.compareTo(bindVar) < 0; } else { return true; } }
This way, your view object with view link consistency on will not inadvertently have added to it rows that don't qualify for its where clause.
2:35:43 PM
|