Updated: 5/27/03; 2:08:54 PM.
BC4J Helper by Sung Im
Thoughts on how BC4J works, code samples, and other helpful techniques
        

Tuesday, May 27, 2003

This little write-up talks about QueryCollection, RowSet, and ViewObject (in a QA fashion):

Question:  What is the role of the QueryCollection class (oracle.jbo.server.QueryCollection)?  Is there any connection between this class and the RowSet?  When are they constructed and for what purpose?

Answer:  QC (QuyerCollection) is the real collection that holds view rows.  RowSet is a front-man (API) object.  Multiple RowSet's may share (point to) the same QC.  Each QC has an object called, row filter, with it.  The row filter decides the rows that the QC will hold.  For example, if you have Dept Emp master detail VOs, the Emp VOs may have 0 or more QCs.  Assuming that the master-detail link is on the Deptno, the row filter in this case will contain the Deptno of the qualifying Emp rows.  You will have a QC for Deptno 10, a QC for Deptno 20, etc.

The ViewObject holds a HashMap of QCs keyed by this row filter.  This facilitates the sharing of the QC by the row filter.  In contrast, when you have view link accessors, RowSet's returned by accessors are not shared.  When the user calls a viewlink accessor, a new RowSet is returned.  Many RowSet's may point to the same QC.

Let's take a look at a different example to illustrate this point.  Suppose we have Dept and Emp.  But this time, the link is on the Loc attribute.  When you call the view link accessor on a Dept row, it returns Emp's that work at that location.  The row filter holds the Loc attr value.

Suppose further that Dept 10 and Dept 50 have the same location.  When you call the view link accessor for Dept 10, it returns a new RowSet with a new QC.  When you later call the view link accessor for Dept 50, it returns a different RowSet that points to the same QC:  2 RowSet's and one QC.

QC sharing saves resources and database hits.

It's important to understand that the situation works differently when you have data model view link.  (The above discussion was more for the row level master detail.  Now, I'm discussing data model master detail.  For a discussion of the Data Model ViewLink vs. Row Level ViewLink, take a look at:  http://radio.weblogs.com/0123729/2003/05/07.html.)

When you have a DM master detail, you have one RowSet (behind the detail VO).  As you traverse through the master VO, the change of currency causes an event to fire.  This event causes the detail RowSet to refresh
its collection with the new view link attribute values.  During this process, we look into the aforementioned HashMap.  If the QC with the matching row filter is found, the QC slides in to replace the old QC.  If not, a new QC is created and executeQuery'ed (and registered into the HashMap).

Thus, in the DM MD case, you have one RowSet's with switching QCs.

Question:  Can a ViewObject hold more than 1 RowSets at one time?  Can all of them be used at the same time?

Most certainly.  In the row level MD case, each view link accessor call will return a new RowSet (from the same VO).

No restriction on how multiple RowSet's can be used from BC4J's perspective.

Question:  How is it decided that the time has come to build a NEW RowSet?

In the row level MD case, the view link accessor call will create a new RowSet.

You can create a secondary RowSet manually by calling the following oracle.jbo.ViewObject API:

   public RowSet createRowSet(String name);

When you have multiple RowSet's on a VO, they all share the VO ==> They share the JDBC statement, where-clause, etc.  However, each RowSet could have its own where-clause parameters.  Hence, you could have a RS whose param value is 10 and another one (using the same query stmt) whose param value is 20.

 


2:08:42 PM    comment []



© Copyright 2003 Sung Im.
 
May 2003
Sun Mon Tue Wed Thu Fri Sat
        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 31
Apr   Jun


Click here to visit the Radio UserLand website.

Subscribe to "BC4J Helper by Sung Im" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.