// TODO Replace IUpdate with a SparqlUpdateCommand private void UpdateInternal(IUpdate spinQuery, Uri outputGraphUri) { ISparqlPrinter sparqlFactory = new BaseSparqlPrinter(this); // TODO handle the current Execution Context while rewriting queries SparqlParameterizedString command = sparqlFactory.GetCommandText(spinQuery); command.SetUri("datasetUri", Configuration.BaseUri); command.SetUri("outputGraph", outputGraphUri); this.SaveConfiguration(); if (!(spinQuery is IInsertData || spinQuery is IDeleteData)) { CommandCalls.Add(command.ToString()); Storage.Update(command.ToString()); UpdateInternal(new DeleteDataImpl(RDF.Nil, spinProcessor), outputGraphUri); UpdateInternal(new InsertDataImpl(RDF.Nil, spinProcessor), outputGraphUri); ResetActiveGraph(); return; } SaveInMemoryChanges(); HashSet <Uri> dataGraphs = new HashSet <Uri>(RDFUtil.uriComparer); dataGraphs.UnionWith(spinQuery is IDeleteData ? Configuration.GetTriplesRemovalsGraphs() : Configuration.GetTriplesAdditionsGraphs()); try { Storage.Update(command.ToString()); _ignoreMonitoredChangeEvents = true; // TODO if needed : postpone this until full update execution is done to alleviate I/O foreach (IGraph synced in _synchronizedGraphs) { Uri changesGraphUri = spinQuery is IDeleteData?Configuration.GetTripleRemovalsMonitorUri(synced.BaseUri) : Configuration.GetTripleAdditionsMonitorUri(synced.BaseUri); IGraph changes = new ThreadSafeGraph(); Storage.LoadGraph(changes, changesGraphUri); if (spinQuery is IDeleteData) { synced.Retract(changes.Triples); } else { synced.Assert(changes.Triples); } } _ignoreMonitoredChangeEvents = false; } finally { foreach (Uri graphUri in dataGraphs) { Storage.DeleteGraph(graphUri); } } }
/// <summary> /// Process a SPIN query and return the SPARQL Update commands that it compiles to /// </summary> /// <param name="spinQuery"></param> /// <returns></returns> public String GetUpdateQuery(String spinQuery) { StringBuilder sb = new StringBuilder(); foreach (IUpdate update in _spinProcessor.BuildUpdate(spinQuery)) { this.SaveConfiguration(); BaseSparqlPrinter sparqlFactory = new BaseSparqlPrinter(this); sb.Append(sparqlFactory.GetCommandText(update)); sb.AppendLine(); } return(sb.ToString()); }
internal object ExecuteQuery(IQuery spinQuery) { ExecuteUpdate(); ISparqlPrinter sparqlFactory = new BaseSparqlPrinter(this); if (_queryExecutionMode != QueryMode.UserQuerying && spinQuery is IConstruct) { ExecuteUpdate((IConstruct)spinQuery); return(null); // TODO is this correct or should we return the execution graph ? } SparqlParameterizedString commandText = sparqlFactory.GetCommandText(spinQuery); return(Storage.Query(commandText.ToString())); }