Browse Source

Merge remote-tracking branch 'origin/3.0' into 3.0

125473094@qq.com 7 năm trước cách đây
mục cha
commit
3ac790a2b5

+ 0 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Condition.java

@@ -23,7 +23,6 @@ package com.baomidou.mybatisplus.core.conditions;
  * @author hubin Caratacus
  * @author hubin Caratacus
  * @date 2016-11-7
  * @date 2016-11-7
  */
  */
-@SuppressWarnings({"rawtypes", "serial"})
 public abstract class Condition {
 public abstract class Condition {
 
 
     /**
     /**

+ 87 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/EntityWrapper.java

@@ -16,7 +16,11 @@
 package com.baomidou.mybatisplus.core.conditions;
 package com.baomidou.mybatisplus.core.conditions;
 
 
 
 
+import com.baomidou.mybatisplus.core.metadata.Column;
+import com.baomidou.mybatisplus.core.metadata.Columns;
+import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -33,6 +37,10 @@ public class EntityWrapper<T> extends Wrapper<T> {
      * 数据库表映射实体类
      * 数据库表映射实体类
      */
      */
     protected T entity = null;
     protected T entity = null;
+    /**
+     * SQL 查询字段内容,例如:id,name,age
+     */
+    protected String sqlSelect = null;
 
 
     public EntityWrapper() {
     public EntityWrapper() {
         /* 注意,传入查询参数 */
         /* 注意,传入查询参数 */
@@ -56,6 +64,85 @@ public class EntityWrapper<T> extends Wrapper<T> {
         this.entity = entity;
         this.entity = entity;
     }
     }
 
 
+    public String getSqlSelect() {
+        return StringUtils.isEmpty(sqlSelect) ? null : SqlUtils.stripSqlInjection(sqlSelect);
+    }
+
+    public Wrapper<T> setSqlSelect(String sqlSelect) {
+        if (StringUtils.isNotEmpty(sqlSelect)) {
+            this.sqlSelect = sqlSelect;
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用字符串数组封装sqlSelect,便于在不需要指定 AS 的情况下通过实体类自动生成的列静态字段快速组装 sqlSelect,<br/>
+     * 减少手动录入的错误率
+     * </p>
+     *
+     * @param columns 字段
+     * @return
+     */
+    public Wrapper<T> setSqlSelect(String... columns) {
+        StringBuilder builder = new StringBuilder();
+        for (String column : columns) {
+            if (StringUtils.isNotEmpty(column)) {
+                if (builder.length() > 0) {
+                    builder.append(",");
+                }
+                builder.append(column);
+            }
+        }
+        this.sqlSelect = builder.toString();
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用对象封装的setsqlselect
+     * </p>
+     *
+     * @param column 字段
+     * @return
+     */
+    public Wrapper<T> setSqlSelect(Column... column) {
+        if (ArrayUtils.isNotEmpty(column)) {
+            StringBuilder builder = new StringBuilder();
+            for (int i = 0; i < column.length; i++) {
+                if (column[i] != null) {
+                    String col = column[i].getColumn();
+                    String as = column[i].getAs();
+                    if (StringUtils.isEmpty(col)) {
+                        continue;
+                    }
+                    builder.append(col).append(as);
+                    if (i < column.length - 1) {
+                        builder.append(",");
+                    }
+                }
+            }
+            this.sqlSelect = builder.toString();
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * 使用对象封装的setsqlselect
+     * </p>
+     *
+     * @param columns 字段
+     * @return
+     */
+    public Wrapper<T> setSqlSelect(Columns columns) {
+        Column[] columnArray = columns.getColumns();
+        if (ArrayUtils.isNotEmpty(columnArray)) {
+            setSqlSelect(columnArray);
+        }
+        return this;
+    }
+
     /**
     /**
      * SQL 片段
      * SQL 片段
      */
      */

+ 7 - 6
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/UpdateWrapper.java

@@ -26,13 +26,16 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  * @author hubin , yanghu , Dyang , Caratacus
  * @author hubin , yanghu , Dyang , Caratacus
  * @Date 2016-11-7
  * @Date 2016-11-7
  */
  */
-@SuppressWarnings("serial")
 public class UpdateWrapper<T> extends Wrapper<T> {
 public class UpdateWrapper<T> extends Wrapper<T> {
 
 
     /**
     /**
      * 数据库表映射实体类
      * 数据库表映射实体类
      */
      */
     protected T entity = null;
     protected T entity = null;
+    /**
+     * SQL 更新字段内容,例如:name='1',age=2
+     */
+    protected String sqlSet = null;
 
 
     public UpdateWrapper() {
     public UpdateWrapper() {
         /* 注意,传入查询参数 */
         /* 注意,传入查询参数 */
@@ -42,9 +45,9 @@ public class UpdateWrapper<T> extends Wrapper<T> {
         this.entity = entity;
         this.entity = entity;
     }
     }
 
 
-    public UpdateWrapper(T entity, String sqlSelect) {
+    public UpdateWrapper(T entity, String sqlSet) {
         this.entity = entity;
         this.entity = entity;
-        this.sqlSelect = sqlSelect;
+        this.sqlSet = sqlSet;
     }
     }
 
 
     @Override
     @Override
@@ -59,10 +62,8 @@ public class UpdateWrapper<T> extends Wrapper<T> {
     /**
     /**
      * SQL SET 字段
      * SQL SET 字段
      */
      */
-    @Override
     public String getSqlSet() {
     public String getSqlSet() {
-
-        return null;
+        return this.sqlSet;
     }
     }
 
 
     /**
     /**

+ 5 - 102
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Wrapper.java

@@ -25,8 +25,6 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 
 import com.baomidou.mybatisplus.core.enums.SqlLike;
 import com.baomidou.mybatisplus.core.enums.SqlLike;
 import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
-import com.baomidou.mybatisplus.core.metadata.Column;
-import com.baomidou.mybatisplus.core.metadata.Columns;
 import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
 import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.MapUtils;
 import com.baomidou.mybatisplus.core.toolkit.MapUtils;
@@ -43,7 +41,6 @@ import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
  * @author hubin , yanghu , Dyang , Caratacus
  * @author hubin , yanghu , Dyang , Caratacus
  * @Date 2016-11-7
  * @Date 2016-11-7
  */
  */
-@SuppressWarnings("serial")
 public abstract class Wrapper<T> implements Serializable {
 public abstract class Wrapper<T> implements Serializable {
 
 
     /**
     /**
@@ -63,10 +60,6 @@ public abstract class Wrapper<T> implements Serializable {
     private final Map<String, Object> paramNameValuePairs = new HashMap<>();
     private final Map<String, Object> paramNameValuePairs = new HashMap<>();
     private final AtomicInteger paramNameSeq = new AtomicInteger(0);
     private final AtomicInteger paramNameSeq = new AtomicInteger(0);
     protected String paramAlias = null;
     protected String paramAlias = null;
-    /**
-     * SQL 查询字段内容,例如:id,name,age
-     */
-    protected String sqlSelect = null;
     /**
     /**
      * 自定义是否输出sql为 WHERE OR AND OR OR
      * 自定义是否输出sql为 WHERE OR AND OR OR
      */
      */
@@ -105,98 +98,11 @@ public abstract class Wrapper<T> implements Serializable {
         return !isEmptyOfWhere();
         return !isEmptyOfWhere();
     }
     }
 
 
-    public String getSqlSelect() {
-        return StringUtils.isEmpty(sqlSelect) ? null : SqlUtils.stripSqlInjection(sqlSelect);
-    }
-
-    public Wrapper<T> setSqlSelect(String sqlSelect) {
-        if (StringUtils.isNotEmpty(sqlSelect)) {
-            this.sqlSelect = sqlSelect;
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用字符串数组封装sqlSelect,便于在不需要指定 AS 的情况下通过实体类自动生成的列静态字段快速组装 sqlSelect,<br/>
-     * 减少手动录入的错误率
-     * </p>
-     *
-     * @param columns 字段
-     * @return
-     */
-    public Wrapper<T> setSqlSelect(String... columns) {
-        StringBuilder builder = new StringBuilder();
-        for (String column : columns) {
-            if (StringUtils.isNotEmpty(column)) {
-                if (builder.length() > 0) {
-                    builder.append(",");
-                }
-                builder.append(column);
-            }
-        }
-        this.sqlSelect = builder.toString();
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用对象封装的setsqlselect
-     * </p>
-     *
-     * @param column 字段
-     * @return
-     */
-    public Wrapper<T> setSqlSelect(Column... column) {
-        if (ArrayUtils.isNotEmpty(column)) {
-            StringBuilder builder = new StringBuilder();
-            for (int i = 0; i < column.length; i++) {
-                if (column[i] != null) {
-                    String col = column[i].getColumn();
-                    String as = column[i].getAs();
-                    if (StringUtils.isEmpty(col)) {
-                        continue;
-                    }
-                    builder.append(col).append(as);
-                    if (i < column.length - 1) {
-                        builder.append(",");
-                    }
-                }
-            }
-            this.sqlSelect = builder.toString();
-        }
-        return this;
-    }
-
-    /**
-     * <p>
-     * 使用对象封装的setsqlselect
-     * </p>
-     *
-     * @param columns 字段
-     * @return
-     */
-    public Wrapper<T> setSqlSelect(Columns columns) {
-        Column[] columnArray = columns.getColumns();
-        if (ArrayUtils.isNotEmpty(columnArray)) {
-            setSqlSelect(columnArray);
-        }
-        return this;
-    }
-
     /**
     /**
      * SQL 片段 (子类实现)
      * SQL 片段 (子类实现)
      */
      */
     public abstract String getSqlSegment();
     public abstract String getSqlSegment();
 
 
-    /**
-     * SQL SET 字段
-     */
-    public String getSqlSet() {
-        // to do nothing
-        return null;
-    }
-
     @Override
     @Override
     public String toString() {
     public String toString() {
         StringBuilder sb = new StringBuilder("Wrapper<T>:");
         StringBuilder sb = new StringBuilder("Wrapper<T>:");
@@ -1617,14 +1523,11 @@ public abstract class Wrapper<T> implements Serializable {
         return this;
         return this;
     }
     }
 
 
-    //TODO: 3.0
-    public boolean isEmptyWrapper() {
-        return checkWrapperEmpty();
-    }
-
-    //TODO: 3.0 提供protect方法,让子类可覆盖
-    protected boolean checkWrapperEmpty() {
-        return sql.isEmptyOfWhere() && sqlSelect == null;
+    /**
+     * 是否为空
+     */
+    public boolean isEmpty() {
+        return sql.isEmptyOfWhere();
     }
     }
 
 
     public static <T> Wrapper<T> getInstance() {
     public static <T> Wrapper<T> getInstance() {

+ 2 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/AbstractMethod.java

@@ -172,7 +172,8 @@ public abstract class AbstractMethod {
      * @return
      * @return
      */
      */
     protected String sqlWordConvert(String column) {
     protected String sqlWordConvert(String column) {
-        return this.getGlobalConfig().getDbConfig().getReservedWordsHandler().convert(this.getGlobalConfig(), column);
+        return this.getGlobalConfig().getDbConfig().getReservedWordsHandler()
+            .convert(this.getGlobalConfig().getDbConfig().getDbType(), column);
     }
     }
 
 
     /**
     /**

+ 2 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/Column.java

@@ -66,7 +66,8 @@ public class Column implements Serializable {
         String quote = null;
         String quote = null;
         if (isEscape() && ISqlRunner.FACTORY != null) {
         if (isEscape() && ISqlRunner.FACTORY != null) {
             GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(ISqlRunner.FACTORY.getConfiguration());
             GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(ISqlRunner.FACTORY.getConfiguration());
-            quote = globalConfig.getIdentifierQuote() == null ? globalConfig.getDbType().getQuote() : globalConfig.getIdentifierQuote();
+            // TODO 这里调整了转义
+            // quote = globalConfig.getIdentifierQuote() == null ? globalConfig.getDbType().getQuote() : globalConfig.getIdentifierQuote();
         }
         }
         return AS + (StringUtils.isNotEmpty(quote) ? String.format(quote, as) : as);
         return AS + (StringUtils.isNotEmpty(quote) ? String.format(quote, as) : as);
     }
     }

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java

@@ -171,7 +171,7 @@ public class TableInfo {
         /*
         /*
          * 启动逻辑删除注入、判断该表是否启动
          * 启动逻辑删除注入、判断该表是否启动
          */
          */
-        if (null != globalConfig.getLogicDeleteValue()) {
+        if (null != globalConfig.getDbConfig().getLogicDeleteValue()) {
             for (TableFieldInfo tfi : fieldList) {
             for (TableFieldInfo tfi : fieldList) {
                 if (tfi.isLogicDelete()) {
                 if (tfi.isLogicDelete()) {
                     this.setLogicDelete(true);
                     this.setLogicDelete(true);

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/sql/SqlHelper.java

@@ -215,7 +215,7 @@ public class SqlHelper {
      * @return
      * @return
      */
      */
     public static boolean isEmptyOfWrapper(Wrapper<?> wrapper) {
     public static boolean isEmptyOfWrapper(Wrapper<?> wrapper) {
-        return null == wrapper || wrapper.isEmptyWrapper();
+        return null == wrapper || wrapper.isEmpty();
     }
     }
 
 
     /**
     /**