浏览代码

异构字段类型转换

穿云 2 月之前
父节点
当前提交
63691400ff

+ 4 - 0
dbsyncer-connector/dbsyncer-connector-mysql/src/main/java/org/dbsyncer/connector/mysql/schema/support/MySQLLongType.java

@@ -3,6 +3,7 @@
  */
 package org.dbsyncer.connector.mysql.schema.support;
 
+import org.dbsyncer.common.util.NumberUtil;
 import org.dbsyncer.sdk.model.Field;
 import org.dbsyncer.sdk.schema.support.LongType;
 
@@ -50,6 +51,9 @@ public final class MySQLLongType extends LongType {
         if (val instanceof Number) {
             return ((Number) val).longValue();
         }
+        if (val instanceof String) {
+            return NumberUtil.toLong((String) val);
+        }
         return throwUnsupportedException(val, field);
     }
 

+ 0 - 18
dbsyncer-connector/dbsyncer-connector-mysql/src/main/java/org/dbsyncer/connector/mysql/schema/support/MySQLShortType.java

@@ -43,24 +43,6 @@ public final class MySQLShortType extends ShortType {
         if (val instanceof Number) {
             return ((Number) val).shortValue();
         }
-//        if (val instanceof BitSet) {
-//            BitSet bitSet = (BitSet) val;
-//            byte[] bytes = bitSet.toByteArray();
-//            if (bytes.length > 0) {
-//                return (short) bytes[0];
-//            }
-//            return 0;
-//        }
-//        if (val instanceof Boolean) {
-//            Boolean b = (Boolean) val;
-//            return (short) (b ? 1 : 0);
-//        }
-//        if (val instanceof byte[]) {
-//            byte[] bytes = (byte[]) val;
-//            if (bytes.length > 1) {
-//                return (short) bytes[1];
-//            }
-//        }
         return throwUnsupportedException(val, field);
     }