Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Best practice for unique ID generation

In a database centered design, it's very easy to get a unique identifier(primary key) by using database provider's built-in sequence. But it's not the case in Gigaspaces. I'm wondering if there is any best practice for unique ID generation in Gigaspaces. I'm thinking of getting the ID from a database sequence table and then passing it onto Gigapaces. But I'd like to know if there is any better implementation.

Thanks,

Simon

Attachments

  1. UUIDBean.java

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2008-05-21 12:58:12 -0500

noiseba gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
0

if the Space UID generator is not good enough for you and you need different one you can try this:
http://www.gigaspaces.com/docs/JiniApi/net/jini/id/UuidFactory.html

net.jini.id.Uuid uid1 = UuidFactory.generate();

I'm not sure what is the cost of this UID generator compared to a database one.
I managed to create 1 million UIDs in 7 seconds.

Shay

answered 2008-05-21 17:10:10 -0500

shay hassidim gravatar image
edit flag offensive delete link more
0

Back in my EJB days this issue came up often.

There are several patterns that address different variants of this need. For complete pattern info, you can look at chapter 5 of the following EJB design patterns book (as a PDF) http://labs.cs.utt.ro/labs/sprc/html/...

When a non-sequenced String PK is needed you can use the attached UUIDBean. Feel free to improve it.

HTH

Owen. h4. Attachments

[UUIDBean.java|/upfiles/13759718563718033.java]

answered 2008-05-22 10:27:57 -0500

owentaylor gravatar image
edit flag offensive delete link more
0

There's the UUID class, part of the JDK since Java 1.5, that may fit your need.

/Vanio

answered 2008-05-22 10:35:19 -0500

vanio gravatar image
edit flag offensive delete link more

Comments

Sorry, I do a mistake. Oups!!

Carole

Edited by: carole benazza on Jun 26, 2008 10:12 AM

Edited by: carole benazza on Jun 26, 2008 10:13 AM

cbe gravatar imagecbe ( 2008-06-26 10:04:27 -0500 )edit
0

Hi Simon,

The answer depends on the requirements you have for id. If all you need is a unique identifier, than take a look at the @SpaceId with auto generation equals to true. This annotation makes sure the identifier is generated by the space.

As a side note; in a distributed system, trying to centralize services, like id generation usually works against scalability requirements.

Guy

answered 2008-05-21 13:05:49 -0500

nirpaz gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2008-05-21 12:58:12 -0500

Seen: 682 times

Last updated: May 22 '08