xbkaishui commented on a change in pull request #7601:
URL: https://github.com/apache/shardingsphere/pull/7601#discussion_r497181358
##########
File path:
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ResultSetUtil.java
##########
@@ -77,6 +82,49 @@ public static Object convertValue(final Object value, final
Class<?> convertType
return value;
}
}
+
+ private static Object convertURL(final Object value) {
+ String val = value.toString();
+ try {
+ return new URL(val);
+ } catch (MalformedURLException ex) {
+ throw new ShardingSphereException("Unsupported Date type: URL
value %s", value);
+ }
+ }
+
+ /**
+ * Convert object to BigDecimal.
+ *
+ * @param value current db object
+ * @param needScale need scale
+ * @param scale scale size
+ * @return big decimal
+ */
+ public static Object convertBigDecimalValue(final Object value, final
boolean needScale, final int scale) {
+ if (null == value) {
+ return convertNullValue(BigDecimal.class);
+ }
+ if (value.getClass() == BigDecimal.class) {
+ return adjustBigDecimalResult((BigDecimal) value, needScale,
scale);
+ }
+ if (value instanceof Number || value instanceof String) {
+ BigDecimal bigDecimal = new BigDecimal(value.toString());
+ return adjustBigDecimalResult(bigDecimal, needScale, scale);
+ }
+ throw new ShardingSphereException("Unsupported Date type: BigDecimal
value %s", value);
+ }
+
+ private static BigDecimal adjustBigDecimalResult(final BigDecimal value,
final boolean needScale, final int scale) {
+ if (needScale) {
+ try {
+ return value.setScale(scale);
+ } catch (ArithmeticException ex) {
Review comment:
done
##########
File path:
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ResultSetUtil.java
##########
@@ -77,6 +82,49 @@ public static Object convertValue(final Object value, final
Class<?> convertType
return value;
}
}
+
+ private static Object convertURL(final Object value) {
+ String val = value.toString();
+ try {
+ return new URL(val);
+ } catch (MalformedURLException ex) {
+ throw new ShardingSphereException("Unsupported Date type: URL
value %s", value);
+ }
+ }
+
+ /**
+ * Convert object to BigDecimal.
+ *
+ * @param value current db object
+ * @param needScale need scale
+ * @param scale scale size
+ * @return big decimal
+ */
+ public static Object convertBigDecimalValue(final Object value, final
boolean needScale, final int scale) {
+ if (null == value) {
+ return convertNullValue(BigDecimal.class);
+ }
+ if (value.getClass() == BigDecimal.class) {
+ return adjustBigDecimalResult((BigDecimal) value, needScale,
scale);
+ }
+ if (value instanceof Number || value instanceof String) {
+ BigDecimal bigDecimal = new BigDecimal(value.toString());
+ return adjustBigDecimalResult(bigDecimal, needScale, scale);
+ }
+ throw new ShardingSphereException("Unsupported Date type: BigDecimal
value %s", value);
+ }
+
+ private static BigDecimal adjustBigDecimalResult(final BigDecimal value,
final boolean needScale, final int scale) {
+ if (needScale) {
+ try {
+ return value.setScale(scale);
+ } catch (ArithmeticException ex) {
+ // try this if above fails
Review comment:
done
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]