aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/BaseJdbcService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service/BaseJdbcService.java')
-rw-r--r--src/main/java/com/juick/service/BaseJdbcService.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main/java/com/juick/service/BaseJdbcService.java b/src/main/java/com/juick/service/BaseJdbcService.java
index d6f29283..ab2e3fc8 100644
--- a/src/main/java/com/juick/service/BaseJdbcService.java
+++ b/src/main/java/com/juick/service/BaseJdbcService.java
@@ -17,7 +17,6 @@
package com.juick.service;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -30,7 +29,6 @@ import java.sql.Types;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
/**
* Created by aalexeev on 11/13/16.
@@ -82,9 +80,9 @@ public class BaseJdbcService {
}
public OffsetDateTime getOffsetDateTime(ResultSet rs, int columnIndex) throws SQLException {
if (haveNoDates) {
- var date = rs.getString(columnIndex);
- if (StringUtils.isNotEmpty(date)) {
- return OffsetDateTime.parse(date);
+ var date = rs.getLong(columnIndex);
+ if (date != 0) {
+ return Instant.ofEpochMilli(date).atOffset(ZoneOffset.UTC);
}
return null;
}
@@ -99,17 +97,22 @@ public class BaseJdbcService {
}
public Object fromEpochMilli(Long milliseconds) {
if (haveNoDates) {
- return Instant.ofEpochMilli(milliseconds).atOffset(ZoneOffset.UTC)
- .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
+ return milliseconds;
}
if (haveNoOffsetDateTime) {
return new Timestamp(milliseconds);
}
return Instant.ofEpochMilli(milliseconds).atOffset(ZoneOffset.UTC);
}
+ public Object toDateTime(OffsetDateTime now) {
+ if (haveNoDates) {
+ return now.toInstant().toEpochMilli();
+ }
+ return now;
+ }
public int dateTimeType() {
if (haveNoDates) {
- return Types.VARCHAR;
+ return Types.INTEGER;
}
if (haveNoOffsetDateTime) {
return Types.TIMESTAMP;