You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/10/30 12:25:20 UTC
svn commit: r1711450 - in
/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query:
BasicQueryInstructions.java BasicQueryInstructionsBuilder.java
BasicSortCriteria.java DefaultQueryManager.java
Author: cziegeler
Date: Fri Oct 30 11:25:19 2015
New Revision: 1711450
URL: http://svn.apache.org/viewvc?rev=1711450&view=rev
Log:
SLING-4752 : New resource query API. Implementation stub
Added:
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicSortCriteria.java (with props)
Modified:
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java
Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java?rev=1711450&r1=1711449&r2=1711450&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java (original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java Fri Oct 30 11:25:19 2015
@@ -31,8 +31,16 @@ public class BasicQueryInstructions impl
private final List<SortCriteria> sortCriteria;
- public BasicQueryInstructions(final List<SortCriteria> sortCriteria) {
+ private final String continuationKey;
+
+ private final int limit;
+
+ public BasicQueryInstructions(final List<SortCriteria> sortCriteria,
+ final String continuationKey,
+ final int limit) {
this.sortCriteria = Collections.unmodifiableList(sortCriteria);
+ this.continuationKey = continuationKey;
+ this.limit = limit;
}
@Override
@@ -43,25 +51,25 @@ public class BasicQueryInstructions impl
@Override
public int getLimit() {
- // TODO Auto-generated method stub
- return 0;
+ return this.limit;
}
@Override
public String getContinuationKey() {
- // TODO Auto-generated method stub
- return null;
+ return this.continuationKey;
}
@Override
- public String generateContinuationKey(Resource resource) {
+ public String generateContinuationKey(final Resource resource) {
+ if ( resource == null ) {
+ throw new IllegalArgumentException("No resource provided for continuation key.");
+ }
// TODO Auto-generated method stub
return null;
}
@Override
public List<SortCriteria> getSortCriteria() {
- // TODO Auto-generated method stub
return sortCriteria;
}
}
\ No newline at end of file
Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java?rev=1711450&r1=1711449&r2=1711450&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java (original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java Fri Oct 30 11:25:19 2015
@@ -18,7 +18,11 @@
*/
package org.apache.sling.resourceresolver.impl.query;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.sling.api.resource.query.QueryInstructions;
+import org.apache.sling.api.resource.query.QueryInstructions.SortCriteria;
import org.apache.sling.api.resource.query.QueryInstructionsBuilder;
/**
@@ -26,29 +30,38 @@ import org.apache.sling.api.resource.que
*/
public class BasicQueryInstructionsBuilder implements QueryInstructionsBuilder {
+ private final List<SortCriteria> sortCriteria = new ArrayList<SortCriteria>();
+
+ private String continuationKey;
+
+ private int limit = -1;
+
@Override
- public QueryInstructionsBuilder limit(int limit) {
+ public QueryInstructionsBuilder limit(final int limit) {
+ this.limit = limit;
return this;
}
@Override
public QueryInstructionsBuilder continueAt(String continuationKey) {
+ this.continuationKey = continuationKey;
return this;
}
@Override
- public QueryInstructionsBuilder sortAscendingBy(String propName) {
+ public QueryInstructionsBuilder sortAscendingBy(final String propName) {
+ this.sortCriteria.add(new BasicSortCriteria(propName, true));
return this;
}
@Override
- public QueryInstructionsBuilder sortDescendingBy(String propName) {
+ public QueryInstructionsBuilder sortDescendingBy(final String propName) {
+ this.sortCriteria.add(new BasicSortCriteria(propName, false));
return this;
}
@Override
public QueryInstructions build() {
- // TODO Auto-generated method stub
- return null;
+ return new BasicQueryInstructions(sortCriteria, continuationKey, limit);
}
}
\ No newline at end of file
Added: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicSortCriteria.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicSortCriteria.java?rev=1711450&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicSortCriteria.java (added)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicSortCriteria.java Fri Oct 30 11:25:19 2015
@@ -0,0 +1,46 @@
+/*
+ * 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.resourceresolver.impl.query;
+
+import org.apache.sling.api.resource.query.QueryInstructions.SortCriteria;
+
+/**
+ * Implementation of the sort criteria
+ */
+public class BasicSortCriteria implements SortCriteria {
+
+ private final String name;
+
+ private final boolean isAscending;
+
+ public BasicSortCriteria(final String name, final boolean isAscending) {
+ this.name = name;
+ this.isAscending = isAscending;
+ }
+
+ @Override
+ public String getPropertyName() {
+ return this.name;
+ }
+
+ @Override
+ public boolean isAscending() {
+ return this.isAscending;
+ }
+}
\ No newline at end of file
Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicSortCriteria.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicSortCriteria.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java?rev=1711450&r1=1711449&r2=1711450&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java (original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java Fri Oct 30 11:25:19 2015
@@ -19,6 +19,7 @@
package org.apache.sling.resourceresolver.impl.query;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -30,13 +31,16 @@ import org.apache.sling.api.resource.que
import org.apache.sling.api.resource.query.QueryInstructions;
import org.apache.sling.api.resource.query.QueryInstructionsBuilder;
import org.apache.sling.api.resource.query.QueryManager;
+import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
public class DefaultQueryManager implements QueryManager {
@Override
- public Iterator<Resource> find(ResourceResolver resolver, Query q, QueryInstructions qi) {
- // TODO Auto-generated method stub
- return null;
+ public Iterator<Resource> find(final ResourceResolver resolver, final Query q, final QueryInstructions qi) {
+ if ( !(resolver instanceof ResourceResolverImpl) ) {
+ throw new IllegalArgumentException("Resource resolver is not provided by this bundle.");
+ }
+ return Collections.EMPTY_LIST.iterator();
}
@Override
@@ -72,7 +76,6 @@ public class DefaultQueryManager impleme
@Override
public QueryInstructionsBuilder instructions() {
- // TODO Auto-generated method stub
- return null;
+ return new BasicQueryInstructionsBuilder();
}
}
\ No newline at end of file