A data source changing method, system, intelligent terminal and storage medium

By judging and responding to data source status changes in real time, and using thread variables and interceptors to dynamically manage data source connections, the problem of inability to add and modify data sources in real time in the existing technology is solved, and efficient data source management and response are achieved.

CN119066059BActive Publication Date: 2025-02-14KINCHENG BANK OF TIANJIN CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411556090.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-04
Publication Date
2025-02-14
Estimated Expiration
2044-11-04

AI Technical Summary

Technical Problem

In the prior art, data sources cannot be added and modified in real time when the application is running, resulting in the need to restart the application to take effect, and the data sources cannot be specified dynamically.

Method used

After receiving the database operation instructions, we can judge in real time whether the data source status has changed. When the change occurs, we search and connect to the target database based on the data source identifier in the thread variable. After the operation is completed, we use an interceptor to delete the data source identifier for identification The newly written data source identifier.

Benefits of technology

It realizes the real-time addition and modification of data sources in the application running state, avoiding the need to restart the application, and improving the response efficiency of data source state changes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119066059B_ABST
    Figure CN119066059B_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical field of computer software, and discloses a method, system, intelligent terminal and storage medium for changing a data source. The method comprises: after receiving an operation instruction for a database, judging in real time whether the state of a data source has changed; when a change occurs, searching and connecting to a target database according to a data source identifier in a thread variable to operate the target database; after the operation on the target database is completed, deleting the data source identifier from the thread variable by using an interceptor, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction, thereby realizing real-time selection, addition and modification of a data source, and avoiding interference with the selection of a new data source when executing the next operation instruction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer software, and in particular to a method, system, intelligent terminal and storage medium for changing a data source. Background Art

[0002] In the prior art, when open source static multi-data sources change, the application needs to be restarted to take effect, and they cannot be added or modified in real time.

[0003] For example, database connection pools such as Druid and hikari have the following shortcomings when operating databases: 1. Data sources need to be configured in advance and will only take effect after the application is restarted; 2. Data sources can be selected through directory scanning or annotation, but data sources cannot be specified in real time through dynamic methods. When JDBC (JDBC: Java Database connect, Chinese name Java database connection, it is a set of Java API (API: Application Programming Interface, Chinese name Application Programming Interface, refers to a set of methods for interaction between two different software applications)) manually operates dynamic data sources, there are problems such as implementation difficulties, large amount of code and unreliability.

[0004] Therefore the prior art still needs to be improved and enhanced. Summary of the invention

[0005] The main purpose of the present invention is to provide a method, system, intelligent terminal and storage medium for changing a data source, aiming to solve the problem in the prior art that a data source cannot be added and modified in real time when an application is running.

[0006] In order to achieve the above object, the present invention adopts the following technical solutions:

[0007] In a first aspect, an embodiment of the present application provides a method for changing a data source, including:

[0008] After receiving the operation instruction on the database, it determines in real time whether the state of the data source has changed;

[0009] When a change occurs, the target database is searched and connected according to the data source identifier in the thread variable to operate the target database;

[0010] After the operation on the target database is completed, the data source identifier is deleted from the thread variable by using an interceptor, so that the data source identifier newly written into the thread variable can be identified when the next operation instruction is executed.

[0011] In some embodiments, the method for changing the data source further includes:

[0012] When it is determined that the state of the data source has not changed, the original data source is operated according to the operation instruction.

[0013] In some embodiments, searching and connecting to the target database according to the data source identifier in the thread variable includes:

[0014] After the interceptor is used to identify the data source identifier in the annotation or package path in real time and the data source identifier is written into the thread variable, the corresponding target database is searched according to the data source identifier in the thread variable.

[0015] In some embodiments, searching and connecting to the target database according to the data source identifier in the thread variable further includes:

[0016] The corresponding target database is searched according to the data source identifier in the thread variable set at runtime.

[0017] In some embodiments, after receiving the operation instruction on the database, determining in real time whether the state of the data source has changed may also include:

[0018] Mapping relationships between several original data sources of the system and their corresponding databases are established respectively to obtain a mapping table.

[0019] In some embodiments, the real-time determination of whether the state of the data source has changed includes:

[0020] Determine in real time whether the mapping relationship in the mapping table has been modified or added;

[0021] The newly added mapping relationship is the relationship between the data source identifier and the target database.

[0022] In some embodiments, the data source identifier includes: a user name, a password, and an address of a target database.

[0023] In a second aspect, an embodiment of the present application provides a system for changing a data source, including:

[0024] A judgment module is used to judge in real time whether the state of the data source has changed after receiving an operation instruction on the database;

[0025] An operation module, used for searching and connecting to a target database according to a data source identifier in a thread variable when a change occurs, so as to operate the target database;

[0026] The deletion module is used to delete the data source identifier from the thread variable by using an interceptor after the operation on the target database is completed, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction.

[0027] In a third aspect, an embodiment of the present application provides an intelligent terminal, comprising: a memory, a processor, a display, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the method for changing the data source as described above.

[0028] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method for changing a data source as described above.

[0029] Compared with the prior art, the present invention provides a method, system, intelligent terminal and storage medium for changing a data source, the method comprising: after receiving an operation instruction for a database, determining in real time whether the state of a data source has changed; when a change occurs, searching and connecting to a target database according to a data source identifier in a thread variable to operate the target database; after the operation on the target database is completed, deleting the data source identifier from the thread variable by using an interceptor, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction, thereby realizing real-time selection, addition and modification of a data source, and avoiding interference with the selection of a new data source when executing the next operation instruction. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0031] Figure 1 A flowchart of an embodiment of a method for changing a data source provided by the present invention;

[0032] Figure 2 A schematic diagram of the principle of an embodiment of a method for changing a data source provided by the present invention;

[0033] Figure 3 A comparison diagram of call logic with and without AOP added in one embodiment of the method for changing a data source provided by the present invention;

[0034] Figure 4An architectural relationship diagram of an embodiment of a system for changing a data source provided by the present invention. DETAILED DESCRIPTION

[0035] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.

[0036] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0037] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.

[0038] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.

[0039] The following describes the design of the method for changing the data source through specific exemplary embodiments. It should be noted that the following embodiments are only used to explain the technical solution of the invention and are not specifically limited:

[0040] See also Figure 1 , the embodiment of the present application provides a method for changing a data source, comprising steps S100-S300:

[0041] S100: After receiving an operation instruction on a database, determine in real time whether the state of a data source has changed.

[0042] Exemplarily, when a database connection pool (ie, a data source) is used to operate a database, the method for changing a data source in this embodiment may be used.

[0043] See also Figure 2 As shown in the figure, Biz is the abbreviation of Business, which can be called the control layer or business logic layer. The main function of the control layer is to coordinate the direct call and conversion between the model layer and the view layer. Biz needs to perform database operations to complete the business logic. The same business logic may operate multiple databases.

[0044] When the database needs to be operated, the business logic layer first receives the operation instruction for the database, and then determines in real time whether the status of the data source has changed, that is, whether the connection status of the data source in the system has changed, including the modification or addition of the data source in the mapping table, so as to decide whether to reconnect to the target database based on the judgment result.

[0045] In the present application, by determining in real time whether the state of the data source has changed, corresponding measures can be taken when the change occurs, thereby improving the response to the change of the state of the data source.

[0046] Among them, judging whether the state of the data source has changed is equivalent to Figure 2 Identify whether the data source exists; where a change is equivalent to the data source not existing, that is, the connection with the data source is modified or connected to a new data source; and no change is equivalent to the data source already existing, that is, the connection with the data source remains unchanged.

[0047] For example, in one implementation, before step S100, the method for changing the data source further includes:

[0048] A100. Establish mapping relationships between a number of original data sources and their corresponding databases to obtain a mapping table.

[0049] The identifier in this application includes the user name, password and address of the corresponding database, which is the unique identifier of the data source. Then, the corresponding database is: the database corresponding to the user name, password and address of the original database (the database corresponding to the original data source).

[0050] Exemplarily, the system needs to first establish a mapping relationship between each original data source in the application and its corresponding original identifier (including: user name, password and address of the original database) to obtain a mapping table, so as to determine whether the target database has been changed according to the mapping table.

[0051] For example, in one implementation, determining in real time whether the state of a data source has changed includes:

[0052] S110, determining in real time whether the mapping relationship in the mapping table is modified or added;

[0053] The newly added mapping relationship is the relationship between the data source identifier and the target database; the data source identifier includes: the user name, password and address of the target database.

[0054] Exemplarily, after obtaining the mapping table, it is determined in real time whether the mapping relationship in the mapping table is modified or new. In this embodiment, the determination can be made in the following two ways:

[0055] The first method is to determine whether any of the original identifiers (user name, password, and address) in the mapping relationship has changed. The second method is to determine whether a new mapping relationship has appeared in the mapping relationship (a new mapping relationship is the relationship between the data source identifier and the target database). Specifically, it can be determined whether there is a new identifier in the mapping relationship, such as the data source identifier. Then, based on different judgment results, it is decided whether to connect or reconnect to the database.

[0056] Continue reading Figure 1 , S200, when a change occurs, search and connect to the target database according to the data source identifier in the thread variable to operate the target database.

[0057] Among them, DAO (DAO: Data Access Object, Chinese name: Data Access Interface): Java interface entry for operating database. Biz uses DAO to connect to the database. DAO layer: also known as the persistence layer, its function is mainly responsible for database access (can access database, binary files, text files, etc.).

[0058] AOP (Aspect Oriented Programming, Chinese name is aspect-oriented programming, which is a technology that implements unified maintenance of program functions through pre-compilation and runtime dynamic proxy), as an interceptor in the Spring (lightweight Java development framework) system, can intercept specified operations and add custom logic before and after the intercepted operations. In this embodiment, the modification and addition of dynamic data sources are realized, which is based on the characteristics of Aop, and some pre-logic and post-logic are added in the data source operation process.

[0059] Demonstratively, when judging in real time whether the state of the data source has changed: if the state of the data source has changed, the data source identification is started. Here, Spring jdbc's AbstractRoutingDataSource is used (there is an abstract class in spring, through which dynamic data source switching can be achieved). When this Routing (abbreviation of AbstractRoutingDataSource) is executed in the default database, no data source selection is performed. At this time, Spring will select the system default data source for database operations, and then return to the default state of no multiple data sources.

[0060] However, in this application, interceptors such as AOP are used to select data sources before database execution. At this time, AOP is used to identify package paths or annotations (annotations are the process of labeling the database operation interface) or directly identify thread variables set by users to identify whether there is a specified data source operation:

[0061] If the target database is specified, that is, the pre-logic has been added in the database operation process using interceptors such as AOP (adding the data source identifier in the linear thread), then the multi-data source plug-in will enter the target database confirmation and connection logic to achieve connection with the target database to operate the target database, including: adding, deleting, checking and modifying any actions on the target database.

[0062] If the original data source is specified, the current logic will tell jdbc to use the specific database for database operations.

[0063] Finally, after completing the data operation on the specified database, the operation result is returned to the business layer Biz.

[0064] It can be understood that in this embodiment, by setting the pre-logic during the database operation process, that is, using the data source identifier in the thread to find the target database, the changed target database can be found dynamically, efficiently and accurately.

[0065] For example, in one implementation, searching and connecting to a target database according to a data source identifier in a thread variable includes:

[0066] S10. After using the interceptor to identify the data source identifier in the annotation or package path in real time and writing the data source identifier into the thread variable, searching for the corresponding target database according to the data source identifier in the thread variable.

[0067] Exemplarily, after determining that the state of the data source has changed, the database connection pool is informed of how to identify the target database, that is, data source identification is performed. There are two identification methods:

[0068] The first identification method uses the interceptor to determine the logical position of the currently running code (current logical position), automatically identifies and extracts the identification information in the annotation or package path as a thread variable, that is, after using the interceptor to identify the data source identifier in the annotation or package path in real time, the data source identifier is written into the thread variable, so as to identify the corresponding target database according to the data source identifier in the thread variable. These two identification methods are used to realize the data source identification in the front-end logic of operating the database.

[0069] Then, connect to the target database according to the data source identifier:

[0070] If the database connection pool has established a connection with the target database (old link), it means that the target database is the modified original data source. At this time, the old link needs to be destroyed and a new connection needs to be established. If the database connection pool has not established a connection with the target database, it means that the target database is a new data source in the system. In this case, a connection needs to be established with the target database.

[0071] For example, in one implementation, searching and connecting to a target database according to a data source identifier in a thread variable further includes:

[0072] S20. Search for a corresponding target database according to a data source identifier in a thread variable set at runtime.

[0073] Exemplarily, in the second identification method, when the code runs to the front logic, after setting the thread variable in real time, the data source identifier in the thread variable is identified. Then, the target database is searched according to the data source identifier, and similarly, the target database is connected according to the data source identifier.

[0074] It can be understood that the present application supports methods such as determining data sources including annotations, directory distinction (i.e., package path distinction) and real-time specification using thread variables, and can also expand the data source specification method to achieve dynamic data source changes.

[0075] S300: After the operation on the target database is completed, the data source identifier is deleted from the thread variable by using an interceptor, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction.

[0076] Among them, you can also use interceptors such as AOP to add post-logic in the database operation process, and the subsequent logic is taken over by Druid (open source data source component or Druid connection pool) and MyBatis (mybatis is a lightweight, semi-automatic ORM (Object Relational Mapping, Chinese name is object relationship mapping, which is used to realize the conversion between data of different types of systems in object-oriented programming language) framework for persistence layer. It is a persistence layer framework that encapsulates all jdbc operations and operations of setting query parameters and obtaining result sets. It supports custom SQL (SQL: Structured Query Language, Chinese name is structured query language, which is the operating language for relational databases), stored procedures and advanced mapping). Among them, Druid helps manage the connection pool. After obtaining the connection pool, MyBatis performs SQL syntax processing, sends the final SQL to the database for processing, and then returns the processing results to the business logic.

[0077] Exemplarily, after the operation on the target database is completed, interceptors such as AOP are used to add post-logic in the database operation process: the data source identifier is deleted from the thread variable so that when the next operation instruction is executed, the data source identifier newly written into the thread variable is identified, that is, in subsequent database operations, it will no longer interfere with the new data source selection.

[0078] The comparison of call logic with and without AOP is shown in the figure below: Figure 3 As shown. Among them, (a) is a call logic diagram without AOP. In this case, method A will directly call method B without any intermediate logic; and (b) is a call logic diagram with AOP. In this case, AOP can form a section in the process of A calling B. This section can execute some preset logic (pre-logic) before method B is executed, and can also execute some preset logic (post-logic) after method B is executed. When Aop captures an exception, it is to obtain the result of method B execution in the post-logic of AOP. If method B executes abnormally, the post-logic can also obtain the exception details.

[0079] It can be understood that in this application, by deleting the data source identifier from the thread variable, the impact of the new data source identifier on the data source is reduced. At the same time, customization under the open source protocol is achieved to improve security and scenario adaptability. In addition, it is attached to the open source data source component druid, has stable and reliable characteristics, and supports any data source source, which increases the application scenario. Furthermore, reducing dependence on existing fee-based / non-open source tools can effectively save costs.

[0080] Furthermore, the method for changing the data source also includes:

[0081] S400: When it is determined that the state of the data source has not changed, operate the original data source in the system according to the operation instruction.

[0082] Exemplarily, when determining in real time whether the state of a data source has changed:

[0083] If it is determined that the state of the data source has not changed, that is, no new data source has been added to the system or the original data source has not been modified, in this case, the original data source is always connected, that is, the data source already exists. Then, the original data source in the system can be directly operated according to the operation instructions, including adding, deleting, checking and modifying.

[0084] See also Figure 4 , an embodiment of the present application provides a data source change system, including:

[0085] The judgment module 1 is used to judge in real time whether the state of the data source has changed after receiving an operation instruction on the database.

[0086] The operation module 2 is used to search and connect to the target database according to the data source identifier in the thread variable when a change occurs, so as to operate the target database.

[0087] The deletion module 3 is used to delete the data source identifier from the thread variable by using the interceptor after the operation on the target database is completed, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction.

[0088] Exemplarily, the data source change method is applicable to the data source change system. Then, the implementation process of the data source change system is similar to the method:

[0089] First, after receiving the operation instruction for the database, the modification or addition of the data source in the system is judged in real time (whether the status of the data source has changed). If the status of the data source has changed, the specified data source is identified, that is, the data source identifier in the thread variable is identified to find and connect to the target database, and then further operations such as adding, deleting, checking and modifying the target database are performed.

[0090] Then, after the operation on the target database is completed, the data source identifier is deleted from the thread variable so that when the next operation instruction is executed, the data source identifier newly written into the thread variable is identified to avoid interference with the new data source selection.

[0091] The single data source solution based on Druid in this application expands the dynamic data source solution through a self-developed plug-in. This application also provides a terminal device, which exemplarily includes a processor and a memory, wherein the memory stores a computer program, and the processor runs the computer program to enable the terminal device to execute the above-mentioned data source change method or the functions of each module in the above-mentioned data source change system.

[0092] Among them, the processor can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application.

[0093] The memory may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electric erasable programmable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.

[0094] The present application also provides a computer-readable storage medium for storing the computer program used in the above terminal device. For example, the computer-readable storage medium may include but is not limited to: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0095] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0096] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0097] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0098] In summary, the present application discloses a method, system, intelligent terminal and storage medium for changing a data source, the method comprising: after receiving an operation instruction for a database, determining in real time whether the state of a data source has changed; when a change occurs, searching and connecting to a target database according to a data source identifier in a thread variable to operate the target database; after the operation on the target database is completed, deleting the data source identifier from the thread variable using an interceptor, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction.

[0099] After determining that the state of the data source has changed, the target database is searched and connected according to the data source identifier in the thread variable, and the target database is operated. After the operation is completed, the data source identifier in the thread variable is deleted, thereby achieving real-time connection and operation with the changed data source, and effectively avoiding the identification of the new data source when executing the next operation instruction.

[0100] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.

Claims

1. A method for changing a data source, characterized in that: include: After receiving the operation instruction on the database, it determines in real time whether the state of the data source has changed; When a change occurs, the target database is searched and connected according to the data source identifier in the thread variable to operate the target database; After the operation on the target database is completed, the data source identifier is deleted from the thread variable by using an interceptor, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction; After receiving the operation instruction for the database, determining in real time whether the state of the data source has changed, the method also includes: Establish mapping relationships between several original data sources and their corresponding databases respectively to obtain a mapping table; The real-time determination of whether the state of the data source has changed includes: Determine in real time whether the mapping relationship in the mapping table has been modified or added; The newly added mapping relationship is the relationship between the data source identifier and the target database; The step of searching and connecting to the target database according to the data source identifier in the thread variable includes: After the interceptor is used to identify the data source identifier in the annotation or package path in real time and the data source identifier is written into the thread variable, the corresponding target database is searched according to the data source identifier in the thread variable.

2. The method for changing a data source according to claim 1, characterized in that: Also includes: When it is determined that the state of the data source has not changed, the original data source is operated according to the operation instruction.

3. The method for changing a data source according to claim 1, characterized in that: The step of searching and connecting to the target database according to the data source identifier in the thread variable also includes: The corresponding target database is searched according to the data source identifier in the thread variable set at runtime.

4. The method for changing a data source according to claim 1, characterized in that: The data source identifier includes: the user name, password and address of the target database.

5. A data source change system, characterized in that: include: A judgment module is used to judge in real time whether the state of the data source has changed after receiving an operation instruction on the database; An operation module, used for searching and connecting to a target database according to a data source identifier in a thread variable when a change occurs, so as to operate the target database; A deletion module, used to delete the data source identifier from the thread variable by using an interceptor after the operation on the target database is completed, so as to identify the data source identifier newly written into the thread variable when executing the next operation instruction; After receiving the operation instruction for the database, determining in real time whether the state of the data source has changed, the method also includes: Establish mapping relationships between several original data sources and their corresponding databases respectively to obtain a mapping table; The real-time determination of whether the state of the data source has changed includes: Determine in real time whether the mapping relationship in the mapping table has been modified or added; The newly added mapping relationship is the relationship between the data source identifier and the target database; The step of searching and connecting to the target database according to the data source identifier in the thread variable includes: After the interceptor is used to identify the data source identifier in the annotation or package path in real time and the data source identifier is written into the thread variable, the corresponding target database is searched according to the data source identifier in the thread variable.

6. An intelligent terminal, characterized in that: include: A memory, a processor, a display, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the method for changing a data source as described in any one of claims 1 to 4 are implemented.

7. A computer-readable storage medium, characterized in that: A computer program is stored, and when the computer program is executed by a processor, the steps of the method for changing a data source according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Spring framework-based database access method and device, computer equipment and medium

    CN111309785A

  • Database connection pool configuration method, device and system

    CN113779119A