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:10:44 UTC

svn commit: r1711447 - /sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/

Author: cziegeler
Date: Fri Oct 30 11:10:44 2015
New Revision: 1711447

URL: http://svn.apache.org/viewvc?rev=1711447&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/
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicPropertyConstraint.java   (with props)
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQuery.java   (with props)
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryBuilder.java   (with props)
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java   (with props)
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java   (with props)
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java   (with props)

Added: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicPropertyConstraint.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicPropertyConstraint.java?rev=1711447&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicPropertyConstraint.java (added)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicPropertyConstraint.java Fri Oct 30 11:10:44 2015
@@ -0,0 +1,96 @@
+/*
+ * 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.Query.PropertyConstraint;
+import org.apache.sling.api.resource.query.Query.PropertyOperator;
+
+/**
+ * Implementation of the property constraint.
+ */
+public class BasicPropertyConstraint implements PropertyConstraint {
+
+    private final PropertyOperator operator;
+
+    private final String name;
+
+    private final Object value;
+
+    public BasicPropertyConstraint(final PropertyOperator operator,
+            final String name,
+            final Object value) {
+        this.operator = operator;
+        this.name = name;
+        this.value = value;
+    }
+
+    @Override
+    public PropertyOperator getOperator() {
+        return this.operator;
+    }
+
+    @Override
+    public String getName() {
+        return this.name;
+    }
+
+    @Override
+    public Object getValue() {
+        return this.value;
+    }
+
+    @Override
+    public String toString() {
+        return "BasicPropertyConstraint [operator=" + operator + ", name=" + name + ", value=" + value + "]";
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((operator == null) ? 0 : operator.hashCode());
+        result = prime * result + ((value == null) ? 0 : value.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        BasicPropertyConstraint other = (BasicPropertyConstraint) obj;
+        if (name == null) {
+            if (other.name != null)
+                return false;
+        } else if (!name.equals(other.name))
+            return false;
+        if (operator != other.operator)
+            return false;
+        if (value == null) {
+            if (other.value != null)
+                return false;
+        } else if (!value.equals(other.value))
+            return false;
+        return true;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicPropertyConstraint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicPropertyConstraint.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQuery.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQuery.java?rev=1711447&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQuery.java (added)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQuery.java Fri Oct 30 11:10:44 2015
@@ -0,0 +1,101 @@
+/*
+ * 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 java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.sling.api.resource.query.Query;
+
+/**
+ * Implementation of the query.
+ */
+public class BasicQuery implements Query {
+
+    private final Set<String> paths;
+
+    private final Set<String> resourceTypes;
+
+    private final Set<String> names;
+
+    private final Set<PropertyConstraint> propertyConstraints;
+
+    private final QueryType queryType;
+
+    private final List<Query> subQueries;
+
+    public BasicQuery(final Set<String> paths,
+            final Set<String> resourceTypes,
+            final Set<String> names,
+            final Set<PropertyConstraint> propertyConstraints) {
+        this.paths = Collections.unmodifiableSet(paths);
+        this.resourceTypes = Collections.unmodifiableSet(resourceTypes);
+        this.names = Collections.unmodifiableSet(names);
+        this.propertyConstraints = Collections.unmodifiableSet(propertyConstraints);
+        this.subQueries = null;
+        this.queryType = QueryType.SINGLE;
+    }
+
+    public BasicQuery(final QueryType qt,
+            final List<Query> subQueries) {
+        this.queryType = qt;
+        this.subQueries = Collections.unmodifiableList(subQueries);
+        this.paths = null;
+        this.resourceTypes = null;
+        this.names = null;
+        this.propertyConstraints = null;
+    }
+
+    @Override
+    public String getId() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Set<String> getPaths() {
+        return this.paths;
+    }
+
+    @Override
+    public Set<String> getResourceNames() {
+        return this.names;
+    }
+
+    @Override
+    public Set<String> getIsA() {
+        return this.resourceTypes;
+    }
+
+    @Override
+    public Set<PropertyConstraint> getPropertyConstraints() {
+        return propertyConstraints;
+    }
+
+    @Override
+    public List<Query> getParts() {
+        return this.subQueries;
+    }
+
+    @Override
+    public QueryType getQueryType() {
+        return this.queryType;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQuery.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryBuilder.java?rev=1711447&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryBuilder.java (added)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryBuilder.java Fri Oct 30 11:10:44 2015
@@ -0,0 +1,116 @@
+/*
+ * 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 java.util.HashSet;
+import java.util.Set;
+
+import org.apache.sling.api.resource.query.PropertyBuilder;
+import org.apache.sling.api.resource.query.Query;
+import org.apache.sling.api.resource.query.Query.PropertyConstraint;
+import org.apache.sling.api.resource.query.Query.PropertyOperator;
+import org.apache.sling.api.resource.query.QueryBuilder;
+
+/**
+ * Implementation of the query builder.
+ */
+public class BasicQueryBuilder implements QueryBuilder {
+
+    private final Set<String> paths = new HashSet<String>();
+
+    private final Set<String> resourceTypes = new HashSet<String>();
+
+    private final Set<String> names = new HashSet<String>();
+
+    private final Set<PropertyConstraint> propertyConstraints = new HashSet<PropertyConstraint>();
+
+    @Override
+    public Query build() {
+        return new BasicQuery(paths, resourceTypes, names, propertyConstraints);
+    }
+
+    @Override
+    public QueryBuilder at(final String... path) {
+        for(final String p : path) {
+            this.paths.add(p);
+        }
+        return this;
+    }
+
+    @Override
+    public QueryBuilder isA(final String resourceType) {
+        this.resourceTypes.add(resourceType);
+        return this;
+    }
+
+    @Override
+    public QueryBuilder name(final String resourceName) {
+        this.names.add(resourceName);
+        return this;
+    }
+
+    @Override
+    public PropertyBuilder property(final String name) {
+        return new PropertyBuilder() {
+
+            @Override
+            public QueryBuilder isLessOrEq(final Object value) {
+                propertyConstraints.add(new BasicPropertyConstraint(PropertyOperator.LT_OR_EQ, name, value));
+                return BasicQueryBuilder.this;
+            }
+
+            @Override
+            public QueryBuilder isLess(final Object value) {
+                propertyConstraints.add(new BasicPropertyConstraint(PropertyOperator.LT, name, value));
+                return BasicQueryBuilder.this;
+            }
+
+            @Override
+            public QueryBuilder isGreaterOrEq(final Object value) {
+                propertyConstraints.add(new BasicPropertyConstraint(PropertyOperator.GT_OR_EQ, name, value));
+                return BasicQueryBuilder.this;
+            }
+
+            @Override
+            public QueryBuilder isGreater(final Object value) {
+                propertyConstraints.add(new BasicPropertyConstraint(PropertyOperator.GT, name, value));
+                return BasicQueryBuilder.this;
+            }
+
+            @Override
+            public QueryBuilder exists() {
+                propertyConstraints.add(new BasicPropertyConstraint(PropertyOperator.EXISTS, name, null));
+                return BasicQueryBuilder.this;
+            }
+
+            @Override
+            public QueryBuilder eq(final Object value) {
+                propertyConstraints.add(new BasicPropertyConstraint(PropertyOperator.EQ, name, value));
+                return BasicQueryBuilder.this;
+            }
+
+            @Override
+            public QueryBuilder contains(final Object value) {
+                propertyConstraints.add(new BasicPropertyConstraint(PropertyOperator.CONTAINS, name, value));
+                return BasicQueryBuilder.this;
+            }
+        };
+    }
+
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryBuilder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 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=1711447&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java (added)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java Fri Oct 30 11:10:44 2015
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.Collections;
+import java.util.List;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.query.QueryInstructions;
+
+/**
+ * Implementation of the query instructions.
+ */
+public class BasicQueryInstructions implements QueryInstructions {
+
+    private final List<SortCriteria> sortCriteria;
+
+    public BasicQueryInstructions(final List<SortCriteria> sortCriteria) {
+        this.sortCriteria = Collections.unmodifiableList(sortCriteria);
+    }
+
+    @Override
+    public String getId() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public int getLimit() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public String getContinuationKey() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public String generateContinuationKey(Resource resource) {
+        // 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

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructions.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 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=1711447&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java (added)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java Fri Oct 30 11:10:44 2015
@@ -0,0 +1,54 @@
+/*
+ * 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;
+import org.apache.sling.api.resource.query.QueryInstructionsBuilder;
+
+/**
+ * Implementation of the query instructions builder.
+ */
+public class BasicQueryInstructionsBuilder implements QueryInstructionsBuilder {
+
+    @Override
+    public QueryInstructionsBuilder limit(int limit) {
+        return this;
+    }
+
+    @Override
+    public QueryInstructionsBuilder continueAt(String continuationKey) {
+        return this;
+    }
+
+    @Override
+    public QueryInstructionsBuilder sortAscendingBy(String propName) {
+        return this;
+    }
+
+    @Override
+    public QueryInstructionsBuilder sortDescendingBy(String propName) {
+        return this;
+    }
+
+    @Override
+    public QueryInstructions build() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/BasicQueryInstructionsBuilder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 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=1711447&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java (added)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java Fri Oct 30 11:10:44 2015
@@ -0,0 +1,78 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.query.Query;
+import org.apache.sling.api.resource.query.Query.QueryType;
+import org.apache.sling.api.resource.query.QueryBuilder;
+import org.apache.sling.api.resource.query.QueryInstructions;
+import org.apache.sling.api.resource.query.QueryInstructionsBuilder;
+import org.apache.sling.api.resource.query.QueryManager;
+
+public class DefaultQueryManager implements QueryManager {
+
+    @Override
+    public Iterator<Resource> find(ResourceResolver resolver, Query q, QueryInstructions qi) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public QueryBuilder query() {
+        return new BasicQueryBuilder();
+    }
+
+    @Override
+    public Query andQuery(final Query q1, final Query... q2) {
+        if ( q2 == null || q2.length == 0 ) {
+            return q1;
+        }
+        final List<Query> list = new ArrayList<Query>();
+        list.add(q1);
+        for(final Query q : q2) {
+            list.add(q);
+        }
+        return new BasicQuery(QueryType.COMPOUND_AND, list);
+    }
+
+    @Override
+    public Query orQuery(final Query q1, final Query... q2) {
+        if ( q2 == null || q2.length == 0 ) {
+            return q1;
+        }
+        final List<Query> list = new ArrayList<Query>();
+        list.add(q1);
+        for(final Query q : q2) {
+            list.add(q);
+        }
+        return new BasicQuery(QueryType.COMPOUND_OR, list);
+    }
+
+    @Override
+    public QueryInstructionsBuilder instructions() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/query/DefaultQueryManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url