Implemented a Year-to-Integer converter
authorKai Moritz <kai@juplo.de>
Mon, 21 Dec 2015 22:45:48 +0000 (23:45 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 15 Aug 2017 17:44:40 +0000 (19:44 +0200)
src/main/java/de/juplo/jpa/converters/YearConverter.java [new file with mode: 0644]

diff --git a/src/main/java/de/juplo/jpa/converters/YearConverter.java b/src/main/java/de/juplo/jpa/converters/YearConverter.java
new file mode 100644 (file)
index 0000000..59875a6
--- /dev/null
@@ -0,0 +1,26 @@
+package de.juplo.jpa.converters;
+
+import java.time.Year;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+
+/**
+ * Converts a {@link Year} into its {@link Integer} representation.
+ * @author Kai Moritz
+ */
+@Converter(autoApply = true)
+public class YearConverter implements AttributeConverter<Year, Integer>
+{
+  @Override
+  public Integer convertToDatabaseColumn(Year year)
+  {
+    return year.getValue();
+  }
+
+  @Override
+  public Year convertToEntityAttribute(Integer integer)
+  {
+    return Year.of(integer);
+  }
+}