Search in sources :

Example 1 with RdfCloudTripleStoreConnection

use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.

the class RdfController method performUpdate.

private void performUpdate(final String query, final SailRepositoryConnection conn, final ServletOutputStream os, final String infer, final String vis) throws RepositoryException, MalformedQueryException, IOException {
    final Update update = conn.prepareUpdate(QueryLanguage.SPARQL, query);
    if (infer != null && infer.length() > 0) {
        update.setBinding(RdfCloudTripleStoreConfiguration.CONF_INFER, VALUE_FACTORY.createLiteral(Boolean.parseBoolean(infer)));
    }
    if (conn.getSailConnection() instanceof RdfCloudTripleStoreConnection && vis != null) {
        final RdfCloudTripleStoreConnection<?> sailConnection = (RdfCloudTripleStoreConnection<?>) conn.getSailConnection();
        sailConnection.getConf().set(RdfCloudTripleStoreConfiguration.CONF_CV, vis);
    }
    final long startTime = System.currentTimeMillis();
    try {
        update.execute();
    } catch (final UpdateExecutionException e) {
        final String message = "Update could not be successfully completed for query: ";
        os.print(String.format(message + "%s\n\n", StringEscapeUtils.escapeHtml4(query)));
        log.error(message + LogUtils.clean(query), e);
    }
    log.info(String.format("Update Time = %.3f\n", (System.currentTimeMillis() - startTime) / 1000.));
}
Also used : UpdateExecutionException(org.openrdf.query.UpdateExecutionException) ParsedUpdate(org.openrdf.query.parser.ParsedUpdate) Update(org.openrdf.query.Update) RdfCloudTripleStoreConnection(org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection)

Example 2 with RdfCloudTripleStoreConnection

use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.

the class EntityTupleSet method evaluate.

@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings) throws QueryEvaluationException {
    // into the remainder of the star query to be evaluated
    if (minCard < 1000 && starQuery.size() > 2 && numberOfSpVars(minSp) == 1 && !starQuery.commonVarConstant()) {
        try {
            RdfCloudTripleStoreConnection conn = getRyaSailConnection();
            CloseableIteration<BindingSet, QueryEvaluationException> sol = (CloseableIteration<BindingSet, QueryEvaluationException>) conn.evaluate(minSp, null, bindings, false);
            Set<BindingSet> bSet = Sets.newHashSet();
            while (sol.hasNext()) {
                // TODO this is not optimal - should check if bindings variables intersect minSp variables
                // creating the following QueryBindingSet is only necessary if no intersection occurs
                QueryBindingSet bs = new QueryBindingSet();
                bs.addAll(sol.next());
                bs.addAll(bindings);
                bSet.add(bs);
            }
            List<StatementPattern> spList = starQuery.getNodes();
            spList.remove(minSp);
            StarQuery sq = new StarQuery(spList);
            conn.close();
            return new EntityTupleSet(sq, conf, true).evaluate(bSet);
        } catch (Exception e) {
            throw new QueryEvaluationException(e);
        }
    } else {
        this.evalOptUsed = true;
        return this.evaluate(Collections.singleton(bindings));
    }
}
Also used : CloseableIteration(info.aduna.iteration.CloseableIteration) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) CardinalityStatementPattern(org.apache.rya.indexing.accumulo.entity.StarQuery.CardinalityStatementPattern) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RdfCloudTripleStoreConnection(org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 3 with RdfCloudTripleStoreConnection

use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.

the class EntityTupleSet method getRyaSailConnection.

private RdfCloudTripleStoreConnection getRyaSailConnection() throws AccumuloException, AccumuloSecurityException, SailException {
    RdfCloudTripleStore store = new RdfCloudTripleStore();
    AccumuloRyaDAO crdfdao = new AccumuloRyaDAO();
    crdfdao.setConnector(accCon);
    AccumuloRdfConfiguration acc = new AccumuloRdfConfiguration(conf);
    crdfdao.setConf(acc);
    store.setRyaDAO(crdfdao);
    store.initialize();
    return (RdfCloudTripleStoreConnection) store.getConnection();
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) RdfCloudTripleStoreConnection(org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection)

Example 4 with RdfCloudTripleStoreConnection

use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.

the class RdfController method loadRdf.

@RequestMapping(value = "/loadrdf", method = RequestMethod.POST)
public void loadRdf(@RequestParam(required = false) final String format, @RequestParam(value = RdfCloudTripleStoreConfiguration.CONF_CV, required = false) final String cv, @RequestParam(required = false) final String graph, @RequestBody final String body, final HttpServletResponse response) throws RepositoryException, IOException, RDFParseException {
    RDFFormat format_r = RDFFormat.RDFXML;
    if (format != null) {
        format_r = RDFFormat.valueOf(format);
        if (format_r == null) {
            throw new RuntimeException("RDFFormat[" + format + "] not found");
        }
    }
    // add named graph as context (if specified).
    final List<Resource> contextList = new ArrayList<Resource>();
    if (graph != null) {
        contextList.add(VALUE_FACTORY.createURI(graph));
    }
    SailRepositoryConnection conn = null;
    try {
        conn = repository.getConnection();
        if (conn.getSailConnection() instanceof RdfCloudTripleStoreConnection && cv != null) {
            final RdfCloudTripleStoreConnection<?> sailConnection = (RdfCloudTripleStoreConnection<?>) conn.getSailConnection();
            sailConnection.getConf().set(RdfCloudTripleStoreConfiguration.CONF_CV, cv);
        }
        conn.add(new StringReader(body), "", format_r, contextList.toArray(new Resource[contextList.size()]));
        conn.commit();
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Resource(org.openrdf.model.Resource) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) RdfCloudTripleStoreConnection(org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection) RDFFormat(org.openrdf.rio.RDFFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RdfCloudTripleStoreConnection (org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection)4 CloseableIteration (info.aduna.iteration.CloseableIteration)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)1 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)1 CardinalityStatementPattern (org.apache.rya.indexing.accumulo.entity.StarQuery.CardinalityStatementPattern)1 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)1 Resource (org.openrdf.model.Resource)1 BindingSet (org.openrdf.query.BindingSet)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 Update (org.openrdf.query.Update)1 UpdateExecutionException (org.openrdf.query.UpdateExecutionException)1 StatementPattern (org.openrdf.query.algebra.StatementPattern)1 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)1 ParsedUpdate (org.openrdf.query.parser.ParsedUpdate)1 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)1 RDFFormat (org.openrdf.rio.RDFFormat)1