dbTalk Databases Forums  

DPL and searching for entities.

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss DPL and searching for entities. in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Fabio M
 
Posts: n/a

Default DPL and searching for entities. - 05-22-2007 , 02:17 PM






Dear all,

I am experimenting with the BDB-JE DPL but I cannot understand how to
search for entities.
I will detail my problem with an example.

I have an Entity with a composite class as its primary key and *no*
secondary keys.
Basically something like that:

@Entity
public class MyEntity {
@PrimaryKey
private ID id;
...
}

@Persistent
public class ID {
@KeyField(1) private String f1;
@KeyField(2) private String f2;
@KeyField(3) private String f3;
...
}

I can browse all the entities stored in the DB by using

PrimaryIndex<ID, MyEntity> entitiesByID =
store.getPrimaryIndex(ID.class, MyEntity.class);
EntityCursor<Entity> cursor = entitiesByID.entities();
for(MyEntity e : cursor) { ...}

However I would like to do more specific queries, such as 'I want all
the entities for which f1="foo"'.
But I cannot figure out how to express this using the DPL API.

I can think of 2 workarounds:
1) Scanning all the entities looking for the good ones (ugly and slow)
2) Duplicate the f1 field in the MyEntity class and use it as a
SecondaryKey

Maybe the 2nd solution could be reasonable, but I wonder if there is a
"3rd way" that implies the usage of the already existing primary key
without modifying the classes I wrote at the beginning of the message

Thank you for your help.

Cheers,
Fabio


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.