Objects: remove TransactionPrivate

This commit is contained in:
2025-05-07 15:00:15 +02:00
parent 9403556220
commit 56ab3bad4c
5 changed files with 13 additions and 53 deletions

View File

@@ -1,7 +0,0 @@
package com.usatiuk.objects.transaction;
import java.util.Collection;
public interface TransactionHandlePrivate extends TransactionHandle {
Collection<Runnable> getOnFlush();
}

View File

@@ -5,13 +5,14 @@ import com.usatiuk.objects.JDataVersionedWrapper;
import com.usatiuk.objects.JObjectKey; import com.usatiuk.objects.JObjectKey;
import com.usatiuk.objects.iterators.*; import com.usatiuk.objects.iterators.*;
import com.usatiuk.objects.snapshot.Snapshot; import com.usatiuk.objects.snapshot.Snapshot;
import com.usatiuk.utils.AutoCloseableNoThrow;
import com.usatiuk.utils.ListUtils; import com.usatiuk.utils.ListUtils;
import io.quarkus.logging.Log; import io.quarkus.logging.Log;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import java.util.*; import java.util.*;
class TransactionImpl implements TransactionPrivate { class TransactionImpl implements Transaction, AutoCloseableNoThrow {
private final Map<JObjectKey, Optional<JDataVersionedWrapper>> _readSet = new HashMap<>(); private final Map<JObjectKey, Optional<JDataVersionedWrapper>> _readSet = new HashMap<>();
private final NavigableMap<JObjectKey, TxRecord.TxObjectRecord<?>> _writes = new TreeMap<>(); private final NavigableMap<JObjectKey, TxRecord.TxObjectRecord<?>> _writes = new TreeMap<>();
private final List<Runnable> _onCommit = new LinkedList<>(); private final List<Runnable> _onCommit = new LinkedList<>();
@@ -63,23 +64,19 @@ class TransactionImpl implements TransactionPrivate {
_onFlush.add(runnable); _onFlush.add(runnable);
} }
@Override Collection<Runnable> getOnCommit() {
public Collection<Runnable> getOnCommit() {
return Collections.unmodifiableCollection(_onCommit); return Collections.unmodifiableCollection(_onCommit);
} }
@Override Snapshot<JObjectKey, JDataVersionedWrapper> snapshot() {
public Snapshot<JObjectKey, JDataVersionedWrapper> snapshot() {
return _snapshot; return _snapshot;
} }
@Override Collection<Runnable> getOnFlush() {
public Collection<Runnable> getOnFlush() {
return Collections.unmodifiableCollection(_onFlush); return Collections.unmodifiableCollection(_onFlush);
} }
@Override <T extends JData> Optional<T> getFromSource(Class<T> type, JObjectKey key) {
public <T extends JData> Optional<T> getFromSource(Class<T> type, JObjectKey key) {
if (_knownNew.contains(key)) { if (_knownNew.contains(key)) {
return Optional.empty(); return Optional.empty();
} }
@@ -156,8 +153,7 @@ class TransactionImpl implements TransactionPrivate {
_newWrites.put(key, record); _newWrites.put(key, record);
} }
@Override Collection<TxRecord.TxObjectRecord<?>> drainNewWrites() {
public Collection<TxRecord.TxObjectRecord<?>> drainNewWrites() {
if (!_writeTrack) { if (!_writeTrack) {
_writeTrack = true; _writeTrack = true;
return Collections.unmodifiableCollection(_writes.values()); return Collections.unmodifiableCollection(_writes.values());
@@ -167,13 +163,11 @@ class TransactionImpl implements TransactionPrivate {
return ret.values(); return ret.values();
} }
@Override Map<JObjectKey, Optional<JDataVersionedWrapper>> reads() {
public Map<JObjectKey, Optional<JDataVersionedWrapper>> reads() {
return _readSet; return _readSet;
} }
@Override Set<JObjectKey> knownNew() {
public Set<JObjectKey> knownNew() {
return _knownNew; return _knownNew;
} }

View File

@@ -11,7 +11,7 @@ import java.util.Stack;
@Singleton @Singleton
public class TransactionManagerImpl implements TransactionManager { public class TransactionManagerImpl implements TransactionManager {
private static final ThreadLocal<Stack<TransactionPrivate>> _currentTransaction = ThreadLocal.withInitial(Stack::new); private static final ThreadLocal<Stack<TransactionImpl>> _currentTransaction = ThreadLocal.withInitial(Stack::new);
@Inject @Inject
TransactionService transactionService; TransactionService transactionService;

View File

@@ -1,27 +0,0 @@
package com.usatiuk.objects.transaction;
import com.usatiuk.objects.JData;
import com.usatiuk.objects.JDataVersionedWrapper;
import com.usatiuk.objects.JObjectKey;
import com.usatiuk.objects.snapshot.Snapshot;
import com.usatiuk.utils.AutoCloseableNoThrow;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
// The transaction interface actually used by user code to retrieve objects
public interface TransactionPrivate extends Transaction, TransactionHandlePrivate, AutoCloseableNoThrow {
Collection<TxRecord.TxObjectRecord<?>> drainNewWrites();
Map<JObjectKey, Optional<JDataVersionedWrapper>> reads();
Set<JObjectKey> knownNew();
<T extends JData> Optional<T> getFromSource(Class<T> type, JObjectKey key);
Collection<Runnable> getOnCommit();
Snapshot<JObjectKey, JDataVersionedWrapper> snapshot();
}

View File

@@ -46,14 +46,14 @@ public class TransactionService {
_ready = true; _ready = true;
} }
public TransactionPrivate createTransaction() { public TransactionImpl createTransaction() {
verifyReady(); verifyReady();
var tx = new TransactionImpl(writebackObjectPersistentStore.getSnapshot()); var tx = new TransactionImpl(writebackObjectPersistentStore.getSnapshot());
Log.tracev("Created transaction with snapshotId={0}", tx.snapshot().id()); Log.tracev("Created transaction with snapshotId={0}", tx.snapshot().id());
return tx; return tx;
} }
public Pair<Collection<Runnable>, TransactionHandle> commit(TransactionPrivate tx) { public Pair<Collection<Runnable>, TransactionHandle> commit(TransactionImpl tx) {
verifyReady(); verifyReady();
var writes = new HashMap<JObjectKey, TxRecord.TxObjectRecord<?>>(); var writes = new HashMap<JObjectKey, TxRecord.TxObjectRecord<?>>();
Snapshot<JObjectKey, JDataVersionedWrapper> commitSnapshot = null; Snapshot<JObjectKey, JDataVersionedWrapper> commitSnapshot = null;
@@ -257,7 +257,7 @@ public class TransactionService {
} }
} }
public void rollback(TransactionPrivate tx) { public void rollback(TransactionImpl tx) {
verifyReady(); verifyReady();
tx.close(); tx.close();
} }