| Author |
Message |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 07/27/2012 05:39:57
|
chrismas
journeyman
Joined: 07/27/2012 01:16:24
Messages: 27
Offline
|
Hello to all,
I plan to store a reference key to an other cache value in an object value.
I'm wondering if it is possible to check the reference key existence into an EhCache Query.
The idea :
Code:
key1 => Element{key2}
key2 => Element{...}
Element key1 refers to element k2 by a value argument.
Attribute<Integer> key = cache.getSearchAttribute("key");
query.addCriteria(new IsKeyExist(key);
It is possible to do this kind of thing with the EhCache search API ?
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 07/30/2012 13:57:52
|
teck
seraphim
Joined: 05/24/2006 15:03:25
Messages: 1103
Offline
|
I'm not sure I understand your question exactly, perhaps with some code a little more fleshed out I might get a better idea.
The easiest way to tell if a key exists in a cache is just call get()
|
Tim Eck (terracotta engineer)
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 08/01/2012 01:57:33
|
chrismas
journeyman
Joined: 07/27/2012 01:16:24
Messages: 27
Offline
|
Teck, my goal is to test the existence of a key contains in a value attribute in a search query execution.
I think is not possible. By the way, I put some code to explain my need:
I have an object A with a variable named "pointerToB". "pointerToB" is a pointer to an other value in the cache; this parameter contains the cached element key of the pointed value.
Code:
class A{
String pointerToB;
}
A a = new A();
A b = new A();
String keyOfA=...;
String keyOfB=...;
a.setPointerToB(keyOfB);
cache.put(new Element(keyOfA, a));
cache.put(new Element(keyOfB, b));
Now, I want to find all A objects that reference an existing B objet; B objects can be evicted of the cache and not existing anymore in the cache.
To do that job, ideally, I need a new search attribute method's that I named below "keyExist()".
Code:
Query query = cache.createQuery();
Attribute<String> pointerToBAttribute = cache.getSearchAttribute("pointerToB");
query.addCriteria(pointerToBAttribute.keyExist());
query.execute();
It is possible to do this thing in EhCache ?
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 08/01/2012 14:05:33
|
teck
seraphim
Joined: 05/24/2006 15:03:25
Messages: 1103
Offline
|
I think the only way to accomplish that at the moment is to select all values for the "pointerToB" attribute and execute get() calls yourself.
|
Tim Eck (terracotta engineer)
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 08/02/2012 00:33:39
|
chrismas
journeyman
Joined: 07/27/2012 01:16:24
Messages: 27
Offline
|
Thanks teck.
Now, I finally update "pointerToB" value to null on every B object deletion.
So, I check if this attribute is not null in my search expression.
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 08/03/2012 14:21:46
|
teck
seraphim
Joined: 05/24/2006 15:03:25
Messages: 1103
Offline
|
Sorry was that a question in your last post about "not-null" in your search expression?
Search in ehcache doesn't have a concept of a null value for attributes at the moment. There is no [direct] way to search for elements which have null for a given attribute. The best you can do at the moment is to use a boolean attribute for this purpose. Adding proper support for nulls is on the roadmap though
|
Tim Eck (terracotta engineer)
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 08/04/2012 03:58:20
|
chrismas
journeyman
Joined: 07/27/2012 01:16:24
Messages: 27
Offline
|
I created a custom AttributeExtractor (that returns a Boolean value) to test if this parameter is null.
|
|
|
 |
|
|