Data source switching method and device, medium and electronic equipment

By building data source management and routing classes, using aspect-oriented programming technology and data source registration methods, dynamic switching of data sources is achieved when the application runs, solving the problems of poor flexibility and low efficiency of data source switching in the existing technology, and improving the flexibility and efficiency of data source switching.

CN119917592APending Publication Date: 2025-05-02LINGSHU TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510003515.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-02
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

The prior art has poor flexibility and low switching efficiency when switching data sources. It usually requires restarting the application to achieve switching of data sources.

Method used

By building data source management and routing classes, the data source registration method is used to pre-register candidate data sources, and annotate the data access method using aspect-oriented programming technology, and configure connection pools for the target data source in memory, so as to dynamically switch data sources when the application is run.

Benefits of technology

Method-level data source switching is realized, improving the flexibility and switching efficiency of data source switching, and avoiding the need to restart the application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917592A_ABST
    Figure CN119917592A_ABST
Patent Text Reader

Abstract

The invention discloses a data source switching method and device, a medium and electronic equipment, and the method comprises the steps: in response to monitoring that a data access method is called, determining a to-be-switched target data source in at least two candidate data sources based on an annotation associated with the data access method; based on a connection pool configured for the target data source in a memory, accessing the target data source to switch from an initial data source to the target data source; wherein the candidate data source is registered in advance by adopting a data source registration method, and the data source registration method is operation in data source management and routing classes. By executing the technical scheme provided by the invention, the dynamic switching of the data sources is realized, and the switching flexibility of the data sources and the switching efficiency of the data sources are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data source management, and in particular to a data source switching method, device, medium and electronic device. Background Art

[0002] Applications need to switch between multiple data sources. Data source switching is the process of dynamically selecting which data source to use based on business needs or specific conditions among multiple configured data sources. The configuration method of the data source directly affects the flexibility and efficiency of data source switching.

[0003] Mainstream development frameworks such as Spring Boot use static configuration to configure data sources. Statically configured data sources are loaded and initialized when the application starts, and are usually cached in the application context. To switch data sources at runtime, the application needs to reload and initialize the new data source and update the related context configuration, which usually requires restarting the application, resulting in poor flexibility and low switching efficiency. Summary of the invention

[0004] The present application provides a data source switching method, device, medium and electronic device, which can achieve the purpose of improving the flexibility of data source switching and the switching efficiency of data source.

[0005] According to a first aspect of the present application, a data source switching method is provided, the method comprising:

[0006] In response to monitoring that a data access method is called, determining a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method;

[0007] Based on the connection pool configured for the target data source in the memory, access the target data source to switch from the initial data source to the target data source;

[0008] The candidate data source is pre-registered using a data source registration method, and the data source registration method is an operation in a data source management and routing class.

[0009] According to a second aspect of the present application, a data source switching device is provided, the device comprising:

[0010] A target data source determination module, configured to determine, in response to monitoring that a data access method is called, a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method;

[0011] A target data source access module, configured to access the target data source based on a connection pool configured for the target data source in a memory to switch from an initial data source to the target data source;

[0012] The candidate data source is pre-registered using a data source registration method, and the data source registration method is an operation in a data source management and routing class.

[0013] According to a third aspect of the present invention, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data source switching method as described in the embodiment of the present application.

[0014] According to a fourth aspect of the present invention, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the data source switching method as described in the embodiment of the present application is implemented.

[0015] According to a fifth aspect of the present application, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the data source switching method as described in the embodiment of the present application.

[0016] The technical solution of the embodiment of the present application, by constructing a data source management and routing class, adopting the data source registration method in the data source management and routing class, registering candidate data sources, and supporting dynamic registration of data sources when the application is running. The present application adopts aspect-oriented programming technology to add annotations to the data access method, specifies the target data source to be switched among at least two candidate data sources, and switches access to the target data source from the initial data source to the target data source based on the connection pool configured for the target data source in the memory, realizing method-level data source switching when the application is running, improving the flexibility of data source switching and the efficiency of data source switching.

[0017] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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 application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0019] Figure 1is a flow chart of a data source switching method provided according to Embodiment 1;

[0020] Figure 2 is a flow chart of a data source switching method provided according to Embodiment 2;

[0021] Figure 3 is a structural diagram of a data source switching device provided in Embodiment 3 of the present application;

[0022] Figure 4 It is a structural schematic diagram of an electronic device provided in Example 4 of the present application. DETAILED DESCRIPTION

[0023] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described 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, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0024] It should be noted that the terms "first", "second", "target" and "candidate" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or precedence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0025] Embodiment 1

[0026] Figure 1 This is a flow chart of a data source switching method provided according to the first embodiment. This embodiment is applicable to the case where an application switches between multiple data sources. The method can be executed by a data source switching device, which is implemented in the form of hardware and / or software and can be integrated into an electronic device running this system.

[0027] like Figure 1 As shown, the method includes:

[0028] S110 . In response to monitoring that a data access method is called, determine a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method.

[0029] S120: Based on the connection pool configured for the target data source in the memory, access the target data source to switch from the initial data source to the target data source.

[0030] The candidate data source is pre-registered using a data source registration method, and the data source registration method is an operation in a data source management and routing class.

[0031] Optionally, when the front-end page control is clicked, the data access method is called. The data access method is used to access the data source to read or write the data source. The data access method is associated with an annotation, where the annotation is used to indicate whether the data access method involves switching of a specified data source. Optionally, AOP (Aspect Oriented Programming) technology is used to add annotations to the data access method. AOP technology can intervene before and after the execution of the data access method without changing the business code, and is often used for the processing of cross-cutting concerns. Use AOP technology to add annotations to the data access method, specify which data source the data access method uses, and use AOP technology to switch the data source when the data access method is executed.

[0032] It is understandable that not all data access methods involve switching of a specified data source. Based on the annotation associated with the data access method, it can be determined whether the data access method involves switching of a specified data source.

[0033] The target data source to be switched refers to another data source that needs to be switched from the initial data source according to specific logic or conditions during the execution of the data access method. The target data source to be switched can be a relational database or a non-relational database. The specific type of the target data source is determined according to the actual situation and is not limited here.

[0034] The target data source is generated from the candidate data sources, and there are at least two candidate data sources. The number of candidate data sources is not limited here and is determined according to actual business needs. The target data source is pre-registered using the data source registration method. The data source registration method is used to register a new data source.

[0035] A certain number of data source connections are pre-created and maintained in the connection pool so that the application can quickly acquire and release them when it needs to access the data source.

[0036] Optionally, after the candidate data source is registered, a connection pool is configured in memory for the candidate data source. That is, each candidate data source has a corresponding connection pool. Based on the connection pool of the target data source, a connection is established with the target data source, and the target data source is accessed by switching from the initial data source to the target data source.

[0037] The technical solution of the embodiment of the present application, by constructing a data source management and routing class, adopting the data source registration method in the data source management and routing class, registering candidate data sources, and supporting dynamic registration of data sources when the application is running. The present application adopts aspect-oriented programming technology to add annotations to the data access method, specifies the target data source to be switched among at least two candidate data sources, and switches access to the target data source from the initial data source to the target data source based on the connection pool configured for the target data source in the memory, realizing method-level data source switching when the application is running, improving the flexibility of data source switching and the efficiency of data source switching.

[0038] In an optional embodiment, the accessing the target data source based on the connection pool configured for the target data source in the memory includes: determining the connection pool configured for the target data source in the memory; and establishing a connection with the target data source based on the connection object in the connection pool to access the target data source.

[0039] The target data source is pre-registered using the data source registration method. A connection pool is configured in memory for the target data source. The connection pool includes at least two connection objects, which encapsulate the connection information with the data source server and provide an interface for communicating with the data source. The number of connection objects is not limited here and is determined according to actual business needs. Based on the connection objects in the connection pool, a connection with the target data source is established to access the target data source.

[0040] The above technical solution configures a connection pool for the target data source in memory and establishes a connection with the target data source based on the connection object in the connection pool. There is no need to go through the overhead of establishing a new connection each time. The time for establishing a connection is significantly reduced, and the response speed and overall performance of the application are improved.

[0041] In an optional embodiment, the method further includes: calling the data source registration method in response to receiving a data source registration request, and obtaining connection information of the data source to be added through the data source registration method; creating a connection pool for the data source to be added in memory, and generating a connection object for the data source to be added based on the connection information; and adding the connection object created for the data source to be added to the connection pool of the data source to be added.

[0042] The data registration request is used to request to call the data source registration method, and the data source registration method is used to register a new data source. The data source to be added refers to a new data source that needs to be registered.

[0043] The connection information of the data source to be added refers to the information relied on for establishing a connection with the data source to be added. The specific content of the connection information is not limited here. For example, the connection information includes: server name or address, database name, user name and password corresponding to the user name, and other configuration information, such as connection timeout and character set encoding.

[0044] The connection object of the data source to be added is generated based on the connection information of the data source to be added. A connection pool is created in memory for the data source to be added, and the connection object of the data source to be added is added to the pool.

[0045] The above technical solution provides a feasible data source registration method, which uses the data source registration method to register a new data source and supports dynamic registration of data sources when the application is running. By configuring a connection pool for the target data source and adding a connection object to the connection pool, technical support is provided for subsequent establishment of a connection with the data source based on the connection object, which is conducive to improving the switching efficiency of the data source.

[0046] In an optional embodiment, the method further includes: in response to receiving a data source deregistration request, determining a data source to be deregistered; calling a data source deregistration method to delete a connection pool created for the data source to be deregistered from memory; wherein the data source deregistration method is an operation in a data source management and routing class.

[0047] The data deregistration request is used to request the call of the data source deregistration method. The data source deregistration method and the data source registration method are both operations in the data source management and routing classes. The data source deregistration method is used to deregister an existing data source. The data source to be deregistered refers to the existing data source that needs to be deregistered.

[0048] Optionally, the data cancellation request carries information for identifying the data source to be cancelled, such as a data source identifier of the data source to be cancelled. The data source to be cancelled can be determined based on the data cancellation request.

[0049] There is a connection pool configured for an existing data source in the memory. When some of the existing data sources need to be deregistered, the connection pools corresponding to these data sources are deleted from the memory through the data source deregistration method.

[0050] The above technical solution provides a feasible data source deregistration solution, supports dynamic deregistration of data sources when the application is running, and improves the flexibility of data source configuration.

[0051] In an optional embodiment, the method further includes: determining the access popularity of the candidate data source based on the access record of the candidate data source; and adjusting the connection pool size of the candidate data source based on the access popularity.

[0052] Among them, the access records can reflect the usage of the candidate data source. For example, the access frequency of the candidate data source can be determined. The access records can be used to determine the access popularity. The access popularity directly reflects the usage and popularity of the data source. Generally speaking, the higher the access popularity of the candidate data source, the higher the access frequency of the candidate data source, and the more frequently it needs to establish connections with the candidate database. For candidate data sources with high access popularity, expand their corresponding connection pool. For candidate data sources with low access popularity, reduce their corresponding connection pool.

[0053] The above technical solution adjusts the connection pool size of the candidate data source based on the access popularity of the candidate data source, which is conducive to improving the resource utilization of memory and avoiding wasting memory resources.

[0054] Embodiment 2

[0055] Figure 2 This is a flow chart of a data source switching method provided according to Embodiment 2. This embodiment is further optimized on the basis of the above embodiment.

[0056] like Figure 2 As shown, the method includes:

[0057] S210 . In response to monitoring that a data access method is called, create a data access thread.

[0058] The data access thread is used to perform data access operations. Optionally, AOP technology is used to monitor the call of the data access method.

[0059] S220: Before the data access thread executes the data access method, read the annotation associated with the data access method.

[0060] After the data access thread is started, it reads and processes the annotations associated with the data access method and then performs the data access operation. Based on the annotations associated with the data access method, it can be determined whether the data access method involves switching of the specified data source.

[0061] S230: If the annotation marks a thread-local variable, read the data source identifier stored in the thread-local variable in the data access thread.

[0062] The annotation marks the thread local variable, indicating that the data access method involves switching of the specified data source, so the data source identifier stored in the thread local variable in the data access thread is read. Among them, the thread local variable is used to store the data source identifier in the data access thread.

[0063] Using thread-local variables to store data source identifiers ensures that each data access thread uses an independent context, which can ensure the isolation between data access threads. This can handle concurrent access scenarios where multiple data access threads access a data source at the same time, avoiding data source conflicts and confusion.

[0064] S240: Determine a target data source to be switched from at least two candidate data sources based on the data source identifier.

[0065] The data source identifier is matched with the data source identifier of the candidate data source, and the candidate data source that matches the data source identifier is determined as the target data source.

[0066] S250: Based on the connection pool configured for the target data source in the memory, access the target data source to switch from the initial data source to the target data source.

[0067] The candidate data source is pre-registered using a data source registration method, and the data source registration method is an operation in a data source management and routing class.

[0068] Optionally, after the data access thread completes the data access operation, the AOP technology is used to restore the initial data source, which can avoid affecting subsequent operations.

[0069] The technical solution of the present application, by setting thread-local variables, stores the data source identifier in the data access thread, ensures that each data access thread uses an independent context, and can ensure the isolation between data access threads. This can cope with the situation in concurrent access scenarios where multiple data access threads access a data source at the same time, and can avoid data source conflicts and confusion. The present application defines data source management and routing classes, and uses the data registration method defined in the data source management and routing classes to achieve dynamic registration of new data sources when the application is running. AOP technology is used to add annotations to data access methods, specify which data source the data access method uses, and use AOP technology to switch the data source when the data access method is executed, realizing method-level data source switching, improving the flexibility of data source switching and the efficiency of data source switching.

[0070] In an optional embodiment, in response to monitoring a data access method being called, a target data source to be switched is determined from at least two candidate data sources based on an annotation associated with the data access method, and further includes: if the annotation does not mark a thread local variable, a default data source is determined as the target data source to be switched.

[0071] If the annotation does not mark the thread local variable, it means that the data access method does not involve the switching of the specified data source, and the default data source is used to determine the target data source to be switched.

[0072] The above technical solution provides a feasible data source switching solution for switching scenarios that do not involve a designated data source, which is beneficial to improving the applicability of the data source switching method.

[0073] The data source switching method provided in the embodiment of the present application is applicable to the case where an architecture supporting AOP technology is used for application development. For example, Spring Boot is used for application development. When Spring Boot is used for application development, the data source management and routing class can be the DataSourceManager class, which supports dynamic registration of new data sources through specific APIs when the application is running. The DataSourceManager class provides at least a data source registration method, a data source deregistration method, a data source setting method, and a data source clearing method.

[0074] Among them, the data source registration method is used to register a new data source; the data source cancellation method is used to cancel an existing data source; the data source setting method is used to set the data source used by the data access thread; the data source clearing method is used to clear the data source used by the data access thread. Using the data source management and routing classes, you can dynamically manage the data source when the application is running.

[0075] Embodiment 3

[0076] Figure 3 This is a structural diagram of a data source switching device provided in Example 3 of the present application. This embodiment can be applied to situations where an application switches between multiple data sources. The device can be implemented by software and / or hardware and can be integrated into electronic devices such as smart terminals.

[0077] like Figure 3 As shown, the device may include:

[0078] A target data source determination module 310 is configured to determine, in response to monitoring that a data access method is called, a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method;

[0079] A target data source access module 320, configured to access the target data source based on a connection pool configured for the target data source in a memory to switch from an initial data source to the target data source;

[0080] The candidate data source is pre-registered using a data source registration method, and the data source registration method is an operation in a data source management and routing class.

[0081] The technical solution of the embodiment of the present application, by constructing a data source management and routing class, adopting the data source registration method in the data source management and routing class, registering candidate data sources, and supporting dynamic registration of data sources when the application is running. The present application adopts aspect-oriented programming technology to add annotations to the data access method, specifies the target data source to be switched among at least two candidate data sources, and switches access to the target data source from the initial data source to the target data source based on the connection pool configured for the target data source in the memory, realizing method-level data source switching when the application is running, improving the flexibility of data source switching and the efficiency of data source switching.

[0082] Optionally, the target data source determination module 310 includes: a thread creation submodule, used to create a data access thread in response to monitoring that a data access method is called; an annotation reading submodule, used to read the annotation associated with the data access method before the data access thread executes the data access method; a data source identifier reading submodule, used to read the data source identifier stored in the thread local variable in the data access thread if the annotation marks the thread local variable; and a target data source determination submodule, used to determine the target data source to be switched from at least two candidate data sources based on the data source identifier.

[0083] Optionally, the target data source determination module 310 is further configured to determine a default data source as the target data source to be switched if the annotation does not mark the thread local variable.

[0084] Optionally, the target data source access module 320 includes: a connection pool determination submodule, used to determine the connection pool configured for the target data source in the memory; a target data source access submodule, used to establish a connection with the target data source based on the connection object in the connection pool to access the target data source.

[0085] Optionally, the device 300 also includes: a connection information acquisition module, which is used to call the data source registration method in response to receiving a data source registration request, and obtain the connection information of the data source to be added through the data source registration method; a connection object generation module, which is used to create a connection pool for the data source to be added in the memory, and generate a connection object for the data source to be added based on the connection information; a connection object adding module, which is used to add the connection object created for the data source to be added to the connection pool of the data source to be added.

[0086] Optionally, the device 300 also includes: a data source deregistration determination module, which is used to determine the data source to be deregistered in response to receiving a data source deregistration request; a connection pool deletion module, which is used to call a data source deregistration method to delete the connection pool created for the data source to be deregistered from the memory; wherein the data source deregistration method is an operation in the data source management and routing class.

[0087] Optionally, the device further includes: an access heat determination module, used to determine the access heat of the candidate data source based on the access record of the candidate data source; and a connection object adjustment module, used to adjust the connection pool of the candidate data source based on the access heat.

[0088] The data source switching device provided in the embodiment of the invention can execute the data source switching method provided in any embodiment of the present application, and has the corresponding performance modules and beneficial effects for executing the data source switching method.

[0089] Embodiment 4

[0090] According to an embodiment of the present application, the present application also provides an electronic device, a readable storage medium and a computer program product.

[0091] Figure 4 The schematic diagram of the structure of the electronic device 410 of the embodiment that can be used to implement is shown. The electronic device 410 includes at least one processor 411, and a memory connected to the at least one processor 411 in communication, such as a read-only memory (ROM) 412, a random access memory (RAM) 413, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 411 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 412 or the computer program loaded from the storage unit 418 to the random access memory (RAM) 413. In the RAM413, various programs and data required for the operation of the electronic device 410 can also be stored. The processor 411, the ROM 412, and the RAM413 are connected to each other via a bus 414. An input / output (I / O) interface 415 is also connected to the bus 414.

[0092] Multiple components in the electronic device 410 are connected to the I / O interface 415, including: an input unit 416, such as a keyboard, a mouse, etc.; an output unit 417, such as various types of displays, speakers, etc.; a storage unit 418, such as a disk, an optical disk, etc.; and a communication unit 419, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 419 allows the electronic device 410 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0093] The processor 411 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 411 executes the various methods and processes described above, such as a data source switching method.

[0094] In some embodiments, the data source switching method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 418. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 410 via the ROM 412 and / or the communication unit 419. When the computer program is loaded into the RAM 413 and executed by the processor 411, one or more steps of the data source switching method described above may be performed. Alternatively, in other embodiments, the processor 411 may be configured to perform the data source switching method in any other appropriate manner (e.g., by means of firmware).

[0095] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0096] The computer programs for implementing the methods of the present application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data source switching device, so that when the computer programs are executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer programs may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0097] In the context of the present application, a computer readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device or equipment. A computer readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer readable storage medium may be a machine readable signal medium. A more specific example of a machine readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0098] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0099] The systems and techniques described herein may be implemented in a computing system that includes a backend component (e.g., as a data source switching server), or a computing system that includes a middleware component (e.g., an application server), or a computing system that includes a frontend component (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0100] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0101] The embodiment of the present application also discloses a computer program product, which includes a computer program, and when the computer program is executed by a processor, the data source switching method provided in any embodiment of the present application is implemented. The program product and the data source switching method disclosed in each embodiment of the present application belong to the same inventive concept, so it will not be repeated here.

[0102] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution of this application can be achieved, and this document is not limited here.

[0103] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.

Claims

1. A data source switching method, characterized in that: The method comprises: In response to monitoring that a data access method is called, determining a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method; Based on the connection pool configured for the target data source in the memory, access the target data source to switch from the initial data source to the target data source; The candidate data source is pre-registered using a data source registration method, and the data source registration method is an operation in a data source management and routing class.

2. The method according to claim 1, characterized in that In response to monitoring that a data access method is called, determining a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method includes: In response to monitoring that a data access method is called, creating a data access thread; Before the data access thread executes the data access method, reading an annotation associated with the data access method; If the annotation marks a thread-local variable, reading a data source identifier stored in the thread-local variable in the data access thread; Based on the data source identifier, a target data source to be switched is determined from at least two candidate data sources.

3. The method according to claim 2, characterized in that In response to monitoring that a data access method is called, determining a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method, further comprising: If the annotation does not mark the thread local variable, the default data source is determined as the target data source to be switched.

4. The method according to claim 1, wherein accessing the target data source based on the connection pool configured for the target data source in the memory comprises: In memory, determining a connection pool configured for the target data source; Based on the connection objects in the connection pool, a connection is established with the target data source to access the target data source.

5. The method according to claim 1, characterized in that The method further comprises: In response to receiving the data source registration request, calling the data source registration method, and obtaining connection information of the data source to be added through the data source registration method; Creating a connection pool for the data source to be added in the memory, and generating a connection object for the data source to be added based on the connection information; The connection object created for the data source to be added is added to the connection pool of the data source to be added.

6. The method according to claim 1, characterized in that The method further comprises: In response to receiving a data source deregistration request, determining a data source to be deregistered; Calling a data source deregistration method to delete the connection pool created for the data source to be deregistered from the memory; The data source deregistration method is an operation in the data source management and routing classes.

7. The method according to claim 1, characterized in that The method further comprises: Determining the access popularity of the candidate data source based on the access record of the candidate data source; Based on the access popularity, the connection pool size of the candidate data source is adjusted.

8. A data source switching device, characterized in that: The device comprises: A target data source determination module, configured to determine, in response to monitoring that a data access method is called, a target data source to be switched from at least two candidate data sources based on an annotation associated with the data access method; A target data source access module, configured to access the target data source based on a connection pool configured for the target data source in a memory to switch from an initial data source to the target data source; The candidate data source is pre-registered using a data source registration method, and the data source registration method is an operation in a data source management and routing class.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the data source switching method according to any one of claims 1 to 7 is implemented.

10. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the data source switching method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • System and method for dynamic switching of data source registration

    CN120336293A

  • A system and method for dynamic switching of data source registration

    CN120336293B