You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2023/05/05 13:38:00 UTC

[ignite-3] branch ignite-19321 created (now 26f8fb4756)

This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a change to branch ignite-19321
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


      at 26f8fb4756 Fix conversion jdbc arguments of temporal types.

This branch includes the following new commits:

     new 26f8fb4756 Fix conversion jdbc arguments of temporal types.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[ignite-3] 01/01: Fix conversion jdbc arguments of temporal types.

Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-19321
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 26f8fb4756d391dc199cf347dea2e6fcbd099f96
Author: amashenkov <an...@gmail.com>
AuthorDate: Fri May 5 16:37:48 2023 +0300

    Fix conversion jdbc arguments of temporal types.
---
 .../client/proto/ClientBinaryTupleUtils.java       | 16 ------------
 .../internal/jdbc/JdbcPreparedStatement.java       | 29 +++++++++++++++++++++-
 .../sql/engine/exec/RuntimeSortedIndexTest.java    |  2 +-
 3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java
index 8232844980..183b2544b3 100644
--- a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java
+++ b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientBinaryTupleUtils.java
@@ -21,9 +21,6 @@ import static org.apache.ignite.lang.ErrorGroups.Client.PROTOCOL_ERR;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
 import java.time.Duration;
 import java.time.Instant;
 import java.time.LocalDate;
@@ -178,19 +175,6 @@ public class ClientBinaryTupleUtils {
         } else if (obj instanceof Instant) {
             appendTypeAndScale(builder, ColumnType.TIMESTAMP);
             builder.appendTimestamp((Instant) obj);
-        } else if (obj instanceof Timestamp) {
-            appendTypeAndScale(builder, ColumnType.DATETIME);
-            Timestamp timeStamp = (Timestamp) obj;
-            LocalDateTime localDateTime = timeStamp.toLocalDateTime();
-            builder.appendDateTime(localDateTime);
-        } else if (obj instanceof Date) {
-            appendTypeAndScale(builder, ColumnType.DATE);
-            Date date = (Date) obj;
-            builder.appendDate(date.toLocalDate());
-        } else if (obj instanceof Time) {
-            appendTypeAndScale(builder, ColumnType.TIME);
-            Time time = (Time) obj;
-            builder.appendTime(time.toLocalTime());
         } else if (obj instanceof BigInteger) {
             appendTypeAndScale(builder, ColumnType.NUMBER);
             builder.appendNumber((BigInteger) obj);
diff --git a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcPreparedStatement.java b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcPreparedStatement.java
index d10709347b..680c89e693 100644
--- a/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcPreparedStatement.java
+++ b/modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc/JdbcPreparedStatement.java
@@ -53,6 +53,7 @@ import org.apache.ignite.internal.jdbc.proto.event.JdbcBatchExecuteResult;
 import org.apache.ignite.internal.jdbc.proto.event.JdbcBatchPreparedStmntRequest;
 import org.apache.ignite.internal.util.CollectionUtils;
 import org.apache.ignite.internal.util.StringUtils;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Jdbc prepared statement implementation.
@@ -652,7 +653,33 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
             currentArgs.add(null);
         }
 
-        currentArgs.set(paramIdx - 1, val);
+        currentArgs.set(paramIdx - 1, convertJdbcTypeToInternal(val));
+    }
+
+    /**
+     * Converts value of JDBC type to value of Ignite Client protocol types.
+     *
+     * <ul>
+     *     <li>java.sql.* to Java Time API</li>
+     * </ul>
+     */
+    private @Nullable Object convertJdbcTypeToInternal(@Nullable Object val) {
+        if (val instanceof java.util.Date) {
+            if (val instanceof Timestamp) {
+                Timestamp timeStamp = (Timestamp) val;
+                return timeStamp.toLocalDateTime();
+            } else if (val instanceof Date) {
+                Date date = (Date) val;
+                return date.toLocalDate();
+            } else if (val instanceof Time) {
+                Time time = (Time) val;
+                return time.toLocalTime();
+            }
+
+            return ((java.util.Date) val).toInstant();
+        }
+
+        return val;
     }
 
     /**
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/RuntimeSortedIndexTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/RuntimeSortedIndexTest.java
index 480996bbb6..940d814c6e 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/RuntimeSortedIndexTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/RuntimeSortedIndexTest.java
@@ -19,11 +19,11 @@ package org.apache.ignite.internal.sql.engine.exec;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import java.sql.Date;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Arrays;
 import java.util.BitSet;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;