mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#659 - ENH: Add support for Instant with @WhenCreated @WhenModified
This commit is contained in:
+11
@@ -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.
|
||||
*/
|
||||
|
||||
+16
@@ -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.
|
||||
*/
|
||||
|
||||
+2
@@ -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());
|
||||
|
||||
+7
@@ -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.
|
||||
*/
|
||||
|
||||
+2
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user