add MapperUtil.getLongNumber

This commit is contained in:
开源海哥 2023-07-04 12:43:29 +08:00
parent 37392d6916
commit 8245e55dce
3 changed files with 14 additions and 16 deletions

View File

@ -645,14 +645,7 @@ public interface BaseMapper<T> {
queryWrapper.select(count());
}
List<Object> objects = selectObjectListByQuery(queryWrapper);
Object object = objects == null || objects.isEmpty() ? null : objects.get(0);
if (object == null) {
return 0;
} else if (object instanceof Number) {
return ((Number) object).longValue();
} else {
throw FlexExceptions.wrap("selectCountByQuery error, Can not get number value for queryWrapper: %s", queryWrapper);
}
return MapperUtil.getLongNumber(objects, queryWrapper);
} finally {
//fixed https://github.com/mybatis-flex/mybatis-flex/issues/49
CPI.setSelectColumns(queryWrapper, selectColumns);

View File

@ -417,14 +417,7 @@ public interface RowMapper {
}
List<Object> objects = selectObjectListByQuery(schema, tableName, queryWrapper);
Object object = objects == null || objects.isEmpty() ? null : objects.get(0);
if (object == null) {
return 0;
} else if (object instanceof Number) {
return ((Number) object).longValue();
} else {
throw FlexExceptions.wrap("selectCountByQuery error, Can not get number value for queryWrapper: %s", queryWrapper);
}
return MapperUtil.getLongNumber(objects, queryWrapper);
}

View File

@ -17,6 +17,7 @@ package com.mybatisflex.core.util;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.constant.SqlConsts;
import com.mybatisflex.core.exception.FlexExceptions;
import com.mybatisflex.core.field.FieldQuery;
import com.mybatisflex.core.field.FieldQueryBuilder;
import com.mybatisflex.core.query.*;
@ -195,4 +196,15 @@ public class MapperUtil {
throw new TooManyResultsException(
"Expected one result (or null) to be returned by selectOne(), but found: " + size);
}
public static long getLongNumber(List<Object> objects,QueryWrapper queryWrapper){
Object object = objects == null || objects.isEmpty() ? null : objects.get(0);
if (object == null) {
return 0;
} else if (object instanceof Number) {
return ((Number) object).longValue();
} else {
throw FlexExceptions.wrap("selectCountByQuery error, Can not get number value for queryWrapper: %s", queryWrapper);
}
}
}