org.meeuw.i18n.regions.persistence.RegionToStringConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of i18n-regions Show documentation
Show all versions of i18n-regions Show documentation
Provides the service loader for Regions, and some utilities to deal with regions generally
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