microstream-one / examples

10 stars 4 forks source link

Restrictive customlegacytypehandler heuristic #25

Open cc-cpo opened 3 years ago

cc-cpo commented 3 years ago

Hello, I would like to disable/restrict the legacy type handling heuristic (which per default tries to automatically migrate schema changes)

My requirements:

Could you please point out how that can be achieved?

Thank you!

hg-ms commented 3 years ago

Hello,

If you simply want to print the mapping results you can use the PrintingLegacyTypeMappingResultor instead of the default one. Please see https://manual.docs.microstream.one/data-store/legacy-type-mapping/user-interaction how to setup.

If you like to verify the mapping results you can implement a custom PersistenceLegacyTypeMappingResultor:

public class CustomLegacyTypeMappingResultor<D> implements PersistenceLegacyTypeMappingResultor<D>
{
    ///////////////////////////////////////////////////////////////////////////
    // instance fields //
    ////////////////////

    final PersistenceLegacyTypeMappingResultor<D> delegate;

    ///////////////////////////////////////////////////////////////////////////
    // constructors //
    /////////////////

    CustomLegacyTypeMappingResultor(final PersistenceLegacyTypeMappingResultor<D> delegate)
    {
        super();
        this.delegate = delegate;
    }

    ///////////////////////////////////////////////////////////////////////////
    // methods //
    ////////////

    @Override
    public <T> PersistenceLegacyTypeMappingResult<D, T> createMappingResult(
        final PersistenceTypeDefinition                                                     legacyTypeDefinition,
        final PersistenceTypeHandler<D, T>                                                  currentTypeHandler  ,
        final XGettingMap<PersistenceTypeDefinitionMember, PersistenceTypeDefinitionMember> explicitMappings    ,
        final XGettingSet<PersistenceTypeDefinitionMember>                                  explicitNewMembers  ,
        final MultiMatch<PersistenceTypeDefinitionMember>                                   matchedMembers
    )
    {
        final PersistenceLegacyTypeMappingResult<D, T> result = this.delegate.createMappingResult(
            legacyTypeDefinition, currentTypeHandler, explicitMappings, explicitNewMembers, matchedMembers
        );

        //Verify, modify, print, etc or throw exception
        //...

        return result;
    }
}