Exforsys

Home arrow Reviews arrow Oracle Coherence

Oracle Coherence: Implementing LookupValuesAggregator

Author: Packt Publishing     Published on: 10th Jul 2010

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.

Ads

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.


Sample Code
  1.    public class LookupValuesAggregator
  2.                 extends AbstractAggregator {
  3.  
  4.        private transient List<lookupvalue></lookupvalue> results
  5.  
  6.        public LookupValuesAggregator(ValueExtractor idExtractor,
  7.                                      ValueExtractor descriptionExtractor){
  8.  
  9.  
  10.             super(new LookupValueExtractor(idExtractor,
  11.                                            descriptionExtractor))
  12.         }
  13.  
  14.         protected void init(boolean isFinal) {
  15.           results = new ArrayList<lookupvalue></lookupvalue>()
  16.         }
  17.  
  18.         protected void process(Object value, boolean isFinal) {
  19.           if (isFinal) {
  20.             results.addAll((Collection<lookupvalue></lookupvalue>) value)
  21.           }
  22.           else {
  23.             results.add((LookupValue) value)
  24.           }
  25.         }
  26.  
  27.         protected Object finalizeResult(boolean isFinal) {
  28.            return results
  29.         }
  30.     }
  31.  
Copyright exforsys.com



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.

Ads

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.

 
This tutorial is part of a Oracle Coherence tutorial series. Read it from the beginning and learn yourself.

Oracle Coherence

 

Comments