Summary of the invention
Technical matters to be solved by this invention is to provide a kind of data insertion method be applied in graphic database online transaction, there is conflict and the incomplete technical matters of data in the database that causes of conflicting in order to solve in prior art.
Another object of the present invention is applied in concrete applied environment above-mentioned design, provides a kind of data insertion system be applied in graphic database online transaction, thus ensure realization and the application of the method.
For solving the problems of the technologies described above, embodiments provide a kind of data insertion method of graphic based database, the method comprises: be pre-created new affairs,
Receive the Transaction Identifier of described new affairs, the target data set identifier be inserted in data and graphic data base;
Lock the Current transaction record that described Transaction Identifier is corresponding, so that the current operation of graphic data base is the data insertion under described new affairs; Described data are inserted and are specifically comprised: be added into by described target data set identifier in the associated nodes field of described Current transaction record, and the described data that are inserted into are write described target data set;
Unlock the Current transaction record that described Transaction Identifier is corresponding.
Preferably, described establishment new affairs, specifically comprise:
Generate the Transaction Identifier that an overall situation is unique, and obtain the first system time;
Insert a Current transaction record in the data centralization of the status data of affairs, described Current transaction record comprises described Transaction Identifier and the first system time.
Preferably, also comprise:
When described be inserted into data insert after, the described the first system time is updated to insert complete time the second system time.
Preferably, described the described data that are inserted into are write described target data set, specifically comprise:
Target data record corresponding for described target data set identifier is masked as and is subordinated to described new affairs;
The affairs of described target data set numbering is updated to the Transaction Identifier of described new affairs.
Preferably, the Transaction Identifier of the described new affairs of described reception, be inserted into data and target data set identifier after, also comprise:
Judge that whether described new affairs are effective, if so, then perform the described step locking Current transaction record corresponding to described Transaction Identifier according to described Transaction Identifier, if not, then terminate this secondary data insertion process.
Preferably, after the Current transaction record that the described Transaction Identifier of described unblock is corresponding, also comprise:
Affairs submit state corresponding for described Transaction Identifier is designated effectively;
Target data record corresponding for target data set identifier is designated and is not subordinated to described new affairs; And the field value of the target data set identifier in described target data record is updated to sky;
Delete the Current transaction record that described Transaction Identifier is corresponding.
Preferably, after the Current transaction record that the described Transaction Identifier of described unblock is corresponding, also comprise:
Be effective by transaction rollback status indicator corresponding for described Transaction Identifier;
Delete and the corresponding target data record of described target data set identifier;
Delete the Current transaction record corresponding with described Transaction Identifier.
The embodiment of the present invention additionally provides a kind of online transaction processing system of graphic based database, comprising:
Creation module, for creating new affairs;
Receiver module, for receiving the Transaction Identifier of described new affairs, the target data set identifier be inserted in data and graphic data base;
Locking module, for the Current transaction record that described Transaction Identifier is corresponding, so that the current operation of graphic data base is the data insertion under described new affairs; Described data are inserted and are specifically comprised: be added into by described target data set identifier in the associated nodes field of described Current transaction record, and the described data that are inserted into are write described target data set;
Unlocked state, for unlocking Current transaction record corresponding to described Transaction Identifier.
Preferably, also comprise:
Mark submit state module, is designated effectively by affairs submit state corresponding for described Transaction Identifier;
Mark dirty data module, is not subordinated to described new affairs for being designated by target data record corresponding for target data set identifier; And the field value of the target data set identifier in described target data record is updated to sky;
First removing module, for deleting Current transaction record corresponding to described Transaction Identifier.
Preferably, also comprise:
Mark rollback block of state, for being effective by transaction rollback status indicator corresponding for described Transaction Identifier;
Second removing module, for deleting and the corresponding target data record of described target data set identifier;
Delete the Current transaction record corresponding with described Transaction Identifier.
Compared with prior art, the present invention has the following advantages:
In embodiments of the present invention, when can ensure data inserting in the online transaction processing system of graphic based database, the incomplete technical matters of data in the database existing and conflict and conflict and cause can be solved in prior art, because when carrying out current data and inserting, can lock Current transaction record, even if now there is other data insertion operation, also waiting status can be in.Therefore, the data insertion method disclosed in the present embodiment, can ensure the integrality of data.
Embodiment
For enabling above-mentioned purpose of the present invention, feature and advantage become apparent more, and below in conjunction with the drawings and specific embodiments, the present invention is further detailed explanation.
Online transaction processing system of the present invention can adopt top-down three-decker to realize, and shown in figure 1, is the hierarchy schematic diagram of online transaction processing system in the present invention.The superiors are the API (Application Programming Interface, application programming interface) towards external call program.API is some predefined functions, and object is to provide application program and the user ability to access one group of routine based on certain software or hardware, and without the need to accessing source code, or understand the details of internal work mechanism.Middle layer is the affair logic key-course, synchronization zone and asynchronous district is divided into by class of operation, in synchronization zone, content of operation means can only have an operation to carry out at one time, when this operation is carried out, other operate in enter between synchronization zone and all process waiting status, and which can utilize the thread synchronization lockout feature of Java language to realize.The operation of synchronization zone comprises: the expired inspection of affairs, data inserting control, delete Data Control, Update Table controls and disaster recovery.But not the operation of synchronization zone is then unrestricted, all can carry out at any time.The operation in asynchronous district comprises data query and controls.Orlop is store data set (DataSet) interface in the graphic data base of data, preserves the status information of online transaction self in DataSet, and the transaction status attribute information of data.
In graphic data base, the status information of online transaction can be stored in name and be called in the DataSet of graphic_db_tx_def, and the data structure of this DataSet demand fulfillment can be as shown in table 1:
Table 1
And each Node all has a corresponding DataSet of the same name in graphic data base, relation (Relation) information between data then can be kept at name and be called in the DataSet of graphic_db_relation_record_def.These save all default built-in two row as shown in table 2 in the DataSet of Relation information:
Table 2
Based on above-mentioned online transaction processing system, with reference to figure 2, show the process flow diagram of the data insertion method embodiment 1 of a kind of graphic based database of the present invention, can comprise the following steps:
Step 201: be pre-created new affairs.
First need in online transaction processing system, to create new affairs in advance, can carry out the operation of data after setting up new affairs, such as data are inserted.Shown in figure 3, described step 201 can comprise the following steps in actual applications:
Step 301: generate the Transaction Identifier that an overall situation is unique, and obtain the first system time.
When receiving the API Calls creating new affairs, generate the Transaction Identifier that an overall situation is unique.The Transaction Identifier (ID) such as generated can be: 123abc.Such as, and obtain present system time as the first system time, the first system time can be: 1291739790803.
Step 302: insert a Current transaction record in the data centralization of the status data of affairs, described Current transaction record comprises described Transaction Identifier and the first system time.
Such as can be called in the DataSet of graphic_db_tx _ def in name and insert a new record as Current transaction record, each field value of this current transaction journal can be as shown in table 3:
Table 3
tx_no |
is_commit |
is_rollback |
is_timeout |
start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739790803 |
null |
-1 |
Step 202: receive the Transaction Identifier of described new affairs, the target data set identifier be inserted in data and graphic data base.
When application call needs the API of data inserting, Transaction Identifier, the data be inserted into and target data set identifier are passed to graphic data base.Wherein, described target data set identifier, for representing the positional information being inserted into data and needing after the insertion to store, is namely deposit which data centralization.
Step 203: lock the Current transaction record that described Transaction Identifier is corresponding, so that the current operation of graphic data base is the data insertion under described new affairs.
Need in this step to open issued transaction mark, be namely find Current transaction record by inquiry graphic_db_tx_def, assuming that Transaction Identifier is 123abc, then the value that the processing of this Current transaction record arranges be set to 1, as shown in table 4:
Table 4
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739790803 |
null |
1 |
Step 204: described target data set identifier is added in the associated nodes field of described Current transaction record.
The title this data inserting being operated the Node related to is increased to the associated nodes field in Current transaction record.Assuming that in the Current transaction record that Transaction Identifier 123abc is corresponding, application call API needs to be inserted into name to be called in the Node of Customer by being inserted into data, now target data set identifier is Customer, and being namely needs Customer to give associate_node; Information in then corresponding Current transaction record is as shown in table 5:
Table 5
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739790803 |
Customer |
1 |
It should be noted that, when in identical affairs, if when relating to the Node of multiple target data set, then by the title of multiple Node with CSV.
Step 205: the described data that are inserted into are write described target data set.
Need in this step to be inserted in data write target DataSet.First needing the value by " _ the dirty " of target data record corresponding for target data set arranges to be set to 1, show that these objective data are recorded as dirty data, is namely that these affairs belonging to objective data record are not also submitted to.Again the value that " _ tx_no " arranges is set to Transaction Identifier, is in the present embodiment " 123abc ".
Step 206: unlock the Current transaction record that described Transaction Identifier is corresponding.
Data will be inserted into be written to described target data and concentrate, and also need to close issued transaction mark.Specifically first can inquire about graphic_db_tx_def, if Transaction Identifier is " 123abc ", then the value of the processing row this recorded is set to "-1 ", and Current transaction record now can be as shown in table 6:
Table 6
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739798888 |
Customer |
-1 |
After unlocking Current transaction record, if the follow-up data insertion operation having other under these affairs again, just can continue to perform.
In actual applications, when the present embodiment can ensure data inserting in the online transaction processing system of graphic based database, the incomplete technical matters of data in the database existing and conflict and conflict and cause can be solved in prior art, because when carrying out current data and inserting, can lock Current transaction record, even if now there is other data insertion operation, also waiting status can be in.Therefore, the data insertion method disclosed in the present embodiment, can ensure the integrality of data.
With reference to figure 4, show the process flow diagram of the data insertion method embodiment 2 of a kind of graphic based database of the present invention, the present embodiment can comprise the following steps:
Step 401: receive the Transaction Identifier of described new affairs, the target data set identifier be inserted in data and graphic data base.
This step describes in detail in a upper embodiment, does not repeat them here.
Step 402: judge that whether described new affairs are effective, if so, then enter step 303, if not, then terminate this secondary data insertion process.
The concrete mode judged in the present embodiment can be, inquiry graphic_db_tx_def, and retrieve using Transaction Identifier as filtercondition, if there is one of following situation, then represent that these new affairs are invalid: record does not find, in record, the value of is_commit is 1 (illustrating that affairs are submitted to), and in record, the value of is_rollback is 1 (affairs rollback is described), and in record, the value of is_timeout is 1 (illustrating that affairs are out of date).If affairs are invalid, then terminate this secondary data insertion process, can also error message be returned.
Step 403: lock Current transaction record corresponding to described Transaction Identifier according to described Transaction Identifier.
If the new affairs created are effective, then perform this step.
Step 404: lock the Current transaction record that described Transaction Identifier is corresponding, so that the current operation of graphic data base is the data insertion under described new affairs.
Step 405: described target data set identifier is added in the associated nodes field of described Current transaction record.
Step 406: target data record corresponding for described target data set identifier is masked as and is subordinated to described new affairs.
Namely this step is that the value that " _ dirty " of target data record corresponding for target data set arranges is set to 1, shows that these objective data are recorded as dirty data, is namely that these affairs belonging to objective data record are not also submitted to.
Step 407: the Transaction Identifier affairs of described target data set numbering being updated to described new affairs.
Namely this step is that the value that " _ tx_no " in target data record arranges is updated to Transaction Identifier, is in the present embodiment " 123abc ".
Step 408: unlock the Current transaction record that described Transaction Identifier is corresponding.
Step 409: when described be inserted into data insert after, the described the first system time is updated to insert complete time the second system time.
In the present embodiment, after data are inserted, also comprise the timestamp upgrading Current transaction record, be updated in the start_time row of affiliated transaction journal by up-to-date system time.That supposes Current transaction is numbered 123abc, and current system time is 1291739798888, then the Current transaction record after upgrading can be as shown in table 7:
Table 7
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739798888 |
Customer |
1 |
With reference to figure 5, show the process flow diagram of the data insertion method embodiment 3 of a kind of graphic based database of the present invention, the present embodiment just can perform after step 206, the method that the present embodiment is introduced also can be called transaction commit method in online transaction processing system, the present embodiment after step 206, can also comprise the following steps:
Step 501: affairs submit state corresponding for described Transaction Identifier is designated effectively.
When affairs need to submit to, the affairs for the new data inserted are submitted to, and first application program calls api interface, and Transaction Identifier is passed to graphic data base.
It should be noted that, before step 501, first can also judge that whether affairs are effective, if affairs are invalid, then terminate these affairs and submit process to, can also error message be returned.If the execution of the effective triggered step 501 again of affairs.Wherein, the whether effective judgment mode of affairs is introduced in example 2, does not repeat them here.
This step can be understood as mark affairs submit state.Inquiry graphic_db_tx_def, assuming that affiliated Transaction Identifier is 123abc, is set to 1 by the value of is_commit row in this Current transaction record, as shown in table 8:
Table 8
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
1 |
-1 |
-1 |
1291739790803 |
Customer |
-1 |
Step 502: target data record corresponding for target data set identifier is designated and is not subordinated to described new affairs.
Need target data record corresponding for the target data set of data inserting to be designated not to be subordinated to new affairs in this step, namely be the dirty data state of change target data record, be specifically as follows inquiry graphic_db_tx_def, if the field value Customer of the associate_node in Current transaction record, then continue the DataSet that inquiry target data set by name is designated Customer, the value that " _ dirty " of the data record inserted new in this DataSet arranges is set to-1.
Step 503: the field value of the target data set identifier in described target data record is updated to sky.
Namely be that the value of " _ tx_no " in row target data record is set to null in this step.
Step 504: delete the Current transaction record that described Transaction Identifier is corresponding.
Finally delete transaction journal again, this submitted to the record of affairs to be called the DataSet of graphic_db_tx_def from name and delete, complete the submit operation of affairs.
It should be noted that, if affairs are submitted to unsuccessful, then can perform transaction rollback process, with reference to figure 6, show the process flow diagram of the data insertion method embodiment 4 of a kind of graphic based database of the present invention, the present embodiment just can perform after step 206, and the method that the present embodiment is introduced also can be called transaction rollback method in online transaction processing system, after step 206, the present embodiment can comprise the following steps the present embodiment:
Step 601: be effective by transaction rollback status indicator corresponding for described Transaction Identifier.
After application call API, Transaction Identifier is passed to graphic data base by online transaction processing system.
First graphic data base specifically can judge that whether affairs are effective, if affairs are invalid, then terminate the operation of this transaction rollback, can also return error message.
If affairs are effectively, mark transaction rollback state, specifically will inquire about graphic_db_tx_def, assuming that affiliated Transaction Identifier is 123abc, then the value of is_rollback row in Current transaction record is set to 1, as shown in table 9:
Table 9
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
-1 |
1 |
-1 |
1291739790803 |
Customer |
-1 |
Step 602: delete and the corresponding target data record of described target data set identifier.
Need in this step to delete dirty data.Namely be by inquiry graphic_db_tx_def, obtain the value of the row associate_node in Current transaction record, suppose that the value of these row is Customer, then continuing query aim data set identification is the DataSet of Customer, is deleted by the data record inserted new in this DataSet.
Step 603: delete the Current transaction record corresponding with described Transaction Identifier.
Finally again Current transaction record is also deleted.Because be called the DataSet of graphic_db_tx_def from name by the data record of these rollback affairs and delete, the rolling back action of affairs just can be completed.
It should be noted that, for aforesaid each embodiment of the method, in order to simple description, therefore it is all expressed as a series of combination of actions, but those skilled in the art should know, the present invention is not by the restriction of described sequence of movement, because according to the present invention, some step can adopt other orders or carry out simultaneously.Secondly, those skilled in the art also should know, the embodiment described in instructions all belongs to preferred embodiment, and involved action and module might not be that the present invention is necessary.
With reference to figure 7, show the structured flowchart of the online transaction processing system embodiment 1 of a kind of graphic based database of the present invention, can comprise with lower module:
Creation module 701, for creating new affairs;
Receiver module 702, for receiving the Transaction Identifier of described new affairs, the target data set identifier be inserted in data and graphic data base;
Locking module 703, for the Current transaction record that described Transaction Identifier is corresponding, so that the current operation of graphic data base is the data insertion under described new affairs; Described data are inserted and are specifically comprised: be added into by described target data set identifier in the associated nodes field of described Current transaction record, and the described data that are inserted into are write described target data set;
Unlocked state 704, for unlocking Current transaction record corresponding to described Transaction Identifier.
If after data inserting, need affairs to submit to, then except the module shown in Fig. 7, with reference to figure 8, the online transaction processing system of graphic based database also should comprise with lower module:
Mark submit state module 801, is designated affairs submit state corresponding for described Transaction Identifier effectively.
Mark dirty data module 802, is not subordinated to described new affairs for being designated by target data record corresponding for target data set identifier; And the field value of the target data set identifier in described target data record is updated to sky.
First removing module 803, for deleting Current transaction record corresponding to described Transaction Identifier.
If after data inserting, need to carry out transaction rollback, then except the module shown in Fig. 7, with reference to figure 9, the online transaction processing system of graphic based database also should comprise with lower module:
Mark rollback block of state 901, for being effective by transaction rollback status indicator corresponding for described Transaction Identifier.
Second removing module 902, for deleting and the corresponding target data record of described target data set identifier.
3rd removing module 903, for deleting the Current transaction record corresponding with described Transaction Identifier.
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.For system class embodiment, due to itself and embodiment of the method basic simlarity, so description is fairly simple, relevant part illustrates see the part of embodiment of the method.
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 described key element and also there is other identical element.
A kind ofly the data insertion method in graphic database online transaction is applied to and the data insertion system be applied in graphic database online transaction is described in detail above to provided by the present invention, apply specific case herein to set forth principle of the present invention and embodiment, the explanation of above embodiment just understands method of the present invention and core concept thereof for helping; Meanwhile, for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.