From eeaa457879188820576f88853b566977515626e8 Mon Sep 17 00:00:00 2001 From: VampireAchao Date: Fri, 17 Feb 2023 12:44:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[enhancement]=20=E6=94=AF=E6=8C=81dbType?= =?UTF-8?q?=E4=B8=BAUNKNOWN=E6=97=B6=E4=BD=BF=E7=94=A8Convertor=EF=BC=8C?= =?UTF-8?q?=E4=BA=A4=E7=94=B1=E7=94=A8=E6=88=B7=E8=87=AA=E5=B7=B1=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhxu/bs/implement/DefaultParamResolver.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java b/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java index 7034d9ee..3a96d429 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java @@ -325,15 +325,13 @@ public class DefaultParamResolver implements ParamResolver { return null; } DbType dbType = meta.getDbType(); - if (dbType != DbType.UNKNOWN) { - if (dbType.getType().isInstance(value)) { - return value; - } - Class vType = value.getClass(); - for (Convertor convertor: convertors) { - if (convertor.supports(dbType, vType)) { - return convertor.convert(dbType, value); - } + if (dbType.getType().isInstance(value)) { + return value; + } + Class vType = value.getClass(); + for (Convertor convertor : convertors) { + if (convertor.supports(dbType, vType)) { + return convertor.convert(dbType, value); } } return value; -- Gitee From 817206f496fd38fc12a28197a76bdc24e9835bad Mon Sep 17 00:00:00 2001 From: VampireAchao Date: Fri, 17 Feb 2023 14:38:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[enhancement]=20=E6=94=AF=E6=8C=81dbType?= =?UTF-8?q?=E4=B8=BAUNKNOWN=E6=97=B6=E4=BD=BF=E7=94=A8Convertor=EF=BC=8C?= =?UTF-8?q?=E4=BA=A4=E7=94=B1=E7=94=A8=E6=88=B7=E8=87=AA=E5=B7=B1=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/zhxu/bs/implement/DefaultParamResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java b/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java index 3a96d429..95440d14 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java @@ -325,7 +325,7 @@ public class DefaultParamResolver implements ParamResolver { return null; } DbType dbType = meta.getDbType(); - if (dbType.getType().isInstance(value)) { + if (dbType.getType() != null && dbType.getType().isInstance(value)) { return value; } Class vType = value.getClass(); -- Gitee From 582ce3e6bdd89ef7c6b02f55aee7b9a1ddc53e4d Mon Sep 17 00:00:00 2001 From: VampireAchao Date: Fri, 17 Feb 2023 15:02:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[enhancement]=20Convertor=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=B9=E6=B3=95DbType=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=94=B9=E4=B8=BAFieldMeta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/zhxu/bs/ParamResolver.java | 13 +++-- .../zhxu/bs/convertor/BoolParamConvertor.java | 7 +-- .../zhxu/bs/convertor/DateParamConvertor.java | 15 +++--- .../bs/convertor/DateTimeParamConvertor.java | 21 +++++--- .../bs/convertor/NumberParamConvertor.java | 23 ++++---- .../zhxu/bs/convertor/TimeParamConvertor.java | 15 +++--- .../bs/implement/DefaultParamResolver.java | 49 +++++++++++++---- .../convertor/BoolParamConvertorTestCase.java | 52 ++++++++++--------- .../convertor/DateParamConvertorTestCase.java | 22 ++++---- .../DateTimeParamConvertorTestCase.java | 22 ++++---- .../NumberParamConvertorTestCase.java | 26 ++++++---- 11 files changed, 160 insertions(+), 105 deletions(-) diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/ParamResolver.java b/bean-searcher/src/main/java/cn/zhxu/bs/ParamResolver.java index aec7ba85..e04b5459 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/ParamResolver.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/ParamResolver.java @@ -1,10 +1,9 @@ package cn.zhxu.bs; -import cn.zhxu.bs.bean.DbType; -import cn.zhxu.bs.param.FetchType; - import java.util.Map; +import cn.zhxu.bs.param.FetchType; + /** * 请求参数解析器接口 * @@ -28,18 +27,18 @@ public interface ParamResolver { interface Convertor { /** - * @param dbType 需转换的目标类型 + * @param meta 字段元信息 * @param valueType 值类型 * @return 是否支持 */ - boolean supports(DbType dbType, Class valueType); + boolean supports(FieldMeta meta, Class valueType); /** - * @param dbType 目标类型 + * @param meta 字段元信息 * @param value 待转换的值 * @return 转换后的值 */ - Object convert(DbType dbType, Object value); + Object convert(FieldMeta meta, Object value); } diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/BoolParamConvertor.java b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/BoolParamConvertor.java index bedae3fc..2c00b3d1 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/BoolParamConvertor.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/BoolParamConvertor.java @@ -1,5 +1,6 @@ package cn.zhxu.bs.convertor; +import cn.zhxu.bs.FieldMeta; import cn.zhxu.bs.ParamResolver; import cn.zhxu.bs.bean.DbType; import cn.zhxu.bs.util.StringUtils; @@ -15,14 +16,14 @@ public class BoolParamConvertor implements ParamResolver.Convertor { private String[] falseValues = new String[] { "0", "OFF", "FALSE", "N", "NO", "F" }; @Override - public boolean supports(DbType dbType, Class valueType) { - return dbType == DbType.BOOL && ( + public boolean supports(FieldMeta meta, Class valueType) { + return meta.getDbType() == DbType.BOOL && ( String.class == valueType || Number.class.isAssignableFrom(valueType) || Boolean.class == valueType ); } @Override - public Object convert(DbType dbType, Object value) { + public Object convert(FieldMeta meta, Object value) { if (value instanceof Boolean) { return value; } diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateParamConvertor.java b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateParamConvertor.java index 9e0a0782..11f259ff 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateParamConvertor.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateParamConvertor.java @@ -1,10 +1,6 @@ package cn.zhxu.bs.convertor; -import cn.zhxu.bs.ParamResolver; -import cn.zhxu.bs.bean.DbType; -import cn.zhxu.bs.util.StringUtils; - import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; @@ -17,6 +13,11 @@ import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.ParamResolver; +import cn.zhxu.bs.bean.DbType; +import cn.zhxu.bs.util.StringUtils; + /** * [String | java.util.Date | LocalDate to java.sql.Date] 参数值转换器 * @@ -30,15 +31,15 @@ public class DateParamConvertor implements ParamResolver.Convertor { static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); @Override - public boolean supports(DbType dbType, Class valueType) { - return dbType == DbType.DATE && ( + public boolean supports(FieldMeta meta, Class valueType) { + return meta.getDbType() == DbType.DATE && ( String.class == valueType || Date.class == valueType || LocalDate.class == valueType || Timestamp.class == valueType || LocalDateTime.class == valueType ); } @Override - public Object convert(DbType dbType, Object value) { + public Object convert(FieldMeta meta, Object value) { if (value instanceof String) { String s = ((String) value).trim().replaceAll("/", "-"); if (StringUtils.isBlank(s)) { diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateTimeParamConvertor.java b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateTimeParamConvertor.java index 891302cd..f94a01e8 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateTimeParamConvertor.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/DateTimeParamConvertor.java @@ -1,12 +1,14 @@ package cn.zhxu.bs.convertor; -import cn.zhxu.bs.ParamResolver; -import cn.zhxu.bs.bean.DbType; -import cn.zhxu.bs.util.StringUtils; +import static java.time.temporal.ChronoField.EPOCH_DAY; import java.sql.Timestamp; -import java.time.*; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; @@ -14,7 +16,10 @@ import java.util.Date; import java.util.TimeZone; import java.util.regex.Pattern; -import static java.time.temporal.ChronoField.EPOCH_DAY; +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.ParamResolver; +import cn.zhxu.bs.bean.DbType; +import cn.zhxu.bs.util.StringUtils; /** * [String | java.util.Date | LocalDate to java.sql.Date] 参数值转换器 @@ -34,12 +39,12 @@ public class DateTimeParamConvertor implements ParamResolver.Convertor { private TimeZone timeZone = TimeZone.getDefault(); @Override - public boolean supports(DbType dbType, Class valueType) { - return dbType == DbType.DATETIME && (String.class == valueType || Date.class == valueType || LocalDate.class == valueType || LocalDateTime.class == valueType); + public boolean supports(FieldMeta meta, Class valueType) { + return meta.getDbType() == DbType.DATETIME && (String.class == valueType || Date.class == valueType || LocalDate.class == valueType || LocalDateTime.class == valueType); } @Override - public Object convert(DbType dbType, Object value) { + public Object convert(FieldMeta meta, Object value) { if (value instanceof String) { String s = ((String) value).trim().replaceAll("/", "-"); if (StringUtils.isBlank(s)) { diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/NumberParamConvertor.java b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/NumberParamConvertor.java index 32279bd0..9b340524 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/NumberParamConvertor.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/NumberParamConvertor.java @@ -1,11 +1,12 @@ package cn.zhxu.bs.convertor; +import java.math.BigDecimal; + +import cn.zhxu.bs.FieldMeta; import cn.zhxu.bs.ParamResolver; import cn.zhxu.bs.bean.DbType; import cn.zhxu.bs.util.StringUtils; -import java.math.BigDecimal; - /** * [String | Number to Number] 参数值转换器 * @@ -15,23 +16,25 @@ import java.math.BigDecimal; public class NumberParamConvertor implements ParamResolver.Convertor { @Override - public boolean supports(DbType dbType, Class valueType) { + public boolean supports(FieldMeta meta, Class valueType) { + DbType dbType = meta.getDbType(); return ( - dbType == DbType.BYTE || dbType == DbType.SHORT || dbType == DbType.INT || dbType == DbType.LONG || - dbType == DbType.FLOAT || dbType == DbType.DOUBLE || dbType == DbType.DECIMAL + dbType == DbType.BYTE || dbType == DbType.SHORT || dbType == DbType.INT || dbType == DbType.LONG || + dbType == DbType.FLOAT || dbType == DbType.DOUBLE || dbType == DbType.DECIMAL ) && ( - String.class == valueType || Byte.class == valueType || Short.class == valueType || - Integer.class == valueType || Long.class == valueType || Float.class == valueType || - Double.class == valueType || BigDecimal.class == valueType + String.class == valueType || Byte.class == valueType || Short.class == valueType || + Integer.class == valueType || Long.class == valueType || Float.class == valueType || + Double.class == valueType || BigDecimal.class == valueType ); } @Override - public Object convert(DbType dbType, Object value) { + public Object convert(FieldMeta meta, Object value) { + DbType dbType = meta.getDbType(); try { return doConvert(dbType, value); } catch (NumberFormatException e) { - throw new IllegalArgumentException("Field type is " + dbType +", but the param value is: " + value, e); + throw new IllegalArgumentException("Field type is " + dbType + ", but the param value is: " + value, e); } } diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/TimeParamConvertor.java b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/TimeParamConvertor.java index 86b74374..f6ce9329 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/convertor/TimeParamConvertor.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/convertor/TimeParamConvertor.java @@ -1,10 +1,6 @@ package cn.zhxu.bs.convertor; -import cn.zhxu.bs.ParamResolver; -import cn.zhxu.bs.bean.DbType; -import cn.zhxu.bs.util.StringUtils; - import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalQueries; @@ -12,6 +8,11 @@ import java.time.temporal.TemporalQuery; import java.util.regex.Matcher; import java.util.regex.Pattern; +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.ParamResolver; +import cn.zhxu.bs.bean.DbType; +import cn.zhxu.bs.util.StringUtils; + /** * [String | java.util.Date | LocalDate to java.sql.Date] 参数值转换器 * @@ -27,12 +28,12 @@ public class TimeParamConvertor implements ParamResolver.Convertor { static final DateTimeFormatter FORMATTER_2 = DateTimeFormatter.ofPattern("HH:mm"); @Override - public boolean supports(DbType dbType, Class valueType) { - return dbType == DbType.TIME && (String.class == valueType || LocalTime.class == valueType); + public boolean supports(FieldMeta meta, Class valueType) { + return meta.getDbType() == DbType.TIME && (String.class == valueType || LocalTime.class == valueType); } @Override - public Object convert(DbType dbType, Object value) { + public Object convert(FieldMeta meta, Object value) { if (value instanceof String) { String s = ((String) value).trim(); if (StringUtils.isBlank(s)) { diff --git a/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java b/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java index 95440d14..d6dfc9df 100644 --- a/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java +++ b/bean-searcher/src/main/java/cn/zhxu/bs/implement/DefaultParamResolver.java @@ -1,18 +1,47 @@ package cn.zhxu.bs.implement; -import cn.zhxu.bs.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import cn.zhxu.bs.BeanMeta; +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.FieldOp; +import cn.zhxu.bs.FieldOpPool; +import cn.zhxu.bs.FieldOps; +import cn.zhxu.bs.IllegalParamException; +import cn.zhxu.bs.PageExtractor; +import cn.zhxu.bs.ParamFilter; +import cn.zhxu.bs.ParamResolver; +import cn.zhxu.bs.SearchParam; import cn.zhxu.bs.bean.DbType; -import cn.zhxu.bs.convertor.*; +import cn.zhxu.bs.convertor.BoolParamConvertor; +import cn.zhxu.bs.convertor.DateParamConvertor; +import cn.zhxu.bs.convertor.DateTimeParamConvertor; +import cn.zhxu.bs.convertor.NumberParamConvertor; +import cn.zhxu.bs.convertor.TimeParamConvertor; import cn.zhxu.bs.filter.SizeLimitParamFilter; import cn.zhxu.bs.group.DefaultGroupResolver; import cn.zhxu.bs.group.Group; import cn.zhxu.bs.group.GroupResolver; -import cn.zhxu.bs.param.*; -import cn.zhxu.bs.util.*; - -import java.util.*; -import java.util.regex.Pattern; -import java.util.stream.Collectors; +import cn.zhxu.bs.param.FetchType; +import cn.zhxu.bs.param.FieldParam; +import cn.zhxu.bs.param.OrderBy; +import cn.zhxu.bs.param.Paging; +import cn.zhxu.bs.util.Builder; +import cn.zhxu.bs.util.MapBuilder; +import cn.zhxu.bs.util.MapWrapper; +import cn.zhxu.bs.util.ObjectUtils; +import cn.zhxu.bs.util.StringUtils; /** * @author Troy.Zhou @ 2017-03-20 @@ -330,8 +359,8 @@ public class DefaultParamResolver implements ParamResolver { } Class vType = value.getClass(); for (Convertor convertor : convertors) { - if (convertor.supports(dbType, vType)) { - return convertor.convert(dbType, value); + if (convertor.supports(meta, vType)) { + return convertor.convert(meta, value); } } return value; diff --git a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/BoolParamConvertorTestCase.java b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/BoolParamConvertorTestCase.java index 7a4bcbec..abdda2c8 100644 --- a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/BoolParamConvertorTestCase.java +++ b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/BoolParamConvertorTestCase.java @@ -1,9 +1,11 @@ package cn.zhxu.bs.convertor; -import cn.zhxu.bs.bean.DbType; import org.junit.Assert; import org.junit.Test; +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.bean.DbType; + public class BoolParamConvertorTestCase { final BoolParamConvertor convertor = new BoolParamConvertor(); @@ -26,34 +28,36 @@ public class BoolParamConvertorTestCase { } void assertSupports(DbType dbType, boolean supports) { - Assert.assertEquals(supports, convertor.supports(dbType, Byte.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Short.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Integer.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Long.class)); - Assert.assertEquals(supports, convertor.supports(dbType, String.class)); + final FieldMeta meta = new FieldMeta(null, null, null, null, false, null, dbType); + Assert.assertEquals(supports, convertor.supports(meta, Byte.class)); + Assert.assertEquals(supports, convertor.supports(meta, Short.class)); + Assert.assertEquals(supports, convertor.supports(meta, Integer.class)); + Assert.assertEquals(supports, convertor.supports(meta, Long.class)); + Assert.assertEquals(supports, convertor.supports(meta, String.class)); } @Test public void test_convert() { - Assert.assertEquals(true, convertor.convert(DbType.BOOL, 1)); - Assert.assertEquals(true, convertor.convert(DbType.BOOL, true)); - Assert.assertEquals(true, convertor.convert(DbType.BOOL, "true")); - Assert.assertEquals(true, convertor.convert(DbType.BOOL, "on")); - Assert.assertEquals(true, convertor.convert(DbType.BOOL, "TRUE")); - Assert.assertEquals(true, convertor.convert(DbType.BOOL, "ON")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, 0)); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, false)); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "false")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "f")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "off")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "n")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "no")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "FALSE")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "F")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "OFF")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "N")); - Assert.assertEquals(false, convertor.convert(DbType.BOOL, "NO")); + FieldMeta meta = new FieldMeta(null, null, null, null, false, null, DbType.BOOL); + Assert.assertEquals(true, convertor.convert(meta, 1)); + Assert.assertEquals(true, convertor.convert(meta, true)); + Assert.assertEquals(true, convertor.convert(meta, "true")); + Assert.assertEquals(true, convertor.convert(meta, "on")); + Assert.assertEquals(true, convertor.convert(meta, "TRUE")); + Assert.assertEquals(true, convertor.convert(meta, "ON")); + Assert.assertEquals(false, convertor.convert(meta, 0)); + Assert.assertEquals(false, convertor.convert(meta, false)); + Assert.assertEquals(false, convertor.convert(meta, "false")); + Assert.assertEquals(false, convertor.convert(meta, "f")); + Assert.assertEquals(false, convertor.convert(meta, "off")); + Assert.assertEquals(false, convertor.convert(meta, "n")); + Assert.assertEquals(false, convertor.convert(meta, "no")); + Assert.assertEquals(false, convertor.convert(meta, "FALSE")); + Assert.assertEquals(false, convertor.convert(meta, "F")); + Assert.assertEquals(false, convertor.convert(meta, "OFF")); + Assert.assertEquals(false, convertor.convert(meta, "N")); + Assert.assertEquals(false, convertor.convert(meta, "NO")); } } diff --git a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateParamConvertorTestCase.java b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateParamConvertorTestCase.java index bcad4b93..dc7cb88c 100644 --- a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateParamConvertorTestCase.java +++ b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateParamConvertorTestCase.java @@ -1,9 +1,5 @@ package cn.zhxu.bs.convertor; -import cn.zhxu.bs.bean.DbType; -import org.junit.Assert; -import org.junit.Test; - import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -11,6 +7,12 @@ import java.time.LocalDate; import java.util.Calendar; import java.util.Date; +import org.junit.Assert; +import org.junit.Test; + +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.bean.DbType; + public class DateParamConvertorTestCase { final DateParamConvertor convertor = new DateParamConvertor(); @@ -33,10 +35,11 @@ public class DateParamConvertorTestCase { } void assertSupports(DbType dbType, boolean supports) { - Assert.assertEquals(supports, convertor.supports(dbType, Date.class)); - Assert.assertEquals(supports, convertor.supports(dbType, LocalDate.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Timestamp.class)); - Assert.assertEquals(supports, convertor.supports(dbType, String.class)); + final FieldMeta meta = new FieldMeta(null, null, null, null, false, null, dbType); + Assert.assertEquals(supports, convertor.supports(meta, Date.class)); + Assert.assertEquals(supports, convertor.supports(meta, LocalDate.class)); + Assert.assertEquals(supports, convertor.supports(meta, Timestamp.class)); + Assert.assertEquals(supports, convertor.supports(meta, String.class)); } @Test @@ -56,7 +59,8 @@ public class DateParamConvertorTestCase { } private void assertConvert(Object value) { - Object date = convertor.convert(DbType.DATE, value); + FieldMeta meta = new FieldMeta(null, null, null, null, false, null, DbType.DATE); + Object date = convertor.convert(meta, value); Assert.assertTrue(date instanceof java.sql.Date); Calendar calendar = Calendar.getInstance(); calendar.setTime((java.sql.Date) date); diff --git a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateTimeParamConvertorTestCase.java b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateTimeParamConvertorTestCase.java index 01c1bf69..b2afe3fe 100644 --- a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateTimeParamConvertorTestCase.java +++ b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/DateTimeParamConvertorTestCase.java @@ -1,9 +1,5 @@ package cn.zhxu.bs.convertor; -import cn.zhxu.bs.bean.DbType; -import org.junit.Assert; -import org.junit.Test; - import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -12,6 +8,12 @@ import java.time.LocalDateTime; import java.util.Calendar; import java.util.Date; +import org.junit.Assert; +import org.junit.Test; + +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.bean.DbType; + public class DateTimeParamConvertorTestCase { final DateTimeParamConvertor convertor = new DateTimeParamConvertor(); @@ -34,10 +36,11 @@ public class DateTimeParamConvertorTestCase { } void assertSupports(DbType dbType, boolean supports) { - Assert.assertEquals(supports, convertor.supports(dbType, Date.class)); - Assert.assertEquals(supports, convertor.supports(dbType, LocalDate.class)); - Assert.assertEquals(supports, convertor.supports(dbType, LocalDateTime.class)); - Assert.assertEquals(supports, convertor.supports(dbType, String.class)); + FieldMeta meta = new FieldMeta(null, null, null, null, false, null, dbType); + Assert.assertEquals(supports, convertor.supports(meta, Date.class)); + Assert.assertEquals(supports, convertor.supports(meta, LocalDate.class)); + Assert.assertEquals(supports, convertor.supports(meta, LocalDateTime.class)); + Assert.assertEquals(supports, convertor.supports(meta, String.class)); } @Test @@ -60,7 +63,8 @@ public class DateTimeParamConvertorTestCase { } private void assertConvert(Object value, int hour, int minutes, int seconds) { - Object date = convertor.convert(DbType.DATETIME, value); + FieldMeta meta = new FieldMeta(null, null, null, null, false, null, DbType.DATETIME); + Object date = convertor.convert(meta, value); Assert.assertTrue(date instanceof java.sql.Timestamp); Calendar calendar = Calendar.getInstance(); calendar.setTime((java.sql.Timestamp) date); diff --git a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/NumberParamConvertorTestCase.java b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/NumberParamConvertorTestCase.java index 6f50a9dc..e260159f 100644 --- a/bean-searcher/src/test/java/cn/zhxu/bs/convertor/NumberParamConvertorTestCase.java +++ b/bean-searcher/src/test/java/cn/zhxu/bs/convertor/NumberParamConvertorTestCase.java @@ -1,10 +1,12 @@ package cn.zhxu.bs.convertor; -import cn.zhxu.bs.bean.DbType; +import java.math.BigDecimal; + import org.junit.Assert; import org.junit.Test; -import java.math.BigDecimal; +import cn.zhxu.bs.FieldMeta; +import cn.zhxu.bs.bean.DbType; public class NumberParamConvertorTestCase { @@ -28,14 +30,15 @@ public class NumberParamConvertorTestCase { } void assertSupports(DbType dbType, boolean supports) { - Assert.assertEquals(supports, convertor.supports(dbType, String.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Byte.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Short.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Integer.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Long.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Float.class)); - Assert.assertEquals(supports, convertor.supports(dbType, Double.class)); - Assert.assertEquals(supports, convertor.supports(dbType, BigDecimal.class)); + FieldMeta meta = new FieldMeta(null, null, null, null, false, null, dbType); + Assert.assertEquals(supports, convertor.supports(meta, String.class)); + Assert.assertEquals(supports, convertor.supports(meta, Byte.class)); + Assert.assertEquals(supports, convertor.supports(meta, Short.class)); + Assert.assertEquals(supports, convertor.supports(meta, Integer.class)); + Assert.assertEquals(supports, convertor.supports(meta, Long.class)); + Assert.assertEquals(supports, convertor.supports(meta, Float.class)); + Assert.assertEquals(supports, convertor.supports(meta, Double.class)); + Assert.assertEquals(supports, convertor.supports(meta, BigDecimal.class)); } @Test @@ -61,7 +64,8 @@ public class NumberParamConvertorTestCase { } private void assertConvert(DbType dbType, Object value) { - Object num = convertor.convert(dbType, value); + FieldMeta meta = new FieldMeta(null, null, null, null, false, null, dbType); + Object num = convertor.convert(meta, value); Assert.assertTrue(dbType.getType().isInstance(num)); String numStr = num.toString(); String valStr = value.toString(); -- Gitee