Forum Stats

  • 3,769,982 Users
  • 2,253,043 Discussions
  • 7,875,258 Comments

Discussions

How to get a count of records when using Persistence API?

531207
531207 Member Posts: 11
edited Sep 1, 2006 2:23AM in Berkeley DB Java Edition
i noticed there is no method i could use to get a count number of db record when using Persistence API.
by now i'm using:

while(myEntityCursor.next()!=null)
count ++;

but i'm sure that would not be a good implementation. Could anyone help me for that?

Thanks
Richie

Comments

  • Greybird-Oracle
    Greybird-Oracle Member Posts: 2,690
    There is currently no record count method in the DPL (Direct Persistence Layer) nor in the base JE API.

    You can call EntityIndex.map().size() to get a record count. However, this is implemented by iterating over all records using read uncommitted. So this is no faster than if you iterate yourself (as you've already done) but using read uncommitted (Cursor.READ_UNCOMMITTED or LockMode.READ_UNCOMMITTED).

    In the next release we are adding a faster count to the base API and the DPL. This will be used automatically by EntityIndex.map().size(). This count, just like the count obtained by iterating with read uncommitted, will not be transactionally correct.

    Mark
  • 531207
    531207 Member Posts: 11
    got that.

    thanks for your reply and now i'm expecting for the next release,

    thanks again and good luck.

    Richie
This discussion has been closed.