Skip to content

Commit 28edab6

Browse files
committed
GH-5221 fix bug where added statements from a SPARQL update were not notified and were also not added. This only happens when the exact statement was removed by the DELETE clause.
1 parent 7a1a8f5 commit 28edab6

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

core/repository/sail/src/main/java/org/eclipse/rdf4j/repository/sail/helpers/SailUpdateExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ protected void executeModify(Modify modify, UpdateContext uc, int maxExecutionTi
447447
whereClause, uc, maxExecutionTime)) {
448448
while (sourceBindings.hasNext()) {
449449
BindingSet sourceBinding = sourceBindings.next();
450-
deleteBoundTriples(sourceBinding, modify.getDeleteExpr(), uc);
451450

451+
deleteBoundTriples(sourceBinding, modify.getDeleteExpr(), uc);
452452
insertBoundTriples(sourceBinding, modify.getInsertExpr(), uc);
453453
}
454454
}

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/Changeset.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.stream.Collectors;
3030
import java.util.stream.Stream;
3131

32+
import org.eclipse.rdf4j.common.annotation.Experimental;
3233
import org.eclipse.rdf4j.common.annotation.InternalUseOnly;
3334
import org.eclipse.rdf4j.common.transaction.IsolationLevels;
3435
import org.eclipse.rdf4j.model.IRI;
@@ -175,7 +176,8 @@ boolean hasApproved(Resource subj, IRI pred, Value obj, Resource[] contexts) {
175176
}
176177
}
177178

178-
boolean hasDeprecated(Resource subj, IRI pred, Value obj, Resource[] contexts) {
179+
@Experimental
180+
public boolean hasDeprecated(Resource subj, IRI pred, Value obj, Resource[] contexts) {
179181
assert !closed;
180182
if ((deprecated == null || deprecatedEmpty) && deprecatedContexts == null) {
181183
return false;

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/SailSourceConnection.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,13 @@ private void add(Resource subj, IRI pred, Value obj, SailDataset dataset, SailSi
763763
if (hasConnectionListeners()) {
764764
if (!hasStatement(dataset, subj, pred, obj, NULL_CTX)) {
765765
notifyStatementAdded(vf.createStatement(subj, pred, obj));
766-
sink.approve(subj, pred, obj, null);
766+
} else if (sink instanceof Changeset && ((Changeset) sink).hasDeprecated(subj, pred, obj, NULL_CTX)) {
767+
notifyStatementAdded(vf.createStatement(subj, pred, obj));
767768
}
769+
770+
// always approve the statement, even if it already exists
771+
sink.approve(subj, pred, obj, null);
772+
768773
} else {
769774
sink.approve(subj, pred, obj, null);
770775
}
@@ -784,8 +789,11 @@ private void add(Resource subj, IRI pred, Value obj, SailDataset dataset, SailSi
784789
if (hasConnectionListeners()) {
785790
if (!hasStatement(dataset, subj, pred, obj, contextsToCheck)) {
786791
notifyStatementAdded(vf.createStatement(subj, pred, obj, ctx));
787-
sink.approve(subj, pred, obj, ctx);
792+
} else if (sink instanceof Changeset
793+
&& ((Changeset) sink).hasDeprecated(subj, pred, obj, contextsToCheck)) {
794+
notifyStatementAdded(vf.createStatement(subj, pred, obj));
788795
}
796+
sink.approve(subj, pred, obj, ctx);
789797
} else {
790798
sink.approve(subj, pred, obj, ctx);
791799
}
@@ -830,7 +838,6 @@ private boolean remove(Resource subj, IRI pred, Value obj, SailDataset dataset,
830838
while (iter.hasNext()) {
831839
Statement st = iter.next();
832840
sink.deprecate(st);
833-
834841
statementsRemoved = true;
835842
notifyStatementRemoved(st);
836843
}

core/sail/extensible-store/src/main/java/org/eclipse/rdf4j/sail/extensiblestore/valuefactory/ExtensibleStatementImpl.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.eclipse.rdf4j.model.IRI;
1616
import org.eclipse.rdf4j.model.Resource;
17+
import org.eclipse.rdf4j.model.Statement;
1718
import org.eclipse.rdf4j.model.Value;
1819
import org.eclipse.rdf4j.model.impl.GenericStatement;
1920

@@ -45,19 +46,17 @@ public boolean equals(Object o) {
4546
if (this == o) {
4647
return true;
4748
}
48-
if (!(o instanceof ExtensibleStatementImpl)) {
49+
if (!(o instanceof Statement)) {
4950
return false;
5051
}
52+
if (!(o instanceof ExtensibleStatement)) {
53+
return super.equals(o);
54+
}
5155
if (!super.equals(o)) {
5256
return false;
5357
}
54-
ExtensibleStatementImpl that = (ExtensibleStatementImpl) o;
55-
return inferred == that.inferred;
56-
}
57-
58-
@Override
59-
public int hashCode() {
60-
return Objects.hash(super.hashCode(), inferred);
58+
ExtensibleStatement that = (ExtensibleStatement) o;
59+
return inferred == that.isInferred();
6160
}
6261

6362
}

0 commit comments

Comments
 (0)