org.jobrunr.storage.nosql.common.NoSqlDatabaseMigrationsProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jobrunr Show documentation
Show all versions of jobrunr Show documentation
An easy way to perform background processing on the JVM. Backed by persistent storage. Open and free for commercial use.
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 extends NoSqlStorageProvider> 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