Summary of the invention
In order to address the above problem, the present invention proposes the implementation method of online transaction in a kind of graphic data base, to realize control to online transaction.
The technical solution used in the present invention is as follows:
The implementation method of online transaction in a kind of graphic data base is characterized in that:
Transaction Processing is divided into three layers from top to bottom:
The superiors are the API that is exposed to the external call program;
The middle layer is an affairs logic control layer, be divided into synchronization zone and asynchronous district by class of operation, the synchronization zone means can only have an operation to carry out at one time, other operate in to enter and all are in waiting status between the synchronization zone, this mechanism utilizes the thread synchronization lockout feature of Java language to realize, the operation in asynchronous district is then unrestricted, all can carry out at any time;
Orlop in DataSet, is preserved the status information of online transaction self for the DataSet operation level of abstraction of storage data, and the transaction status attribute information of data;
The status data of online transaction in the graphic data base is stored in name is called among the data set DataSet of graphic_db_tx_def, the data structure of this DataSet is as follows:
Each Node all has a data set DataSet in graphic data base, default built-in following two row among this DataSet:
Carry out following steps:
1) newly-built online transaction;
2) carry out the online transaction data manipulation;
3) submit online transaction to,, otherwise carry out next step if submit to the online transaction success then to finish;
4) rollback online transaction.
Further:
In described step 1), the detailed step of newly-built online transaction is: 1.1) generate the unique affairs ID of the overall situation; 1.2) obtain current system time; 1.3) be called in name and insert a new record among the DataSet of graphic_db_tx_def, the affairs ID that generates is inserted in the tx_no row of this record, the current system time that obtains is inserted in the start_time row of this record; 1.4) newly-generated affairs ID is returned.
In described step 2) in, following steps are carried out in the operation each time in these affairs: the title of 2.1) obtaining this operated node; 2.2) title of this node is saved in the associate_node row of graphic_db_tx_def, if the title of this node do not preserve in front, then in the associate_node row with between the nodename of the title of this node and front with CSV; Otherwise no longer preserve nodename in this operation; 2.3) simultaneously current system time is updated among the row start_time of graphic_db_tx_def.
In described step 3), submit to the detailed step of online transaction to be: 3.1) mark affairs submit state, Query Name are the DataSet of graphic_db_tx_def, and the value to the is_commit row of that record that should affairs wherein is changed to 1; 3.2) read the interdependent node title in the associate_node row of this record, handle the dirty data relevant in the respective nodes successively with these affairs, be converted into formal data, that is, the value that the dirty among the DataSet of respective nodes is listed as changes-1 into; 3.3) among the DataSet of deletion graphic_db_tx_def to that record that should affairs, affairs are submitted to and are finished.
In described step 4), the detailed step of rollback online transaction is: 4.1) mark transaction rollback state, Query Name are the DataSet of graphic_db_tx_def, and the value to the is_rollback row of that record that should affairs wherein is changed to 1; 4.2) read the interdependent node title in the associate_node row of this record, recover the dirty data relevant in the respective nodes successively with these affairs, that is, the value that the dirty among the DataSet of respective nodes is listed as reverts to 1; 4.3) among the DataSet of deletion graphic_db_tx_def to that record that should affairs, transaction rollback is finished.
In the process of submitting online transaction to, also carry out the expired processing of following affairs:
Make regular check on the data among the DataSet who is called graphic_db_tx_def, following inspection done in every record:
Start_time in current system time and the record is compared, if the difference of current time and start_time is greater than the transaction time of setting, mean that then these affairs are expired, check the value of the processing row of this transaction journal then,, illustrate that then these affairs are just in operation if value is 1, this does not carry out expired processing to this transaction journal, the expired processing of affairs finishes, otherwise, continue to carry out next step;
The expired state of mark affairs is changed to 1 with the value to the is_timeout row of that record that should affairs among the DataSet of graphic_db_tx_def;
Read the interdependent node title in the associate_node row of this record, recover the dirty data relevant with these affairs in the respective nodes successively, that is, the value that the dirty among the DataSet of respective nodes is listed as reverts to 1;
To that record that should affairs, affairs are expired to dispose among the DataSet of deletion graphic_db_tx_def.The present invention has the following advantages:
Online transaction identifies with " affairs ID ", and modulated does not limit with the connection of client-side program, and same affairs can be shared between a plurality of clients, realize distributed transaction very easily.
Embodiment
The present invention proposes the implementation method of online transaction in a kind of graphic data base, describe in detail below in conjunction with accompanying drawing.
The graphic data base general introduction
The framework of graphic data base of the present invention can be divided into three layers from top to bottom.As shown in Figure 1, the superiors are the tissue and the realization of various conceptual objects in the graph data.The middle layer is abstract data physical store interface layer, is several data sets DataSet with the data abstraction of physical store.Bottom is that physical store realizes layer, realizes by existing storage engines by program, such as: traditional relational database, XML file or the like.
DataSet (data set)
DataSet is the logic storage unit of data in the graphic data base, the logical definition of data in the graphic data base and database self all is stored among the DataSet, DataSet is an abstract interface, and the realization procedure stores that real data can be by following the DataSet interface is in the file of relational database, XML or user-defined format.Each DataSet is made up of unique title and several row (Column) of the overall situation.Following two kinds of data types are supported in tabulation among the DataSet:
Type |
Explanation |
String |
Be used to preserve the descriptor of Textuality |
Number |
Be used to preserve integer, floating number digital information, or be used for preserving Boolean information, represent true with 1, represent false. with-1 |
Table 1
Node (node)
Node is the logical block of storage data in the graphic data base, in graphic data base, each record entity can abstractly be Node all, such as when explaining an applications of computer network system, port in the switch, the network interface card of PC server, CPU, produce the manufacturer of accessory, we provide the client of service for it, user in the system, authority or the like, each Node has a title that the overall situation is unique, its distinctive attributes with some, be used for recording configuration information, for example: with respect to the client of our service, we are with its called after Customer, and it has following attribute: contractedAmount (contract total value), industry (affiliated industry), name (customer name), description (description) etc.In the present invention, the attribute of Node can be the data of following type.
Table 2
The definition information of each Node all is kept at name and is called among the DataSet of graphic_db_node_def, and the data structure of this DataSet is as follows:
The row title |
Data type |
Explanation |
?node_id |
Number |
The ID that the overall situation is unique |
?name |
String |
Be used to preserve the title of Node |
Table 3
Among each Node defined attribute information be kept at the name be called among the DataSet of graphic_db_node_attr_def, the data structure of this DataSet is as follows:
Table 4
Be directed to the definition of Node, similar following two tables of the DataSet of physical store:
Table 5
Table 6
The data message of each Node is kept among the DataSet of the same name with it, supposes that we have a name to be called the Node of Customer, and this Node has following attribute:
Property Name |
Data type |
Explanation |
RID |
String |
Database is built-in |
name |
String |
Customer name |
contractedAmount |
Number |
Contract value |
industry |
Reference |
Affiliated industry |
description |
String |
Client's descriptor |
Table 7
Then the DataSet structure of this Node correspondence is:
Table 8
The similar following table of the DataSet of physical store:
Table 9
RID (Record ID, Record ID)
In graphic data base, each Node can have a name to be called the attribute of RID, and the RID value that is stored in each the bar data among the Node all is that the overall situation is unique, is recorded in sign in the graphic data base as this.The data type of RID is the String type.Each Node all contains this attribute.The RID form is: Node title+underscore+increase progressively numeral, a typical R ID numerical value is similar to following form: Industry_109.
Relation (relation)
The entity of each category information all can be abstract is Node, in real world applications, usually needs these Node by certain logical organization, and Relation is used for describing the membership credentials between Node and the Node.Suppose the now existing Node:Customer that represent client, representative system user's Node:SysUser, in real world, our sales force can become a user in the system, and be responsible for some clients sale, reach communication work.Therefore, we Relation that can set up a SysUserServeCustomer by name between SysUser and Customer explains relation between the two.We explain this relation with Fig. 2, and Relation is used to describe the special object that concerns between Node and the Node.Each Relation all has a title that the overall situation is unique, a source Node, a target Node.By the direction of source Node to target Node, we are referred to as forward, and we are referred to as oppositely to the direction of initial Node by target Node.
The definition information of each Relation all is kept at name and is called among the DataSet of graphic_db_relation_def, and the data structure of this DataSet is as follows:
The row title |
Data type |
Explanation |
?relation_id |
Number |
The ID that the overall situation is unique |
?name |
String |
Be used to preserve the title of Relation |
?source_node |
Number |
The ID of source Node |
?target_node |
Number |
The ID of target Node |
Table 10
Be directed to the definition of Relation, the similar following table of the DataSet of physical store:
Table 11
According to the definition of Relation, the data among two Node that connect by Relation can connect.The link information of all data is kept at name and is called among the DataSet of graphic_db_relation_record_def, and the data structure of this DataSet is as follows:
Table 12
In application scenarios, the similar following table of the DataSet of its physical store:
Table 13
Reference (quoting)
In graphic data base was abstract, some Node commonly used can have relation with other most of Node, and these Node data volumes commonly used are very limited and can not change substantially, such as: country, province, city etc.If adopt the mode of Relation to explain, then need and other Node between the big magnitude relation set up, this maintenance to the later stage will cause certain difficulty.Under this kind situation, can consider to adopt the form of Reference to explain relation.A Node quotes another one Node by the attribute that it had, and realizes in form at it, and is largely similar with the Foreign Key (external key) of RDBMS (relational database).That preserve in the Dictionary attribute of a certain record is the RID of data recording among the another one Node.Node---the Customer that we discussed before considering has this attribute of (industry) industry, supposes that in our application scenarios, the quantity of industry is very limited, and can often not change.Then can quote certain bar record among this Node of Industry with the mode of Reference attribute.The storage mode of data in DataSet as shown in Figure 3.
We dot the Reference between the Node in the present invention, to be different from Relation, see Fig. 4.
Online transaction and non-online transaction
The operation of data can be divided in the graphic data base: " online transaction data manipulation " and " non-online transaction data manipulation ".Online transaction data manipulation steps in sequence is: create online transaction, carry out online transaction data manipulation (this operation can repeat repeatedly in an online transaction), submit to online transaction that operation is come into force or rollback online transaction abort operation.See shown in Figure 5.But not the online transaction data manipulation is not controlled by affairs, directly calls graphic data base API and gets final product.
As shown in Figure 6, Transaction Processing of the present invention is divided into three layers from top to bottom:
The superiors are the API that is exposed to the external call program.
The middle layer is an affairs logic control layer, be divided into synchronization zone and asynchronous district by class of operation, the synchronization zone means can only have an operation to carry out at one time, and other operate in to enter and all are in waiting status between the synchronization zone, and this mechanism utilizes the thread synchronization lockout feature of Java language to realize.The operation in asynchronous district is then unrestricted, all can carry out at any time.
Orlop in DataSet, is preserved the status information of online transaction self for the DataSet operation level of abstraction of storage data, and the transaction status attribute information of data.
In graphic data base, the status data of online transaction is stored in name and is called among the DataSet of graphic_db_tx_def, and the data structure of this DataSet is as follows:
Table 14
Each Node all has a corresponding DataSet of the same name in graphic data base, and the Relation information between the data is kept at name and is called among the DataSet of graphic_db_relation_record_def.All default built-in following two row among these DataSet:
Table 15
Newly-built issued transaction flow process
When receiving the API Calls of creating affairs, treatment step is as follows:
(1) generates the unique affairs ID of the overall situation.Suppose that the affairs ID that generates is: 123abc
(2) obtain current system time, suppose that current system time is: 1291739790803
(3) be called in name and insert a new record among the DataSet of graphic_db_tx_def, the affairs ID that generates is inserted in the tx_no row of this record, the current system time that obtains is inserted in the start_time row of this record.Its record value is as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739790803 |
null |
-1 |
Table 16
(4) newly-generated affairs ID is returned, that is, the overall unique affairs ID that generates in the step (1) is returned to the client-side program that calls API.
Increase in the affairs, delete, the treatment scheme when changing data
When in affairs, increasing, delete, changing the operation of data, at first obtain the title of operated node, with after the title of this node is saved in the associate_node row of graphic_db_tx_def, the affairs ID that supposes generation is 123abc, and the creation-time of affairs is 1291739790803.Then after new establishment finished affair, the initial value of data was as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739790803 |
null |
-1 |
Table 17
Suppose that the nodename of operating for the first time is Customer in these affairs, current system time is 1291739800000, then Customer is saved in the associate_node row of graphic_db_tx_def, simultaneously current system time is updated among the row start_time, the value of data is as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739800000 |
Customer |
-1 |
Table 18
Suppose that the nodename of operating for the second time is Contract in these affairs, current system time is 1291739801000, then Contract also is saved in the associate_node row of graphic_db_tx_def, between the different nodenames with CSV.Simultaneously current system time is updated among the row start_time, the value of data is as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739801000 |
Customer,Contract |
-1 |
Table 19
Suppose that the nodename of operating for the third time is again Customer in these affairs, current system time is 1291739802000, because value is being saved to during associate_node is listed as before for the node name of Customer, then this no longer preserves nodename.Current system time is updated among the row start_time, and the value of data is as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
-1 |
1291739802000 |
Customer,Contract |
-1 |
Table 20
The treatment scheme that affairs are submitted to
(1) mark affairs submit state.Inquiry graphic_db_tx_def, affairs are numbered 123abc under supposing, and the value that this record is_commit is listed as is changed to 1, and is as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
1 |
-1 |
-1 |
1291739802000 |
Customer,Contract |
-1 |
Table 21
(2) read interdependent node title in the associate_node row, handle the dirty data relevant in the respective nodes successively with these affairs.Be converted into formal data, that is: the value of data dirty row is-1 among the change respective nodes DataSet, and the value of general _ tx_no row is made as null simultaneously.
(3) deletion name is called the data recording that affairs among the DataSet of graphic_db_tx_def are numbered 123abc.Affairs are submitted to and are finished.
The treatment scheme of transaction rollback
(1) mark transaction rollback state.Inquiry graphic_db_tx_def, affairs are numbered 123abc under supposing, and the value that this record is_rollback is listed as is changed to 1, and is as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
-1 |
1 |
-1 |
1291739802000 |
Customer,Contract |
-1 |
Table 22
(2) read interdependent node title in the associate_node row, recover the dirty data relevant in the respective nodes successively with these affairs.
(3) deletion name is called the data recording that affairs among the DataSet of graphic_db_tx_def are numbered 123abc.Transaction rollback is finished.
The treatment scheme that affairs are expired
In graphic data base, be that 10 milliseconds repeating query program checkout name is called the data among the DataSet of graphic_db_tx_def by the cycle, as follows to the step of the inspection of every record:
(1) start_time in current system time and the record is compared, if the difference of current time and start_time is greater than 30000 (30 seconds), mean that then these affairs are expired, check the value of the processing row of this transaction journal then, if value is 1, illustrate that then these affairs are just in operation, this does not carry out expired processing to this transaction journal, and the expired processing of affairs finishes.Otherwise, continue execution in step (2).
(2) the expired state of mark affairs.The affairs of supposing this record are numbered 123abc, and the value that this record is_timeout is listed as is changed to 1, and is as follows:
tx_no |
is_commit |
is_rollback |
is_timeout |
Start_time |
associate_node |
processing |
123abc |
-1 |
-1 |
1 |
1291739802000 |
Customer,Contract |
-1 |
Table 23
(3) read interdependent node title in the associate_node row, recover the dirty data relevant in the respective nodes successively with these affairs.
(4) deletion name is called the data recording that affairs among the DataSet of graphic_db_tx_def are numbered 123abc.Affairs are expired to dispose.