Refactor viewer sessions and selections and optimize transaction queries

This commit is contained in:
eyck committed 2026-11-15 10:08:36 +01:00
1 parent 4824d48828
commit 589762b220
42 files changed
+1118 -720

No files matched your search

@@ -0,0 +1,12 @@
package com.minres.scviewer.database.tx;
import java.util.List;
/** Optional indexed access scoped to one transaction stream or generator. */
public interface ITransactionProvider {
/** Immutable list ordered by begin time and transaction ID; does not load attributes. */
List<ITx> getTransactionList();
/** Returns null when the ID does not belong to this stream or generator. */
ITx getTransaction(long id);
}
@@ -0,0 +1,36 @@
package com.minres.scviewer.database.tx;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.BooleanSupplier;
import com.minres.scviewer.database.EventEntry;
import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
public final class TransactionLists {
private TransactionLists() {}
/** Compatibility path for event-backed waveforms; callers can cache the completed result. */
public static List<ITx> fromEvents(IEventList events, BooleanSupplier cancelled) {
List<ITx> transactions = new ArrayList<>();
for (EventEntry entry : events.entrySet()) {
if (cancelled.getAsBoolean()) throw new java.util.concurrent.CancellationException();
if (entry.events == null) continue;
for (IEvent event : entry.events) {
if (cancelled.getAsBoolean()) throw new java.util.concurrent.CancellationException();
if (event instanceof ITxEvent tx && (event.getKind() == EventKind.BEGIN || event.getKind() == EventKind.SINGLE))
transactions.add(tx.getTransaction());
}
}
return sorted(transactions);
}
public static List<ITx> sorted(java.util.Collection<ITx> transactions) {
List<ITx> sorted = new ArrayList<>(transactions);
sorted.sort(Comparator.comparingLong(ITx::getBeginTime).thenComparingLong(ITx::getId));
return List.copyOf(sorted);
}
}