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

com.itranswarp.warpdb.converter.LocalDateConverter Maven / Gradle / Ivy

There is a newer version: 6.0.3
Show newest version
package com.itranswarp.warpdb.converter;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;

import javax.persistence.AttributeConverter;

/**
 * Built-in converter to store Java LocalDate type to database DATE type.
 * 
 * @author liaoxuefeng
 */
public class LocalDateConverter implements AttributeConverter {

	static final ZoneId SYSTEM_ZONE_ID = ZoneId.systemDefault();

	@Override
	public java.sql.Date convertToDatabaseColumn(LocalDate attribute) {
		return new java.sql.Date(attribute.atStartOfDay(SYSTEM_ZONE_ID).toEpochSecond() * 1000);
	}

	@Override
	public LocalDate convertToEntityAttribute(java.sql.Date dbData) {
		return Instant.ofEpochMilli(dbData.getTime()).atZone(SYSTEM_ZONE_ID).toLocalDate();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy