ObjectManager om = getStateManager().getObjectManager();
return mapping.getObject(om, parentKey, NOT_USED);
}
private Object lookupOneToOneChild(AbstractMemberMetaData ammd, ClassLoaderResolver clr) {
ObjectManager om = getStateManager().getObjectManager();
AbstractClassMetaData childClassMetaData =
om.getMetaDataManager().getMetaDataForClass(ammd.getType(), clr);
String kind = getStoreManager().getIdentifierFactory().newDatastoreContainerIdentifier(
childClassMetaData).getIdentifierName();
Entity parentEntity = fieldManager.getEntity();
// We're going to issue a query for all entities of the given kind with
// the parent entity's key as their parent. There should be only 1.
Query q = new Query(kind, parentEntity.getKey());
DatastoreService datastoreService = DatastoreServiceFactoryInternal.getDatastoreService();
// We have to pull back all children because the datastore does not let us
// filter ancestors by depth and an indirect child could come back before a
// direct child. eg:
// a/b/c
// a/c
for (Entity e : datastoreService.prepare(q).asIterable()) {
if (parentEntity.getKey().equals(e.getKey().getParent())) {
// TODO(maxr) Figure out how to hook this up to a StateManager!
return DatastoreQuery.entityToPojo(e, childClassMetaData, clr, om, false, om.getFetchPlan());
// We are potentially ignoring data errors where there is more than one
// direct child for the one to one. Unfortunately, in order to detect
// this we need to read all the way to the end of the Iterable and that
// might pull back a lot more data than is really necessary.
}