mirror of https://github.com/bvn13/ADaStor.git
24 lines
627 B
Java
24 lines
627 B
Java
package ru.bvn13.adastor.converters;
|
|
|
|
import javax.persistence.AttributeConverter;
|
|
import javax.persistence.Converter;
|
|
import java.sql.Date;
|
|
import java.time.LocalDate;
|
|
|
|
/**
|
|
* @author boykovn at 11.03.2019
|
|
*/
|
|
@Converter(autoApply = true)
|
|
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
|
|
|
|
@Override
|
|
public Date convertToDatabaseColumn(LocalDate locDate) {
|
|
return (locDate == null ? null : Date.valueOf(locDate));
|
|
}
|
|
|
|
@Override
|
|
public LocalDate convertToEntityAttribute(Date sqlDate) {
|
|
return (sqlDate == null ? null : sqlDate.toLocalDate());
|
|
}
|
|
}
|