Re: What happened to automatic binary primary keys?
Gary Teter <[email protected]> Tue, 25 Mar 2003 14:00:44 -0800
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
I believe they may still exist if you set the primary key type to
NSData with a width of 24. You can also create them yourself by
implementing EODatabaseContext's delegate method
databaseContextNewPrimaryKey. The easiest size to generate is 24 bytes,
just use EOTemporaryGlobalID's assignGloballyUniqueBytes. For smaller
sizes you'd want to do a hash of some sort.
In WireHose 2.0 we use this method along with EOModelGroup's
subEntityForEntity delegate method to optionally encode entity
information in the primary key, which can be useful for avoiding extra
fetches when resolving to-one faults against abstract entities.
In WireHose 1.0, we took a different approach, which was to create a
JDBC plug in wrapper which only implemented the newPrimaryKeys method
and delegated all other methods to the wrapped plugin. Implementing the
databaseContextNewPrimaryKey method is easier. :-)
Here's a simple implementation:
public NSDictionary databaseContextNewPrimaryKey(EODatabaseContext
databaseContext, Object object, EOEntity entity) {
if (entity.primaryKeyAttributeNames().count() != 1) { // don't handle
compound primary keys
return null;
}
EOAttribute primaryKeyAttribute =
(EOAttribute)entity.primaryKeyAttributes().objectAtIndex(0);
if (primaryKeyAttribute.adaptorValueType() !=
EOAttribute.AdaptorBytesType) { // only handle NSData primary keys
return null;
}
int pkWidth = primaryKeyAttribute.width();
if (pkWidth == EOTemporaryGlobalID.UniqueBinaryKeyLength) {
String primaryKeyAttributeName = primaryKeyAttribute.name();
byte[] hashBytes = new
byte[EOTemporaryGlobalID.UniqueBinaryKeyLength];
EOTemporaryGlobalID.assignGloballyUniqueBytes(hashBytes);
return new NSDictionary(new NSData(hashBytes),
primaryKeyAttributeName);
} else {
return null;
}
}
On Tuesday, March 25, 2003, at 12:46 AM, Ashley Aitken wrote:
> I browsed Apple's documentation, Omnigroup's mailing lists, googled
> here
> and googled there, but I can't find anything about those globally
> unique
> binary keys that EOF used to be able to generate automatically. I
> think
> they were 12 bytes then jumped to 20 (or was that) 24 bytes. They were
> made up, IIRC, of an IP address, an entity name, etc etc.
>
> Do these still exist in WO 5.2.x? Can someone please point me to some
> documentation? Or do they just automatically if you declare the
> primary key to be NSData with external type something like Byte width
> of
> 20 etc?
--
Gary Teter, Big Dog
Bulldog Beach Interactive http://www.bulldogbeach.com
WireHose: Powerful WebObjects content management
http://www.wirehose.com