GWT: Decrypt GAE-JDO key to access parent
In the GAE-JDO docs it is possible to get parent keys from child keys:
Note also that the string representation of the string is not encrypted: the user can decode the key string to retrieve its components, including the species and identifiers of the object and its ancestors.
REF: "Objects, Properties and Keys"
I am generating keys using the following:
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
When validating the datastore, the entity keys look like this:
parent.id = agpzfnZpdmVlbGFichQLEgdTZXNzaW9uGICAgICgwMsIDA
child1.id = agpzfnZpdmVlbGFiciYLEgdTZXNzaW9uGICAgICgwMsIDAsSBVN0YWdlGICAgICAwK8KDA
...
(where the parent has children of type Child). So, I'm looking for a GWT function like this:
String getParentIdFromChildId(String childId) {
String parentId = ...
return parentId;
}
so from the client (GWT) I can refer to the child object (by first discovering its parent):
Child child = data.getParent(getParentIdFromChildId(childId)).getChild(childId);
I could solve this by also tracking the parent id, but if the parent information is already embedded in the child id, this is inefficient.
Thanks in advance.
~ Owen
source to share
child1.getParent()
returns the key of the parent of the object child1
.
So, if you have an object child1
and you want its parent id, just call:
String parentId = child1.getParent().id;
to return the parent id.
More details here: Entity 'getParent ()' method documentation
Not sure if this is what you wanted, but this is how I would do it.
Thank,
~ Samir
source to share