Reviews
Oracle CoherenceOracle Coherence: Querying The Data Grid
So far, you have learned how to access data in the Coherence cache using identity-based operations, such as get and put. In many cases this will be exactly what you need, but there will also be many other situations where you either won't know an object's identity or you will simply need to look up one or more objects based on attributes other than the identity.
Coherence allows you to do that by specifying a filter for set-based operations defined by the QueryMap interface, which we mentioned briefly in Chapter 3, Planning Your Caches.
- public interface QueryMap extends Map {
- Set keySet(Filter filter)
- Set entrySet(Filter filter)
- Set entrySet(Filter filter, Comparator comparator)
- ...
- }
As you can see from the previous interface definition, all three methods accept a filter as the first argument, which is an instance of a class implementing a very simple com.tangosol.util.Filter interface:
- public interface Filter {
- boolean evaluate(Object o)
- }
Basically, the Filter interface defines a single method, evaluate, which takes an object to evaluate as an argument and returns true if the specified object satisfies the criteria defined by the filter, or false if it doesn't.
This mechanism is very flexible, as it allows you to filter your cached objects any way you want. For example, it would be quite simple to implement a filter that can be used to retrieve all the account transactions in a specific period:
- public class TransactionFilter implements Filter {
- private Long m_accountId
- private Date m_from
- private Date m_to
- public TransactionFilter(Long accountId, Date from, Date to) {
- m_accountId = accountId
- m_from = from
- m_to = to
- }
- public boolean evaluate(Object o) {
- Transaction tx = (Transaction) o
- return tx.getId().getAccountId().equals(m_accountId)
- && tx.getTime().compareTo(from) >= 0
- && tx.getTime().compareTo(to) <= 0
- }
- }
While the previous sample filter implementation is perfectly valid and will return correct results if executed against the transactions cache, it would be very cumbersome if you had to define every single query criterion in the application by implementing a custom filter class as we did previously.
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







