Database logging method and apparatus, computer device and computer readable storage medium

By intercepting database operations through Java annotations and Aspect-Oriented Programming (AOP), descriptive or field-based logs are generated and bound to user information. This solves the problems of intrusiveness and high cost in existing technologies, and achieves efficient, readable logging and enterprise audit support.

CN116561146BActive Publication Date: 2025-11-07BEIJING INSIGHT NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310525141.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-10
Publication Date
2025-11-07
Estimated Expiration
2043-05-10

AI Technical Summary

Technical Problem

The existing database logging method has an intrusive impact on the original business system, requires additional effort to understand the log files, makes it difficult to identify the operator, and may lead to high system reset costs.

Method used

Using Java annotations and Aspect-Oriented Programming (AOP), database operations are intercepted, descriptive or field-based log content is generated, and user information is bound to it, avoiding hardcoding and log file analysis, and the data is directly stored in the database table.

Benefits of technology

It requires no modification to business code, reduces system invasiveness, lowers costs, improves log readability and operator identification, and supports enterprise auditing and supervision.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116561146B_ABST
    Figure CN116561146B_ABST
Patent Text Reader

Abstract

The application discloses a database log recording method and device, computer equipment and a computer readable storage medium, and relates to the technical field of database management. The method comprises the following steps: after receiving a database operation request, first, starting to execute business code for responding to the request; then, adding Java annotations to a function when the business code executes a database operation function; then, based on aspect-oriented programming, intercepting the operation, and according to the Java annotations, cutting in to execute to obtain descriptive log content when a field is added or deleted or field type log content for reflecting the change of a difference field when the field is modified; finally, obtaining user information, and binding the user information, log content and log information generation time stamp together to save in a database table, so that the original business system is not affected, and the operator can be clearly distinguished, which is beneficial to subsequent enterprise auditing and supervision.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of database management, and particularly relates to a database log recording method and device, computer equipment and a computer readable storage medium. BACKGROUND

[0002] A business system refers to business links required by an enterprise to achieve positioning, roles played by each partner, and ways and contents of cooperation and transaction of stakeholders. In order to meet the requirements of enterprise audit and supervision, the business system needs to record changes of each data and each field.

[0003] At present, the database log recording method of the business system usually has the following two kinds:

[0004] (1) hard coding in the business code, and then generating database log information by using the hard coding when the business code is executed; however, this will modify the original business code, and invades the original business system, and increases the risk of program errors;

[0005] (2) asynchronously analyzing and processing a log file to obtain database log information; however, since the log file is usually not easy for a user to directly understand, this causes that additional efforts need to be invested to perceive when the log file is analyzed, and the log file usually does not contain information of an operation user, which causes that it is difficult to distinguish who performs the database table operation when the log file is analyzed; and in order to cope with various situations when the log file is analyzed, the business system usually needs to be well designed in the early stage, which will bring a high system reset cost to the formed or running business system. SUMMARY

[0006] The application aims to provide a database log recording method, device, computer equipment and computer readable storage medium, to solve the problems that the existing database log recording method invades the original business system, needs to invest additional efforts to perceive the log file, is difficult to distinguish the operation personnel, and may bring a high business system reset cost.

[0007] In order to achieve the above-mentioned purpose, the application adopts the following technical scheme:

[0008] In a first aspect, a database log recording method is provided, comprising:

[0009] starting to execute a business code for responding to a database operation request initiated by a user after receiving the database operation request;

[0010] When the business code executes the database operation function, a Java annotation is added to the database operation function, wherein the Java annotation refers to annotation content of each field in a Java entity class corresponding to the operation target database table;

[0011] When the database operation function executes the database operation on the operation target database table, the database operation is intercepted based on aspect-oriented programming (AOP) and the following processing logic (A) or (B) is executed:

[0012] (A) If the database operation is a field addition operation or a field deletion operation, first, descriptive log processing is performed according to the Java annotation to obtain descriptive log content; then, the database operation is executed and business data is saved; finally, a timestamp recording the time of the database operation is generated as a log information generation timestamp, and the descriptive log content is added to the log record buffer pool as a piece of database log information;

[0013] (B) If the database operation is a field modification operation, first, a function for querying the pre-modification data state is executed according to the Java annotation to obtain the pre-modification data state of the operation target database table; then, the database operation is executed and business data is saved; then, the difference fields between the pre-modification data state and the post-modification data state of the operation target database table are determined by one-to-one comparison; then, the difference fields are translated according to the annotation content in the Java annotation to obtain field-type log content reflecting the change of the difference fields; finally, a timestamp recording the time of the database operation is generated as a log information generation timestamp, and the field-type log content is added to the log record buffer pool as a piece of database log information;

[0014] When the response to the database operation request ends due to the completion of the execution of the business code, the user information of the user is obtained;

[0015] The database log information and the user information are bound and saved in a database table by calling a log information persistence interface.

[0016] Based on the above invention content, a new database logging scheme based on Java annotation and aspect-oriented programming AOP is provided, that is, after receiving a database operation request initiated by a user, the business code for responding to the request is first started to be executed, then Java annotation is added to the function when the business code executes the database operation function, and then when the function executes the database operation on the target database table, the operation is intercepted based on aspect-oriented programming AOP, and the descriptive log content when the field is added or deleted or the field type log content reflecting the change of the difference field when the field is modified is executed according to the Java annotation, finally the user information is obtained, and the log content and log information timestamp are bound and saved in the database table, so that without hard coding and analyzing the log file, the original business system can be avoided. Invasive effect, additional effort to perceive log files and business system reset costs, at the same time, since the log information and user information will be bound, the operator can also be clearly distinguished, which is beneficial to subsequent enterprise audit and supervision, and is convenient for practical application and promotion.

[0017] In one possible design, the content includes the SPEL expression of the field type, field meaning, field name, and handler processing function.

[0018] In one possible design, the descriptive log processing according to the description nature of the Java annotation obtains the descriptive log content, including:

[0019] The descriptive log processing according to the description nature of the SPEL expression of the deleted field or the added field in the Java annotation obtains the descriptive log content.

[0020] In one possible design, the difference field between the pre-modification data state and the post-modification data state of the operation target database table is determined by field-by-field comparison, including:

[0021] When the database operation is a field modification operation for modifying multiple fields, the input parameter entity class of this field modification operation is taken as the post-modification data state of the operation target database table, and then the difference field between the pre-modification data state and the post-modification data state is determined by field-by-field comparison.

[0022] In one possible design, the field type log content reflecting the change of the difference field is obtained by translation processing according to the annotation content of the difference field in the Java annotation, including:

[0023] According to the SPEL expression / in the field type in the Java annotation and the difference field, a field type log content reflecting the change of the difference field is obtained.

[0024] In one possible design, after the database operation is intercepted based on aspect-oriented programming (AOP) and the processing logic (A) or (B) is executed, the method further includes the following steps.

[0025] When the response to the database operation request is exited due to the termination of the business code execution, the database log information is deleted from the log record buffer pool.

[0026] In one possible design, when the response to the database operation request is ended due to the completion of the business code execution, user information of the user is obtained, including the following steps.

[0027] When the response to the database operation request is ended due to the completion of the business code execution, the user interface (User Interface) is invoked to obtain the user information of the user.

[0028] In the second aspect, a database log recording apparatus is provided, including a code start execution module, a Java annotation adding module, a processing logic execution module, a user information obtaining module and an information binding saving module which are sequentially connected in communication.

[0029] The code start execution module is configured to start execution of a business code for responding to a database operation request initiated by a user after the database operation request is received.

[0030] The Java annotation adding module is configured to add a Java annotation to a database operation function of the business code when the database operation function is executed.

[0031] The processing logic execution module is configured to intercept the database operation based on aspect-oriented programming (AOP) and execute a processing logic (A) or (B) when the database operation function executes a database operation on an operation target database table.

[0032] (A) If the database operation is a field addition operation or a field deletion operation, first, descriptive log processing is performed according to the Java annotation to obtain descriptive log content; then, the database operation is executed and business data is saved; finally, a timestamp recording a time of the database operation is generated as a log information generation timestamp, and the timestamp and the descriptive log content are added as a piece of database log information to a log record buffer pool.

[0033] (B) if the database operation is a field modification operation, first execute a function for querying the pre-modification data state according to the Java annotation, to obtain the pre-modification data state of the operation target database table; then execute the database operation and save the business data; then determine the difference field between the pre-modification data state and the post-modification data state of the operation target database table through one-to-one comparison of fields; then perform translation processing according to the annotation content of the difference field in the Java annotation, to obtain field-type log content for reflecting the change situation of the difference field; finally, add a timestamp recording the time of the database operation as a log information generation timestamp to the log record buffer pool together with the field-type log content as a piece of database log information;

[0034] The user information acquisition module is configured to acquire the user information of the user when the response to the database operation request ends due to the completion of the execution of the business code;

[0035] The information binding and saving module is configured to bind and save the database log information and the user information together in a database table by calling a persistence interface of log information.

[0036] In a third aspect, the present application provides a computer device, comprising a memory, a processor and a transceiver which are sequentially connected in communication, wherein the memory is configured to store a computer program, the transceiver is configured to receive and send messages, and the processor is configured to read the computer program and execute the database log recording method as described in the first aspect or any possible design of the first aspect.

[0037] In a fourth aspect, the present application provides a computer readable storage medium, wherein the computer readable storage medium stores instructions, and when the instructions are run on a computer, the database log recording method as described in the first aspect or any possible design of the first aspect is executed.

[0038] In a fifth aspect, the present application provides a computer program product comprising instructions, and when the instructions are run on a computer, the computer is caused to execute the database log recording method as described in the first aspect or any possible design of the first aspect.

[0039] The above-mentioned scheme has the following beneficial effects:

[0040] (1) The application creatively provides a new database logging scheme based on Java annotation and aspect-oriented programming AOP, that is, after receiving a database operation request initiated by a user, a business code for responding to the request is first started to be executed, then a Java annotation is added to a function when the business code executes a database operation function, and then when the function executes a database operation on a target database table, the operation is intercepted based on aspect-oriented programming AOP, and the Java annotation is cut in to execute to obtain descriptive log content when a field is added or deleted, or field type log content for reflecting the difference field change when a field is modified, finally, user information is obtained and bound with log content and log information generation timestamp to be saved in a database table, so that without hard coding and analyzing log files, the original business system can be avoided to be invasively affected, additional effort is not needed to perceive log files, and business system resetting cost is not brought, and since the log information and user information are bound, the operator can be clearly distinguished, which is beneficial to subsequent enterprise auditing and supervision, and is convenient for practical application and promotion;

[0041] (2) Since the log processing part is abstracted to the entity class level, it can be separated from the business logic code, and will not invade the original code logic, and also reduces the modification to the original business system;

[0042] (3) Since the SPEL expression is introduced, the log description can be customized, and the readability of the log is also enhanced, and the user cannot understand the situation;

[0043] (4) Since the related code of the log processing is integrated in the business system, and the business system shares a transaction, when the business system has an error and the data is not correctly modified, the dirty data will not exist in the log change record;

[0044] (5) Since the log processing buffer pool is introduced, the execution efficiency of the log storage is improved. BRIEF DESCRIPTION OF DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description only some embodiments of the application, and for those skilled in the art, other drawings can be obtained without creative labor on the basis of these drawings.

[0046] Figure 1 The flowchart of the database logging method provided by the embodiment of the application.

[0047] Figure 2A structural schematic diagram of a database log recording device provided by an embodiment of the present application.

[0048] Figure 3 A structural schematic diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the present application will be briefly introduced below with reference to the drawings and the description of the embodiments or the prior art. Obviously, the following description of the drawings is only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor under the premise of the drawings. It should be noted that the description of these embodiment modes is used to help understand the present application, but does not constitute a limitation on the present application.

[0050] It should be understood that although the terms first and second, etc. may be used herein to describe various objects, these objects should not be limited by these terms. These terms are only used to distinguish one object from another object. For example, a first object can be called a second object, and similarly a second object can be called a first object, without departing from the scope of the example embodiments of the present application.

[0051] It should be understood that for the term "and / or" that may appear in the present application, it is only a description of the association relationship of the associated objects, which means that there can be three kinds of relationships, for example, A and / or B, which can represent three cases of A alone, B alone, or A and B together; For example, A, B and / or C, which means that any one of A, B and C or any combination thereof exists; for the term " / and" that may appear in the present application, it is another description of the relationship of another associated object, which means that there can be two kinds of relationships, for example, A / and B, which can represent two cases of A alone or A and B together; in addition, for the character " / " that may appear in the present application, it generally represents an "or" relationship between the associated objects before and after it.

[0052] Embodiment:

[0053] As Figure 1As shown, the database logging method provided by the first aspect of the present embodiment can be, but is not limited to, executed by a computer device with certain computing resources and communicatively connected with a user terminal, such as a platform server, a personal computer (PC, referring to a multi-purpose computer with size, price and performance suitable for personal use), a smart phone, a personal digital assistant (PDA) or a wearable device, etc. Figure 1 As shown, the database logging method can include, but is not limited to, the following steps S1-S5.

[0054] S1. After receiving a database operation request initiated by a user, start executing a business code for responding to the database operation request.

[0055] In the step S1, the database operation request can be, but is not limited to, initiated by the user through a user terminal held by the user, such as initiating a network call request for executing a database operation by clicking a certain button on the user terminal. The business code is one of the essential elements of an existing business system, which can be executed by a conventional way to respond to the database operation request and start execution. In addition, the user terminal can include, but is not limited to, a personal computer, a smart phone, a personal digital assistant or a wearable device, etc.

[0056] S2. When the business code executes a database operation function, add a Java annotation to the database operation function, wherein the Java annotation refers to the content of annotating each field in the operation target database table in the Java entity class corresponding to the operation target database table.

[0057] In the step S2, since in the business system developed based on Java programming technology, a processing mode that Java entity class corresponds to database table is generally adopted, each field in the database table can be annotated in the Java entity class to indicate the field type, field meaning, field name, and SPEL (full name: Spring Expression Language) expression of handler processing function (which is an existing processing function), etc. of the corresponding field, so that when the Java entity class is used for field addition, field modification, and field deletion of the database table, the meaning represented by each field and how to process during log recording can be clearly known. Specifically, the content includes but is not limited to field type, field meaning, field name, and SPEL expression of handler processing function, etc. In addition, the database operation function can also be obtained and applied for execution in the existing business system.

[0058] S3. When the database operation function performs the database operation on the operation target database table, the database operation is intercepted based on aspect-oriented programming AOP, and the processing logic (A) or (B) is cut in and executed.

[0059] (A) If the database operation is a field addition operation or a field deletion operation, first, descriptive log processing according to the Java annotation is performed to obtain descriptive log content; then, the database operation is executed and business data is saved; finally, a timestamp recording the time of the database operation is generated as a log information generation timestamp, and the descriptive log content is added to the log record buffer pool as a piece of database log information.

[0060] In the above processing logic (A), the descriptive log content is specifically a piece of descriptive text, which can not record the data of each added field in detail, or can record the data of each added field in detail. Specifically, the descriptive log processing according to the Java annotation to obtain the descriptive log content includes but is not limited to: the descriptive log processing according to the SPEL expression of the deleted field or the added field in the Java annotation to obtain the descriptive log content; the specific process of the foregoing descriptive log processing is an existing process, which is not described here. In addition, the log information generation timestamp and the descriptive log content can be encapsulated into a log entity, and then the log entity is added to the log record buffer pool as a piece of database log information to wait for persistence. In addition, the execution of the database operation and the saving of business data are conventional technical means in the existing business system.

[0061] (B) If the database operation is a field modification operation, first, a function for querying the pre-modification data state is executed according to the Java annotation to obtain the pre-modification data state of the operation target database table; then, the database operation is executed and the business data is saved; then, the difference fields between the pre-modification data state and the post-modification data state of the operation target database table are determined by one-to-one comparison of fields; then, the field type log content reflecting the change of the difference fields is obtained by translating the annotation content of the difference fields in the Java annotation; finally, the timestamp of the database operation is taken as the log information generation timestamp, and the field type log content is added to the log record buffer pool as a piece of database log information.

[0062] In the above processing logic (B), since the handler attribute (i.e., SPEL expression) needs to be defined in the Java entity class to mark the field type, field meaning, and non-text field of each field, the SPEL expression can be used to translate what processing needs to be performed on the target field during the field modification operation, and further, the user can directly understand the information, i.e., preferably, the field type log content reflecting the change of the difference fields is obtained by translating the annotation content of the difference fields in the Java annotation, including but not limited to: the field type log content reflecting the change of the difference fields is obtained by translating the SPEL expression / field type of the difference fields in the Java annotation. Considering the case of modifying multiple fields at a time, an optional item of executing a database table state query again can be provided, and if the optional item is not marked in the database operation function, the latest state of the data can be used as the input parameter of the database modification operation, i.e., the difference fields between the pre-modification data state and the post-modification data state of the operation target database table are determined by one-to-one comparison of fields, including but not limited to: when the database operation is a field modification operation for modifying multiple fields, the input parameter entity class of the current field modification operation is taken as the post-modification data state of the operation target database table, and then the difference fields between the pre-modification data state and the post-modification data state are determined by one-to-one comparison of fields. In addition, the log information generation timestamp and the field type log content can be packaged into a log entity, and then the log entity is added to the log record buffer pool as a piece of database log information for persistence.

[0063] In the step S3, since the aspect-oriented programming AOP (abbreviation of Aspect Oriented Programming) refers to a technology of realizing unified maintenance of program functions through pre-compilation and dynamic proxy during running, the database operation can be intercepted based on the technology, and the processing logic (A) or (B) is cut in for execution. In addition, the aspect-oriented programming AOP can also perform enhancement processing on the business code.

[0064] S4. When the database operation request is ended in response to the execution completion of the business code, user information of the user is acquired.

[0065] In the step S4, the user information is used for uniquely identifying the user, and can specifically include but is not limited to the account, login password, name, and communication mobile phone number of the user. Specifically, when the database operation request is ended in response to the execution completion of the business code, the user information of the user is acquired, including but not limited to: when the database operation request is ended in response to the execution completion of the business code, the user interface UserInterface is called to acquire the user information of the user. The user interface UserInterface can be provided by an existing business system. In addition, considering that the business code can be terminated due to unexpected problems during execution, in order to ensure that the log recording result does not have errors or dirty data, preferably, after the database operation is intercepted based on the aspect-oriented programming AOP and the processing logic (A) or (B) is cut in for execution, the method further includes but is not limited to: when the database operation request is exited in response to the execution termination of the business code, the database log information is removed from the log recording buffer pool.

[0066] S5. The database log information and the user information are bound and saved in a database table by calling a persistence interface of the log information.

[0067] In the step S5, the persistence interface can also be provided by an existing business system. Since the database log information and the user information are bound and saved in a database table, the enterprise can audit and supervise at any time. After the database log information and the user information are bound and saved in a database table, the database log information also needs to be removed from the log recording buffer pool, so as to release the occupied resources of the log recording buffer pool in time. In addition, the database table can be the same data table as the operation target database table, or can not be the same data table.

[0068] Thus, based on the database logging method described in the foregoing steps S1-S5, a new database logging scheme based on Java annotation and aspect-oriented programming AOP is provided, that is, after receiving a database operation request initiated by a user, first, the business code for responding to the request is executed, then Java annotation is added to the function when the business code executes the database operation function, and then when the function executes the database operation on the target database table, the operation is intercepted based on aspect-oriented programming AOP, and the descriptive log content when the field is added / deleted or the field type log content reflecting the difference field change when the field is modified is executed according to the Java annotation, finally, the user information is obtained, and is bound and saved in the database table together with the log content and log information timestamp, thus without hard coding and analyzing the log file, the original business system can be avoided to be invasively affected, additional effort is not needed to perceive the log file, and the business system reset cost is brought, and since the log information and user information are bound, the operator can also be clearly distinguished, which is beneficial to subsequent enterprise audit and supervision, and is convenient for practical application and promotion.

[0069] As Figure 2 shown, the second aspect of the embodiment provides a virtual device for implementing the database logging method of the first aspect, which includes a code execution module, a Java annotation adding module, a processing logic execution module, a user information acquisition module, and an information binding and saving module which are sequentially connected in communication.

[0070] The code execution module is configured to execute the business code for responding to the database operation request after receiving the database operation request initiated by the user.

[0071] The Java annotation adding module is configured to add Java annotation to the database operation function when the business code executes the database operation function, wherein the Java annotation refers to the content of annotating each field in the operation target database table in the Java entity class corresponding to the operation target database table.

[0072] The processing logic execution module is configured to intercept the database operation based on aspect-oriented programming AOP when the database operation function executes the database operation on the operation target database table, and execute the following processing logic (A) or (B):

[0073] (A) If the database operation is a field addition operation or a field deletion operation, first, a descriptive log processing is performed according to the Java annotation to obtain a descriptive log content; then, the database operation is executed and business data is saved; finally, a timestamp recording the time of the database operation is taken as a log information generation timestamp, and the timestamp and the descriptive log content are added to a log record buffer pool as a piece of database log information;

[0074] (B) If the database operation is a field modification operation, first, a function for querying the data state before modification is executed according to the Java annotation to obtain the data state of the operation target database table before modification; then, the database operation is executed and business data is saved; then, the difference field between the data state before modification and the data state after modification of the operation target database table is determined through one-to-one comparison; then, a translation processing is performed according to the annotation content of the difference field in the Java annotation to obtain a field type log content reflecting the change of the difference field; finally, a timestamp recording the time of the database operation is taken as a log information generation timestamp, and the timestamp and the field type log content are added to a log record buffer pool as a piece of database log information;

[0075] The user information obtaining module is configured to obtain the user information of the user when the response to the database operation request ends due to the completion of the execution of the business code;

[0076] The information binding and saving module is configured to bind and save the database log information and the user information in a database table through a call to a persistence interface of the log information.

[0077] The working process, working details and technical effects of the foregoing device provided by the second aspect of the embodiment can be referred to the database log recording method described in the first aspect, and will not be described here.

[0078] As Figure 3As shown, the third aspect of the embodiment provides a computer device for performing the database logging method of the first aspect, comprising a memory, a processor and a transceiver connected in sequence, wherein the memory is configured to store a computer program, the transceiver is configured to transmit and receive messages, and the processor is configured to read the computer program and perform the database logging method of the first aspect. Specifically, the memory can include, but is not limited to, a random-access memory (RAM), a read-only memory (ROM), a flash memory, a first-in first-out memory (FIFO) and / or a first-in last-out memory (FILO), etc.; and the processor can be, but is not limited to, a microprocessor of the STM32F105 series. In addition, the computer device can further include, but is not limited to, a power module, a display screen and other necessary components.

[0079] The working process, working details and technical effects of the aforementioned computer device provided by the third aspect of the embodiment can be referred to the database logging method of the first aspect, which will not be described here again.

[0080] The fourth aspect of the embodiment provides a computer readable storage medium storing instructions of the database logging method of the first aspect, i.e., the computer readable storage medium stores instructions, and when the instructions run on a computer, the database logging method of the first aspect is performed. The computer readable storage medium refers to a carrier storing data, which can include, but is not limited to, floppy disks, optical disks, hard disks, flash memories, USB flash drives and / or memory sticks, etc. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices.

[0081] The working process, working details and technical effects of the aforementioned computer readable storage medium provided by the fourth aspect of the embodiment can be referred to the database logging method of the first aspect, which will not be described here again.

[0082] The fifth aspect of the embodiment provides a computer program product containing instructions, which, when running on a computer, causes the computer to perform the database logging method of the first aspect. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices.

[0083] Finally, it should be noted that the above description is only the preferred embodiment of the present application, and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A database logging method, characterized by, The application comprises the following steps: After receiving a database operation request initiated by a user, start executing business code for responding to the database operation request; When the business code executes a database operation function, add a Java annotation to the database operation function, wherein the Java annotation refers to the content of annotating each field in the operation target database table in a Java entity class corresponding to the operation target database table; When the database operation function executes a database operation on the operation target database table, intercept the database operation based on aspect-oriented programming (AOP) and cut in to execute the following processing logic: If the database operation is a field addition operation or a field deletion operation, first perform descriptive log processing according to the Java annotation to obtain descriptive log content; then execute the database operation and save business data; finally, add a timestamp recording the database operation as a log information generation timestamp to the log record buffer pool together with the descriptive log content as a piece of database log information; If the database operation is a field modification operation, first execute a function for querying the pre-modification data state according to the Java annotation to obtain the pre-modification data state of the operation target database table; then execute the database operation and save business data; then determine the difference field between the pre-modification data state and the post-modification data state of the operation target database table through one-to-one field comparison; then perform translation processing according to the annotation content of the difference field in the Java annotation to obtain field-type log content reflecting the change of the difference field; finally, add a timestamp recording the database operation as a log information generation timestamp to the log record buffer pool together with the field-type log content as a piece of database log information; When the response to the database operation request ends due to the completion of the execution of the business code, obtain user information of the user; Bind and save the database log information and the user information in a database table together through a call to a log information persistence interface.

2. The database logging method of claim 1, wherein, The content contains field type, field meaning, field name, and SPEL expression of handler processing function.

3. The database logging method of claim 1, wherein, The descriptive log processing according to the Java annotation to obtain descriptive log content comprises the following steps: The descriptive log processing according to the SPEL expression of the deleted field or the added field in the Java annotation to obtain descriptive log content.

4. The database logging method of claim 1, wherein, The determination of the difference field between the pre-modification data state and the post-modification data state of the operation target database table through one-to-one field comparison comprises the following steps: When the database operation is a field modification operation for modifying multiple fields, take the parameter entity class of the current field modification operation as the post-modification data state of the operation target database table, and then determine the difference field between the pre-modification data state and the post-modification data state through one-to-one field comparison.

5. The database logging method of claim 1, wherein, According to the content of the Java annotation and the difference field, the field type log content reflecting the change of the difference field is obtained by translation processing, including: According to the content of the Java annotation and the difference field, the field type log content reflecting the change of the difference field is obtained by translation processing, including:

6. The database logging method according to any one of claims 1 to 5, wherein, After the database operation is intercepted based on aspect-oriented programming AOP and the processing logic is cut in, the method further includes: When the response to the database operation request is exited due to the termination of the business code execution, the database log information is removed from the log record buffer pool.

7. The database logging method of claim 1, wherein, When the response to the database operation request is ended due to the completion of the business code execution, the user information of the user is obtained, including: When the response to the database operation request is ended due to the completion of the business code execution, the user interface UserInterface is called to obtain the user information of the user.

8. A database logging apparatus characterized by comprising: The code startup execution module, the Java annotation adding module, the processing logic execution module, the user information obtaining module and the information binding saving module are sequentially communicatively connected; The code startup execution module is used to start the execution of the business code for responding to the database operation request after receiving the database operation request initiated by the user; The Java annotation adding module is used to add Java annotations to the database operation function when the business code executes the database operation function, wherein the Java annotations refer to the content of annotating each field in the operation target database table in the Java entity class corresponding to the operation target database table; The processing logic execution module is used to intercept the database operation based on aspect-oriented programming AOP and cut in to execute the following processing logic when the database operation function executes the database operation on the operation target database table: If the database operation is a field addition operation or a field deletion operation, first, descriptive log processing is performed according to the Java annotation to obtain descriptive log content; then, the database operation is executed and business data is saved; finally, the timestamp recording the database operation is taken as a log information generation timestamp, and the descriptive log content is taken together as a piece of database log information added to the log record buffer pool. If the database operation is a field modification operation, a function for querying the pre-modification data state is executed according to the Java annotation to obtain the pre-modification data state of the operation target database table; then the database operation is executed and business data is saved; then the difference field between the pre-modification data state and the post-modification data state of the operation target database table is determined by one-to-one comparison of fields; then the difference field is translated according to the annotation content of the difference field in the Java annotation to obtain field-type log content reflecting the change of the difference field; finally, a timestamp recording the time of the database operation is taken as a log information generation timestamp, and the field-type log content is added to the log record buffer pool as a piece of database log information. The user information obtaining module is configured to obtain the user information of the user when the response to the database operation request ends due to the completion of the execution of the business code; The information binding and saving module is configured to bind and save the database log information and the user information in a database table by calling a log information persistence interface.

9. A computer device, comprising: The computer readable storage medium has instructions stored thereon, and when the instructions are run on a computer, the database log recording method according to any one of claims 1-7 is executed.

10. A computer-readable storage medium, characterized in that The computer readable storage medium has instructions stored thereon, and when the instructions are run on a computer, the database log recording method according to any one of claims 1-7 is executed.

Citation Information

Patent Citations

  • Operation log recording method and device, computer equipment and storage medium

    CN111708749A

  • Method and system for querying database, as well as a recording medium for storing a database querying program

    US20010051939A1