• 达梦数据库整合流程,mybatisplus踩坑记录


    达梦数据库整合流程,mybatis-plus踩坑记录

    从mysql迁移到达梦数据库可以使用达梦的迁移工具进行迁移,具体可以参考

    https://www.cnblogs.com/zywu-king/p/12337382.html 这篇文章;

    本次项目使用主要架构为

    • mybatis-plus 3.14
    • 达梦数据库版本8

    数据库驱动问题

    使用数据库驱动如下

    <dependency>
      <groupId>com.dameng</groupId>
      <artifactId>Dm8JdbcDriver18</artifactId>
      <version>8.1.1.49</version>
    </dependency>
    
    

    注意点 : DmJdbcDriver18 这类依赖不能使用,否则mybatis 查询数据库会出现类型转换错误;其次 达梦版本为8 就使用 Dm8JdbcDriver18, 如果达梦版本为7 ,就使用 Dm7JdbcDriver17 以此类推;

    如果使用 jpa 那么 达梦8 对应的 hibernate 依赖如下

    <dependency>
      <groupId>com.dameng</groupId>
      <artifactId>DmDialect-for-hibernate4.0</artifactId>
      <version>8.1.2.79</version>
    </dependency>
    

    附方言配置(按需配置)

    #方言
    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.DmDialect
    spring.jpa.database-platform=org.hibernate.dialect.DmDialect
    spring.jpa.properties.hibernate.hbm2ddl.auto=update
    spring.jpa.properties.hibernate.show_sql=true
    

    spring配置文件问题

    达梦数据库类似oracl,其数据库方式为模式方式。一个模式就是一个数据库;如果数据库名称和模式名称不一致,那么使用类似原始的数据库url 就会出问题, 谨慎起见,url后面都配置模式名称;

    错误示范

    url: jdbc:dm://localhost:5236/mydb
    

    正确示范

    url: jdbc:dm://localhost:5236?schema=mydb
    

    mysql 有 longtext, text blog 等大数据库类型,迁移到达梦数据库 一般会转为clob 类型;查询时会报类型转换异常在url后面添加配置,将 clob当作 string处理;

    &clobAsString=true
    

    完整的JDBC连接

              url: jdbc:dm://localhost:5236?schema=mydb&compatibleMode=mysql&characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
              username: SYSDBA
              password: mypassword
              driver-class-name: dm.jdbc.driver.DmDriver
    

    activiti支持达梦数据库

    方案一: 寻找已经整合好的jar包 ; 获取方式 关注gong众号知识追寻者:回复 dm 获取;

    方案二: 将activiti-engine-5.22.0相关源码拷贝到工程src下,保持包路径不变,并做相应修改;

    具体如下:

    1. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,增加成员变量
    public static final String DATABASE_TYPE_DM = "dm";
    public static final String DATABASE_TYPE_H2 = "h2";
    public static final String DATABASE_TYPE_HSQL = "hsql";
    public static final String DATABASE_TYPE_MYSQL = "mysql";
    public static final String DATABASE_TYPE_ORACLE = "oracle";
    
    1. 在org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl,修改getDefaultDatabaseTypeMappings()
    protected static Properties getDefaultDatabaseTypeMappings() {
        Properties databaseTypeMappings = new Properties();
        databaseTypeMappings.setProperty("DM DBMS", DATABASE_TYPE_DM);
        databaseTypeMappings.setProperty("H2", DATABASE_TYPE_H2);
    
    1. 在org.activiti.engine.impl.db.DbSqlSessionFactory,修改initBulkInsertEnabledMap(String databaseType)
    if ("oracle".equals(databaseType) || "dm".equals(databaseType)) {
        bulkInsertableMap.put(EventLogEntryEntity.class, Boolean.FALSE);
    }
    
    1. 在org.activiti.engine.impl.db.DbSqlSessionFactory,修改static{}
    // dm
    databaseSpecificLimitBeforeStatements.put("dm", "");
    databaseSpecificLimitAfterStatements.put("dm", "LIMIT #{maxResults} OFFSET #{firstResult}");
    databaseSpecificLimitBetweenStatements.put("dm", "");
    databaseOuterJoinLimitBetweenStatements.put("dm", "");
    databaseSpecificOrderByStatements.put("dm", defaultOrderBy);
    
    // h2
    databaseSpecificLimitBeforeStatements.put("h2", "");
    databaseSpecificLimitAfterStatements.put("h2", "LIMIT #{maxResults} OFFSET #{firstResult}");
    databaseSpecificLimitBetweenStatements.put("h2", "");
    databaseOuterJoinLimitBetweenStatements.put("h2", "");
    databaseSpecificOrderByStatements.put("h2", defaultOrderBy);
    
    1. 在 org.activiti.engine.impl.AbstractQuery,修改addOrder(String column, String sortOrder, NullHandlingOnOrder nullHandlingOnOrder)
    if (nullHandlingOnOrder.equals(NullHandlingOnOrder.NULLS_FIRST)) {
    
        if (ProcessEngineConfigurationImpl.DATABASE_TYPE_H2.equals(databaseType) 
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_HSQL.equals(databaseType)
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_POSTGRES.equals(databaseType) 
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_ORACLE.equals(databaseType)
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_DM.equals(databaseType)) {
            orderBy = orderBy + defaultOrderByClause + " NULLS FIRST";
        } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_MYSQL.equals(databaseType)) {
            orderBy = orderBy + "isnull(" + column + ") desc," + defaultOrderByClause;
        } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_DB2.equals(databaseType) 
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_MSSQL.equals(databaseType)) {
            orderBy = orderBy + "case when " + column + " is null then 0 else 1 end," + defaultOrderByClause;
        } else {
            orderBy = orderBy + defaultOrderByClause;
        }
    
    } else if (nullHandlingOnOrder.equals(NullHandlingOnOrder.NULLS_LAST)) {
    
        if (ProcessEngineConfigurationImpl.DATABASE_TYPE_H2.equals(databaseType) 
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_HSQL.equals(databaseType)
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_POSTGRES.equals(databaseType) 
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_ORACLE.equals(databaseType)
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_DM.equals(databaseType)) {
            orderBy = orderBy + column + " " + sortOrder + " NULLS LAST";
        } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_MYSQL.equals(databaseType)) {
            orderBy = orderBy + "isnull(" + column + ") asc," + defaultOrderByClause;
        } else if (ProcessEngineConfigurationImpl.DATABASE_TYPE_DB2.equals(databaseType) 
                || ProcessEngineConfigurationImpl.DATABASE_TYPE_MSSQL.equals(databaseType)) {
            orderBy = orderBy + "case when " + column + " is null then 1 else 0 end," + defaultOrderByClause;
        } else {
            orderBy = orderBy + defaultOrderByClause;
        }
    }
    

    同时需要引入外部依赖支持流程引擎

      <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>1.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.enterprise.concurrent</groupId>
                <artifactId>javax.enterprise.concurrent-api</artifactId>
                <version>1.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>2.4.5</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.drools</groupId>
                <artifactId>drools-core</artifactId>
                <version>5.5.0.Final</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.drools</groupId>
                <artifactId>drools-compiler</artifactId>
                <version>5.5.0.Final</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.uuid</groupId>
                <artifactId>java-uuid-generator</artifactId>
                <version>3.1.3</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.transaction</groupId>
                <artifactId>javax.transaction-api</artifactId>
                <version>1.2</version>
                <scope>provided</scope>
            </dependency>
    

    删除源码 test 包内容;

    完成以上重新编译

    数据库手册,达梦数据库连接工具统一关注 gong众号知识追寻者:回复 dm 获取;

    参考连接 https://my.oschina.net/168052730/blog/4300003

  • 相关阅读:
    【Android】Handler的应用(二):从服务器端加载JSON数据的优化
    [置顶] IOS 开发之 CocoaPods讲解
    POJ 1068 (13.10.11)
    android使用百度地图、定位SDK实现地图和定位功能!(最新、可用+吐槽)
    C++笔记(1)
    WCF讲解
    php5 图片验证码一例
    PHP5 GD库生成图形验证码(汉字)
    mysql中limit的用法实例解析
    Limit参数优化MySQL查询的方法
  • 原文地址:https://www.cnblogs.com/zszxz/p/16090901.html
Copyright © 2020-2023  润新知