/// <summary> /// Executes a query on the store which does not expect a result. /// </summary> /// <param name="update">SPARQL Update to be executed.</param> /// <param name="transaction">An optional transaction.</param> public override void ExecuteNonQuery(SparqlUpdate update, ITransaction transaction = null) { if (!_connector.UpdateSupported) { throw new Exception("This store does not support SPARQL update."); } string q = update.ToString(); if (_stardogTransaction?.IsActive ?? false) { Log?.Invoke($"**{q}"); var converter = new StardogUpdateSparqlConverter(this); converter.ParseQuery(q); Log?.Invoke($"UpdateGraph,{converter.Additions.Count},{converter.Removals.Count},{JsonConvert.SerializeObject(converter.Additions)},{JsonConvert.SerializeObject(converter.Removals)}"); _stardogTransaction.AddTripleCount += converter.Additions.Count; _stardogTransaction.RemoveTripleCount += converter.Removals.Count; _connector.UpdateGraph(converter.GraphUri, converter.Additions, converter.Removals); } else { // No transaction so just call update with the query Log?.Invoke(q); _connector.Update(q); } }
public void PersistTriples(string graphIri, HashSet <model.rdf.Triple> triplesToPersist) { _logger.LogTrace("Persisting triples into graph with IRI '{0}'. Triples: {1}", graphIri, triplesToPersist); IGraph model = _rdf4jMapper.TriplesToGraph(triplesToPersist); var tryMore = true; model.BaseUri = new Uri(graphIri); for (var i = 0; i < NUMBER_OF_ATTEMPTS && tryMore; i++) { try { if (_repository.HasGraph(model.BaseUri)) { _stardogGraphConnector.UpdateGraph(model.BaseUri, model.Triples, null); } else { _stardogGraphConnector.SaveGraph(model); } tryMore = false; } catch (Exception ex) { _logger.LogError("Exception was thrown while adding a model to the repository.", ex); } } _logger.LogTrace("Persisted {0} triples into the <{1}> graph.", triplesToPersist.Count, graphIri); }