Reviews
Oracle CoherenceOracle Coherence: Obtaining Query Results
The easiest way to obtain query results is to invoke one of the QueryMap.entrySet methods:
- Filter filter = ...
- Set<map.entry></map.entry> results = cache.entrySet(filter)
This will return a set of Map.Entry instances representing both the key and the value of a cache entry, which is likely not what you want. More often than not you need only values, so you will need to iterate over the results and extract the value from each Map.Entry instance:
- List values = new ArrayList(results.size())
- for (Map.Entry entry : entries) {
- values.add(entry.getValue())
- }
After doing this a couple times you will probably want to create a utility method for this task. Because all the queries should be encapsulated within various repository implementations, we can simply add the following utility methods to our AbstractCoherenceRepository class:
- public abstract class AbstractCoherenceRepository> {
- ...
- protected Collection<v></v> queryForValues(Filter filter) {
- Set> entries = getCache().entrySet(filter)
- return extractValues(entries)
- }
- protected Collection<v></v> queryForValues(Filter filter,
- Comparator comparator) {
- Set> entries =
- getCache().entrySet(filter, comparator)
- return extractValues(entries)
- }
- private Collection<v></v> extractValues(Set> entries) {
- List<v></v> values = new ArrayList<v></v>(entries.size())
- for (Map.Entry entry : entries) {
- values.add(entry.getValue())
- }
- return values
- }
What happened to the QueryMap.values() method?
Obviously, things would be a bit simpler if the QueryMap interface also had an overloaded version of the values method that accepts a filter and optionally comparator as arguments. I'm not sure why this functionality is missing from the API, but I hope it will be added in one of the future releases. In the meantime, a simple utility method is all it takes to provide the missing functionality, so I am not going to complain too much.
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







