CN110333883B - Method and device for updating persistent data - Google Patents

Method and device for updating persistent data Download PDF

Info

Publication number
CN110333883B
CN110333883B CN201910472372.7A CN201910472372A CN110333883B CN 110333883 B CN110333883 B CN 110333883B CN 201910472372 A CN201910472372 A CN 201910472372A CN 110333883 B CN110333883 B CN 110333883B
Authority
CN
China
Prior art keywords
entity
updated
fields
field
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910472372.7A
Other languages
Chinese (zh)
Other versions
CN110333883A (en
Inventor
林春成
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xiamen Wangsu Co Ltd
Original Assignee
Xiamen Wangsu Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xiamen Wangsu Co Ltd filed Critical Xiamen Wangsu Co Ltd
Priority to CN201910472372.7A priority Critical patent/CN110333883B/en
Publication of CN110333883A publication Critical patent/CN110333883A/en
Application granted granted Critical
Publication of CN110333883B publication Critical patent/CN110333883B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

Abstract

The invention discloses a method and a device for updating persistent data, wherein the method comprises the following steps: acquiring a first entity, wherein the first entity comprises all fields of an object to be updated and values of the fields to be updated; acquiring all fields of the object to be updated and values of all fields from a storage device, and storing the fields and values in a second entity; updating the value of the field to be updated in the second entity to the value of the field to be updated in the first entity; and persisting the updated second entity to the storage device. The operation of updating the persistent data is intelligently controlled, so that tedious repeated manual judgment can be reduced, and the data updating can be completed efficiently.

Description

Method and device for updating persistent data
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for updating persistent data.
Background
At present, when a developer designs a program, the data is always required to be persisted into a disk, and the data is repeatedly added, deleted, modified or queried. When performing the "modify" operation, it is often necessary to modify one or more fields, and the remaining fields retain the original values.
At present, the modification of the persistent data is usually carried out manually, a great amount of repeated work exists in the modification process, and the manual modification mode is complex, time-consuming and labor-consuming.
Disclosure of Invention
In order to solve the problems in the prior art, the embodiment of the invention provides a method and a device for updating persistent data. The technical scheme is as follows:
in a first aspect, there is provided a method of updating persistent data, the method comprising:
acquiring a first entity, wherein the first entity comprises all fields of an object to be updated and values of the fields to be updated;
acquiring all fields of the object to be updated and values of all fields from a storage device, and storing the fields and values in a second entity;
updating the value of the field to be updated in the second entity to the value of the field to be updated in the first entity;
and persisting the updated second entity to the storage device.
Optionally, the step of obtaining the first entity includes:
acquiring parameters of entity class;
the first entity is generated based on the parameters.
Optionally, the step of acquiring all the fields of the object to be updated and the values of the fields from the storage device includes:
judging whether the value of an identification field of an object to be updated in the first entity is empty or not;
if so, ending the flow, otherwise, acquiring all the fields of the object to be updated and the values of all the fields from the storage device.
Optionally, before the step of determining whether the value of the identification field of the object to be updated in the first entity is null, the method includes:
and acquiring the value of the identification field of the object to be updated in the first entity through a Java reflection mechanism.
Optionally, the step of updating the value of the field to be updated in the second entity to the value of the field to be updated in the first entity includes:
acquiring all fields in the first entity and traversing all fields;
and if the field with the value not being null exists, taking the field with the value not being null as the field to be updated, and assigning the value of the field to be updated to the field which is the same as the field to be updated in the second entity.
Optionally, the step of acquiring all fields in the first entity further includes:
judging whether the data of the second entity is empty or not;
if yes, the flow ends, otherwise all fields in the first entity are acquired.
In a second aspect, there is provided an apparatus for updating persistent data, the apparatus comprising:
the first acquisition module is used for acquiring a first entity, wherein the first entity comprises all fields of an object to be updated and values of the fields to be updated;
the second acquisition module is used for acquiring all the fields of the object to be updated and the values of all the fields from the storage device and storing the values in a second entity;
the updating module is used for updating the value of the field to be updated in the second entity to the value of the field to be updated in the first entity;
and the persistence module is used for persisting the updated second entity into the storage equipment.
Optionally, the first obtaining module is specifically configured to:
acquiring parameters of entity class;
the first entity is generated based on the parameters.
Optionally, the second obtaining module is specifically configured to:
judging whether the value of an identification field of an object to be updated in the first entity is empty or not;
if so, ending the flow, otherwise, acquiring all the fields of the object to be updated and the values of all the fields from the storage device.
Optionally, the second obtaining module is further specifically configured to:
and acquiring the value of the identification field of the object to be updated in the first entity through a Java reflection mechanism.
Optionally, the persistence module is specifically configured to:
acquiring all fields in the first entity and traversing all fields;
and if the field with the value not being null exists, taking the field with the value not being null as the field to be updated, and assigning the value of the field to be updated to the field which is the same as the field to be updated in the second entity.
Optionally, the persistence module is further specifically configured to:
judging whether the data of the second entity is empty or not;
if yes, the flow ends, otherwise all fields in the first entity are acquired.
In a third aspect, a computer device is provided, the computer device comprising a processor and a memory, the memory storing at least one instruction, at least one program, a set of codes, or a set of instructions, the at least one instruction, the at least one program, the set of codes, or the set of instructions being loaded and executed by the processor to implement the method of updating persistent data as described in the first aspect above.
When the persistent data is updated, the fields needing to be updated and the fields not needing to be updated in the first entity can be automatically obtained through intelligent analysis, old data can be automatically obtained from the storage device and stored as the second entity, the value of the fields to be updated in the first entity is assigned to the second entity, and finally the updated second entity is persisted into the storage device.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for processing a query price according to an embodiment of the present invention;
FIG. 2 is a block diagram of an inquiry processing device according to an embodiment of the present invention;
fig. 3 is a block diagram of a computer device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the embodiments of the present invention will be described in further detail with reference to the accompanying drawings.
The data persisted into the storage device is saved in the form of a database table. The database table may include data for a plurality of objects, each of which may include a plurality of fields, each field having a corresponding value. For example, object a includes fields with values of id, f1, f2, and f3, 1, a2, and a3, respectively. Wherein the id field in the object is used to uniquely identify a record in the database table, i.e. to uniquely identify an object. To distinguish from other fields in an object, the id field in an object is referred to herein as an identification field. When the value of a certain field needs to be modified, for example, the value of the field f2 is changed from a2 to b2, the method for updating the persistent data provided by the embodiment of the invention can be utilized for modifying, and the specific modification flow is as follows.
Referring to fig. 1, a flowchart of a method for updating persistent data according to an embodiment of the present invention is provided, and the method specifically includes the following steps.
Step 101, a first entity is obtained, wherein the first entity comprises all fields of an object to be updated and values of the fields to be updated.
The first ENTITY is an ENTITY of the ENTITY class. The first entity comprises all field information of the object to be updated and values to be modified by the fields to be updated, and the values of the other fields are null. For example, the first entity has an id value of 1, f2 has a value of b2, and both f1 and f3 have values of null. The fields in the first entity that are not null are fields that need to be updated, and the fields that are null are fields that do not need to be updated.
In an implementation, parameters of the ENTITY class, i.e. information to be updated, may be manually input at the application layer, the information to be updated including an id of an object to be updated, a field to be updated in the object to be updated, and a value of the field to be updated. After the information to be updated is acquired, a first entity is generated. Optionally, the pre-created first entity may also be directly obtained, and the embodiment of the present invention does not specifically limit a manner of obtaining the first entity.
And 102, acquiring all the fields of the object to be updated and the values of the fields from the storage device, and storing the values in a second entity.
After the first entity is obtained, the value of the identification field of the object to be updated in the first entity, namely the value of the id in the first entity, is obtained through a Java reflection mechanism. The Java reflection mechanism is a function capable of dynamically acquiring information and dynamically calling an object method. And then judging whether the value of the identification field of the object to be updated in the first entity is empty or not. If the parameters are empty, the process is finished if the parameter is erroneously transmitted, otherwise, all fields of the object to be updated and values of all fields are obtained from the storage device and are stored in a second ENTITY which is the same ENTITY as the ENTITY class. For example, the value of di in the second entity is 1, the value of f1 is a1, the value of f2 is a2, and the value of f3 is a3.
Step 103, updating the value of the field to be updated in the second entity to the value of the field to be updated in the first entity.
After the second entity is obtained, judging whether the data of the second entity is empty, if so, ending the flow, otherwise, updating the value of the field to be updated in the second entity to the value of the field to be updated in the first entity. The specific updating flow is as follows: acquiring all fields in the first entity and traversing all fields; and if the field with the value not being null exists, taking the field with the value not being null as the field to be updated, and assigning the value of the field to be updated to the field which is the same as the field to be updated in the second entity. For example, in the first entity, only the value of f2 is not null, the value b2 of f2 is assigned to f2 in the second entity, the value of f2 is modified from a2 to b2, and the values of the other fields are unchanged, so that the updating operation is completed.
In implementations, all fields in the first entity may be acquired through an introspection mechanism and a reflection mechanism. The introspection mechanism is a default handling method of the Java language for Bean class attributes and events, which accesses object attributes through get or set (modification) methods.
And step 104, persisting the updated second entity to the storage device.
After updating the second entity, the second entity is saved to a permanently storable storage device, such as a disk, i.e., the data is completed to be persisted.
Embodiments of the present invention are not limited to the type of entity, and may be, for example, a cat entity or a dog entity, where the entity may include any type of attribute, and no additional processing is required for different entities.
When the persistent data is updated, the fields needing to be updated and the fields not needing to be updated in the first entity can be automatically obtained through intelligent analysis, old data can be automatically obtained from the storage device and stored as the second entity, the value of the fields to be updated in the first entity is assigned to the second entity, and finally the updated second entity is persisted into the storage device.
Referring to fig. 2, a block diagram of an apparatus for updating persistent data according to an embodiment of the present invention includes:
a first obtaining module 201, configured to obtain a first entity, where the first entity includes all fields of an object to be updated and values of the fields to be updated;
a second obtaining module 202, configured to obtain all the fields of the object to be updated and the values of the fields from the storage device, and store the values in a second entity;
an updating module 203, configured to update the value of the field to be updated in the second entity to the value of the field to be updated in the first entity;
a persistence module 204, configured to persist the updated second entity to the storage device.
Preferably, the first obtaining module 201 is specifically configured to:
acquiring parameters of entity class;
the first entity is generated based on the parameters.
Preferably, the second obtaining module 202 is specifically configured to:
judging whether the value of an identification field of an object to be updated in the first entity is empty or not;
if so, ending the flow, otherwise, acquiring all the fields of the object to be updated and the values of all the fields from the storage device.
Preferably, the second obtaining module 202 is further specifically configured to:
and acquiring the value of the identification field of the object to be updated in the first entity through a Java reflection mechanism.
Preferably, the persistence module 203 is specifically configured to:
acquiring all fields in the first entity and traversing all fields;
and if the field with the value not being null exists, taking the field with the value not being null as the field to be updated, and assigning the value of the field to be updated to the field which is the same as the field to be updated in the second entity.
Preferably, the persistence module 204 is further specifically configured to:
judging whether the data of the second entity is empty or not;
if yes, the flow ends, otherwise all fields in the first entity are acquired.
When the persistent data is updated, the fields needing to be updated and the fields not needing to be updated in the first entity can be automatically obtained through intelligent analysis, old data can be automatically obtained from the storage device and stored as the second entity, the value of the fields to be updated in the first entity is assigned to the second entity, and finally the updated second entity is persisted into the storage device.
It should be noted that: the apparatus for updating persistent data according to the above embodiment may be implemented based on a computer program, and the apparatus is only exemplified by the division of the above functional modules when updating persistent data, and in practical application, the above functional allocation may be performed by different functional modules according to needs, that is, the internal structure of the apparatus is divided into different functional modules to perform all or part of the functions described above. In addition, the apparatus for updating persistent data provided in the foregoing embodiment and the method embodiment for updating persistent data belong to the same concept, and detailed implementation processes of the apparatus for updating persistent data are referred to in the method embodiment, which is not described herein again.
Fig. 3 is a schematic structural diagram of a computer device according to an embodiment of the present invention. The computer device 300 may vary considerably in configuration or performance and may include one or more central processors 322 (e.g., one or more processors) and memory 332, one or more storage media 330 (e.g., one or more mass storage devices) storing applications 342 or data 344. Wherein the memory 332 and the storage medium 330 may be transitory or persistent. The program stored on the storage medium 330 may include one or more modules (not shown), each of which may include a series of instruction operations in a computer device. Still further, the central processor 322 may be configured to communicate with the storage medium 330 to execute a series of instruction operations in the storage medium 330 on the computer device 300.
The computer device 300 may also include one or more power supplies 324, one or more wired or wireless network interfaces 350, one or more input/output interfaces 358, one or more keyboards 354, and/or one or more operating systems 341, such as Windows ServerTM, mac OS XTM, unixTM, linuxTM, freeBSDTM, and the like.
The computer device 300 may include a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising instructions for performing the above-described log processing.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and the storage medium may be a read only memory, a storage device or an optical disc, etc.
The foregoing description of the preferred embodiments of the invention is not intended to limit the invention to the precise form disclosed, and any such modifications, equivalents, and alternatives falling within the spirit and scope of the invention are intended to be included within the scope of the invention.

Claims (11)

1. A method of updating persistent data, the method comprising:
acquiring a first entity, wherein the first entity comprises all fields of an object to be updated and values of the fields to be updated, and the values of the other fields are null;
acquiring all fields of the object to be updated and values of all fields from a storage device, and storing the fields and values in a second entity;
updating the value of the field to be updated in the second entity to the value of the field to be updated in the first entity comprises: acquiring all fields in the first entity and traversing all fields; if a field with a value not being null exists, the field with the value not being null is used as the field to be updated, and the value of the field to be updated is assigned to the field which is the same as the field to be updated in the second entity;
and persisting the updated second entity to the storage device.
2. The method of claim 1, wherein the step of acquiring the first entity comprises:
acquiring parameters of entity class;
the first entity is generated based on the parameters.
3. The method of claim 1, wherein the step of obtaining all fields of the object to be updated and values of the respective fields from a storage device comprises:
judging whether the value of an identification field of an object to be updated in the first entity is empty or not;
if so, ending the flow, otherwise, acquiring all the fields of the object to be updated and the values of all the fields from the storage device.
4. A method according to claim 3, wherein before the step of determining whether the value of the identification field of the object to be updated in the first entity is empty, it comprises:
and acquiring the value of the identification field of the object to be updated in the first entity through a Java reflection mechanism.
5. The method of claim 1, wherein the step of obtaining all fields in the first entity further comprises:
judging whether the data of the second entity is empty or not;
if yes, the flow ends, otherwise all fields in the first entity are acquired.
6. An apparatus for updating persistent data, the apparatus comprising:
the first acquisition module is used for acquiring a first entity, wherein the first entity comprises all fields of an object to be updated and values of the fields to be updated, and the values of the other fields are null;
the second acquisition module is used for acquiring all the fields of the object to be updated and the values of all the fields from the storage device and storing the values in a second entity;
an updating module, configured to update the value of the field to be updated in the second entity to the value of the field to be updated in the first entity, including: acquiring all fields in the first entity and traversing all fields; if a field with a value not being null exists, the field with the value not being null is used as the field to be updated, and the value of the field to be updated is assigned to the field which is the same as the field to be updated in the second entity;
and the persistence module is used for persisting the updated second entity into the storage equipment.
7. The apparatus of claim 6, wherein the first acquisition module is specifically configured to:
acquiring parameters of entity class;
the first entity is generated based on the parameters.
8. The apparatus of claim 6, wherein the second acquisition module is specifically configured to:
judging whether the value of an identification field of an object to be updated in the first entity is empty or not;
if so, ending the flow, otherwise, acquiring all the fields of the object to be updated and the values of all the fields from the storage device.
9. The apparatus of claim 8, wherein the second acquisition module is further specifically configured to:
and acquiring the value of the identification field of the object to be updated in the first entity through a Java reflection mechanism.
10. The apparatus of claim 6, wherein the persistence module is further specifically configured to:
judging whether the data of the second entity is empty or not;
if yes, the flow ends, otherwise all fields in the first entity are acquired.
11. A computer device comprising a processor and a memory having stored therein at least one instruction, at least one program, code set, or instruction set that is loaded and executed by the processor to implement the method of updating persistent data of any of claims 1 to 5.
CN201910472372.7A 2019-05-31 2019-05-31 Method and device for updating persistent data Active CN110333883B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910472372.7A CN110333883B (en) 2019-05-31 2019-05-31 Method and device for updating persistent data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910472372.7A CN110333883B (en) 2019-05-31 2019-05-31 Method and device for updating persistent data

Publications (2)

Publication Number Publication Date
CN110333883A CN110333883A (en) 2019-10-15
CN110333883B true CN110333883B (en) 2023-05-16

Family

ID=68140648

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910472372.7A Active CN110333883B (en) 2019-05-31 2019-05-31 Method and device for updating persistent data

Country Status (1)

Country Link
CN (1) CN110333883B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115086442B (en) * 2022-08-15 2022-12-27 恒生电子股份有限公司 Data processing method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1776676A (en) * 2004-11-18 2006-05-24 国际商业机器公司 Management of metadata in a storage subsystem, system and computer program
CN103345501A (en) * 2013-06-27 2013-10-09 华为技术有限公司 Method and device for updating database
CN105677250A (en) * 2016-01-04 2016-06-15 北京百度网讯科技有限公司 Method and device for updating object data in object storage system

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101216789A (en) * 2008-01-08 2008-07-09 福建星网锐捷网络有限公司 Data update method, device and system
US8260793B2 (en) * 2009-06-29 2012-09-04 Raytheon Company Method and system for data class update
CN103853671B (en) * 2012-12-07 2018-03-02 北京百度网讯科技有限公司 A kind of data write-in control method and device
CN103440204B (en) * 2013-08-28 2016-01-27 华为技术有限公司 A kind of method of updating file system and memory device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1776676A (en) * 2004-11-18 2006-05-24 国际商业机器公司 Management of metadata in a storage subsystem, system and computer program
CN103345501A (en) * 2013-06-27 2013-10-09 华为技术有限公司 Method and device for updating database
CN105677250A (en) * 2016-01-04 2016-06-15 北京百度网讯科技有限公司 Method and device for updating object data in object storage system

Also Published As

Publication number Publication date
CN110333883A (en) 2019-10-15

Similar Documents

Publication Publication Date Title
EP3716090A1 (en) Data processing method, apparatus and system
CN109492053B (en) Method and device for accessing data
US11526475B2 (en) Code generator platform for data transformation
CN112860953A (en) Data importing method, device, equipment and storage medium of graph database
CN110333883B (en) Method and device for updating persistent data
CN113568924A (en) Data processing method and device, electronic equipment and storage medium
CN113190576A (en) Data processing method and device, computer equipment and readable storage medium
CN111159142B (en) Data processing method and device
CN116010345A (en) Method, device and equipment for realizing table service scheme of flow batch integrated data lake
US8595251B2 (en) Flexible interface module
CN113342270A (en) Volume unloading method and device and electronic equipment
EP3436972A1 (en) Multiform persistence abstraction
CN109522014B (en) Algorithm processing method based on new product development, electronic device and readable storage medium
CN112214521A (en) Rule query method, device, equipment and computer storage medium
CN115941834B (en) Automatic operation method, device, equipment and storage medium of smart phone
US11947931B2 (en) Generic factory class
CN113687920B (en) Object policy operation method, device and equipment of distributed system
US20080016029A1 (en) Optimizing a query to a database
CN114706918B (en) Multi-type database compatibility method, device, equipment and storage medium
CN117271641A (en) Data processing method, device and storage medium
CN107729013B (en) Method for managing operation buttons on web page and computer-readable storage medium
CN109905475B (en) Method for outputting cloud computing monitoring data in specified format based on SQL
CN116186112A (en) Metadata query method, device, equipment and computer readable storage medium
CN116595010A (en) Database index optimization method, storage medium and device
CN117130937A (en) Test case processing method, device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant