|
@@ -16,7 +16,7 @@
|
|
package com.baomidou.mybatisplus.core.conditions;
|
|
package com.baomidou.mybatisplus.core.conditions;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
|
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
|
-import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Assert;
|
|
import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache;
|
|
import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache;
|
|
@@ -25,7 +25,7 @@ import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
|
|
import org.apache.ibatis.reflection.property.PropertyNamer;
|
|
import org.apache.ibatis.reflection.property.PropertyNamer;
|
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
-import java.util.Optional;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static java.util.stream.Collectors.joining;
|
|
import static java.util.stream.Collectors.joining;
|
|
|
|
|
|
@@ -40,9 +40,16 @@ import static java.util.stream.Collectors.joining;
|
|
public abstract class AbstractLambdaWrapper<T, Children extends AbstractLambdaWrapper<T, Children>>
|
|
public abstract class AbstractLambdaWrapper<T, Children extends AbstractLambdaWrapper<T, Children>>
|
|
extends AbstractWrapper<T, SFunction<T, ?>, Children> {
|
|
extends AbstractWrapper<T, SFunction<T, ?>, Children> {
|
|
|
|
|
|
|
|
+ private Map<String, ColumnCache> columnMap = null;
|
|
|
|
+ private boolean initColumnMap = false;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void initEntityClass() {
|
|
protected void initEntityClass() {
|
|
super.initEntityClass();
|
|
super.initEntityClass();
|
|
|
|
+ if (entityClass != null) {
|
|
|
|
+ columnMap = LambdaUtils.getColumnMap(entityClass);
|
|
|
|
+ initColumnMap = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
@@ -79,11 +86,14 @@ public abstract class AbstractLambdaWrapper<T, Children extends AbstractLambdaWr
|
|
*/
|
|
*/
|
|
private String getColumn(SerializedLambda lambda, boolean onlyColumn) throws MybatisPlusException {
|
|
private String getColumn(SerializedLambda lambda, boolean onlyColumn) throws MybatisPlusException {
|
|
String fieldName = PropertyNamer.methodToProperty(lambda.getImplMethodName());
|
|
String fieldName = PropertyNamer.methodToProperty(lambda.getImplMethodName());
|
|
-
|
|
|
|
- return Optional.ofNullable(LambdaUtils.getColumnOfProperty(lambda.getInstantiatedMethodType(), fieldName))
|
|
|
|
- .map(onlyColumn ? ColumnCache::getColumn : ColumnCache::getColumnSelect)
|
|
|
|
- .orElseThrow(() ->
|
|
|
|
- ExceptionUtils.mpe("Your property named \"%s\" cannot find the corresponding database column name!", fieldName)
|
|
|
|
- );
|
|
|
|
|
|
+ Class aClass = lambda.getInstantiatedMethodType();
|
|
|
|
+ if (!initColumnMap) {
|
|
|
|
+ columnMap = LambdaUtils.getColumnMap(aClass);
|
|
|
|
+ Assert.notNull(columnMap, "can not find lambda cache for this entity [%s]", aClass.getName());
|
|
|
|
+ }
|
|
|
|
+ ColumnCache columnCache = columnMap.get(LambdaUtils.formatKey(fieldName));
|
|
|
|
+ Assert.notNull(columnCache, "can not find lambda cache for this property [%s] of entity [%s]",
|
|
|
|
+ fieldName, aClass.getName());
|
|
|
|
+ return onlyColumn ? columnCache.getColumn() : columnCache.getColumnSelect();
|
|
}
|
|
}
|
|
}
|
|
}
|