You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/18 06:06:20 UTC

[shardingsphere] branch master updated: Simplify SQLValue (#9424)

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

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 27066b0  Simplify SQLValue (#9424)
27066b0 is described below

commit 27066b0563f98771a017386aac32b68241f4cf47
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Feb 18 14:05:48 2021 +0800

    Simplify SQLValue (#9424)
    
    * Simplify SQLValue
    
    * Simplify SQLValue
---
 .../test/integration/cases/value/SQLValue.java     | 38 ++++++++++++----------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/value/SQLValue.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/value/SQLValue.java
index c8bf8c3..2b70e56 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/value/SQLValue.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/value/SQLValue.java
@@ -22,6 +22,7 @@ import lombok.Getter;
 import java.sql.Date;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Locale;
 
 /**
  * SQL value.
@@ -34,27 +35,30 @@ public final class SQLValue {
     private final int index;
     
     public SQLValue(final String value, final String type, final int index) throws ParseException {
-        this.value = getValue(value, type);
+        this.value = null == type ? value : getValue(value, type);
         this.index = index;
     }
     
     private Object getValue(final String value, final String type) throws ParseException {
-        if (null == type || "varchar".equals(type) || "char".equals(type) || "String".equals(type)) {
-            return value;
+        switch (type) {
+            case "String":
+            case "varchar":
+            case "char":
+                return value;
+            case "int":
+                return Integer.parseInt(value);
+            case "long":
+                return Long.parseLong(value);
+            case "double":
+                return Double.parseDouble(value);
+            case "numeric":
+                return value.contains("//.") ? Double.parseDouble(value) : Long.parseLong(value);
+            case "Date":
+            case "datetime":
+                return new Date(new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(value).getTime());
+            default:
+                throw new UnsupportedOperationException(String.format("Cannot support type: `%s`", type));
         }
-        if ("int".equals(type)) {
-            return Integer.valueOf(value);
-        }
-        if ("numeric".equals(type) && !value.contains("//.")) {
-            return Long.valueOf(value);
-        }
-        if ("numeric".equals(type) && value.contains("//.")) {
-            return Double.valueOf(value);
-        }
-        if ("datetime".equals(type)) {
-            return new Date(new SimpleDateFormat("yyyy-MM-dd").parse(value).getTime());
-        }
-        throw new UnsupportedOperationException(String.format("Cannot support type: `%s`", type));
     }
     
     @Override
@@ -63,7 +67,7 @@ public final class SQLValue {
             return "'" + value + "'";
         }
         if (value instanceof Date) {
-            return new SimpleDateFormat("yyyy-MM-dd").format(value);
+            return new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(value);
         }
         return value.toString();
     }