// There is no UUID, so look for a path ...
if (path == null) {
String propName = DnaLexicon.UUID.getString(getExecutionContext().getNamespaceRegistry());
String msg = JpaConnectorI18n.locationShouldHavePathAndOrProperty.text(getSourceName(), propName);
throw new PathNotFoundException(original, pathFactory.createRootPath(), msg);
}
// Walk the child entities, starting at the root, down the to the path ...
if (path.isRoot()) {
Location newLocation = original.with(rootNodeUuid);
cache.addNewNode(workspaceId, newLocation);
return new ActualLocation(newLocation, rootNodeUuidString, null);
}
// See if the parent location is known in the cache ...
Location cachedParent = cache.getLocationFor(workspaceId, path.getParent());
if (cachedParent != null) {
// We know the UUID of the parent, so we can find the child a little faster ...
ChildEntity child = findByPathSegment(workspaceId, cachedParent.getUuid().toString(), path.getLastSegment());
uuidString = child.getId().getChildUuidString();
Location newLocation = original.with(UUID.fromString(uuidString));
cache.addNewNode(workspaceId, newLocation);
return new ActualLocation(newLocation, uuidString, child);
}
// We couldn't find the parent, so we need to search by path ...
String parentUuid = this.rootNodeUuidString;
ChildEntity child = null;
for (Path.Segment segment : path) {
child = findByPathSegment(workspaceId, parentUuid, segment);
if (child == null) {
// Unable to complete the path, so prepare the exception by determining the lowest path that exists ...
Path lowest = path;
while (lowest.getLastSegment() != segment) {
lowest = lowest.getParent();
}
lowest = lowest.getParent();
throw new PathNotFoundException(original, lowest);
}
parentUuid = child.getId().getChildUuidString();
}
assert child != null;
uuidString = child.getId().getChildUuidString();