Browse Source

feat: 分页参数动态编译下mysql的over,路面畅通,随时可以起飞

miemie 6 years ago
parent
commit
55d4f6e677
14 changed files with 437 additions and 413 deletions
  1. 11 5
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/PaginationInterceptor.java
  2. 24 23
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/DialectFactory.java
  3. 8 4
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/DialectModel.java
  4. 67 67
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/DB2Dialect.java
  5. 28 28
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/DmDialect.java
  6. 37 37
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/H2Dialect.java
  7. 34 34
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/HSQLDialect.java
  8. 4 2
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/IDialect.java
  9. 13 2
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/MySqlDialect.java
  10. 36 36
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/OracleDialect.java
  11. 32 32
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/PostgreDialect.java
  12. 75 75
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLServer2005Dialect.java
  13. 36 36
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLServerDialect.java
  14. 32 32
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLiteDialect.java

+ 11 - 5
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/PaginationInterceptor.java

@@ -23,6 +23,7 @@ import com.baomidou.mybatisplus.core.parser.SqlInfo;
 import com.baomidou.mybatisplus.core.toolkit.*;
 import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler;
 import com.baomidou.mybatisplus.extension.plugins.pagination.DialectFactory;
+import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
 import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
 import com.baomidou.mybatisplus.extension.toolkit.SqlParserUtils;
 import lombok.Setter;
@@ -30,19 +31,19 @@ import lombok.experimental.Accessors;
 import org.apache.ibatis.executor.statement.StatementHandler;
 import org.apache.ibatis.mapping.BoundSql;
 import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.ParameterMapping;
 import org.apache.ibatis.mapping.SqlCommandType;
 import org.apache.ibatis.plugin.*;
 import org.apache.ibatis.reflection.MetaObject;
 import org.apache.ibatis.reflection.SystemMetaObject;
 import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
+import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.RowBounds;
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 import static java.util.stream.Collectors.joining;
 
@@ -171,13 +172,18 @@ public class PaginationInterceptor extends AbstractSqlParserHandler implements I
             }
         }
         String buildSql = concatOrderBy(originalSql, page, orderBy);
-        originalSql = DialectFactory.buildPaginationSql(page, buildSql, dbType, dialectClazz);
+        DialectModel model = DialectFactory.buildPaginationSql(page, buildSql, dbType, dialectClazz);
 
+        Configuration configuration = mappedStatement.getConfiguration();
+        List<ParameterMapping> mappings = new ArrayList<>(boundSql.getParameterMappings());
+        model.consumers(mappings, configuration);
+        metaObject.setValue("delegate.boundSql.parameterMappings", mappings);
+        metaObject.setValue("delegate.boundSql.additionalParameters", model.getDialectMap());
         /*
          * <p> 禁用内存分页 </p>
          * <p> 内存分页会查询所有结果出来处理(这个很吓人的),如果结果变化频繁这个数据还会不准。</p>
          */
-        metaObject.setValue("delegate.boundSql.sql", originalSql);
+        metaObject.setValue("delegate.boundSql.sql", model.getDialectSql());
         metaObject.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
         metaObject.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
         return invocation.proceed();

+ 24 - 23
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/DialectFactory.java

@@ -20,7 +20,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.*;
+import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;
+import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.MySqlDialect;
 import org.apache.ibatis.session.RowBounds;
 
 import java.util.Map;
@@ -49,9 +50,9 @@ public class DialectFactory {
      * @param buildSql     编译 SQL
      * @param dbType       数据类型
      * @param dialectClazz 数据库方言
-     * @return
+     * @return 分页模型
      */
-    public static String buildPaginationSql(IPage page, String buildSql, DbType dbType, String dialectClazz) {
+    public static DialectModel buildPaginationSql(IPage page, String buildSql, DbType dbType, String dialectClazz) {
         // fix #196
         return getDialect(dbType, dialectClazz).buildPaginationSql(buildSql, page.offset(), page.getSize());
     }
@@ -108,26 +109,26 @@ public class DialectFactory {
         switch (dbType) {
             case MYSQL:
                 return new MySqlDialect();
-            case MARIADB:
-                return new MariaDBDialect();
-            case ORACLE:
-                return new OracleDialect();
-            case DB2:
-                return new DB2Dialect();
-            case H2:
-                return new H2Dialect();
-            case SQL_SERVER:
-                return new SQLServerDialect();
-            case SQL_SERVER2005:
-                return new SQLServer2005Dialect();
-            case POSTGRE_SQL:
-                return new PostgreDialect();
-            case HSQL:
-                return new HSQLDialect();
-            case SQLITE:
-                return new SQLiteDialect();
-            case DM:
-                return new DmDialect();
+//            case MARIADB:
+//                return new MariaDBDialect();
+//            case ORACLE:
+//                return new OracleDialect();
+//            case DB2:
+//                return new DB2Dialect();
+//            case H2:
+//                return new H2Dialect();
+//            case SQL_SERVER:
+//                return new SQLServerDialect();
+//            case SQL_SERVER2005:
+//                return new SQLServer2005Dialect();
+//            case POSTGRE_SQL:
+//                return new PostgreDialect();
+//            case HSQL:
+//                return new HSQLDialect();
+//            case SQLITE:
+//                return new SQLiteDialect();
+//            case DM:
+//                return new DmDialect();
             default:
                 throw ExceptionUtils.mpe("The Database's IDialect Not Supported!");
         }

+ 8 - 4
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/DialectModel.java

@@ -56,7 +56,12 @@ public class DialectModel {
      * 分页数据参数 map
      */
     @Setter(value = AccessLevel.NONE)
-    private Map<String, Long> dialectMap = new HashMap<>(2);
+    private Map<String, Long> dialectMap;
+
+    public DialectModel(String dialectSql, long offset, long limit) {
+        this.dialectSql = dialectSql;
+        this.putToDialectMap(offset, limit);
+    }
 
     /**
      * 设置消费
@@ -117,11 +122,10 @@ public class DialectModel {
      *
      * @param offset 偏移量
      * @param limit  范围量
-     * @return this
      */
-    public DialectModel putToDialectMap(long offset, long limit) {
+    private void putToDialectMap(long offset, long limit) {
+        dialectMap = new HashMap<>(2);
         dialectMap.put(OFFSET_NAME, offset);
         dialectMap.put(LIMIT_NAME, limit);
-        return this;
     }
 }

+ 67 - 67
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/DB2Dialect.java

@@ -1,67 +1,67 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-
-/**
- * <p>
- * DB2 数据库分页方言
- * </p>
- *
- * @author hubin
- * @since 2016-11-10
- */
-public class DB2Dialect implements IDialect {
-
-    private static String getRowNumber(String originalSql) {
-        StringBuilder rownumber = new StringBuilder(50).append("rownumber() over(");
-        int orderByIndex = originalSql.toLowerCase().indexOf("order by");
-        if (orderByIndex > 0 && !hasDistinct(originalSql)) {
-            rownumber.append(originalSql.substring(orderByIndex));
-        }
-        rownumber.append(") as rownumber_,");
-        return rownumber.toString();
-    }
-
-    private static boolean hasDistinct(String originalSql) {
-        return originalSql.toLowerCase().contains("select distinct");
-    }
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        int startOfSelect = originalSql.toLowerCase().indexOf("select");
-        StringBuilder pagingSelect = new StringBuilder(originalSql.length() + 100)
-            .append(originalSql, 0, startOfSelect).append("select * from ( select ")
-            .append(getRowNumber(originalSql));
-        if (hasDistinct(originalSql)) {
-            pagingSelect.append(" row_.* from ( ").append(originalSql.substring(startOfSelect)).append(" ) as row_");
-        } else {
-            pagingSelect.append(originalSql.substring(startOfSelect + 6));
-        }
-
-        // 20180829 modify by hepengju
-        // https://github.com/baomidou/mybatis-plus/issues/450
-        if (offset > 0) {
-            String endString = offset + StringPool.PLUS + limit;
-            pagingSelect.append(" fetch first ").append(endString).append(" rows only) as temp_ where rownumber_ ")
-                .append("> ").append(offset);
-        } else {
-            pagingSelect.append(" fetch first ").append(limit).append(" rows only) as temp_ ");
-        }
-        return pagingSelect.toString();
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+//import com.baomidou.mybatisplus.core.toolkit.StringPool;
+//
+///**
+// * <p>
+// * DB2 数据库分页方言
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-11-10
+// */
+//public class DB2Dialect implements IDialect {
+//
+//    private static String getRowNumber(String originalSql) {
+//        StringBuilder rownumber = new StringBuilder(50).append("rownumber() over(");
+//        int orderByIndex = originalSql.toLowerCase().indexOf("order by");
+//        if (orderByIndex > 0 && !hasDistinct(originalSql)) {
+//            rownumber.append(originalSql.substring(orderByIndex));
+//        }
+//        rownumber.append(") as rownumber_,");
+//        return rownumber.toString();
+//    }
+//
+//    private static boolean hasDistinct(String originalSql) {
+//        return originalSql.toLowerCase().contains("select distinct");
+//    }
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        int startOfSelect = originalSql.toLowerCase().indexOf("select");
+//        StringBuilder pagingSelect = new StringBuilder(originalSql.length() + 100)
+//            .append(originalSql, 0, startOfSelect).append("select * from ( select ")
+//            .append(getRowNumber(originalSql));
+//        if (hasDistinct(originalSql)) {
+//            pagingSelect.append(" row_.* from ( ").append(originalSql.substring(startOfSelect)).append(" ) as row_");
+//        } else {
+//            pagingSelect.append(originalSql.substring(startOfSelect + 6));
+//        }
+//
+//        // 20180829 modify by hepengju
+//        // https://github.com/baomidou/mybatis-plus/issues/450
+//        if (offset > 0) {
+//            String endString = offset + StringPool.PLUS + limit;
+//            pagingSelect.append(" fetch first ").append(endString).append(" rows only) as temp_ where rownumber_ ")
+//                .append("> ").append(offset);
+//        } else {
+//            pagingSelect.append(" fetch first ").append(limit).append(" rows only) as temp_ ");
+//        }
+//        return pagingSelect.toString();
+//    }
+//}

+ 28 - 28
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/DmDialect.java

@@ -1,28 +1,28 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * <p>
- * 达梦数据库完全继承 Oracle
- * </p>
- *
- * @author hubin
- * @since 2018-08-21
- */
-public class DmDialect extends OracleDialect {
-
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+///**
+// * <p>
+// * 达梦数据库完全继承 Oracle
+// * </p>
+// *
+// * @author hubin
+// * @since 2018-08-21
+// */
+//public class DmDialect extends OracleDialect {
+//
+//}

+ 37 - 37
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/H2Dialect.java

@@ -1,37 +1,37 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * <p>
- * H2 数据库分页方言
- * </p>
- *
- * @author hubin
- * @since 2016-11-10
- */
-public class H2Dialect implements IDialect {
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        StringBuilder sql = new StringBuilder(originalSql);
-        sql.append(" limit ").append(limit);
-        if (offset > 0) {
-            sql.append(" offset ").append(offset);
-        }
-        return sql.toString();
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+///**
+// * <p>
+// * H2 数据库分页方言
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-11-10
+// */
+//public class H2Dialect implements IDialect {
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        StringBuilder sql = new StringBuilder(originalSql);
+//        sql.append(" limit ").append(limit);
+//        if (offset > 0) {
+//            sql.append(" offset ").append(offset);
+//        }
+//        return sql.toString();
+//    }
+//}

+ 34 - 34
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/HSQLDialect.java

@@ -1,34 +1,34 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-
-/**
- * <p>
- * HSQL 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @since 2016-01-23
- */
-public class HSQLDialect implements IDialect {
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        return originalSql + " limit " + offset + StringPool.COMMA + limit;
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+//import com.baomidou.mybatisplus.core.toolkit.StringPool;
+//
+///**
+// * <p>
+// * HSQL 数据库分页语句组装实现
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-01-23
+// */
+//public class HSQLDialect implements IDialect {
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        return originalSql + " limit " + offset + StringPool.COMMA + limit;
+//    }
+//}

+ 4 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/IDialect.java

@@ -15,6 +15,8 @@
  */
 package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
+
 /**
  * <p>
  * 数据库 分页语句组装接口
@@ -31,7 +33,7 @@ public interface IDialect {
      * @param originalSql 原始语句
      * @param offset      偏移量
      * @param limit       界限
-     * @return 分页语句
+     * @return 分页模型
      */
-    String buildPaginationSql(String originalSql, long offset, long limit);
+    DialectModel buildPaginationSql(String originalSql, long offset, long limit);
 }

+ 13 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/MySqlDialect.java

@@ -16,6 +16,7 @@
 package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
 
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
 
 /**
  * <p>
@@ -28,7 +29,17 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
 public class MySqlDialect implements IDialect {
 
     @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        return originalSql + " LIMIT " + offset + StringPool.COMMA + limit;
+    public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
+        String sql;
+        boolean existOffset = true;
+        if (offset == 0) {
+            existOffset = false;
+            sql = originalSql + " LIMIT " + StringPool.QUESTION_MARK;
+        } else {
+            sql = originalSql + " LIMIT " + StringPool.QUESTION_MARK + StringPool.COMMA + StringPool.QUESTION_MARK;
+        }
+        DialectModel model = new DialectModel(sql, offset, limit);
+        model.setConsumer(false);
+        return existOffset ? model.setConsumer(true) : model;
     }
 }

+ 36 - 36
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/OracleDialect.java

@@ -1,36 +1,36 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * <p>
- * ORACLE 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @since 2016-01-23
- */
-public class OracleDialect implements IDialect {
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        StringBuilder sql = new StringBuilder();
-        sql.append("SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( ");
-        sql.append(originalSql).append(" ) TMP WHERE ROWNUM <=").append((offset >= 1) ? (offset + limit) : limit);
-        sql.append(") WHERE ROW_ID > ").append(offset);
-        return sql.toString();
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+///**
+// * <p>
+// * ORACLE 数据库分页语句组装实现
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-01-23
+// */
+//public class OracleDialect implements IDialect {
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        StringBuilder sql = new StringBuilder();
+//        sql.append("SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( ");
+//        sql.append(originalSql).append(" ) TMP WHERE ROWNUM <=").append((offset >= 1) ? (offset + limit) : limit);
+//        sql.append(") WHERE ROW_ID > ").append(offset);
+//        return sql.toString();
+//    }
+//}

+ 32 - 32
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/PostgreDialect.java

@@ -1,32 +1,32 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * <p>
- * Postgre 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @since 2016-01-23
- */
-public class PostgreDialect implements IDialect {
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        return originalSql + " limit " + limit + " offset " + offset;
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+///**
+// * <p>
+// * Postgre 数据库分页语句组装实现
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-01-23
+// */
+//public class PostgreDialect implements IDialect {
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        return originalSql + " limit " + limit + " offset " + offset;
+//    }
+//}

+ 75 - 75
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLServer2005Dialect.java

@@ -1,75 +1,75 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-
-/**
- * <p>
- * SQLServer 2005 数据库分页方言
- * </p>
- *
- * @author hubin
- * @since 2016-11-10
- */
-public class SQLServer2005Dialect implements IDialect {
-
-
-    private static String getOrderByPart(String sql) {
-        String loweredString = sql.toLowerCase();
-        int orderByIndex = loweredString.indexOf("order by");
-        if (orderByIndex != -1) {
-            return sql.substring(orderByIndex);
-        } else {
-            return StringPool.EMPTY;
-        }
-    }
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        StringBuilder pagingBuilder = new StringBuilder();
-        String orderby = getOrderByPart(originalSql);
-        String distinctStr = StringPool.EMPTY;
-
-        String loweredString = originalSql.toLowerCase();
-        String sqlPartString = originalSql;
-        if (loweredString.trim().startsWith("select")) {
-            int index = 6;
-            if (loweredString.startsWith("select distinct")) {
-                distinctStr = "DISTINCT ";
-                index = 15;
-            }
-            sqlPartString = sqlPartString.substring(index);
-        }
-        pagingBuilder.append(sqlPartString);
-
-        // if no ORDER BY is specified use fake ORDER BY field to avoid errors
-        if (StringUtils.isEmpty(orderby)) {
-            orderby = "ORDER BY CURRENT_TIMESTAMP";
-        }
-
-        StringBuilder sql = new StringBuilder();
-        sql.append("WITH selectTemp AS (SELECT ").append(distinctStr).append("TOP 100 PERCENT ")
-            .append(" ROW_NUMBER() OVER (").append(orderby).append(") as __row_number__, ").append(pagingBuilder)
-            .append(") SELECT * FROM selectTemp WHERE __row_number__ BETWEEN ")
-            //FIX#299:原因:mysql中limit 10(offset,size) 是从第10开始(不包含10),;而这里用的BETWEEN是两边都包含,所以改为offset+1
-            .append(offset + 1)
-            .append(" AND ")
-            .append(offset + limit).append(" ORDER BY __row_number__");
-        return sql.toString();
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+//import com.baomidou.mybatisplus.core.toolkit.StringPool;
+//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+//
+///**
+// * <p>
+// * SQLServer 2005 数据库分页方言
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-11-10
+// */
+//public class SQLServer2005Dialect implements IDialect {
+//
+//
+//    private static String getOrderByPart(String sql) {
+//        String loweredString = sql.toLowerCase();
+//        int orderByIndex = loweredString.indexOf("order by");
+//        if (orderByIndex != -1) {
+//            return sql.substring(orderByIndex);
+//        } else {
+//            return StringPool.EMPTY;
+//        }
+//    }
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        StringBuilder pagingBuilder = new StringBuilder();
+//        String orderby = getOrderByPart(originalSql);
+//        String distinctStr = StringPool.EMPTY;
+//
+//        String loweredString = originalSql.toLowerCase();
+//        String sqlPartString = originalSql;
+//        if (loweredString.trim().startsWith("select")) {
+//            int index = 6;
+//            if (loweredString.startsWith("select distinct")) {
+//                distinctStr = "DISTINCT ";
+//                index = 15;
+//            }
+//            sqlPartString = sqlPartString.substring(index);
+//        }
+//        pagingBuilder.append(sqlPartString);
+//
+//        // if no ORDER BY is specified use fake ORDER BY field to avoid errors
+//        if (StringUtils.isEmpty(orderby)) {
+//            orderby = "ORDER BY CURRENT_TIMESTAMP";
+//        }
+//
+//        StringBuilder sql = new StringBuilder();
+//        sql.append("WITH selectTemp AS (SELECT ").append(distinctStr).append("TOP 100 PERCENT ")
+//            .append(" ROW_NUMBER() OVER (").append(orderby).append(") as __row_number__, ").append(pagingBuilder)
+//            .append(") SELECT * FROM selectTemp WHERE __row_number__ BETWEEN ")
+//            //FIX#299:原因:mysql中limit 10(offset,size) 是从第10开始(不包含10),;而这里用的BETWEEN是两边都包含,所以改为offset+1
+//            .append(offset + 1)
+//            .append(" AND ")
+//            .append(offset + limit).append(" ORDER BY __row_number__");
+//        return sql.toString();
+//    }
+//}

+ 36 - 36
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLServerDialect.java

@@ -1,36 +1,36 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * <p>
- * SQLServer 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @since 2016-03-23
- */
-public class SQLServerDialect implements IDialect {
-
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        StringBuilder sql = new StringBuilder(originalSql);
-        sql.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ");
-        sql.append(limit).append(" ROWS ONLY");
-        return sql.toString();
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+///**
+// * <p>
+// * SQLServer 数据库分页语句组装实现
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-03-23
+// */
+//public class SQLServerDialect implements IDialect {
+//
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        StringBuilder sql = new StringBuilder(originalSql);
+//        sql.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ");
+//        sql.append(limit).append(" ROWS ONLY");
+//        return sql.toString();
+//    }
+//}

+ 32 - 32
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLiteDialect.java

@@ -1,32 +1,32 @@
-/*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * <p>
- * SQLite 数据库分页语句组装实现
- * </p>
- *
- * @author hubin
- * @since 2016-01-23
- */
-public class SQLiteDialect implements IDialect {
-
-    @Override
-    public String buildPaginationSql(String originalSql, long offset, long limit) {
-        return originalSql + " limit " + limit + " offset " + offset;
-    }
-}
+///*
+// * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+// * <p>
+// * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// * use this file except in compliance with the License. You may obtain a copy of
+// * the License at
+// * <p>
+// * http://www.apache.org/licenses/LICENSE-2.0
+// * <p>
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// * License for the specific language governing permissions and limitations under
+// * the License.
+// */
+//package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+//
+///**
+// * <p>
+// * SQLite 数据库分页语句组装实现
+// * </p>
+// *
+// * @author hubin
+// * @since 2016-01-23
+// */
+//public class SQLiteDialect implements IDialect {
+//
+//    @Override
+//    public String buildPaginationSql(String originalSql, long offset, long limit) {
+//        return originalSql + " limit " + limit + " offset " + offset;
+//    }
+//}