#659 - ENH: Add support for Instant with @WhenCreated @WhenModified

This commit is contained in:
Robin Bygrave
2016-04-22 16:51:30 +12:00
parent b79bb892f7
commit e769abf737
9 changed files with 87 additions and 1 deletions
@@ -36,6 +36,17 @@ public class GeneratedInsertJavaTime {
}
}
/**
* Instant support.
*/
public static class InstantDT extends Base {
@Override
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
return JavaTimeUtils.toInstant(now);
}
}
/**
* LocalDateTime support.
*/
@@ -31,6 +31,22 @@ public class GeneratedUpdateJavaTime {
}
}
/**
* Instant support.
*/
public static class InstantDT extends Base {
@Override
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
return JavaTimeUtils.toInstant(now);
}
@Override
public Object getUpdateValue(BeanProperty prop, EntityBean bean, long now) {
return JavaTimeUtils.toInstant(now);
}
}
/**
* LocalDateTime support.
*/
@@ -5,6 +5,7 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import javax.persistence.PersistenceException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
@@ -27,6 +28,7 @@ public class InsertTimestampFactory {
map.put(long.class, longTime);
if (classLoadConfig.isJavaTimePresent()) {
map.put(Instant.class, new GeneratedInsertJavaTime.InstantDT());
map.put(LocalDateTime.class, new GeneratedInsertJavaTime.LocalDT());
map.put(OffsetDateTime.class, new GeneratedInsertJavaTime.OffsetDT());
map.put(ZonedDateTime.class, new GeneratedInsertJavaTime.ZonedDT());
@@ -11,6 +11,13 @@ import java.time.ZonedDateTime;
*/
public class JavaTimeUtils {
/**
* Return the system millis time as a LocalDateTime.
*/
public static Object toInstant(long systemMillis) {
return Instant.ofEpochMilli(systemMillis);
}
/**
* Return the system millis time as a LocalDateTime.
*/
@@ -5,6 +5,7 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import javax.persistence.PersistenceException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
@@ -27,6 +28,7 @@ public class UpdateTimestampFactory {
map.put(long.class, longTime);
if (classLoadConfig.isJavaTimePresent()) {
map.put(Instant.class, new GeneratedUpdateJavaTime.InstantDT());
map.put(LocalDateTime.class, new GeneratedUpdateJavaTime.LocalDT());
map.put(OffsetDateTime.class, new GeneratedUpdateJavaTime.OffsetDT());
map.put(ZonedDateTime.class, new GeneratedUpdateJavaTime.ZonedDT());