SchemaSanitizingObjectSupport extends ResourceObjectSupport implements SchemaSanitizingObject { protected boolean removeValue(String propertyIri, Object value) { ObjectConnection connection = getObjectConnection(); try { if(value instanceof ResourceObject) { connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE {" + " <" + getResourceAsString() + "> ?p <" + ((ResourceObject) value).getResourceAsString() + "> . " + "} WHERE {" + " ?p rdfs:subPropertyOf+ <" + propertyIri + "> . " + "}" ).execute(); connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE DATA {" + " <" + getResourceAsString() + "> <" + propertyIri + "> <" + ((ResourceObject) value).getResourceAsString() + "> . " + "}" ).execute(); } else { String valueString; if(value instanceof Number) { valueString = value.toString(); } else { valueString = "'" + value.toString() + "'"; } connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE {" + " <" + getResourceAsString() + "> ?p ?v . " + "} WHERE {" + " <" + getResourceAsString() + "> ?p ?v . " + " ?p rdfs:subPropertyOf+ <" + propertyIri + "> . " + " FILTER(?v = " + valueString + ")" + "}" ).execute(); connection.prepareUpdate(QueryLanguage.SPARQL, "DELETE {" + " <" + getResourceAsString() + "> <" + propertyIri + "> ?v . " + "} WHERE {" + " <" + getResourceAsString() + "> <" + propertyIri + "> ?v ." + " FILTER(?v = " + valueString + ")" + "}" ).execute(); } return true; } catch (MalformedQueryException | UpdateExecutionException | RepositoryException e) { return false; } }  @Override boolean sanitizeSchema(Resource propertyUri); @Override boolean sanitizeSchema(String propertyUri);  }
@Test public void testRemoveValue() throws Exception { SanitizingTestResource resource = anno4j.createObject(SanitizingTestResource.class, (Resource) new URIImpl("urn:anno4j:r")); SanitizingTestResource x1 = anno4j.createObject(SanitizingTestResource.class, (Resource) new URIImpl("urn:anno4j:x1")); SanitizingTestResource x2 = anno4j.createObject(SanitizingTestResource.class, (Resource) new URIImpl("urn:anno4j:x2")); resource.setSuperproperty(Sets.newHashSet(1)); resource.setSubproperty(Sets.newHashSet(2)); resource.setObjectSuperproperty(Sets.newHashSet(x1)); resource.setObjectSubproperty(Sets.newHashSet(x2)); resource.testRemoveValue(x2); }