[Minor] Automated Code cleanup: Class can be a record

This commit is contained in:
Robert von Burg 2023-04-04 14:24:30 +02:00
parent 877c02ede8
commit d74ed6fb2d
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
3 changed files with 18 additions and 24 deletions

View File

@ -10,27 +10,21 @@ import li.strolch.utils.Version;
*
* @author Reto Breitenmoser <reto.breitenmoser@4trees.ch>
*/
public class MigrationVersion {
private final Version dataVersion;
private final Version codeVersion;
public MigrationVersion(Version dataVersion, Version codeVersion) {
this.dataVersion = dataVersion;
this.codeVersion = codeVersion;
}
public record MigrationVersion(Version dataVersion, Version codeVersion) {
/**
* @return the dataVersion
*/
public Version getDataVersion() {
@Override
public Version dataVersion() {
return dataVersion;
}
/**
* @return the codeVersion
*/
public Version getCodeVersion() {
@Override
public Version codeVersion() {
return codeVersion;
}

View File

@ -92,8 +92,8 @@ public class Migrations {
if (this.verbose)
logger.info("[" + realm + "] Performing all migrations after " + currentVersion);
Version nextPossibleCodeVersion = currentVersion.getCodeVersion().add(0, 0, 1);
Version nextPossibleDataVersion = currentVersion.getDataVersion().add(0, 0, 1);
Version nextPossibleCodeVersion = currentVersion.codeVersion().add(0, 0, 1);
Version nextPossibleDataVersion = currentVersion.dataVersion().add(0, 0, 1);
CodeMigration currentCodeMigration = new CodeMigration(realm, nextPossibleCodeVersion, null);
DataMigration currentDataMigration = new DataMigration(realm, nextPossibleDataVersion, null);
@ -170,16 +170,16 @@ public class Migrations {
SortedSet<CodeMigration> migrations = new TreeSet<>(Comparator.comparing(Migration::getVersion));
migrations.addAll(listOfMigrations);
Version nextVersion = currentVersion.getCodeVersion().add(0, 0, 1);
Version nextVersion = currentVersion.codeVersion().add(0, 0, 1);
CodeMigration nextMigration = new CodeMigration(realm, nextVersion);
SortedSet<CodeMigration> migrationsToRun = migrations.tailSet(nextMigration);
for (CodeMigration migration : migrationsToRun) {
DBC.INTERIM.assertEquals("Realms do not match!", realm, migration.getRealm());
Version migrateVersion = migration.getVersion();
boolean isLaterMigration = migrateVersion.compareTo(currentVersion.getCodeVersion()) > 0;
boolean isLaterMigration = migrateVersion.compareTo(currentVersion.codeVersion()) > 0;
DBC.INTERIM.assertTrue(
"Current version " + currentVersion.getCodeVersion() + " is not before next " + migrateVersion,
"Current version " + currentVersion.codeVersion() + " is not before next " + migrateVersion,
isLaterMigration);
String msg = "[{0}] Running code migration {1} {2}";
@ -295,8 +295,8 @@ public class Migrations {
for (Entry<String, MigrationVersion> entry : currentVersions.entrySet()) {
String realm = entry.getKey();
Version nextPossibleCodeVersion = entry.getValue().getCodeVersion().add(0, 0, 1);
Version nextPossibleDataVersion = entry.getValue().getDataVersion().add(0, 0, 1);
Version nextPossibleCodeVersion = entry.getValue().codeVersion().add(0, 0, 1);
Version nextPossibleDataVersion = entry.getValue().dataVersion().add(0, 0, 1);
CodeMigration currentCodeMigration = new CodeMigration(realm, nextPossibleCodeVersion, null);
DataMigration currentDataMigration = new DataMigration(realm, nextPossibleDataVersion, null);

View File

@ -70,8 +70,8 @@ public class MigrationsTest {
MigrationsHandler migrationsHandler = runtimeMock.getContainer().getComponent(MigrationsHandler.class);
Map<String, MigrationVersion> currentVersions = migrationsHandler.getCurrentVersions(certificate);
String defRealm = StrolchConstants.DEFAULT_REALM;
assertEquals("1.1.1", currentVersions.get(defRealm).getDataVersion().toString());
assertEquals("0.0.0", currentVersions.get("other").getCodeVersion().toString());
assertEquals("1.1.1", currentVersions.get(defRealm).dataVersion().toString());
assertEquals("0.0.0", currentVersions.get("other").codeVersion().toString());
MapOfLists<String, Version> lastMigrations = migrationsHandler.getLastMigrations();
List<Version> expectedMigrations = Arrays
@ -85,8 +85,8 @@ public class MigrationsTest {
// assert new current version
currentVersions = migrationsHandler.getCurrentVersions(certificate);
assertEquals("1.1.1", currentVersions.get(defRealm).getDataVersion().toString());
assertEquals("0.0.0", currentVersions.get("other").getCodeVersion().toString());
assertEquals("1.1.1", currentVersions.get(defRealm).dataVersion().toString());
assertEquals("0.0.0", currentVersions.get("other").codeVersion().toString());
MapOfLists<String, CodeMigration> codeMigrationsByRealm = new MapOfLists<>();
// add migrations in wrong sequence - should be fixed by migration handler
@ -102,8 +102,8 @@ public class MigrationsTest {
// assert new current version
currentVersions = migrationsHandler.getCurrentVersions(certificate);
assertEquals("1.2.0.a", currentVersions.get(defRealm).getCodeVersion().toString());
assertEquals("0.0.0", currentVersions.get("other").getDataVersion().toString());
assertEquals("1.2.0.a", currentVersions.get(defRealm).codeVersion().toString());
assertEquals("0.0.0", currentVersions.get("other").dataVersion().toString());
}
private static class MyMigration0 extends CodeMigration {