浏览代码

添加对 行云 数据库分页的支持

huyang 3 年之前
父节点
当前提交
b25a0dd8b7

+ 4 - 0
mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/DbType.java

@@ -148,6 +148,10 @@ public enum DbType {
      * Vertica
      */
     VERTICA("vertica", "vertica数据库"),
+    /**
+     * xcloud
+     */
+    XCloud("xcloud", "行云数据库"),
     /**
      * UNKONWN DB
      */

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

@@ -82,6 +82,8 @@ public class DialectFactory {
                 dialect = new GBasedbtDialect();
             } else if (dbType == DbType.GBASE_INFORMIX){
                 dialect = new GBaseInfromixDialect();
+            }else if (dbType == DbType.XCloud){
+                dialect = new XCloudDialect();
             }
             DIALECT_ENUM_MAP.put(dbType, dialect);
         }

+ 46 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/XCloudDialect.java

@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011-2022, baomidou (jobob@qq.com).
+ *
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.extension.plugins.pagination.DialectModel;
+
+/**
+ * XCloud 数据库分页语句组装实现
+ *
+ * @author huyang
+ * @since 2022-04-13
+ */
+public class XCloudDialect implements IDialect {
+    /**
+     *
+     * @param originalSql
+     * @param offset
+     * @param limit
+     * @return
+     */
+
+    @Override
+    public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
+        StringBuilder sql = new StringBuilder(originalSql).append(" LIMIT ");
+        if (offset != 0L) {
+            sql.append(" ("+FIRST_MARK +","+SECOND_MARK+") ") ;
+            return new DialectModel(sql.toString(), offset+1, offset+limit).setConsumerChain();
+        } else {
+            sql.append(FIRST_MARK);
+            return new DialectModel(sql.toString(), limit).setConsumer(true);
+        }
+    }
+}

+ 3 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/JdbcUtils.java

@@ -122,7 +122,9 @@ public class JdbcUtils {
             return DbType.IMPALA;
         } else if (url.contains(":vertica:")) {
             return DbType.VERTICA;
-        } else {
+        } else if (url.contains(":xcloud:")) {
+            return DbType.XCloud;
+        }else {
             logger.warn("The jdbcUrl is " + jdbcUrl + ", Mybatis Plus Cannot Read Database type or The Database's Not Supported!");
             return DbType.OTHER;
         }