Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequential Guid in Java

Considering the post I've made about the sequential guid performance on Microsoft.NET framework (see What are the performance improvement of Sequential Guid over standard Guid?) does somebody have a proper, sure, fast and well working Java implementation of the same algorithm implemented in the Windows DLLs?

Regards Massimo

like image 1000
massimogentilini Avatar asked Feb 04 '10 16:02

massimogentilini


People also ask

What is a GUID in Java?

GUID is an acronym for Globally Unique Identifier . It is often also referred to Universally Unique Identifiers or UUIDs . There is no genuine difference between the two terms. Technically, these are 128-bit immutable, unique, cryptographically-strong, random numbers.

Is UUID sequential?

UUID are supposed to be in-sequential, so that someone can not predict the other value. If you need sequence then UUID is not a right choice.

What is the difference between UUID and GUID?

UUID is a term that stands for Universal Unique Identifier. Similarly, GUID stands for Globally Unique Identifier. So basically, two terms for the same thing. They can be used, just like a product number, as a unique reference for an academic standard or content title.

How does UUID randomUUID work?

The randomUUID() method is used to retrieve a type 4 (pseudo randomly generated) UUID. The UUID is generated using a cryptographically strong pseudo random number generator.


1 Answers

See this article: http://www.informit.com/articles/article.aspx?p=25862&seqNum=7 (linked to Page 7).

It contains an algorithm for what the author refers to as "COMB" Guids; I reproduce his code (SQL) below:

SET @aGuid = CAST(CAST(NEWID() AS BINARY(10)) 
+ CAST(GETDATE() AS BINARY(6)) AS UNIQUEIDENTIFIER)

Trivial to convert this to Java, or your desired language. The obvious underlying principle is to make the date a component of the Guid. The entire article is a good read, as he does a nice analysis of the performance of the various approaches.

like image 132
Noon Silk Avatar answered Oct 05 '22 17:10

Noon Silk