thomasmueller commented on code in PR #535:
URL: https://github.com/apache/jackrabbit-oak/pull/535#discussion_r861784849
##########
oak-api/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java:
##########
@@ -91,6 +92,24 @@ Result executeQuery(
String statement, String language, long limit, long offset,
Map<String, ? extends PropertyValue> bindings,
Map<String, String> mappings) throws ParseException;
+
+ /**
+ * Execute a query and get the result.
+ *
+ * @param statement the query statement
+ * @param language the language
+ * @param limit the maximum result set size (may not be negative but may
be empty)
+ * @param offset the number of rows to skip (may not be negative but may
be empty)
+ * @param bindings the bind variable value bindings
+ * @param mappings namespace prefix mappings
+ * @return the result
+ * @throws ParseException if the statement could not be parsed
+ * @throws IllegalArgumentException if there was an error executing the
query
+ */
+ Result executeQuery(
+ String statement, String language, Optional<Long> limit,
Optional<Long> offset,
Review Comment:
I think Optional has some advantage for the case where we have multiple
"layers", like we have here: one could set the limit using the JCR API
Query.setLimit (I think), or via query statement "... option(limit <n>)". If we
use magic values, then it's harder to read the code (for humans). I think.
Depending on which one has higher precedence:
long limit = queryLimit.orElse(statementLimit.orElse(Long.MAX_VALUE));
or
long limit = statementLimit.orElse(queryLimit.orElse(Long.MAX_VALUE));
If you want to do the same with magic values (say, -1), it would be:
long limit = queryLimit >= 0 ? queryLimit : statementLimit >= 0 ?
statementLimit : Long.MAX_VALUE;
or
long limit = statementLimit >= 0 ? statementLimit : queryLimit >= 0 ?
queryLimit : Long.MAX_VALUE;
... which is harder to read.
But then we should use Optional consistently (avoid magic values where
possible).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]