CN111125110B - Non-primary key field checking method, device, computer equipment and storage medium - Google Patents

Non-primary key field checking method, device, computer equipment and storage medium Download PDF

Info

Publication number
CN111125110B
CN111125110B CN201911352694.4A CN201911352694A CN111125110B CN 111125110 B CN111125110 B CN 111125110B CN 201911352694 A CN201911352694 A CN 201911352694A CN 111125110 B CN111125110 B CN 111125110B
Authority
CN
China
Prior art keywords
data entity
entity class
database
result set
modified
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
CN201911352694.4A
Other languages
Chinese (zh)
Other versions
CN111125110A (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.)
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Original Assignee
Shenzhen Qianhai Huanrong Lianyi Information Technology Service 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 Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd filed Critical Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority to CN201911352694.4A priority Critical patent/CN111125110B/en
Publication of CN111125110A publication Critical patent/CN111125110A/en
Application granted granted Critical
Publication of CN111125110B publication Critical patent/CN111125110B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • G06F16/285Clustering or classification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • G06F16/288Entity relationship models

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method, a device, computer equipment and a storage medium for checking non-primary key fields, wherein the method comprises the following steps: acquiring a non-primary key field which is transmitted by a front end and needs to be subjected to uniqueness check, and acquiring a field value of a data entity class under the non-primary key field; inquiring records with the same field value in a database through the encapsulation class, and returning a result set in a list form; judging whether the result set is empty or not; if the result set is empty, controlling to allow the data entity class to be newly added or modified in a database; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database. The invention improves the reusability and efficiency of the inspection method.

Description

Non-primary key field checking method, device, computer equipment and storage medium
Technical Field
The present invention relates to the field of data storage, and in particular, to a method and apparatus for checking non-primary key fields, a computer device, and a storage medium.
Background
When a certain entity class data is newly added or modified, besides a certain record ID of the database, whether a certain non-primary key field is unique or not needs to be judged, for example, when information of a legal person is inserted or newly added, whether the corresponding mobile phone number and the identity card are unique or not needs to be judged, namely, whether the same record of the mobile phone number or the identity card number exists in the database or not needs to be judged. Under the condition that most of the new and the modification share the same interface, even if the database is queried that the same mobile phone number or identity card number exists, whether the record belongs to the modification of the same record or the new record needs to be judged according to whether the main key ID exists in the entity class transmitted from the front end. In various projects, certain fields of entity class need to be subjected to uniqueness detection, such as when core enterprise information is newly built and modified, enterprise name or simply uniqueness is required, newly added legal information identity card number and mobile phone number are unique, in an actual project, multiple places are involved in judgment of the logic, the judgment of the logic is repeated, reusability is low, even codes of a plurality of private methods are written for achieving the constraint, and therefore time is consumed and faults such as judgment errors are easy to occur.
In view of the above-mentioned problems with the prior art, there is a need for optimization and improvement of the prior art.
Disclosure of Invention
The embodiment of the invention provides a method, a device, computer equipment and a storage medium for checking non-primary key fields, which aim to solve the problems of low reusability and low efficiency of the existing checking method.
In a first aspect, an embodiment of the present invention provides a method for checking uniqueness of a non-primary key field in a database, including:
acquiring an object corresponding to a data entity class under a mybatis-plus packet, and constructing an encapsulation class for checking uniqueness of a non-primary key field in the object;
acquiring a data entity class which is transmitted by the front end and needs to be newly added or modified;
acquiring a non-primary key field which is transmitted by a front end and needs to be subjected to uniqueness check, and acquiring a field value of the data entity class under the non-primary key field;
inquiring records with the same field value in a database through the packaging class, and returning a result set in a list form;
judging whether the result set is empty or not;
if the result set is empty, controlling to allow the data entity class to be newly added or modified in a database; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database.
Preferably, the obtaining the non-primary key field that needs to be checked for uniqueness and is transmitted by the front end, and obtaining a field value of the data entity class under the non-primary key field, includes:
transmitting non-primary key fields needing to be subjected to uniqueness check according to a hump naming format;
and acquiring a field value of the data entity class under the non-primary key field.
Preferably, the ID is a primary key field having uniqueness.
Preferably, if the result set is empty, controlling to allow the data entity class to be newly added or modified in the database includes:
when new addition processing is needed, the data entity class is controlled to be stored in the database as a new record;
when the modification processing is required, control does not allow the modification processing.
Preferably, if the result set is not empty, determining whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database, including:
if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class;
if the ID recorded in the result set is different from the ID of the data entity class, confirming that the non-primary key field does not meet the uniqueness, and controlling not to allow the data entity class to be newly added or modified in the database.
Preferably, if the result set is not empty, determining whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and further including:
if the ID recorded in the result set is the same as the ID of the data entity class, judging whether the data entity class needs to be newly added or modified;
if the new processing of the data entity class is needed, the control does not allow the new processing;
and if the modification processing of the data entity class is needed, controlling the modification processing of the record corresponding to the ID in the database.
Preferably, if the result set is not empty, determining whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and further including:
if the result set is not empty, judging whether the number of records in the result set is 1;
if the ID recorded in the result set is 1, judging whether the ID is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database;
if not, the control does not allow the data entity class to be newly added or modified in the database.
In a second aspect, an embodiment of the present invention provides a device for checking uniqueness of a non-primary key field in a database, including:
the construction unit is used for acquiring an object corresponding to the data entity class under the mybs-plus package, and constructing an encapsulation class for checking uniqueness of the non-primary key field in the object;
the data transmission unit is used for acquiring the data entity class which is transmitted by the front end and needs to be newly added or modified;
the field input unit is used for acquiring a non-primary key field which is input by the front end and needs to be subjected to uniqueness check, and acquiring a field value of the data entity class under the non-primary key field;
the query unit is used for querying the records with the same field value in the database through the encapsulation class and returning a result set in a list form;
a result set judging unit for judging whether the result set is empty;
the control unit is used for controlling the permission of newly adding or modifying the data entity class in the database if the result set is empty; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database.
In a third aspect, an embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the method for checking uniqueness of non-primary key fields in a database according to the first aspect when the computer program is executed.
In a fourth aspect, an embodiment of the present invention provides a computer readable storage medium, on which a computer program is stored, which when executed by a processor implements a method for checking uniqueness of non-primary key fields in a database according to the first aspect.
The embodiment of the invention provides a method, a device, computer equipment and a storage medium for checking non-primary key fields, wherein the method comprises the following steps: acquiring an object corresponding to a data entity class under a mybatis-plus packet, and constructing an encapsulation class for checking uniqueness of a non-primary key field in the object; acquiring a data entity class which is transmitted by the front end and needs to be newly added or modified; acquiring a non-primary key field which is transmitted by a front end and needs to be subjected to uniqueness check, and acquiring a field value of the data entity class under the non-primary key field; inquiring records with the same field value in a database through the packaging class, and returning a result set in a list form; judging whether the result set is empty or not; if the result set is empty, controlling to allow the data entity class to be newly added or modified in a database; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database. The method improves the reusability and efficiency of the inspection method. The method is suitable for any entity class under the mybatis-plus framework, and solves the repeated and complicated detection problem of new addition or modification.
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 obvious that the drawings in the following description are 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 schematic flow chart of a method for checking uniqueness of non-primary key fields in a database according to an embodiment of the present invention;
fig. 2 is a schematic block diagram of a device for checking uniqueness of non-primary key fields in a database according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It should be understood that the terms "comprises" and "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations.
Referring to fig. 1, fig. 1 is a flowchart of a method for checking uniqueness of non-primary key fields in a database according to an embodiment of the present invention, where the method may include steps S101 to S106:
s101, acquiring an object corresponding to a data entity class under a mybatis-plus package, and constructing an encapsulation class for checking uniqueness of a non-primary key field in the object;
the object is a service corresponding to a data entity class under a mybatis-plus package, and the service is provided with a list method and can query data meeting the conditions according to the query conditions.
mybatis-plus (MP for short) is an enhancement tool of mybatis, and is developed based on mybatis in a simplified way, and efficiency is improved. Some methods are packaged in mybatis-plus, and the methods are directly called without rewriting xml.
The invention solves the problem of repeated codes in the prior art, and enables the developer to concentrate more energy on the service codes of the core. The invention is suitable for all entity classes by the characteristic of the incoming JAVA inner generalization, and can use the method to abstract the whole detection logic as long as the Service class of mybatis-Plus corresponding to the data entity class exists, thereby realizing the compatibility of diversified entity classes and reducing the writing of trivial and complex codes in the prior art.
Specifically, a query Wrapper (encapsulation class) may be constructed within the object to check for non-primary key field uniqueness and return the result set in a list.
S102, acquiring a data entity class which is transmitted by a front end and needs to be newly added or modified;
the step is that the front end transmits in the data entity class, which is the content needing to be added or modified.
S103, acquiring a non-primary key field which is transmitted by a front end and needs to be subjected to uniqueness check, and acquiring a field value of the data entity class under the non-primary key field;
in this step, the non-primary key field to be checked for uniqueness is determined, i.e. the name of the non-primary key field or the names of the non-primary key fields need to be entered in advance, and the non-primary key field or the non-primary key fields need to be checked for uniqueness is defined.
Meanwhile, after determining the non-primary key field to be subjected to the uniqueness check, a field value of the data entity class under the non-primary key field can be acquired. For example, the non-primary key field is a mobile phone number, and then the field value is a specific mobile phone number.
S104, inquiring records which are the same as the field values in a database through the packaging class, and returning a result set in a list form;
the query procedure may be performed in a database through the encapsulation class. I.e. a record is queried which is identical to the field value, i.e. a record is queried which is identical to the field value of the non-primary key field. And then returning the result set in the form of a list.
S105, judging whether the result set is empty or not;
the step may first determine whether the result set is empty, if there is a record in the result set, it is determined that it is not empty, and if there is no record in the result set, it is determined that it is empty.
S106, if the result set is empty, controlling to allow the data entity class to be newly added or modified in a database; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database.
This step may be performed differently depending on the situation of the result set. For example, when the result set is empty, control allows the data entity class to be added or modified in the database. When the result set is not empty, it is further required to determine whether the ID recorded in the result set is different from the ID of the data entity class, and control according to the determination result. If the ID of the record is different from the ID of the data entity class, it is indicated that there is a record currently, and the field value of the non-primary key field is the same as the field value of the non-primary key field in the data entity class, so that the data entity class is not allowed to be newly added or modified in the database at this time. If the recorded ID is the same as the ID of the data entity class, control allows the data entity class to be added or modified in the database.
In an embodiment, the obtaining the non-primary key field that needs to be checked for uniqueness and is transmitted by the front end, and obtaining a field value of the data entity class under the non-primary key field, includes:
transmitting non-primary key fields needing to be subjected to uniqueness check according to a hump naming format;
and acquiring a field value of the data entity class under the non-primary key field.
In this embodiment, the non-primary key field that needs to be checked for uniqueness is entered in a hump naming format. And then acquiring a field value of the data entity class under the non-primary key field, for example, the non-primary key field is a mobile phone number, and then the field value is the field value of the data entity class under the mobile phone number, namely, a specific mobile phone number. Hump naming, i.e. camel naming, is when a variable name or function name is a unique identification word consisting of one or more words joined together, the first word starts with a lowercase letter; the first letter of each word after the beginning of the second word is in uppercase letters, such as: myFirstName, myLastName.
In one embodiment, the ID is a primary key field with uniqueness. That is, among the records stored in the database, there should be a unique identifier, which is a primary key field, and the ID can be used to distinguish between the records.
In an embodiment, if the result set is empty, controlling to allow the data entity class to be newly added or modified in the database includes:
when new addition processing is needed, the data entity class is controlled to be stored in the database as a new record;
when the modification processing is required, control does not allow the modification processing.
In this embodiment, if the result set is empty, it indicates that there is no field value in the database that is the same as the data entity class under the non-primary key field. If a new class of data entities needs to be added to the database, the data entity class can be inserted into the database at this time as a new record, since the field value does not exist in the database before. If the data entity class needs to be modified in the database, since the field value does not exist in the database before, no basis for modification exists at this time, i.e. modification processing is not allowed.
In an embodiment, if the result set is not empty, determining whether the ID recorded in the result set is different from the ID of the data entity class, if not, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database, including:
if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class;
if the ID recorded in the result set is different from the ID of the data entity class, confirming that the non-primary key field does not meet the uniqueness, and controlling not to allow the data entity class to be newly added or modified in the database.
In this embodiment, if the result set is not null, it is indicated that the same field value exists in the database as the data entity class under the non-primary key field. At this time, it is necessary to determine whether the ID recorded in the result set is different from the ID of the data entity class.
If the ID recorded in the result set is not identical to the ID of the data entity class, in this case, if the data entity class is allowed to be newly added in the database, the non-primary key field will not satisfy the uniqueness, and if the data entity class is allowed to be modified in the database, since the IDs of the two are not identical, there is no basis for modification, so the control in this step does not allow the data entity class to be newly added or modified in the database.
In an embodiment, if the result set is not empty, determining whether the ID recorded in the result set is different from the ID of the data entity class, if not, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database, and further including:
if the ID recorded in the result set is the same as the ID of the data entity class, judging whether the data entity class needs to be newly added or modified;
if the new processing of the data entity class is needed, the control does not allow the new processing;
and if the modification processing of the data entity class is needed, controlling the modification processing of the record corresponding to the ID in the database.
In this embodiment, if the ID recorded in the result set is the same as the ID of the data entity class, it is necessary to confirm whether the data entity class is newly added or modified.
If the new data entity class is needed, the new processing is not allowed because the corresponding record exists in the database. If the data entity class needs to be modified, the basis of the modification is the corresponding record in the database, so that the modification processing can be directly carried out on the record corresponding to the ID in the database.
In an embodiment, if the result set is not empty, determining whether the ID recorded in the result set is different from the ID of the data entity class, if not, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database, and further including:
if the result set is not empty, judging whether the number of records in the result set is 1;
if the ID recorded in the result set is 1, judging whether the ID is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database;
if not, the control does not allow the data entity class to be newly added or modified in the database.
Normally, there should be only one record in the result set, and since the non-primary key field must have uniqueness, the previous storage process of the database should also be stored strictly according to the rule of uniqueness, i.e. there is only one record if there is a corresponding record in the database.
If the number of records in the result set is not 1, it indicates that the uniqueness of the non-primary key field in the database is not satisfied, so that the data entity class is not allowed to continue to be newly added or modified in the database. If 1, then the subsequent steps of determining whether the IDs recorded in the result set are different from the IDs of the data entity class can be continued.
Referring to fig. 2, fig. 2 is a schematic block diagram of an apparatus 200 for checking uniqueness of non-primary key fields in a database according to an embodiment of the present invention, where the apparatus 200 may include:
a construction unit 201, configured to obtain an object corresponding to a data entity class under a mybs-plus packet, and construct an encapsulation class for checking uniqueness of a non-primary key field in the object;
a data input unit 202, configured to obtain a data entity class that needs to be added or modified and is input by the front end;
a field input unit 203, configured to obtain a non-primary key field that needs to be checked for uniqueness and is input by a front end, and obtain a field value of the data entity class under the non-primary key field;
a query unit 204, configured to query, through the encapsulation class, a database for a record that is the same as the field value, and return a result set in a list form;
a result set judging unit 205 for judging whether the result set is empty;
a control unit 206, configured to control to allow the data entity class to be newly added or modified in the database if the result set is empty; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database.
In an embodiment, the field incoming unit 203 includes:
the naming unit is used for transmitting a non-primary key field which needs to be subjected to uniqueness check according to a hump naming format;
and the field value acquisition unit is used for acquiring the field value of the data entity class under the non-primary key field.
In one embodiment, the ID is a primary key field with uniqueness.
In one embodiment, the control unit 206 includes:
the first control unit is used for controlling the data entity class to be stored in the database as a new record when new addition processing is needed;
and the second control unit is used for controlling not to allow the modification processing when the modification processing is needed.
In one embodiment, the control unit 206 includes:
an ID determining unit, configured to determine whether an ID recorded in the result set is different from an ID of the data entity class if the result set is not empty;
and the third control unit is used for confirming that the non-primary key field does not meet the uniqueness if the ID recorded in the result set is different from the ID of the data entity class, and controlling that the data entity class is not allowed to be newly added or modified in the database.
In an embodiment, the control unit 206 further comprises:
a type judging unit, configured to judge whether a new process or a modification process of the data entity class is required if the ID recorded in the result set is the same as the ID of the data entity class;
a fourth control unit, configured to control not to allow the new addition processing if the new addition processing of the data entity class is required;
and the fifth control unit is used for controlling the modification processing of the record corresponding to the ID in the database if the modification processing of the data entity class is required.
In an embodiment, the control unit 206 further comprises:
a number judging unit, configured to judge whether the number of records in the result set is 1 if the result set is not empty;
a sixth control unit, configured to determine whether the ID recorded in the result set is different from the ID of the data entity class if the ID recorded in the result set is 1, and if the ID is different from the ID of the data entity class, control the data entity class not to be allowed to be added or modified in the database, and if the ID is the same, control the data entity class not to be added or modified in the database;
and a seventh control unit, configured to control not to allow the data entity class to be newly added or modified in the database if the data entity class is not 1.
Since the embodiments of the apparatus portion and the embodiments of the method portion correspond to each other, the embodiments of the apparatus portion are referred to the description of the embodiments of the method portion, and are not repeated herein.
The present invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method provided by the above embodiments. The storage medium may include: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The invention also provides a computer device, which can comprise a memory and a processor, wherein the memory stores a computer program, and the processor can realize the method provided by the embodiment when calling the computer program in the memory. Of course the computer device may also include various network interfaces, power supplies, and the like.
In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (5)

1. A method for checking uniqueness of non-primary key fields in a database, comprising:
acquiring an object corresponding to a data entity class under a mybatis-plus packet, and constructing an encapsulation class for checking uniqueness of a non-primary key field in the object;
acquiring a data entity class which is transmitted by the front end and needs to be newly added or modified;
acquiring a non-primary key field which is transmitted by a front end and needs to be subjected to uniqueness check, and acquiring a field value of the data entity class under the non-primary key field;
inquiring records with the same field value in a database through the packaging class, and returning a result set in a list form;
judging whether the result set is empty or not;
if the result set is empty, controlling to allow the data entity class to be newly added or modified in a database; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database;
the step of acquiring the non-primary key field which is transmitted by the front end and needs to be subjected to uniqueness check, and acquiring the field value of the data entity class under the non-primary key field, comprises the following steps:
transmitting non-primary key fields needing to be subjected to uniqueness check according to a hump naming format;
acquiring a field value of the data entity class under the non-primary key field;
and if the result set is empty, controlling to allow the data entity class to be newly added or modified in a database, including:
when new addition processing is needed, the data entity class is controlled to be stored in the database as a new record;
when the modification processing is needed, the control does not allow the modification processing;
if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database, including:
if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class;
if the ID recorded in the result set is different from the ID of the data entity class, confirming that the non-primary key field does not meet the uniqueness, and controlling not to allow the data entity class to be newly added or modified in a database;
if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database, further comprising:
if the ID recorded in the result set is the same as the ID of the data entity class, judging whether the data entity class needs to be newly added or modified;
if the new processing of the data entity class is needed, the control does not allow the new processing;
if the modification processing of the data entity class is needed, controlling the modification processing of the record corresponding to the ID in the database;
if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database, further comprising:
if the result set is not empty, judging whether the number of records in the result set is 1;
if the ID recorded in the result set is 1, judging whether the ID is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database;
if not, the control does not allow the data entity class to be newly added or modified in the database.
2. The method for checking uniqueness of non-primary key fields in a database according to claim 1, wherein the ID is a primary key field having uniqueness.
3. A uniqueness checking device for non-primary key fields in a database, comprising:
the construction unit is used for acquiring an object corresponding to the data entity class under the mybs-plus package, and constructing an encapsulation class for checking uniqueness of the non-primary key field in the object;
the data transmission unit is used for acquiring the data entity class which is transmitted by the front end and needs to be newly added or modified;
the field input unit is used for acquiring a non-primary key field which is input by the front end and needs to be subjected to uniqueness check, and acquiring a field value of the data entity class under the non-primary key field;
the query unit is used for querying the records with the same field value in the database through the encapsulation class and returning a result set in a list form;
a result set judging unit for judging whether the result set is empty;
the control unit is used for controlling the permission of newly adding or modifying the data entity class in the database if the result set is empty; if the result set is not empty, judging whether the ID recorded in the result set is different from the ID of the data entity class, if so, controlling not to allow the data entity class to be newly added or modified in the database, and if so, controlling not to allow the data entity class to be newly added or modified in the database;
the field incoming unit includes:
the naming unit is used for transmitting a non-primary key field which needs to be subjected to uniqueness check according to a hump naming format;
a field value obtaining unit, configured to obtain a field value of the data entity class under the non-primary key field; the control unit includes:
the first control unit is used for controlling the data entity class to be stored in the database as a new record when new addition processing is needed;
the second control unit is used for controlling not to allow the modification processing when the modification processing is needed;
an ID determining unit, configured to determine whether an ID recorded in the result set is different from an ID of the data entity class if the result set is not empty;
a third control unit, configured to confirm that the non-primary key field does not satisfy uniqueness if the ID recorded in the result set is different from the ID of the data entity class, and control not to allow the data entity class to be newly added or modified in the database;
a type judging unit, configured to judge whether a new process or a modification process of the data entity class is required if the ID recorded in the result set is the same as the ID of the data entity class;
a fourth control unit, configured to control not to allow the new addition processing if the new addition processing of the data entity class is required;
a fifth control unit, configured to control modification processing to a record corresponding to an ID in the database if modification processing of a data entity class is required;
a number judging unit, configured to judge whether the number of records in the result set is 1 if the result set is not empty;
a sixth control unit, configured to determine whether the ID recorded in the result set is different from the ID of the data entity class if the ID recorded in the result set is 1, and if the ID is different from the ID of the data entity class, control the data entity class not to be allowed to be added or modified in the database, and if the ID is the same, control the data entity class not to be added or modified in the database;
and a seventh control unit, configured to control not to allow the data entity class to be newly added or modified in the database if the data entity class is not 1.
4. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing a method of uniqueness checking of non-primary key fields in a database as claimed in any one of claims 1 to 2 when the computer program is executed.
5. A computer-readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, implements a method for checking uniqueness of non-primary key fields in a database according to any one of claims 1 to 2.
CN201911352694.4A 2019-12-25 2019-12-25 Non-primary key field checking method, device, computer equipment and storage medium Active CN111125110B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911352694.4A CN111125110B (en) 2019-12-25 2019-12-25 Non-primary key field checking method, device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911352694.4A CN111125110B (en) 2019-12-25 2019-12-25 Non-primary key field checking method, device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111125110A CN111125110A (en) 2020-05-08
CN111125110B true CN111125110B (en) 2023-08-18

Family

ID=70502341

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911352694.4A Active CN111125110B (en) 2019-12-25 2019-12-25 Non-primary key field checking method, device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111125110B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113592039A (en) * 2021-09-02 2021-11-02 北京沃东天骏信息技术有限公司 Method and device for predicting model primary key

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2005004001A1 (en) * 2003-06-04 2005-01-13 M-Penbase Pda-type computer device for storing and processing relational databases
CN104252481A (en) * 2013-06-27 2014-12-31 阿里巴巴集团控股有限公司 Dynamic check method and device for consistency of main and salve databases
CN109857806A (en) * 2018-12-30 2019-06-07 贝壳技术有限公司 The synchronization verification method and device of database table

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7584178B2 (en) * 2006-04-20 2009-09-01 International Business Machines Corporation Query condition building using predefined query objects

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2005004001A1 (en) * 2003-06-04 2005-01-13 M-Penbase Pda-type computer device for storing and processing relational databases
CN104252481A (en) * 2013-06-27 2014-12-31 阿里巴巴集团控股有限公司 Dynamic check method and device for consistency of main and salve databases
CN109857806A (en) * 2018-12-30 2019-06-07 贝壳技术有限公司 The synchronization verification method and device of database table

Also Published As

Publication number Publication date
CN111125110A (en) 2020-05-08

Similar Documents

Publication Publication Date Title
CN112003703B (en) Method and device for transmitting authenticatable message across chains
CN107038242B (en) Block chain-oriented global intelligent contract service data analysis method
CN109670081B (en) Method and device for processing service request
US20200366485A1 (en) Method and apparatus for inter-blockchain transmission of authenticable message
AU2017200895B2 (en) Software integration testing with unstructured database
CN108256870B (en) Method and device for generating description information, updating and processing data based on topological structure
CN102750629B (en) Schedule association method and device
CN104426868A (en) Request processing method and processing apparatus
CN110535928A (en) A kind of event method for pushing of the JAVA intelligence contract of block chain
CN110532529A (en) A kind of recognition methods of file type and device
CN111125110B (en) Non-primary key field checking method, device, computer equipment and storage medium
US7263656B2 (en) Method and device for scheduling, generating and processing a document comprising blocks of information
CN106528066B (en) Business process operation method and device
CN110879806A (en) Data fusion method, device, equipment and storage medium
CN108183890B (en) Method and system for analyzing data communication protocol
CN113342647A (en) Test data generation method and device
KR101888131B1 (en) Method for Performing Real-Time Changed Data Publish Service of DDS-DBMS Integration Tool
JP2010250548A (en) Log output device
CN116627843A (en) Method and device for automatically generating test data, electronic equipment and storage medium
US20150256614A1 (en) Resource synchronization control method, device, and system
CN113377672B (en) Test method, device and equipment
CN115544169A (en) Data synchronization method, device, equipment and storage medium
CN114064653A (en) Data insertion method and device, computer equipment and storage medium
CN110597712A (en) Component attribute checking method and device, terminal and storage medium
CN113407546A (en) Rule configuration method suitable for various scenes

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