mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
This commit is contained in:
parent
d40c0d46d0
commit
a500230a6b
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||
import com.github.yulichang.config.MPJInterceptorConfig;
|
||||
import org.apache.ibatis.type.SimpleTypeRegistry;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -36,32 +37,34 @@ public class TableHelper {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static TableInfo get(Class<?> clazz) {
|
||||
if (Objects.nonNull(clazz)) {
|
||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
||||
if (Objects.nonNull(tableInfo)) {
|
||||
return tableInfo;
|
||||
}
|
||||
TableInfo info = TABLE_INFO_CACHE.get(clazz);
|
||||
//尝试获取父类缓存
|
||||
Class<?> currentClass = clazz;
|
||||
while (Object.class != currentClass) {
|
||||
currentClass = currentClass.getSuperclass();
|
||||
info = TABLE_INFO_CACHE.get(ClassUtils.getUserClass(currentClass));
|
||||
}
|
||||
if (Objects.nonNull(info)) {
|
||||
TABLE_INFO_CACHE.put(currentClass, info);
|
||||
} else {
|
||||
if (!load) {
|
||||
SpringContentUtils.getBean(MPJInterceptorConfig.class);
|
||||
SpringContentUtils.getBeansOfType(BaseMapper.class);
|
||||
load = true;
|
||||
return get(clazz);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
} else {
|
||||
if (clazz == null || clazz.isPrimitive() || SimpleTypeRegistry.isSimpleType(clazz) || clazz.isInterface()) {
|
||||
return null;
|
||||
}
|
||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
||||
if (Objects.nonNull(tableInfo)) {
|
||||
return tableInfo;
|
||||
}
|
||||
TableInfo info = TABLE_INFO_CACHE.get(clazz);
|
||||
if (null != info) {
|
||||
return info;
|
||||
}
|
||||
//尝试获取父类缓存
|
||||
Class<?> currentClass = clazz;
|
||||
while (Object.class != currentClass) {
|
||||
currentClass = currentClass.getSuperclass();
|
||||
info = TABLE_INFO_CACHE.get(ClassUtils.getUserClass(currentClass));
|
||||
}
|
||||
if (Objects.nonNull(info)) {
|
||||
TABLE_INFO_CACHE.put(currentClass, info);
|
||||
} else {
|
||||
if (!load) {
|
||||
SpringContentUtils.getBean(MPJInterceptorConfig.class);
|
||||
SpringContentUtils.getBeansOfType(BaseMapper.class);
|
||||
load = true;
|
||||
return get(clazz);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public static TableInfo getAssert(Class<?> clazz) {
|
||||
|
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.OrderBy;
|
||||
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.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
@ -345,8 +344,7 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
for (Children wrapper : onWrappers) {
|
||||
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (this.subLogicSql && this.logicDelType == LogicDelTypeEnum.ON) {
|
||||
TableInfo tableInfo = TableHelper.get(wrapper.getJoinClass());
|
||||
Assert.notNull(tableInfo, "not find tableInfo by class %s", wrapper.getJoinClass().getName());
|
||||
TableInfo tableInfo = TableHelper.getAssert(wrapper.getJoinClass());
|
||||
if (ConfigProperties.tableInfoAdapter.mpjHasLogic(tableInfo)) {
|
||||
wrapper.appendSqlSegments(APPLY, () -> LogicInfoUtils.getLogicInfoNoAnd(
|
||||
wrapper.getIndex(), wrapper.getJoinClass(), wrapper.isHasAlias(), wrapper.getAlias()
|
||||
|
@ -6,6 +6,8 @@ import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 关系映射配置
|
||||
*
|
||||
@ -16,7 +18,8 @@ import lombok.NoArgsConstructor;
|
||||
public class MappingConfig {
|
||||
|
||||
public static void init() {
|
||||
TableInfoHelper.getTableInfos().forEach(i ->
|
||||
TableInfoHelper.getTableInfos().stream().filter(f ->
|
||||
Objects.nonNull(TableInfoHelper.getTableInfo(f.getEntityType()))).forEach(i ->
|
||||
MPJTableInfoHelper.initTableInfo(i.getEntityType(), MPJTableMapperHelper.getMapper(i.getEntityType())));
|
||||
}
|
||||
}
|
||||
|
@ -152,8 +152,7 @@ public class MPJTableFieldInfo {
|
||||
}
|
||||
|
||||
private void initBindField(String bindName) {
|
||||
TableInfo info = TableHelper.get(this.joinClass);
|
||||
Assert.notNull(info, "未注册的实体类 <%s>", this.joinClass.getSimpleName());
|
||||
TableInfo info = TableHelper.getAssert(this.joinClass);
|
||||
//根据属性名查询
|
||||
Field field = info.getFieldList().stream().filter(i -> i.getProperty().equals(bindName))
|
||||
.findFirst().map(f -> getField(this.joinClass, f)).orElse(null);
|
||||
@ -304,11 +303,7 @@ public class MPJTableFieldInfo {
|
||||
}
|
||||
|
||||
private TableInfo getTableInfo(Class<?> clazz) {
|
||||
TableInfo tableInfo = TableHelper.get(clazz);
|
||||
if (tableInfo == null) {
|
||||
throw ExceptionUtils.mpe("未注册 mapper " + clazz.getName());
|
||||
}
|
||||
return tableInfo;
|
||||
return TableHelper.getAssert(clazz);
|
||||
}
|
||||
|
||||
private Field getField(Class<?> table, TableFieldInfo tableFieldInfo) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user