Summary of the invention
In view of this, the invention provides a kind of data uniqueness inspection method and device, in order to solve in prior art utilize from database carry out data uniqueness check time, there is the technical matters of error in check result.For realizing described goal of the invention, technical scheme provided by the invention is as follows:
A kind of data uniqueness inspection method, comprising:
When receiving data to be saved, according to described data genaration target index to be saved;
Obtain the concordance list pre-set in master data base; Wherein, in described concordance list, store the index having preserved data in described master data base, and described index is set to major key;
Perform the operation writing described target index to described concordance list, obtain and write result;
Write described in judgement in result and whether comprise major key duplicate message;
If so, determine that described data to be saved do not have uniqueness;
Otherwise, determine that described data to be saved have uniqueness.
Above-mentioned data uniqueness inspection method, preferably, described according to described data genaration target index to be saved, comprising:
When described packet to be saved is containing multiple field, obtains several preset field and splice, obtain target index; Wherein, several preset field described are multiple fields that acquiescence has the not reproducible constraint of associating.
Above-mentioned data uniqueness inspection method, preferably, writes result described in described foundation, after determining the uniqueness check result of described data to be saved, also comprises:
When described uniqueness check result is for having uniqueness, described data to be written are write in described master data base;
When described uniqueness check result is not for having uniqueness, reminder-data repeats.
Above-mentioned data uniqueness inspection method, preferably, described described data to be written are write in described master data base after, also comprise:
By extremely described from database for the data syn-chronization to be written write in described master data base.
Above-mentioned data uniqueness inspection method, preferably, described target index is index character string.
Present invention also provides a kind of data uniqueness testing fixture, comprising:
Target index generation unit, for when receiving data to be saved, according to described data genaration target index to be saved;
Concordance list acquiring unit, for obtaining the concordance list pre-set in master data base; Wherein, in described concordance list, store the index having preserved data in described master data base, and described index is set to major key;
Target index r/w cell, for performing the operation writing described target index to described concordance list, obtains and writes result;
Judging unit, writes in result whether comprise major key duplicate message described in judging; If so, the first result unit is triggered; Otherwise, trigger the second result unit;
First result unit, for determining that described data to be saved do not have uniqueness;
Second result unit, for determining that described data to be saved have uniqueness.
Above-mentioned data uniqueness testing fixture, preferably, described target index generation unit comprises:
Target index generates subelement, for when described packet to be saved is containing multiple field, obtains several preset field and splices, obtain target index; Wherein, several preset field described are multiple fields that acquiescence has the not reproducible constraint of associating.
Above-mentioned data uniqueness testing fixture, preferably, also comprises:
Described data to be written, for when described uniqueness check result is for having uniqueness, are write in described master data base by data write unit;
Miscue unit, for when described uniqueness check result is not for having uniqueness, reminder-data repeats.
Above-mentioned data uniqueness testing fixture, preferably, also comprises:
Data synchronisation unit, for described described data to be written are write in described master data base after, by the data syn-chronization to be written that writes in described master data base to described from database.
Above-mentioned data uniqueness testing fixture, preferably, the target index that described target index generation unit generates is index character string.
Data uniqueness inspection method provided by the invention and device, when receiving data to be saved, according to described data genaration target index to be saved, and obtain the concordance list pre-set in master data base; Wherein, the index having preserved data in described master data base is stored in described concordance list, and described index is set to major key, and the operation writing described target index is performed to described concordance list, result is write in acquisition, comprises major key duplicate message if write in result, determines that described data to be saved do not have uniqueness, if write in result and do not comprise major key duplicate message, determine that described data to be saved have uniqueness.Need explanation, the embodiment of the present invention carries out write operation to the concordance list in master data, whether return major key duplicate message according to concordance list and determine whether data to be saved have uniqueness in master data base, visible, the embodiment of the present invention only utilizes the write operation of master data base, do not carry out read operation to from database, uniqueness check result is more accurate.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.
Use in the Database Systems of read and write abruption technology, when carrying out uniqueness and checking, there will be inspection error.Particularly, after writing data in master data, to before carrying out data syn-chronization operation from database, error can be there is because data are asynchronous to the uniqueness inquiry from database.Trace it to its cause, in master data base, first write data, need thereafter certain hour to from database synchronization data, in the mistiming, carry out uniqueness inspection then must cause error.
One of resolving ideas avoids this mistiming, specifically, is carry out uniqueness inspection in master data again to after database synchronization data.But, the invention provides another one resolving ideas, namely directly in master data base, carry out uniqueness inspection.But, we know, main logarithmic data storehouse provides transactional operation, namely increase, delete and revise, do not provide inquiry service, and the setting of master and slave database is exactly the on-stream pressure read to solve the write of individual data storehouse, therefore, the present invention, when utilizing above-mentioned thinking, needs to find a kind of effective inspection method.
With reference to Fig. 1, it illustrates the flow process of the data uniqueness inspection method that the embodiment of the present invention provides, specifically comprise the following steps:
Step S101: when receiving data to be saved, according to described data genaration target index to be saved.
Wherein, data to be saved are the data needing to be written in master data base.When receiving data to be saved, generate the index that these data to be saved are corresponding.Index has uniqueness, and this uniqueness index therefore can be utilized to check data.Wherein, the method for data genaration index to be saved is utilized to refer to hereafter.
Step S102: obtain the concordance list pre-set in master data base; Wherein, in described concordance list, store the index having preserved data in described master data base, and described index is set to major key.
In the present embodiment, in advance for the every bar data record in database all generates corresponding unique index, and by each index stores in the concordance list pre-set.That is, the index of the total data of having preserved in master data base is stored in concordance list.
Need to illustrate, in concordance list, the row storing index are set to major key.Reason is, because the Major key of bar data record every in tables of data all can not be identical, thus, arranges major key just in order to ensure that in concordance list to there is repeating data in concordance list.Due to the index that major key is data in master data base, thus, the uniqueness of data in master data base is namely ensured.
Step S103: perform the operation writing described target index to described concordance list, obtains and writes result.
Wherein, we know, database, before carrying out write operation to the data in tables of data, can carry out corresponding judgement according to every setting of tables of data.Wherein, tables of data is set to major key, then major key must be utilized to judge whether to there is repeating data, if existed, generates major key duplicate message, causes writing unsuccessfully.When by every inspection, write successfully.
That is, write the index of data to be saved to concordance list, concordance list automatically generates and writes result.Wherein, write in result and may include major key duplicate message.
Step S104: write in result whether comprise major key duplicate message described in judgement; If so, step S105 is performed; Otherwise, perform step S106.
Wherein, by judging to write in result whether comprise major key duplicate message, just can know whether data to be written have uniqueness in concordance list.Following two steps is performed respectively according to judged result.
Step S105: determine that described data to be saved do not have uniqueness.
Not there is uniqueness, that is, in concordance list, there are not the data identical with data to be written, because the major key in concordance list is the index of data in master data base, and then illustrate in master data base there are not the data identical with data to be written.
Step S106: determine that described data to be saved have uniqueness.
There is uniqueness, that is, in concordance list, there are the data identical with data to be written, and then illustrate in master data base to there is identical data.
From above technical scheme, the data uniqueness inspection method that the embodiment of the present invention provides, when receiving data to be saved, according to described data genaration target index to be saved, and obtains the concordance list pre-set in master data base; Wherein, the index having preserved data in described master data base is stored in described concordance list, and described index is set to major key, and the operation writing described target index is performed to described concordance list, result is write in acquisition, comprises major key duplicate message if write in result, determines that described data to be saved do not have uniqueness, if write in result and do not comprise major key duplicate message, determine that described data to be saved have uniqueness.Need explanation, the embodiment of the present invention carries out write operation to the concordance list in master data, whether return major key duplicate message according to concordance list and determine whether data to be saved have uniqueness in master data base, visible, the embodiment of the present invention only utilizes the write operation of master data base, do not carry out read operation to from database, uniqueness check result is more accurate.
In the above-described embodiments, step S101 is when receiving data to be saved, and the concrete mode according to described data genaration target index to be saved can be:
When receiving data to be saved and described packet to be saved contains multiple field, obtaining several preset field and splicing, obtain target index.Wherein, several preset field described are provided with the not reproducible constraint of associating in described master data base.
Particularly, the data record preserved in master data base, can give tacit consent to multiple field and have the character of combining not reproducible constraint, and namely the field value of joinirreducible bundle can not be simultaneously identical.Such as, the data record stored in master data base comprises six fields, is ID, CODE, NAME, GRADE, CLASS and AGE, represents major key, student number, name, grade, class and age respectively.Wherein, default na ME, GRADE and CLASS tri-fields are the not reproducible field of associating, that is, can not store identical two the data records of name, grade and class in a database.
In the present embodiment, data to be saved are identical with data in master data base, comprise same multiple fields, and then, generate unique index by arranging the field of combining not reproducible constraint.Preferably, described index is index character string.The method of generating indexes character string can have multiple, as the value of multiple preset field spliced successively, can use "-" character during splicing.Such as, data to be saved are as shown in table 1, and NAME, GRADE and CLASS tri-fields are the field being provided with joinirreducible bundle in master data base, therefore, utilize "-" to splice successively " Zhang San ", " senior class " and " six classes " three values, the target index of acquisition can be " Zhang San-senior class-six classes ".
Table 1
ID |
CODE |
NAME |
GRADE |
CLASS |
AGE |
10002 |
S00123 |
Zhang San |
Senior class |
Six classes |
10 |
Need to illustrate, the mode of above-mentioned generating indexes is a kind of example, is not limited thereto in the embodiment of the present invention.In real data storehouse, because field amount is different or field data types is different, the mode of generating indexes is not quite similar, and has the field value of combining not reproducible constraint character as long as can utilize to be spliced into the mode of index all passable.In addition, splicing index also necessarily uses the field having and combine not reproducible constraint, can also utilize multiple fields of associating major key or other unique constraints.
Need to illustrate, in each embodiment above-mentioned, in master data base, acquiescence has the field of combining not reproducible constraint character and does not arrange the not reproducible constraint of this associating, does not also arrange joint index.We know that the tables of data arranging joint index needs the index to having set up to upgrade after process write, amendment and deletion action, therefore, arrange the readwrite performance that joint index can affect database.Therefore, the present embodiment does not arrange joint index in tables of data, but concordance list is set separately, concordance list is utilized to preserve the index value generated by the not reproducible bind field of associating, this index value is set to major key, utilize the major key of concordance list to detect data uniqueness, like this, the uniqueness of data is detected more rapidly and efficiently.Certainly, in order to improve the efficiency of inspection further, this concordance list only can comprise index field one column data.
See Fig. 2, it illustrates another flow process of the data uniqueness inspection method that the embodiment of the present invention provides, comprising on the embodiment step basis shown in above-mentioned Fig. 1, further comprising the steps of:
Step S107: reminder-data repeats.
After step S105, perform this step, that is, when data to be saved do not have uniqueness in master data base, generate the prompting message of Data duplication, and point out to user.
Step S108: described data to be written are write in described master data base.
Perform this step after step s 106, that is, when data to be saved have uniqueness in master data base, in master data base, write data to be saved.
Further, on the basis of the embodiment shown in Fig. 2, can also comprise: by extremely described from database for the data syn-chronization to be written write in described master data base.So far, can complete and the data to be saved with uniqueness are as one man preserved in master data base and from database, also just accurately can inquire about from database.
Be introduced the data uniqueness testing fixture that the embodiment of the present invention provides below, need to illustrate, the explanation of relevant data uniqueness testing fixture see the explanation of each data uniqueness inspection method above, can not repeat below.
With reference to Fig. 3, it illustrates the structure of the data uniqueness testing fixture that the invention process provides, specifically comprise: target index generation unit 101, concordance list acquiring unit 102, target index r/w cell 103, judging unit 104, first result unit 105 and the second result unit 106.Wherein:
Target index generation unit 101, for when receiving data to be saved, according to described data genaration target index to be saved;
Concordance list acquiring unit 102, for obtaining the concordance list pre-set in master data base; Wherein, in described concordance list, store the index having preserved data in described master data base, and described index is set to major key;
Target index r/w cell 103, for performing the operation writing described target index to described concordance list, obtains and writes result;
Judging unit 104, writes in result whether comprise major key duplicate message described in judging; If so, the first result unit is triggered; Otherwise, trigger the second result unit;
First result unit 105, for determining that described data to be saved do not have uniqueness;
Second result unit 106, for determining that described data to be saved have uniqueness.
From the technical scheme of the present embodiment, target index generation unit 101 is when receiving data to be saved, and according to described data genaration target index to be saved, concordance list acquiring unit 102 obtains the concordance list pre-set in master data base, wherein, the index having preserved data in described master data base is stored in described concordance list, and described index is set to major key, target index r/w cell 103 performs the operation writing described target index to described concordance list, result is write in acquisition, judging unit 104 writes in result whether comprise major key duplicate message described in judging, major key duplicate message is comprised if write in result, first result unit 105 determines that described data to be saved do not have uniqueness, if write in result and do not comprise major key duplicate message, second result unit 106 determines that described data to be saved have uniqueness.Need explanation, the embodiment of the present invention carries out write operation to the concordance list in master data, whether return major key duplicate message according to concordance list and determine whether data to be saved have uniqueness in master data base, visible, the embodiment of the present invention only utilizes the write operation of master data base, do not carry out read operation to from database, uniqueness check result is more accurate.
Alternatively, above-mentioned target index generation unit 101 comprises:
Target index generates subelement, for when described packet to be saved is containing multiple field, obtains several preset field and splices, obtain target index; Wherein, several preset field described are multiple fields that acquiescence has the not reproducible constraint of associating.
See Fig. 4, on the data uniqueness testing fixture basis shown in above-mentioned Fig. 3, can also comprise:
Miscue unit 107, is connected with described first result unit 105, repeats for reminder-data.
Data write unit 108, is connected with described second result unit 106, for described data to be written being write in described master data base.
On the device basic shown in Fig. 4 alternatively, also comprise: data synchronisation unit, be connected with described data write unit 108, for described described data to be written are write in described master data base after, by the data syn-chronization to be written that writes in described master data base to described from database.
Alternatively, the target index that described target index generation unit generates is index character string.
It should be noted that, each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed is the difference with other embodiments, between each embodiment identical similar part mutually see.
Also it should be noted that, in this article, the such as relational terms of first and second grades and so on is only used for an entity or operation to separate with another entity or operational zone, and not necessarily requires or imply the relation that there is any this reality between these entities or operation or sequentially.And, term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability, thus make to comprise the process of a series of key element, method, article or equipment and not only comprise those key elements, but also comprise other key elements clearly do not listed, or also comprise by the intrinsic key element of this process, method, article or equipment.When not more restrictions, the key element limited by statement " comprising ... ", and be not precluded within process, method, article or the equipment comprising above-mentioned key element and also there is other identical element.
To the above-mentioned explanation of the disclosed embodiments, professional and technical personnel in the field are realized or uses the present invention.To be apparent for those skilled in the art to the multiple amendment of these embodiments, General Principle as defined herein can without departing from the spirit or scope of the present invention, realize in other embodiments.Therefore, the present invention can not be restricted to these embodiments shown in this article, but will meet the widest scope consistent with principle disclosed herein and features of novelty.