/// <summary> /// Processes a CLEAR command /// </summary> /// <param name="cmd">Clear Command</param> public void ProcessClearCommand(ClearCommand cmd) { this.ProcessCommand(cmd); }
new public void ProcessClearCommand(ClearCommand cmd) { switch (cmd.Mode) { case ClearMode.Default: case ClearMode.Graph: _manager.DeleteGraph(cmd.TargetUri); break; case ClearMode.Named: _manager.DeleteGraphs(_manager.ListGraphs().Select(u=>u.ToString())); break; case ClearMode.All: _manager.DeleteGraphs(_manager.ListGraphs().Select(u=>u.ToString()).Union(new string[]{Constants.DefaultGraphUri})); break; } }
/// <summary> /// Processes a CLEAR command /// </summary> /// <param name="cmd">Clear Command</param> /// <remarks> /// Implemented by replacing the Graph with an empty Graph /// </remarks> public void ProcessClearCommand(ClearCommand cmd) { if (this._manager is IUpdateableGenericIOManager) { ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString()); } else { try { IGraph g; switch (cmd.Mode) { case ClearMode.Default: case ClearMode.Graph: if (cmd.TargetUri == null && (this._manager.IOBehaviour & IOBehaviour.HasDefaultGraph) == 0) throw new SparqlUpdateException("Unable to clear the default graph as the underlying store does not support an explicit default graph"); if (cmd.TargetUri != null && (this._manager.IOBehaviour & IOBehaviour.HasNamedGraphs) == 0) throw new SparqlUpdateException("Unable to clear a named graph as the underlying store does not support named graphs"); if ((cmd.TargetUri == null && (this._manager.IOBehaviour & IOBehaviour.OverwriteDefault) != 0) || (cmd.TargetUri != null && (this._manager.IOBehaviour & IOBehaviour.OverwriteNamed) != 0)) { //Can approximate by saving an empty Graph over the existing Graph g = new Graph(); g.BaseUri = cmd.TargetUri; this._manager.SaveGraph(g); } else if (this._manager.UpdateSupported && (this._manager.IOBehaviour & IOBehaviour.CanUpdateDeleteTriples) != 0) { //Can approximate by loading the Graph and then deleting all Triples from it g = new NonIndexedGraph(); this._manager.LoadGraph(g, cmd.TargetUri); this._manager.UpdateGraph(cmd.TargetUri, null, g.Triples); } else { throw new SparqlUpdateException("Unable to evaluate a CLEAR command as the underlying store does not provide appropriate IO Behaviour to approximate this command"); } break; case ClearMode.Named: case ClearMode.All: if ((this._manager.IOBehaviour & IOBehaviour.HasNamedGraphs) == 0) throw new SparqlUpdateException("Unable to clear named graphs as the underlying store does not support named graphs"); if (this._manager.ListGraphsSupported) { List<Uri> graphs = this._manager.ListGraphs().ToList(); foreach (Uri u in graphs) { if ((u == null && (this._manager.IOBehaviour & IOBehaviour.OverwriteDefault) != 0) || (u != null && (this._manager.IOBehaviour & IOBehaviour.OverwriteNamed) != 0)) { //Can approximate by saving an empty Graph over the existing Graph g = new Graph(); g.BaseUri = u; this._manager.SaveGraph(g); } else if (this._manager.UpdateSupported && (this._manager.IOBehaviour & IOBehaviour.CanUpdateDeleteTriples) != 0) { //Can approximate by loading the Graph and then deleting all Triples from it g = new NonIndexedGraph(); this._manager.LoadGraph(g, u); this._manager.UpdateGraph(u, null, g.Triples); } else { throw new SparqlUpdateException("Unable to evaluate a CLEAR command as the underlying store does not provide appropriate IO Behaviour to approximate this command"); } } } else { throw new NotSupportedException("The Generic Update processor does not support this form of the CLEAR command"); } break; } } catch { if (!cmd.Silent) throw; } } }
/// <summary> /// Processes a CLEAR command /// </summary> /// <param name="cmd">Clear Command</param> /// <remarks> /// Implemented by replacing the Graph with an empty Graph /// </remarks> public void ProcessClearCommand(ClearCommand cmd) { if (this._manager is IUpdateableGenericIOManager) { ((IUpdateableGenericIOManager)this._manager).Update(cmd.ToString()); } else { try { Graph g; switch (cmd.Mode) { case ClearMode.Default: case ClearMode.Graph: g = new Graph(); g.BaseUri = cmd.TargetUri; this._manager.SaveGraph(g); break; case ClearMode.Named: case ClearMode.All: if (this._manager.ListGraphsSupported) { List<Uri> graphs = this._manager.ListGraphs().ToList(); foreach (Uri u in graphs) { g = new Graph(); g.BaseUri = u; this._manager.SaveGraph(g); } } else { throw new NotSupportedException("The Generic Update processor does not support this form of the CLEAR command"); } break; } } catch { if (!cmd.Silent) throw; } } }
/// <summary> /// Processes a CLEAR command /// </summary> /// <param name="cmd">Clear Command</param> /// <param name="context">SPARQL Update Evaluation Context</param> protected virtual void ProcessClearCommandInternal(ClearCommand cmd, SparqlUpdateEvaluationContext context) { cmd.Evaluate(context); }
/// <summary> /// Processes a CLEAR command /// </summary> /// <param name="cmd">Clear Command</param> public void ProcessClearCommand(ClearCommand cmd) { this.ProcessClearCommandInternal(cmd, this.GetContext()); }
private void TryParseClearCommand(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(); } //Then expect a GRAPH followed by a URI or one of the DEFAULT/NAMED/ALL keywords if (next.TokenType == Token.GRAPH) { Uri u = this.TryParseGraphRef(context); ClearCommand cmd = new ClearCommand(u, ClearMode.Graph, silent); context.CommandSet.AddCommand(cmd); } else if (next.TokenType == Token.DEFAULT) { context.CommandSet.AddCommand(new ClearCommand(ClearMode.Default, silent)); } else if (next.TokenType == Token.NAMED) { context.CommandSet.AddCommand(new ClearCommand(ClearMode.Named, silent)); } else if (next.TokenType == Token.ALLWORD) { context.CommandSet.AddCommand(new ClearCommand(ClearMode.All, silent)); } else { throw ParserHelper.Error("Unexpected Token '" + next.GetType().ToString() + "' encountered, expected a GRAPH <URI> to specify the Graph to CLEAR or one of the DEFAULT/NAMED/ALL keywords", next); } }