com.jwebmp.entityassist.converters.LocalDateTimestampAttributeConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of entity-assist Show documentation
Show all versions of entity-assist Show documentation
A Domain Driven SQL Builder Generator for JPMS/JDK8
package com.jwebmp.entityassist.converters;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@Converter()
public class LocalDateTimestampAttributeConverter implements AttributeConverter
{
@Override
public Timestamp convertToDatabaseColumn(LocalDate attribute)
{
return (attribute == null ? null : Timestamp.valueOf(attribute.format(DateTimeFormatter.ISO_DATE_TIME)));
}
@Override
public LocalDate convertToEntityAttribute(Timestamp sqlTimestamp)
{
return (sqlTimestamp == null ? null : sqlTimestamp.toLocalDateTime().toLocalDate());
}
}