maksaska commented on code in PR #317:
URL: https://github.com/apache/ignite-extensions/pull/317#discussion_r2255267302


##########
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/postgresql/JavaToSqlTypeMapper.java:
##########
@@ -0,0 +1,264 @@
+package org.apache.ignite.cdc.postgresql;
+
+import java.math.BigDecimal;
+import java.sql.PreparedStatement;
+import java.sql.Types;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.Period;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.lang.RunnableX;
+
+/** */
+public class JavaToSqlTypeMapper {
+    /** */
+    private static final int NO_SQL_TYPE = -1;
+
+    /** */
+    private static final Map<String, JavaToSqlType> JAVA_TO_SQL_TYPE_MAP = new 
HashMap<>();
+
+    static {
+        for (JavaToSqlType type : JavaToSqlType.values())
+            JAVA_TO_SQL_TYPE_MAP.put(type.javaTypeName(), type);
+    }
+
+    /**
+     * Sets a value in the PreparedStatement at the given index using the 
appropriate setter
+     * based on the runtime type of the object.
+     * @param stmt {@link PreparedStatement}
+     * @param idx value index in {@link PreparedStatement}
+     * @param obj value
+     */
+    public void setEventFieldValue(PreparedStatement stmt, Integer idx, Object 
obj) {
+        if (obj == null) {
+            setSafe(() -> stmt.setNull(idx, Types.NULL));
+
+            return;
+        }
+
+        int types = JAVA_TO_SQL_TYPE_MAP.get(obj.getClass().getName()).types();
+
+        if (types != -1)
+            setSafe(() -> stmt.setObject(idx, obj, types));
+        else if (obj instanceof Duration) {
+            Duration dur = (Duration)obj;
+
+            BigDecimal durVal = 
BigDecimal.valueOf(dur.getSeconds()).add(BigDecimal.valueOf(dur.getNano(), 9));
+
+            setSafe(() -> stmt.setBigDecimal(idx, durVal));
+        }
+        else if (obj instanceof byte[])
+            setSafe(() -> stmt.setBytes(idx, (byte[])obj));

Review Comment:
   There is no Types constant for byte[] to use with `setObject(idx, obj, 
types)` setter in jdbc



##########
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/postgresql/JavaToSqlTypeMapper.java:
##########
@@ -0,0 +1,264 @@
+package org.apache.ignite.cdc.postgresql;
+
+import java.math.BigDecimal;
+import java.sql.PreparedStatement;
+import java.sql.Types;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.Period;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.lang.RunnableX;
+
+/** */
+public class JavaToSqlTypeMapper {
+    /** */
+    private static final int NO_SQL_TYPE = -1;
+
+    /** */
+    private static final Map<String, JavaToSqlType> JAVA_TO_SQL_TYPE_MAP = new 
HashMap<>();
+
+    static {
+        for (JavaToSqlType type : JavaToSqlType.values())
+            JAVA_TO_SQL_TYPE_MAP.put(type.javaTypeName(), type);
+    }
+
+    /**
+     * Sets a value in the PreparedStatement at the given index using the 
appropriate setter
+     * based on the runtime type of the object.
+     * @param stmt {@link PreparedStatement}
+     * @param idx value index in {@link PreparedStatement}
+     * @param obj value
+     */
+    public void setEventFieldValue(PreparedStatement stmt, Integer idx, Object 
obj) {
+        if (obj == null) {
+            setSafe(() -> stmt.setNull(idx, Types.NULL));
+
+            return;
+        }
+
+        int types = JAVA_TO_SQL_TYPE_MAP.get(obj.getClass().getName()).types();
+
+        if (types != -1)
+            setSafe(() -> stmt.setObject(idx, obj, types));
+        else if (obj instanceof Duration) {
+            Duration dur = (Duration)obj;

Review Comment:
   Removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to