Relational database switching method and device and electronic equipment

By loading and replacing SQL statements when the project is started, and using the configuration information of the Mybatis persistence layer framework, the problem of low efficiency of relational database switching in the existing technology is solved, and efficient database switching and user experience improvement are achieved.

CN118747202APending Publication Date: 2024-10-08TIANJIN ZHUOLANG KUNLUN CLOUD SOFTWARE TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410894672.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-10-08

AI Technical Summary

Technical Problem

The existing relational database switching method is inefficient and slow in response, resulting in poor user experience. Especially when multiple relational databases need to be supported, developers need to manually modify SQL statements, and the interceptor method is difficult to use in complex situations. Will result in increased response time.

Method used

When the target project starts, the pre-stored original SQL statement is loaded into the data structure, replaced according to the configuration information of the Mybatis persistence layer framework, and the target SQL statement is generated to achieve database switching. The method includes loading modules, generating modules and replacing modules, using automated construction tools and configuration information to achieve relational database switching between different projects.

Benefits of technology

It improves the efficiency of relational database switching, reduces the need for manual modification, improves user experience, simplifies the database switching process and reduces labor costs through the use of automated build tools and configuration information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118747202A_ABST
    Figure CN118747202A_ABST
Patent Text Reader

Abstract

The invention provides a relational database switching method and device and electronic equipment, and relates to the technical field of computers.The method comprises the steps that when a target project is started, an original SQL statement pre-stored in a Mybatis persistent layer framework is loaded into a data structure of the target project; the original SQL statement is a statement supported by an original relational database; according to configuration information stored in the Mybatis persistent layer framework, replacing a target statement in the original SQL statement to generate a target SQL statement; replacing the target SQL statement with the original SQL statement loaded into the data structure to realize database switching supported by the target project; through the method, the technical problems of low switching efficiency and slow response in the prior art are relieved, and the technical effects of improving the switching efficiency of the relational database and improving the user experience are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a relational database switching method, device and electronic equipment. Background Art

[0002] During the project development phase, developers can develop structured query language (SQL) statements based on the selected relational database. However, during the sales phase, due to the complexity of customer relationships, the project usually needs to support multiple relational databases, so the SQL statements need to be modified to meet the needs of supporting multiple relational databases. The current common methods for modifying SQL statements include: directly copying the XML file of MyBatis and replacing the SQL fragment. This method requires manual modification and adjustment of the existing SQL statement, and the same SQL fragment needs to be modified repeatedly in subsequent development, which is inefficient and error-prone; or you can intercept the statement before MyBatis executes SQL and replace the SQL fragment according to the rules, but intercepting through the interceptor will cause each SQL statement executed by the project to be intercepted. When the number of replacement rules increases or the SQL statement is complex, the replacement time is greatly increased, the overall response of the request is slowed down, and the user experience is seriously affected.

[0003] The above methods of modifying SQL statements to implement relational database switching all have certain defects. That is, the existing methods of switching relational databases have technical problems of low switching efficiency and slow response. Summary of the invention

[0004] The object of the present invention is to provide a relational database switching method, device and electronic device to alleviate the technical problems of low switching efficiency and slow response in the prior art.

[0005] In the first aspect, an embodiment of the present invention provides a relational database switching method, the method comprising: when a target project is started, loading an original SQL statement pre-stored in a Mybatis persistence layer framework into a data structure of the target project; the original SQL statement is a statement supported by the original relational database; according to the configuration information stored in the Mybatis persistence layer framework, replacing the target statement in the original SQL statement to generate a target SQL statement; the target SQL statement is a statement supported by the target relational database to be switched to the target project; replacing the target SQL statement with the original SQL statement loaded into the data structure to achieve database switching supported by the target project.

[0006] In some optional implementations, the method further includes: parsing the original SQL statement to obtain a complete original SQL statement.

[0007] In some optional implementations, the target statement in the above original SQL statement is replaced according to the configuration information stored in the Mybatis persistence layer framework to generate a target SQL statement, including: determining the target statement in the above complete original SQL statement according to the configuration information stored in the Mybatis persistence layer framework; the above target statement is a characteristic statement in the above original relational database; and replacing the above target statement to generate a target SQL statement.

[0008] In some optional implementations, the above configuration information includes database connection parameters and configuration replacement rules; the above database connection parameters are used to indicate the type of supported relational databases; the above configuration replacement rules are used to indicate the correspondence between statements in different relational databases for implementing the same functions.

[0009] In some optional implementations, the method further includes: using an automated build tool to reference Maven coordinates and project configuration information to implement relational database switching for different projects; the project configuration information includes: project configuration, file configuration, and database table storage replacement rules.

[0010] In the second aspect, an embodiment of the present invention provides a relational database switching device, which includes: a loading module, which is used to load the original SQL statement pre-stored in the Mybatis persistence layer framework into the data structure of the above-mentioned target project when the target project is started; the above-mentioned original SQL statement is a statement supported by the original relational database; a generation module, which is used to replace the target statement in the above-mentioned original SQL statement according to the configuration information stored in the Mybatis persistence layer framework to generate a target SQL statement; the above-mentioned target SQL statement is a statement supported by the target relational database to be switched to the above-mentioned target project; a replacement module, which is used to replace the above-mentioned target SQL statement with the above-mentioned original SQL statement loaded into the above-mentioned data structure, so as to realize the database switching supported by the above-mentioned target project.

[0011] In some optional implementations, the apparatus further includes: a parsing module, configured to parse the original SQL statement to obtain a complete original SQL statement.

[0012] In some optional implementations, the above-mentioned device also includes: a reference module, which is used to use an automated construction tool to reference Maven coordinates and project configuration information to achieve relational database switching between different projects; the configuration information of the above-mentioned project includes: project configuration, file configuration and replacement rules for database table storage.

[0013] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, and when the processor executes the computer program, the steps of any one of the methods described in the first aspect are implemented.

[0014] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores machine-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to execute any method described in the first aspect above.

[0015] The present invention provides a relational database switching method, device and electronic device. The method comprises: when a target project is started, an original SQL statement pre-stored in a Mybatis persistence layer framework is loaded into a data structure of the target project; then, according to configuration information stored in the Mybatis persistence layer framework, a target statement in the original SQL statement is replaced to generate a target SQL statement; finally, the target SQL statement is replaced with the original SQL statement loaded into the data structure to realize database switching supported by the target project, thereby alleviating the technical problems of low switching efficiency and slow response existing in the prior art, and realizing the technical effect of improving the efficiency of relational database switching and enhancing user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0017] Figure 1 A schematic diagram of a flow chart of a relational database switching method provided by an embodiment of the present invention;

[0018] Figure 2 A schematic diagram of a flow chart of a relational database switching method provided by an embodiment of the present invention;

[0019] Figure 3 A schematic diagram of the structure of a relational database switching device provided by an embodiment of the present invention;

[0020] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0022] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0023] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings. Some embodiments of the present invention are described in detail below in conjunction with the drawings. The following embodiments and features in the embodiments can be combined with each other without conflict.

[0024] A relational database is a database that uses a relational model to organize data. It stores data in the form of rows and columns to facilitate user understanding. This series of rows and columns in a relational database is called a table, and a group of tables constitutes a database. Users retrieve data from the database through queries, and a query is an execution code used to limit certain areas in the database. A relational database uses structured query language (i.e. SQL) to query the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and the relationships between them.

[0025] During the project development phase, developers can develop Structured Query Language (SQL) statements based on the selected relational database. However, during the sales phase, due to the complexity of customer relationships (e.g., only domestic databases can be used, relational databases already available in the customer environment must be used, etc.), projects are usually required to support multiple relational databases. Therefore, SQL statements need to be modified to meet the needs of supporting multiple relational databases.

[0026] At present, there are two common methods for modifying SQL statements: First, directly copy the XML file of MyBatis, then modify the SQL statement (i.e. replace the SQL fragment), and then integrate it by pointing to the XML files in different files through different configurations. This method requires manual modification and adjustment of existing SQL statements, which is time-consuming and error-prone. In subsequent development, the same SQL fragment (such as replacing the same function, because it belongs to two SQL statements) needs to be modified repeatedly.

[0027] The second method is to intercept the statements before MyBatis executes SQL through extensions, replace SQL fragments according to rules, and return the replaced SQL to MyBatis for execution. However, interception through interceptors will cause each SQL executed by the project to be intercepted. When there are more replacement rules or more complex SQL statements, the replacement time will increase, resulting in a slower overall response to requests and affecting user experience. In addition, relational database access is the data source of most systems and needs to be accessed frequently. As the number of interception services increases, the impact on the system will become greater and greater.

[0028] The above two existing methods of modifying SQL statements to switch relational databases both have certain defects, that is, the existing methods of switching relational databases have technical problems of low switching efficiency and slow response. Based on this, the embodiments of the present invention provide a relational database switching method, device and electronic device to solve the above problems.

[0029] To facilitate understanding of this embodiment, a relational database switching method disclosed in an embodiment of the present invention is first described in detail. Figure 1 The flowchart of a relational database switching method shown in FIG. 1 is a flowchart of a relational database switching method, which can be executed by an electronic device and mainly includes the following steps S110 to S130:

[0030] S110: When the target project is started, the original SQL statement pre-stored in the Mybatis persistence layer framework is loaded into the data structure of the target project; the original SQL statement is a statement supported by the original relational database;

[0031] Among them, the target project can be a project that originally supports relational databases, and it is necessary to switch the relational database it supports when facing different customer environments. For example, a certain target project A originally supports MySQL as the relational database. According to the needs of actual applications, the relational database supported by the target project A is switched from MySQL to Oracle database. The original SQL statement is the statement supported by MySQL database, while the target SQL statement is the statement supported by Oracle database.

[0032] The relational database switching method provided in this embodiment is applicable to Java projects of the SSM framework (Spring+SpringMVC+MyBatis). MyBatis is an excellent persistence layer framework that supports customized SQL, stored procedures, and advanced mapping. MyBatis avoids almost all JDBC codes and manual parameter settings and result set acquisition. Simple XML or annotations can be used to configure and map native information, and interfaces and Java POJOs (Plain Ordinary JavaObjects) are mapped into records in the database.

[0033] S120: According to the configuration information stored in the Mybatis persistence layer framework, the target statement in the original SQL statement is replaced to generate a target SQL statement; the target SQL statement is a statement supported by the target relational database to be switched to the target project;

[0034] In one implementation, the configuration information includes database connection parameters and configuration replacement rules; the database connection parameters are used to indicate the types of supported relational databases; the configuration replacement rules are used to indicate the correspondence between statements in different relational databases for implementing the same function.

[0035] Among them, the target statement is generally a statement with the same function in the relational database (MySQL database) originally supported by the project and in the relational database (Oracle database) to be switched later, for example: the IFNULL(name,”) statement in the MySQL database and the nvl(name,”) statement in the Oracle database, that is, statements used to implement the same function in different relational databases.

[0036] S130: Replace the target SQL statement with the original SQL statement loaded into the data structure to implement database switching supported by the target project.

[0037] The specific method of replacing the target SQL statement with the corresponding original SQL statement may be to replace keywords through regular expressions.

[0038] A relational database switching method provided by an embodiment of the present invention comprises: when a target project is started, an original SQL statement pre-stored in a Mybatis persistence layer framework is loaded into a data structure of the target project; the original SQL statement is a statement supported by the original relational database; according to configuration information stored in the Mybatis persistence layer framework, a target statement in the original SQL statement is replaced to generate a target SQL statement; the target SQL statement is replaced with the original SQL statement loaded into the data structure to realize database switching supported by the target project; this method alleviates the technical problems of low switching efficiency and slow response existing in the prior art, and achieves the technical effect of improving the efficiency of relational database switching and enhancing user experience.

[0039] In one implementation, before the above step S110, the method further includes: parsing the original SQL statement to obtain a complete original SQL statement.

[0040] Correspondingly, the above S120 replaces the target statement in the original SQL statement according to the configuration information stored in the Mybatis persistence layer framework to generate a target SQL statement, including:

[0041] (S121) determining a target statement in the complete original SQL statement according to the configuration information stored in the Mybatis persistence layer framework; the target statement is a characteristic statement in the original relational database;

[0042] Among them, the characteristic statements are generally statements with the same functions but inconsistent expressions in the original relational database and the relational database to be switched, for example: the IFNULL(name,”) statement in the MySQL database and the nvl(name,”) statement in the Oracle database.

[0043] (S122) The target statement is replaced to generate a target SQL statement. The target SQL statement at this time is actually a complete SQL statement that has completed the feature statement replacement, the target item is to be switched, and is supported by the target relational database.

[0044] In one embodiment, the method further includes: using an automated build tool to reference Maven coordinates and project configuration information to implement relational database switching between different projects; wherein the project configuration information includes: project configuration, file configuration, and database table storage replacement rules.

[0045] The coordinates in Maven are the unique identifiers of resources. Through these coordinates, the resource location can be uniquely located, so that it can support the introduction of dependencies between multiple projects and support the switching of relational databases through simple configuration.

[0046] In one embodiment, the present invention provides a relational database switching method, which quickly supports relational database switching by referencing Maven coordinates and configurations (project configuration file configuration and database table storage replacement rules). This method is executed when the project is started, see Figure 2 As shown, the specific process of this method mainly includes:

[0047] S210: Load the configured original SQL statement into the data structure;

[0048] S220: Parse the original SQL statement to obtain a complete statement of the original SQL;

[0049] S230: According to the configuration information, the original SQL statement is replaced, and the replaced target statement is replaced with the original SQL in the data structure.

[0050] Then the project is started. In other words, this method supports dynamically switching the stored SQL statements when the project starts. The main purpose is to replace the corresponding SQL statements according to the configuration file when the project starts. For example, if the configuration file is mysql replaced by oracle, the original SQL statement (the statement supported by the mysql database) is obtained, and the fragment (such as IFNULL(name,”)) is replaced with the nvl(name,”) statement supported by oracle. The key to this method is the SQL replacement supported when the project starts. The purpose of the switch is that the developer only needs to modify the database connection parameters and configure the replacement rules to change the original support for only the mysql database to support multiple relational databases.

[0051] As a specific example, the above method inherits the native Configuration (class for Mybatis to store configuration information) class (ExtendConfiguration) of Mybatis, and provides methods for operating the original data structure (SQL fragment) object and replacing the original SQL fragment;

[0052] Through the above implementation, the original SQL set written by the developer and stored in mybatis is obtained, the original SQL set is looped, and the replacement rules (such as IFNULL(name,") of mysql are replaced with the nvl(name,") statement supported by oracle, and the replaced SQL statement is replaced with the original SQL of mybatis;

[0053] Inherit SqlSessionFactoryBean (the class that persists SqlSession in an instance), and rewrite the code of its SqlSessionFactory construction method so that it calls the method provided by the ExtendConfiguration extension class mentioned above during the instantiation process to achieve the purpose of replacing Sql.

[0054] SqlSessionFactoryBean is a code for constructing SqlSessionFactory provided by mybatis. Inheriting SqlSessionFactoryBean can have its corresponding functions, which also represents an extension of it. The purpose of rewriting the code for constructing the SqlSessionFactory method is to implement an implementation that can replace the original SQL of mybatis (the default implementation does not support SQL replacement). Its main purpose is to obtain the original SQL statement (the statement supported by MySQL database) according to the configuration file when the project starts, such as replacing mysql with oracle, and replace the fragments (such as IFNULL(name,”)) with nvl(name,”) statements supported by oracle. At this time, after the project is started, it will support the Oracle database project, switching from supporting MySQL to supporting Oracle. By adding replacement rules, it can support multiple databases.

[0055] The present invention realizes switching relational databases and stores configuration replacement rules in a database, so that previous projects can be reused and completed rules can be replaced by simply referencing and configuring them between multiple projects, thereby realizing technology accumulation without multiple configurations and reducing the large amount of manpower costs generated by switching relational databases.

[0056] By using the method provided in the embodiment of the present invention to switch relational databases, the problem of manual switching by developers in the prior art is solved, which is time-consuming, labor-intensive and error-prone; the problem of previous labor results being reused between multiple projects is solved; and the strong coupling caused by relational database switching is solved, making the switching function more independent.

[0057] The above-mentioned relational database switching method provided in the embodiment of the present invention supports replacement when the project is started by extending mybatis. When the project startup is completed, all replacements have been completed, and the subsequent operation of the project will not affect the project business. Using the above-mentioned method to realize the switching of relational databases is equivalent to providing a plug-in for switching relational databases. Mybatis is extended to support dynamic switching of stored SQL statements when the project is started. Developers only need to modify the database connection parameters and configure the replacement rules to realize the original support for only MySQL database to support multiple relational databases.

[0058] In addition, the embodiment of the present invention also provides a relational database switching device, see Figure 3 As shown, the device comprises:

[0059] The loading module 310 is used to load the original SQL statement pre-stored in the Mybatis persistence layer framework into the data structure of the target project when the target project is started; the original SQL statement is a statement supported by the original relational database;

[0060] The generating module 320 is used to replace the target statement in the original SQL statement according to the configuration information stored in the Mybatis persistence layer framework, and generate a target SQL statement; the target SQL statement is a statement supported by the target relational database to be switched to the target project;

[0061] The replacement module 330 is used to replace the target SQL statement with the original SQL statement loaded into the data structure to achieve database switching supported by the target project.

[0062] In one embodiment, the above device further includes: a parsing module, configured to parse the original SQL statement to obtain a complete original SQL statement.

[0063] In one embodiment, the above-mentioned device also includes: a reference module, which is used to use an automated construction tool to reference Maven coordinates and project configuration information to achieve relational database switching between different projects; the project configuration information includes: project configuration, file configuration and replacement rules for database table storage.

[0064] The relational database switching device provided in the embodiment of the present application can be specific hardware on the device or software or firmware installed on the device. The device provided in the embodiment of the present application, its implementation principle and the technical effect produced are the same as those in the aforementioned method embodiment. For the sake of brief description, the parts not mentioned in the device embodiment can refer to the corresponding contents in the aforementioned method embodiment. Technical personnel in the relevant field can clearly understand that for the convenience and conciseness of description, the specific working processes of the systems, devices and units described above can all refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. The relational database switching device provided in the embodiment of the present application has the same technical features as the relational database switching method provided in the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.

[0065] An embodiment of the present application further provides an electronic device. Specifically, the electronic device includes a processor and a storage device. The storage device stores a computer program, and when the computer program is executed by the processor, it executes the method described in any one of the above-mentioned embodiments.

[0066] Figure 4 A structural schematic diagram of an electronic device provided in an embodiment of the present application, the electronic device 400 includes: a processor 40, a memory 41, a bus 42 and a communication interface 43, wherein the processor 40, the communication interface 43 and the memory 41 are connected via the bus 42; the processor 40 is used to execute an executable module stored in the memory 41, such as a computer program.

[0067] The memory 41 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 43 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.

[0068] The bus 42 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0069] Among them, the memory 41 is used to store programs, and the processor 40 executes the program after receiving the execution instruction. The method executed by the process definition device disclosed in any embodiment of the above-mentioned embodiment of the present invention can be applied to the processor 40 or implemented by the processor 40.

[0070] The processor 40 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 40. The above processor 40 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiments of the present invention can be directly embodied as a hardware decoding processor to execute, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 41, and the processor 40 reads the information in the memory 41 and completes the steps of the above method in combination with its hardware.

[0071] Corresponding to the above method, an embodiment of the present application also provides a computer-readable storage medium, which stores machine-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the steps of the above method.

[0072] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0073] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0074] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0075] If the functions are implemented in the form of software functional units 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 invention, in essence, 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 personal computer, electronic device, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as 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.

[0076] It should be noted that similar numbers and letters represent similar items in the accompanying drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0077] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A relational database switching method, characterized in that: include: When the target project is started, the original SQL statement pre-stored in the Mybatis persistence layer framework is loaded into the data structure of the target project; the original SQL statement is a statement supported by the original relational database; According to the configuration information stored in the Mybatis persistence layer framework, the target statement in the original SQL statement is replaced to generate a target SQL statement; the target SQL statement is a statement supported by the target relational database to be switched for the target project; The target SQL statement is replaced with the original SQL statement loaded into the data structure to implement database switching supported by the target project.

2. The relational database switching method according to claim 1, characterized in that: The method further includes: parsing the original SQL statement to obtain a complete original SQL statement.

3. The relational database switching method according to claim 2, characterized in that: According to the configuration information stored in the Mybatis persistence layer framework, the target statement in the original SQL statement is replaced to generate a target SQL statement, including: Determine the target statement in the complete original SQL statement according to the configuration information stored in the Mybatis persistence layer framework; the target statement is a characteristic statement in the original relational database; The target statement is replaced to generate a target SQL statement.

4. The relational database switching method according to claim 1, characterized in that: The configuration information includes database connection parameters and configuration replacement rules; the database connection parameters are used to indicate the type of supported relational databases; the configuration replacement rules are used to indicate the correspondence between statements in different relational databases for implementing the same function.

5. The relational database switching method according to claim 1, characterized in that: The method further comprises: The automated construction tool is used to reference Maven coordinates and project configuration information to implement relational database switching of different projects; the project configuration information includes: project configuration, file configuration and replacement rules for database table storage.

6. A relational database switching device, characterized in that: include: A loading module is used to load the original SQL statements pre-stored in the Mybatis persistence layer framework into the data structure of the target project when the target project is started; the original SQL statements are statements supported by the original relational database; A generation module, used to replace the target statement in the original SQL statement according to the configuration information stored in the Mybatis persistence layer framework, and generate a target SQL statement; the target SQL statement is a statement supported by the target relational database to be switched for the target project; A replacement module is used to replace the target SQL statement with the original SQL statement loaded into the data structure to achieve database switching supported by the target project.

7. The relational database switching device according to claim 6, characterized in that: The device also includes: a parsing module, which is used to parse the original SQL statement to obtain a complete original SQL statement.

8. The relational database switching device according to claim 6, characterized in that: The device also includes: a reference module, which is used to use the automated construction tool to reference Maven coordinates and project configuration information to achieve relational database switching of different projects; the project configuration information includes: project configuration, file configuration and database table storage replacement rules.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores machine executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to execute the method according to any one of claims 1 to 5.

Citation Information

Cited By

  • SQL (Structured Query Language) processing method and system based on MyBatis

    CN119088843A