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

com.jwebmp.entityassist.converters.LocalDateTimestampAttributeConverter Maven / Gradle / Ivy

There is a newer version: 0.68.0.1
Show newest version
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());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy