[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
"Is key exist" Query criteria  XML
Forum Index -> Ehcache
Author Message
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 ?
teck

seraphim
[Avatar]
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)
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 ?
teck

seraphim
[Avatar]
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)
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.
teck

seraphim
[Avatar]
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)
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.
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team