-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: UUID ToString Algorithm
PostPosted: Fri Jul 08, 2005 12:37 pm 
I was reading the NHibernate docs:

Section 3.1.4.4 wrote:
The UUID is generated by calling Guid.NewGuid().ToByteArray() and then converting the byte[] into a char[]. The char[] is returned as a String consisting of 16 characters.


A few questions:
1. Why use ToByteArray etc... and not .ToString("N") ?? seems like ToString would be faster
2. Why 16 chars and not the full 32 ?? Using 16 makes comparing guids visually somewhat difficult since most of the time you'll be looking at 32 caracters. Granted, I hope to never have to visually compare these - but when writing test cases I would have to do the same ToByteArray junk just to get a working test....


Top
  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:59 pm 
Well i just went ahead and changed the UUIDStringGenerator.cs file to make it work how I think it should:

Code:
public object Generate( ISessionImplementor session, object obj )
{
//   byte[ ] guidInBytes = new byte[16];
//   StringBuilder guidBuilder = new StringBuilder( 16, 16 );
//
//   guidInBytes = Guid.NewGuid().ToByteArray();
//
//   // add each item in Byte[] to the string builder
//   for( int i = 0; i < guidInBytes.Length; i++ )
//   {
//      guidBuilder.Append( ( char ) guidInBytes[ i ] );
//   }

   return Guid.NewGuid().ToString("N");
}


I'm still curious as to the whole byte[] and 16 char thing though....


Top
  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 10:11 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Hello thejez,

Can you create a JIRA issue (http://jira.nhibernate.org) so that we can investigate on it later? :)

As this implementation (probably) comes from Hibernate; it is possible that Java don't have a Guid.ToString("N")...
We just need to make sure that they are functionally equivalents.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 6:53 pm 
Newbie

Joined: Sun Jul 10, 2005 6:30 pm
Posts: 10
Well, they are functional equivalents, although they do not return the same length string... but that shouldn't matter too much.

I went ahead and added it as an improvment to jira as you suggested.

http://jira.nhibernate.org/browse/NH-331


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.