Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/206#discussion_r133450932
  
    --- Diff: 
common/rya.api/src/main/java/org/apache/rya/api/persist/utils/RyaDaoQueryWrapper.java
 ---
    @@ -0,0 +1,179 @@
    +/*
    + * 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.rya.api.persist.utils;
    +
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import org.apache.rya.api.RdfCloudTripleStoreConfiguration;
    +import org.apache.rya.api.domain.RyaStatement;
    +import org.apache.rya.api.persist.RyaDAO;
    +import org.apache.rya.api.resolver.RyaToRdfConversions;
    +import org.openrdf.model.Resource;
    +import org.openrdf.model.Statement;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.query.QueryEvaluationException;
    +
    +import info.aduna.iteration.CloseableIteration;
    +
    +/**
    + * Wraps Rya DAO queries into a simpler interface that just passes in the
    + * statement to query for and a handler for dealing with each statement in 
the
    + * query result. This handles iterating over the query, throwing any 
exceptions,
    + * and closing the query iterator when done. The same wrapper can be 
re-used
    + * for multiple queries.
    + */
    +public class RyaDaoQueryWrapper {
    +    private final RyaDAO<?> ryaDao;
    +    private final RdfCloudTripleStoreConfiguration conf;
    +
    +    /**
    +     * Creates a new instance of {@link RyaDaoQueryWrapper}.
    +     * @param ryaDao the {@link RyaDAO}. (not {@code null})
    +     * @param conf the {@link RdfCloudTripleStoreConfiguration}.
    +     * (not {@code null})
    +     */
    +    public RyaDaoQueryWrapper(final RyaDAO<?> ryaDao, final 
RdfCloudTripleStoreConfiguration conf) {
    +        this.ryaDao = checkNotNull(ryaDao);
    +        this.conf = checkNotNull(conf);
    +    }
    +
    +    /**
    +     * Creates a new instance of {@link RyaDaoQueryWrapper}.
    +     * @param ryaDao the {@link RyaDAO}. (not {@code null})
    +     */
    +    public RyaDaoQueryWrapper(final RyaDAO<?> ryaDao) {
    +        this(checkNotNull(ryaDao), ryaDao.getConf());
    +    }
    +
    +    /**
    +     * Handles all results of a query. Closes the query iterator when done.
    +     * @param subject the subject {@link Resource} to query for.
    +     * @param predicate the predicate {@link URI} to query for.
    +     * @param object the object {@link Value} to query for.
    +     * @param ryaDaoStatementIterHandler the {@link 
RyaDaoStatementIterHandler}
    +     * to use for handling each statement returned. (not {@code null})
    +     * @param contexts the context {@link Resource}s to query for.
    +     * @throws QueryEvaluationException
    +     */
    +    public void queryAll(final Resource subject, final URI predicate, 
final Value object, final RyaDaoStatementIterHandler 
ryaDaoStatementIterHandler, final Resource... contexts) throws 
QueryEvaluationException {
    +        checkNotNull(ryaDaoStatementIterHandler);
    +        final CloseableIteration<Statement, QueryEvaluationException> iter 
= RyaDAOHelper.query(ryaDao, subject, predicate, object, conf, contexts);
    +        try {
    +            while (iter.hasNext()) {
    +                final Statement statement = iter.next();
    +                try {
    +                    
ryaDaoStatementIterHandler.handleStatementIter(statement);
    +                } catch (final Exception e) {
    +                    throw new QueryEvaluationException("Error handling 
statement.", e);
    +                }
    +            }
    +        } finally {
    +            if (iter != null) {
    +                iter.close();
    +            }
    +        }
    +    }
    +
    +    /**
    +     * Handles all results of a query. Closes the query iterator when done.
    +     * @param statement the {@link Statement} to query for.
    +     * @param ryaDaoStatementIterHandler the {@link 
RyaDaoStatementIterHandler}
    +     * to use for handling each statement returned. (not {@code null})
    +     * @throws QueryEvaluationException
    +     */
    +    public void queryAll(final Statement statement, final 
RyaDaoStatementIterHandler ryaDaoStatementIterHandler) throws 
QueryEvaluationException {
    +        final Resource subject = statement != null ? 
statement.getSubject() : null;
    +        final URI predicate = statement != null ? statement.getPredicate() 
: null;
    +        final Value object = statement != null ? statement.getObject() : 
null;
    +        final Resource context = statement != null ? 
statement.getContext() : null;
    +        queryAll(subject, predicate, object, ryaDaoStatementIterHandler, 
context);
    --- End diff --
    
    It seems like you want to allow for the possibility of a null statement 
here (which would result in scanning the entire Rya instance).  Given that we 
don't support such look ups, wouldn't it be cleaner to just require the 
Statement to be non-null here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to