Class DurationToIntegerConverter

java.lang.Object
com.endurancetrio.data.event.model.converter.DurationToIntegerConverter
All Implemented Interfaces:
jakarta.persistence.AttributeConverter<Duration,Integer>

public class DurationToIntegerConverter extends Object implements jakarta.persistence.AttributeConverter<Duration,Integer>
The DurationToIntegerConverter class is responsible for converting Duration values to their corresponding database column representation (milliseconds) and vice versa.

This converter is used to persist Duration fields as an Integer of milliseconds in the database. It converts the Duration to its total milliseconds when storing it and converts the milliseconds back to a Duration when retrieving it from the database.

  • Constructor Details

    • DurationToIntegerConverter

      public DurationToIntegerConverter()
  • Method Details

    • convertToDatabaseColumn

      public Integer convertToDatabaseColumn(Duration duration)
      Specified by:
      convertToDatabaseColumn in interface jakarta.persistence.AttributeConverter<Duration,Integer>
    • convertToEntityAttribute

      public Duration convertToEntityAttribute(Integer milliseconds)
      Specified by:
      convertToEntityAttribute in interface jakarta.persistence.AttributeConverter<Duration,Integer>