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中达梦连接串可以直接跑项目文章来源:https://uudwc.com/A/126jG
初始化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);
pom引入依赖
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>sql-springboot-starter</artifactId>
<version>3.23.3-RELEASE</version>
</dependency>
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>8.1.2.192</version>
</dependency>
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
SimpleDataSourceConfig
在com.dameng.beetlsql3_x_dm.DataSource目录下新建连接类文章来源地址https://uudwc.com/A/126jG
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;
}
}
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);
}
}