Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2007

Tip: Looking for answers? Try searching our database.

FilteredRowSet size

Thread view: 
Carl  Leiby - 02 Mar 2007 17:51 GMT
Hello,

I'm working on a Swing app.  I want to show a pair of parent/child
JTables so that selection within the parent drives filtering in the
child.  It seemed to me that FilteredRowSet would be ideal for this.
So I wrote a TableModel on top of a FilteredRowSet.  I can vary the
filter and get different sets of information in the JTable.

It almost works.  The problem is in my implementation of getRowCount.
It seems that FilteredRowSet doesn't override the CachedRowSet
implementation of size() to tell me how many rows are in the filtered
subset.  calling last() and getRow() doesn't work cause I get the row
number relative to the superset of results.

The only way I see to make it work is to first() and next() till the
end and count the rows myself.  That seems insane and terribly
inefficient.  Am I wrong?  Please tell me that there's a better way.

Thanks
kuassi.mensah@gmail.com - 04 Mar 2007 19:23 GMT
Hi,

Have you tried chunking/paging the rowset? The javadoc says that
size() also returns the number of rows in the current page but maybe
this is not what you are looking for.

Kuassi http://db360.blogspot.com/2006/09/manipulating-tabular-data-using-jdbc_03.html

> Hello,
>
[quoted text clipped - 15 lines]
>
> Thanks
Carl  Leiby - 05 Mar 2007 13:59 GMT
I haven't done any paging yet.  It's a Swing app so I essentially want
the whole filtered subset.  The problem is that the JTable uses the
getRowCount function in my model to decide how many rows to draw and
in turn how to render the scrollbar nect to the table.  I'd like those
two to to accurately reflect how many rows are really available for
the propper user experience.  Short of doing an absolute(1) and next()
to count the rows there doesn't seem to be a way to tell how many rows
are in the filtered subset.  I've written this code to loop through
the records.  Since they are all already in memory it runs fairly
quickly.  I just don't like how much code that ends up executing.
Each call to next() results in a call to to my filter Predicate for
each row until the next suitable row is found.  It seems like an
immense overhead.

On Mar 4, 2:23 pm, "kuassi.men...@gmail.com" <kuassi.men...@gmail.com>
wrote:
> Hi,
>
[quoted text clipped - 23 lines]
>
> > Thanks
lipska@gmail.com - 18 Mar 2007 10:58 GMT
This has also been frustrating me. What I have discovered is that the
way the FilteredRowSet works is that once you have declared it and
applied your filter the actual filtered data has still not been
derived since working out the filtered set actually involves cycling
through all the data and applying your evaluate function defined by
your predicate. So for example lets say you ran a query and populated
your FRS and the applied a filter. I have written a basic predicate
that looks for exact matching values on columns called search

Search pred = new Search("gender",gender);
frs.populate(rs);
frs_ret.setFilter(pred);

At this point the Filter has not actually been applied so it does not
actually know how big it is. It is only applied when you call the
frs.next() function. And at this point it is only applied with one
evaluate function at a time i.e. not over the whole set

In this case it calls the evaluate function that checks to see if your
criteria applies and I assume it skips to the next one if it doesnt
apply. This is how it appears to work. So unfortunately it does look
like in order to work out the size of the filtered rowset you would
need to loop until the resultset is deemed to be finished. This
shoulnt post too much of a problem on a small resultset.

public int Size()
{
 cnt = 0;
 frs.beforeFirst();
 while (frs.next())
 {
   cnt ++;
 }
 return cnt;
 frs.beforeFirst();
}

This does seem rather inefficient but at some point the filter needs
to actually determine which rows apply and need to apply the tests
from your predicate. Perhaps there is a more elegant method. These are
my finding from running some tests on the FiltereRowSet and playing
with different predicates


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.