ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [05/41] ignite git commit: IGNITE-5483: Added limited support for Java8 LocalDateTime. This closes #2248.
Date Mon, 10 Jul 2017 12:00:21 GMT
IGNITE-5483: Added limited support for Java8 LocalDateTime. This closes #2248.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/99fd75dd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/99fd75dd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/99fd75dd

Branch: refs/heads/ignite-5578-1
Commit: 99fd75dd7766318af88a38b5640a648bba3ccdf1
Parents: 30922ed
Author: Sergey Kalashnikov <skalashnikov@gridgain.com>
Authored: Fri Jul 7 14:38:36 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Fri Jul 7 14:38:36 2017 +0300

----------------------------------------------------------------------
 .../query/h2/DmlStatementsProcessor.java         | 19 +++++++++++++++++++
 .../processors/query/h2/H2DatabaseType.java      | 10 ++++++++++
 .../processors/query/h2/H2RowDescriptor.java     | 13 +++++++++++++
 3 files changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/99fd75dd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
index 98d123f..0c1dbf9 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/DmlStatementsProcessor.java
@@ -20,6 +20,8 @@ package org.apache.ignite.internal.processors.query.h2;
 import java.lang.reflect.Array;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -79,8 +81,13 @@ import org.h2.command.dml.Insert;
 import org.h2.command.dml.Merge;
 import org.h2.command.dml.Update;
 import org.h2.table.Column;
+import org.h2.util.DateTimeUtils;
+import org.h2.util.LocalDateTimeUtils;
 import org.h2.value.DataType;
 import org.h2.value.Value;
+import org.h2.value.ValueDate;
+import org.h2.value.ValueTime;
+import org.h2.value.ValueTimestamp;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -711,6 +718,18 @@ public class DmlStatementsProcessor {
             return U.unmarshal(desc.context().marshaller(), (byte[]) val,
                 U.resolveClassLoader(desc.context().gridConfig()));
 
+        if (LocalDateTimeUtils.isJava8DateApiPresent()) {
+            if (val instanceof Timestamp && LocalDateTimeUtils.isLocalDateTime(expCls))
+                return LocalDateTimeUtils.valueToLocalDateTime(ValueTimestamp.get((Timestamp)val));
+
+            if (val instanceof Date && LocalDateTimeUtils.isLocalDate(expCls))
+                return LocalDateTimeUtils.valueToLocalDate(ValueDate.fromDateValue(
+                    DateTimeUtils.dateValueFromDate(((Date)val).getTime())));
+
+            if (val instanceof Time && LocalDateTimeUtils.isLocalTime(expCls))
+                return LocalDateTimeUtils.valueToLocalTime(ValueTime.get((Time)val));
+        }
+
         // We have to convert arrays of reference types manually - see https://issues.apache.org/jira/browse/IGNITE-4327
         // Still, we only can convert from Object[] to something more precise.
         if (type == Value.ARRAY && currCls != expCls) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/99fd75dd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java
index 47c7eb9..8e4e639 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.query.h2;
 
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.h2.util.LocalDateTimeUtils;
 import org.h2.value.DataType;
 
 import java.math.BigDecimal;
@@ -142,6 +143,15 @@ public enum H2DatabaseType {
         if (DataType.isGeometryClass(cls))
             return GEOMETRY;
 
+        if (LocalDateTimeUtils.isJava8DateApiPresent()) {
+            if (LocalDateTimeUtils.isLocalDate(cls))
+                return DATE;
+            else if (LocalDateTimeUtils.isLocalTime(cls))
+                return TIME;
+            else if (LocalDateTimeUtils.isLocalDateTime(cls))
+                return TIMESTAMP;
+        }
+
         return cls.isArray() && !cls.getComponentType().isPrimitive() ? ARRAY : OTHER;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/99fd75dd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
index a9bbd23..dab83d1 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2RowDescriptor.java
@@ -36,6 +36,7 @@ import org.h2.message.DbException;
 import org.h2.mvstore.cache.CacheLongKeyLIRS;
 import org.h2.result.SearchRow;
 import org.h2.result.SimpleRow;
+import org.h2.util.LocalDateTimeUtils;
 import org.h2.value.DataType;
 import org.h2.value.Value;
 import org.h2.value.ValueArray;
@@ -246,14 +247,26 @@ public class H2RowDescriptor implements GridH2RowDescriptor {
                 UUID uuid = (UUID)obj;
                 return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
             case Value.DATE:
+                if (LocalDateTimeUtils.isLocalDate(obj.getClass()))
+                    return LocalDateTimeUtils.localDateToDateValue(obj);
+
                 return ValueDate.get((Date)obj);
+
             case Value.TIME:
+                if (LocalDateTimeUtils.isLocalTime(obj.getClass()))
+                    return LocalDateTimeUtils.localTimeToTimeValue(obj);
+
                 return ValueTime.get((Time)obj);
+
             case Value.TIMESTAMP:
                 if (obj instanceof java.util.Date && !(obj instanceof Timestamp))
                     obj = new Timestamp(((java.util.Date)obj).getTime());
 
+                if (LocalDateTimeUtils.isLocalDateTime(obj.getClass()))
+                    return LocalDateTimeUtils.localDateTimeToValue(obj);
+
                 return ValueTimestamp.get((Timestamp)obj);
+
             case Value.DECIMAL:
                 return ValueDecimal.get((BigDecimal)obj);
             case Value.STRING:


Mime
View raw message