Ejemplo n.º 1
0
 public void ExecuteSparql(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, string sparqlQuery, IStore store)
 {
     try
     {
         var query          = ParseSparql(sparqlQuery);
         var queryProcessor = new BrightstarQueryProcessor(store, new StoreSparqlDataset(store));
         queryProcessor.ProcessQuery(rdfHandler, resultsHandler, query);
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.SparqlExecutionError,
                          "Error Executing Sparql {0}. Cause: {1}",
                          sparqlQuery, ex);
         throw;
     }
 }
Ejemplo n.º 2
0
 public void ExecuteSparql(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, string sparqlQuery, IStore store)
 {
     try
     {
         var query = ParseSparql(sparqlQuery);
         var queryProcessor = new BrightstarQueryProcessor(store, new StoreSparqlDataset(store));
         queryProcessor.ProcessQuery(rdfHandler, resultsHandler, query);
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.SparqlExecutionError,
                          "Error Executing Sparql {0}. Cause: {1}",
                          sparqlQuery, ex);
         throw;
     }
 }
Ejemplo n.º 3
0
 public BrightstarSparqlResultSet ExecuteSparql(string expression, IStore store)
 {
     try
     {
         Logging.LogDebug("ExecuteSparql {0}", expression);
         var query          = ParseSparql(expression);
         var queryProcessor = new BrightstarQueryProcessor(store, new StoreSparqlDataset(store));
         return(new BrightstarSparqlResultSet(queryProcessor.ProcessQuery(query)));
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.SparqlExecutionError,
                          "Error Executing Sparql {0}. Cause: {1}",
                          expression, ex);
         throw;
     }
 }
Ejemplo n.º 4
0
 public BrightstarSparqlResultSet ExecuteSparql(string expression, IStore store)
 {
     try
     {
         Logging.LogDebug("ExecuteSparql {0}", expression);
         var query = ParseSparql(expression);
         var queryProcessor = new BrightstarQueryProcessor(store, new StoreSparqlDataset(store));
         return new BrightstarSparqlResultSet(queryProcessor.ProcessQuery(query));
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarEventId.SparqlExecutionError,
             "Error Executing Sparql {0}. Cause: {1}", 
             expression, ex);
         throw;
     }
 }
Ejemplo n.º 5
0
 public BrightstarSparqlResultSet ExecuteSparql(SparqlQuery query, IStore store)
 {
     try
     {
         var dataset = MakeDataset(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;
     }
 }
Ejemplo n.º 6
0
 /// <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 = MakeDataset(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;
     }
 }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
 /// <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 = MakeDataset(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;
     }
 }
Ejemplo n.º 10
0
        public BrightstarSparqlResultsType ExecuteSparql(SparqlQuery query, IStore store, TextWriter resultsWriter)
        {
            try
            {
                EnsureValidResultFormat(query);

                var dataset = MakeDataset(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);
                    try
                    {
                        resultsWriter.Flush();
                    }
                    catch (ObjectDisposedException)
                    {
                        // resultWriter is already closed
                    }
                    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;
            }
        }