Search in sources :

Example 1 with QueryResultHandlerException

use of org.openrdf.query.QueryResultHandlerException in project incubator-rya by apache.

the class RdfCloudTripleStoreConnectionTest method testNamespaceUsage.

public void testNamespaceUsage() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    conn.setNamespace("lit", litdupsNS);
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    final URI uri1 = vf.createURI(litdupsNS, "uri1");
    conn.add(cpu, loadPerc, uri1);
    conn.commit();
    String query = "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {lit:cpu lit:loadPerc ?o.}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleQuery.evaluate(new TupleQueryResultHandler() {

        @Override
        public void startQueryResult(List<String> strings) throws TupleQueryResultHandlerException {
        }

        @Override
        public void endQueryResult() throws TupleQueryResultHandlerException {
        }

        @Override
        public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
            assertTrue(uri1.toString().equals(bindingSet.getBinding("o").getValue().stringValue()));
        }

        @Override
        public void handleBoolean(boolean paramBoolean) throws QueryResultHandlerException {
        }

        @Override
        public void handleLinks(List<String> paramList) throws QueryResultHandlerException {
        }
    });
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) BindingSet(org.openrdf.query.BindingSet) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) TupleQuery(org.openrdf.query.TupleQuery) TupleQueryResultHandler(org.openrdf.query.TupleQueryResultHandler) QueryResultHandlerException(org.openrdf.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) URI(org.openrdf.model.URI)

Example 2 with QueryResultHandlerException

use of org.openrdf.query.QueryResultHandlerException in project incubator-rya by apache.

the class InferenceIT method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    dao = new AccumuloRyaDAO();
    connector = new MockInstance().getConnector("", new PasswordToken(""));
    dao.setConnector(connector);
    conf = new AccumuloRdfConfiguration();
    conf.setInfer(true);
    dao.setConf(conf);
    dao.init();
    store = new RdfCloudTripleStore();
    store.setConf(conf);
    store.setRyaDAO(dao);
    inferenceEngine = new InferenceEngine();
    inferenceEngine.setRyaDAO(dao);
    store.setInferenceEngine(inferenceEngine);
    inferenceEngine.refreshGraph();
    store.initialize();
    repository = new SailRepository(store);
    conn = repository.getConnection();
    solutions = new LinkedList<>();
    resultHandler = new TupleQueryResultHandler() {

        @Override
        public void endQueryResult() throws TupleQueryResultHandlerException {
        }

        @Override
        public void handleBoolean(final boolean value) throws QueryResultHandlerException {
        }

        @Override
        public void handleLinks(final List<String> linkUrls) throws QueryResultHandlerException {
        }

        @Override
        public void handleSolution(final BindingSet bindingSet) throws TupleQueryResultHandlerException {
            if (bindingSet != null && bindingSet.iterator().hasNext()) {
                solutions.add(bindingSet);
            }
        }

        @Override
        public void startQueryResult(final List<String> bindingNames) throws TupleQueryResultHandlerException {
            solutions.clear();
        }
    };
}
Also used : AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) BindingSet(org.openrdf.query.BindingSet) ListBindingSet(org.openrdf.query.impl.ListBindingSet) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) SailRepository(org.openrdf.repository.sail.SailRepository) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) TupleQueryResultHandler(org.openrdf.query.TupleQueryResultHandler) QueryResultHandlerException(org.openrdf.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException)

Example 3 with QueryResultHandlerException

use of org.openrdf.query.QueryResultHandlerException in project incubator-rya by apache.

the class RdfController method performQuery.

private void performQuery(final String query, final RepositoryConnection conn, final String auth, final String infer, final String nullout, final TupleQueryResultHandler handler) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException {
    final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    if (auth != null && auth.length() > 0) {
        tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, VALUE_FACTORY.createLiteral(auth));
    }
    if (infer != null && infer.length() > 0) {
        tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_INFER, VALUE_FACTORY.createLiteral(Boolean.parseBoolean(infer)));
    }
    if (nullout != null && nullout.length() > 0) {
        // output nothing, but still run query
        tupleQuery.evaluate(new TupleQueryResultHandler() {

            @Override
            public void startQueryResult(final List<String> strings) throws TupleQueryResultHandlerException {
            }

            @Override
            public void endQueryResult() throws TupleQueryResultHandlerException {
            }

            @Override
            public void handleSolution(final BindingSet bindings) throws TupleQueryResultHandlerException {
            }

            @Override
            public void handleBoolean(final boolean arg0) throws QueryResultHandlerException {
            }

            @Override
            public void handleLinks(final List<String> arg0) throws QueryResultHandlerException {
            }
        });
    } else {
        final CountingTupleQueryResultHandlerWrapper sparqlWriter = new CountingTupleQueryResultHandlerWrapper(handler);
        final long startTime = System.currentTimeMillis();
        tupleQuery.evaluate(sparqlWriter);
        log.info(String.format("Query Time = %.3f   Result Count = %s\n", (System.currentTimeMillis() - startTime) / 1000., sparqlWriter.getCount()));
    }
}
Also used : BindingSet(org.openrdf.query.BindingSet) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) ParsedTupleQuery(org.openrdf.query.parser.ParsedTupleQuery) TupleQuery(org.openrdf.query.TupleQuery) TupleQueryResultHandler(org.openrdf.query.TupleQueryResultHandler) QueryResultHandlerException(org.openrdf.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException)

Aggregations

BindingSet (org.openrdf.query.BindingSet)3 QueryResultHandlerException (org.openrdf.query.QueryResultHandlerException)3 TupleQueryResultHandler (org.openrdf.query.TupleQueryResultHandler)3 TupleQueryResultHandlerException (org.openrdf.query.TupleQueryResultHandlerException)3 TupleQuery (org.openrdf.query.TupleQuery)2 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)1 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)1 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)1 URI (org.openrdf.model.URI)1 ListBindingSet (org.openrdf.query.impl.ListBindingSet)1 ParsedTupleQuery (org.openrdf.query.parser.ParsedTupleQuery)1 RepositoryConnection (org.openrdf.repository.RepositoryConnection)1 SailRepository (org.openrdf.repository.sail.SailRepository)1