Re: Globally Unique IDs
Re: Globally Unique IDs
- Subject: Re: Globally Unique IDs
- From: Chuck Hill <email@hidden>
- Date: Tue, 24 Jun 2003 20:55:35 -0700
At 09:31 PM 24/06/2003 -0400, Goodbye Bill wrote:
>I am assuming this question has been asked a bazillion times already. My
>apologies if it has...
>
>How can I create a globally unique ID using Java and/or WebObjects?
>
I'd be very much surprised if you ever needed to.
>I am
>having to port a .NET / SQL 2000 application to WebObjects and need to
>ensure that an ID is never duplicated for several million records in a
>database. I also cannot depend on the database to generate the ID.
>
>Any assistance would be greatly appreciated.
>
Usually an EOGlobalID under the covers is nothing more than the name of the
Entity from the EOModel and the PK of the corresponding row. It is
important to know that this ID is not really globally unique in the sense
of the large binary identifiers things like Corba and COM use. It is only
unique within all the objects of that Entity. If you are using EO
inheritance then it is unique within that inheritance hierarchy.
As long as your entities map to tables with a primary key there is nothing
to do. If the primary keys are single column integers, when EOF creates
the primary key support it will take into account existing data in the
tables. If both the .NET app and the WO app are writing into the same
database at the same time, well you have a problem. You can either coerce
one to use the PK generation scheme of the other or ensure that each
generates keys in a different range. EOF will not deal with identity
columns (something which is by no means unique to EOF).
If you really can't use the DB to generate the PK, then you can get EOF to
create binary keys for you. Even doing this you still don't need to muck
with EOGlobalID yourself. However, if your schema is not already built on
the same type of key migration might be tiresome and stress provoking.
Then I thought, perhaps that is not what he means at all. Perhaps this is
what you were asking:
public String globallyUniqueString()
{
String localIP = null;
String uniqueString = null;
String uniqueThang = null;
try {
localIP = java.net.InetAddress.getLocalHost().getHostAddress();
} catch (java.net.UnknownHostException e) {
throw new RuntimeException("couldn't get IP!");
}
uniqueThang = (new java.rmi.server.UID()).toString(); // nasty, but
seems to work ok
uniqueString = localIP + " " + uniqueThang;
return uniqueString;
}
I'm certain there must be a better Java way. I recall that you an get EOF
to give you one of its binary primary key values, but how slips my mind at
the moment.
Chuck
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.