CN113468213A - Dynamic data source switching method and system based on multi-data source configuration - Google Patents

Dynamic data source switching method and system based on multi-data source configuration Download PDF

Info

Publication number
CN113468213A
CN113468213A CN202110834760.2A CN202110834760A CN113468213A CN 113468213 A CN113468213 A CN 113468213A CN 202110834760 A CN202110834760 A CN 202110834760A CN 113468213 A CN113468213 A CN 113468213A
Authority
CN
China
Prior art keywords
utf8
data source
null
database
configuration
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110834760.2A
Other languages
Chinese (zh)
Inventor
王启志
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yi Tai Fei Liu Information Technology LLC
Original Assignee
Yi Tai Fei Liu Information Technology LLC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yi Tai Fei Liu Information Technology LLC filed Critical Yi Tai Fei Liu Information Technology LLC
Priority to CN202110834760.2A priority Critical patent/CN113468213A/en
Publication of CN113468213A publication Critical patent/CN113468213A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method and a system for dynamically switching data sources based on multi-data source configuration, wherein a target database is established and target data is initialized; modifying the configuration file, customizing the configuration items, and controlling the opening and closing of the configuration of multiple data sources; and dynamically switching the data source according to the set configuration file. When facing multiple data sources, the invention can write a config class of mybatis for each data source respectively, so that each DataSource has a Session factory only belonging to itself, thus finding out the corresponding mybases instance according to the mapping directory of each mapper (dao), the specific data source switching is to select the needed data source by the self-defined annotation in the service layer, and to switch the data source needed to be used by the MultiSource ExAop class.

Description

Dynamic data source switching method and system based on multi-data source configuration
Technical Field
The invention relates to the technical field of data sources, in particular to a dynamic data source switching method based on multi-data source configuration.
Background
Because the requirement of accessing data of different data sources for display is frequently met in a project, the technical scheme of the invention mainly utilizes springboot to configure a plurality of data sources, writes data switching classes and creates a tangent plane to realize automatic switching of the data sources, thereby realizing configuration of a plurality of data sources in one project and automatically switching the data sources to carry out application and display of the data according to the requirement of the project.
Disclosure of Invention
In view of the above-mentioned shortcomings of the prior art, the present invention is directed to a method for dynamically switching data sources based on multiple data source configurations, which solves the problems of the prior art.
To achieve the above and other related objects, the present invention provides a method for dynamically switching data sources based on multiple data source configurations, comprising the following steps:
creating a target database and initializing the target data; wherein, the target database comprises: a ztmldb database, a jcmldb database;
modifying the configuration file, customizing the configuration items, and controlling the opening and closing of the configuration of multiple data sources;
and dynamically switching the data source according to the set configuration file.
Optionally, creating the ztmldb database, initializing the ztmldb database, creating a new t _ user table, and importing test data; the method comprises the following steps:
Figure BDA0003179049390000011
Figure BDA0003179049390000021
optionally, creating and initializing a jcmldb database, creating a new tb _ user01 table and importing test data; the method comprises the following steps:
Figure BDA0003179049390000022
Figure BDA0003179049390000031
optionally, modifying the configuration file, customizing the configuration item, and controlling the opening and closing of the configuration of multiple data sources; the method comprises the following steps:
modifying the configuration file and customizing a configuration item muti-database-open;
flypig:
whether muti-datasource-open is the multiple data source (true/false)
Adding connection information of a MySQL database as a test data source of multiple data sources as follows;
Figure BDA0003179049390000032
Figure BDA0003179049390000041
optionally, dynamically switching the data source according to the set configuration file includes:
determining constant classes of multiple data sources;
storing the data source type of the current thread by using the context of the datasource;
defining a dynamic data source and inheriting AbsstractRoutengingDataSource;
determining which data source the annotation uses on a Service method from a predefined annotation;
defining core AOP type, and realizing dynamic switching of data source by Spring AOP technology.
The invention also provides a dynamic data source switching system based on multi-data source configuration, which comprises:
the database module is used for creating a target database and initializing the target data; wherein, the target database comprises: a ztmldb database, a jcmldb database;
the configuration module is used for modifying the configuration file, customizing the configuration item and controlling the opening and closing of the configuration of the multiple data sources;
and the switching module is used for dynamically switching the data source according to the set configuration file.
Optionally, the process of creating the ztmldb database and initializing the ztmldb database by the configuration module, and creating a new t _ user table and importing test data by the configuration module includes:
Figure BDA0003179049390000042
Figure BDA0003179049390000051
Figure BDA0003179049390000061
optionally, the process of creating and initializing a jcmldb database and creating a new tb _ user01 table and importing test data by the configuration module includes:
Figure BDA0003179049390000062
optionally, the configuration module modifies the configuration file and customizes the configuration item, and the process of controlling the opening and closing of the configuration of multiple data sources includes:
modifying the configuration file and customizing a configuration item muti-database-open;
flypig:
whether muti-datasource-open is the multiple data source (true/false)
Adding connection information of a MySQL database as a test data source of multiple data sources as follows;
Figure BDA0003179049390000063
Figure BDA0003179049390000071
optionally, the process of dynamically switching the data source by the switching module according to the set configuration file includes:
determining constant classes of multiple data sources;
storing the data source type of the current thread by using the context of the datasource;
defining a dynamic data source and inheriting AbsstractRoutengingDataSource;
determining which data source the annotation uses on a Service system according to predefined annotations;
defining core AOP type, and realizing dynamic switching of data source by Spring AOP technology.
As described above, the present invention provides a method and a system for dynamically switching data sources based on multiple data source configurations, which have the following advantages:
the invention provides a method for performing static multi-data source configuration and dynamically switching multi-data sources by using springboots and mybases, which can write a config class of mybases for each data source when facing multi-data sources, so that each DataSource has a Session factory only belonging to the DataSource, and thus, a corresponding mybases instance can be found according to respective mapper (dao) mapping directories, the specific data source switching is to select a needed data source through self-defined annotations on a service layer, and to switch the data source needed to be used through the MultiSource Aop class.
Drawings
Fig. 1 is a flowchart illustrating a method for dynamically switching data sources based on multiple data source configurations according to an embodiment.
Detailed Description
The embodiments of the present invention are described below with reference to specific embodiments, and other advantages and effects of the present invention will be easily understood by those skilled in the art from the disclosure of the present specification. The invention is capable of other and different embodiments and of being practiced or of being carried out in various ways, and its several details are capable of modification in various respects, all without departing from the spirit and scope of the present invention. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present invention, and the components related to the present invention are only shown in the drawings rather than drawn according to the number, shape and size of the components in actual implementation, and the type, quantity and proportion of the components in actual implementation may be changed freely, and the layout of the components may be more complicated.
Referring to fig. 1, the present invention provides a method for dynamically switching data sources based on multiple data source configurations, including the following steps:
s100, creating a target database and initializing the target data; wherein, the target database comprises: a ztmldb database, a jcmldb database;
s200, modifying the configuration file, customizing the configuration item, and controlling the opening and closing of the configuration of multiple data sources;
and S300, dynamically switching data sources according to the set configuration file.
The invention provides a method for performing static multi-data source configuration and dynamically switching multi-data sources by using springboots and mybases, which can write a config class of mybases for each data source when facing multi-data sources, so that each DataSource has a Session factory only belonging to the DataSource, and thus, a corresponding mybases instance can be found according to respective mapper (dao) mapping directories, the specific data source switching is to select a needed data source through self-defined annotations on a service layer, and to switch the data source needed to be used through the MultiSource Aop class.
According to the above description, in an exemplary embodiment, the ztmldb database is created and initialized, and a t _ user table is newly created and test data is imported; the method comprises the following steps:
Figure BDA0003179049390000091
Figure BDA0003179049390000101
according to the above description, in an exemplary embodiment, a jcmldb database is created and initialized, a tb _ user01 table is newly created and test data is imported; the method comprises the following steps:
Figure BDA0003179049390000102
optionally, modifying the configuration file, customizing the configuration item, and controlling the opening and closing of the configuration of multiple data sources; the method comprises the following steps:
modifying the configuration file and customizing a configuration item muti-database-open;
flypig:
whether muti-datasource-open is the multiple data source (true/false)
Adding connection information of a MySQL database as a test data source of multiple data sources as follows;
Figure BDA0003179049390000111
according to the above description, in an exemplary embodiment, dynamically switching data sources according to a set profile includes:
determining constant classes of multiple data sources;
public interface DSEnum{
String DATA_SOURCE_CENTER="dataSourceCenter";
String DATA_SOURCE_ORACLE="dataSourceOracle";
}
storing the data source type of the current thread by using the context of the datasource;
Figure BDA0003179049390000121
Figure BDA0003179049390000132
defining a dynamic data source and inheriting AbsstractRoutengingDataSource;
Figure BDA0003179049390000131
determining which data source the annotation uses on a Service method from a predefined annotation; by way of example, for example, an annotation is customized to annotate which data source is used on the Service method, here, the selection of the required data source is realized by the customized @ DataSource annotation, and the code is as follows:
@DataSource(name=DSEnum.DATA_SOURCE_BMML)
public int getBMMLLDetailCount(String tablename){
return depMenuDao.getDetailCount(tablename);
}
@DataSource(name=DSEnum.DATA_SOURCE_JCML)
public int getJCMLDetailCount(String tablename){
return depMenuDao.getDetailCount(tablename);
}
@DataSource(name=DSEnum.DATA_SOURCE_ZTML)
public int getZTMLDetailCount(String tablename){
return depMenuDao.getDetailCount(tablename);
}
defining core AOP type, and realizing dynamic switching of data source by Spring AOP technology.
Figure BDA0003179049390000141
Figure BDA0003179049390000151
Figure BDA0003179049390000161
The annotation @ conditional on property is used here, and will only take effect if the muti-database-open in the configuration file is true. It should be noted that the order of aop must be set to 1 before the spring transaction, and the sequence of the spring transaction is set to 2.
And (4) defining the configuration class, writing a config class of mybatis for each data source respectively, and ending the process.
Figure BDA0003179049390000171
Figure BDA0003179049390000181
Figure BDA0003179049390000191
According to the above description, in an embodiment, the present invention provides a method for performing static multi-data source configuration and dynamically switching multi-data sources based on springboot, mybatis and drive, including the following steps:
step 1: testing the tb _ user01 table in the jcmldb database, and counting the data in the table according to the following processing method;
acquiring data in the table tb _ user01, wherein the total number of the data is 15; the table tb _ user01 is shown in Table 1.
Tb _ user01 Table data in the jcmldb database of Table 1
Figure BDA0003179049390000192
Figure BDA0003179049390000201
The simulation, with a POSTMAN request, needs to obtain the number of pieces of data in the jcmldb.tb _ user01 table, and the result is as follows:
parameters are as follows:
Figure BDA0003179049390000202
and (3) obtaining a result:
15
the result of printing the springboot background log is as follows:
2021-02-19 09:31:40.252 INFO 22304---[restartedMain]cn.com.jetflow.flypig.FlypigApplication:Started FlypigApplication in 28.311seconds(JVM running for 31.163)
2021-02-19 09:31:40.252 INFO 22304---[restartedMain]cn.com.jetflow.flypig.FlypigApplication:FlypigApplication is success!
2021-02-19 09:35:55.639 INFO 22304---[io-18081-exec-1]o.a.c.c.C.[Tomcat].[localhost].[/api]:Initializing Spring FrameworkServlet'dispatcherServlet'
2021-02-19 09:35:55.640 INFO 22304---[io-18081-exec-1]o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':initialization started
2021-02-19 09:35:55.728 INFO 22304---[io-18081-exec-1]o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':initialization completed in 88ms
database:jcmldb
jcmldb library tb _ user01 shows the number of detail data: 15.
step 2: testing a t _ user table in a ztmldb database, mainly counting the number of data in the table, and processing the data according to the following method;
acquiring data in a t _ user table, wherein 2 data are obtained; the t _ user table is shown in table 2.
Figure BDA0003179049390000211
The simulation, with a post mn request, needs to obtain the number of pieces of data in ztmldb.t _ user table, with the following results:
parameters are as follows:
Figure BDA0003179049390000212
and (3) obtaining a result:
2
the result of printing the springboot background log is as follows:
2021-02-19 09:31:40.252 INFO 22304---[restartedMain]cn.com.jetflow.flypig.FlypigApplication:FlypigApplication is success!
2021-02-19 09:35:55.639 INFO 22304---[io-18081-exec-1]o.a.c.c.C.[Tomcat].[localhost].[/api]:Initializing Spring FrameworkServlet'dispatcherServlet'
2021-02-19 09:35:55.640 INFO 22304---[io-18081-exec-1]o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':initialization started
2021-02-19 09:35:55.728 INFO 22304---[io-18081-exec-1]o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':initialization completed in 88 ms
database:jcmldb
jcmldb library tb _ user01 shows the number of detail data: 15
database:ztmldb
Number of detailed data of ztmldb library t _ user table: 2
The technical problem solved by the invention is to provide a method for configuring multiple data sources by using springboot, mybatis and draid and dynamically switching multiple data sources. When facing multiple data sources, the method can write a config class of mybatis for each data source respectively, so that each DataSource has a sessionFactory only belonging to the DataSource, and accordingly, a corresponding mybases instance can be found according to a mapper (dao) mapping directory of each DataSource, the specific data source switching is to select a required data source through a self-defined annotation in a service layer, and to switch the data source required to be used through a MultiSource ExAop class.
The invention also provides a dynamic data source switching system based on multi-data source configuration, which comprises:
the database module is used for creating a target database and initializing the target data; wherein, the target database comprises: a ztmldb database, a jcmldb database;
the configuration module is used for modifying the configuration file, customizing the configuration item and controlling the opening and closing of the configuration of the multiple data sources;
and the switching module is used for dynamically switching the data source according to the set configuration file.
According to the above description, in an exemplary embodiment, the process of the configuration module creating the ztmldb database, initializing the ztmldb database, creating a new t _ user table, and importing test data includes:
Figure BDA0003179049390000231
Figure BDA0003179049390000241
according to the above description, in an exemplary embodiment, the process of creating and initializing the jcmldb database and creating and importing the tb _ user01 table includes:
Figure BDA0003179049390000242
Figure BDA0003179049390000251
according to the above description, in an exemplary embodiment, the process of controlling the opening and closing of the configuration of multiple data sources by the configuration module modifying the configuration file and customizing the configuration item includes:
modifying the configuration file and customizing a configuration item muti-database-open;
flypig:
whether muti-datasource-open is the multiple data source (true/false)
Adding connection information of a MySQL database as a test data source of multiple data sources as follows;
Figure BDA0003179049390000252
according to the above description, in an exemplary embodiment, the process of dynamically switching the data source according to the configured configuration file by the switching module includes:
determining constant classes of multiple data sources;
storing the data source type of the current thread by using the context of the datasource;
defining a dynamic data source and inheriting AbsstractRoutengingDataSource;
determining which data source the annotation uses on a Service system according to predefined annotations;
defining core AOP type, and realizing dynamic switching of data source by Spring AOP technology.
According to the above description, in a specific embodiment, the present invention provides a system for performing static multi-data source configuration and dynamically switching multi-data sources based on springboot, mybatis and drive, which is used to execute the above method, and the embodiments of the present invention are not described in detail herein.
The technical problem solved by the invention is to provide a system for configuring multiple data sources by using springboot, mybatis and draid and dynamically switching multiple data sources. When facing multiple data sources, the system can write a config class of mybatis for each data source respectively, so that each DataSource has a Session factory only belonging to the DataSource, and a corresponding mybases instance can be found according to respective mapper (dao) mapping directories, and the specific data source switching is to select a required data source through self-defined annotation in a service layer and switch the data source required to be used through a MultiSource ExAop class.
The foregoing embodiments are merely illustrative of the principles and utilities of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or change the above-mentioned embodiments without departing from the spirit and scope of the present invention. Accordingly, it is intended that all equivalent modifications or changes which can be made by those skilled in the art without departing from the spirit and technical spirit of the present invention be covered by the claims of the present invention.

Claims (10)

1. A method for dynamically switching data sources based on multi-data source configuration is characterized by comprising the following steps:
creating a target database and initializing the target data; wherein, the target database comprises: a ztmldb database, a jcmldb database;
modifying the configuration file, customizing the configuration items, and controlling the opening and closing of the configuration of multiple data sources;
and dynamically switching the data source according to the set configuration file.
2. The method for dynamically switching data sources based on multiple data source configurations of claim 1, wherein the ztmldb database is created and initialized, and a t _ user table is created and test data is imported; the method comprises the following steps:
CREATE DATABASE IF NOT EXISTS ztmldb default charset utf8 COLLATE utf8_general_ci;
SET FOREIGN_KEY_CHECKS=0;
USE ztmldb;
DROP TABLE IF EXISTS`t_user`;
CREATE TABLE`t_user`(
'ID' int (11) NOT NULL AUTO _ INCREMENT COMMENT 'primary key ID',
"username" varchar (32) CHARACTER SET utf8COLLATE utf8_ general _ ci NOT NULL COMMENT 'Account',
"name" varchar (16) CHARACTER SET utf8COLLATE utf8_ general _ ci NULL DEFAULT "COMMENT' name",
"passsword 'varchar (128) CHARACTER SET utf8COLLATE utf8_ general _ ci NULL DEFAULT" COMMENT's password,
"salt" varchar (64) CHARACTER SET utf8 cold ute utf8_ general _ ci NULL DEFAULT "common' md5 cryptographic salt",
"phone 'varchar (32) CHARACTER SET utf8 cold ute utf8_ general _ ci NULL DEFAULT" communent' contact phone ",
"tips" varchar (255) CHARACTER SET utf8COLLATE utf8_ general _ ci NULL DEFAULT NULL COMMENT' remarks,
state 'tinyint (1) NULL DEFAULT 1 common' state 1: and 2, normal: the combination of the following is forbidden',
"created _ time" data time (0) NULL DEFAULT CURRENT _ TIMESTAMP COMMENT 'creation time',
"updated _ time (0) NULL DEFAULT CURRENT _ TIMESTAMP ON UPDATE CURRENT _ TIMESTAMP (0) COMMENT 'update time',
PRIMARY KEY(`id`)USING BTREE
) The "new _ FORMAT" table of the background management user "includes an" InnoDB AUTO _ INCREMENT "table of 3CHARACTER SET, an" utf8 cold "table of utf8, a" general _ ci "table of the background management user" Dynamic.
3. The method for dynamically switching data sources based on multiple data source configurations of claim 1, wherein a jcmldb database is created and initialized, a tb _ user01 table is created and test data is imported; the method comprises the following steps:
CREATE DATABASE IF NOT EXISTS jcmldb default charset utf8 COLLATE utf8_general_ci;
SET FOREIGN_KEY_CHECKS=0;
USE jcmldb;
DROP TABLE IF EXISTS`tb_user01`;
CREATE TABLE`tb_user01`(
`id`int(11)NOT NULL,
`name`varchar(255)CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex`int(11)NULL DEFAULT NULL,
`age`decimal(8,2)NULL DEFAULT NULL,
`data_time`datetime(0)NULL DEFAULT NULL,
PRIMARY KEY(`id`)USING BTREE
)ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=Dynamic;
SET FOREIGN_KEY_CHECKS=1。
4. the method for dynamically switching data sources based on multiple data source configurations of claim 1, wherein configuration files are modified, configuration items are customized, and the opening and closing of multiple data source configurations are controlled; the method comprises the following steps:
modifying the configuration file and customizing a configuration item muti-database-open;
flypig:
whether muti-datasource-open is the multiple data source (true/false)
Adding connection information of a MySQL database as a test data source of multiple data sources as follows;
spring:
profiles:produce
datasource:
slaveztml:
url:
jdbc:mysql://10.194.22.160:3306/ztmldbuseSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
username:root
password:U_tywg_2013
type:com.alibaba.druid.pool.DruidDataSource
slavejcml:
url:
jdbc:mysql://10.194.22.160:3306/jcmldbuseSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
username:root
password:U_tywg_2013
type:com.alibaba.druid.pool.DruidDataSource。
5. the method for dynamically switching data sources based on multiple data source configurations of claim 1, wherein dynamically switching data sources according to a configured configuration file comprises:
determining constant classes of multiple data sources;
storing the data source type of the current thread by using the context of the datasource;
defining a dynamic data source and inheriting AbsstractRoutengingDataSource;
determining which data source the annotation uses on a Service method from a predefined annotation;
defining core AOP type, and realizing dynamic switching of data source by Spring AOP technology.
6. A dynamic switching data source system based on multi-data source configuration is characterized by comprising:
the database module is used for creating a target database and initializing the target data; wherein, the target database comprises: a ztmldb database, a jcmldb database;
the configuration module is used for modifying the configuration file, customizing the configuration item and controlling the opening and closing of the configuration of the multiple data sources;
and the switching module is used for dynamically switching the data source according to the set configuration file.
7. The system of claim 6, wherein the configuration module creates the ztmldb database and initializes the ztmldb database, and the process of creating the t _ user table and importing the test data comprises:
CREATE DATABASE IF NOT EXISTS ztmldb default charset utf8 COLLATE utf8_general_ci;
SET FOREIGN_KEY_CHECKS=0;
USE ztmldb;
DROP TABLE IF EXISTS`t_user`;
CREATE TABLE`t_user`(
'ID' int (11) NOT NULL AUTO _ INCREMENT COMMENT 'primary key ID',
"username" varchar (32) CHARACTER SET utf8COLLATE utf8_ general _ ci NOT NULL COMMENT 'Account',
"name" varchar (16) CHARACTER SET utf8COLLATE utf8_ general _ ci NULL DEFAULT "COMMENT' name",
"passsword 'varchar (128) CHARACTER SET utf8COLLATE utf8_ general _ ci NULL DEFAULT" COMMENT's password,
"salt" varchar (64) CHARACTER SET utf8 cold ute utf8_ general _ ci NULL DEFAULT "common' md5 cryptographic salt",
"phone 'varchar (32) CHARACTER SET utf8 cold ute utf8_ general _ ci NULL DEFAULT" communent' contact phone ",
"tips" varchar (255) CHARACTER SET utf8COLLATE utf8_ general _ ci NULL DEFAULT NULL COMMENT' remarks,
state 'tinyint (1) NULL DEFAULT 1 common' state 1: and 2, normal: the combination of the following is forbidden',
"created _ time" data time (0) NULL DEFAULT CURRENT _ TIMESTAMP COMMENT 'creation time',
"updated _ time (0) NULL DEFAULT CURRENT _ TIMESTAMP ON UPDATE CURRENT _ TIMESTAMP (0) COMMENT 'update time',
PRIMARY KEY(`id`)USING BTREE
) The "new _ FORMAT" table of the background management user "includes an" InnoDB AUTO _ INCREMENT "table of 3CHARACTER SET, an" utf8 cold "table of utf8, a" general _ ci "table of the background management user" Dynamic.
8. The system of claim 6, wherein the configuration module creates a jcmldb database and initializes the jcmldb database, and the process of creating a tb _ user01 table and importing test data comprises:
CREATE DATABASE IF NOT EXISTS jcmldb default charset utf8 COLLATE utf8_general_ci;
SET FOREIGN_KEY_CHECKS=0;
USE jcmldb;
DROP TABLE IF EXISTS`tb_user01`;
CREATE TABLE`tb_user01`(
`id`int(11)NOT NULL,
`name`varchar(255)CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex`int(11)NULL DEFAULT NULL,
`age`decimal(8,2)NULL DEFAULT NULL,
`data_time`datetime(0)NULL DEFAULT NULL,
PRIMARY KEY(`id`)USING BTREE
)ENGINE=InnoDB CHARACTER SET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=Dynamic;
SET FOREIGN_KEY_CHECKS=1。
9. the system of claim 6, wherein the configuration module modifies configuration files and customizes configuration items, and the process of controlling the on/off of the configuration of multiple data sources comprises:
modifying the configuration file and customizing a configuration item muti-database-open;
flypig:
whether muti-datasource-open is the multiple data source (true/false)
Adding connection information of a MySQL database as a test data source of multiple data sources as follows;
spring:
profiles:produce
datasource:
slaveztml:
url:
jdbc:mysql://10.194.22.160:3306/ztmldbuseSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
username:root
password:U_tywg_2013
type:com.alibaba.druid.pool.DruidDataSource
slavejcml:
url:
jdbc:mysql://10.194.22.160:3306/jcmldbuseSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
username:root
password:U_tywg_2013
type:com.alibaba.druid.pool.DruidDataSource。
10. the system of claim 6, wherein the switching module dynamically switches the data sources according to the configured configuration file comprises:
determining constant classes of multiple data sources;
storing the data source type of the current thread by using the context of the datasource;
defining a dynamic data source and inheriting AbsstractRoutengingDataSource;
determining which data source the annotation uses on a Service system according to predefined annotations;
defining core AOP type, and realizing dynamic switching of data source by Spring AOP technology.
CN202110834760.2A 2021-07-26 2021-07-26 Dynamic data source switching method and system based on multi-data source configuration Pending CN113468213A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110834760.2A CN113468213A (en) 2021-07-26 2021-07-26 Dynamic data source switching method and system based on multi-data source configuration

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110834760.2A CN113468213A (en) 2021-07-26 2021-07-26 Dynamic data source switching method and system based on multi-data source configuration

Publications (1)

Publication Number Publication Date
CN113468213A true CN113468213A (en) 2021-10-01

Family

ID=77882095

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110834760.2A Pending CN113468213A (en) 2021-07-26 2021-07-26 Dynamic data source switching method and system based on multi-data source configuration

Country Status (1)

Country Link
CN (1) CN113468213A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110727438A (en) * 2019-09-11 2020-01-24 宝付网络科技(上海)有限公司 Automatic web system generation tool based on SpringBoot
CN110825369A (en) * 2019-11-07 2020-02-21 四川长虹电器股份有限公司 Method for automatically generating codes based on java language
CN111078801A (en) * 2019-12-28 2020-04-28 安徽微沃信息科技股份有限公司 Bidirectional synchronous data system between double data sources
CN112612818A (en) * 2020-12-21 2021-04-06 贝壳技术有限公司 Data processing method and device, computing equipment and storage medium
CN113110885A (en) * 2019-12-25 2021-07-13 深圳市华胜软件技术有限公司 Method for connecting application software with database, storage medium and terminal equipment
CN113127102A (en) * 2021-05-18 2021-07-16 中国农业银行股份有限公司 Method, device, equipment, storage medium and program for processing service data

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110727438A (en) * 2019-09-11 2020-01-24 宝付网络科技(上海)有限公司 Automatic web system generation tool based on SpringBoot
CN110825369A (en) * 2019-11-07 2020-02-21 四川长虹电器股份有限公司 Method for automatically generating codes based on java language
CN113110885A (en) * 2019-12-25 2021-07-13 深圳市华胜软件技术有限公司 Method for connecting application software with database, storage medium and terminal equipment
CN111078801A (en) * 2019-12-28 2020-04-28 安徽微沃信息科技股份有限公司 Bidirectional synchronous data system between double data sources
CN112612818A (en) * 2020-12-21 2021-04-06 贝壳技术有限公司 Data processing method and device, computing equipment and storage medium
CN113127102A (en) * 2021-05-18 2021-07-16 中国农业银行股份有限公司 Method, device, equipment, storage medium and program for processing service data

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
我行其野&芃芃其麦: "Springboot整合Mybatis实现多数据源动态切换", 《HTTPS://BLOG.CSDN.NET/HONGER_HUA/ARTICLE/DETAILS/102463401》, pages 2 - 3 *
汪卫兵;: "多商户系统多个数据库的访问设计和实现", 数码世界, no. 05, pages 83 *

Similar Documents

Publication Publication Date Title
US20210026613A1 (en) Data model api for live applications in a cloud collaboration platform
US7752165B2 (en) Persistent query system for automatic on-demand data subscriptions from mobile devices
US10740093B2 (en) Advanced packaging techniques for improving work flows
US8219919B2 (en) Method for automating construction of the flow of data driven applications in an entity model
US8566732B2 (en) Synchronization of widgets and dashboards
US6366954B1 (en) Method and data format for exchanging data between a Java system database entry and an LDAP directory service
US8782605B2 (en) Methods and systems for presenting different versions of an application
US20100058332A1 (en) Systems and methods for provisioning machines having virtual storage resources
US9727593B2 (en) Database element versioning system and method
CN112930529B (en) Generating software artifacts from conceptual data models
JP2003044473A (en) Internet presentation system and method, and projector
Martí et al. Dataclay: A distributed data store for effective inter-player data sharing
CN110321337A (en) A kind of method and computer readable storage medium for realizing Database Dynamic switching
JP2008234673A (en) System and method for managing application installation for mobile device
US20050066155A1 (en) Utility for configuring and verifying data sources
US20170351506A1 (en) Automating feature graduation
US8521875B2 (en) Identity for data sources
US7213039B2 (en) Synchronizing differing data formats
US11216482B2 (en) Systems and methods for access to multi-tenant heterogeneous databases
CN109271211A (en) Method, apparatus of attending to anything else, equipment and the medium of application program
US10248668B2 (en) Mapping database structure to software
CN107844519A (en) Electronic installation, data base querying scenario generation method and storage medium
US20060041575A1 (en) Method and system for object linking
US7739232B2 (en) Programming system for occasionally-connected mobile business applications
CN113468213A (en) Dynamic data source switching method and system based on multi-data source configuration

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination