Mike Kienenberger <mkienen..laska.net> wrote:
> Despite the fact that it's called a "meaningless primary key", I would
like
> to programmically determine the value of each entity's primary key.
>
> One way for me to do this is to generate a primaryKey() method in my class
> generation template, but I'd rather use the framework if possible.
>
> It seems like the way to do this is:
>
> Class objEntityClass = aCayenneDataObject.getObjectId().getObjClass();
>
> and from there:
>
> DbEntity aDbEntityClass = objEntityClass.getDbEntity();
>
>
> Are these intended for "user" access, or only internal framework use?
For those who need it, this is the code I came up with to generate a string
representation of a primary key for someDataObject:
String primaryKeysString = null;
Map pkAttributes = someDataObject.getObjectId().getIdSnapshot();
Iterator pkIterator = pkAttributes.keySet().iterator();
while (pkIterator.hasNext())
{
String primaryKeyName = (String) pkIterator.next();
Object primaryKeyValue = pkAttributes.get(primaryKeyName);
if (null == primaryKeysString)
{
primaryKeysString = primaryKeyName + "=" + primaryKeyValue;
}
else
{
primaryKeysString = primaryKeysString + "," + primaryKeyName + "=" +
primaryKeyValue;
}
}
This archive was generated by hypermail 2.0.0 : Mon Sep 22 2003 - 18:41:16 EDT