|
| 1 | +/* |
| 2 | + * Copyright © 2024 XDEV Software (https://xdev.software) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.migrater; |
| 17 | + |
| 18 | +import java.util.TreeSet; |
| 19 | +import java.util.function.Consumer; |
| 20 | + |
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
| 22 | +import org.springframework.stereotype.Component; |
| 23 | + |
| 24 | +import software.xdev.micromigration.migrater.ExplicitMigrater; |
| 25 | +import software.xdev.micromigration.migrater.MicroMigrater; |
| 26 | +import software.xdev.micromigration.notification.ScriptExecutionNotificationWithScriptReference; |
| 27 | +import software.xdev.micromigration.scripts.VersionAgnosticMigrationScript; |
| 28 | +import software.xdev.micromigration.version.MigrationVersion; |
| 29 | +import software.xdev.micromigration.versionagnostic.VersionAgnosticMigrationEmbeddedStorageManager; |
| 30 | + |
| 31 | + |
| 32 | +@Component |
| 33 | +public class CustomMigrater implements MicroMigrater |
| 34 | +{ |
| 35 | + private ExplicitMigrater explicitMigrater; |
| 36 | + final PersistedEntityRepository repository; |
| 37 | + |
| 38 | + @Autowired |
| 39 | + public CustomMigrater(final PersistedEntityRepository repository) |
| 40 | + { |
| 41 | + this.repository = repository; |
| 42 | + } |
| 43 | + |
| 44 | + private ExplicitMigrater ensureExplicitMigrater() |
| 45 | + { |
| 46 | + if(this.explicitMigrater == null) |
| 47 | + { |
| 48 | + this.explicitMigrater = new ExplicitMigrater(new v1_0_0_Init(this.repository)); |
| 49 | + } |
| 50 | + return this.explicitMigrater; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public TreeSet<? extends VersionAgnosticMigrationScript<?, ?>> getSortedScripts() |
| 55 | + { |
| 56 | + return this.ensureExplicitMigrater().getSortedScripts(); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public <E extends VersionAgnosticMigrationEmbeddedStorageManager<?, ?>> MigrationVersion migrateToNewest( |
| 61 | + final MigrationVersion fromVersion, |
| 62 | + final E storageManager, |
| 63 | + final Object root) |
| 64 | + { |
| 65 | + return this.ensureExplicitMigrater().migrateToNewest(fromVersion, storageManager, root); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public <E extends VersionAgnosticMigrationEmbeddedStorageManager<?, ?>> MigrationVersion migrateToVersion( |
| 70 | + final MigrationVersion fromVersion, |
| 71 | + final MigrationVersion targetVersion, |
| 72 | + final E storageManager, |
| 73 | + final Object objectToMigrate) |
| 74 | + { |
| 75 | + return this.ensureExplicitMigrater() |
| 76 | + .migrateToVersion(fromVersion, targetVersion, storageManager, objectToMigrate); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public void registerNotificationConsumer( |
| 81 | + final Consumer<ScriptExecutionNotificationWithScriptReference> notificationConsumer |
| 82 | + ) |
| 83 | + { |
| 84 | + this.ensureExplicitMigrater().registerNotificationConsumer(notificationConsumer); |
| 85 | + } |
| 86 | +} |
0 commit comments