All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.meeuw.i18n.regions.persistence.RegionToStringConverter Maven / Gradle / Ivy

Go to download

Provides the service loader for Regions, and some utilities to deal with regions generally

There is a newer version: 2.1.0
Show newest version
package org.meeuw.i18n.regions.persistence;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.meeuw.i18n.regions.Region;
import org.meeuw.i18n.regions.RegionService;

/**
 * How to persist.
 *
 * Uses the iso code.
 *
 * TODO, we might need to prefix other region than Countries, because their codes may not be unique.
 * @author Michiel Meeuwissen
 * @since 0.1
 */
@Converter(autoApply = true)
public class RegionToStringConverter implements AttributeConverter {

    @Override
    @Nullable
    public String convertToDatabaseColumn(@Nullable Region region) {
        return region == null ? null : region.getCode();
    }

    @Override
    @Nullable
    public Region convertToEntityAttribute(@Nullable String region) {
        return region == null ? null :
            RegionService.getInstance().getByCode(region, true).orElse(null);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy