de.bund.bva.isyfact.persistence.datetime.attributeconverter.PeriodAttributeConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of isy-persistence Show documentation
Show all versions of isy-persistence Show documentation
Die Querschnittsbibliothek isy-persistence
The newest version!
package de.bund.bva.isyfact.persistence.datetime.attributeconverter;
import java.time.Period;
import java.util.Objects;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
/**
* {@link javax.persistence.AttributeConverter} für {@link Period}.
*
* Das Speichern erfolgt in der ISO-8601-Darstellung als String.
*
*/
@Converter(autoApply = true)
public class PeriodAttributeConverter implements AttributeConverter {
@Override
public String convertToDatabaseColumn(Period period) {
return Objects.toString(period, null);
}
@Override
public Period convertToEntityAttribute(String aString) {
if (aString == null) {
return null;
}
return Period.parse(aString);
}
}