dbTalk Databases Forums  

Filter object

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


Discuss Filter object in the comp.databases.berkeley-db forum.



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

Default Filter object - 05-30-2006 , 05:33 PM






Peoples,

I'm trying to retrive objects that I put in JE BD using any filter to
do it, I'm using DataAccessor to get the objects from DB, but I'm can
retrive using any filter, how can I do it?

EntityCursor items = da.peopleByName.entities();

"da" is an instance of DataAcessor.

I can retrieve all objects that exists in db but I want only the
objects that que name init with "James" (for example), and the
DataAccessor give me all objects that the name init with "James".


Reply With Quote
  #2  
Old   
mark.hayes (AT) oracle (DOT) com
 
Posts: n/a

Default Re: Filter object - 05-31-2006 , 08:52 AM






Hello Haas,

Berkeley DB doesn't have "filters" or a query language -- it provides
direct access to the store using primary and secondary indices. This
direct access, and the associated high performance, is what
distinguishes BDB from other databases. We call our new API the Direct
Persistence Layer for this reason.

If you want to query by name and name is a secondary index
(personByName), then you can use a sub-index. For example:

EntityCursor<Person> employees =
dao.personByName.subIndex("Bob Smith").entities();
try {
for (Person employee : employees) {
/* do something */
}
} finally {
employees.close();
}

If there is no secondary index for the name field, simply loop through
the records by primary index (personBySsn) and check the name field.
This is what a query language does internally when there is no
secondary index. For example:

EntityCursor<Person> employees =
dao.personBySsn.entities();
try {
for (Person employee : employees) {
if (employee.name.equals("Bob Smith")) {
/* do something */
}
}
} finally {
employees.close();
}

The code for the examples above was copied and modified from this page,
which is where you can start reading the Javadocs:

http://www.sleepycat.com/jedocs/java...e-summary.html

Another good starting point is to read Getting Started with the
Persistence API:

http://www.sleepycat.com/jedocs/Pers...API/index.html

In the future I suggest posting questions about BDB Java Edition to the
bdbje (AT) sleepycat (DOT) com mailing list, since this newsgroup is primarily for
BDB C Edition. See:

http://dev.sleepycat.com/community/discussion.html

Thanks,
Mark


Reply With Quote
  #3  
Old   
Haas
 
Posts: n/a

Default Re: Filter object - 05-31-2006 , 09:08 AM



Hello Mark,

First, thank you to answer my question!

Based in your answer I have a new question:

If I had more than 5000 entity of person persisted in DB (for example)
and I need do the the filter, when I get the entities from DB by
"EntityCursor<Person> employees = dao.personBySsn.entities();", Do I
full the computer memory with any objects that I don't will use it?



mark.hayes (AT) oracle (DOT) com wrote:
Quote:
Hello Haas,

Berkeley DB doesn't have "filters" or a query language -- it provides
direct access to the store using primary and secondary indices. This
direct access, and the associated high performance, is what
distinguishes BDB from other databases. We call our new API the Direct
Persistence Layer for this reason.

If you want to query by name and name is a secondary index
(personByName), then you can use a sub-index. For example:

EntityCursor<Person> employees =
dao.personByName.subIndex("Bob Smith").entities();
try {
for (Person employee : employees) {
/* do something */
}
} finally {
employees.close();
}

If there is no secondary index for the name field, simply loop through
the records by primary index (personBySsn) and check the name field.
This is what a query language does internally when there is no
secondary index. For example:

EntityCursor<Person> employees =
dao.personBySsn.entities();
try {
for (Person employee : employees) {
if (employee.name.equals("Bob Smith")) {
/* do something */
}
}
} finally {
employees.close();
}

The code for the examples above was copied and modified from this page,
which is where you can start reading the Javadocs:

http://www.sleepycat.com/jedocs/java...e-summary.html

Another good starting point is to read Getting Started with the
Persistence API:

http://www.sleepycat.com/jedocs/Pers...API/index.html

In the future I suggest posting questions about BDB Java Edition to the
bdbje (AT) sleepycat (DOT) com mailing list, since this newsgroup is primarily for
BDB C Edition. See:

http://dev.sleepycat.com/community/discussion.html

Thanks,
Mark


Reply With Quote
  #4  
Old   
mark.hayes (AT) oracle (DOT) com
 
Posts: n/a

Default Re: Filter object - 05-31-2006 , 10:06 AM



Haas wrote:
Quote:
Hello Mark,

First, thank you to answer my question!
You're welcome.

Quote:
Based in your answer I have a new question:

If I had more than 5000 entity of person persisted in DB (for example)
and I need do the the filter, when I get the entities from DB by
"EntityCursor<Person> employees = dao.personBySsn.entities();", Do I
full the computer memory with any objects that I don't will use it?
No, you won't fill up memory. When you read records, BDB loads them
into its cache. When the cache fills up, the least recently used
record is removed from the cache. In general, the larger the cache the
better the performance.

The size of the JE (BDB Java Edition) cache is, by default, 60% of the
Java heap size. The Java heap size can be specified using the Java
-Xmx option, and is normally 64 MB by default. You can override the
size of the JE cache using the environment configuration cache size
property:

http://www.sleepycat.com/jedocs/Pers.../EnvProps.html
http://www.sleepycat.com/jedocs/java...CacheSize(long)

Please do take a close look at the documentation above.

Thanks,
Mark



Reply With Quote
  #5  
Old   
Haas
 
Posts: n/a

Default Re: Filter object - 05-31-2006 , 12:30 PM



Ok Mark,

I understood, thank you again for the answer!

Now I'm starting to like DBD! :-)

Best regards.


mark.hayes (AT) oracle (DOT) com wrote:
Quote:
Haas wrote:
Hello Mark,

First, thank you to answer my question!

You're welcome.

Based in your answer I have a new question:

If I had more than 5000 entity of person persisted in DB (for example)
and I need do the the filter, when I get the entities from DB by
"EntityCursor<Person> employees = dao.personBySsn.entities();", Do I
full the computer memory with any objects that I don't will use it?

No, you won't fill up memory. When you read records, BDB loads them
into its cache. When the cache fills up, the least recently used
record is removed from the cache. In general, the larger the cache the
better the performance.

The size of the JE (BDB Java Edition) cache is, by default, 60% of the
Java heap size. The Java heap size can be specified using the Java
-Xmx option, and is normally 64 MB by default. You can override the
size of the JE cache using the environment configuration cache size
property:

http://www.sleepycat.com/jedocs/Pers.../EnvProps.html
http://www.sleepycat.com/jedocs/java...CacheSize(long)

Please do take a close look at the documentation above.

Thanks,
Mark


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.