Search code examples
javaguidsequential

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


Solution

  • 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.