Explorar el Código

jsqlParerUtils Optimization

Caratacus hace 8 años
padre
commit
3d9b2f7605

+ 5 - 8
src/main/java/com/baomidou/mybatisplus/toolkit/JsqlParserUtils.java

@@ -42,7 +42,7 @@ import net.sf.jsqlparser.statement.select.SelectItem;
  */
 public class JsqlParserUtils {
 
-    private static List<SelectItem> countSelectItem = null;
+    private static final List<SelectItem> countSelectItem = countSelectItem();
 
     /**
      * <p>
@@ -73,7 +73,7 @@ public class JsqlParserUtils {
             }
 
             // 优化 SQL
-            plainSelect.setSelectItems(countSelectItem());
+            plainSelect.setSelectItems(countSelectItem);
             countOptimize.setCountSQL(selectStatement.toString());
             return countOptimize;
         } catch (Throwable e) {
@@ -91,9 +91,6 @@ public class JsqlParserUtils {
      * @return
      */
     private static List<SelectItem> countSelectItem() {
-        if (CollectionUtils.isNotEmpty(countSelectItem)) {
-            return countSelectItem;
-        }
         Function function = new Function();
         function.setName("COUNT");
         List<Expression> expressions = new ArrayList<>();
@@ -102,9 +99,9 @@ public class JsqlParserUtils {
         expressions.add(longValue);
         expressionList.setExpressions(expressions);
         function.setParameters(expressionList);
-        countSelectItem = new ArrayList<>();
+        List<SelectItem> selectItems = new ArrayList<>();
         SelectExpressionItem selectExpressionItem = new SelectExpressionItem(function);
-        countSelectItem.add(selectExpressionItem);
-        return countSelectItem;
+        selectItems.add(selectExpressionItem);
+        return selectItems;
     }
 }

+ 1 - 61
src/main/java/com/baomidou/mybatisplus/toolkit/ReflectionKit.java

@@ -31,9 +31,6 @@ import java.util.Map;
 import org.apache.ibatis.logging.Log;
 import org.apache.ibatis.logging.LogFactory;
 
-import com.baomidou.mybatisplus.entity.TableFieldInfo;
-import com.baomidou.mybatisplus.entity.TableInfo;
-import com.baomidou.mybatisplus.enums.FieldStrategy;
 import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
 
 
@@ -110,41 +107,6 @@ public class ReflectionKit {
         return getMethodValue(entity.getClass(), entity, str);
     }
 
-    /**
-     * <p>
-     * 调用对象的get方法检查对象所有属性是否为null
-     * </p>
-     *
-     * @param bean 检查对象
-     * @return boolean true对象所有属性不为null,false对象所有属性为null
-     */
-    public static boolean checkFieldValueNotNull(Object bean) {
-        if (null == bean) {
-            return false;
-        }
-        Class<?> cls = bean.getClass();
-        TableInfo tableInfo = getTableInfoAsSuperClass(cls);
-        boolean result = false;
-        List<TableFieldInfo> fieldList = tableInfo.getFieldList();
-        for (TableFieldInfo tableFieldInfo : fieldList) {
-            FieldStrategy fieldStrategy = tableFieldInfo.getFieldStrategy();
-            Object val = getMethodValue(cls, bean, tableFieldInfo.getProperty());
-            if (FieldStrategy.NOT_EMPTY.equals(fieldStrategy)) {
-                if (StringUtils.checkValNotNull(val)) {
-                    result = true;
-                    break;
-                }
-            } else {
-                if (null != val) {
-                    result = true;
-                    break;
-                }
-            }
-
-        }
-        return result;
-    }
-
     /**
      * <p>
      * 反射对象获取泛型
@@ -250,26 +212,4 @@ public class ReflectionKit {
         }
         return fieldList;
     }
-
-    /**
-     * <p>
-     * 递归自身的class,获取TableInfo
-     * </p>
-     *
-     * @param cls
-     * @return TableInfo
-     * @throws MybatisPlusException
-     */
-    private static TableInfo getTableInfoAsSuperClass(Class<?> cls) {
-        TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
-        if (tableInfo == null) {
-            if (Object.class.equals(cls)) {
-                throw new MybatisPlusException(String.format("Error: Could Not find %s in TableInfo Cache. ", cls.getSimpleName()));
-            } else {
-                tableInfo = getTableInfoAsSuperClass(cls.getSuperclass());
-            }
-        }
-        return tableInfo;
-    }
-
-}
+}