Data writing method and device of a database

By intercepting database write operation points using aspect-oriented programming (AOP), the problem of code duplication during database replacement or upgrades is solved, achieving efficient data consistency management.

CN116756164BActive Publication Date: 2026-03-20ZHEJIANG ZEEKR INTELLIGENT TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

During database replacement or upgrades, existing technologies require developers to write duplicate business code for both databases, resulting in a large amount of code changes and impacting development efficiency.

Method used

By intercepting database write operations using aspect-oriented programming, the target notification is invoked to perform the same write operation, and the first write operation is executed after the second write operation is completed, ensuring data consistency.

Benefits of technology

This reduces the impact of business code between the first and second write operations, improving overall development efficiency and data consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116756164B_ABST
    Figure CN116756164B_ABST
Patent Text Reader

Abstract

The present specification provides a data writing method and device of a database. The method comprises: intercepting an aspect-oriented programming interception point, the interception point corresponding to a first writing operation for a first database; calling a target notification corresponding to the interception point, the target notification being used to execute a second writing operation for a second database, the second writing operation being the same as the first writing operation; and in the case where the second writing operation is executed, calling the interception point to execute the first writing operation.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present specification relates to the technical field of computer, and particularly relates to a data writing method and device of a database. BACKGROUND

[0002] In the software development process, the database plays a key role in the organization, storage and management of related data. In order to consider the stability of the system and the security of the data, a new database which is replaced or upgraded is generally deployed on the basis of the original database which is not replaced or upgraded, and the same write operation is performed on the two databases during the transition period before and after the database is replaced or upgraded.

[0003] In the related art, the developers need to write the same business code for the two databases, which leads to a large amount of code changes and easily affects the original database code, thereby reducing the overall development efficiency. SUMMARY

[0004] Therefore, the present specification provides a data writing method and device of a database to solve the problems in the related art.

[0005] Specifically, the present specification is implemented by the following technical solutions:

[0006] According to a first aspect of the present specification, a data writing method of a database is provided, and the method comprises:

[0007] intercepting an interception point based on aspect-oriented programming, the interception point corresponding to a first write operation for a first database;

[0008] calling a target notification corresponding to the interception point, the target notification being used to execute a second write operation for a second database, the second write operation being the same as the first write operation;

[0009] in a case where the second write operation is executed, calling the interception point to execute the first write operation.

[0010] According to a second aspect of the present specification, a data writing device of a database is provided, and the device comprises:

[0011] a first write operation interception unit, configured to intercept an interception point based on aspect-oriented programming, the interception point corresponding to a first write operation for a first database;

[0012] a second write operation execution unit, configured to call a target notification corresponding to the interception point, the target notification being used to execute a second write operation for a second database, the second write operation being the same as the first write operation;

[0013] The first write operation execution unit is configured to invoke the aspect point to execute the first write operation in a case where the second write operation execution is completed. According to a third aspect of the embodiments of the present specification, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. The program is executed by a processor to implement the steps of the method according to the first aspect.

[0014] According to a fourth aspect of the embodiments of the present specification, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the program to implement the steps of the method according to the first aspect.

[0015] The technical solutions provided by the embodiments of the present specification can include the following beneficial effects:

[0016] In the embodiments of the present specification, by introducing the aspect-oriented programming technology, the first write operation for the first database is taken as an aspect point, and the second write operation for the second database is taken as a target notification of the aspect point, so that the second write operation can be executed in the form of an aspect in cooperation with the first write operation. The business code influence between the first write operation and the second write operation is greatly reduced, thereby improving the overall development efficiency. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions of the present specification, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the present specification, and those skilled in the art can obtain other drawings according to these drawings without creative labor.

[0018] Figure 1 is a flow diagram of a database data writing method according to an exemplary embodiment of the present specification;

[0019] Figure 2 is a flow diagram of another database data writing method according to an exemplary embodiment of the present specification;

[0020] Figure 3 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present specification;

[0021] Figure 4 is a structural diagram of a database data writing device according to an exemplary embodiment of the present specification. DETAILED DESCRIPTION

[0022] The exemplary embodiments will be described in detail herein with reference to the attached drawings. The description of the exemplary embodiments is intended to apply to all alternative modifications and equivalents of the exemplary embodiments. Unless otherwise indicated, the description of the exemplary embodiments set forth herein is not intended to be construed to limit the scope of the disclosure. Rather, the description is intended to be construed as several examples of devices and methods consistent with the disclosure.

[0023] The terminology used in the description herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used in the description of the embodiments and the appended claims, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It also will be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.

[0024] It is to be understood that the singular forms "a", "an" and "the" include plural referents unless the context clearly dictates otherwise. It is to be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items. It is to be understood that the terms "including", "comprising", "consisting" and "consisting essentially of" as used herein are intended to be open terms, not limiting. The use of the term "comprise" or "comprises" or "comprising" or "comprises" in the description or claims of this application should not be limited to the features of the specific embodiments described herein. Rather, it is intended to cover any implementation of the application that includes any of the features of the specific embodiments described herein, or combinations thereof.

[0025] Compared with traditional object-oriented programming (OOP), aspect-oriented programming (AOP) is a programming method that shifts the focus of program structure from "object" to "aspect", and extracts and encapsulates the public behavior that is irrelevant to the core business but affects multiple program classes into a reusable module (i.e., the above-mentioned aspect), so as to achieve the purpose of code reuse and module decoupling. For the convenience of reading and understanding in the following, some terms in AOP are briefly described here: In AOP, advice (also known as enhancement) can be used to define the specific functions and use occasions of the corresponding aspect. According to the use occasion of the advice, it can be divided into before advice (Before), after advice (After), return advice (After-returning), exception advice (After-throwing) and around advice (Around). Each type of advice follows the order of "part before the around advice -> before advice -> target method corresponding to the pointcut -> exception advice / return advice -> after advice -> part after the around advice ->". Among them, the pointcut can be a join point (Join point) in the above-mentioned advice acting on the business logic. Compared with the advice, the pointcut can be used to define the use position of the aspect. The above-mentioned join point can be a "point" that can insert the aspect advice in the execution process of the business logic to support the Spring framework of AOP. For example, this point can be when calling a method, after calling a method, or when throwing an exception. The aspect can insert these points into the normal flow of the application (at this time these points can be regarded as the above-mentioned pointcut), and add new behaviors on the basis of the above-mentioned target method.

[0026] Figure 1 is a flowchart of a database data writing method according to an example embodiment of the present specification.

[0027] As shown in Figure 1 , the method can include the following steps:

[0028] S101, based on aspect-oriented programming to intercept a pointcut, the pointcut corresponds to a first write operation for a first database.

[0029] When a user wants to perform a second write operation after or before performing a first write operation, the first write operation for the first database can be set as an aspect in the corresponding program based on AOP, so as to be intercepted when the first write operation is performed. The first database can be a database originally used in the business code, and the first write operation setting can be recorded in a corresponding database operation file according to a preset software design specification, or can be recorded in a self-defined file location according to actual needs. For example, in an SSM (Spring SpringMVC MyBatis) framework implemented in an MVC (Model View Controller) mode, the first write operation can be recorded in a mapper layer for directly operating the database, which is not limited in the present specification.

[0030] S102, a target notification corresponding to the aspect point is called, and the target notification is used to perform a second write operation for a second database, the second write operation being the same as the first write operation.

[0031] When the aspect point is intercepted, the target notification corresponding to the aspect point can be called, and the second write operation for the second database can be performed through the target notification. The target notification can be at least a pre-notification or a surround notification, so that the second write operation in the aspect and the first write operation corresponding to the aspect point can be executed independently and sequentially through the corresponding execution order. In addition, since the second write operation is the same as the first write operation, the data consistency between the first database and the second database can be ensured. Of course, the consistency also requires that the stored data between the first database and the second database is the same, otherwise even if the second write operation is the same as the first write operation, the operation results in the corresponding database can be different (for example, when a record existing only in the first database is deleted in the second database, the second database will have related errors, when a new record is added in the first database and the second database, neither of the two databases will have related errors).

[0032] The first write operation and the second write operation can be associated at the code level using annotations preset by AOP. Still taking the SSM framework as an example, the file where the second write operation is located can be identified as a special AOP class through the @aspect annotation, and the target notification corresponding to the second write operation can use the @pointcut (address of the first write operation) annotation to set the method corresponding to the first write operation as an aspect point.

[0033] The second write operation in the target notification of the present specification can not pre-configure the execution logic corresponding to the first write operation, but determine the corresponding execution logic in real time according to the first write operation.

[0034] In an embodiment, the database statement corresponding to the first write operation can be extracted in the target notification, and the corresponding execution logic is constructed according to the database statement, and the second write operation is implemented according to the constructed execution logic. In this embodiment, through the above dynamic construction of the execution logic, the redundant code caused by repeatedly writing the same second write operation as the first write operation in the target notification can be saved, so as to realize the scene that one target notification matches multiple different first write operations, and further flexibly modify the second write operation without modifying the first write operation, thereby improving the overall development efficiency.

[0035] The above database statement can be, for example, Structured Query Language (SQL), Hibernate Query Language (HQL), or Java Persistence query language (JPA), and the present specification does not limit this.

[0036] The above method of extracting the database statement corresponding to the first write operation can be through the tool kit of the corresponding language (for example, the getNamespaceSql method of the SqlHelper class provided in SQL), and the present specification does not limit this.

[0037] Of course, considering that the second database is usually a new database that will replace the original database in the actual scene, there are usually a large number of data storage abnormalities that need to be developed, analyzed, or solved by the developer in the early stage of replacement / upgrade, and a small amount of data storage abnormalities may occur in the original database. In this process, the rollback operation of the database is inevitably missing, and the rollback operation can actually be understood as a reverse operation for the executed operation, so the related write data in the first write operation (or the second write operation) can be extracted through the above tool kit to facilitate the execution of the rollback operation in the following, wherein the related write data can be the data table information and the corresponding field information in the database statement, and the present specification does not limit this. In addition, since the second write operation and the first write operation of the present specification are coupled in business logic based on AOP, the code of either party does not affect the other party. Compared with the manual modification method of the first write operation and the second write operation in the same file in the related art, the first write operation and the second write operation in the present specification are independent of each other in the scene of repairing the code logic, and have better readability and stability.

[0038] S103, if the second write operation is completed, the cut-in point is invoked to execute the first write operation.

[0039] Once the second write operation is completed, the first write operation can continue to be executed based on the characteristics of AOP. When the first write operation is also successfully executed, the data consistency between the first database and the second database can be guaranteed.

[0040] Those skilled in the art will understand that, on the one hand, if the second write operation succeeds but the first write operation fails, the second database also needs to perform a rollback operation (the first database does not need to perform a rollback operation, for the same reason as above). On the other hand, due to the characteristics of AOP and the differences in the type of target notification, the completion of the second write operation may not necessarily mean that the second write operation was successful. Therefore, if the second write operation fails, it is necessary to discuss separately whether the first write operation was executed and how to roll back when the first write operation was executed (note that due to the atomicity of the business mechanism in the database, the failure of the second write operation will not affect the second database, so there is no need to perform a rollback operation on the second database).

[0041] If the second write operation succeeds but the first write operation fails, this manual can perform a rollback operation on the second database containing the written data based on the relevant write data mentioned above.

[0042] In an embodiment, the data table information and corresponding field information in the database statement can be extracted and recorded, and in a case where the first write operation occurs abnormally, a rollback operation is performed on the second database according to the recorded data table information and corresponding field information to ensure the consistency of the second database of the first database, wherein the field information can include the name, the before and after values and the corresponding filtering conditions of the field. Specifically, the above-mentioned rollback operation can be: in a case where the database statement is an insert statement, a corresponding delete operation is performed on the second database according to the recorded data table information and corresponding field information, for example, in a case where the insert statement is "INSERT INTO (data column 1, data column 2, data column 3, … data column N) VALUES (value 1, value 2, value 3 … value N)", the statement of the corresponding delete operation can be "DELETE FROM WHERE <insert statement completes the corresponding record row> "; in a case where the database statement is a delete statement, a corresponding insert operation is performed on the second database according to the recorded data table information and corresponding field information, for example, in a case where the delete statement is "DELETE FROM WHERE <filtering condition>", the statement of the corresponding insert operation can be "INSERT INTO (data column 1 … data column N of the deleted record) VALUES (value of data column 1 … value of data column N)"; in a case where the database statement is an update statement, a corresponding update operation is performed on the second database according to the recorded data table information and corresponding field information, for example, in a case where the update statement is "UPDATE SET <data column = updated value> WHERE <filtering condition>", the statement of the corresponding update operation can be "UPDATE SET <data column = original value> WHERE <filtering condition>". The determination method of each corresponding statement can be adjusted according to the actual situation, which is not limited in the present specification.

[0043] In the above embodiment, the abnormality of the first write operation can be captured in different stages according to different target notifications, for example: in a case where the target notification is a pre-notification, a corresponding post-notification of the corresponding interception point can be called, wherein the post-notification is used to capture the operation exception sent by the first write operation; in a case where the target notification is a surround notification, a check operation in the surround notification can be executed, the check operation is used to capture the operation exception sent by the first write operation, and in a case where at least one operation exception is captured through the target notification, it is determined that the first write operation occurs abnormally. The check operation can be located in the post-notification corresponding to the pre-notification, or can be located in the business code after the first write operation in the surround notification.

[0044] The above two (to the above pre-notification and the above wrap notification) are basically consistent in implementation effect, but will have some differences in the execution logic of the "first write operation after the second write operation occurs abnormally".

[0045] In an embodiment, when the target notification is a pre-notification, the first write operation is still executed and the first database is rolled back in the case that the second write operation occurs abnormally. In this embodiment, the method execution of the interception point cannot be selectively skipped according to the specific situation (for example, the second write operation occurs abnormally) in the pre-notification of the restricted AOP, so the first database needs to be rolled back again.

[0046] In an embodiment, the target notification is a wrap notification, and the first write operation can be canceled in the wrap notification in the case that the second write operation occurs abnormally, so that the execution of the first write operation is canceled. In this embodiment, since the wrap notification in the AOP can actively call the interception point through the "proceed()" method, the method execution of the interception point can be skipped in the case that the second write operation occurs abnormally and the like through a similar judgment statement, thereby reducing the meaningless resource overhead required for executing the first write operation.

[0047] Next, taking a java project under the SSM framework as an example, the setting and actual application of the aspect are introduced, Figure 2 is another flowchart of a database data writing method shown in an exemplary embodiment of the present specification, as shown in the figure, the process includes: Figure 2

[0048] S201, obtaining the source file of the program to be detected.

[0049] In an embodiment, the source file of the program to be detected can be obtained from the project management warehouse gitlab through the gitclone command, and the source file contains the corresponding source code. It is assumed that only the business logic for the first database as the original database and the product version Mysql5.0 is designed in the source code, and the logic is recorded in the "DataMapper" file, and the file only includes the modification method "NumberAdd1()" for the first database.

[0050] S202, setting the aspect file.

[0051] In an embodiment, it is assumed that the above first database is upgraded from Mysql5.0 to Mysql8.0 (hereinafter referred to as the second database), so the class "databaserewrite.java" implementing the logic of the second database can be added to the project source code, and the class is annotated as an AOP aspect class through the @aspect annotation.​

[0052] S203, Set the target notification corresponding to the inset point in the aspect file.

[0053] In one embodiment, the `@Pointcut(execution(*.mapper.NumberAdd1())` annotation in the aspect class file `databaserewrite.java` can be used to intercept a specified database operation (i.e., the method `NumberAdd1`). Of course, if it is necessary to intercept all database operation methods under this mapper file, it can be configured using `@Pointcut(execution(*.mapper.*)`. Furthermore, if it is only necessary to intercept insert, update, and delete statements in all database operation methods, it can be done through a similar method.

[0054] This can be achieved using the `@pointcut(execution(*.mapper.*[*insert*,*update*,*delete*]` method.

[0055] S204: Extract and record the SQL statement corresponding to the first write operation from the pre-notification.

[0056] In one embodiment, assuming the SQL statement corresponding to the first write operation is "UPDATE Table SET number=number+1WHERE ID>10" (equivalent to incrementing the value of the field "number" in the record with ID greater than 10 in the data table named "Table" by 1), it can be extracted and persisted by calling the SqlHelper.getNamespaceSql method.

[0057] S205, Extract the data table information and corresponding field information from the SQL statement.

[0058] In one embodiment, the table information "Table" and corresponding field information in the above SQL statement can also be obtained by calling the SqlHelper.getNamespaceSql method, such as the field content "number", the corresponding value "number+1", and the record filtering condition "ID>10".

[0059] S206, execute the second write operation via SQL statement.

[0060] In one embodiment, the SQL statement obtained through S204 can be used to construct corresponding execution logic, and the second write operation can be implemented according to the constructed execution logic, that is, to execute the corresponding "UPDATE Table SET number=" command into the second database.

[0061] the second write operation of the SQL statement "UPDATE Table SET number+1WHERE ID>10".

[0062] S207, executing the first write operation in the cut-in point.

[0063] In an embodiment, assuming that the second write operation is executed successfully, the cut-in point can be called to execute the first write operation to the first database in the case that the second write operation is executed completely.

[0064] S208, judging whether there is data storage exception in the post-notification.

[0065] In an embodiment, the post-notification is a processing logic executed after the cut-in point, thus the current method can be captured by the ExceptionCatch statement whether there is an exception in the process of data writing, updating or deleting, if there is no exception, S210 is executed, otherwise S209 is executed.

[0066] S209, data rollback to the second database.

[0067] In an embodiment, since the first write operation has an exception, it is necessary to rollback the second database which successfully executes the second write operation, specifically, the reverse update statement of the above SQL "UPDATE Table SET number=number-1WHERE ID>10" can be constructed according to the data table information and the corresponding field information extracted in S205 to restore the originally updated data.

[0068] S210, prompting the write success.

[0069] In an embodiment, the user can be shown the message of write success in the form of log, table or image.

[0070] Figure 3 Fig. 1 is a schematic structural diagram of an electronic device in an exemplary embodiment. Please refer to Figure 4 At the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory and a non-volatile memory, and of course, it can also include other required hardware. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs, and at the logical level, it forms a data writing device of a database. Of course, in addition to the software implementation, the present specification does not exclude other implementation manners, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logical unit, but can also be hardware or logic devices.

[0071] Corresponding to the embodiment of the data writing method of the database, the specification also provides an embodiment of a data writing device of the database.

[0072] Please refer to Figure 4 , Figure 4 FIG. 1 is a structural schematic diagram of a data writing device of a database according to an exemplary embodiment.

[0073] As shown in Figure 4 , in a software implementation, the device can include:

[0074] A first write operation interception unit 401 is configured to intercept an aspect-oriented programming interception point, the interception point corresponding to a first write operation for a first database;

[0075] A second write operation execution unit 402 is configured to call a target notification corresponding to the interception point, the target notification being used to execute a second write operation for a second database, the second write operation being the same as the first write operation;

[0076] A first write operation execution unit 403 is configured to call the interception point to execute the first write operation in a case where the second write operation execution is completed.

[0077] Optionally, the second write operation is not configured with corresponding execution logic; and the second write operation execution unit 402 is specifically configured to:

[0078] extract a database statement corresponding to the first write operation;

[0079] construct corresponding execution logic according to the database statement;

[0080] implement the second write operation according to the constructed execution logic.

[0081] Optionally, the device further includes:

[0082] A data rollback unit 404 is configured to extract and record data table information and corresponding field information in the database statement;

[0083] In a case where it is determined that the first write operation is abnormal, a rollback operation is performed on the second database according to the recorded data table information and corresponding field information, so as to ensure consistency of the second database with the first database.

[0084] Optionally, the target notification is a pre-notification or a surround notification; and the data rollback unit 404 is specifically configured to:

[0085] In a case where the target notification is a pre-notification, a post-notification corresponding to the cut-in point is invoked, and the post-notification is used to capture operation exceptions sent by the first write operation;

[0086] In a case where the target notification is a wrap-around notification, a check operation in the wrap-around notification is executed, and the check operation is used to capture operation exceptions sent by the first write operation;

[0087] In a case where at least one operation exception is captured through the target notification, it is determined that the first write operation is abnormal.

[0088] Optionally, the data rollback unit 404 is specifically configured to:

[0089] In a case where the database statement is an insert statement, a corresponding delete operation is performed on the second database according to the recorded data table information and corresponding field information;

[0090] In a case where the database statement is a delete statement, a corresponding insert operation is performed on the second database according to the recorded data table information and corresponding field information;

[0091] In a case where the database statement is an update statement, a corresponding update operation is performed on the second database according to the recorded data table information and corresponding field information.

[0092] Optionally, the target notification is a wrap-around notification, and the apparatus further includes:

[0093] The second write operation canceling unit 405 is configured to, in a case where it is determined that the second write operation is abnormal, cancel the invocation of the cut-in point in the wrap-around notification, so that the first write operation is canceled.

[0094] The implementation process of the functions and roles of each unit in the above apparatus is specifically described in the implementation process of the corresponding steps in the above method, and will not be repeated here.

[0095] For the device embodiment, since it basically corresponds to the method embodiment, the related parts can be referred to the part of the method embodiment. The device embodiments described above are only illustrative, and the units described as separate components can be or can not be physically separated, and the components displayed as units can be or can not be physical units, that is, they can be located in one place, or can be distributed on multiple network units. According to actual needs, part or all of the modules can be selected to achieve the purpose of the scheme of the present application. Those skilled in the art can understand and implement it without creative labor.

[0096] Embodiments of the subject matter and the functional operations described in this specification can be implemented in digital electronic circuitry, in tangibly-embodied computer software or firmware, in computer hardware, including the structures disclosed in this specification and their structural equivalents, or in combinations of one or more of them. Embodiments of the subject matter described in this specification can be implemented as one or more computer programs, i.e., one or more modules of computer program instructions encoded on a tangible non-transitory program carrier for execution by, or to control the operation of, data processing apparatus. Alternatively or additionally, the program instructions can be encoded on an artificially generated propagated signal, e.g., a machine-generated electrical, optical, or electromagnetic signal that is generated to encode information for transmission to suitable receiver apparatus for execution by a data processing apparatus. The computer storage medium can be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.

[0097] The processes and logic flows described in this specification can be performed by one or more programmable computers executing one or more computer programs to perform functions by operating on input data and generating output. The processes and logic flows can also be performed by special purpose logic circuitry, e.g., an FPGA (field programmable gate array) or an ASIC (application specific integrated circuit), and the apparatus can be implemented as special purpose logic circuitry.

[0098] Computers suitable for the execution of a computer program include, by way of example, general and / or special purpose microprocessors, or any other kind of central processing unit. Generally, a central processing unit will receive instructions and data from a read-only memory and / or a random access memory. The essential elements of a computer are a central processing unit for performing instructions and one or more memory devices for storing instructions and data. Generally, a computer will also include, or be operatively coupled to receive data from or transfer data to, or both, one or more mass storage devices for storing data, e.g., magnetic, magneto-optical disks, or optical disks. However, a computer need not have such devices. Moreover, a computer can be embedded in another device, e.g., a mobile telephone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a Global Positioning System (GPS) receiver, or a portable storage device (e.g., a universal serial bus (USB) flash drive), to name just a few.

[0099] Computer readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media and memory devices, including by way of example semiconductor memory devices, e.g., EPROM, EEPROM, and flash memory devices; magnetic disks, e.g., internal hard disks or removable disks; magneto-optical disks; and CD-ROM and DVD-ROM disks. The processor and the memory can be supplemented by, or incorporated in, special purpose logic circuitry.

[0100] While the specification contains many specifics, these should not be construed as limiting the scope of any invention or of the required claims in any way. The specification and the described embodiments are merely illustrative of specific ways to make and use the many inventive features and the present application will be measured in terms of the claims which follow, rather than the ability to practice the specification. Certain features described in the specification in the context of one embodiment also can be implemented in other embodiments. Conversely, certain features of the described embodiments can also be implemented in a less than all of the embodiments described. In addition, although the features can be described and illustrated with respect to particular combinations, one or more of the features can be used in other combinations than those described.

[0101] Similarly, while operations are depicted in the drawings in a particular order, this should not be understood as requiring or implying that such operations be performed in the particular order shown or in sequential order, or that all illustrated operations be performed, to achieve desirable results. In certain circumstances, multitasking and parallel processing can be advantageous. Moreover, the separation of various system modules and components in the embodiments described above should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product or packaged into multiple software products.

[0102] Accordingly, particular embodiments of the subject matter have been described. Further, the processes depicted in the accompanying figures do not require the particular order shown, or sequential order, to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous.

[0103] The above description is merely illustrative of the preferred embodiments of this description various modifications can be made by those skilled in the art without departing from the scope of the description. Thus, the scope of the description is not to be interpreted as limited to the particular embodiments described but should be construed as including all modifications that are within the scope of the claims.

Claims

1. A method for writing data to a database, characterized in that, The method includes: The interception point is based on aspect-oriented programming, and the point corresponds to the first write operation to the first database; Invoke the target notification corresponding to the entry point. The target notification is used to perform a second write operation for the second database. The second write operation is the same as the first write operation, but no corresponding execution logic is configured in the second write operation. If the second write operation is completed, the cutoff point is invoked to execute the first write operation; The execution of the second write operation for the second database includes: Extract the database statement corresponding to the first write operation; Construct the corresponding execution logic based on the database statement; The second write operation is implemented according to the constructed execution logic.

2. The method according to claim 1, characterized in that, The method further includes: Extract and record the data table information and corresponding field information from the database statement; If an anomaly is detected in the first write operation, a rollback operation is performed on the second database based on the recorded data table information and corresponding field information to ensure the consistency between the first database and the second database.

3. The method according to claim 2, characterized in that, The target notification is a before notification or a surrounding notification; determining that the first write operation has encountered an anomaly includes: If the target notification is a pre-notification, the corresponding post-notification for the entry point is invoked. The post-notification is used to capture the operation exception sent by the first write operation. In the case that the target notification is a surround notification, a check operation is performed in the surround notification, the check operation being used to capture an operation exception sent by the first write operation; If at least one operational anomaly is detected through the target notification, it is determined that the first write operation has an anomaly.

4. The method according to claim 2, characterized in that, The rollback operation on the second database based on the recorded data table information and corresponding field information includes: When the database statement is an insert statement, the corresponding deletion operation is performed on the second database according to the recorded data table information and the corresponding field information; When the database statement is a delete statement, the corresponding insert operation is performed on the second database according to the recorded data table information and the corresponding field information; When the database statement is an update statement, the corresponding update operation is performed on the second database based on the recorded data table information and the corresponding field information.

5. The method according to claim 1, characterized in that, The target notification is an surround notification; the method further includes: If it is determined that an exception has occurred in the second write operation, the pointcut is canceled in the surround notification so that the first write operation is canceled.

6. The method according to claim 1, characterized in that, The execution logic of the target notification is recorded in the aspect file; the aspect file maintains an entry flag for the first write operation, which is used to instruct the target notification to intercept the first write operation.

7. A data writing device for a database, characterized in that, The device includes: The first write operation interception unit is used to intercept the pointcut based on aspect-oriented programming, the pointcut corresponding to the first write operation against the first database; The second write operation execution unit is used to call the target notification corresponding to the entry point. The target notification is used to execute a second write operation for the second database. The second write operation is the same as the first write operation, but no corresponding execution logic is configured in the second write operation. The first write operation execution unit is configured to invoke the pointcut to execute the first write operation after the second write operation has been completed. The second write operation execution unit is specifically used for: Extract the database statement corresponding to the first write operation; Construct the corresponding execution logic based on the database statement; The second write operation is implemented according to the constructed execution logic.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the method as described in any one of claims 1 to 6.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Distributed domain data synchronization method, system and device

    CN112487097A