This commit is contained in:
yulichang 2023-01-03 21:10:44 +08:00
parent d8cf0b4b8b
commit 5e36c4d3b0
20 changed files with 265 additions and 38 deletions

View File

@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.config.InterceptorConfig;
import com.github.yulichang.config.MPJInterceptorConfig;
import com.github.yulichang.injector.MPJSqlInjector;
import com.github.yulichang.interceptor.MPJInterceptor;
import com.github.yulichang.toolkit.SpringContentUtils;
@ -75,8 +75,8 @@ public class MybatisPlusJoinAutoConfiguration {
*/
@Bean
@ConditionalOnBean(SqlSessionFactory.class)
public InterceptorConfig interceptorConfig(List<SqlSessionFactory> sqlSessionFactoryList) {
return new InterceptorConfig(sqlSessionFactoryList, properties.getBanner());
public MPJInterceptorConfig mpjInterceptorConfig(List<SqlSessionFactory> sqlSessionFactoryList) {
return new MPJInterceptorConfig(sqlSessionFactoryList, properties.getBanner());
}
/**

View File

@ -6,6 +6,7 @@ import com.github.yulichang.annotation.EntityMapping;
import com.github.yulichang.annotation.FieldMapping;
import com.github.yulichang.exception.MPJException;
import com.github.yulichang.mapper.MPJTableInfo;
import com.github.yulichang.toolkit.TableHelper;
import org.apache.ibatis.session.Configuration;
import java.lang.reflect.Field;
@ -75,7 +76,7 @@ public class MPJTableInfoHelper {
}
MPJTableInfo mpjTableInfo = new MPJTableInfo();
mpjTableInfo.setMapperClass(mapperClass);
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
TableInfo tableInfo = TableHelper.get(clazz);
if (tableInfo == null) {
return;
}

View File

@ -18,12 +18,12 @@ import java.util.List;
*
* @author yulichang
*/
public class InterceptorConfig {
public class MPJInterceptorConfig {
private static final Log logger = LogFactory.getLog(InterceptorConfig.class);
private static final Log logger = LogFactory.getLog(MPJInterceptorConfig.class);
public InterceptorConfig(List<SqlSessionFactory> sqlSessionFactoryList, Boolean banner) {
public MPJInterceptorConfig(List<SqlSessionFactory> sqlSessionFactoryList, Boolean banner) {
replaceInterceptorChain(sqlSessionFactoryList);
if (banner) {
//打印banner

View File

@ -6,13 +6,19 @@ import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.methods.*;
import com.baomidou.mybatisplus.core.mapper.Mapper;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
import com.github.yulichang.mapper.MPJTableMapperHelper;
import com.github.yulichang.method.*;
import com.github.yulichang.method.mp.SelectOne;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.springframework.core.GenericTypeResolver;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -116,10 +122,33 @@ public class MPJSqlInjector extends DefaultSqlInjector {
Class<?> modelClass = getSuperClassGenericType(mapperClass, Mapper.class, 0);
super.inspectInject(builderAssistant, mapperClass);
MPJTableMapperHelper.init(modelClass, mapperClass);
TableHelper.init(modelClass, extractModelClassOld(mapperClass));
}
public static Class<?> getSuperClassGenericType(final Class<?> clazz, final Class<?> genericIfc, final int index) {
Class<?>[] typeArguments = GenericTypeResolver.resolveTypeArguments(ClassUtils.getUserClass(clazz), genericIfc);
Class<?>[] typeArguments = GenericTypeUtils.resolveTypeArguments(ClassUtils.getUserClass(clazz), genericIfc);
return null == typeArguments ? null : typeArguments[index];
}
protected Class<?> extractModelClassOld(Class<?> mapperClass) {
Type[] types = mapperClass.getGenericInterfaces();
ParameterizedType target = null;
for (Type type : types) {
if (type instanceof ParameterizedType) {
Type[] typeArray = ((ParameterizedType) type).getActualTypeArguments();
if (ArrayUtils.isNotEmpty(typeArray)) {
for (Type t : typeArray) {
if (t instanceof TypeVariable || t instanceof WildcardType) {
break;
} else {
target = (ParameterizedType) type;
break;
}
}
}
break;
}
}
return target == null ? null : (Class<?>) target.getActualTypeArguments()[0];
}
}

View File

@ -1,7 +1,6 @@
package com.github.yulichang.interceptor;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.mapper.MPJTableMapperHelper;
@ -9,6 +8,7 @@ import com.github.yulichang.method.MPJResultType;
import com.github.yulichang.query.MPJQueryWrapper;
import com.github.yulichang.toolkit.Constant;
import com.github.yulichang.toolkit.MPJReflectionKit;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.github.yulichang.wrapper.resultmap.MybatisLabel;
import com.github.yulichang.wrapper.resultmap.Result;
@ -84,7 +84,7 @@ public class MPJInterceptor implements Interceptor {
*/
@SuppressWarnings("rawtypes")
public MappedStatement getMappedStatement(MappedStatement ms, Class<?> resultType, Object ew) {
String id = ms.getId() + StringPool.UNDERSCORE + resultType.getName();
String id = ms.getId() + StringPool.DASH + (resultType.getName().replaceAll("\\.", StringPool.DASH));
if (ew instanceof MPJLambdaWrapper) {
MPJLambdaWrapper wrapper = (MPJLambdaWrapper) ew;
wrapper.setEntityClass(MPJTableMapperHelper.getEntity(getEntity(ms.getId())));
@ -94,12 +94,13 @@ public class MPJInterceptor implements Interceptor {
if (ew instanceof MPJQueryWrapper) {
MPJQueryWrapper wrapper = (MPJQueryWrapper) ew;
if (ConfigProperties.msCache) {
return getCache(ms, id + StringPool.UNDERSCORE + wrapper.getSqlSelect(), resultType, ew);
return getCache(ms, id + StringPool.UNDERSCORE + removeDot(wrapper.getSqlSelect()), resultType, ew);
}
}
return buildMappedStatement(ms, resultType, ew, id);
}
/**
* 走缓存
*/
@ -150,7 +151,7 @@ public class MPJInterceptor implements Interceptor {
@SuppressWarnings({"rawtypes", "unchecked"})
private List<ResultMap> buildResultMap(MappedStatement ms, Class<?> resultType, Object obj) {
List<ResultMap> result = new ArrayList<>();
TableInfo tableInfo = TableInfoHelper.getTableInfo(resultType);
TableInfo tableInfo = TableHelper.get(resultType);
String id = ms.getId() + StringPool.DOT + Constants.MYBATIS_PLUS + StringPool.UNDERSCORE + resultType.getName();
//基本数据类型
if (MPJReflectionKit.isPrimitiveOrWrapper(resultType)) {
@ -244,9 +245,9 @@ public class MPJInterceptor implements Interceptor {
ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), columnName, r.getJavaType());
if (r.isId()) {//主键标记为id标签
builder.flags(Collections.singletonList(ResultFlag.ID));
childId.append(ResultFlag.ID);
childId.append("i");
} else {
childId.append(ResultFlag.CONSTRUCTOR);
childId.append("c");
}
//TypeHandle
if (label.hasTypeHandle() && label.getColumnType().isAssignableFrom(field.getType())) {
@ -361,4 +362,12 @@ public class MPJInterceptor implements Interceptor {
return null;
}
}
private String removeDot(String str) {
if (StringUtils.isBlank(str)) {
return str;
} else {
return str.replaceAll("\\.", StringPool.DASH);
}
}
}

View File

@ -4,12 +4,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.MPJTableInfoHelper;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.github.yulichang.annotation.EntityMapping;
import com.github.yulichang.annotation.FieldMapping;
import com.github.yulichang.exception.MPJException;
import com.github.yulichang.toolkit.SpringContentUtils;
import com.github.yulichang.toolkit.TableHelper;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@ -164,7 +164,8 @@ public class MPJTableFieldInfo {
}
private void initBindField(String bindName) {
TableInfo info = TableInfoHelper.getTableInfo(this.joinClass);
TableInfo info = TableHelper.get(this.joinClass);
Assert.notNull(info, "未注册的实体类 <%s>", this.joinClass.getSimpleName());
Field field = info.getFieldList().stream()
.filter(i -> i.getColumn().equals(bindName))
.map(TableFieldInfo::getField).findFirst().orElse(null);
@ -285,7 +286,7 @@ public class MPJTableFieldInfo {
}
private TableInfo getTableInfo(Class<?> clazz) {
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
TableInfo tableInfo = TableHelper.get(clazz);
if (tableInfo == null) {
throw new MPJException("未注册 mapper " + clazz.getName());
}

View File

@ -6,11 +6,11 @@ import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.query.interfaces.StringJoin;
import com.github.yulichang.toolkit.TableHelper;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@ -159,7 +159,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
*/
@Override
public MPJLambdaQueryWrapper<T> select(Class<T> entityClass, Predicate<TableFieldInfo> predicate) {
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
TableInfo info = TableHelper.get(entityClass);
Assert.notNull(info, "table not find by class <%s>", entityClass.getSimpleName());
selectColumns.addAll(info.getFieldList().stream().filter(predicate).map(c ->
alias + StringPool.DOT + c.getColumn()).collect(Collectors.toList()));
@ -184,7 +184,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
*/
@SuppressWarnings("DuplicatedCode")
public final MPJLambdaQueryWrapper<T> selectAll(Class<?> clazz, String as) {
TableInfo info = TableInfoHelper.getTableInfo(clazz);
TableInfo info = TableHelper.get(clazz);
Assert.notNull(info, "table not find by class <%s>", clazz.getSimpleName());
if (info.havePK()) {
selectColumns.add(as + StringPool.DOT + info.getKeyColumn());

View File

@ -6,11 +6,11 @@ import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.query.interfaces.StringJoin;
import com.github.yulichang.toolkit.MPJWrappers;
import com.github.yulichang.toolkit.TableHelper;
import java.util.ArrayList;
import java.util.Arrays;
@ -134,7 +134,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
*/
@Override
public MPJQueryWrapper<T> select(Class<T> entityClass, Predicate<TableFieldInfo> predicate) {
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
TableInfo info = TableHelper.get(entityClass);
Assert.notNull(info, "table not find by class <%s>", entityClass.getSimpleName());
selectColumns.addAll(info.getFieldList().stream().filter(predicate).map(c ->
alias + StringPool.DOT + c.getSqlSelect()).collect(Collectors.toList()));
@ -159,7 +159,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
*/
@SuppressWarnings({"DuplicatedCode", "UnusedReturnValue"})
public final MPJQueryWrapper<T> selectAll(Class<?> clazz, String as) {
TableInfo info = TableInfoHelper.getTableInfo(clazz);
TableInfo info = TableHelper.get(clazz);
Assert.notNull(info, "table not find by class <%s>", clazz);
if (info.havePK()) {
selectColumns.add(as + StringPool.DOT + info.getKeySqlSelect());

View File

@ -1,7 +1,6 @@
package com.github.yulichang.toolkit;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
@ -33,7 +32,7 @@ public class LogicInfoUtils implements Constants {
private static String getLogicStr(String prefix, Class<?> clazz) {
String logicStr;
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
TableInfo tableInfo = TableHelper.get(clazz);
Assert.notNull(tableInfo, "table not find by class <%s>", clazz.getSimpleName());
if (tableInfo.isWithLogicDelete() && Objects.nonNull(tableInfo.getLogicDeleteFieldInfo())) {
final String value = tableInfo.getLogicDeleteFieldInfo().getLogicNotDeleteValue();

View File

@ -15,8 +15,10 @@
*/
package com.github.yulichang.toolkit;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.reflect.GenericTypeUtils;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.yulichang.toolkit;
import java.lang.reflect.AccessibleObject;
import java.security.PrivilegedAction;
/**
* Create by hcl at 2021/5/14
*/
public class SetAccessibleAction<T extends AccessibleObject> implements PrivilegedAction<T> {
private final T obj;
public SetAccessibleAction(T obj) {
this.obj = obj;
}
@Override
public T run() {
obj.setAccessible(true);
return obj;
}
}

View File

@ -0,0 +1,43 @@
package com.github.yulichang.toolkit;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author yulichang
* @since 1.4.3
*/
public class TableHelper {
private static final Map<Class<?>, TableInfo> TABLE_INFO_CACHE = new ConcurrentHashMap<>();
public static void init(Class<?> newClass, Class<?> oldClass) {
if (Objects.nonNull(newClass)) {
TableInfo info = TableInfoHelper.getTableInfo(newClass);
if (Objects.isNull(info)) {
if (Objects.nonNull(oldClass)) {
TableInfo oldInfo = TableInfoHelper.getTableInfo(oldClass);
if (Objects.nonNull(oldInfo)) {
TABLE_INFO_CACHE.put(newClass, oldInfo);
}
}
}
}
}
public static TableInfo get(Class<?> clazz) {
if (Objects.nonNull(clazz)) {
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
if (Objects.nonNull(tableInfo)) {
return tableInfo;
}
return TABLE_INFO_CACHE.get(clazz);
} else {
return null;
}
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.yulichang.toolkit.reflect;
/**
* 泛型类工具用于隔离Spring的代码
*
* @author noear
* @author hubin
* @since 2021-09-03
*/
@SuppressWarnings("ALL")
public class GenericTypeUtils {
private static IGenericTypeResolver GENERIC_TYPE_RESOLVER;
/**
* 获取泛型工具助手
*/
public static Class<?>[] resolveTypeArguments(final Class<?> clazz, final Class<?> genericIfc) {
if (null == GENERIC_TYPE_RESOLVER) {
// 直接使用 spring 静态方法减少对象创建
return SpringReflectionHelper.resolveTypeArguments(clazz, genericIfc);
}
return GENERIC_TYPE_RESOLVER.resolveTypeArguments(clazz, genericIfc);
}
/**
* 设置泛型工具助手如果不想使用Spring封装可以使用前替换掉
*/
public static void setGenericTypeResolver(IGenericTypeResolver genericTypeResolver) {
GENERIC_TYPE_RESOLVER = genericTypeResolver;
}
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.yulichang.toolkit.reflect;
/**
* 泛型类助手用于隔离Spring的代码
*
* @author noear
* @author hubin
* @since 2021-09-03
*/
public interface IGenericTypeResolver {
Class<?>[] resolveTypeArguments(final Class<?> clazz, final Class<?> genericIfc);
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.yulichang.toolkit.reflect;
import org.springframework.core.GenericTypeResolver;
/**
* Spring 反射辅助类
*
* @author noear
* @author hubin
* @since 2021-09-03
*/
public class SpringReflectionHelper {
public static Class<?>[] resolveTypeArguments(Class<?> clazz, Class<?> genericIfc) {
return GenericTypeResolver.resolveTypeArguments(clazz, genericIfc);
}
}

View File

@ -1,8 +1,8 @@
package com.github.yulichang.toolkit.support;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.wrapper.segments.SelectCache;
import java.util.ArrayList;
@ -26,7 +26,7 @@ public class ColumnCache {
public static List<SelectCache> getListField(Class<?> clazz) {
return LIST_CACHE.computeIfAbsent(clazz, c -> {
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
TableInfo tableInfo = TableHelper.get(clazz);
Assert.notNull(tableInfo, "table not find by class <%s>", c.getSimpleName());
List<SelectCache> list = new ArrayList<>();
if (tableInfo.havePK()) {

View File

@ -3,13 +3,13 @@ package com.github.yulichang.wrapper;
import com.baomidou.mybatisplus.core.conditions.SharedString;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.config.ConfigProperties;
import com.github.yulichang.toolkit.Constant;
import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.LogicInfoUtils;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.support.ColumnCache;
import com.github.yulichang.wrapper.interfaces.Query;
import com.github.yulichang.wrapper.interfaces.QueryJoin;
@ -230,7 +230,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
StringBuilder value = new StringBuilder();
for (MPJLambdaWrapper<?> wrapper : onWrappers) {
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
TableInfo info = TableInfoHelper.getTableInfo(wrapper.getJoinClass());
TableInfo info = TableHelper.get(wrapper.getJoinClass());
Assert.notNull(info, "table not find by class <%s>", wrapper.getJoinClass().getSimpleName());
String tableName = info.getTableName();
value.append(StringPool.SPACE)

View File

@ -2,12 +2,12 @@ package com.github.yulichang.wrapper.interfaces;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.MPJReflectionKit;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.support.ColumnCache;
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
import com.github.yulichang.wrapper.enums.DefaultFuncEnum;
@ -50,7 +50,7 @@ public interface Query<Children> extends Serializable {
* @return children
*/
default <E> Children select(Class<E> entityClass, Predicate<TableFieldInfo> predicate) {
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
TableInfo info = TableHelper.get(entityClass);
Assert.notNull(info, "table not find by class <%s>", entityClass.getSimpleName());
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(entityClass);
info.getFieldList().stream().filter(predicate).collect(Collectors.toList()).forEach(

View File

@ -1,12 +1,12 @@
package com.github.yulichang.wrapper.resultmap;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.toolkit.LambdaUtils;
import com.github.yulichang.toolkit.MPJReflectionKit;
import com.github.yulichang.toolkit.TableHelper;
import com.github.yulichang.toolkit.support.ColumnCache;
import com.github.yulichang.wrapper.segments.SelectCache;
import lombok.Getter;
@ -209,7 +209,7 @@ public class MybatisLabel<E, T> {
}
private void autoBuild(boolean auto, Class<E> entityClass, Class<T> tagClass) {
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
TableInfo tableInfo = TableHelper.get(entityClass);
Assert.notNull(tableInfo, "table not find by class <%s>", entityClass.getSimpleName());
Map<String, Field> tagMap = MPJReflectionKit.getFieldMap(tagClass);
if (auto && !tagMap.isEmpty()) {

View File

@ -2,9 +2,9 @@ package com.github.yulichang.wrapper.segments;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.toolkit.TableHelper;
import lombok.Getter;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.type.TypeHandler;
@ -54,7 +54,7 @@ public class SelectCache {
} else {
this.hasTypeHandle = this.tableFieldInfo.getTypeHandler() != null && tableFieldInfo.getTypeHandler() != UnknownTypeHandler.class;
if (this.hasTypeHandle) {
TableInfo info = TableInfoHelper.getTableInfo(clazz);
TableInfo info = TableHelper.get(clazz);
Assert.notNull(info, "table not find by class <%s>", clazz.getSimpleName());
this.typeHandler = getTypeHandler(info.getConfiguration(), tableFieldInfo);
} else {