Skip to content

Commit

Permalink
升级mybatis至3.5.16
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Apr 4, 2024
1 parent 2c8ff8d commit 11a230f
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 332 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ext {
]

libraries = [
mybatisVersion = '3.5.15',
mybatisVersion = '3.5.16',
mybatisSpringVersion = '2.1.2',
mybatisSpringBootStarterVersion = '2.3.1',
springVersion = '5.3.27',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import org.apache.ibatis.type.TypeHandler;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -366,15 +366,16 @@ public Executor newExecutor(Transaction transaction, ExecutorType executorType)

// Slow but a one time cost. A better solution is welcome.
@Override
protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
public void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
if (rm.hasNestedResultMaps()) {
for (Map.Entry<String, ResultMap> entry : resultMaps.entrySet()) {
Object value = entry.getValue();
if (value instanceof ResultMap) {
ResultMap entryResultMap = (ResultMap) value;
final String resultMapId = rm.getId();
for (Object resultMapObject : resultMaps.values()) {
if (resultMapObject instanceof ResultMap) {
ResultMap entryResultMap = (ResultMap) resultMapObject;
if (!entryResultMap.hasNestedResultMaps() && entryResultMap.getDiscriminator() != null) {
Collection<String> discriminatedResultMapNames = entryResultMap.getDiscriminator().getDiscriminatorMap().values();
if (discriminatedResultMapNames.contains(rm.getId())) {
Collection<String> discriminatedResultMapNames = entryResultMap.getDiscriminator().getDiscriminatorMap()
.values();
if (discriminatedResultMapNames.contains(resultMapId)) {
entryResultMap.forceNestedResultMaps();
}
}
Expand All @@ -387,8 +388,7 @@ protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
@Override
protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
if (!rm.hasNestedResultMaps() && rm.getDiscriminator() != null) {
for (Map.Entry<String, String> entry : rm.getDiscriminator().getDiscriminatorMap().entrySet()) {
String discriminatedResultMapName = entry.getValue();
for (String discriminatedResultMapName : rm.getDiscriminator().getDiscriminatorMap().values()) {
if (hasResultMap(discriminatedResultMapName)) {
ResultMap discriminatedResultMap = resultMaps.get(discriminatedResultMapName);
if (discriminatedResultMap.hasNestedResultMaps()) {
Expand All @@ -400,17 +400,32 @@ protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
}
}

protected class StrictMap<V> extends HashMap<String, V> {
protected class StrictMap<V> extends ConcurrentHashMap<String, V> {

private static final long serialVersionUID = -4950446264854982944L;
private final String name;
private BiFunction<V, V, String> conflictMessageProducer;

public StrictMap(String name, int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
this.name = name;
}

public StrictMap(String name, int initialCapacity) {
super(initialCapacity);
this.name = name;
}

public StrictMap(String name) {
super();
this.name = name;
}

public StrictMap(String name, Map<String, ? extends V> m) {
super(m);
this.name = name;
}

/**
* Assign a function for producing a conflict error message when contains value with the same key.
* <p>
Expand Down Expand Up @@ -445,6 +460,15 @@ public V put(String key, V value) {
return super.put(key, value);
}

@Override
public boolean containsKey(Object key) {
if (key == null) {
return false;
}

return super.get(key) != null;
}

@Override
public V get(Object key) {
V value = super.get(key);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ResultMapping buildResultMapping(Class<?> resultType, String property, St
boolean lazy) {
Class<?> javaTypeClass = resolveResultJavaType(resultType, property, javaType);
TypeHandler<?> typeHandlerInstance = null;
if (typeHandler != null && typeHandler != UnknownTypeHandler.class) {
if (typeHandler != null) {
if (IJsonTypeHandler.class.isAssignableFrom(typeHandler)) {
try {
Field field = resultType.getDeclaredField(property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public <T> boolean hasMapper(Class<T> type) {
return knownMappers.containsKey(type);
}

/**
/**
* 清空 Mapper 缓存信息
*/
protected <T> void removeMapper(Class<T> type) {
Expand Down
Loading

0 comments on commit 11a230f

Please sign in to comment.