String reference = weak ? PropertyType.TYPENAME_WEAKREFERENCE : PropertyType.TYPENAME_REFERENCE;
String pName = propertyName == null ? "*" : propertyName; // TODO: sanitize against injection attacks!?
Map<String, ? extends PropertyValue> bindings = Collections.singletonMap("uuid", PropertyValues.newString(uuid));
try {
Result result = root.getQueryEngine().executeQuery(
"SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference + "') = $uuid",
Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, NO_MAPPINGS);
return findPaths(result, uuid, propertyName, nodeTypeNames,
weak ? Type.WEAKREFERENCE : Type.REFERENCE,
weak ? Type.WEAKREFERENCES : Type.REFERENCES