/// <summary> /// Updates the properties of a resource in the backing RDF store. /// </summary> /// <param name="resource">Resource that is to be updated in the backing store.</param> /// <param name="transaction">Transaction associated with this action.</param> public virtual void UpdateResource(Resource resource, ITransaction transaction = null) { string updateString; if (resource.IsNew) { updateString = string.Format(@"WITH {0} INSERT {{ {1} }} WHERE {{}}", SparqlSerializer.SerializeUri(Uri), SparqlSerializer.SerializeResource(resource, IgnoreUnmappedProperties)); } else { updateString = string.Format(@"WITH {0} DELETE {{ {1} ?p ?o. }} INSERT {{ {2} }} WHERE {{ OPTIONAL {{ {1} ?p ?o. }} }}", SparqlSerializer.SerializeUri(Uri), SparqlSerializer.SerializeUri(resource.Uri), SparqlSerializer.SerializeResource(resource, IgnoreUnmappedProperties)); } SparqlUpdate update = new SparqlUpdate(updateString) { Resource = resource }; ExecuteUpdate(update, transaction); resource.IsNew = false; resource.IsSynchronized = true; }
/// <summary> /// Updates the properties of a resource in the backing RDF store. /// </summary> /// <param name="resource">Resource that is to be updated in the backing store.</param> /// <param name="transaction">ransaction associated with this action.</param> public void UpdateResource(Resource resource, ITransaction transaction = null) { string updateString; if (resource.IsNew) { updateString = string.Format(@"WITH {0} INSERT {{ {1} }} WHERE {{}}", SparqlSerializer.SerializeUri(Uri), SparqlSerializer.SerializeResource(resource)); } else { updateString = string.Format(@"WITH {0} DELETE {{ {1} ?p ?o. }} INSERT {{ {2} }} WHERE {{ {1} ?p ?o. }} ", SparqlSerializer.SerializeUri(Uri), SparqlSerializer.SerializeUri(resource.Uri), SparqlSerializer.SerializeResource(resource)); } SparqlUpdate update = new SparqlUpdate(updateString); update.Resource = resource; ExecuteUpdate(update, transaction); resource.IsNew = false; }
/// <summary> /// Removes the given resource from the model and its backing RDF store. Note that there is no verification /// that the given resource and its stored representation have identical properties. /// </summary> /// <param name="uri">A Uniform Resource Identifier.</param> /// <param name="transaction">Transaction associated with this action.</param> public virtual void DeleteResource(Uri uri, ITransaction transaction = null) { // NOTE: Regrettably, dotNetRDF does not support the full SPARQL 1.1 update syntax. To be precise, // it does not support FILTERs or OPTIONAL in Modify clauses. This requires us to formulate the // deletion of the resource in subject and object of any triples in two statements. SparqlUpdate deleteSubject = new SparqlUpdate(@"DELETE WHERE { GRAPH @graph { @subject ?p ?o . } }"); deleteSubject.Bind("@graph", Uri); deleteSubject.Bind("@subject", uri); _store.ExecuteNonQuery(deleteSubject, transaction); SparqlUpdate deleteObject = new SparqlUpdate(@"DELETE WHERE { GRAPH @graph { ?s ?p @object . } }"); deleteObject.Bind("@graph", Uri); deleteObject.Bind("@object", uri); _store.ExecuteNonQuery(deleteObject, transaction); }
/// <summary> /// Executes a query on the store which does not expect a result. /// </summary> /// <param name="update">SPARQL Update to be executed.</param> /// <param name="transaction">An optional transaction.</param> public abstract void ExecuteNonQuery(SparqlUpdate update, ITransaction transaction = null);
/// <summary> /// Not supported. ModelGroups are read-only. /// </summary> /// <param name="update"></param> /// <param name="transaction"></param> public void ExecuteUpdate(SparqlUpdate update, ITransaction transaction = null) { throw new NotSupportedException(); }
/// <summary> /// Execute a SPARQL Update. /// </summary> /// <param name="update">A SparqlUpdate object.</param> /// <param name="transaction">Transaction associated with this action.</param> public void ExecuteUpdate(SparqlUpdate update, ITransaction transaction = null) { _store.ExecuteNonQuery(update, transaction); }