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://www.toymoban.com/news/detail-697964.html
初始化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://www.toymoban.com/news/detail-697964.html
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);
}
}
到了这里,关于beetlsql3.x版本适配达梦数据库的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!