// If this is an encoded pk field, transform the Key into its String representation.
return KeyFactory.keyToString(datastoreEntity.getKey());
} else {
if (datastoreEntity.getKey().isComplete() && datastoreEntity.getKey().getName() == null) {
// This is trouble, probably an incorrect mapping.
throw new NucleusFatalUserException(
"The primary key for " + getClassMetaData().getFullClassName() + " is an unencoded "
+ "string but the key of the corresponding entity in the datastore does not have a "
+ "name. You may want to either change the primary key to be an encoded string "
+ "(add the \"" + DatastoreManager.ENCODED_PK + "\" extension), change the "
+ "primary key to be of type " + Key.class.getName() + ", or, if you're certain that "
+ "this class will never have a parent, change the primary key to be of type Long.");
}
return datastoreEntity.getKey().getName();
}
} else if (MetaDataUtils.isParentPKField(getClassMetaData(), fieldNumber)) {
Key parentKey = datastoreEntity.getKey().getParent();
if (parentKey == null) {
return null;
}
return KeyFactory.keyToString(parentKey);
} else if (MetaDataUtils.isPKNameField(getClassMetaData(), fieldNumber)) {
AbstractMemberMetaData mmd = getMetaData(fieldNumber);
if (!mmd.getType().equals(String.class)) {
throw new NucleusFatalUserException(
"Field with \"" + DatastoreManager.PK_NAME + "\" extension must be of type String");
}
Key key = datastoreEntity.getKey();
if (key.getName() == null) {
throw new NucleusFatalUserException(
"Attempting to fetch field with \"" + DatastoreManager.PK_NAME + "\" extension but the "
+ "entity is identified by an id, not a name.");
}
return datastoreEntity.getKey().getName();
}