Method and device for obtaining database data
Through the database link manager and single -process thread mechanism, the problem of resource consumption and efficiency when obtaining data from multiple databases, and realizing efficient data acquisition and processing.
Patent Information
- Application Number
- CN202111355902.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-16
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2041-11-16
AI Technical Summary
When obtaining data from multiple databases in the prior art, the database agent only supports isomorphic databases. The multi-process method increases resource consumption and business processing time and reduces efficiency.
Through the database link manager to manage the database link, create a thread with link to the database link, and perform database access operations in the single process to avoid multi -process data interaction.
Reduce data acquisition and processing complexity, reduce resource consumption and business processing time, and improve the efficiency of data acquisition and processing.
Smart Images

Figure CN114090626B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database applications, and in particular to a method and device for acquiring database data. Background Art
[0002] In some complex business scenarios, an application needs to obtain data from multiple databases. Currently, there are two ways to obtain data from multiple databases:
[0003] 1. Use database proxy to enable applications to obtain data from multiple databases.
[0004] 2. Split the application into multiple processes, each process connects to a database, and obtains data from multiple databases in a multi-process manner.
[0005] However, in the above method 1, the database proxy only supports obtaining data from multiple homogeneous databases, and cannot obtain data from multiple heterogeneous databases; in the above method 2, the multi-process approach increases the application's consumption of resources such as CPU and memory, and the multi-process approach requires data to be processed through data interaction between multiple processes, which occupies application computing resources and reduces business processing efficiency. Summary of the invention
[0006] The embodiment of the present invention provides a method and device for acquiring database data, which are used to avoid accessing the database in a multi-process manner, reduce the complexity of data acquisition and processing, and increase the efficiency of data acquisition and processing.
[0007] In a first aspect, an embodiment of the present invention provides a method for obtaining database data, comprising:
[0008] For a database access operation during the running process of the application, determine a unique identifier of a database to be accessed corresponding to the database access operation;
[0009] Matching the database link of the database to be accessed from the database link manager according to the unique identifier of the database to be accessed; each database link in the database link manager is obtained after the application is started and a connection is established with each database according to the configuration information of each database;
[0010] A thread having a database link of the database to be accessed is created in the process, and the database access operation is performed based on the thread; wherein each database access operation in the application is completed through each thread in the process.
[0011] In the above technical solution, by matching the database link of the database to be accessed from the database link manager and creating a thread with the database link of the database to be accessed in the process, for multiple database access operations, the database access is completed through the thread under the same process; thereby avoiding the increase in the consumption of CPU, memory and other resources by the application due to multiple processes, and because data is obtained from multiple databases only through the thread under one process, the business processing time increased by data interaction between multiple processes can be avoided, thereby reducing the complexity of data acquisition and processing and increasing the efficiency of data acquisition and processing.
[0012] Optionally, the database access operation includes a unique identifier of the first database to be accessed and a unique identifier of the second database to be accessed;
[0013] Creating a thread having a database link of the database to be accessed in the process includes:
[0014] Creating a first thread having a database link of the first database to be accessed in the process;
[0015] A second thread having a database link of the second database to be accessed is created in the process.
[0016] In the above technical solution, according to the pre-set database link, the first thread and the second thread are created for the first database to be accessed and the second database to be accessed respectively, so that multiple threads under one process can obtain data from multiple databases, which can avoid the business processing time increased by data interaction between multiple processes, reduce the complexity of data acquisition and processing, and increase the efficiency of data acquisition and processing.
[0017] Optionally, the database access operation includes a unique identifier of the first database to be accessed and a unique identifier of the second database to be accessed;
[0018] Creating a thread having a database link of the database to be accessed in the process includes:
[0019] Creating a thread having a database link of the first database to be accessed in the process;
[0020] Executing the database access operation based on the thread includes:
[0021] Based on the thread, executing a database access operation on the first database to be accessed;
[0022] After executing the database access operation for the first database to be accessed, the database link in the thread is set as the database link of the second database to be accessed, and based on the thread, the database access operation for the second database to be accessed is executed.
[0023] In the above technical solution, according to the pre-set database link, in order, a thread with a database link of a database to be accessed is first created for a database to be accessed, and then the thread is updated for another database to be accessed, so that one thread can obtain data from multiple databases, which can avoid the business processing time increased by data interaction between multiple processes, reduce the complexity of data acquisition and processing, and increase the efficiency of data acquisition and processing.
[0024] Optionally, each database link in the database link manager is obtained after the application is started and a connection is established with each database according to each database configuration information, including:
[0025] For any database configuration, after the application is started, a connection is established with the corresponding database according to the database configuration information through a database link manager to obtain a database link of the database;
[0026] The unique identifier of each database and the database link of each database are correspondingly stored in the database link manager.
[0027] Optionally, storing the unique identifier of each database and the database link of each database in the database link manager in correspondence includes:
[0028] For any database, the unique identifier of the database is used as the key, and the database link of the database is used as the value, and the database is stored in the database link manager in the form of a map data structure.
[0029] Optionally, if a new database is involved in the application, a database link of the new database is determined according to database configuration information of the new database, and the database link of the new database is stored;
[0030] If the application involves deleting a database, the configuration information and database link of the database to be deleted are deleted according to the unique identifier of the database to be deleted;
[0031] After storing the newly added database link or deleting the configuration information and database link of the to-be-deleted database, the database link manager is updated.
[0032] In the above technical solution, any database link is pre-established, and each database link is managed by a database link manager to dynamically add or delete database links, thereby increasing the flexibility of managing each database link and improving the scalability of database link management.
[0033] Optionally, creating a thread having a database link of the database to be accessed in the process includes:
[0034] A thread is created in the process, and the database link of the database to be accessed is written into the TreadLocal of the thread.
[0035] In a second aspect, an embodiment of the present invention provides a device for acquiring database data, including:
[0036] An analysis module, for determining a unique identifier of a database to be accessed corresponding to a database access operation during the running process of an application process;
[0037] A matching module, used for matching the database link of the database to be accessed from the database link manager according to the unique identifier of the database to be accessed; each database link in the database link manager is obtained after the application is started and a connection is established with each database according to the configuration information of each database;
[0038] A processing module is used to create a thread with a database link of the database to be accessed in the process, and perform the database access operation based on the thread; wherein each database access operation in the application is completed through each thread in the process.
[0039] Optionally, the database access operation includes a unique identifier of the first database to be accessed and a unique identifier of the second database to be accessed;
[0040] The processing module is specifically used for:
[0041] Creating a first thread having a database link of the first database to be accessed in the process;
[0042] A second thread having a database link of the second database to be accessed is created in the process.
[0043] Optionally, the database access operation includes a unique identifier of the first database to be accessed and a unique identifier of the second database to be accessed;
[0044] The processing module is specifically used for:
[0045] Creating a thread having a database link of the first database to be accessed in the process;
[0046] Based on the thread, executing a database access operation on the first database to be accessed;
[0047] After executing the database access operation for the first database to be accessed, the database link in the thread is set as the database link of the second database to be accessed, and based on the thread, the database access operation for the second database to be accessed is executed.
[0048] Optionally, the processing module is specifically used for:
[0049] For any database configuration, after the application is started, a connection is established with the corresponding database according to the database configuration information through a database link manager to obtain a database link of the database;
[0050] The unique identifier of each database and the database link of each database are correspondingly stored in the database link manager.
[0051] Optionally, the processing module is specifically used for:
[0052] For any database, the unique identifier of the database is used as the key, and the database link of the database is used as the value, and the database is stored in the database link manager in the form of a map data structure.
[0053] Optionally, the processing module is specifically used for:
[0054] If a new database is involved in the application, a database link of the new database is determined according to database configuration information of the new database, and the database link of the new database is stored;
[0055] If the application involves deleting a database, the configuration information and database link of the database to be deleted are deleted according to the unique identifier of the database to be deleted;
[0056] After storing the newly added database link or deleting the configuration information and database link of the to-be-deleted database, the database link manager is updated.
[0057] Optionally, the processing module is specifically used for:
[0058] A thread is created in the process, and the database link of the database to be accessed is written into the TreadLocal of the thread.
[0059] In a third aspect, an embodiment of the present invention further provides a computer device, including:
[0060] A memory for storing program instructions;
[0061] The processor is used to call the program instructions stored in the memory and execute the above method for obtaining database data according to the obtained program.
[0062] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above-mentioned method for obtaining database data. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0064] Figure 1 A schematic diagram of obtaining data in a database proxy manner provided by an embodiment of the present invention;
[0065] Figure 2 A schematic diagram of acquiring data in a multi-process manner provided by an embodiment of the present invention;
[0066] Figure 3 A schematic diagram of a system architecture provided for an embodiment of the present invention;
[0067] Figure 4 A flowchart of a method for obtaining database data provided by an embodiment of the present invention;
[0068] Figure 5 A schematic diagram of a database link manager provided by an embodiment of the present invention;
[0069] Figure 6 A schematic diagram of the structure of a device for acquiring database data provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0071] In the prior art, methods for acquiring data from multiple databases generally include the following two methods:
[0072] 1. Use database proxy to enable applications to obtain data from multiple databases.
[0073] 2. Split the application into multiple processes, each process connects to a database, and obtains data from multiple databases in a multi-process manner.
[0074] Specifically, Figure 1 The schematic diagram of a database proxy method for obtaining data is shown as an example. Figure 1 As shown, the application accesses database 1, database 2 and database 3 through the database proxy, thereby obtaining data from multiple databases (including database 1, database 2 and database 3) at the same time. However, this method can only be implemented if database 1, database 2 and database 3 are homogeneous databases, and cannot be implemented for heterogeneous databases, that is, there are restrictions.
[0075] Figure 2 The schematic diagram of obtaining data in a multi-process manner is shown as an example. Figure 2 As shown, the database includes database A1, database A2 and database 3. According to the number of databases, the application splits one process into multiple processes (3), namely process A`1, process A`2 and process A`3; a connection is established between process A`1 and database A1, a connection is established between process A`2 and database A2, and a connection is established between process A`3 and database A3, so as to obtain data from multiple databases at the same time. However, after each process obtains the data, this method needs to transfer the data through communication or shared memory, which increases the consumption of CPU, memory and other resources by the application, increases the business processing time, reduces the business processing efficiency, and when the database is expanded, the number of processes needs to be expanded synchronously, so the scalability is low.
[0076] Therefore, a method for acquiring database data is now needed to reduce the complexity of data acquisition and processing and increase the efficiency of data acquisition and processing, thereby reducing business processing time and increasing business processing efficiency.
[0077] Figure 3 A system architecture applicable to an embodiment of the present invention is exemplarily shown, and the system architecture includes an application 310 , a database link manager 320 and a database 330 .
[0078] Among them, application 310 is used to determine the unique identifier of the database to be accessed corresponding to the database access operation during the running process, and match the database link of the database to be accessed from the database link manager 320 according to the process of application 310, and then create a thread with the database link of the database to be accessed, and perform the database access operation based on the thread.
[0079] The database link manager 320 is used to establish a connection with the corresponding database according to the database configuration information, obtain the database link of the database, and store the unique identifier of each database and the database link of each database in correspondence.
[0080] The database 330 is used to provide data corresponding to the database access operation; the database 330 can be a plurality of heterogeneous and / or homogeneous databases, which is not specifically limited here.
[0081] It should be noted that the above Figure 3 The structure shown is only an example and is not limited to this embodiment of the present invention.
[0082] Based on the above description, Figure 4 A schematic flow chart of a method for acquiring database data provided by an embodiment of the present invention is exemplarily shown, and the flow chart can be executed by a device for acquiring database data.
[0083] like Figure 4 As shown in the figure, the process specifically includes:
[0084] Step 410: for a database access operation during the running process of the application, determine a unique identifier of a database to be accessed corresponding to the database access operation.
[0085] In the embodiment of the present invention, there may be multiple unique identifiers of the database to be accessed in the database access operation, and the present invention does not specifically limit the number of unique identifiers of the database to be accessed.
[0086] Step 420: Match the database link of the database to be accessed from the database link manager according to the unique identifier of the database to be accessed.
[0087] In the embodiment of the present invention, each database link in the database link manager is obtained after the application is started and a connection is established with each database according to configuration information of each database.
[0088] Step 430: Create a thread having a database link of the database to be accessed in the process, and execute the database access operation based on the thread.
[0089] In the embodiment of the present invention, each database access operation in the application is completed through each thread in the process.
[0090] In step 410, the application process acquires a business request during operation; the business request includes a database access operation, and the unique identifier of the database to be accessed corresponding to the database access operation may be multiple.
[0091] For example, the business request is to determine the result of "1+N+M", where the data of "N" is stored in database N' and the data of "M" is stored in database M'. The unique identifier of the database to be accessed includes the unique identifiers of database N' and database M'.
[0092] In step 420, the application will establish a connection with the database through the database link manager to obtain the corresponding database link; specifically, for any database configuration, after the application is started, the database link manager will establish a connection with the corresponding database according to the database configuration information to obtain the database link of the database; the unique identifier of each database and the database link of each database will be stored in the database link manager accordingly.
[0093] The configuration information of the database includes the unique identifier of the database, the database description, the database user name, the database link address, the database driver loading class and the database password. The configuration information of each database is independent of each other, and the application distinguishes different database links by the unique identifier of the database. The unique identifier of the database can be the model of the database, the database name, etc., which is not specifically limited here.
[0094] Furthermore, the configuration information of the database is shown in the code program as follows:
[0095]
[0096] In the above program, dbName represents the database name, dbDesc is used to describe database-related information, dbUser represents the database user name, dbUrl is used to connect to the database through jdbc, which contains the database IP, port and database name, dbDriver represents the driver used to load the database link, and supports multiple databases such as mysql and db2, and dbPassword represents the password used to connect to the database.
[0097] In one practicable manner, the established database links are stored according to dates;
[0098] In the embodiment of the present invention, for any database, the unique identifier of the database is used as the key, and the database link of the database is used as the value, and the database is stored in the database link manager in the form of a map data structure.
[0099] Figure 5 A schematic diagram of a database link manager is shown as an example. Figure 5As shown, "DB-1" is the unique identifier of database 1, and "conn-1" is the database link of database 1; with "DB-1" as the key, "conn-1" is stored in the database link manager as the value; "DB-2" is the unique identifier of database 2, and "conn-2" is the database link of database 2; with "DB-2" as the key, "conn-2" is stored in the database link manager as the value; "DB-3" is the unique identifier of database 3, and "conn-3" is the database link of database 3; with "DB-3" as the key, "conn-3" is stored in the database link manager as the value.
[0100] Exemplarily, the user can manage the database links in the database link manager as needed; specifically, if a new database is involved in the application, the database link of the new database is determined according to the database configuration information of the new database, and the database link of the new database is stored; if the application involves deleting a database, the configuration information and database link of the database to be deleted are deleted according to the unique identifier of the database to be deleted; after storing the new database link or deleting the configuration information and database link of the database to be deleted, the database link manager is updated.
[0101] Based on the above Figure 5 For example, if the user adds the configuration information of database 4, the database link of the newly added database 4 is determined through the database link manager, where the unique identifier of the newly added database 4 is "DB-4", and the database link of the newly added database 4 is established as "conn-4", and then ("DB-4"-"conn-4") is determined according to the map data structure form, and ("DB4"-"conn-4") is stored in the database link manager.
[0102] For another example, the user decides to delete database 2. First, the database link of database 2 is determined to be "conn-2" based on the unique identifier "DB-2" of database 2, and the database link of database 2 is disconnected as "conn-2"; then the database link of database 2 is deleted as "conn-2" and the configuration information of database 2 in the database link manager.
[0103] In one feasible manner, if the configuration information in a database is modified, the corresponding database link and the database configuration information can be deleted in the database link manager first; then the database link can be re-established according to the modified configuration information, and the re-established database link can be stored in the database link manager.
[0104] In step 430, when there are multiple unique identifiers of the database to be accessed corresponding to the database access operation, multiple threads may be established to obtain the data in the database, or one thread may be established to obtain the data in the database.
[0105] Specifically, in one implementable manner, the database access operation includes a unique identifier of a first database to be accessed and a unique identifier of a second database to be accessed; a first thread having a database link to the first database to be accessed is created in the process; and a second thread having a database link to the second database to be accessed is created in the process.
[0106] In the embodiment of the present invention, it is taken as an example that the number of unique identifiers of the database to be accessed is two. Similarly, the number of unique identifiers of the database to be accessed may also be three, four, etc., which is not specifically limited here.
[0107] Based on the above description, the business request is to determine the result of "1+N+M"; wherein the unique identifier of the first database to be accessed is "N`", and the database link of the first database to be accessed is "conn-N`"; the unique identifier of the second database to be accessed is "M`", and the database link of the second database to be accessed is "conn-M`".
[0108] A first thread is established based on the database link "conn-N`", and a second thread is established based on the database link "conn-M`". Data N is obtained from database N` through the first thread, and data M is obtained from database M` through the second thread.
[0109] In another practicable manner, the database access operation includes a unique identifier of a first database to be accessed and a unique identifier of a second database to be accessed; a thread having a database link of the first database to be accessed is created in a process; based on the thread, a database access operation for the first database to be accessed is performed; after the database access operation for the first database to be accessed is performed, the database link in the thread is set to a database link of the second database to be accessed, and based on the thread, a database access operation for the second database to be accessed is performed.
[0110] Based on the above description, an example is given. First, thread T1 is established according to the database link "conn-N`", and then data N is obtained from database N` based on thread T1; then the database link in thread T1 is set to database link "conn-M`", which is equivalent to updating thread T1 to obtain thread T2. Thread T2 represents the thread after setting the database link "conn-M`", and then data M is obtained from database M` through thread T2.
[0111] Furthermore, the process of creating a thread is: creating a thread in a process, and writing a database link of a database to be accessed into TreadLocal of the thread.
[0112] For example, write the database link "conn-M`" into the thread's TreadLocal, and get the thread's logic code as: ThreadLocal <jdbctemplate>dbConn = conn-M; then according to "ThreadLocal <jdbctemplate>dbConn=conn-M" accesses the database M`, and executes the logic code "dbConn.get().query("select*from tbl_nm")" on the thread to obtain the corresponding data M in the data table 1 (tb1) of the database M`.
[0113] In the embodiment of the present invention, only one process instance is required. The process simultaneously connects multiple database links through the database link manager, and can perform add, delete, modify and query operations on multiple databases. The database link manager uses the unique identifier of the database to distinguish different database links. When the application starts, the database link manager reads the configuration information of each database, establishes a database link according to the configuration information of each database, and then stores the database link to achieve the management of multiple database links.
[0114] Because the present invention obtains database data through a single process, it reduces the extra consumption of resources such as CPU and memory, and avoids the consumption of system resources by multi-process switching. The data transmission obtained from the database does not require inter-process communication, which reduces the processing delay of the business. The connection switching of the database is realized through the database link stored in the database link manager, and the data of different databases are cached in the same process. When exchanging data between different businesses, it is only necessary to operate the cache of the process, avoiding data exchange between multiple processes, reducing the consumption of network resources and time resources, and thus improving the business processing efficiency.
[0115] Based on the same technical concept, Figure 6 The schematic diagram of the structure of a device for acquiring database data provided by an embodiment of the present invention is exemplarily shown, and the process that can be executed by the device.
[0116] like Figure 6 As shown, the device specifically includes:
[0117] An analysis module 610 is used to determine a unique identifier of a database to be accessed corresponding to a database access operation during the running process of an application process;
[0118] A matching module 620 is used to match the database link of the database to be accessed from the database link manager according to the unique identifier of the database to be accessed; each database link in the database link manager is obtained after the application is started and a connection is established with each database according to the configuration information of each database;
[0119] The processing module 630 is used to create a thread having a database link of the database to be accessed in the process, and execute the database access operation based on the thread; wherein each database access operation in the application is completed through each thread in the process.
[0120] Optionally, the database access operation includes a unique identifier of the first database to be accessed and a unique identifier of the second database to be accessed;
[0121] The processing module 630 is specifically used for:
[0122] Creating a first thread having a database link of the first database to be accessed in the process;
[0123] A second thread having a database link of the second database to be accessed is created in the process.
[0124] Optionally, the database access operation includes a unique identifier of the first database to be accessed and a unique identifier of the second database to be accessed;
[0125] The processing module 630 is specifically used for:
[0126] Creating a thread having a database link of the first database to be accessed in the process;
[0127] Based on the thread, executing a database access operation on the first database to be accessed;
[0128] After executing the database access operation for the first database to be accessed, the database link in the thread is set as the database link of the second database to be accessed, and based on the thread, the database access operation for the second database to be accessed is executed.
[0129] Optionally, the processing module 630 is specifically used for:
[0130] For any database configuration, after the application is started, a connection is established with the corresponding database according to the database configuration information through a database link manager to obtain a database link of the database;
[0131] The unique identifier of each database and the database link of each database are correspondingly stored in the database link manager.
[0132] Optionally, the processing module 630 is specifically used for:
[0133] For any database, the unique identifier of the database is used as the key, and the database link of the database is used as the value, and the database is stored in the database link manager in the form of a map data structure.
[0134] Optionally, the processing module 630 is specifically used for:
[0135] If a new database is involved in the application, a database link of the new database is determined according to database configuration information of the new database, and the database link of the new database is stored;
[0136] If the application involves deleting a database, the configuration information and database link of the database to be deleted are deleted according to the unique identifier of the database to be deleted;
[0137] After storing the newly added database link or deleting the configuration information and database link of the to-be-deleted database, the database link manager is updated.
[0138] Optionally, the processing module 630 is specifically used for:
[0139] A thread is created in the process, and the database link of the database to be accessed is written into the TreadLocal of the thread.
[0140] Based on the same technical concept, an embodiment of the present invention further provides a computer device, including:
[0141] A memory for storing program instructions;
[0142] The processor is used to call the program instructions stored in the memory and execute the above method for obtaining database data according to the obtained program.
[0143] Based on the same technical concept, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above method for obtaining database data.
[0144] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0145] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0146] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0147] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0148] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.< / jdbctemplate> < / jdbctemplate>
Claims
1. A method for obtaining database data, characterized in that: include: For a database access operation during the running process of the application, determine a unique identifier of a database to be accessed corresponding to the database access operation; Matching the database link of the database to be accessed from the database link manager according to the unique identifier of the database to be accessed; each database link in the database link manager is obtained after the application is started and a connection is established with each database according to the configuration information of each database; Creating a thread having a database link of the database to be accessed in the process, and executing the database access operation based on the thread; wherein each database access operation in the application is completed through each thread in the process; Also includes: If a new database is involved in the application, a database link of the new database is determined according to database configuration information of the new database, and the database link of the new database is stored; If the application involves deleting a database, the configuration information and database link of the database to be deleted are deleted according to the unique identifier of the database to be deleted; After storing the newly added database link or deleting the configuration information and database link of the to-be-deleted database, the database link manager is updated.
2. The method according to claim 1, characterized in that The database access operation includes a unique identifier of a first database to be accessed and a unique identifier of a second database to be accessed; Creating a thread having a database link of the database to be accessed in the process includes: Creating a first thread having a database link of the first database to be accessed in the process; A second thread having a database link of the second database to be accessed is created in the process.
3. The method according to claim 1, characterized in that The database access operation includes a unique identifier of a first database to be accessed and a unique identifier of a second database to be accessed; Creating a thread having a database link of the database to be accessed in the process includes: Creating a thread having a database link of the first database to be accessed in the process; Executing the database access operation based on the thread includes: Based on the thread, executing a database access operation on the first database to be accessed; After executing the database access operation for the first database to be accessed, the database link in the thread is set as the database link of the second database to be accessed, and based on the thread, the database access operation for the second database to be accessed is executed.
4. The method according to any one of claims 1 to 3, characterized in that The database links in the database link manager are obtained after the application is started and a connection is established with each database according to the configuration information of each database, including: For any database configuration, after the application is started, a connection is established with the corresponding database according to the database configuration information through a database link manager to obtain a database link of the database; The unique identifier of each database and the database link of each database are correspondingly stored in the database link manager.
5. The method according to claim 4, characterized in that Storing the unique identifier of each database and the database link of each database in the database link manager accordingly includes: For any database, the unique identifier of the database is used as the key, and the database link of the database is used as the value, and the database is stored in the database link manager in the form of a map data structure.
6. The method according to claim 1, characterized in that Creating a thread having a database link of the database to be accessed in the process includes: A thread is created in the process, and the database link of the database to be accessed is written into the TreadLocal of the thread.
7. A device for acquiring database data, characterized in that: include: An analysis module, for determining a unique identifier of a database to be accessed corresponding to a database access operation during the running process of an application process; A matching module, used for matching the database link of the database to be accessed from the database link manager according to the unique identifier of the database to be accessed; each database link in the database link manager is obtained after the application is started and a connection is established with each database according to the configuration information of each database; A processing module, used for creating a thread having a database link of the database to be accessed in the process, and performing the database access operation based on the thread; wherein each database access operation in the application is completed through each thread in the process; The processing module is also used to, if the application involves a new database, determine the database link of the new database according to the database configuration information of the new database, and store the database link of the new database; if the application involves deleting a database, delete the configuration information and database link of the database to be deleted according to the unique identifier of the database to be deleted; and update the database link manager after storing the new database link or deleting the configuration information and database link of the database to be deleted.
8. A computer device, characterized in that: include: A memory for storing program instructions; A processor, configured to call the program instructions stored in the memory, and execute the method according to any one of claims 1 to 6 according to the obtained program.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Report generation method and device
CN113268501A