General data change historical record method

Through custom annotation and extension interface methods, combined with the Javers and MyBatis framework, the complexity and security problems of data change tracking in enterprise-level applications built by Java language are solved, and a simple and efficient data change history is achieved, which improves the maintainability and flexibility of the system.

CN120255855APending Publication Date: 2025-07-04JIANGSU FINANCIAL LEASING
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510357073.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-25
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

In the enterprise-level application built by the Java language, data change tracking relies on hard coding to cause complex encoding, low maintainability, limited scalability and security risks, making it difficult to meet the needs of flexible data comparison.

Method used

Through custom annotation and extension interfaces, combined with Javers and MyBatis frameworks, the difference detection and change history of entity objects are realized, the annotation configuration comparison rules are used, and SPI dynamic loading and formatting output is supported, which simplifies the generation of data change history.

Benefits of technology

It realizes a simple and efficient data change history, improves development efficiency and system maintainability, reduces error rates, and enhances system flexibility and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120255855A_ABST
    Figure CN120255855A_ABST
Patent Text Reader

Abstract

The invention discloses an entity object comparison method based on user-defined annotations and an expansion interface, and relates to the technical field of computer data processing, a comparison rule is defined by defining annotations such as a definition (at) ID, a definition (at) DiffIgnore, a definition (at) AttributeField and a definition (at) AttributeEntity, user-defined logic is expanded by utilizing a CustomValueComparator interface, object differences are detected in combination with a Java framework, and a standardized change historical record is generated. The method supports the SPI to dynamically load the comparator, annotes drive configuration and change persistence, remarkably improves the development efficiency and the system maintainability, and is suitable for a business scene needing to record the data change history.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer data processing, and in particular to a general method for recording data change history. Background Art

[0002] In enterprise applications built with the Java language, traditional data change tracking usually relies on Java's reflection mechanism. This method involves checking the properties of Java Beans one by one in a hard-coded manner to compare data changes. However, this approach has its inherent limitations:

[0003] 1. Complex coding: When processing entity objects using this method, developers need to write and maintain a large amount of code. This not only requires considering the differences in primary keys between different entities, different field descriptions, but also dealing with issues such as fields to be ignored, undoubtedly increasing the coding complexity.

[0004] 2. Low maintainability: Hard-coded solutions are often difficult to interpret. Especially when the code needs to be modified later, it increases the cognitive burden on developers and affects the readability and maintainability of the code.

[0005] 3. Scalability limitations: As the project develops, entity classes may add new attributes or undergo structural adjustments. Traditional methods may require manual updating of the reflection logic to adapt to these changes, which is not conducive to the long-term expansion and maintenance of the system.

[0006] 4. Security issues: The reflection mechanism may break encapsulation, allowing private attributes and methods to be accessed externally, which may introduce potential security risks.

[0007] For the above reasons, the present invention designs a general method for recording data change history, which is used to simplify the difference detection and change history generation of complex objects and collections, and supports configuring comparison rules through annotations, customizing comparison logic extension, and formatted output. Summary of the Invention

[0008] The object of the present invention is to solve the problems in the prior art, and to propose a general method for recording data change history.

[0009] A method for comparing entity objects based on custom annotations and extended interfaces, characterized by including the following steps:

[0010] S1: Customize comparison annotations: Develop custom annotations to clarify the rules for comparing change history, and define the unique identifier of the field, the ignore comparison flag, the group attribution, and the display name;

[0011] S2: Define a comparison extension interface. When an object with complex attributes is involved, customize the comparison logic for specific data types by implementing the CustomValueComparator interface, and dynamically load the custom comparison logic based on the SPI mechanism;

[0012] S3: Create a comparison utility class: encapsulate the comparison operation so that it can be conveniently applied to ordinary objects or collection objects;

[0013] S4: Develop specific comparison logic using the Javers framework, and generate a formatted change history record according to the comparison logic. The formats include:

[0014] Modification operation record: Modify {specific expression} {field display name 1}: {old value} → {new value}; {field display name 2}: {old value} → {new value};

[0015] Add {specific expression};

[0016] Delete {specific expression};

[0017] S5: Persist the change history: Design a change history storage table, and persistently store the change history record through the MyBatis framework.

[0018] In the above general data change history record method;

[0019] Define the @AttributeField annotation to include a grouping identifier, a field belonging object, and a custom display name, which is used to replace the field path with a business-readable display name in the change history record;

[0020] Define @AttributeEntity to mark complex attribute fields. After marking, the field attributes can be expanded;

[0021] Define @ID to mark the unique ID of the entity and judge the uniqueness of the entity;

[0022] Define @DiffIgnore to ignore entity attributes for comparison.

[0023] In the above general data change history record method;

[0024] Define AchievePreDescItf to obtain characteristic description fields when comparing collections to get the change history. Implement this interface to obtain such fields;

[0025] Define BelongItf which may need to be implemented when grouping.

[0026] In the above general data change history recording method, in step S3, the ChangeHistoryUtil tool is called, and the underlying comparison logic is encapsulated based on the Javers framework. The ChangeHistoryUtil tool class provides object Change Function and collectChange Function methods, which are used to compare the changes of a single object and a collection of objects respectively.

[0027] In the above general data change history recording method, the specific description is custom-generated by implementing the Achieve PreDescItf interface and is used for the prefix description of the collection change record.

[0028] In the above general data change history recording method, in step S5, the structure of the change history storage table includes operation type, entity type, entity unique ID, field path, old value, and new value fields.

[0029] In the above general data change history recording method, in step S5, the structure of the change history storage table includes operation type, entity type, entity unique ID, field path, old value, and new value fields

[0030] Compared with the existing technologies, the advantages of the present invention are as follows:

[0031] The present invention simplifies the data comparison process of complex Java Bean objects and collection objects. The user only needs to annotate the entity objects with annotations instead of performing complex coding processes, which greatly reduces the workload and error rate of developers. The advantages of this method are as follows:

[0032] 1. Concise and efficient: Through the annotation method, the data mapping rules can be intuitively configured on the JavaBean, simplifying the code volume and improving the development efficiency.

[0033] 2. Easy to maintain: Using the annotation method can make the code clearer and easier to understand, reducing the difficulty of subsequent maintenance and the possibility of errors.

[0034] 3. Strong flexibility: By configuring different annotation parameters, various complex comparison objects can be flexibly processed to meet the requirements in different scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 It is a flowchart in a general data change history recording method proposed by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0036] Refer to Figure 1 , a general data change history recording method, includes the following steps

[0037] 1. Custom comparison annotations: Develop custom annotations to clarify the rules for comparing change histories. These annotations can identify key attributes such as primary keys and comparison field descriptions, thus providing guidance for subsequent comparison operations;

[0038] Among them, the present invention defines the following annotations for marking Java Bean objects and fields:

[0039] @AttributeField: Used to mark the group to which the field belongs, the Java Bean object to which it belongs, the custom display name, etc.

[0040] @AttributeEntity: Used to mark complex attribute fields. After marking, the field attributes can be expanded.

[0041] @ID: The unique ID of the Java Bean entity, used to judge the uniqueness of the entity.

[0042] @DiffIgnore: Ignore the entity attributes to be compared.

[0043] 2. Define a comparison extension interface: For objects containing complex attributes, implement custom comparison logic by extending the CustomValueComparator interface. This ensures that the comparison process can adapt to the specific requirements of different data structures;

[0044] This solution defines the following interfaces for extension:

[0045] AchievePreDescItf: When obtaining the change history by comparing a collection, implement this interface to obtain the characteristic description field.

[0046] BelongItf: This interface may need to be implemented during grouping.

[0047] CustomValueComparator: In addition to the built-in comparators for the three types of BaseEnumDict, BigDecimal, and DictionaryInfo, this solution also supports customizing comparison logic by implementing the CustomValueComparator interface. Among them, the custom comparator can be dynamically loaded and extended through the SPI (Service Provider Interface) mechanism.

[0048] 3. Implement specific operation logic: Utilize the Javers framework to develop specific comparison logic. This step involves capturing change details such as object modifications, additions, and deletions, providing detailed data support for the change history record.

[0049] 4. Create a comparison utility class: encapsulate comparison operations so that they can be conveniently applied to ordinary objects or collection objects. This encapsulation improves code reusability and maintainability;

[0050] This solution constructs a utility class called ChangeHistoryUtil, which encapsulates the underlying comparison logic based on the Javers framework and provides the following utility methods:

[0051] objectChangeFunction: used to compare the changes of a single object.

[0052] collectChangeFunction: used to compare the changes of a collection of objects.

[0053] 5. Persistence of change history: Design a change history storage table and use the MyBatis framework to implement the persistent storage of change history. This step ensures the long-term preservation and traceability of change data.

[0054] This solution defines the change history record format as follows:

[0055] 1. Modify {specific expression}{change field name 1}: {before change content} ---> {after change content}; {change field name 2}: {before change content} ---> {after change content};

[0056] 2. Add {specific expression};

[0057] 3. Delete {specific expression}.

[0058] This solution comprehensively uses custom annotations, the Javers framework, the MyBatis framework, and the SPI mechanism, significantly improving the clarity, maintainability, and scalability of data change history records.

[0059] As is known by common technical knowledge, the present invention can be implemented by other embodiments that do not depart from its spiritual essence or essential features. Therefore, the above-disclosed embodiments are illustrative in all aspects and not exclusive. All changes within the scope of the present invention or equivalent to the present invention are encompassed by the present invention.

Claims

1. A method for comparing entity objects based on custom annotations and extension interfaces, characterized in that It includes the following steps: S1: Customize comparison annotations: Develop custom annotations to clarify the rules for comparing change history, and define the unique identifier of the field, the ignore comparison flag, the group belonging, and the display name; S2: Define a comparison extension interface. When dealing with objects containing complex attributes, customize the comparison logic for specific data types by implementing the CustomValueComparator interface, and dynamically load the custom comparison logic based on the SPI mechanism; S3: Create a comparison utility class: Package the comparison operation so that it can be conveniently applied to ordinary objects or collection objects; S4: Develop specific comparison logic using the Javers framework, and generate a formatted change history record according to the comparison logic. The formats of the change history record include: Modify {specific description}{changed field name 1}: {content before change}--->{content after change}; {changed field name 2}: {content before change}--->{content after change}; Add {specific description}; Delete {specific description}; S5: Persist the change history: Design a change history storage table, and persistently store the change history record through the MyBatis framework.

2. The entity object comparison method based on custom annotations and extended interfaces according to claim 1, characterized in that: In step S1: Define the @AttributeField annotation to include the group identifier, the field belonging object, and the custom display name, which is used to replace the field path with a business-readable display name in the change history record; Define @AttributeEntity to mark complex attribute fields, and the field attributes can be expanded after marking; Define @ID to mark the unique ID of the entity and judge the uniqueness of the entity; Define @DiffIgnore to ignore the entity attributes to be compared.

3. The entity object comparison method based on custom annotations and extension interfaces according to claim 1, characterized in that: In step S2: Define AchievePreDescItf to obtain the characteristic description field when implementing this interface for set comparison to obtain the change history; Define BelongItf which may need to be implemented for grouping.

4. The entity object comparison method based on custom annotations and extended interfaces according to claim 1, characterized in that: In step S3, call the ChangeHistoryUtil tool to encapsulate the underlying comparison logic based on the Javers framework. The ChangeHistoryUtil tool class provides object Change Function and collectChangeFunction methods, which are used to compare the changes of a single object and a collection of objects respectively.

5. The entity object comparison method based on custom annotations and extended interfaces according to claim 3, characterized in that: The specific description is customized through implementing the Achieve PreDescItf interface and is used for the prefix description of the set change record.

6. The entity object comparison method based on custom annotations and extended interfaces according to claim 1, characterized in that: In step S5, the structure of the change history storage table includes operation type, entity type, entity unique ID, field path, old value, and new value fields.

7. The method for comparing entity objects based on custom annotations and extension interfaces according to claim 1, wherein: In step S2, comparators of three types, namely BaseEnumDict, BigDecimal, and DictionaryInfo, are also built-in.