Skip to content

Commit 07577f2

Browse files
committed
fixed unit test
1 parent f3339be commit 07577f2

5 files changed

Lines changed: 84 additions & 238 deletions

File tree

backend/src/main/java/org/rdfarchitect/api/dto/ChangeLogEntryMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.rdfarchitect.models.cim.rdf.resources.RDFA;
2626

2727
import java.lang.ref.WeakReference;
28-
import java.util.ArrayList;
2928
import java.util.List;
3029

3130
@Mapper(componentModel = "spring")
@@ -46,7 +45,7 @@ default ContextDeltaDTO toContextDeltaDTO(ContextDelta contextDelta) {
4645
default List<TripleDTO> mapTriples(WeakReference<Graph> graphReference) {
4746
var graph = graphReference.get();
4847
if (graph == null) {
49-
return new ArrayList<>();
48+
return null;
5049
}
5150
return graph.stream()
5251
.filter(triple -> !triple.getPredicate().equals(RDFA.uuid.asNode()))

backend/src/main/java/org/rdfarchitect/database/inmemory/GraphWithContextTransactional.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.slf4j.LoggerFactory;
4242

4343
import java.lang.ref.WeakReference;
44+
import java.util.ArrayList;
4445
import java.util.List;
4546
import java.util.Map;
4647
import java.util.UUID;
@@ -71,7 +72,7 @@ public class GraphWithContextTransactional implements GraphContext {
7172
private final ConcurrentHashMap<UUID, CustomDiagram> customDiagrams = new ConcurrentHashMap<>();
7273

7374
/** The fixed participants that are always part of every transaction. */
74-
private final List<TransactionParticipant> coreTransactionParticipants;
75+
private final List<RDFGraphDelta> graphParticipants;
7576

7677
private final List<NamedRewindable> coreRewindables;
7778
private final AtomicInteger stepsSinceNamedCommit = new AtomicInteger(0);
@@ -94,7 +95,7 @@ public GraphWithContextTransactional(Graph base) {
9495
this.customSHACL =
9596
new RDFGraphDelta(
9697
GraphFactory.createDefaultGraph(), maxVersions, compressCount, txnContext);
97-
this.coreTransactionParticipants = List.of(rdfGraph, diagramLayout, customSHACL, changeLog);
98+
this.graphParticipants = List.of(rdfGraph, customSHACL);
9899
this.coreRewindables =
99100
List.of(
100101
new NamedRewindable("rdf", rdfGraph),
@@ -107,12 +108,11 @@ public GraphWithContextTransactional(Graph base) {
107108
// Helpers — build the effective participant / rewindable lists
108109
// -------------------------------------------------------------------------
109110

110-
/**
111-
* Returns the core transaction participants. Custom diagrams are managed separately since they
112-
* are not part of the undo/redo history.
113-
*/
114-
private List<TransactionParticipant> allTransactionParticipants() {
115-
return coreTransactionParticipants;
111+
private List<TransactionParticipant> allParticipants() {
112+
var all = new ArrayList<TransactionParticipant>(graphParticipants);
113+
all.add(diagramLayout);
114+
all.add(changeLog);
115+
return all;
116116
}
117117

118118
/**
@@ -182,9 +182,13 @@ public void commit() {
182182
}
183183
GraphUtils.enhanceWithUUIDs(rdfGraph);
184184
changeLog.clearRedo();
185-
allTransactionParticipants().forEach(TransactionParticipant::commit);
185+
if (graphParticipants.stream().anyMatch(TransactionParticipant::hasChanges)) {
186+
graphParticipants.forEach(TransactionParticipant::commit);
187+
stepsSinceNamedCommit.incrementAndGet();
188+
}
189+
diagramLayout.commit();
190+
changeLog.commit();
186191
customDiagrams.values().forEach(CustomDiagram::commit);
187-
stepsSinceNamedCommit.incrementAndGet();
188192
logger.debug("Context committed.");
189193
}
190194

@@ -349,7 +353,7 @@ public void abort() {
349353
if (txnContext.transactionMode() == ReadWrite.READ) {
350354
throw new GraphTransactionException("Cannot abort a read transaction.");
351355
}
352-
allTransactionParticipants().forEach(TransactionParticipant::abort);
356+
allParticipants().forEach(TransactionParticipant::abort);
353357
customDiagrams.values().forEach(CustomDiagram::abort);
354358
logger.debug("Context aborted.");
355359
}
@@ -361,10 +365,9 @@ public void end() {
361365
}
362366
if (txnContext.transactionMode() == ReadWrite.WRITE
363367
&& !rdfGraph.isClosed()
364-
&& allTransactionParticipants().stream()
365-
.anyMatch(TransactionParticipant::hasChanges)) {
368+
&& allParticipants().stream().anyMatch(TransactionParticipant::hasChanges)) {
366369
logger.warn("Ending write transaction with uncommitted changes — aborting.");
367-
allTransactionParticipants().forEach(TransactionParticipant::abort);
370+
allParticipants().forEach(TransactionParticipant::abort);
368371
customDiagrams.values().forEach(CustomDiagram::abort);
369372
}
370373
var lock =

backend/src/main/java/org/rdfarchitect/models/changelog/ChangeLog.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,6 @@ public void restore(UUID versionId) {
198198
});
199199
}
200200

201-
/**
202-
* Buffers replacing the oldest (bottom-most) entry of the undo stack with the given entry. As a
203-
* side effect, the redo stack is cleared when the mutation is applied. This is used during
204-
* delta compression to replace the base entry with a compressed version.
205-
*
206-
* <p>If the undo stack is empty when the mutation is applied, a {@link
207-
* java.util.NoSuchElementException} will be thrown at commit time.
208-
*
209-
* @param entry the replacement entry
210-
* @throws GraphNotInATransactionException if no transaction is active
211-
* @throws GraphNotInAWriteTransactionException if the active transaction is read-only
212-
*/
213-
public void replaceOldest(ChangeLogEntry entry) {
214-
checkWriteTransaction();
215-
pendingMutations.add(
216-
() -> {
217-
undoStack.removeLast();
218-
undoStack.addLast(entry);
219-
redoStack.clear();
220-
});
221-
}
222-
223201
// -------------------------------------------------------------------------
224202
// read queries
225203
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)