timoninmaxim commented on code in PR #319:
URL: https://github.com/apache/ignite-extensions/pull/319#discussion_r2281779490


##########
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/postgresql/JavaToSqlTypeMapper.java:
##########
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cdc.postgresql;
+
+import java.math.BigDecimal;
+import java.sql.PreparedStatement;
+import java.sql.Types;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteException;
+
+/** */
+class JavaToSqlTypeMapper {
+    /** */
+    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 setValue(PreparedStatement stmt, int idx, Object obj) {
+        try {
+            assert obj != null;
+
+            if (obj instanceof byte[]) {
+                stmt.setBytes(idx, (byte[])obj); // Preferred setter for byte[]
+
+                return;
+            }
+
+            JavaToSqlType type = 
JAVA_TO_SQL_TYPE_MAP.get(obj.getClass().getName());
+
+            if (type != null)
+                stmt.setObject(idx, obj, type.typeId());
+            else
+                throw new IgniteException("Java-to-SQL type mapping is not 
defined for class: "
+                    + obj.getClass().getName());
+        }
+        catch (Throwable e) {

Review Comment:
   catch SQLException



-- 
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