Reviews
Oracle CoherenceOracle Coherence: Implementing LookupValuesAggregator
Earlier in the chapter, we started the implementation of a generic solution that will allow us to extract lookup values that are suitable for data binding to UI controls such as drop-downs and list boxes. So far, we have implemented a LookupValueExtractor, which allows us to extract a LookupValue instance from any object, in any cache.
In this section we will complete the exercise by implementing a LookupValuesAggregator--a simple aggregator that can be used to aggregate extracted lookup values into a list.
- public class LookupValuesAggregator
- extends AbstractAggregator {
- private transient List<lookupvalue></lookupvalue> results
- public LookupValuesAggregator(ValueExtractor idExtractor,
- ValueExtractor descriptionExtractor){
- super(new LookupValueExtractor(idExtractor,
- descriptionExtractor))
- }
- protected void init(boolean isFinal) {
- results = new ArrayList<lookupvalue></lookupvalue>()
- }
- protected void process(Object value, boolean isFinal) {
- if (isFinal) {
- results.addAll((Collection<lookupvalue></lookupvalue>) value)
- }
- else {
- results.add((LookupValue) value)
- }
- }
- protected Object finalizeResult(boolean isFinal) {
- return results
- }
- }
As you can see, both init and finalizeResult methods are trivial--the first one simply initializes the results list, while the second one returns it. This works both for the main and parallel aggregators, so we can ignore the isFinal flag.
The process method, however, uses the isFinal flag to determine if it should add a single LookupValue instance or the list of LookupValues returned by the parallel aggregator to the results collection.
Summary
In this chapter, you have learned how to query Coherence caches and how to perform aggregations on the data within the cache. We have covered built-in filters and aggregators and learned how to build custom ones.
We also talked about indexes and the impact they have on query performance. I cannot stress enough how important indexes are--make sure that you always use them and you will avoid a lot of potential performance problems.
In the next chapter, we will look at the remaining methods defined by the InvocableMap and learn one of the most important Coherence features from the scalability and performance perspective--a feature that allows us to process data in place and in parallel across the cluster.
Oracle Coherence
- Oracle Coherence 3.5
- Oracle Coherence: Distributed Caching
- Oracle Coherence: In-place and Parallel Processing
- Oracle Coherence: Coherence within the Oracle Ecosystem
- Oracle Coherence: Querying The Data Grid
- Oracle Coherence: Built-in Filters
- Oracle Coherence: Value and Reflection Extractor
- Oracle Coherence: Other built-in value extractors
- Oracle Coherence: Implementing Custom Value Extractor
- Oracle Coherence: Simplifying Coherence Queries
- Oracle Coherence: Obtaining Query Results
- Oracle Coherence: Controlling Query Scope Using Data Affinity
- Oracle Coherence: Querying Near Cache
- Oracle Coherence: Paging Over Query Results
- Oracle Coherence: Anatomy of an Index
- Oracle Coherence: Creating Indexes
- Oracle Coherence: Query Limitations
- Oracle Coherence: Aggregators
- Oracle Coherence: Built-in Aggregators
- Oracle Coherence: Implementing LookupValuesAggregator







