Class AbstractMigrater
- java.lang.Object
-
- software.xdev.micromigration.migrater.AbstractMigrater
-
- All Implemented Interfaces:
MicroMigrater
- Direct Known Subclasses:
ExplicitMigrater
public abstract class AbstractMigrater extends java.lang.Object implements MicroMigrater
Provides the basic functionality to applyVersionAgnosticMigrationScript
s to a datastore.- Author:
- Johannes Rabauer
-
-
Constructor Summary
Constructors Constructor Description AbstractMigrater()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkIfVersionIsAlreadyRegistered(VersionAgnosticMigrationScript<?,?> scriptToCheck)
Checks if the givenVersionAgnosticMigrationScript
is not already registered in theMicroMigrater.getSortedScripts()
.<E extends VersionAgnosticMigrationEmbeddedStorageManager<?,?>>
MigrationVersionmigrateToNewest(MigrationVersion fromVersion, E storageManager, java.lang.Object root)
Executes all the scripts that are available to the migrater.<E extends VersionAgnosticMigrationEmbeddedStorageManager<?,?>>
MigrationVersionmigrateToVersion(MigrationVersion fromVersion, MigrationVersion targetVersion, E storageManager, java.lang.Object objectToMigrate)
Executes all the scripts that are available to the migrater until the given targetVersion is reached.void
registerNotificationConsumer(java.util.function.Consumer<ScriptExecutionNotificationWithScriptReference> notificationConsumer)
Registers a callback to take action when a script is executed.AbstractMigrater
withClock(java.time.Clock clock)
Change used clock for notifications fromregisterNotificationConsumer(Consumer)
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface software.xdev.micromigration.migrater.MicroMigrater
getSortedScripts
-
-
-
-
Method Detail
-
registerNotificationConsumer
public void registerNotificationConsumer(java.util.function.Consumer<ScriptExecutionNotificationWithScriptReference> notificationConsumer)
Description copied from interface:MicroMigrater
Registers a callback to take action when a script is executed.- Specified by:
registerNotificationConsumer
in interfaceMicroMigrater
- Parameters:
notificationConsumer
- is executed when a script is used from this migrater.
-
migrateToNewest
public <E extends VersionAgnosticMigrationEmbeddedStorageManager<?,?>> MigrationVersion migrateToNewest(MigrationVersion fromVersion, E storageManager, java.lang.Object root)
Description copied from interface:MicroMigrater
Executes all the scripts that are available to the migrater. Only scripts with a higher target version than the given fromVersion are executed.
Scripts are executed one after another from the lowest to the highest version.Example:
Current version is 1.0.0
Scripts for v1.1.0, v2.0.0 and v1.2.1 are available
Scripts are chain executed like v1.1.0 then v1.2.1 then v2.0.0- Specified by:
migrateToNewest
in interfaceMicroMigrater
- Type Parameters:
E
- theVersionAgnosticMigrationEmbeddedStorageManager
which contains the migrating object- Parameters:
fromVersion
- is the current version of the datastore. Scripts for lower versions then the fromVersion are not executed.storageManager
- is relayed to the scriptsVersionAgnosticMigrationScript.migrate(Context)
method. This way the script can callVersionAgnosticMigrationEmbeddedStorageManager.store(Object)
or another method on the storage manager.root
- is relayed to the scriptsVersionAgnosticMigrationScript.migrate(Context)
method. This way the script can change something within the root object.- Returns:
- the target version of the last executed script
-
migrateToVersion
public <E extends VersionAgnosticMigrationEmbeddedStorageManager<?,?>> MigrationVersion migrateToVersion(MigrationVersion fromVersion, MigrationVersion targetVersion, E storageManager, java.lang.Object objectToMigrate)
Description copied from interface:MicroMigrater
Executes all the scripts that are available to the migrater until the given targetVersion is reached. Only scripts with a higher target version than the given fromVersion are executed.
Scripts are executed one after another from the lowest to the highest version.Example:
Current version is 1.0.0
Scripts for v1.1.0, v2.0.0 and v1.2.1 are available
Scripts are chain executed like v1.1.0 then v1.2.1 then v2.0.0- Specified by:
migrateToVersion
in interfaceMicroMigrater
- Type Parameters:
E
- theVersionAgnosticMigrationEmbeddedStorageManager
which contains the migrating object- Parameters:
fromVersion
- is the current version of the datastore. Scripts for lower versions then the fromVersion are not executed.targetVersion
- is the highest allowed script version. Scripts which have a higher version won't be exectued.storageManager
- is relayed to the scriptsVersionAgnosticMigrationScript.migrate(Context)
method. This way the script can call EmbeddedStorageManager#store or another method on the storage manager.objectToMigrate
- is relayed to the scriptsVersionAgnosticMigrationScript.migrate(Context)
method. This way the script can change something within the object to migrate.- Returns:
- the target version of the last executed script
-
checkIfVersionIsAlreadyRegistered
protected void checkIfVersionIsAlreadyRegistered(VersionAgnosticMigrationScript<?,?> scriptToCheck)
Checks if the givenVersionAgnosticMigrationScript
is not already registered in theMicroMigrater.getSortedScripts()
.- Parameters:
scriptToCheck
- It's target version is checked, if it is not already registered.- Throws:
VersionAlreadyRegisteredException
- if script is already registered.
-
withClock
public AbstractMigrater withClock(java.time.Clock clock)
Change used clock for notifications fromregisterNotificationConsumer(Consumer)
.- Parameters:
clock
- is used when aScriptExecutionNotificationWithoutScriptReference
is created- Returns:
- self
-
-