Database optimistic lock implementation method and system based on SpringBoot + JPA

An implementation method and database technology, applied in the database field, can solve problems such as data duplication, and achieve the effects of avoiding data duplication, promoting the use value, and using a wide range of applications.

Active Publication Date: 2020-01-21
SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF6 Cites 2 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0008] The technical task of the present invention is to provide a database optimistic lock implementation method and system based on SpringBoot+JPA to solve the problem of how to use optimistic locks to avoid data duplication in the process of regularly inserting data into the database under concurrent conditions

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Database optimistic lock implementation method and system based on SpringBoot + JPA
  • Database optimistic lock implementation method and system based on SpringBoot + JPA

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0049] as attached figure 1 As shown, the database optimistic lock implementation method based on SpringBoot+JPA of the present invention, the method steps are as follows:

[0050]S1. Create a lock_table table: create a new lock_table table in the database, and the lock_table is used to store lock data information; the lock data information includes lock name (lock_name), version number (version) and status (lock_state). The lock_table table structure is designed as follows:

[0051] lock_name version lock_state lock name version number state

[0052] S2. Operation lock: lock the concurrent transaction operation, and add the data information of the lock in the lock_table table in the database; the details are as follows:

[0053] S201. Obtaining a lock: query the lock_table table to obtain information about the lock, and ensure that the corresponding process acquires the lock; the steps are as follows:

[0054] (1) Query the lock information in lo...

Embodiment 2

[0063] as attached figure 2 Shown, the database optimistic locking system based on SpringBoot+JPA of the present invention, this system comprises,

[0064] The lock_table table creation module is used to create a new lock_table table in the database, and the lock_table is used to store lock data information; the lock data information includes lock name (lock_name), version number (version) and status (lock_state).

[0065] The locking operation module is used to lock the concurrent transaction operation, and increase the data information of the lock in the lock_table table in the database;

[0066] Among them, the locking operation module includes,

[0067] The lock acquisition module is used to query the lock_table table to acquire lock information, and ensure that the corresponding process acquires the lock;

[0068] The transaction execution module is used to continue the execution of the corresponding process and complete the transaction operation on the database;

[0...

Embodiment 3

[0078] Take the concurrent transaction operation lock A as an example:

[0079] Add the data of lock A in the lock_table table of the database. The execution steps of concurrent transaction locking are as follows:

[0080] 1) Acquiring a lock: Query the information of lock A in lock_table. If the version number of lock A is less than the current date and the status is "unlocked", execute the update statement to update the status of lock A to "locked", and the update statement adds @ Transactional, @Modifying annotations, after successful execution, the return value is the number of updated data items. If the number of data items updated by process A is greater than 0, it means that process A has acquired the lock. Process A continues to execute the next step, and other processes that have not acquired the lock terminate execution.

[0081] 2) Executing a transaction: Process A continues to execute and completes the transaction operation on the database.

[0082] 3) Release...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

PUM

No PUM Login to view more

Abstract

The invention discloses a database optimistic lock implementation method and system based on SpringBoot + JPA, and belongs to the field of database. The technical problem to be solved by the inventionis how to avoid data repetition in the process of regularly inserting data into a database under a concurrent condition by using an optimistic lock. The adopted technical scheme is as follows: the method comprises the following steps: S1, creating a lock _ table: creating a new lock _ table in a database, wherein the lock _ table is used for storing data information of a lock; S2, operation locking: locking the concurrent transaction operation, and adding data information of the lock in a lock _ table in a database; the method specifically comprising the following steps: S201, acquiring a lock: querying a lock _ table to acquire information of the lock, and ensuring that a corresponding process acquires the lock; S202, executing the transaction: continuously executing the corresponding process to finish the transaction operation on the database; and S203, releasing the lock: after the transaction execution is finished, updating the version number of the corresponding lock to be the current date by the corresponding process, updating the state to be unlocked, and finishing the operation. The system comprises a lock _ table creating module and a locking operation module.

Description

technical field [0001] The invention relates to the field of databases, in particular to a database optimistic lock implementation method and system based on SpringBoot+JPA. Background technique [0002] SpringBoot is an open source application framework on the Java platform that provides a container with inversion of control features. The framework uses a specific approach to configuration, so that developers no longer need to define boilerplate configuration. [0003] JPA is the abbreviation of Java Persistence API. The Chinese name is Java Persistence Layer API. It is JDK 5.0 annotation or XML description object-relational table mapping relationship, and persists the entity object in the runtime to the database. [0004] Concurrency means that multiple execution units are executed simultaneously and in parallel, and the access of concurrent execution units to shared resources (hardware resources and software global variables, static variables, etc.) can easily lead to ra...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to view more

Application Information

Patent Timeline
no application Login to view more
Patent Type & Authority Applications(China)
IPC IPC(8): G06F16/22G06F16/23
CPCG06F16/2282G06F16/2329G06F16/2322
Inventor 孙文君吴东生于法栋
Owner SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products