diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/AbstractTargetSystem.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/AbstractTargetSystem.java index 8096dcad4..7bedd12b5 100644 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/AbstractTargetSystem.java +++ b/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/AbstractTargetSystem.java @@ -99,6 +99,24 @@ public final T applyChange(Function changeApplier, Exec return changeApplier.apply(executionRuntime); } + /** + * Rolls back (reverts) a previously applied change with session-scoped dependency injection. + *

+ * This method is the entry point for non-transactional rollback execution. + * It calls {@link #enhanceExecutionRuntime(ExecutionRuntime, boolean)} to allow + * subclasses to inject session-scoped dependencies before executing the rollback. + * + * @param the return type of the rollback operation + * @param changeRollbacker the function that executes the actual rollback + * @param executionRuntime the runtime context for dependency resolution + * @return the result of the rollback operation + */ + public final T rollbackChange(Function changeRollbacker, ExecutionRuntime executionRuntime) { + enhanceExecutionRuntime(executionRuntime, false); + return changeRollbacker.apply(executionRuntime); + } + + /** * Hook for injecting session-scoped dependencies into the execution runtime. *

diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOps.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOps.java index df9e61a9a..992b3a32e 100644 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOps.java +++ b/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOps.java @@ -56,4 +56,23 @@ public interface TargetSystemOps extends TargetSystem { */ T applyChange(Function changeApplier, ExecutionRuntime executionRuntime); + /** + * Rolls back (reverts) a previously applied change in this target system. + *

+ * This method coordinates the execution of a rollback by: + *

+ *

+ * Implementations should strive for idempotency: invoking the rollback more than + * once should not produce side effects beyond the first successful revert. + * + * @param the return type of the rollback operation + * @param changeRollbacker the function that executes the actual rollback + * @param executionRuntime the runtime context for dependency resolution + * @return the result of the rollback operation + */ + T rollbackChange(Function changeRollbacker, ExecutionRuntime executionRuntime); + } diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOpsImpl.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOpsImpl.java index 0851efb97..23d52d0dc 100644 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOpsImpl.java +++ b/core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/operations/TargetSystemOpsImpl.java @@ -41,6 +41,12 @@ public final T applyChange(Function changeApplier, Exec return targetSystem.applyChange(changeApplier, executionRuntime); } + @Override + public final T rollbackChange(Function changeRollbacker, ExecutionRuntime executionRuntime) { + executionRuntime.addContextLayer(targetSystem.getContext()); + return targetSystem.rollbackChange(changeRollbacker, executionRuntime); + } + @Override public String getId() { return targetSystem.getId(); diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/NonTxChangeProcessStrategy.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/NonTxChangeProcessStrategy.java index 31c8621dc..d3e79063e 100644 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/NonTxChangeProcessStrategy.java +++ b/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/NonTxChangeProcessStrategy.java @@ -111,7 +111,7 @@ protected ChangeProcessResult doApplyChange() { private void rollbackActualChangeAndChain(FailedAfterExecutionAuditStep rollableFailedStep, ExecutionContext executionContext) { rollableFailedStep.getRollbackSteps().forEach(rollableStep -> { - ManualRolledBackStep rolledBack = rollableStep.rollback(buildExecutionRuntime()); + ManualRolledBackStep rolledBack = targetSystemOps.rollbackChange(rollableStep::rollback, buildExecutionRuntime()); stepLogger.logManualRollbackResult(rolledBack); summarizer.add(rolledBack); auditAndLogManualRollback(rolledBack, executionContext); diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SharedTxChangeProcessStrategy.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SharedTxChangeProcessStrategy.java index 032ac3f30..a81eaf686 100644 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SharedTxChangeProcessStrategy.java +++ b/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SharedTxChangeProcessStrategy.java @@ -142,7 +142,7 @@ private void rollbackChain(RollableFailedStep rollableFailedStep, ExecutionConte rollableFailedStep.getRollbackSteps() .stream().skip(1) .forEach(rollableStep -> { - ManualRolledBackStep rolledBack = rollableStep.rollback(buildExecutionRuntime()); + ManualRolledBackStep rolledBack = targetSystemOps.rollbackChange(rollableStep::rollback, buildExecutionRuntime()); stepLogger.logManualRollbackResult(rolledBack); summarizer.add(rolledBack); auditAndLogManualRollback(rolledBack, executionContext); diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SimpleTxChangeProcessStrategy.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SimpleTxChangeProcessStrategy.java index a44452661..15ff692b5 100644 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SimpleTxChangeProcessStrategy.java +++ b/core/flamingock-core/src/main/java/io/flamingock/internal/core/task/navigation/navigator/strategy/SimpleTxChangeProcessStrategy.java @@ -138,7 +138,7 @@ private void rollbackChain(RollableFailedStep rollableFailedStep, ExecutionConte rollableFailedStep.getRollbackSteps() .stream().skip(1) .forEach(rollableStep -> { - ManualRolledBackStep rolledBack = rollableStep.rollback(buildExecutionRuntime()); + ManualRolledBackStep rolledBack = targetSystemOps.rollbackChange(rollableStep::rollback, buildExecutionRuntime()); stepLogger.logManualRollbackResult(rolledBack); summarizer.add(rolledBack); auditAndLogManualRollback(rolledBack, executionContext);