public BrightstarSparqlResultSet ExecuteSparql(SparqlQuery query, IStore store) { try { var dataset = new StoreSparqlDataset(store); if (_defaultGraphUris != null) { dataset.SetDefaultGraph(_defaultGraphUris); } var queryProcessor = new BrightstarQueryProcessor(store, dataset); return(new BrightstarSparqlResultSet(queryProcessor.ProcessQuery(query))); } catch (Exception ex) { Logging.LogError(BrightstarEventId.SparqlExecutionError, "Error Executing Sparql {0}. Cause: {1}", query, ex); throw; } }
public void ExecuteSparql(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, string sparqlQuery, IStore store) { try { var query = ParseSparql(sparqlQuery); var dataset = new StoreSparqlDataset(store); if (_defaultGraphUris != null) { dataset.SetDefaultGraph(_defaultGraphUris); } var queryProcessor = new BrightstarQueryProcessor(store, dataset); queryProcessor.ProcessQuery(rdfHandler, resultsHandler, query); } catch (Exception ex) { Logging.LogError(BrightstarEventId.SparqlExecutionError, "Error Executing Sparql {0}. Cause: {1}", sparqlQuery, ex); throw; } }
/// <summary> /// Provides the required SPARQL query interface for the <see cref="BrightstarIOManager"/> used for SPARQL update support /// </summary> /// <param name="rdfHandler"></param> /// <param name="resultsHandler"></param> /// <param name="sparqlQuery"></param> /// <param name="store"></param> public void ExecuteSparql(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, string sparqlQuery, IStore store) { try { var query = ParseSparql(sparqlQuery); var dataset = new StoreSparqlDataset(store); if (_defaultGraphUris != null) { dataset.SetDefaultGraph(_defaultGraphUris); } var queryProcessor = new BrightstarQueryProcessor(store, dataset); queryProcessor.ProcessQuery(rdfHandler, resultsHandler, query); } catch (Exception ex) { Logging.LogError(BrightstarEventId.SparqlExecutionError, "Error Executing Sparql {0}. Cause: {1}", sparqlQuery, ex); throw; } }
public BrightstarSparqlResultSet ExecuteSparql(string expression, IStore store) { try { Logging.LogDebug("ExecuteSparql {0}", expression); var query = ParseSparql(expression); var dataset = new StoreSparqlDataset(store); if (_defaultGraphUris != null) { dataset.SetDefaultGraph(_defaultGraphUris); } var queryProcessor = new BrightstarQueryProcessor(store, dataset); return new BrightstarSparqlResultSet(queryProcessor.ProcessQuery(query)); } catch (Exception ex) { Logging.LogError(BrightstarEventId.SparqlExecutionError, "Error Executing Sparql {0}. Cause: {1}", expression, ex); throw; } }
public BrightstarSparqlResultsType ExecuteSparql(SparqlQuery query, IStore store, TextWriter resultsWriter) { try { EnsureValidResultFormat(query); var dataset = new StoreSparqlDataset(store); if (_defaultGraphUris != null) { dataset.SetDefaultGraph(_defaultGraphUris); } var queryProcessor = new BrightstarQueryProcessor(store, dataset); var queryResult = queryProcessor.ProcessQuery(query); if (queryResult is SparqlResultSet) { var sparqlResultSet = (SparqlResultSet) queryResult; ISparqlResultsWriter sparqlResultsWriter = null; if (_sparqlResultsFormat != null) { sparqlResultsWriter = MimeTypesHelper.GetSparqlWriter(new string[] {_sparqlResultsFormat.ToString()}); } if (sparqlResultsWriter == null) { throw new NoAcceptableFormatException(typeof (SparqlResultsFormat), "No acceptable format provided for writing a SPARQL result set."); } sparqlResultsWriter.Save(sparqlResultSet, resultsWriter); switch (sparqlResultSet.ResultsType) { case SparqlResultsType.Boolean: return BrightstarSparqlResultsType.Boolean; case SparqlResultsType.VariableBindings: return BrightstarSparqlResultsType.VariableBindings; default: throw new BrightstarInternalException("Unrecognized SPARQL result type"); } } if (queryResult is IGraph) { var g = (IGraph) queryResult; var rdfWriter = _rdfFormat == null ? null : MimeTypesHelper.GetWriter(new string[] {_rdfFormat.ToString()}); if (rdfWriter == null) { throw new NoAcceptableFormatException(typeof (RdfFormat), "No acceptable format provided for writing an RDF graph result."); } rdfWriter.Save(g, resultsWriter); return BrightstarSparqlResultsType.Graph; } throw new BrightstarInternalException( String.Format("Unexpected return type from QueryProcessor.ProcessQuery: {0}", queryResult.GetType())); } catch (Exception ex) { Logging.LogError(BrightstarEventId.SparqlExecutionError, "Error Executing query {0}. Cause: {1}", query.ToString(), ex); throw; } }
public BrightstarSparqlResultsType ExecuteSparql(SparqlQuery query, IStore store, TextWriter resultsWriter) { try { EnsureValidResultFormat(query); var dataset = new StoreSparqlDataset(store); if (_defaultGraphUris != null) { dataset.SetDefaultGraph(_defaultGraphUris); } var queryProcessor = new BrightstarQueryProcessor(store, dataset); var queryResult = queryProcessor.ProcessQuery(query); if (queryResult is SparqlResultSet) { var sparqlResultSet = (SparqlResultSet)queryResult; ISparqlResultsWriter sparqlResultsWriter = null; if (_sparqlResultsFormat != null) { sparqlResultsWriter = MimeTypesHelper.GetSparqlWriter(new string[] { _sparqlResultsFormat.ToString() }); } if (sparqlResultsWriter == null) { throw new NoAcceptableFormatException(typeof(SparqlResultsFormat), "No acceptable format provided for writing a SPARQL result set."); } sparqlResultsWriter.Save(sparqlResultSet, resultsWriter); switch (sparqlResultSet.ResultsType) { case SparqlResultsType.Boolean: return(BrightstarSparqlResultsType.Boolean); case SparqlResultsType.VariableBindings: return(BrightstarSparqlResultsType.VariableBindings); default: throw new BrightstarInternalException("Unrecognized SPARQL result type"); } } if (queryResult is IGraph) { var g = (IGraph)queryResult; var rdfWriter = _rdfFormat == null ? null : MimeTypesHelper.GetWriter(new string[] { _rdfFormat.ToString() }); if (rdfWriter == null) { throw new NoAcceptableFormatException(typeof(RdfFormat), "No acceptable format provided for writing an RDF graph result."); } rdfWriter.Save(g, resultsWriter); return(BrightstarSparqlResultsType.Graph); } throw new BrightstarInternalException( String.Format("Unexpected return type from QueryProcessor.ProcessQuery: {0}", queryResult.GetType())); } catch (Exception ex) { Logging.LogError(BrightstarEventId.SparqlExecutionError, "Error Executing query {0}. Cause: {1}", query.ToString(), ex); throw; } }