[summary of the invention]
Based on this, it is necessary to provide a kind of tables of data processing method that can prevent serial number from conflicting.
A kind of tables of data processing method, comprises the following steps:
Creating sequence table, described sequence table includes the name field of tables of data, sequence current maximum field and major key field;
Obtain user's operation requests to tables of data, obtain the title of the tables of data of user operation according to described operation requests;
In described sequence table, search the title of the tables of data of described user operation, the record of the title comprising described tables of data in described sequence table is locked;
Obtain the sequence current maximum in the record of locking in described sequence table, and described sequence current maximum is increased predetermined value, update described sequence current maximum;
The tables of data of described user operation is updated according to the sequence current maximum after described renewal.
Preferably, described sequence table is searched the title of the tables of data of described user operation, the record of the title comprising described tables of data in described sequence table is entered line-locked step particularly as follows:
The title of the tables of data of described user operation is searched in described sequence table, when described sequence table does not finds, described sequence table is locked, the record of the title of the tables of data comprising described user operation is created in described sequence table, initialize the sequence current maximum in described record, then the record of the title comprising described tables of data in described sequence table is locked.
Preferably, the sequence current maximum in the record of locking in obtaining described sequence table, and described sequence current maximum is increased predetermined value, further comprise the steps of: after updating the step of described sequence current maximum
Form the sequence of interval block comprising predetermined value serial number;
The step of the tables of data according to the sequence current maximum described user operation of renewal after described renewal is: update the tables of data of described user operation according to described sequence of interval block.
Preferably, after described acquisition user's step to the operation requests of described tables of data, also include:
Judge that in described sequence of interval block, whether serial number is finished, the most then obtain new sequence of interval block, if it is not, then directly obtain serial number from described sequence of interval block, according to the tables of data of user operation described in the sequence number update obtained, wherein, described serial number is less than described sequence current maximum.
Preferably, described sequence of interval block have recorded homing sequence number, maximum sequence number and current sequence number.
Additionally, there is a need to provide a kind of tables of data processing system that can prevent serial number from conflicting.
A kind of tables of data processing system, including:
Creation module, is used for creating sequence table, and described sequence table includes the name field of tables of data, sequence current maximum field and major key field;
Acquisition module, for obtaining user's operation requests to tables of data, obtains the title of the tables of data of user operation according to described operation requests;
Search module, for searching the title of the tables of data of described user operation in described sequence table;
Processing module, for the record of the title comprising described tables of data in described sequence table is locked, obtain the sequence current maximum in the record of locking in described sequence table, and described sequence current maximum is increased predetermined value, update described sequence current maximum;
More new module, for updating the tables of data of described user operation according to the sequence current maximum after described renewal.
Preferably, when the title of the tables of data that described lookup module does not finds described user operation in described sequence table, described processing module is additionally operable to lock by described sequence table, the record of the title of the tables of data comprising described user operation is created in described sequence table, initialize the sequence current maximum of described record, then the record of the title comprising described tables of data in described sequence table is locked.
Preferably, described processing module is additionally operable to form the sequence of interval block comprising predetermined value serial number;Described more new module is additionally operable to update the tables of data of described user operation according to described sequence of interval block.
Preferably, also include judge module, described judge module is after obtaining the described user operation requests to described tables of data at described acquisition module, judge in described sequence of interval block, whether serial number is finished, described acquisition module is time in described judge module judges described sequence of interval block, serial number has been used up, described processing module is additionally operable to obtain new sequence of interval block, when described processing module is additionally operable to that serial number is not run out in described judge module judges described sequence of interval block, from described sequence blocks, directly obtain serial number, described more new module is additionally operable to the tables of data according to user operation described in the sequence number update obtained, wherein, described serial number is less than described sequence current maximum.
Preferably, described sequence blocks have recorded homing sequence number, maximum sequence number and current sequence number.
Above-mentioned tables of data processing method and system, create sequence table, obtain user's operation requests to tables of data and the title of tables of data, the title of the tables of data of user operation is searched in sequence table, the record of the title comprising this tables of data is locked, obtain the sequence current maximum in the record of locking, after increasing predetermined value, renewal sequence current maximum, the tables of data of user operation is updated further according to the sequence current maximum updated, owing to having locked the record of the title of the tables of data comprising user operation, can ensure when tables of data is operated by certain user, other users are invalid to the operation of this tables of data, so do not have the situation of serial number conflict, can be applicable to the data syn-chronization in distributed environment.
[detailed description of the invention]
Below in conjunction with specific embodiment and accompanying drawing, the technical scheme of sequence generating method and system is described in detail.
As it is shown in figure 1, in one embodiment, a kind of sequence generating method, comprise the following steps:
Step S110, creates sequence table, and this sequence table includes the name field of tables of data, sequence current maximum field and major key field.
The sql like language utilizing standard creates a sequence table.This sequence table includes the name field of tables of data, sequence current maximum field and major key field.Such as, the structure of the sequence table of establishment is as follows:
createtableMy_IDSequence(
SeqNamevarchar (128),
SeqNextint,
primarykey(seqName)
);
Wherein, seqNamevarchar (128) represents the name field of tables of data, and seqNextint represents sequence current maximum field, and primarykey (seqName) represents major key field.This sequence table has the record of a plurality of tables of data.Value in sequence current maximum field represents in tables of data the serial number that in the maximum of existing serial number or tables of data, next time will generate, if the maximum of serial number already present in tables of data is 20, then in sequence table, the sequence current maximum of this tables of data of record can be 20 or 21.In the present embodiment, in this sequence table, the sequence current maximum of the tables of data of record is the next serial number that will generate of tables of data.This sequence table is using the name field of tables of data as major key.
Step S120, obtains user's operation requests to tables of data, obtains the title of the tables of data of user operation according to this operation requests.
Obtain user's operation requests to tables of data, because sequence table has the record of a plurality of tables of data, the title of the tables of data of user operation need to be obtained, in order to follow-up lookup in sequence table.After acquisition user is to the operation requests of tables of data, can be connected with Database, now, this connection need to be set to non-automatic submission data, to ensure follow-up lock operation.Data are submitted to be association database affairs to data base.Generally, db transaction is defaulted as automatically submitting to, i.e. i.e. submit data to as after an operation, in the present embodiment, this connection need to be kept a period of time, it is ensured that after the operation in whole affairs completes, just submit data to, as user A carries out transferring accounts 100 yuan in the account of user B, it is divided into two steps: 1. button goes 100 yuan in the account of user A;2. in the account of user B, increase 100 yuan.When two steps all complete, just submit data to.
Step S130, searches the title of the tables of data of user operation in this sequence table, is locked by the record of the title comprising this tables of data in this sequence table.
In sequence table, searching the title of the tables of data of user operation, if finding, then directly the record of the title comprising this tables of data in sequence table being locked, to prevent other users from operating the record of the title of this tables of data.
In one embodiment, if do not find in sequence table, then this sequence table is locked, the record of the title of the tables of data comprising this user operation is created in sequence table, initialize the sequence current maximum of the record created, then the record of the title of the tables of data comprising user operation in this sequence table is locked.Locking sequence table, when can prevent other users from operating this tables of data, sequence table also creates same record, thus causes record to repeat, and occupies resource simultaneously.After the record of the title creating the tables of data comprising this user operation, the sequence current maximum of the tables of data comprising this user operation is initialized, if this sequence current maximum can be 1, i.e. represent that the serial number generated in the tables of data of this user operation is from the beginning of 1.Then the record of the title of the tables of data comprising user operation of this establishment is locked, releasably the locking to sequence table, facilitate other users that the record of the title comprising other tables of data in sequence table is operated.
Step S140, obtains the sequence current maximum in the record of locking in this sequence table, and this sequence current maximum is increased predetermined value, update this sequence current maximum.
After the record of the title of the tables of data of the user operation comprised in sequence table is locked, get the sequence current maximum of this record, this sequence current maximum is the next serial number that will generate of this tables of data, is increased predetermined value, have updated sequence current maximum.This predetermined value can be Arbitrary Digit, such as 10000.The sequence current maximum of the record of the title of the tables of data comprising user operation such as obtained is 10001, then, after increasing predetermined value 10000, the sequence current maximum after renewal is 20001.
In a preferred embodiment, the sequence of interval block that formation comprises predetermined value serial number is further comprised the steps of: after step s 140.Such as the sequence of interval block [10001,20000] comprising 10000 serial numbers formed, Serial No. sequence of interval block comprises the integer value of two end points.
Sequence of interval block have recorded homing sequence number, maximum sequence number and current sequence number, save cache resources.Wherein, after current sequence number refers to the serial number in sequence of interval block is distributed to user, the next serial number by distribution.
Also include after forming the sequence of interval block comprising predetermined value serial number: submit data to, the sequence table of release locking comprises the record of the title of the tables of data of user operation.So that the record of the title of this tables of data is operated by other users.
Step S150, updates the tables of data of user operation according to the sequence current maximum after updating.
After forming the sequence of interval block comprising predetermined value serial number, update the tables of data of user operation according to the sequence current maximum after updating particularly as follows: update the tables of data of user operation according to this sequence of interval block.This sequence of interval block contain the sequence current maximum before renewal to update after sequence current maximum between serial number, serial number in this sequence of interval block is distributed on this user, when this tables of data is operated by other users, it is impossible to use the serial number in this sequence of interval block.
In one embodiment, after obtaining this user operation requests to this tables of data, also include: judge in this sequence of interval block, whether serial number is finished, the most then perform to obtain new sequence of interval block, if not, from this sequence of interval block, then directly obtain serial number, according to the tables of data of this user operation of sequence number update obtained, wherein, described serial number is less than described sequence current maximum.
Such as, when personnel system operation user's table, in user's table, insert user A, a serial number need to be distributed to user A, if the sequence generator of user's table obtains sequence of interval block [1,10000], first judging whether the serial number in this sequence of interval block is finished, if not having, then directly obtaining a serial number from sequence of interval block distributes to user A, the most then need to obtain new sequence of interval block.
As in figure 2 it is shown, in one embodiment, a kind of tables of data processing system, including creation module 210, acquisition module 220, search module 230, processing module 240 and more new module 250.Wherein,
Creation module 210 is used for creating sequence table, and this sequence table includes the name field of tables of data, sequence current maximum field and major key field.The sql like language utilizing standard creates a sequence table.This sequence table includes the name field of tables of data, sequence current maximum field and major key field.The structure of sequence table can not repeat them here as described in above-mentioned tables of data processing method.
Acquisition module 220, for obtaining user's operation requests to tables of data, obtains the title of the tables of data of user operation according to this operation requests.Acquisition module office 220 obtains user's operation requests to tables of data, because there being the record of a plurality of tables of data in sequence table, need to obtain the title of the tables of data of user operation, in order to follow-up lookup in sequence table.
Search module 230 for searching the title of the tables of data of this user operation in this sequence table.
Search the title that module 230 searches the tables of data of user operation in sequence table, if finding, then the record of the title comprising this tables of data in sequence table is directly locked, to prevent other users from operating the record of the title of this tables of data by processing module 240.
If lookup module 230 does not finds in sequence table, then this sequence table is locked by processing module 240, the record of the title of the tables of data comprising this user operation is created in sequence table, initialize the sequence current maximum of the record created, then the record of the title of the tables of data comprising user operation in this sequence table is locked.Locking sequence table, when can prevent other users from operating this tables of data, sequence table also creates same record simultaneously, causes record to repeat, occupies resource.After the record of the title creating the tables of data comprising this user operation, the sequence current maximum of the tables of data comprising this user operation is initialized, if this sequence current maximum can be 1, i.e. represent that the serial number generated in the tables of data of this user operation is from the beginning of 1.Then the record of the title of the tables of data comprising user operation of this establishment is locked, releasably the locking to sequence table, facilitate other users that the record of the title comprising other tables of data in sequence table is operated.
Processing module 240 is for locking the record of the title of the tables of data comprising user operation in this sequence table, obtain the sequence current maximum in the record of locking in this sequence table, and this sequence current maximum is increased predetermined value, update this sequence current maximum.
After the record of the title of the tables of data of the processing module 240 user operation to comprising in sequence table locks, get the sequence current maximum of this record, this sequence current maximum is the next serial number that will generate of this tables of data, is increased predetermined value, have updated sequence current maximum.This predetermined value can be Arbitrary Digit, such as 10000.The sequence current maximum of the record of the title of the tables of data comprising user operation such as obtained is 10001, then, after increasing predetermined value 10000, the sequence current maximum after renewal is 20001.
In preferred embodiment, processing module 240 is additionally operable to form the sequence of interval block comprising predetermined value serial number.Such as the sequence of interval block [10001,20000] comprising 10000 serial numbers formed, Serial No. sequence of interval block comprises the integer value of two end points.
Sequence of interval block have recorded homing sequence number, maximum sequence number and current sequence number.Save cache resources.Wherein, after current sequence number refers to the serial number in sequence of interval block is distributed to user, the next serial number by distribution.
Processing module 240 is additionally operable to submit to data, comprises the record of the title of the tables of data of user operation in the sequence table of release locking.So that the record of the title of this tables of data is operated by other users.
More new module 250 for updating the tables of data of this user operation according to the sequence current maximum after this renewal.
More new module 250 is additionally operable to update the tables of data of this user operation according to this sequence of interval block.This sequence of interval block contain the sequence current maximum before renewal to update after sequence current maximum between serial number, serial number in this sequence of interval block is distributed on this user, when this tables of data is operated by other users, it is impossible to use the serial number in this sequence of interval block.
In one embodiment, as it is shown on figure 3, above-mentioned tables of data processing system, except including creation module 210, acquisition module 220, searching module 230, processing module 240 and more new module 250, judge module 260 is also included.Wherein,
Judge module 260 is for after acquisition module 220 obtains this user operation requests to this tables of data, judge in this sequence of interval block, whether serial number is finished, acquisition module 220 is time in judge module 260 judges this sequence of interval block, serial number has been used up, the title of the tables of data of user operation is obtained according to this operation requests, search module 230 and be additionally operable to search the title of the tables of data of this user operation in this sequence table, processing module 240 is additionally operable to the record of the title by the tables of data comprising user operation in this sequence table and locks, obtain the sequence current maximum in the record of locking in this sequence table, and this sequence current maximum is increased predetermined value, update this sequence current maximum, form the new sequence of interval block comprising predetermined value serial number;When processing module 240 is additionally operable to that serial number is not run out in judge module 260 judges this sequence of interval block, from this sequence blocks, directly obtain serial number, more new module 250 is additionally operable to the tables of data according to this user operation of sequence number update obtained, wherein, this serial number is less than this sequence current maximum.
Such as, when personnel system operation user's table, in user's table, insert user A, a serial number need to be distributed to user A, if user's table obtains sequence blocks [1,10000], judge module 260 judges whether the serial number in this sequence blocks is finished, if not having, then directly obtain a serial number from sequence of interval block distributes to user A to processing module 240, the most then need to obtain new sequence of interval block.
For the work process of clearer explanation tables of data processing system, describe with concrete example, but notebook data list processing system is not limited to be applied to this concrete example.
There is user table T_user (idint, userNamevarchar (128)) in main data system;Organization table T_org (idint, orgNamevarchar (128)).Creation module 210 first creates sequence table My_IDSequence in data base.If having two application systems, human resource system S1 and purchasing system S2.S1 and S2 has the business creating user, need to generate the serial number of user.S1 system creation sequence generator SEQ1, S2 system creation sequence generator SEQ2, all of serial number starts to generate from 1.
nullWhen the request of user A1 is inserted in S1 system of users table T_user operation,After then acquisition module 220 obtains this operation requests,SEQ1 is connected with Database,Search module 230 from the seqName of My_IDSequence table, search whether to exist the record of T_user,If not existing,Then processing module 240 locks My_IDSequence table,The record of the title comprising this T_user is created in My_IDSequence table,The most again the record of the title comprising this T_user is locked,The sequence current maximum seqNext initializing this T_user is 1,It is 1 that inquiry obtains the sequence current maximum seqNext of this T_user,Predetermined value 10000 is increased by 1,Then updating seqNext is 10001,And formation sequence extent block [1,10000],This sequence of interval block is that SEQ1 uniquely holds.More new module 250 updates this user table T_user according to this sequence of interval block, i.e. obtains a serial number from sequence of interval block and distributes to user A1.
Equally, the request of user a1 is inserted in S2 system of users table T_user operation, after then acquisition module 220 obtains operation requests, SEQ2 is connected with Database, lookup module 230 finds the T_user record in the seqName of My_IDSequence table, processing module 240 obtains the row level lock of this T_user, it is 10001 that inquiry obtains the sequence current maximum seqNext of this T_user, predetermined value 10000 is increased by 10001, then updating seqNext is 20001, and formation sequence extent block [10001,20000], this sequence of interval block is that SEQ2 uniquely holds.More new module 250 updates this user table T_user according to this sequence of interval block, i.e. obtains a serial number from this sequence of interval block and distributes to user a1.
The data that so SEQ1 inserts in user table T_user are (1, A1), (2, A2) ..., (10000, A10000).
The data that SEQ2 inserts in user table T_user are (10001, a1), (10002, a2) ..., (20000, a10000).
Above-mentioned tables of data processing method and system, create sequence table, obtain user's operation requests to tables of data and the title of tables of data, the title of the tables of data of user operation is searched in sequence table, the record of the title comprising this tables of data is locked, obtain the sequence current maximum in the record of locking, after increasing predetermined value, renewal sequence current maximum, the tables of data of user operation is updated further according to the sequence current maximum updated, owing to having locked the record of the title of the tables of data comprising user operation, can ensure when tables of data is operated by certain user, other users are invalid to the operation of this tables of data, so do not have serial number conflict, can be applicable to data syn-chronization in distributed environment.
It addition, do not rely on concrete programming language, extend its range of application, obtain a sequence of interval block every time, decrease the access times of data base, improve serial number formation efficiency;Only record start serial number, maximum sequence number and current sequence number in sequence blocks, can save cache resources.
Embodiment described above only have expressed the several embodiments of the present invention, and it describes more concrete and detailed, but therefore can not be interpreted as the restriction to the scope of the claims of the present invention.It should be pointed out that, for the person of ordinary skill of the art, without departing from the inventive concept of the premise, it is also possible to make some deformation and improvement, these broadly fall into protection scope of the present invention.Therefore, the protection domain of patent of the present invention should be as the criterion with claims.