Method, device, middleware and computer-readable storage medium for accessing database

The middleware-based solution for database access simplifies the development of new versions by parsing and routing database requests through a change information table, addressing complexity and maintenance issues in database grayscale release.

CN112948454BActive Publication Date: 2024-12-17CHINA TELECOM CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201911172693.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-11-26
Publication Date
2024-12-17
Estimated Expiration
2039-11-26

AI Technical Summary

Technical Problem

The complexity and workload of database grayscale release are increased due to data distribution being implemented at the application layer, and the mixing of data distribution code with business logic code complicates maintenance.

Method used

A middleware layer is introduced between the application and database instances, utilizing a database change information table to parse, match, and route database access requests to either the new or old version of the database based on element changes, thereby reducing the need for application layer modifications.

Benefits of technology

This approach simplifies the development of new version applications and databases by allowing data distribution without modifying the application, reducing complexity and maintenance challenges.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112948454B_ABST
    Figure CN112948454B_ABST
Patent Text Reader

Abstract

The present disclosure provides a method, device, middleware and computer-readable storage medium for accessing a database, and relates to the field of information technology. The method for accessing a database includes: the middleware parses the database access request sent by the application to obtain the target access element in the database access request; the middleware uses the target access element to match the database change information table to obtain the matching result of the target access element; the database change information table contains the change information of each element between the new version of the database and the old version of the database, and the element change information includes the element before the change and the element after the change; the middleware routes the database access request to the new version of the database or the old version of the database according to the matching result of the target access element. The present disclosure can realize the data distribution of the application to different databases without modifying the application, thereby reducing the constraints on the development of new version applications and new version databases, and reducing the complexity of developing new version applications and new version databases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of information technology, and in particular to a method, device, middleware and computer-readable storage medium for accessing a database. Background Art

[0002] Grayscale release is a data release method that allows for a smooth transition during the application and database development process. Specifically, grayscale release allows some users to continue using the old version of the application and database, while other users try out the new version of the application and database. If the trial users have no objections, then all users will be gradually migrated to the new version of the application. Grayscale release can include both the application and database levels.

[0003] For the grayscale release of a database, the data generated by all users' database requests needs to be distributed to both the old and new version database instances. When the release is completed or rolled back, you only need to delete a database instance to ensure the integrity of the business data during the grayscale release process. Currently, the grayscale release of a database mainly distributes data through the application layer. Summary of the invention

[0004] A technical problem solved by the present disclosure is how to reduce the complexity of developing new version applications and new version databases.

[0005] According to one aspect of an embodiment of the present disclosure, a method for accessing a database is provided, including: the middleware parses a database access request sent by an application to obtain a target access element in the database access request; the middleware uses the target access element to match a database change information table to obtain a matching result of the target access element; the database change information table contains information on changes to various elements between a new version of the database and an old version of the database, and the element change information includes elements before the change and elements after the change; the middleware routes the database access request to the new version of the database or the old version of the database according to the matching result of the target access element.

[0006] In some embodiments, the matching result of the target access element is the element change information corresponding to the target access element; the middleware routes the database access request to the new version of the database or the old version of the database according to the matching result of the target access element, including: the middleware copies the database access request to obtain the original database access request and the copied database access request; if the target access element is the element before the change in the matching result, the middleware modifies the target access element in the copied database access request to the element after the change in the matching result; the middleware routes the copied database access request to the new version of the database, and routes the original database access request to the old version of the database.

[0007] In some embodiments, the middleware routes the database access request to the new version of the database or the old version of the database based on the matching result of the target access element, and also includes: if the target access element is an element that has been changed in the matching result, the middleware modifies the target access element in the copied database access request to an element that has been changed in the matching result; the middleware routes the copied database access request to the old version of the database, and routes the original database access request to the new version of the database.

[0008] In some embodiments, the middleware routes the database access request to the new version database or the old version database according to the matching result of the target access element, including: if the matching result of the target access element is empty, the middleware routes the database access request to the new version database and the old version database respectively.

[0009] In some embodiments, the method also includes: using an element after change in the new version database and an element before change in the corresponding old version database to construct an element change information between the new version database and the old version database; using the element change information between the new version database and the old version database to construct a database change information table.

[0010] According to another aspect of an embodiment of the present disclosure, a middleware is provided, including: a request parsing module, configured to parse a database access request sent by an application, and obtain a target access element in the database access request; an information matching module, configured to match a database change information table with the target access element, and obtain a matching result of the target access element; the database change information table contains information on changes to various elements between a new version of the database and an old version of the database, and the element change information includes elements before the change and elements after the change; a routing module, configured to route the database access request to the new version of the database or the old version of the database according to the matching result of the target access element.

[0011] In some embodiments, the matching result of the target access element is the element change information corresponding to the target access element; the routing module includes: a request replication unit, configured to replicate the database access request to obtain the original database access request and the replicated database access request; a request modification unit, configured to: if the target access element is the element before the change in the matching result, modify the target access element in the replicated database access request to the element after the change in the matching result; a request routing unit, configured to: route the replicated database access request to the new version of the database, and route the original database access request to the old version of the database.

[0012] In some embodiments, the request modification unit is further configured to: if the target access element is a changed element in the matching result, modify the target access element in the copied database access request to an element before the change in the matching result; the request routing unit is further configured to: route the copied database access request to the old version of the database, and route the original database access request to the new version of the database.

[0013] In some embodiments, the matching result of the target access element is empty, and the routing module is configured to: route the database access request to the new version database and the old version database respectively.

[0014] In some embodiments, the middleware also includes an information table construction module, which is configured to: use an element after change in the new version database and an element before change in the corresponding old version database to construct an element change information between the new version database and the old version database; use the element change information between the new version database and the old version database to construct a database change information table.

[0015] According to another aspect of an embodiment of the present disclosure, there is provided a device for accessing a database, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute the aforementioned method for accessing a database based on instructions stored in the memory.

[0016] According to another aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and when the instructions are executed by a processor, the aforementioned method of accessing a database is implemented.

[0017] The present disclosure can implement data distribution of an application to different databases without modifying the application, thereby reducing constraints on developing new versions of applications and new versions of databases, and reducing the complexity of developing new versions of applications and new versions of databases.

[0018] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0020] Figure 1 The data publishing process diagram in the traditional database grayscale publishing technology is shown by way of example.

[0021] Figure 2 The data publishing process diagram of the method for accessing a database disclosed in the present invention is exemplified.

[0022] Figure 3 A flowchart of some embodiments of constructing a database change information table is shown.

[0023] Figure 4 The present invention provides a flowchart of some embodiments of the method for accessing a database.

[0024] Figure 5 A flow chart of some embodiments of middleware routing database access requests to a database is shown.

[0025] Figure 6 The schematic diagrams of the structures of some embodiments of the middleware of the present disclosure are shown.

[0026] Figure 7 A schematic diagram showing the structures of some embodiments of the device for accessing a database disclosed in the present invention. DETAILED DESCRIPTION

[0027] The following will be combined with the drawings in the embodiments of the present disclosure to clearly and completely describe the technical solutions in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present disclosure and its application or use. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0028] Figure 1 The following is an exemplary diagram of the data publishing process in the traditional database grayscale publishing technology. Figure 1 As shown, in the traditional database grayscale release technology, the old version of the application needs to release the old version of the data to the old version of the database and the new version of the database, and the new version of the application needs to release the new version of the data to the old version of the database and the new version of the database. The inventors have found that the traditional database grayscale release technology has the following problems: on the one hand, data distribution needs to be implemented at the application layer, which greatly increases the complexity and workload of design and development; on the other hand, the data distribution code and the business logic code are mixed together, resulting in the application layer code being polluted and difficult to maintain.

[0029] To solve these problems, the present disclosure adds a middleware layer between the application and the database instance. Figure 2 The following is a schematic diagram showing the data publishing process of the method for accessing a database disclosed in the present invention. Figure 2 As shown, both the new version application and the old version application access the new and old version database instances through the middleware.

[0030] Before implementing the method for accessing a database disclosed in the present invention, it is necessary to construct a database change information table. Figure 3 Some embodiments of constructing a database change information table are described.

[0031] Figure 3 The following is a flow chart showing some embodiments of constructing a database change information table. Figure 3 As shown, this embodiment includes steps S301 to S302.

[0032] In step S301, an element change information between the new version database and the old version database is constructed by using an element after the change in the new version database and an element before the change in the corresponding old version database.

[0033] For example, DSL (Domain-Specific Languages) can be used to define the element change information between the new version of the database and the old version of the database. The element change information can be defined from two dimensions: element type and new and old versions to describe the change strategy of the new and old versions of the database. For example, the new version of the database adds a new field based on the old version of the database. The element type in the element change information is field, the value of the old version is empty, and the value of the new version is the newly added field name. For another example, the new version of the database modifies a field name based on the old version of the database. The element type in the element change information is field, the value of the old version is the original field name, and the value of the new version is the new field name.

[0034] In step S302, a database change information table is constructed using the change information of various elements between the new version database and the old version database.

[0035] Table 1 shows an example of a database change information table. The change information of each element between the new version of the database and the old version of the database is combined to form a database change information table, so that the database change information table can be subsequently queried to determine whether the target access element in the database access request (the target element to be accessed by the SQL statement) involves the changes between the new version of the database and the old version of the database.

[0036] Table 1

[0037] Element Type Value of the new version database Values ​​of old version databases Fields A B Fields C D …… …… ……

[0038] Combine the following Figure 4 Some embodiments of the method of accessing a database disclosed herein are described.

[0039] Figure 4 The flowchart of some embodiments of the method for accessing a database disclosed in the present invention is shown. Figure 4 As shown, this embodiment includes steps S401 to S403.

[0040] In step S401, the middleware parses the database access request sent by the application and obtains the target access element in the database access request.

[0041] The database access requests sent by the application access data service include database access requests sent by the new version of the application and database access requests sent by the old version of the application. The middleware parses the database access requests (incoming SQL statements) sent by the application and can obtain the request type of the SQL statement (including addition, deletion, modification, query), the objects included in the SQL statement (including tables, views, functions, stored procedures, etc.), and the fields included in the SQL statement (including query fields, condition fields, etc.).

[0042] In step S402, the middleware matches the database change information table with the target access element to obtain a matching result of the target access element.

[0043] The database change information table contains the change information of each element between the new version of the database and the old version of the database. The element change information includes the elements before and after the change. For example, if the target access element is A, the matching result is (field, A, B); for another example, if the target access element is D, the matching result is (field, C, D).

[0044] In step S403, the middleware routes the database access request to the new version database or the old version database according to the matching result of the target access element.

[0045] Combine the following Figure 5 Describe the process of step S403 where the middleware routes the database access request to the database. Figure 5 The flowchart of some embodiments of the middleware routing database access requests to the database is shown. Figure 5 As shown, this embodiment includes steps S5031 to S5037.

[0046] In step S5030, the middleware determines whether the match is successful.

[0047] The middleware determines whether to modify the content in the SQL request statement based on the matching result between the target access element in the SQL request statement and the database change information table. That is, the middleware determines whether each element in the SQL request statement involves the change information of each element between the new version of the database and the old version of the database.

[0048] If the match is successful, the matching result of the target access element is the element change information corresponding to the target access element. That is, the target access element involves a change, and the SQL request statement needs to be modified, and the modification of the SQL request statement determines the routing destination of the SQL request statement. According to this situation, step S5031 is executed.

[0049] In step S5031, the middleware copies the database access request to obtain the original database access request and the copied database access request.

[0050] In step S5032, the middleware determines whether the target access element is the element before the change or the element after the change in the matching result.

[0051] If the target access element is the element before the change in the matching result, step S5033 to step S5034 are executed.

[0052] In step S5033, the middleware modifies the target access element in the copied database access request to the changed element in the matching result.

[0053] Those skilled in the art should understand that this embodiment also supports the addition or deletion of elements such as tables and fields. If a new version of the database adds a new field based on the old version of the database, the newly added field in the database access request can be removed.

[0054] In step S5034, the middleware routes the copied database access request to the new version database, and routes the original database access request to the old version database.

[0055] If the target access element is the changed element in the matching result, step S5035 to step S5036 are executed.

[0056] In step S5035, the middleware modifies the target access element in the copied database access request to the element before the change in the matching result.

[0057] In step S5036, the middleware routes the copied database access request to the old version database, and routes the original database access request to the new version database.

[0058] If the match fails, the matching result of the target access element is empty. That is, the target access element does not involve changes, and the SQL request statement does not need to be modified. In this case, the database access request is directly routed.

[0059] In this case, execute step S5037.

[0060] In step S5037, the middleware routes the database access request to the new version database and the old version database respectively.

[0061] This embodiment uses the pre-established database change information table, and cooperates with the middleware to parse, match, dynamically modify, and dynamically route SQL requests, so that the application can distribute data to different databases without modifying the application. Therefore, this embodiment does not need to add code for data distribution at the application layer, reduces the constraints on developing new versions of applications and new versions of databases, and reduces the complexity of developing new versions of applications and new versions of databases.

[0062] Combine the following Figure 6 Some embodiments of the middleware of the present disclosure are described.

[0063] Figure 6 Schematic diagrams showing the structures of some embodiments of the middleware of the present disclosure are shown. Figure 6 As shown, the middleware 60 in this embodiment includes:

[0064] The request parsing module 601 is configured to parse the database access request sent by the application and obtain the target access element in the database access request; the information matching module 602 is configured to use the target access element to match the database change information table to obtain the matching result of the target access element; the database change information table contains the change information of each element between the new version of the database and the old version of the database, and the element change information includes the elements before the change and the elements after the change; the routing module 603 is configured to route the database access request to the new version of the database or the old version of the database according to the matching result of the target access element.

[0065] In some embodiments, the matching result of the target access element is the element change information corresponding to the target access element; the routing module 603 includes: a request replication unit 6031, configured to replicate the database access request to obtain the original database access request and the replicated database access request; a request modification unit 6032, configured to: if the target access element is the element before the change in the matching result, modify the target access element in the replicated database access request to the element after the change in the matching result; a request routing unit 6033, configured to: route the replicated database access request to the new version of the database, and route the original database access request to the old version of the database.

[0066] In some embodiments, the request modification unit 6032 is also configured to: if the target access element is a changed element in the matching result, modify the target access element in the copied database access request to an element before the change in the matching result; the request routing unit 6033 is also configured to: route the copied database access request to the old version of the database, and route the original database access request to the new version of the database.

[0067] In some embodiments, the matching result of the target access element is empty, and the routing module 603 is configured to: route the database access request to the new version database and the old version database respectively.

[0068] The above embodiment uses the pre-established database change information table, and cooperates with the middleware to parse, match, dynamically modify, and dynamically route SQL requests, so that the application can distribute data to different databases without modifying the application. Therefore, this embodiment does not need to add code for data distribution at the application layer, reduces the constraints on developing new versions of applications and new versions of databases, and reduces the complexity of developing new versions of applications and new versions of databases.

[0069] In some embodiments, the middleware also includes an information table construction module 600, which is configured to: use an element after change in the new version database and an element before change in the corresponding old version database to construct an element change information between the new version database and the old version database; use the element change information between the new version database and the old version database to construct a database change information table.

[0070] Combine the following Figure 7 Some embodiments of the apparatus for accessing a database disclosed herein are described.

[0071] Figure 7 The schematic diagrams of the structures of some embodiments of the device for accessing a database disclosed in the present invention are shown. Figure 7 As shown, the device 70 for accessing a database in this embodiment includes: a memory 710 and a processor 720 coupled to the memory 710 , and the processor 720 is configured to execute the method for accessing a database in any of the aforementioned embodiments based on instructions stored in the memory 710 .

[0072] The memory 710 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, and other programs.

[0073] The device 70 for accessing the database may also include an input / output interface 730, a network interface 740, a storage interface 750, etc. These interfaces 730, 740, 750, the memory 710, and the processor 720 may be connected, for example, via a bus 760. The input / output interface 730 provides a connection interface for input / output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 740 provides a connection interface for various networked devices. The storage interface 750 provides a connection interface for external storage devices such as SD cards and USB flash drives.

[0074] The present disclosure also includes a computer-readable storage medium on which computer instructions are stored. When the instructions are executed by a processor, the method for accessing a database in any of the aforementioned embodiments is implemented.

[0075] The present disclosure is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0076] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0077] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0078] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present disclosure should be included in the protection scope of the present disclosure.

Claims

1. A method for accessing a database, comprising: The middleware parses the database access request sent by the application and obtains the target access element in the database access request; The middleware uses the target access element to match the database change information table to obtain a matching result of the target access element; the database change information table includes the change information of each element between the new version database and the old version database, and the element change information includes the element before the change and the element after the change; The middleware routes the database access request to the new version database or the old version database according to the matching result of the target access element, including: In the case where the matching result of the target access element is the element change information corresponding to the target access element, the middleware copies the database access request to obtain the original database access request and the copied database access request; If the target access element is the element before the change in the matching result, the middleware modifies the target access element in the copied database access request to the element after the change in the matching result; the middleware routes the copied database access request to the new version of the database, and routes the original database access request to the old version of the database.

2. The method of claim 1, wherein: The middleware routes the database access request to the new version database or the old version database according to the matching result of the target access element, and further includes: If the target access element is the changed element in the matching result, the middleware modifies the target access element in the copied database access request to the element before the change in the matching result; the middleware routes the copied database access request to the old version of the database, and routes the original database access request to the new version of the database.

3. The method of claim 1, wherein: The middleware routes the database access request to the new version database or the old version database according to the matching result of the target access element, and further includes: When the matching result of the target access element is empty, the middleware routes the database access request to the new version database and the old version database respectively.

4. The method of claim 1, further comprising: Using an element after the change in the new version database and an element before the change in the corresponding old version database, construct an element change information between the new version database and the old version database; The database change information table is constructed using the change information of various elements between the new version of the database and the old version of the database.

5. A middleware comprising: A request parsing module is configured to parse a database access request sent by an application and obtain a target access element in the database access request; An information matching module is configured to match the database change information table with the target access element to obtain a matching result of the target access element; The database change information table contains information about changes in various elements between the new version of the database and the old version of the database, and the element change information includes the elements before the change and the elements after the change; A routing module is configured to route the database access request to the new version database or the old version database according to the matching result of the target access element, including: a request copying unit configured to copy the database access request to obtain an original database access request and a copied database access request when the matching result of the target access element is the element change information corresponding to the target access element; a request modification unit configured to: if the target access element is the element before the change in the matching result, modify the target access element in the copied database access request to the element after the change in the matching result; The request routing unit is configured to: route the copied database access request to the new version database, and route the original database access request to the old version database.

6. The middleware according to claim 5, wherein: The request modification unit is further configured to: if the target access element is the changed element in the matching result, modify the target access element in the copied database access request to the element before the change in the matching result; The request routing unit is further configured to: route the copied database access request to the old version database, and route the original database access request to the new version database.

7. The middleware according to claim 5, wherein: The matching result of the target access element is empty, and the routing module is configured to: route the database access request to the new version database and the old version database respectively.

8. The middleware according to claim 5, further comprising an information table construction module configured to: Using an element after change in the new version database and an element before change in the corresponding old version database, an element change information between the new version database and the old version database is constructed; using each element change information between the new version database and the old version database, a database change information table is constructed.

9. A device for accessing a database, comprising: Memory; as well as A processor coupled to the memory, wherein the processor is configured to execute the method for accessing a database according to any one of claims 1 to 4 based on instructions stored in the memory.

10. A computer-readable storage medium, wherein: The computer-readable storage medium stores computer instructions, and when the instructions are executed by a processor, the method for accessing a database according to any one of claims 1 to 4 is implemented.