-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify migration: Add AbstractDoValueMigrationHandlerByMap
403145
- Loading branch information
Showing
5 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...test/java/org/eclipse/scout/rt/dataobject/migration/fixture/house/StreetNameStringId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.scout.rt.dataobject.migration.fixture.house; | ||
|
||
import org.eclipse.scout.rt.dataobject.id.AbstractStringId; | ||
import org.eclipse.scout.rt.dataobject.id.IdTypeName; | ||
import org.eclipse.scout.rt.platform.util.StringUtility; | ||
|
||
@IdTypeName("charlieFixture.StreetNameStringId") | ||
public final class StreetNameStringId extends AbstractStringId { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private StreetNameStringId(String id) { | ||
super(id); | ||
} | ||
|
||
public static StreetNameStringId of(String id) { | ||
if (StringUtility.isNullOrEmpty(id)) { | ||
return null; | ||
} | ||
return new StreetNameStringId(id); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...t/rt/dataobject/migration/fixture/house/StreetNameStringIdValueMigrationHandlerByMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.scout.rt.dataobject.migration.fixture.house; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.scout.rt.dataobject.ITypeVersion; | ||
import org.eclipse.scout.rt.dataobject.migration.AbstractDoValueMigrationHandlerByMap; | ||
import org.eclipse.scout.rt.dataobject.migration.DoValueMigrationId; | ||
import org.eclipse.scout.rt.dataobject.migration.fixture.version.CharlieFixtureTypeVersions.CharlieFixture_1; | ||
import org.eclipse.scout.rt.platform.IgnoreBean; | ||
|
||
@IgnoreBean | ||
public class StreetNameStringIdValueMigrationHandlerByMap extends AbstractDoValueMigrationHandlerByMap<StreetNameStringId> { | ||
|
||
@Override | ||
public DoValueMigrationId id() { | ||
return DoValueMigrationId.of("f2ccdfaf-e6cf-42af-963f-30aecd761d23"); | ||
} | ||
|
||
@Override | ||
public Class<? extends ITypeVersion> typeVersionClass() { | ||
return CharlieFixture_1.class; | ||
} | ||
|
||
@Override | ||
protected Map<StreetNameStringId, StreetNameStringId> initMigrationMap() { | ||
return Map.of( | ||
StreetNameStringId.of("Old Street"), StreetNameStringId.of("New Street"), | ||
StreetNameStringId.of("Evergreen Terrace"), StreetNameStringId.of("West 57th Street") | ||
); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...est/java/org/eclipse/scout/rt/dataobject/migration/fixture/house/StreetNameWrapperDo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.scout.rt.dataobject.migration.fixture.house; | ||
|
||
import jakarta.annotation.Generated; | ||
|
||
import org.eclipse.scout.rt.dataobject.DoEntity; | ||
import org.eclipse.scout.rt.dataobject.DoValue; | ||
import org.eclipse.scout.rt.dataobject.TypeName; | ||
|
||
/** | ||
* Only used to wrap a {@link StreetNameStringId} for migration | ||
*/ | ||
@TypeName("charlieFixture.StreetNameWrapper") | ||
public class StreetNameWrapperDo extends DoEntity { | ||
|
||
public DoValue<StreetNameStringId> value() { | ||
return doValue("value"); | ||
} | ||
|
||
|
||
/* ************************************************************************** | ||
* GENERATED CONVENIENCE METHODS | ||
* *************************************************************************/ | ||
|
||
@Generated("DoConvenienceMethodsGenerator") | ||
public StreetNameWrapperDo withValue(StreetNameStringId value) { | ||
value().set(value); | ||
return this; | ||
} | ||
|
||
@Generated("DoConvenienceMethodsGenerator") | ||
public StreetNameStringId getValue() { | ||
return value().get(); | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
.../java/org/eclipse/scout/rt/dataobject/migration/AbstractDoValueMigrationHandlerByMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2010, 2025 BSI Business Systems Integration AG | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.scout.rt.dataobject.migration; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* Simple {@link AbstractDoValueMigrationHandler} migrating values from old to new using a {@link Map} storing all | ||
* possible old to new mappings. The {@link #initMigrationMap()} method is called only once during object | ||
* initialization. | ||
*/ | ||
public abstract class AbstractDoValueMigrationHandlerByMap<T> extends AbstractDoValueMigrationHandler<T> { | ||
|
||
private final Map<T, T> m_migrationMap = Collections.unmodifiableMap(initMigrationMap()); | ||
|
||
protected abstract Map<T, T> initMigrationMap(); | ||
|
||
protected Map<T, T> getMigrationMap() { | ||
return m_migrationMap; | ||
} | ||
|
||
@Override | ||
public T migrate(DataObjectMigrationContext ctx, T value) { | ||
T migratedValue = getMigrationMap().get(value); | ||
return migratedValue != null ? migratedValue : value; | ||
} | ||
} |