Database switching method and device, computer equipment, readable storage medium and program product

By dynamically switching data source configuration and connection pools, seamless switching of multiple databases is achieved, solving the problem of large-scale modification and testing of traditional database switching, improving project flexibility and reducing development and maintenance costs.

CN119396367APending Publication Date: 2025-02-07SHENZHEN COMTOP INFORMATION TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411529421.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

Traditional projects require a lot of modification and testing work when replacing databases, resulting in very high development and maintenance costs.

Method used

By identifying the type of database to be switched, dynamically switch the data source configuration, obtain the data source corresponding to the database type, and determine the database dialect class and data access object through the data source, determine the corresponding connection pool from the connection pool configuration file, Complete the database switching.

Benefits of technology

It realizes seamless switching of multiple databases without modifying business logic, improves the flexibility of business projects, and reduces development and maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396367A_ABST
    Figure CN119396367A_ABST
Patent Text Reader

Abstract

The invention relates to a database switching method and device, computer equipment, a computer readable storage medium and a computer program product. The method comprises the following steps: identifying the type of a to-be-switched database; according to the type, dynamically switching data source configuration to obtain a data source corresponding to the type; the data source is a connection path and points to the database to be switched; and determining a database dialect class and a data access object corresponding to the type through the data source, and determining a corresponding connection pool from a connection pool configuration file to complete database switching. By adopting the method, the types of the databases can be seamlessly switched, the flexibility of business items is improved, and the development and maintenance cost of the business items is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a database switching method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art

[0002] With the advent of the big data era, the old management model of traditional enterprises has been severely challenged. Nowadays, enterprises are constantly undergoing new changes in management. If modern enterprises want to survive and develop in the fierce competition, they need to constantly innovate their management model.

[0003] In the process of software development, we often have to face the situation where different customers use different database systems.

[0004] Traditional projects often require hard-coding database connections and SQL (Structured Query Language) statements in the code, which results in a lot of modification and testing work when the project changes the database, and the cost of development and maintenance is very high. Summary of the invention

[0005] Based on this, it is necessary to provide a database switching method, device, computer equipment, computer-readable storage medium and computer program product that can reduce project development and maintenance costs in response to the above technical problems.

[0006] In a first aspect, the present application provides a database switching method, comprising:

[0007] Identify the type of database to be switched;

[0008] According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0009] The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

[0010] In one embodiment, the process of generating the connection pool configuration file includes:

[0011] Determine the maximum number of connections, initial number of connections, and timeout duration for business systems that need to connect to the database;

[0012] A connection pool configuration file is generated according to the maximum number of connections, the initial number of connections and the timeout duration.

[0013] In one embodiment, the method further comprises:

[0014] When the business system processes data in the database, it captures exceptions in the processing process, encapsulates the exceptions, and converts them into preset exception types for reporting and automatic warning.

[0015] In one embodiment, before identifying the type of the database to be switched, the method includes:

[0016] Identify the anomalies generated during the operation of the database before the switch, and generate corresponding log information based on the identified anomalies.

[0017] In one embodiment, before identifying the type of the database to be switched, the method includes:

[0018] Define the database operation interface;

[0019] During the operation of the database before switching, the corresponding database dialect class is automatically adjusted according to the database type through the dialect parser of the structured query language.

[0020] In one embodiment, dynamically switching the data source configuration according to the type includes:

[0021] According to the type, a data source configuration file is determined in a configuration file library, and the data source configuration is switched based on the data source configuration file. The configuration file library contains data source configuration files corresponding to different database types.

[0022] In a second aspect, the present application also provides a database switching device, including:

[0023] An identification module, used to identify the type of database to be switched;

[0024] A switching module, used to dynamically switch the data source configuration according to the type, and obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0025] The determination module is used to determine the database dialect class and data access object corresponding to the type through the data source, and determine the corresponding connection pool from the connection pool configuration file to complete the database switching.

[0026] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0027] Identify the type of database to be switched;

[0028] According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0029] The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

[0030] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:

[0031] Identify the type of database to be switched;

[0032] According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0033] The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

[0034] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:

[0035] Identify the type of database to be switched;

[0036] According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0037] The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

[0038] The above-mentioned database switching method, device, computer equipment, computer-readable storage medium and computer program product first identify the type of database to be switched; according to the type of database to be switched, dynamically switch the data source configuration to obtain the data source corresponding to the type of database to be switched; the data source is a connection path pointing to the database to be switched; through the corresponding data source, determine the database dialect class and data access object corresponding to the type of database to be switched, and determine the corresponding connection pool from the connection pool configuration file to complete the database switching. In this way, by identifying the type of database to be switched, a series of configurations are switched to achieve seamless switching of multiple databases, and the database can be switched without modifying the business logic, which improves the flexibility of business projects and reduces the cost of business project development and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions 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 related drawings can be obtained based on these drawings without paying creative work.

[0040] FIG1 is a schematic diagram of a flow chart of a database switching method in one embodiment;

[0041] FIG2 is a structural block diagram of a database switching device in one embodiment;

[0042] FIG. 3 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0044] In one embodiment, as shown in FIG1 , a database switching method is provided. This embodiment is illustrated by applying the method to a terminal. It is understandable that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0045] Step 102: Identify the type of database to be switched.

[0046] Among them, the types of databases include relational databases, non-relational databases, key-value storage databases and other databases.

[0047] In some embodiments, the terminal may identify the type of database to be switched through a code.

[0048] Step 104, dynamically switch the data source configuration according to the type, and obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0049] In some embodiments, the terminal dynamically switches the configuration of the data source according to the type of the database to be switched, and obtains a data source corresponding to the type of the data source to be switched.

[0050] Furthermore, the terminal may access the information in the database to be switched through the determined data source.

[0051] Step 106, determine the database dialect class and data access object corresponding to the type through the data source, and determine the corresponding connection pool from the connection pool configuration file to complete the database switch.

[0052] The database dialect class is a specific implementation class for handling different databases. The data access object is the entity type corresponding to different databases. The connection pool is a mechanism for managing and maintaining database connections.

[0053] In some implementations, the terminal can determine the database dialect class and data access object corresponding to the database to be switched through the determined data source, and determine the corresponding connection pool from the connection pool configuration file, thereby completing the database switch and officially starting to use the database to be switched.

[0054] In the above database switching method, the type of database to be switched is identified; according to the type of database to be switched, the data source configuration is dynamically switched to obtain the data source corresponding to the type of database to be switched; the data source is a connection path pointing to the database to be switched; through the corresponding data source, the database dialect class and data access object corresponding to the type of database to be switched are determined, and the corresponding connection pool is determined from the connection pool configuration file to complete the database switching. In this way, by identifying the type of database to be switched, a series of configurations are switched to achieve seamless switching of multiple databases, and the database can be switched without modifying the business logic, which improves the flexibility of the business project and reduces the cost of business project development and maintenance.

[0055] In an exemplary embodiment, the process of generating a connection pool configuration file includes: determining the maximum number of connections, the initial number of connections and the timeout duration of a business system that needs to connect to a database when connecting to the database; generating a connection pool configuration file based on the maximum number of connections, the initial number of connections and the timeout duration.

[0056] In actual implementation, the terminal will add C3P0 as a database connection pool implementation to the business project before the database is switched, combine the C3P0 (an open source database connection pool library) connection pool with the data source, and configure an independent connection pool for each data source.

[0057] Furthermore, the terminal configures multiple data sources, obtains different data source connection objects through ComboPooledDataSource (the core class of the C3P0 database connection pool, used to manage database connections), and accesses different databases through different data source connection objects. Among them, the specific configuration file for connection pool switching includes the maximum number of connections, the initial number of connections, the timeout duration, etc.

[0058] In the above embodiment, by integrating an open source database connection pool library technology, the management of connection resources by the database is optimized and the access efficiency of the database is improved.

[0059] In some exemplary embodiments, the database switching method also includes capturing exceptions during the process of the business system processing data in the database, encapsulating the exceptions, and converting them into preset exception types for reporting and automatic warning.

[0060] In actual implementation, when the business system processes data in the database, the terminal uses the try-catch block (a code structure used to capture and handle exceptions) to capture exceptions during the execution process, encapsulate the exceptions, and convert them into preset exception types for reporting and automatic warning. Different database type exceptions are encapsulated into different exception types and returned to the terminal. Among them, the exception types include SQLException, DataAccessException, PSQLException, MySQLSyntaxErrorException, ConnectionException, etc.

[0061] In the above embodiment, by real-time monitoring of the data processing process, errors in the operation process can be discovered in time, so as to proceed to the next step of processing.

[0062] In some exemplary embodiments, before identifying the type of the database to be switched, the method includes: identifying anomalies generated during the operation of the database before the switch, and generating corresponding log information based on the identified anomalies.

[0063] In actual implementation, the terminal will identify the exceptions generated during the operation of the database before the switch, and use the log framework (such as Log4j2 (log output plug-in), SLF4J (Simple Log Facade), etc.) to record key information, including the executed SQL statement, parameters, execution time, exception information, etc.

[0064] In the above embodiment, by recording the log information of the exceptions generated during the operation, it is helpful to track the problem.

[0065] In some exemplary embodiments, before identifying the type of database to be switched, the method includes: defining the operation interface of the database; and automatically adjusting the corresponding database dialect class according to the database type through a dialect parser of a structured query language during the operation of the database before switching.

[0066] In actual implementation, the terminal will define a unified database operation interface, such as adding, deleting, modifying, and querying. The interface should include basic database operation methods, such as save(T entity) (save a single entity object to the database), delete(T entity) (delete through the entity object), update(T entity) (update the corresponding record of a given entity object in the database), findById(ID id) (used to retrieve the entity object according to the given id), findAll() (used to search for all strings that match the regular expression in the entire string and return them in the form of a list), etc.

[0067] In some embodiments, the terminal uses an SQL template or a builder pattern to establish a dialect parser, and through the dialect parser, automatically adjusts the corresponding database dialect class according to the database type.

[0068] In the above implementation, the database dialect class corresponding to the database type is dynamically switched through a unified operation interface, which reduces the cost of switching databases and speeds up the switching rate.

[0069] In some exemplary embodiments, the data source configuration is dynamically switched according to the type, including: determining the data source configuration file in the configuration file library according to the type, and switching the data source configuration based on the data source configuration file, wherein the configuration file library contains data source configuration files corresponding to different database types.

[0070] In actual implementation, the terminal will establish a data source configuration file library before switching the database type to support the configuration of multiple data sources, including database type, URL (Uniform Resource Locator of the database), user name, password, etc.

[0071] Furthermore, the terminal uses Apache Commons DBCP (an open source project that implements pooled management of database connections) or Spring (an open source application development framework that aims to simplify the development of enterprise-level applications)'s AbstractRoutingDataSource (a class in the Spring framework that implements dynamic data source routing) to manage multiple data sources and dynamically switch data sources based on specific keys (such as database name or tenant ID).

[0072] In the above embodiment, the data source corresponding to the database is quickly switched through a specific key, thereby improving the efficiency of database switching.

[0073] To explain the database switching method in the present application in detail, an embodiment is used for explanation below. By way of example, the present application is explained with a specific database switching method.

[0074] Before switching the database, the terminal will add C3P0 as a database connection pool implementation to the business project, combine the C3P0 (an open source database connection pool library) connection pool with the data source, and configure an independent connection pool for each data source.

[0075] Furthermore, the terminal configures multiple data sources, obtains different data source connection objects through ComboPooledDataSource (the core class of the C3P0 database connection pool, used to manage database connections), and accesses different databases through different data source connection objects. Among them, the specific configuration file for connection pool switching includes the maximum number of connections, the initial number of connections, the timeout duration, etc.

[0076] In actual implementation, the terminal will establish a data source configuration file library before switching the database type to support the configuration of multiple data sources, including database type, URL (Uniform Resource Locator of the database), user name, password, etc.

[0077] Furthermore, the terminal uses Apache Commons DBCP (an open source project that implements pooled management of database connections) or Spring (an open source application development framework that aims to simplify the development of enterprise-level applications)'s AbstractRoutingDataSource (a class in the Spring framework that implements dynamic data source routing) to manage multiple data sources and dynamically switch data sources based on specific keys (such as database name or tenant ID).

[0078] The terminal will define a unified database operation interface, such as adding, deleting, modifying, and querying. The interface should include basic database operation methods, such as save(T entity) (save a single entity object to the database), delete(T entity) (delete through the entity object), update(T entity) (update the corresponding record of a given entity object in the database), findById(ID id) (used to retrieve an entity object based on a given id), findAll() (used to search for all strings that match a regular expression in the entire string and return them as a list), etc.

[0079] The terminal uses the SQL template or constructor mode to establish a dialect parser, and through the dialect parser, automatically adjusts the corresponding database dialect class according to the database type.

[0080] The terminal will identify the type of the database to be switched through the code, and dynamically switch the configuration of the data source according to the type of the database to be switched to obtain a data source corresponding to the type of the data source to be switched.

[0081] Furthermore, the terminal may access the information in the database to be switched through the determined data source.

[0082] The terminal can determine the database dialect class and data access object corresponding to the database to be switched through the determined data source, and determine the corresponding connection pool from the connection pool configuration file, thereby completing the database switch and officially starting to use the database to be switched.

[0083] When the business system processes the data in the database, the terminal uses the try-catch block (a code structure used to capture and handle exceptions) to capture exceptions during the execution process, encapsulate the exceptions, and convert them into preset exception types for reporting and automatic warning. Different database type exceptions are encapsulated into different exception types and returned to the terminal. Among them, the exception types include SQLException, DataAccessException, PSQLException, MySQLSyntaxErrorException, ConnectionException, etc.

[0084] The terminal will identify the exceptions generated during the operation of the database before the switch, and use the log framework (such as Log4j2 (log output plug-in), SLF4J (Simple Log Facade), etc.) to record key information, including the executed SQL statement, parameters, execution time, exception information, etc.

[0085] This application achieves seamless switching of multiple databases by defining a unified data interface in advance, implementing dynamic configuration of data sources, developing SQL dialect parsers and other technical means. Databases can be switched without modifying business logic, which improves the flexibility of business projects and reduces the cost of business project development and maintenance.

[0086] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0087] Based on the same inventive concept, the embodiment of the present application also provides a database switching device for implementing the database switching method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more database switching device embodiments provided below can refer to the limitations on the database switching method above, and will not be repeated here.

[0088] In an exemplary embodiment, as shown in FIG2 , a database switching device is provided, including: an identification module 201, a switching module 202 and a determination module 203, wherein:

[0089] An identification module, used to identify the type of database to be switched;

[0090] A switching module, used to dynamically switch the data source configuration according to the type, and obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0091] The determination module is used to determine the database dialect class and data access object corresponding to the type through the data source, and determine the corresponding connection pool from the connection pool configuration file to complete the database switching.

[0092] In some embodiments, the device also includes a generation module for determining the maximum number of connections, initial number of connections and timeout duration of a business system that needs to connect to a database when connecting to the database; and generating a connection pool configuration file based on the maximum number of connections, initial number of connections and timeout duration.

[0093] In some embodiments, the device also includes an early warning module, which is used to capture exceptions in the process of processing data in the database by the business system, encapsulate the exceptions, and convert them into preset exception types for reporting and automatic early warning.

[0094] In some embodiments, the device further includes an identification module for identifying anomalies generated during the operation of the database before switching, and generating corresponding log information based on the identified anomalies.

[0095] In some embodiments, the device further includes an adjustment module for defining an operation interface of the database; during the operation of the database before switching, the corresponding database dialect class is automatically adjusted according to the database type through a dialect parser of the structured query language.

[0096] In some embodiments, the device also includes a switching module for determining a data source configuration file in a configuration file library according to the type, and switching the data source configuration based on the data source configuration file, wherein the configuration file library contains data source configuration files corresponding to different database types.

[0097] Each module in the above-mentioned database switching device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0098] In an exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG3. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data to be stored in the database. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a database switching method is implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0099] Those skilled in the art will understand that the structure shown in FIG. 3 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0100] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0101] Identify the type of database to be switched;

[0102] According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0103] The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

[0104] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0105] Identify the type of database to be switched;

[0106] According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0107] The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

[0108] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:

[0109] Identify the type of database to be switched;

[0110] According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched;

[0111] The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

[0112] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0113] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0114] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0115] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A database switching method, characterized in that: The method comprises: Identify the type of database to be switched; According to the type, dynamically switch the data source configuration to obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched; The database dialect class and data access object corresponding to the type are determined through the data source, and the corresponding connection pool is determined from the connection pool configuration file to complete the switching of the database.

2. The method according to claim 1, characterized in that The generation process of the connection pool configuration file includes: Determine the maximum number of connections, initial number of connections, and timeout duration for business systems that need to connect to the database; A connection pool configuration file is generated according to the maximum number of connections, the initial number of connections and the timeout duration.

3. The method according to claim 1, characterized in that The method further comprises: When the business system processes data in the database, it captures exceptions in the processing process, encapsulates the exceptions, and converts them into preset exception types for reporting and automatic warning.

4. The method according to claim 1, characterized in that: Before identifying the type of the database to be switched, the method includes: Identify the anomalies generated during the operation of the database before the switch, and generate corresponding log information based on the identified anomalies.

5. The method according to claim 1, characterized in that: Before identifying the type of the database to be switched, the method includes: Define the database operation interface; During the operation of the database before switching, the dialect parser of the structured query language automatically adjusts the corresponding database dialect class according to the database type.

6. The method according to claim 1, characterized in that The dynamically switching the data source configuration according to the type includes: According to the type, a data source configuration file is determined in a configuration file library, and the data source configuration is switched based on the data source configuration file. The configuration file library contains data source configuration files corresponding to different database types.

7. A database switching device, characterized in that: The device comprises: An identification module, used to identify the type of database to be switched; A switching module, used to dynamically switch the data source configuration according to the type, and obtain a data source corresponding to the type; the data source is a connection path pointing to the database to be switched; The determination module is used to determine the database dialect class and data access object corresponding to the type through the data source, and determine the corresponding connection pool from the connection pool configuration file to complete the database switching.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

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

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Multi-version dynamically extensible data source method and device, terminal and storage medium

    CN120315681A