开发者

autonicrement berkeley db, or list

开发者 https://www.devze.com 2023-02-03 22:27 出处:网络
Do berkeley db has autoincrement? I\'m using java for testing, I saw the example: collections.ship.tuple.Sample where the author uses a StoredSortedMap to handle the data, so he needs to put a key

Do berkeley db has autoincrement?

I'm using java for testing,

I saw the example: collections.ship.tuple.Sample where the author uses a StoredSortedMap to handle the data, so he needs to put a key every time.开发者_Python百科

I'd like to know if the Berkeley has autoincrement stuff.

Or if there is a kind of list to be stored and retrieved...


David Segleau, Director of Product Management for Berkeley DB here. Generally, we recommend that people ask questions on the Berkeley DB forums. You'll find a large community of active Berkeley DB application developers there.

The short answer to your question is that Berkeley DB has auto-increment services available. You just have to decide how you want to use them. Those options include:

  1. Put the code in your application. Since BDB is a library and it's linked into your application, many people simply control auto-increment key generation within the application itself. Of course, this can be somewhat more complicated if you are developing a multi-threaded or multi-process application.
  2. Use the a Berkeley DB Sequence to manage auto-increment. If you are using the basic Key/Value Pair API or the Collections API (as in your case), you can create a BDB Sequence, call the appropriate routines in order to get the next value and then assign that value to the key before writing the record. Since BDB Sequences are transactionally protected and function across a BDB environment, any multi-threading or multi-process issues are taken care of by the BDB library. You can find more information about BDB Sequences in chapter 19 of the BDB Reference Guide and in the Java API Programmers Reference Guide.
  3. If you are using the DPL (Direct Persistence Layer) API, you can define the primary key as a sequence. The DPL will then automatically take care of incrementing the key value during a put() operation.

I hope that was helpful.

Regards,

Dave

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号