|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tangosol.util.Base
com.tangosol.util.filter.KeyAssociatedFilter
public class KeyAssociatedFilter
Filter which limits the scope of another filter according to the key association information.
This filter is intended to be used to optimize queries for partitioned
caches that utilize any of the key association algorithms (by implementing
either KeyAssociator
or
KeyAssociation
) to ensure placement of
all associated entries in the same distributed cache partition (and
therefore in the same storage-enabled cluster node). Using the
KeyAssociatedFilter will instruct the distributed cache to apply the
wrapped filter only to the entries stored at the cache service node that
owns the specified host key.
Note 1: This filter must be the outermost filter and cannot be used as a part of any composite filter (AndFilter, OrFilter, etc.)
Note 2: This filter is intended to be processed only on the client side of the partitioned cache service, so it intentionally does not implement the Serializable and PortableObject interfaces.
For example, consider two classes called Parent and Child that are stored in separate caches using ParentKey and ChildKey objects respectively. The Parent and Child classes have a getId method that returns a Long value that uniquely identifies the object. Similarly, the ParentKey and ChildKey classes have a getId method that uniquely identifies the corresponding cached object. Futhermore, the Child and ChildKey classes include a getParentId method that returns the Long identifier of the Parent object.
There are two ways to ensure that Child objects are collocated with their Parent objects (in the same storage-enabled cluster node).
KeyAssociation
as follows:
public Object getAssociatedKey() { return getParentId(); }and the ParentKey class implement
KeyAssociation
as follows:
public Object getAssociatedKey() { return getId(); }
KeyAssociator
as follows:
public Object getAssociatedKey(Object oKey) { if (oKey instanceof ChildKey) { return ((ChildKey) oKey).getParentId(); } else if (oKey instanceof ParentKey) { return ((ParentKey) oKey).getId(); } else { return null; } }
Now, to retrieve all the Child objects of a given Parent using an optimized query you would do the following:
ParentKey parentKey = new ParentKey(...); Long parentId = parentKey.getId(); // this Filter will be applied to all Child objects in order to fetch those // for which getParentId() returns the specified Parent identifier Filter filterEq = new EqualsFilter("getParentId", parentId); // this Filter will direct the query to the cluster node that currently // owns the Parent object with the given identifier Filter filterAsc = new KeyAssociatedFilter(filterEq, parentId); // run the optimized query to get the ChildKey objects Set setChildKeys = cacheChildren.keySet(filterAsc); // get all the Child objects at once Set setChildren = cacheChildren.getAll(setChildKeys);To remove the Child objects you would then do the following:
cacheChildren.keySet().removeAll(setChildKeys);
Constructor Summary | |
---|---|
KeyAssociatedFilter(Filter filter,
Object oHostKey)
Construct a key associated filter. |
Method Summary | |
---|---|
boolean |
equals(Object o)
Compare the KeyAssociatedFilter with another object to determine equality. |
boolean |
evaluate(Object o)
Apply the test to the object. |
Filter |
getFilter()
Obtain the wrapped Filter. |
Object |
getHostKey()
Obtain the host key that serves as an associated key for all keys that the wrapped filter will be applied to. |
int |
hashCode()
Determine a hash value for the KeyAssociatedFilter object according to the general Object.hashCode() contract. |
String |
toString()
Return a human-readable description for this Filter. |
Constructor Detail |
---|
public KeyAssociatedFilter(Filter filter, Object oHostKey)
filter
- the underlying (wrapped) filteroHostKey
- the host key that serves as an associated key for all
keys that the wrapped filter will be applied toMethod Detail |
---|
public boolean evaluate(Object o)
evaluate
in interface Filter
public Filter getFilter()
public Object getHostKey()
public boolean equals(Object o)
public int hashCode()
Object.hashCode()
contract.
public String toString()
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |