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

nl.vpro.persistence.DurationToTimeConverter Maven / Gradle / Ivy

The newest version!
package nl.vpro.persistence;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.sql.Time;
import java.time.Duration;

/**
 * @author Michiel Meeuwissen
 * @since 0.36
 */
@Converter
public class DurationToTimeConverter implements AttributeConverter {

    @Override
    public Time convertToDatabaseColumn(Duration duration) {
        return duration == null ? null : new Time(duration.toMillis());
    }

    @Override
    public Duration convertToEntityAttribute(Time timestamp) {
        return timestamp == null ? null : Duration.ofMillis(timestamp.getTime());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy