greenplum是pivotal在postgresql的基础上修改的一个数据库,语法和postgresql通用。使用PageHelper做分页插件的时候,发现目前没有针对greenplum做支持,但是对postgresql做了支持,因为只是分页的时候用到,所以只需要支持分页的语法即可。

PageHelper的github整合Spring Bootgreenplum

依赖:

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>

1、配置文件

pagehelper:
helperDialect: mysql # 默认的
autoRuntimeDialect: true # 必填
reasonable: true
supportMethodsArguments: true
params: count=countSql
auto-dialect: true # 必填
close-conn: false
offset-as-page-num: true

2、代码

com.github.pagehelper.page.PageAutoDialect中配置了各个方言。

 static {
//注册别名
dialectAliasMap.put("hsqldb", HsqldbDialect.class);
dialectAliasMap.put("h2", HsqldbDialect.class);
dialectAliasMap.put("postgresql", HsqldbDialect.class);
dialectAliasMap.put("phoenix", HsqldbDialect.class); dialectAliasMap.put("mysql", MySqlDialect.class);
dialectAliasMap.put("mariadb", MySqlDialect.class);
dialectAliasMap.put("sqlite", MySqlDialect.class); dialectAliasMap.put("oracle", OracleDialect.class);
dialectAliasMap.put("db2", Db2Dialect.class);
dialectAliasMap.put("informix", InformixDialect.class); dialectAliasMap.put("sqlserver", SqlServerDialect.class);
dialectAliasMap.put("sqlserver2012", SqlServer2012Dialect.class); dialectAliasMap.put("derby", SqlServer2012Dialect.class);
}

发现其实是使用jdbc的url的连接的jdbc:<数据库>://<IP>:<PODT>/<DB>中的<数据库>来作为key的。

postgresql的url格式:

jdbc:postgresql://localhost:5432/postgres

greenplum的jdbc配置连接格式为:

jdbc:pivotal:greenplum://localhost:5432;DatabaseName=test

我们需要将pivotal作为key,HsqldbDialect.class作为value添加到com.github.pagehelper.page.PageAutoDialectdialectAliasMap中即可。

PageHelper是从jdbcUrl获得数据源的方言的,获取之后会缓存到com.github.pagehelper.page.PageAutoDialect#urlDialectMap中:

private String fromJdbcUrl(String jdbcUrl) {
for (String dialect : dialectAliasMap.keySet()) {
if (jdbcUrl.indexOf(":" + dialect + ":") != -1) {
return dialect;
}
}
return null;
}

配置类PageHelperConfiguration实现:

import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import com.github.pagehelper.dialect.helper.HsqldbDialect;
import com.github.pagehelper.page.PageAutoDialect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Configuration; import javax.annotation.PostConstruct;
import java.lang.reflect.Field;
import java.util.Map; @AutoConfigureAfter(PageHelperAutoConfiguration.class)
@Configuration
public class PageHelperConfiguration { final static Logger logger = LoggerFactory.getLogger(PageHelperConfiguration.class); @PostConstruct
public void init() throws Exception {
try{
PageAutoDialect pageAutoDialect = new PageAutoDialect();
Field dialectAliasMap = pageAutoDialect.getClass().getDeclaredField("dialectAliasMap");
dialectAliasMap.setAccessible(true);
Map<String, Class<?>> dialectAliasMapValue = (Map<String, Class<?>>)dialectAliasMap.get(pageAutoDialect);
dialectAliasMapValue.put("pivotal", HsqldbDialect.class);
}catch (Exception e) {
logger.error("修改 PageAutoDialect 出错:{}", e.getMessage());
throw e;
}
} }

PageHelper支持GreenPlum的更多相关文章

  1. GreenPlum简单性能测试与分析--续

    版权声明:本文由黄辉原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/259 来源:腾云阁 https://www.qclou ...

  2. GreenPlum简单性能测试与分析

    版权声明:本文由黄辉原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/195 来源:腾云阁 https://www.qclou ...

  3. Greenplum——升级的分布式PostgresSQL

    Greenplum数据库基于PostgreSQL开源技术.本质上讲,它是多个PostgreSQL实例一起充当一个数据库管理系统.Greenplum以PostgreSQL 8.2.15为基础构建,在SQ ...

  4. Greenplum 简单性能测试与分析

    如今,多样的交易模式以及大众消费观念的改变使得数据库应用领域不断扩大,现代的大型分布式应用系统的数据膨胀也对数据库的海量数据处理能力和并行处理能力提出了更高的要求,如何在数据呈现海量扩张的同时提高处理 ...

  5. Pivotal开源基于PostgreSQL的数据库Greenplum

    http://www.infoq.com/cn/news/2015/11/PostgreSQL-Pivotal 近日,Pivotal宣布开源大规模并行处理(MPP)数据库Greenplum,其架构是针 ...

  6. 【大数据之数据仓库】HAWQ versus GreenPlum

    谈到GreenPlum,肯定会有同事说HAWQ!是的,在本系列第一篇选型流水记里,也有提到.因为对HAWQ接触有限,没有深入具体了解,所以很多信息都是来自于博文,人云亦云,我把看过的资料简要整理,希望 ...

  7. spring-boot | 整合通用Mabatis 分页插件PageHelper

    Mybatis通用Mapper介绍 Mybatis 通用 Mapper 极其方便的使用 Mybatis 单表的增删改查,支持单表操作,不支持通用的多表联合查询 优点: 通用 Mapper 可以极大的方 ...

  8. Mybatis中使用PageHelper插件进行分页

    分页的场景比较常见,下面主要介绍一下使用PageHelper插件进行分页操作: 一.概述: PageHelper支持对mybatis进行分页操作,项目在github地址: https://github ...

  9. Github PageHelper 原理解析

    任何服务对数据库的日常操作,都离不开增删改查.如果一次查询的纪录很多,那我们必须采用分页的方式.对于一个Springboot项目,访问和查询MySQL数据库,持久化框架可以使用MyBatis,分页工具 ...

随机推荐

  1. Java——DOS命令窗口用命令编译文件夹下所有.java文件

    1.进入指定目录    cd 进入用户主目录    cd ~ 进入用户主目录     cd - 返回进入此目录之前所在的目录     cd .. 返回上级目录    cd\ 直接退回到当前盘根目录2. ...

  2. PHP非常用函数汇总

    1) ARRAY_FILTER — 用回调函数过滤数组中的单元 function  odd ( $var ) {      // returns whether the input integer i ...

  3. html浏览器高度和宽度和其他dom获取

    1.获取网页可见区域的宽度:document.body.clientWidth ; 2.获取网页可见区域的高度:document.body.clientHeight; 3.获取 网页可见区域宽:doc ...

  4. 基于 kubeadm 搭建高可用的kubernetes 1.18.2 (k8s)集群 三 集群可用性测试

    1. 创建nginx ds # 写入配置 $ cat > nginx-ds.yml <<EOF apiVersion: v1 kind: Service metadata: name ...

  5. Unity 游戏框架搭建 2019 (五十、五十一) 消息机制小结&MonoBehaviourSimplify 是框架?

    我们花了 5 篇文章学习了消息机制的方方面面.并且完成了一个简易消息机制,之后集成到了我们的 MonoBehaviourSimplify 里. 现在 MonoBehaviourSimplify 有一点 ...

  6. BUUCTF WEB-WP(3)

    BUUCTF WEB 几道web做题的记录 [ACTF2020 新生赛]Exec 知识点:exec命令执行 这题最早是在一个叫中学生CTF平台上看到的类似,比这题稍微要复杂一些,多了一些限制(看看大佬 ...

  7. Spring/SpringBoot常用注解总结

    转自:[Guide哥] 0.前言 可以毫不夸张地说,这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景.对于每一个注解我都说了具体用法,掌握搞懂,使 ...

  8. 使用docker方式构建prometheus监控的学习

    一.背景:近期学习部署prometheus监控系统,经研究发现prometheus提供docker运行模式.根据我的经验,能够使用docker模式构建系统一定多快好省. 二.环境: 1.centos7 ...

  9. Chisel3 - Tutorial - Stack

    https://mp.weixin.qq.com/s/-AVJD1IfvNIJhmZM40DemA   实现后入先出(last in, first out)的栈.   参考链接: https://gi ...

  10. Java实现 蓝桥杯 算法提高 字符串匹配

    试题 算法提高 字符串匹配 问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行.你的程序还需支持大小写敏感选项:当选项打开时,表示同一个字母的大写和小写看作不同的字符:当选项关闭时 ...