public void SparqlUpdateLoad() { TripleStore store = new TripleStore(); LoadCommand loadLondon = new LoadCommand(new Uri("http://dbpedia.org/resource/London")); LoadCommand loadSouthampton = new LoadCommand(new Uri("http://dbpedia.org/resource/Southampton"), new Uri("http://example.org")); store.ExecuteUpdate(loadLondon); store.ExecuteUpdate(loadSouthampton); Assert.AreEqual(2, store.Graphs.Count, "Should now be 2 Graphs in the Store"); Assert.AreNotEqual(0, store.Triples.Count(), "Should be some Triples in the Store"); foreach (IGraph g in store.Graphs) { foreach (Triple t in g.Triples) { Console.Write(t.ToString()); if (g.BaseUri != null) { Console.WriteLine(" from " + g.BaseUri.ToString()); } else { Console.WriteLine(); } } } }
/// <summary> /// Processes a LOAD command /// </summary> /// <param name="cmd">Load Command</param> public void ProcessLoadCommand(LoadCommand cmd) { this.ProcessCommand(cmd); }
/// <summary> /// Processes a LOAD command /// </summary> /// <param name="cmd">Load Command</param> public void ProcessLoadCommand(LoadCommand cmd) { if (this._manager is IUpdateableGenericIOManager) { ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString()); } else { try { //Check IO Behaviour //For a load which is essentially an insert we either need the ability to Update Add Triples or to Overwrite Graphs if (cmd.TargetUri == null) { //Must support notion of default graph if ((this._manager.IOBehaviour & IOBehaviour.HasDefaultGraph) == 0) throw new SparqlUpdateException("The underlying store does not support the notion of an explicit unnamed Default Graph required to process this command"); //Must allow either OverwriteDefault or CanUpdateDeleteTriples if ((this._manager.IOBehaviour & IOBehaviour.CanUpdateAddTriples) == 0 && (this._manager.IOBehaviour & IOBehaviour.OverwriteDefault) == 0) throw new SparqlUpdateException("The underlying store does not support the required IO Behaviour to implement this command"); } else { //Must support named graphs if ((this._manager.IOBehaviour & IOBehaviour.HasNamedGraphs) == 0) throw new SparqlUpdateException("The underlying store does not support the notion of named graphs required to process this command"); //Must allow either CanUpdateDeleteTriples or OverwriteNamed if ((this._manager.IOBehaviour & IOBehaviour.CanUpdateAddTriples) == 0 && (this._manager.IOBehaviour & IOBehaviour.OverwriteNamed) == 0) throw new SparqlUpdateException("The underlying store does not support the required IO Behaviour to implement this command"); } #if !NO_SYNC_HTTP Graph g = new Graph(); if (!this._manager.UpdateSupported) this._manager.LoadGraph(g, cmd.TargetUri); UriLoader.Load(g, cmd.SourceUri); g.BaseUri = cmd.TargetUri; if (this._manager.UpdateSupported) { this._manager.UpdateGraph(cmd.TargetUri, g.Triples, Enumerable.Empty<Triple>()); } else { this._manager.SaveGraph(g); } #else throw new SparqlUpdateException("Executing the LOAD command requires synchronous HTTP requests which are not supported on your platform currently"); #endif } catch { if (!cmd.Silent) throw; } } }
/// <summary> /// Processes a LOAD command /// </summary> /// <param name="cmd">Load Command</param> public void ProcessLoadCommand(LoadCommand cmd) { if (this._manager is IUpdateableGenericIOManager) { ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString()); } else { try { Graph g = new Graph(); if (!this._manager.UpdateSupported) this._manager.LoadGraph(g, cmd.TargetUri); UriLoader.Load(g, cmd.SourceUri); g.BaseUri = cmd.TargetUri; if (this._manager.UpdateSupported) { this._manager.UpdateGraph(cmd.TargetUri, g.Triples, Enumerable.Empty<Triple>()); } else { this._manager.SaveGraph(g); } } catch { if (!cmd.Silent) throw; } } }
/// <summary> /// Processes a LOAD command /// </summary> /// <param name="cmd">Load Command</param> /// <param name="context">SPARQL Update Evaluation Context</param> protected virtual void ProcessLoadCommandInternal(LoadCommand cmd, SparqlUpdateEvaluationContext context) { cmd.Evaluate(context); }
/// <summary> /// Processes a LOAD command /// </summary> /// <param name="cmd">Load Command</param> public void ProcessLoadCommand(LoadCommand cmd) { this.ProcessLoadCommandInternal(cmd, this.GetContext()); }
private void TryParseLoadCommand(SparqlUpdateParserContext context) { LoadCommand cmd; String baseUri = context.BaseUri.ToSafeString(); //May optionally have a SILENT keyword bool silent = false; if (context.Tokens.Peek().TokenType == Token.SILENT) { silent = true; context.Tokens.Dequeue(); } //Expect a URI which is the Source URI Uri sourceUri = this.TryParseIriRef(context, "to LOAD data from"); //Then optionally an INTO GRAPH followed by a Graph URI to assign if (context.Tokens.Count > 0) { IToken next = context.Tokens.Peek(); if (next.TokenType == Token.INTO) { context.Tokens.Dequeue(); next = context.Tokens.Dequeue(); if (next.TokenType == Token.GRAPH) { Uri destUri = this.TryParseGraphRef(context); cmd = new LoadCommand(sourceUri, destUri, silent); } else { throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a GRAPH keyword after the INTO keyword for a LOAD command", next); } } else { cmd = new LoadCommand(sourceUri, silent); } } else { cmd = new LoadCommand(sourceUri, silent); } context.CommandSet.AddCommand(cmd); }