thomasmueller commented on a change in pull request #21:
URL: 
https://github.com/apache/sling-org-apache-sling-jcr-resource/pull/21#discussion_r837175782



##########
File path: 
src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/LimitingQueryLanguageProvider.java
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.resource.internal.helper.jcr;
+
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.QueryResult;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.commons.lang3.tuple.Triple;
+import org.apache.sling.jcr.resource.internal.helper.JcrResourceUtil;
+import org.apache.sling.spi.resource.provider.ProviderContext;
+import org.apache.sling.spi.resource.provider.ResolveContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LimitingQueryLanguageProvider extends BasicQueryLanguageProvider {
+
+    private final Logger log = 
LoggerFactory.getLogger(LimitingQueryLanguageProvider.class);
+
+    /** The limit to set for queries */
+    private final long defaultLimit;
+
+    public LimitingQueryLanguageProvider(final ProviderContext ctx, long 
defaultLimit) {
+        super(ctx);
+        this.defaultLimit = defaultLimit;
+    }
+
+    @Override
+    protected QueryResult query(final ResolveContext<JcrProviderState> ctx, 
final String query, final String language)
+            throws RepositoryException {
+        Triple<String, Long, Long> settings = extractQuerySettings(query);
+        return JcrResourceUtil.query(ctx.getProviderState().getSession(), 
settings.getLeft(), language,
+                settings.getMiddle(), settings.getRight());
+    }
+
+    protected Triple<String, Long, Long> extractQuerySettings(String query) {
+        query = query.trim();
+        if (query.endsWith("*/")) {

Review comment:
       Technically, we are adding support for "LIMIT" and "OFFSET" to the JCR 
language here, via comment.
   
   I wonder if it wouldn't be cleaner and simpler if we support "LIMIT" and 
"OFFSET" in Oak itself? That way, all clients would benefit (including those 
that don't use Sling). For example 
https://jackrabbit.apache.org/oak/docs/query/grammar-xpath.html#options (same 
for SQL-2)
   "option(limit 10, offset 2)". This would require minimal changes in Oak in 
my view.
   
   If we really want to support it in Sling, then I think we should use a 
different "language" for this. For example, instead of the language "xpath" we 
could use "sling-xpath" or so, and instead of "JCR-SQL2" we could use 
"sling-JCR-SQL2". The problem with using "xpath" as the language is that we 
already support comments in Oak, and so theoretically (I'm sure not in 
practice) we break backward compatibility with this change: we already support 
queries with comments.




-- 
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: dev-unsubscr...@sling.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to