• beetlsql3.x版本适配达梦数据库


    BeetlSQL介绍

    BeetlSQL的目标是提供开发高效维护高效运行高效数据库访问框架,在一个系统多个库的情况下,提供一致的编写代码方式。支持如下数据平台

    • 传统数据库:MySQL(国内兼容MySQL协议的各种大数据库),MariaDB,Oracle,Postgres,DB2,SQL Server,H2,SQLite,Derby,神通,达梦,华为高斯,人大金仓,PolarDB等
    • 大数据:HBase,ClickHouse,Cassandar,Hive
    • 物联网时序数据库:Machbase,TD-Engine,IotDB
    • SQL查询引擎:Drill,Presto,Druid
    • 内存数据库:ignite,CouchBase

    BeetlSQL 不仅仅是简单的类似MyBatis或者是Hibernate,或者是二者的综合,BeetlSQL远大理想是对标甚至超越Spring Data,是实现数据访问统一的框架,无论是传统数据库,还是大数据,还是查询引擎或者时序库,内存数据库。
    官网资料:https://www.kancloud.cn/xiandafu/beetlsql3_guide/3033051

    BeetlSQL适配

    项目适配的gitee地址:https://gitee.com/gy297879328/beetlsql3.x_dm 代码拉下来后,修改application.properties中达梦连接串可以直接跑项目

    初始化sql语句

    CREATE TABLE "SYS_USER" (
      "id" INT NOT NULL,
      "name" varchar(255) DEFAULT NULL,
      "department_id" int DEFAULT NULL,
      "create_time" date DEFAULT NULL,
      PRIMARY KEY ("id")
    ) ;
    
    
    INSERT INTO "SYS_USER" VALUES (1, 'lijz', 1, NULL);
    INSERT INTO "SYS_USER" VALUES (2, 'lucy', 1, NULL);
    INSERT INTO "SYS_USER" VALUES (3, 'bear', 2, NULL);
    INSERT INTO "SYS_USER" VALUES (4, 'mike', 1, NULL);
    INSERT INTO "SYS_USER" VALUES (5, 'lisan', 1, NULL);
    INSERT INTO "SYS_USER" VALUES (6, 'xb', 1, NULL);
    INSERT INTO "SYS_USER" VALUES (7, 'duanwu', 2, NULL);
    INSERT INTO "SYS_USER" VALUES (8, 'fenh', 1, NULL);
    INSERT INTO "SYS_USER" VALUES (9, 'lj', 2, NULL);
    INSERT INTO "SYS_USER" VALUES (10, 'gshen', 1, NULL);
    INSERT INTO "SYS_USER" VALUES (11, 'lihui', 1, NULL);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    pom引入依赖

    
            <dependency>
                <groupId>com.ibeetlgroupId>
                <artifactId>sql-springboot-starterartifactId>
                <version>3.23.3-RELEASEversion>
            dependency>
    
            <dependency>
                <groupId>com.damenggroupId>
                <artifactId>DmJdbcDriver18artifactId>
                <version>8.1.2.192version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    application.properties

    spring.datasource.url=jdbc:dm://127.0.0.1:5236
    spring.datasource.username=SYSDBA
    spring.datasource.password=SYSDBA
    spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
    beetlsql.sqlManagers=sqlManager1
    beetlsql.sqlManager1.ds=ds1
    beetlsql.sqlManager1.basePackage=com.dameng.beetlsql3_x_dm
    beetlsql.sqlManager1.dbStyle=org.beetl.sql.core.db.DamengStyle
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    SimpleDataSourceConfig

    在com.dameng.beetlsql3_x_dm.DataSource目录下新建连接类

    package com.dameng.beetlsql3_x_dm.DataSource;
    
    
    import com.zaxxer.hikari.HikariDataSource;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Primary;
    import org.springframework.core.env.Environment;
    
    import javax.sql.DataSource;
    
    
    @Configuration
    public class SimpleDataSourceConfig {
        @Autowired
        ApplicationContext ctx;
    
        @Primary
        @Bean(name = "ds1")
        public DataSource datasource(Environment env) {
            HikariDataSource ds = new HikariDataSource();
            ds.setJdbcUrl(env.getProperty("spring.datasource.url"));
            ds.setUsername(env.getProperty("spring.datasource.username"));
            ds.setPassword(env.getProperty("spring.datasource.password"));
            ds.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
            return ds;
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    UserService

    package com.dameng.beetlsql3_x_dm.Service;
    
    import com.dameng.beetlsql3_x_dm.Domain.UserInfo;
    import com.dameng.beetlsql3_x_dm.Mapper.UserMapper;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import java.util.List;
    
    @Service
    @Transactional
    public class UserService {
        @Autowired
        UserMapper userMapper;
    
        public void selectUserList() {
            List<UserInfo> allList = userMapper.all();
            System.out.println(allList);
        }
    }
      
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
  • 相关阅读:
    数据结构前言
    css2024
    前端性能优化之LightHouse
    14:00面试,14:06就出来了,问的问题有点变态。。。
    Python图像处理丨图像的灰度线性变换
    【Unity程序技巧】公共Update管理器
    自学Python第二十五天- Pipenv 虚拟环境和包管理工具
    统一建模语言UML(1~8章在线测试参考答案)
    JavaScript数字、数字方法
    [蓝桥杯2015决赛]穿越雷区 (BFS)
  • 原文地址:https://blog.csdn.net/qq_35349982/article/details/132708189