Java-based memory transaction management method

By empowering Java class data structures as Diff classes, the problem of memory data rollback under complex memory data structures is solved, realizing memory-level transaction management and multi-level nested transaction processing, supporting Java native collections and basic data types, and ensuring efficient rollback and recovery of data in abnormal situations.

CN116185572BActive Publication Date: 2026-07-10TOPJOY

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TOPJOY
Filing Date
2023-03-09
Publication Date
2026-07-10

Smart Images

  • Figure CN116185572B_ABST
    Figure CN116185572B_ABST
Patent Text Reader

Abstract

The Java-based memory transaction management method disclosed by the embodiment of the application comprises the following steps: enabling a Java class data structure to be a Diff class; obtaining a transaction context instance of a Diff object through a unique identifier rootID of the Diff object; executing a start method of the transaction context to start a transaction; executing original business logic to modify memory data of the Diff object; after the execution of the business logic, if the business logic is normal, executing a commit method of the transaction context to submit the transaction, and ending the transaction; if the business logic has an exception, executing a rollback method of the transaction context to roll back the transaction, restoring modified data content of the Diff object, and ending the transaction. The Java-based memory transaction management method realizes memory level transaction processing of Java objects and object attributes, supports complex class data structure and multi-layer transaction nested execution, and provides a method with application potential for transaction management based on memory data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of memory data processing technology, specifically relating to a Java-based memory transaction management method. Background Technology

[0002] During the processing of business logic, in the event of program exceptions or specific business scenarios, it is necessary to roll back the modified memory data to its previous state. This requires the program to have memory-level data transaction processing capabilities. However, the actual memory data structure is very complex, with various nested and referenced relationships, and the program code execution process is also very complex. Recording the modified data in memory and rolling back these modifications has become a technical challenge. Summary of the Invention

[0003] In view of this, some embodiments disclose a Java-based memory transaction management method, including:

[0004] Java class data structures can be enabled to become Diff classes;

[0005] The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object;

[0006] The transaction context executes the start method to begin the transaction;

[0007] Execute the original business logic and modify the memory data of the Diff object;

[0008] After the business logic is executed,

[0009] If the business logic is normal, the transaction context executes the commit method to commit the transaction, and the transaction ends.

[0010] If there is an exception in the business logic, the transaction context executes the rollback method to roll back the transaction, restore the modified data content of the Diff object, and the transaction ends.

[0011] Furthermore, some embodiments disclose Java-based memory transaction management methods, where Java class data structures are enabled to become Diff classes, including:

[0012] Data structure classes inherit from DiffObject;

[0013] For member attributes of data structure classes, add a method to retrieve values, execute the method provided by the parent class DiffObject, and update the data change path of the attribute node;

[0014] For member attributes of data structure classes, add an assignment method to execute the parent class DiffObject method and record each change in attribute data in the transaction context.

[0015] Some embodiments of the Java-based memory transaction management method disclosed, which enable Java class data structures to become Diff classes, also include:

[0016] For member attributes of collection classes, replace Java List and Java Set data types with DArrayList; replace Java Map data types with DHashMap.

[0017] Some embodiments disclose Java-based memory transaction management methods, where Java class data structures are enabled to become Diff classes, including:

[0018] In the root node class constructor, the root node identifier and root node path properties are initialized to ensure that each root node class object instance has a unique root node identifier and that each instance object corresponds to a transaction context.

[0019] Some embodiments disclose a Java-based memory transaction management method that updates the data change path of an attribute node, wherein the attribute node data includes the name of the attribute and the current value of the attribute.

[0020] Some embodiments disclose a Java-based memory transaction management method that records each change in attribute data in the transaction context. The changes in attribute data include the name of the attribute, the value of the attribute after modification, and the value of the attribute before modification.

[0021] Some embodiments of the Java-based memory transaction management method disclose obtaining the transaction context instance of the Diff object through its unique identifier rootID, including:

[0022] Obtain the root node identifier rootID through the root node Diff object;

[0023] The transaction context instance corresponding to the root node identifier rootID is obtained through the transaction context management class.

[0024] Some embodiments disclose a Java-based memory transaction management method, in which memory transactions include multiple nested transactions, and the management of multiple transactions is performed in a nested manner.

[0025] Some embodiments disclose Java-based memory transaction management methods, in which a second transaction is nested within a first transaction, and the nested management methods for the first and second transactions include:

[0026] Java class data structures can be enabled to become Diff classes;

[0027] The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object;

[0028] The transaction context executes the start method to begin the first transaction, including creating the first transaction and creating the first Diff data cache pool.

[0029] Execute the first transaction business logic, modify the memory data of the Diff object, and record the Diff data;

[0030] The transaction context executes the start method again to begin the transaction;

[0031] Create a second transaction and a second Diff data cache pool;

[0032] Execute the second transaction business logic, modify the memory data of the Diff object, and record the Diff data;

[0033] After all business logic is executed, if all business logic is normal, the transaction context executes the commit method to commit the second transaction, committing the recorded modified Diff content to the first transaction and recording the Diff data; the transaction context executes the commit method to commit the first transaction, committing the recorded modified Diff content to the transaction context's DiffMap, the DiffMap records the modified Diff content, and the transaction ends.

[0034] Some embodiments disclose Java-based memory transaction management methods, in which a second transaction is nested within a first transaction, and the nested management methods for the first and second transactions include:

[0035] Java class data structures can be enabled to become Diff classes;

[0036] The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object;

[0037] The transaction context executes the start method to begin the first transaction, including creating the first transaction and creating the first Diff data cache pool.

[0038] Execute the first transaction business logic, modify the memory data of the Diff object, and record the Diff data;

[0039] The transaction context executes the start method again to begin the second transaction, including creating the second transaction and creating the second Diff data cache pool.

[0040] Execute the second transaction logic, modify the memory data of the Diff object, and record the Diff data;

[0041] After all business logic is executed, if the second transaction's business logic has an exception while the first transaction's business logic is normal, the transaction context executes the rollback method to roll back the second transaction, clearing the recorded Diff modifications and restoring the modified values ​​through Java reflection. The transaction context then executes the commit method to commit the first transaction, submitting the recorded modified Diff content to the transaction context's DiffMap. The DiffMap records the Diff modifications, and the transaction ends.

[0042] The Java-based memory transaction management method disclosed in this invention realizes memory-level transaction processing of Java objects and object attributes, while supporting complex class data structures, such as basic data types, Java native collections List and Map, and multi-level nested transaction execution. It provides a method with application potential for memory-based transaction management. Attached Figure Description

[0043] Figure 1 Some embodiments disclose schematic flowcharts of Java-based memory transaction management methods. Figure 1 ;

[0044] Figure 2 Some embodiments disclose schematic flowcharts of Java-based memory transaction management methods. Figure 2 ;

[0045] Figure 3 Some embodiments disclose schematic flowcharts of Java-based memory transaction management methods. Figure 3 . Detailed Implementation

[0046] The term "embodiment" used herein, as an example, is not necessarily to be construed as superior to or better than other embodiments. Performance testing in these embodiments of the invention, unless otherwise specified, employs conventional testing methods in the art. It should be understood that the terminology used in these embodiments is merely for describing particular implementations and is not intended to limit the scope of the disclosure of these embodiments.

[0047] Unless otherwise stated, the technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the embodiments of this invention pertain; other experimental methods and technical means not specifically noted in the embodiments of this invention refer to experimental methods and technical means commonly used by one of ordinary skill in the art.

[0048] In this document, including in the claims, conjunctions such as "comprising," "including," "with," "having," "containing," "involving," and "accommodating" are understood to be open-ended, meaning "including but not limited to." Only the conjunctions "consisting of" and "composed of" are closed conjunctions.

[0049] To better illustrate the content of this invention, numerous specific details are provided in the following detailed embodiments. Those skilled in the art should understand that the invention can be practiced even without certain specific details. In the embodiments, some methods, means, instruments, and devices well-known to those skilled in the art are not described in detail, in order to highlight the main points of the invention.

[0050] Without conflict, the technical features disclosed in the embodiments of the present invention can be combined arbitrarily, and the resulting technical solutions belong to the content disclosed in the embodiments of the present invention.

[0051] In this paper, a transaction refers to a unit of program execution that accesses and may update various data items in a database. Transactions are typically triggered by the execution of user programs written in high-level database manipulation languages ​​or programming languages ​​such as SQL, C++, or Java, and are delimited by statements or function calls such as `begin transaction` and `end transaction`. A transaction consists of all operations executed between the start of the transaction (`begin transaction`) and the end of the transaction (`end transaction`). A class is the foundation of Object-Oriented Programming (OOP) for information encapsulation; it is a user-defined reference data type, also known as a class type. Each class contains data descriptions and a set of functions for manipulating data or passing messages. Instances of a class are called objects. `DiffObject` is the basic transaction class, a Java class used to empower existing program code. The `Diff` class refers to the transaction data class, a Java class modified from the business program, inheriting from the `DiffObject` class. A `Diff` object is a transaction data object; during program runtime, instances of the `Diff` class are stored in runtime memory. The `Diff` object carries business memory data and is the object of memory transaction management in this embodiment of the invention. DiffPath refers to the data change path, used to record the node paths for data modifications in memory. Each data modification of a Diff object will have a corresponding DiffPath. TransactionContext refers to the transaction context, which is the transaction context for data modifications in memory. During program execution, each Diff object corresponds to a transaction context, which manages the transaction cycle of the Diff object and records the content of each memory data modification.

[0052] In some implementations, such as Figure 1As shown, Java-based memory transaction management methods include transforming data structures into transactional data classes (Diff classes), and then modifying the business program to add transaction logic processing. Typically, transforming data structures into data classes involves empowering Java class data structures to become Diff classes. Complex class data structures can be transformed into transactional data classes, including basic data types, Java native collections List and Map, as well as nested classes.

[0053] Modify the business logic and add transaction logic processing steps, including:

[0054] The transaction context instance of the Diff object is obtained by using the unique identifier rootID of the root node of the Diff object. Typically, the root node identifier rootID is obtained from the root node Diff object, and then the transaction context corresponding to the root node identifier rootID is obtained from the transaction context management class TransactionContextManager.

[0055] The transaction context executes the start method to begin the transaction; typically, the transaction context's start function is executed before the business logic modifies the inner data to begin the transaction cycle.

[0056] Execute the original business logic and modify the memory data of the Diff object;

[0057] After the business logic is executed,

[0058] If the business logic is normal and the business execution is successful, the transaction context executes the commit method to commit the transaction and the transaction ends.

[0059] If an exception occurs in the business logic and the business execution fails, the transaction context executes the `rollback` method to roll back the transaction, restoring the modified data content of the `Diff` object, and the transaction ends. Transaction rollback is typically performed at an appropriate point in the business logic, such as where an exception is caught.

[0060] In some embodiments, Java class data structures are enabled to become Diff classes, including:

[0061] Data structure classes inherit from DiffObject;

[0062] For member properties of data structure classes, add a getter method. In the getter method, execute the updatedPath() method provided by the parent class DiffObject to update the data change path Diffpath of the property node. The input parameters are usually the name of the property and the current value of the property.

[0063] For member attributes of data structure classes, add a setter method. In the setter method, execute the fieldChanged() method of the parent class DiffObject to record each change in attribute data in the transaction context TransactionContext. The input parameters are usually the name of the attribute, the value of the attribute after modification, and the value of the attribute before modification. The attribute name is usually expressed as a string.

[0064] In some embodiments, Java class data structures are enabled to become Diff classes, including:

[0065] For member attributes of collection classes, replace Java List and Java Set data types with DArrayList; replace Java Map data types with DHashMap.

[0066] In some embodiments, the transaction context instance of the Diff object is obtained through its unique identifier, rootID, including:

[0067] Obtain the root node identifier rootID through the root node Diff object;

[0068] The transaction context instance corresponding to the root node identifier rootID is obtained through the transaction context management class.

[0069] In some embodiments, Java class data structures are enabled to become Diff classes, including:

[0070] In the constructor of the root node class, the root node identifier rootID and the root node path Diffpath property are initialized to ensure that each root node class object instance has a unique root node identifier rootID and that each instance object corresponds to a transaction context TransactionContext.

[0071] Some embodiments disclose a Java-based memory transaction management method, in which memory transactions include multiple transactions, and the management of multiple transactions is nested.

[0072] In some embodiments of the Java-based memory transaction management method disclosed, such as Figure 2 As shown, methods for modifying business procedures and adding transaction logic processing include:

[0073] The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object;

[0074] The transaction context executes the start method to begin the first transaction; this includes the transaction context creating the first transaction and creating the first Diff data cache pool.

[0075] Execute the first transaction business logic, modify the memory data of the Diff object, and record the Diff data;

[0076] The transaction context executes the start method again to begin the second transaction; this includes the transaction context creating the second transaction and creating the second Diff data cache pool.

[0077] Execute the second transaction business logic, modify the memory data of the Diff object, and record the Diff data;

[0078] After all business logic is executed, if the business logic of the first transaction and the second transaction is normal, the transaction context executes the commit method to commit the second transaction, and commits the recorded modified Diff content to the first transaction, and records the Diff data.

[0079] The transaction context executes the commit method to commit the first transaction, and commits the recorded modified Diff content to the transaction context's DiffMap. The DiffMap records the modified Diff content, and the transaction ends.

[0080] In some embodiments of the Java-based memory transaction management method disclosed, such as Figure 3 As shown, methods for modifying business procedures and adding transaction logic processing include:

[0081] The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object;

[0082] The transaction context executes the start method to begin the first transaction; this includes the transaction context creating the first transaction and creating the first Diff data cache pool.

[0083] Execute the first transaction business logic, modify the memory data of the Diff object, and record the Diff data;

[0084] The transaction context executes the start method again to begin the second transaction, including creating the second transaction and creating the second Diff data cache pool.

[0085] Execute the second transaction logic, modify the memory data of the Diff object, and record the Diff data;

[0086] After all business logic is executed, if the second transaction's business logic has an exception while the first transaction's business logic is normal, the transaction context executes the rollback method to roll back the second transaction, clearing the recorded Diff modifications and restoring the modified values ​​through Java reflection. The transaction context then executes the commit method to commit the first transaction, submitting the recorded modified Diff content to the transaction context's DiffMap. The DiffMap records the Diff modifications, and the transaction ends.

[0087] The Java-based memory transaction management method disclosed in this invention realizes memory-level transaction processing of Java objects and object attributes, while supporting complex class data structures, such as basic data types, Java native collections List and Map, and multi-level nested transaction execution. It provides a method with application potential for memory-based transaction management.

[0088] The technical solutions and technical details disclosed in the embodiments of this invention are merely illustrative of the inventive concept of this invention and do not constitute a limitation on the technical solutions of the embodiments of this invention. Any conventional changes, substitutions, or combinations made to the technical details disclosed in the embodiments of this invention have the same inventive concept as this invention and are within the protection scope of the claims of this invention.

Claims

1. A Java-based memory transaction management method, characterized in that, include: Java class data structures can be made into Diff classes; specifically, this includes: the data structure class inheriting from DiffObject; for the member attributes of the data structure class, adding a getter method to execute the method provided by the parent class DiffObject and update the data change path of the attribute node; for the member attributes of the data structure class, adding an assignment method to execute the method of the parent class DiffObject and record each change of attribute data in the transaction context; The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object; The transaction context executes the start method to begin the transaction; Execute the original business logic and modify the memory data of the Diff object; After the business logic is executed, If the business logic is normal, the transaction context executes the commit method to commit the transaction, and the transaction ends. If there is an exception in the business logic, the transaction context executes the rollback method to roll back the transaction, restore the modified data content of the Diff object, and the transaction ends.

2. The Java-based memory transaction management method according to claim 1, characterized in that, The ability to transform a Java class data structure into a Diff class also includes: For member attributes of collection classes, replace Java List and Java Set data types with DArrayList; replace Java Map data types with DHashMap.

3. The Java-based memory transaction management method according to claim 1, characterized in that, The Java class data structure is enabled to become a Diff class, including: In the root node class constructor, the root node identifier and root node path properties are initialized to ensure that each root node class object instance has a unique root node identifier and that each instance object corresponds to a transaction context.

4. The Java-based memory transaction management method according to claim 1, characterized in that, Update the data change path of the attribute node, where the input parameters include the name of the attribute and the current value of the attribute.

5. The Java-based memory transaction management method according to claim 1, characterized in that, Each change in attribute data is recorded in the transaction context, where the input parameters include the attribute name, the modified value of the attribute, and the original value of the attribute.

6. The Java-based memory transaction management method according to claim 1, characterized in that, The step of obtaining the transaction context instance of the Diff object through its unique identifier rootID includes: Obtain the root node identifier rootID through the root node Diff object; The transaction context instance corresponding to the root node identifier rootID is obtained through the transaction context management class.

7. The Java-based memory transaction management method according to claim 1, characterized in that, If a memory transaction includes multiple nested transactions, the management of these multiple transactions is performed in a nested manner.

8. The Java-based memory transaction management method according to claim 7, characterized in that, The first transaction contains a nested second transaction. The methods for managing nested first and second transactions include: Java class data structures can be enabled to become Diff classes; The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object; The transaction context executes the start method to begin the first transaction, including creating the first transaction and creating the first Diff data cache pool. Execute the first transaction business logic, modify the memory data of the Diff object, and record the Diff data; The transaction context executes the start method again to begin the second transaction, including creating the second transaction and creating a second Diff data cache pool. Execute the second transaction business logic, modify the memory data of the Diff object, and record the Diff data; After all business logic has been executed... If all business logic is normal, the transaction context executes the commit method to commit the second transaction, submitting the recorded modified Diff content to the first transaction and recording the Diff data; the transaction context instance executes the commit method to commit the first transaction, submitting the recorded modified Diff content to the transaction context's DiffMap, the DiffMap records the modified Diff content, and the transaction ends.

9. The Java-based memory transaction management method according to claim 7, characterized in that, The first transaction contains a nested second transaction. The methods for managing nested first and second transactions include: Java class data structures can be enabled to become Diff classes; The transaction context instance of the Diff object can be obtained by using the unique identifier rootID of the Diff object; The transaction context executes the start method to begin the first transaction, including creating the first transaction and creating the first Diff data cache pool. Execute the first transaction business logic, modify the memory data of the Diff object, and record the Diff data; The transaction context instance executes the start method again to begin the second transaction, including creating the second transaction and creating a second Diff data cache pool. Execute the second transaction logic, modify the memory data of the Diff object, and record the Diff data; After all business logic has been executed... If the business logic of the second transaction is abnormal, while the business logic of the first transaction is normal, the transaction context executes the rollback method to roll back the second transaction, clears the recorded Diff modifications, and restores the modified values ​​through Java reflection. The transaction context then executes the commit method to commit the first transaction, submitting the recorded modified Diff content to the transaction context's DiffMap. The DiffMap records the Diff modifications, and the transaction ends.