Search in sources :

Example 31 with SailException

use of org.eclipse.rdf4j.sail.SailException in project incubator-rya by apache.

the class RdfCloudTripleStoreConnection method getStatementsInternal.

@Override
protected CloseableIteration<? extends Statement, SailException> getStatementsInternal(final Resource subject, final IRI predicate, final Value object, final boolean flag, final Resource... contexts) throws SailException {
    // try {
    // have to do this to get the inferred values
    // TODO: Will this method reduce performance?
    final Var subjVar = decorateValue(subject, "s");
    final Var predVar = decorateValue(predicate, "p");
    final Var objVar = decorateValue(object, "o");
    StatementPattern sp = null;
    final boolean hasContext = contexts != null && contexts.length > 0;
    final Resource context = (hasContext) ? contexts[0] : null;
    final Var cntxtVar = decorateValue(context, "c");
    // TODO: Only using one context here
    sp = new StatementPattern(subjVar, predVar, objVar, cntxtVar);
    // return new StoreTripleSource(store.getConf()).getStatements(resource, uri, value, contexts);
    final CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate = evaluate(sp, null, null, false);
    return new // TODO: Use a util class to do this
    CloseableIteration<Statement, SailException>() {

        private boolean isClosed = false;

        @Override
        public void close() throws SailException {
            isClosed = true;
            try {
                evaluate.close();
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }

        @Override
        public boolean hasNext() throws SailException {
            try {
                return evaluate.hasNext();
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }

        @Override
        public Statement next() throws SailException {
            if (!hasNext() || isClosed) {
                throw new NoSuchElementException();
            }
            try {
                final BindingSet next = evaluate.next();
                final Resource bs_subj = (Resource) ((subjVar.hasValue()) ? subjVar.getValue() : next.getBinding(subjVar.getName()).getValue());
                final IRI bs_pred = (IRI) ((predVar.hasValue()) ? predVar.getValue() : next.getBinding(predVar.getName()).getValue());
                final Value bs_obj = (objVar.hasValue()) ? objVar.getValue() : next.getBinding(objVar.getName()).getValue();
                final Binding b_cntxt = next.getBinding(cntxtVar.getName());
                // convert BindingSet to Statement
                if (b_cntxt != null) {
                    return SimpleValueFactory.getInstance().createStatement(bs_subj, bs_pred, bs_obj, (Resource) b_cntxt.getValue());
                } else {
                    return SimpleValueFactory.getInstance().createStatement(bs_subj, bs_pred, bs_obj);
                }
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }

        @Override
        public void remove() throws SailException {
            try {
                evaluate.remove();
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }
    };
// } catch (QueryEvaluationException e) {
// throw new SailException(e);
// }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) EmptyBindingSet(org.eclipse.rdf4j.query.impl.EmptyBindingSet) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) IRI(org.eclipse.rdf4j.model.IRI) RyaIRI(org.apache.rya.api.domain.RyaIRI) Var(org.eclipse.rdf4j.query.algebra.Var) Resource(org.eclipse.rdf4j.model.Resource) SailException(org.eclipse.rdf4j.sail.SailException) CloseableIteration(org.eclipse.rdf4j.common.iteration.CloseableIteration) StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Value(org.eclipse.rdf4j.model.Value) NoSuchElementException(java.util.NoSuchElementException)

Example 32 with SailException

use of org.eclipse.rdf4j.sail.SailException in project incubator-rya by apache.

the class RdfCloudTripleStoreConnection method clearInternal.

@Override
protected void clearInternal(final Resource... aresource) throws SailException {
    try {
        final RyaIRI[] graphs = new RyaIRI[aresource.length];
        for (int i = 0; i < graphs.length; i++) {
            graphs[i] = RdfToRyaConversions.convertResource(aresource[i]);
        }
        ryaDAO.dropGraph(conf, graphs);
    } catch (final RyaDAOException e) {
        throw new SailException(e);
    }
}
Also used : RyaIRI(org.apache.rya.api.domain.RyaIRI) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) SailException(org.eclipse.rdf4j.sail.SailException)

Example 33 with SailException

use of org.eclipse.rdf4j.sail.SailException in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphConnection method addStatement.

/**
 * Adds the statement.
 *
 * @param subject the subject
 * @param predicate the predicate
 * @param object the object
 * @param contexts the contexts
 * @throws SailException the sail exception
 */
@Override
public void addStatement(Resource subject, IRI predicate, Value object, Resource... contexts) throws SailException {
    try {
        String[] predicateParts;
        if (predicate != null) {
            // predicateParts= predicate.stringValue().split(IntelligentGraphConstants.PATH_QL_REGEX);
            predicateParts = decodePredicate(predicate);
            switch(predicateParts[0]) {
                case PATHQL.addFact:
                    addFact(subject, predicateParts[1], object, contexts);
                    break;
                default:
                    super.addStatement(subject, predicate, object, contexts);
                    checkReificationsChanged(predicate);
            }
        } else
            super.addStatement(subject, predicate, object, contexts);
        this.intelligentGraphSail.clearCache();
    } catch (Exception e) {
        throw new SailException(e);
    }
}
Also used : SailException(org.eclipse.rdf4j.sail.SailException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) SailException(org.eclipse.rdf4j.sail.SailException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 34 with SailException

use of org.eclipse.rdf4j.sail.SailException in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphConnection method removeStatement.

/**
 * Removes the statement.
 *
 * @param modify the modify
 * @param subj the subj
 * @param pred the pred
 * @param obj the obj
 * @param contexts the contexts
 * @throws SailException the sail exception
 */
@Override
public void removeStatement(UpdateContext modify, Resource subj, IRI pred, Value obj, Resource... contexts) throws SailException {
    try {
        String[] predicateParts;
        if (pred != null) {
            // predicateParts= pred.stringValue().split(IntelligentGraphConstants.PATH_QL_REGEX);
            predicateParts = decodePredicate(pred);
            switch(predicateParts[0]) {
                case PATHQL.removeFact:
                case PATHQL.removeFacts:
                    deleteFacts(modify, subj, predicateParts[1], obj, contexts);
                    break;
                default:
                    super.removeStatement(modify, subj, pred, obj, contexts);
                    checkReificationsChanged(pred);
            }
        } else {
            super.removeStatement(modify, subj, pred, obj, contexts);
        }
    } catch (Exception e) {
        throw new SailException(e);
    }
}
Also used : SailException(org.eclipse.rdf4j.sail.SailException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) SailException(org.eclipse.rdf4j.sail.SailException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 35 with SailException

use of org.eclipse.rdf4j.sail.SailException in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentGraphConnection method removeStatements.

/**
 * Removes the statements.
 *
 * @param subj the subj
 * @param pred the pred
 * @param obj the obj
 * @param contexts the contexts
 * @throws SailException the sail exception
 */
@Override
public void removeStatements(Resource subj, IRI pred, Value obj, Resource... contexts) throws SailException {
    try {
        String[] predicateParts;
        if (pred != null) {
            predicateParts = decodePredicate(pred);
            switch(predicateParts[0]) {
                case PATHQL.removeFact:
                case PATHQL.removeFacts:
                    deleteFacts(null, subj, predicateParts[1], obj, contexts);
                    break;
                default:
                    super.removeStatements(subj, pred, obj, contexts);
                    checkReificationsChanged(pred);
            }
        } else {
            super.removeStatements(subj, pred, obj, contexts);
        }
    } catch (Exception e) {
        throw new SailException(e);
    }
}
Also used : SailException(org.eclipse.rdf4j.sail.SailException) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) SailException(org.eclipse.rdf4j.sail.SailException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Aggregations

SailException (org.eclipse.rdf4j.sail.SailException)36 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)19 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)17 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)17 AccumuloException (org.apache.accumulo.core.client.AccumuloException)13 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)13 RyaClientException (org.apache.rya.api.client.RyaClientException)13 Sail (org.eclipse.rdf4j.sail.Sail)13 InferenceEngineException (org.apache.rya.rdftriplestore.inference.InferenceEngineException)12 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)11 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)8 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)7 IOException (java.io.IOException)6 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)6 PathPatternException (com.inova8.pathql.processor.PathPatternException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 RecognitionException (org.antlr.v4.runtime.RecognitionException)5 Resource (org.eclipse.rdf4j.model.Resource)5 SailRepositoryConnection (org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)5 SailConnection (org.eclipse.rdf4j.sail.SailConnection)5