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

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

package com.github.marschall.threeten.jpa;

import java.sql.Timestamp;
import java.time.Instant;

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

/**
 * Converts {@link Timestamp} to {@link Instant} and back.
 */
@Converter(autoApply = true)
public class InstantConverter implements AttributeConverter {

  @Override
  public Timestamp convertToDatabaseColumn(Instant attribute) {
    if (attribute == null) {
      return null;
    }
    return Timestamp.from(attribute);
  }

  @Override
  public Instant convertToEntityAttribute(Timestamp dbData) {
    if (dbData == null) {
      return null;
    }
    return dbData.toInstant();
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy