All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jobrunr.storage.nosql.common.NoSqlDatabaseMigrationsProvider Maven / Gradle / Ivy

Go to download

An easy way to perform background processing on the JVM. Backed by persistent storage. Open and free for commercial use.

There is a newer version: 7.3.1
Show newest version
package org.jobrunr.storage.nosql.common;

import org.jobrunr.storage.nosql.NoSqlStorageProvider;
import org.jobrunr.storage.nosql.common.migrations.DefaultNoSqlMigrationProvider;
import org.jobrunr.storage.nosql.common.migrations.NoSqlMigration;
import org.jobrunr.storage.nosql.common.migrations.NoSqlMigrationProvider;
import org.jobrunr.storage.nosql.common.migrations.RunningOnJava11OrLowerWithinFatJarNoSqlMigrationProvider;
import org.jobrunr.utils.RuntimeUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static java.util.Comparator.comparing;

public class NoSqlDatabaseMigrationsProvider {

    private List> noSqlStorageProviderClasses;

    public NoSqlDatabaseMigrationsProvider(List> noSqlStorageProviderClasses) {
        this.noSqlStorageProviderClasses = noSqlStorageProviderClasses;
    }

    public Stream getMigrations() {
        NoSqlMigrationProvider migrationProvider = getMigrationProvider();
        return getMigrations(migrationProvider);
    }

    protected Stream getMigrations(NoSqlMigrationProvider migrationProvider) {
        Map migrations = new HashMap<>();
        for (Class noSqlStorageProvider : noSqlStorageProviderClasses) {
            migrationProvider
                    .getMigrations(noSqlStorageProvider)
                    .stream()
                    .filter(m -> m.getClassName().matches("^M[0-9]{3}_(.)*$"))
                    .forEach(m -> migrations.put(m.getClassName(), m));
        }
        return migrations.values().stream().sorted(comparing(NoSqlMigration::getClassName));
    }

    private NoSqlMigrationProvider getMigrationProvider() {
        if (RuntimeUtils.getJvmVersion() < 12 && RuntimeUtils.isRunningFromNestedJar()) {
            return new RunningOnJava11OrLowerWithinFatJarNoSqlMigrationProvider();
        } else {
            return new DefaultNoSqlMigrationProvider();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy