Skip to content

Commit

Permalink
Add missing transaction version update to Migration
Browse files Browse the repository at this point in the history
Also, refactor the code so the entity changes are transaction-based and propagated to the entity on transaction commit, instead of being applied in-place. This should make the migration logic as well as the values observed when debugging clearer.
  • Loading branch information
dmitrykuzmin committed Sep 2, 2020
1 parent 75b5794 commit 4380449
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/src/main/java/io/spine/server/entity/Migration.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ final void finishCurrentOperation() {
Transaction<I, E, S, ?> tx = startTransaction(entity);
EntityLifecycleMonitor<I> monitor = configureLifecycleMonitor(id);
tx.setListener(monitor);
currentOperation().tx = tx;
return tx;
}

Expand Down Expand Up @@ -238,6 +239,7 @@ private static class Operation<I,
private boolean physicallyRemoveRecord;

private final E entity;
private @MonotonicNonNull Transaction<I, E, S, ?> tx;
private final RecordBasedRepository<I, E, S> repository;

private @MonotonicNonNull Event systemEvent;
Expand All @@ -249,16 +251,18 @@ private Operation(E entity, RecordBasedRepository<I, E, S> repository) {

private void updateState(S newState) {
if (!entity.state().equals(newState)) {
entity.updateState(newState, increment(entity.version()));
tx.builder().mergeFrom(newState);
Version version = increment(entity.version());
tx.setVersion(version);
}
}

private void updateLifecycle() {
if (archive) {
entity.setArchived(true);
tx.setArchived(true);
}
if (delete) {
entity.setDeleted(true);
tx.setDeleted(true);
}
}

Expand Down

0 comments on commit 4380449

Please sign in to comment.