org.eclipse.rdf4j.query.TupleQueryResultHandlerException Java Examples
The following examples show how to use
org.eclipse.rdf4j.query.TupleQueryResultHandlerException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SPARQLResultsCSVWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException { if (bindingNames == null) { throw new IllegalStateException("Must call startQueryResult before handleSolution"); } try { for (int i = 0; i < bindingNames.size(); i++) { String name = bindingNames.get(i); Value value = bindingSet.getValue(name); if (value != null) { writeValue(value); } if (i < bindingNames.size() - 1) { writer.write(","); } } writer.write("\r\n"); } catch (IOException e) { throw new TupleQueryResultHandlerException(e); } }
Example #2
Source File: AbstractSPARQLJSONWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void startQueryResult(List<String> columnHeaders) throws TupleQueryResultHandlerException { super.startQueryResult(columnHeaders); try { if (!documentOpen) { startDocument(); } if (!headerOpen) { startHeader(); } tupleVariablesFound = true; jg.writeArrayFieldStart("vars"); for (String nextColumn : columnHeaders) { jg.writeString(nextColumn); } jg.writeEndArray(); } catch (IOException | QueryResultHandlerException e) { throw new TupleQueryResultHandlerException(e); } }
Example #3
Source File: SPARQLResultsTSVWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException { if (!tupleVariablesFound) { throw new IllegalStateException("Must call startQueryResult before handleSolution"); } try { for (int i = 0; i < bindingNames.size(); i++) { String name = bindingNames.get(i); Value value = bindingSet.getValue(name); if (value != null) { writeValue(value); } if (i < bindingNames.size() - 1) { writer.write("\t"); } } writer.write("\n"); } catch (IOException e) { throw new TupleQueryResultHandlerException(e); } }
Example #4
Source File: CbSailProducer.java From rya with Apache License 2.0 | 6 votes |
protected void sparqlQuery(final Exchange exchange, final Collection<String> queries) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, RDFHandlerException { final List list = new ArrayList(); for (final String query : queries) { // Long startTime = exchange.getIn().getHeader(START_TIME_QUERY_PROP, Long.class); // Long ttl = exchange.getIn().getHeader(TTL_QUERY_PROP, Long.class); final String auth = exchange.getIn().getHeader(CONF_QUERY_AUTH, String.class); final Boolean infer = exchange.getIn().getHeader(CONF_INFER, Boolean.class); final Object output = performSelect(query, auth, infer); if (queries.size() == 1) { exchange.getOut().setBody(output); return; } else { list.add(output); } } exchange.getOut().setBody(list); }
Example #5
Source File: AbstractSPARQLXMLWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException { super.startQueryResult(bindingNames); try { if (!documentOpen) { startDocument(); } if (!headerOpen) { startHeader(); } tupleVariablesFound = true; // Write binding names for (String name : bindingNames) { xmlWriter.setAttribute(VAR_NAME_ATT, name); xmlWriter.emptyElement(VAR_TAG); } } catch (IOException | QueryResultHandlerException e) { throw new TupleQueryResultHandlerException(e); } }
Example #6
Source File: AbstractSPARQLXMLWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void endQueryResult() throws TupleQueryResultHandlerException { try { if (!documentOpen) { startDocument(); } if (!headerOpen) { startHeader(); } if (!headerComplete) { endHeader(); } if (!tupleVariablesFound) { throw new IllegalStateException("Could not end query result as startQueryResult was not called first."); } xmlWriter.endTag(RESULT_SET_TAG); endDocument(); } catch (IOException | QueryResultHandlerException e) { throw new TupleQueryResultHandlerException(e); } }
Example #7
Source File: MongoSpinIT.java From rya with Apache License 2.0 | 6 votes |
private Set<BindingSet> executeQuery(final URL queryFile) throws Exception { final SailRepositoryConnection conn = repository.getConnection(); try( final InputStream queryIS = queryFile.openStream(); final BufferedReader br = new BufferedReader(new InputStreamReader(queryIS, StandardCharsets.UTF_8)); ) { final String query = br.lines().collect(Collectors.joining("\n")); final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); final Set<BindingSet> solutions = new HashSet<>(); tupleQuery.evaluate(new AbstractTupleQueryResultHandler() { @Override public void handleSolution(final BindingSet bindingSet) throws TupleQueryResultHandlerException { solutions.add(bindingSet); } }); return solutions; } finally { closeQuietly(conn); } }
Example #8
Source File: DAWGTestResultSetUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static Model toGraph(TupleQueryResult tqr) throws QueryEvaluationException { Model graph = new TreeModel(); DAWGTestResultSetWriter writer = new DAWGTestResultSetWriter(new StatementCollector(graph)); try { writer.startQueryResult(tqr.getBindingNames()); while (tqr.hasNext()) { writer.handleSolution(tqr.next()); } writer.endQueryResult(); } catch (TupleQueryResultHandlerException e) { // No exceptions expected from DAWGTestResultSetWriter or // StatementCollector, foud a bug? throw new RuntimeException(e); } return graph; }
Example #9
Source File: AbstractSPARQLJSONWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException { try { if (!documentOpen) { startDocument(); } if (!headerOpen) { startHeader(); } if (!headerComplete) { endHeader(); } if (!tupleVariablesFound) { throw new IllegalStateException("Must call startQueryResult before handleSolution"); } firstTupleWritten = true; jg.writeStartObject(); Iterator<Binding> bindingIter = bindingSet.iterator(); while (bindingIter.hasNext()) { Binding binding = bindingIter.next(); jg.writeFieldName(binding.getName()); writeValue(binding.getValue()); } jg.writeEndObject(); } catch (IOException | QueryResultHandlerException e) { throw new TupleQueryResultHandlerException(e); } }
Example #10
Source File: AccumuloConstantPcjIT.java From rya with Apache License 2.0 | 5 votes |
@Before public void init() throws RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, RyaDAOException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException { repo = PcjIntegrationTestingUtil.getAccumuloNonPcjRepo(prefix, "instance"); conn = repo.getConnection(); pcjRepo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(prefix, "instance"); pcjConn = pcjRepo.getConnection(); final IRI sub = VF.createIRI("uri:entity"); subclass = VF.createIRI("uri:class"); obj = VF.createIRI("uri:obj"); talksTo = VF.createIRI("uri:talksTo"); conn.add(sub, RDF.TYPE, subclass); conn.add(sub, RDFS.LABEL, VF.createLiteral("label")); conn.add(sub, talksTo, obj); final IRI sub2 = VF.createIRI("uri:entity2"); subclass2 = VF.createIRI("uri:class2"); obj2 = VF.createIRI("uri:obj2"); conn.add(sub2, RDF.TYPE, subclass2); conn.add(sub2, RDFS.LABEL, VF.createLiteral("label2")); conn.add(sub2, talksTo, obj2); accCon = new MockInstance("instance").getConnector("root",new PasswordToken("")); }
Example #11
Source File: SPARQLResultsCSVWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void endQueryResult() throws TupleQueryResultHandlerException { if (bindingNames == null) { throw new IllegalStateException("Could not end query result as startQueryResult was not called first."); } try { writer.flush(); } catch (IOException e) { throw new TupleQueryResultHandlerException(e); } }
Example #12
Source File: MongoRyaDirectExample.java From rya with Apache License 2.0 | 5 votes |
public static void testAddNamespaces(final SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException { conn.setNamespace("rya", "http://rya.com"); final RepositoryResult<Namespace> results = conn.getNamespaces(); for (final Namespace space : Iterations.asList(results)){ System.out.println(space.getName() + ", " + space.getPrefix()); } }
Example #13
Source File: PrecompJoinOptimizerIT.java From rya with Apache License 2.0 | 5 votes |
@Before public void init() throws RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, AccumuloException, AccumuloSecurityException, TableExistsException, RyaDAOException, TableNotFoundException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException { repo = PcjIntegrationTestingUtil.getAccumuloNonPcjRepo(tablePrefix, "instance"); conn = repo.getConnection(); pcjRepo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(tablePrefix, "instance"); pcjConn = pcjRepo.getConnection(); sub = VF.createIRI("uri:entity"); subclass = VF.createIRI("uri:class"); obj = VF.createIRI("uri:obj"); talksTo = VF.createIRI("uri:talksTo"); conn.add(sub, RDF.TYPE, subclass); conn.add(sub, RDFS.LABEL, VF.createLiteral("label")); conn.add(sub, talksTo, obj); sub2 = VF.createIRI("uri:entity2"); subclass2 = VF.createIRI("uri:class2"); obj2 = VF.createIRI("uri:obj2"); conn.add(sub2, RDF.TYPE, subclass2); conn.add(sub2, RDFS.LABEL, VF.createLiteral("label2")); conn.add(sub2, talksTo, obj2); accCon = new MockInstance("instance").getConnector("root", new PasswordToken("")); }
Example #14
Source File: ConsoleQueryResultWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException { StringBuilder builder = new StringBuilder(512); for (String bindingName : bindingNames) { Value value = bindingSet.getValue(bindingName); String valueStr = (value != null) ? Util.getPrefixedValue(value, namespaces) : ""; builder.append("| ").append(valueStr); StringUtil.appendN(' ', columnWidth - valueStr.length(), builder); } builder.append("|"); consoleIO.writeln(builder.toString()); }
Example #15
Source File: AccumuloPcjIT.java From rya with Apache License 2.0 | 5 votes |
@Test public void testEvaluateOneIndex() throws PcjException, RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MalformedQueryException, SailException, QueryEvaluationException, TupleQueryResultHandlerException { final IRI superclass = VF.createIRI("uri:superclass"); final IRI superclass2 = VF.createIRI("uri:superclass2"); conn.add(subclass, RDF.TYPE, superclass); conn.add(subclass2, RDF.TYPE, superclass2); conn.add(obj, RDFS.LABEL, VF.createLiteral("label")); conn.add(obj2, RDFS.LABEL, VF.createLiteral("label2")); conn.add(obj, RDFS.LABEL, VF.createLiteral("label")); conn.add(obj2, RDFS.LABEL, VF.createLiteral("label2")); final String indexSparqlString = ""// + "SELECT ?dog ?pig ?duck " // + "{" // + " ?pig a ?dog . "// + " ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck "// + "}";// final CountingResultHandler crh1 = new CountingResultHandler(); final CountingResultHandler crh2 = new CountingResultHandler(); PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "dog", "pig", "duck" }, Optional.absent()); conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString) .evaluate(crh1); PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, prefix); pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString) .evaluate(crh2); Assert.assertEquals(crh1.count, crh2.count); }
Example #16
Source File: MongoDbRyaSailFactoryLoadFilesIT.java From rya with Apache License 2.0 | 5 votes |
private static int performTupleQuery(final String query, final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException { final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); tupleQuery.setMaxExecutionTime(10); final CountingResultHandler handler = new CountingResultHandler(); tupleQuery.evaluate(handler); return handler.getCount(); }
Example #17
Source File: HTTPTupleQuery.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException { SPARQLProtocolSession client = getHttpClient(); try { conn.flushTransactionState(Protocol.Action.QUERY); client.sendTupleQuery(queryLanguage, queryString, baseURI, dataset, includeInferred, getMaxExecutionTime(), handler, getBindingsArray()); } catch (IOException | RepositoryException | MalformedQueryException e) { throw new HTTPQueryEvaluationException(e.getMessage(), e); } }
Example #18
Source File: StatementMetadataExample.java From rya with Apache License 2.0 | 5 votes |
@Override public void endQueryResult() throws TupleQueryResultHandlerException { System.out.println("==================== END QUERY RESULTS ======================"); System.out.println(""); System.out.println(""); System.out.println(""); }
Example #19
Source File: RDF4JProtocolSession.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TupleQueryResult getRepositoryList() throws IOException, RepositoryException, UnauthorizedException, QueryInterruptedException { try { TupleQueryResultBuilder builder = new TupleQueryResultBuilder(); getRepositoryList(builder); return builder.getQueryResult(); } catch (TupleQueryResultHandlerException e) { // Found a bug in TupleQueryResultBuilder? throw new RuntimeException(e); } }
Example #20
Source File: AccumuloRyaSailFactoryLoadFilesIT.java From rya with Apache License 2.0 | 5 votes |
private static int performTupleQuery(final String query, final RepositoryConnection conn) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException { final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); tupleQuery.setMaxExecutionTime(10); final CountingResultHandler handler = new CountingResultHandler(); tupleQuery.evaluate(handler); return handler.getCount(); }
Example #21
Source File: RDF4JProtocolSession.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TupleQueryResult getNamespaces() throws IOException, RepositoryException, UnauthorizedException, QueryInterruptedException { try { TupleQueryResultBuilder builder = new TupleQueryResultBuilder(); getNamespaces(builder); return builder.getQueryResult(); } catch (TupleQueryResultHandlerException e) { // Found a bug in TupleQueryResultBuilder? throw new RuntimeException(e); } }
Example #22
Source File: BinaryQueryResultWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException { if (!tupleVariablesFound) { throw new IllegalStateException("Must call startQueryResult before handleSolution"); } try { if (bindingSet.size() == 0) { writeEmptyRow(); } else { for (String bindingName : bindingNames) { Value value = bindingSet.getValue(bindingName); if (value == null) { writeNull(); } else if (value.equals(previousBindings.getValue(bindingName))) { writeRepeat(); } else { writeValue(value); } } previousBindings = bindingSet; } } catch (IOException e) { throw new TupleQueryResultHandlerException(e); } }
Example #23
Source File: BinaryQueryResultWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void endQueryResult() throws TupleQueryResultHandlerException { if (!tupleVariablesFound) { throw new IllegalStateException("Could not end query result as startQueryResult was not called first."); } try { out.writeByte(TABLE_END_RECORD_MARKER); endDocument(); } catch (IOException e) { throw new TupleQueryResultHandlerException(e); } }
Example #24
Source File: GeowaveDirectExample.java From rya with Apache License 2.0 | 5 votes |
private static void testGeoFreetextWithPCJSearch( final SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException { // ring outside point final String queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// + "PREFIX fts: <http://rdf.useekm.com/fts#> "// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "// + "SELECT ?feature ?point ?wkt ?e ?c ?l ?o ?person ?match " // + "{" // + " ?person a <http://example.org/ontology/Person> . "// + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . "// + " FILTER(fts:text(?match, \"!alice & hose\")) " // + " ?e a ?c . "// + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + " ?e <uri:talksTo> ?o . "// + " ?feature a geo:Feature . "// + " ?feature geo:hasGeometry ?point . "// + " ?point a geo:Point . "// + " ?point geo:asWKT ?wkt . "// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " // + "}";// final TupleQuery tupleQuery = conn.prepareTupleQuery( QueryLanguage.SPARQL, queryString); final CountingResultHandler tupleHandler = new CountingResultHandler(); tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 0);// TODO ==1 some data is missing for this query! }
Example #25
Source File: AbstractSPARQLXMLWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException { try { if (!documentOpen) { startDocument(); } if (!headerOpen) { startHeader(); } if (!headerComplete) { endHeader(); } if (!tupleVariablesFound) { throw new IllegalStateException("Must call startQueryResult before handleSolution"); } xmlWriter.startTag(RESULT_TAG); for (Binding binding : bindingSet) { xmlWriter.setAttribute(BINDING_NAME_ATT, binding.getName()); xmlWriter.startTag(BINDING_TAG); writeValue(binding.getValue()); xmlWriter.endTag(BINDING_TAG); } xmlWriter.endTag(RESULT_TAG); } catch (IOException | QueryResultHandlerException e) { throw new TupleQueryResultHandlerException(e); } }
Example #26
Source File: RDF4JProtocolSession.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TupleQueryResult getContextIDs() throws IOException, RepositoryException, UnauthorizedException, QueryInterruptedException { try { TupleQueryResultBuilder builder = new TupleQueryResultBuilder(); getContextIDs(builder); return builder.getQueryResult(); } catch (TupleQueryResultHandlerException e) { // Found a bug in TupleQueryResultBuilder? throw new RuntimeException(e); } }
Example #27
Source File: BinaryQueryResultWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void startDocument() throws TupleQueryResultHandlerException { documentStarted = true; try { out.write(MAGIC_NUMBER); out.writeInt(FORMAT_VERSION); } catch (IOException e) { throw new TupleQueryResultHandlerException(e); } }
Example #28
Source File: SPARQLResultsSAXParser.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void endDocument() throws SAXException { try { if (handler != null) { handler.endQueryResult(); } } catch (TupleQueryResultHandlerException e) { throw new SAXException(e); } }
Example #29
Source File: SPARQLTSVTupleTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void assertQueryResultsEqual(TupleQueryResult expected, TupleQueryResult output) throws QueryEvaluationException, TupleQueryResultHandlerException, QueryResultHandlerException, UnsupportedEncodingException { MutableTupleQueryResult r1 = new MutableTupleQueryResult(expected); MutableTupleQueryResult r2 = new MutableTupleQueryResult(output); if (!QueryResults.equals(r1, r2)) { r1.beforeFirst(); r2.beforeFirst(); assertEquals(toString(r1), toString(r2)); r2.beforeFirst(); fail(toString(r2)); } }
Example #30
Source File: SPARQLTSVTupleBackgroundTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void assertQueryResultsEqual(TupleQueryResult expected, TupleQueryResult output) throws QueryEvaluationException, TupleQueryResultHandlerException, QueryResultHandlerException, UnsupportedEncodingException { MutableTupleQueryResult r1 = new MutableTupleQueryResult(expected); MutableTupleQueryResult r2 = new MutableTupleQueryResult(output); if (!QueryResults.equals(r1, r2)) { r1.beforeFirst(); r2.beforeFirst(); assertEquals(toString(r1), toString(r2)); r2.beforeFirst(); fail(toString(r2)); } }