public void SparqlUpdateCreateDrop() { TripleStore store = new TripleStore(); Console.WriteLine("Store has " + store.Graphs.Count + " Graphs"); //Create a couple of Graphs using Create Commands CreateCommand create1 = new CreateCommand(new Uri("http://example.org/1")); CreateCommand create2 = new CreateCommand(new Uri("http://example.org/2")); store.ExecuteUpdate(create1); store.ExecuteUpdate(create2); Assert.AreEqual(3, store.Graphs.Count, "Store should have now had three Graphs"); Assert.AreEqual(0, store.Triples.Count(), "Store should have no triples at this point"); //Trying the same Create again should cause an error try { store.ExecuteUpdate(create1); Assert.Fail("Executing a CREATE command twice without the SILENT modifier should error"); } catch (SparqlUpdateException) { Console.WriteLine("Executing a CREATE command twice without the SILENT modifier errored as expected"); } //Equivalent Create with SILENT should not error CreateCommand create3 = new CreateCommand(new Uri("http://example.org/1"), true); try { store.ExecuteUpdate(create3); Console.WriteLine("Executing a CREATE for an existing Graph with the SILENT modifier suppressed the error as expected"); } catch (SparqlUpdateException) { Assert.Fail("Executing a CREATE for an existing Graph with the SILENT modifier should not error"); } DropCommand drop1 = new DropCommand(new Uri("http://example.org/1")); store.ExecuteUpdate(drop1); Assert.AreEqual(2, store.Graphs.Count, "Store should have only 2 Graphs after we executed the DROP command"); try { store.ExecuteUpdate(drop1); Assert.Fail("Trying to DROP a non-existent Graph should error"); } catch (SparqlUpdateException) { Console.WriteLine("Trying to DROP a non-existent Graph produced an error as expected"); } DropCommand drop2 = new DropCommand(new Uri("http://example.org/1"), ClearMode.Graph, true); try { store.ExecuteUpdate(drop2); Console.WriteLine("Trying to DROP a non-existent Graph with the SILENT modifier suppressed the error as expected"); } catch (SparqlUpdateException) { Assert.Fail("Trying to DROP a non-existent Graph with the SILENT modifier should suppress the error"); } }
/// <summary> /// Processes a CREATE command /// </summary> /// <param name="cmd">Create Command</param> public void ProcessCreateCommand(CreateCommand cmd) { this.ProcessCommand(cmd); }
/// <summary> /// Processes a CREATE command /// </summary> /// <param name="cmd">Create Command</param> /// <remarks> /// <para> /// Implemented by adding an empty Graph to the Store /// </para> /// <para> /// <strong>Warning:</strong> As the <see cref="IGenericIOManager">IGenericIOManager</see> interface does not allow checking whether a Graph exists processing CREATE commands can result in overwriting existing Graphs /// </para> /// </remarks> public void ProcessCreateCommand(CreateCommand cmd) { if (this._manager is IUpdateableGenericIOManager) { ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString()); } else { Graph g = new Graph(); g.BaseUri = cmd.TargetUri; try { //As Khalil Ahmed pointed out the behaviour when the store doesn't support empty graphs the behaviour should be to act as if the operation succeeded if ((this._manager.IOBehaviour & IOBehaviour.ExplicitEmptyGraphs) == 0) return; this._manager.SaveGraph(g); } catch { if (!cmd.Silent) throw; } } }
/// <summary> /// Processes a CREATE command /// </summary> /// <param name="cmd">Create Command</param> /// <remarks> /// <para> /// Implemented by adding an empty Graph to the Store /// </para> /// <para> /// <strong>Warning:</strong> As the <see cref="IGenericIOManager">IGenericIOManager</see> interface does not allow checking whether a Graph exists processing CREATE commands can result in overwriting existing Graphs /// </para> /// </remarks> public void ProcessCreateCommand(CreateCommand cmd) { if (this._manager is IUpdateableGenericIOManager) { ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString()); } else { Graph g = new Graph(); g.BaseUri = cmd.TargetUri; try { this._manager.SaveGraph(g); } catch { if (!cmd.Silent) throw; } } }
/// <summary> /// Processes a CREATE command /// </summary> /// <param name="cmd">Create Command</param> /// <param name="context">SPARQL Update Evaluation Context</param> protected virtual void ProcessCreateCommandInternal(CreateCommand cmd, SparqlUpdateEvaluationContext context) { cmd.Evaluate(context); }
/// <summary> /// Processes a CREATE command /// </summary> /// <param name="cmd">Create Command</param> public void ProcessCreateCommand(CreateCommand cmd) { this.ProcessCreateCommandInternal(cmd, this.GetContext()); }
private void TryParseCreateCommand(SparqlUpdateParserContext context) { bool silent = false; //May possibly have a SILENT Keyword IToken next = context.Tokens.Dequeue(); if (next.TokenType == Token.SILENT) { silent = true; next = context.Tokens.Dequeue(); } //Followed by a mandatory GRAPH Keyword if (next.TokenType != Token.GRAPH) { throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a GRAPH Keyword as part of the CREATE command", next); } //Then MUST have a URI Uri u = this.TryParseGraphRef(context); CreateCommand cmd = new CreateCommand(u, silent); context.CommandSet.AddCommand(cmd); }