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

com.github.marschall.threeten.jpa.LocalTimeConverter Maven / Gradle / Ivy

package com.github.marschall.threeten.jpa;

import java.sql.Time;
import java.time.LocalTime;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * Converts {@link Time} to {@link LocalTime} and back.
 */
@Converter(autoApply = true)
public class LocalTimeConverter implements AttributeConverter {
  // mapping with java.util.Calendar breaks EclipseLink

  @Override
  public Time convertToDatabaseColumn(LocalTime attribute) {
    if (attribute == null) {
      return null;
    }
    return Time.valueOf(attribute);
  }

  @Override
  public LocalTime convertToEntityAttribute(Time dbData) {
    if (dbData == null) {
      return null;
    }

    return dbData.toLocalTime();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy