/// <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; } } }