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
818fdb9191
commit
064c0e3bd2
@ -0,0 +1,23 @@
|
||||
package com.github.yulichang.toolkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @see HashMap
|
||||
* @since 1.4.7.3
|
||||
*/
|
||||
public class FieldStringMap<V> extends HashMap<String, V> {
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
V v = super.get(key);
|
||||
if (Objects.isNull(v)) {
|
||||
String k = (String) key;
|
||||
return entrySet().stream().filter(f -> k.equalsIgnoreCase(f.getKey())).findFirst()
|
||||
.map(Entry::getValue).orElse(null);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ import java.util.stream.Collectors;
|
||||
@SuppressWarnings("unused")
|
||||
public final class MPJReflectionKit {
|
||||
|
||||
private static final Map<Class<?>, Map<String, FieldCache>> CLASS_FIELD_CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, FieldStringMap<FieldCache>> CLASS_FIELD_CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, List<FieldCache>> CLASS_FIELD_LIST_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<String, FieldCache> EMPTY_MAP = new HashMap<>();
|
||||
@ -78,7 +78,7 @@ public final class MPJReflectionKit {
|
||||
*/
|
||||
public static Map<String, FieldCache> getFieldMap(Class<?> clazz) {
|
||||
return CLASS_FIELD_CACHE.computeIfAbsent(clazz, key -> getFieldList(key).stream().collect(Collectors.toMap(f ->
|
||||
f.getField().getName(), Function.identity())));
|
||||
f.getField().getName(), Function.identity(), (o, n) -> n, FieldStringMap::new)));
|
||||
}
|
||||
|
||||
public static List<FieldCache> getFieldList(Class<?> clazz) {
|
||||
|
@ -3,6 +3,7 @@ package com.github.yulichang.toolkit.support;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.toolkit.Asserts;
|
||||
import com.github.yulichang.toolkit.FieldStringMap;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.wrapper.segments.SelectCache;
|
||||
|
||||
@ -23,7 +24,7 @@ public class ColumnCache {
|
||||
|
||||
private static final Map<Class<?>, List<SelectCache>> LIST_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<Class<?>, Map<String, SelectCache>> MAP_CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<Class<?>, FieldStringMap<SelectCache>> MAP_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
public static List<SelectCache> getListField(Class<?> clazz) {
|
||||
return LIST_CACHE.computeIfAbsent(clazz, c -> {
|
||||
@ -31,14 +32,17 @@ public class ColumnCache {
|
||||
Asserts.hasTable(tableInfo, c);
|
||||
List<SelectCache> list = new ArrayList<>();
|
||||
if (ConfigProperties.tableInfoAdapter.mpjHasPK(tableInfo)) {
|
||||
list.add(new SelectCache(clazz, true, tableInfo.getKeyColumn(), tableInfo.getKeyType(), tableInfo.getKeyProperty(), null));
|
||||
list.add(new SelectCache(clazz, true, tableInfo.getKeyColumn(), tableInfo.getKeyType(),
|
||||
tableInfo.getKeyProperty(), null));
|
||||
}
|
||||
list.addAll(tableInfo.getFieldList().stream().map(f -> new SelectCache(clazz, false, f.getColumn(), f.getPropertyType(), f.getProperty(), f)).collect(Collectors.toList()));
|
||||
list.addAll(tableInfo.getFieldList().stream().map(f -> new SelectCache(clazz, false, f.getColumn(),
|
||||
f.getPropertyType(), f.getProperty(), f)).collect(Collectors.toList()));
|
||||
return list;
|
||||
});
|
||||
}
|
||||
|
||||
public static Map<String, SelectCache> getMapField(Class<?> clazz) {
|
||||
return MAP_CACHE.computeIfAbsent(clazz, c -> getListField(c).stream().collect(Collectors.toMap(SelectCache::getColumProperty, Function.identity(), (i, j) -> j)));
|
||||
return MAP_CACHE.computeIfAbsent(clazz, c -> getListField(c).stream().collect(Collectors.toMap(
|
||||
SelectCache::getColumProperty, Function.identity(), (i, j) -> j, FieldStringMap::new)));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user