Class MigrationResult.Builder

java.lang.Object
net.blockhost.commons.config.migration.MigrationResult.Builder
Enclosing interface:
MigrationResult

public static final class MigrationResult.Builder extends Object

Builder for creating migration results incrementally.

This is useful when executing multiple migrations and tracking progress:

MigrationResult.Builder builder = MigrationResult.builder(1, data);
for (Migration migration : migrations) {
    try {
        builder.startStep();
        migration.migrate(context);
        builder.completeStep(migration);
    } catch (Exception e) {
        return builder.fail(migration.targetVersion(), e);
    }
}
return builder.build(targetVersion);
  • Method Details

    • startStep

      public void startStep()
      Marks the start of a migration step.
    • completeStep

      public void completeStep(Migration migration)
      Records the completion of a migration step.
      Parameters:
      migration - the migration that was applied
    • build

      public MigrationResult build(int toVersion)
      Builds a successful result.
      Parameters:
      toVersion - the final version
      Returns:
      the successful result
    • fail

      public MigrationResult fail(int failedAtVersion, MigrationException cause)
      Builds a failed result.
      Parameters:
      failedAtVersion - the version where migration failed
      cause - the exception that caused the failure
      Returns:
      the failed result
    • noMigrationNeeded

      public MigrationResult noMigrationNeeded()
      Builds a result indicating no migration was needed.
      Returns:
      the no-op result