Java Reference
In-Depth Information
Java 7 Recipes - BEATY
Java 7 Recipes - DEA
Java 7 Recipes - GUIME
Java 7 Recipes - OCONNER
Java EE 7 Recipes - JUNEAU
Java FX 2.0 - Introduction by Example - DEA
Adding author filter:
Java 7 Recipes - JUNEAU
Java 7 Recipes - DEA
Java EE 7 Recipes - JUNEAU
Java FX 2.0 - Introduction by Example - DEA
How It Works
Often, the results that are returned from a database query contain a large number of
rows. As you probably know, too many rows can create issues when it comes to visu-
ally working with data. It usually helps to limit the number of rows that are returned
from a query by using a WHERE clause on a SQL statement so that only relevant data is
returned. However, if an application retrieves data into an in-memory RowSet and
then needs to filter the data by various criteria without additional database requests, an
approach other than a query needs to be used. A FilteredRowSet can be used to
filter data that is displayed within a populated RowSet so that it can be more manage-
able to work with.
There are two parts to working with a FilteredRowSet . First, a filter needs to
be created which will be used to specify how the data should be filtered. The filter class
should implement the Predicate interface. There may be multiple constructors,
each accepting a different set of arguments, and the filter may contain multiple eval-
uate() methods that each accept different arguments and contain different imple-
mentations. The constructors should accept an array of contents that can be used to fil-
ter the RowSet . They should also accept a second argument, either the column name
that the filter should be used against or the position of the column that the filter should
be used against. In the solution to this recipe, the filter class is named AuthorFil-
ter , and it is used to filter data per an array of author names. Its constructors each ac-
cept an array containing the author names to filter, along with either the column name
or position. Each of the evaluate() methods has the task of determining whether a
given row of data matches the specified filter; in this case, the author names that have
been passed in via an array. The first evaluate() method is called if a column name
Search WWH ::




Custom Search