当前位置:网站首页>(37) How bee uses different data source instances at the same time
(37) How bee uses different data source instances at the same time
2022-06-12 10:56:00 【abckingaa】
Bee How to use different data source instances at the same time ??
In addition to configuring the tables and tables corresponding to different data sources javabean Outside the package rules of entities ( If in bee.properties To configure ),
stay Bee V1.11 It also provides direct designation of data sources .
For example , ds1 Yes, it is configured as mysql Data source . And then through :
mysqlSuidRich.setDataSourceName("ds1");
public static SuidRich getMysqlSuidRich() {
SuidRich mysqlSuidRich=BF.getSuidRich();
// Data sources can use Java Mode configuration , You can also use xml Mode configuration
// mysqlSuidRich.setDataSourceName("mysqlDsName");
mysqlSuidRich.setDataSourceName("ds1"); // This instance is on InitDsUtil.initDS(); use java Setting mode
return mysqlSuidRich;
}The complete example is as follows :
/*
* Copyright 2016-2022 the original author.All rights reserved.
* Kingstar([email protected])
* The license,see the LICENSE file.
*/
package org.teasoft.exam.bee.osql.ds;
import org.teasoft.bee.osql.SuidRich;
import org.teasoft.exam.bee.osql.entity.Orders;
import org.teasoft.honey.osql.core.HoneyConfig;
import org.teasoft.honey.osql.core.HoneyContext;
import org.teasoft.honey.osql.shortcut.BF;
/**
* Use different data source instances at the same time
* @author Kingstar
* @since 1.11
*/
public class TwoDiffDsWithSet {
static {
InitDsUtil.initDS();
}
public static void main(String[] args) {
HoneyConfig.getHoneyConfig().multiDS_enable = true; // Use multiple data sources Must be set when there are multiple data sources
HoneyConfig.getHoneyConfig().multiDS_differentDbType=true; // Use multiple databases at the same time , Be sure to set
HoneyContext.setConfigRefresh(true);
// When operating mysql when
SuidRich mysqlSuidRich=getMysqlSuidRich();
mysqlSuidRich.select(new Orders(),2);
// When operating sqlite when
SuidRich sqliteSuidRich=getSqliteSuidRich();
sqliteSuidRich.select(new Orders(),2);
//mysql
mysqlSuidRich.select(new Orders(),2);
}
public static SuidRich getMysqlSuidRich() {
SuidRich mysqlSuidRich=BF.getSuidRich();
// Data sources can use Java Mode configuration , You can also use xml Mode configuration
// mysqlSuidRich.setDataSourceName("mysqlDsName");
mysqlSuidRich.setDataSourceName("ds1"); // This instance is on InitDsUtil.initDS(); use java Setting mode
return mysqlSuidRich;
}
public static SuidRich getSqliteSuidRich() {
SuidRich sqliteSuidRich=BF.getSuidRich();
// Data sources can use Java Mode configuration , You can also use xml Mode configuration
// sqliteSuidRich.setDataSourceName("sqliteDsName");
sqliteSuidRich.setDataSourceName("ds2"); // This instance is on InitDsUtil.initDS(); use java Setting mode
return sqliteSuidRich;
}
// 2022-06-12 07:00:14 [ main:0 ] - [ INFO ] com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:721) {dataSource-1} inited
// 2022-06-12 07:00:14 [ main:2 ] - [ ERROR ] com.alibaba.druid.pool.DruidDataSource.validationQueryCheck(DruidDataSource.java:861) testWhileIdle is true, validationQuery not set
// 2022-06-12 07:00:14 [ main:2 ] - [ INFO ] com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:721) {dataSource-2} inited
// 2022-06-12 07:00:14 [ main:3 ] - [ INFO ] com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:721) {dataSource-3} inited
// [Bee] LoggerFactory Use the Logger is : org.teasoft.honey.logging.SystemLogger
// [INFO] [Bee] Parse DataSourceMap: dataSource name to database name , result: {ds1=MySQL, ds2=SQLite, ds3=MySQL}
// [INFO] [Bee] ========= get the dbName from the Connection is :MySQL
// [INFO] [Bee] ========= get the dbName in real time is :MySQL
// [INFO] [Bee] select SQL(entity,size): SELECT id,userid,name,total,createtime,remark,sequence,abc,updatetime FROM orders LIMIT ?,? [values]: 0(Integer),2(Integer)
// [INFO] [Bee] select SQL(entity,size): ( ExecutableSql )
// SELECT id,userid,name,total,createtime,remark,sequence,abc,updatetime FROM orders LIMIT 0,2
// [INFO] [Bee] | <-- select rows: 2
// [INFO] [Bee] ========= get the dbName in real time is :SQLite
// [INFO] [Bee] select SQL(entity,size): SELECT id,userid,name,total,createtime,remark,sequence,abc,updatetime FROM orders LIMIT ? [values]: 2(Integer)
// [INFO] [Bee] select SQL(entity,size): ( ExecutableSql )
// SELECT id,userid,name,total,createtime,remark,sequence,abc,updatetime FROM orders LIMIT 2
// [INFO] [Bee] | <-- select rows: 2
// [INFO] [Bee] ========= get the dbName in real time is :MySQL
// [INFO] [Bee] select SQL(entity,size): SELECT id,userid,name,total,createtime,remark,sequence,abc,updatetime FROM orders LIMIT ?,? [values]: 0(Integer),2(Integer)
// [INFO] [Bee] select SQL(entity,size): ( ExecutableSql )
// SELECT id,userid,name,total,createtime,remark,sequence,abc,updatetime FROM orders LIMIT 0,2
// [INFO] [Bee] ==========get from Cache.
// [INFO] [Bee] | <-- select rows: 2
}
Reference resources :
src/main/java/org/teasoft/exam/bee/osql/ds/TwoDiffDsWithSet.java · automvc/bee-exam - Gitee.com
ORM Bee Data collection
边栏推荐
- 2021-03-24
- How to play the 2022 Taobao 618 Super Cat Games? What are the strategies for the Super Cat Games
- Several methods of importing ThinkPHP
- Malicious code analysis practice - lab03-03 Exe basic dynamic analysis
- Malicious code analysis practice - lab03-01 Exe basic dynamic analysis
- Malicious code analysis practice - lab03-02 DLL analysis
- k53.第二章 基于二进制包安装kubernetes v1.22 --集群部署
- PHP specifies the number of people to distribute the specified amount equally at random (scaling method)
- 模块8作业
- ^33变量提升和函数提升面试题
猜你喜欢

Leetcdoe 2037. Make each student have the minimum number of seat movements (yes, once)

蓝桥杯2015年CA省赛(填坑中)

Leetcode 2169. 得到 0 的操作数

M-arch (fanwai 11) gd32l233 evaluation PWM driven active buzzer

A hundred secrets and a few secrets - Caesar encryption

模块8作业

读mysql45讲-自我总结(部分)

The most detailed explanation of the top ten levels of sqli labs platform

How to refund the pre-sale deposit of JD 618 in 2022? Can JD 618 deposit be refunded?

浅谈调和形状上下文特征HSC对3DSC的改进
随机推荐
scanf返回值被忽略的原因及其解决方法
Malicious code analysis practice - use IDA pro to analyze lab05-01 dll
XML Parsing Error: mismatched tag. Expected
k52.第一章 基于kubeadm安装kubernetes v1.22 -- 集群部署
B+ 树的简单认识
元宇宙链游与传统游戏的区别
MYSQL——内置函数
M-arch (fanwai 12) gd32l233 evaluation -cau encryption and decryption (tease Xiaobian)
浅谈三维形状上下文特征3DSC理论及应用
AcWing 1995. 见面与问候(模拟)
Find the location of a function in PHP
CTF freshman cup PHP deserialization question - EzPop
Module 8 job
PHP uses leanclound to save associated properties
2022-06-11:注意本文件中,graph不是邻接矩阵的含义,而是一个二部图。 在长度为N的邻接矩阵matrix中,所有的点有N个,matrix[i][j]
file_ get_ Contents() JSON after reading_ Decode cannot be converted to array
Malicious code analysis practice - lab06-01 exe~Lab06-04. Exe dynamic analysis
k53.第二章 基于二进制包安装kubernetes v1.22 --集群部署
Get all listening events in the element
Principle analysis of vite HMR