/// <summary> /// Deletes an Object from the underlying Store using SPARQL Update /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> public void DeleteObject(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) { throw new ArgumentNullException("oc", "Cannot delete a Null Object"); } SparqlUpdateCommandSet cmds = this._parser.ParseFromString(this.GetDeletionCommandText(oc, graphUri, mode)); this._underlyingProcessor.ProcessCommandSet(cmds); }
public DeletionAction(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { this._oc = oc; this._graphUri = graphUri; this._mode = mode; }
/// <summary> /// Gets the Text of the SPARQL Update Command which will be used to Delete the Object from the underlying Store /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> /// <returns></returns> public String GetDeletionCommandText(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) { throw new ArgumentNullException("oc", "Cannot delete a Null Object"); } StringBuilder persistCommand = new StringBuilder(); switch (mode) { case LinqDeleteMode.DeleteAll: //Delete all the Triples with this Object's Instance URI as the Subject/Object //Start building a pair of DELETE WHERE commands persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.AppendLine(" ?p ?o ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the first DELETE WHERE command persistCommand.AppendLine("} ;"); //Create the second DELETE WHERE command persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append("?s ?p "); persistCommand.AppendLine(this.FormatAsUri(oc.InstanceUri) + " ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the second DELETE WHERE command persistCommand.AppendLine("} ;"); return(persistCommand.ToString()); case LinqDeleteMode.DeleteValues: //Delete the specific Values associated with this Object Type t = oc.GetType(); PropertyInfo[] propInfo = t.GetProperties(); //Start building an DELETE DATA command persistCommand.AppendLine("DELETE DATA {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } //Assert the Type Triple persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.Append(" a "); persistCommand.Append(this.FormatAsUri(OwlClassSupertype.GetOwlClassUri(t))); persistCommand.AppendLine(" ."); //Assert Triples for annotated properties Graph g = new Graph(); foreach (PropertyInfo info in propInfo) { this.GetTripleText(oc, info, g, persistCommand); } //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the DELETE DATA command persistCommand.AppendLine("}"); return(persistCommand.ToString()); default: throw new LinqToRdfException("Not a valid Linq Delete Mode"); } }
/// <summary> /// Deletes an Object from the underlying Store using SPARQL Update /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> public void DeleteObject(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) throw new ArgumentNullException("oc", "Cannot delete a Null Object"); SparqlUpdateCommandSet cmds = this._parser.ParseFromString(this.GetDeletionCommandText(oc, graphUri, mode)); this._underlyingProcessor.ProcessCommandSet(cmds); }
/// <summary> /// Gets the Text of the SPARQL Update Command which will be used to Delete the Object from the underlying Store /// </summary> /// <param name="oc">Object</param> /// <param name="graphUri">URI of the Graph to delete from</param> /// <param name="mode">Delete Mode</param> /// <returns></returns> public String GetDeletionCommandText(OwlInstanceSupertype oc, String graphUri, LinqDeleteMode mode) { if (oc == null) throw new ArgumentNullException("oc", "Cannot delete a Null Object"); StringBuilder persistCommand = new StringBuilder(); switch (mode) { case LinqDeleteMode.DeleteAll: //Delete all the Triples with this Object's Instance URI as the Subject/Object //Start building a pair of DELETE WHERE commands persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.AppendLine(" ?p ?o ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the first DELETE WHERE command persistCommand.AppendLine("} ;"); //Create the second DELETE WHERE command persistCommand.AppendLine("DELETE WHERE {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } persistCommand.Append("?s ?p "); persistCommand.AppendLine(this.FormatAsUri(oc.InstanceUri) + " ."); //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the second DELETE WHERE command persistCommand.AppendLine("} ;"); return persistCommand.ToString(); case LinqDeleteMode.DeleteValues: //Delete the specific Values associated with this Object Type t = oc.GetType(); PropertyInfo[] propInfo = t.GetProperties(); //Start building an DELETE DATA command persistCommand.AppendLine("DELETE DATA {"); //Need to add a GRAPH clause if a Graph URI has been provided if (!String.IsNullOrEmpty(graphUri)) { persistCommand.Append("GRAPH <"); persistCommand.Append(this._formatter.FormatUri(graphUri)); persistCommand.AppendLine("> {"); } //Assert the Type Triple persistCommand.Append(this.FormatAsUri(oc.InstanceUri)); persistCommand.Append(" a "); persistCommand.Append(this.FormatAsUri(OwlClassSupertype.GetOwlClassUri(t))); persistCommand.AppendLine(" ."); //Assert Triples for annotated properties Graph g = new Graph(); foreach (PropertyInfo info in propInfo) { this.GetTripleText(oc, info, g, persistCommand); } //Need to append an extra } to close the GRAPH clause if using one if (!String.IsNullOrEmpty(graphUri)) { persistCommand.AppendLine("}"); } //Close the DELETE DATA command persistCommand.AppendLine("}"); return persistCommand.ToString(); default: throw new LinqToRdfException("Not a valid Linq Delete Mode"); } }