Summary of the invention
In order to solve above-mentioned technical problem, the invention provides a kind of data replacement method and system, solve the method for replacement data in existing XML database, it is necessary to twice caused complex steps of finding step, work load is big, the problem of transaction concurrency process performance difference.
According to one aspect of the present invention, it is provided that a kind of data replacement method, being applied to XML database, wherein, this data replacement method includes:
Search the destination address of data to be replaced;
Whether detection destination address exist the old value data identical with data name to be replaced;
If destination address exists old value data, data to be replaced are replaced old value data;
If destination address is absent from old value data, data to be replaced are inserted into destination address.
Alternatively, this data replacement method also included before searching the step of destination address of data to be replaced:
Obtain the target address information of described data to be replaced, search described destination address according to described target address information.
Alternatively, when the type of data to be replaced is document, this data replacement method includes:
Search the target container of document to be replaced;
Whether detection target container exist the old value document identical with document title to be replaced;
When old value document exists, document to be replaced is replaced old value document;
When old value document is absent from, target container inserts document to be replaced.
Alternatively, also included before searching the step of target container of document to be replaced:
Create and name the container of storage document, different types of document is stored in the container of correspondence.
Alternatively, the type of document to be replaced include XML file, server end exist file or/and client exist file.
Alternatively, when the type of data to be replaced is node, this data replacement method includes:
Searching the destination path of node to be replaced, destination path calculates according to path expression;
Whether detection destination path place exists old value node;
When old value node exists, node to be replaced is replaced old value node;
When old value node is absent from, it may be judged whether receive insertion instruction, if receiving insertion instruction by node city to be replaced to destination path place; If not receiving insertion instruction, then send error information.
Alternatively, node to be replaced includes: XML path expression fragment or XML fragment.
Alternatively, when the type of data to be replaced is nodal community, this data replacement method includes:
Search the destination path of nodal community to be replaced;
Whether detection destination path place exists the old value nodal community consistent with nodal community title to be replaced,
When old value nodal community exists, nodal community to be replaced is replaced old value nodal community,
When old value nodal community is absent from, it may be judged whether receive insertion instruction, if receiving insertion instruction, nodal community to be replaced is inserted into destination path place; If not receiving insertion instruction, then send error information.
According to another aspect of the present invention, additionally provide a kind of data replacement system, be applied to XML database, including:
Enquiry module, for searching the destination address of data to be replaced;
Whether detection module, exist the old value data identical with data name to be replaced for detecting in destination address;
Replacement module, for when there are old value data in destination address, replacing old value data by data to be replaced;
Insert module, for when destination address is absent from old value data, data to be replaced being inserted into destination address.
Alternatively, this data replacement system, also include:
Acquisition module, for obtaining the target address information of data to be replaced, searches destination address according to target address information.
Alternatively, enquiry module includes: the first enquiry module, for searching the target container of document to be replaced; Detection module includes: first detection module, for detecting whether there is the old value document identical with document title to be replaced in target container; Replacement module includes: the first replacement module, for when old value document exists, document to be replaced being replaced old value document; Insertion module includes: first inserts module, for when old value document is absent from, inserting document to be replaced in target container.
Alternatively, this data replacement system, also include:
Creation module, for creating and name the container of storage document, is stored in different types of document in the container of correspondence.
Alternatively, this enquiry module also includes: the second enquiry module, and for searching the destination path of node to be replaced, destination path calculates according to path expression; This detection module also includes: the second detection module, is used for detecting whether destination path place exists old value node; Replacement module also includes: the second replacement module, for when old value node exists, node to be replaced being replaced old value node; Insert module also to include: second inserts module, for when old value node is absent from, it may be judged whether receive insertion instruction, if receiving insertion instruction by node city to be replaced to destination path place; If not receiving insertion instruction, then send error information.
Alternatively, this enquiry module also includes: the 3rd enquiry module, for searching the destination path of nodal community to be replaced; This detection module also includes: the 3rd detection module, for detecting whether destination path place exists the old value nodal community consistent with nodal community title to be replaced, replacement module also includes: the 3rd replacement module, for when old value nodal community exists, nodal community to be replaced is replaced old value nodal community, insert module also to include: the 3rd inserts module, for when old value nodal community is absent from, judge whether to receive insertion instruction, if receiving insertion instruction, nodal community to be replaced is inserted into destination path place; If not receiving insertion instruction, then send error information.
Embodiments of the invention provide the benefit that: a kind of data replacement method and system, by inquiry is merged into an operation with more newly inserted, when needs replacement data, only need to find destination address, and detect whether this destination address exists the old value data identical with data name to be replaced, if existing, then replace this old value data, if being absent from, then insert data to be replaced in this destination address; In the method for original replacement data, thus decrease the operation once searching destination address, for the affairs that the destination address of data to be replaced is complicated, reduce search operation and can be greatly promoted the process performance of system; Thus improve transaction concurrency amount to a certain extent.
Embodiment
Such as Fig. 1 with as in figure 2 it is shown, The embodiment provides a kind of data replacement method, including:
Step 10: search the destination address of data to be replaced;
When client needs replacement data, obtain the target address information of data to be replaced, search the destination address of data to be replaced according to this target address information;
Step 20: detect and whether there are the old value data identical with this data name to be replaced in this destination address;
When after the destination address finding data to be replaced, it is necessary to detect in this destination address, whether detection exists the old value data identical with the title of data to be replaced in this destination address, makes next step operating procedure according to testing result;
Step 30: if there are this old value data in destination address, data to be replaced are replaced these old value data;
If testing result is the old value data that existence and data to be replaced have same names in destination address, then just data to be replaced is replaced former Value Data, namely realizes the operation of more new data;
Step 40: if the low IQ of target is absent from this old value data, data to be replaced are inserted into destination address;
If detection structure is be absent from having the old value data of same names with data to be replaced in destination address, then just data to be replaced is inserted into destination address, namely realizes the operation of insertion data.
Can realize updating and update by above step, and whole process has only carried out once searching the operation of datum target address to be replaced, for the affairs that destination address is more complicated, the data replacement method of the present invention greatly reduces the working strength of system, the disposal ability of things concurrency thus improves the overall performance of system, thus can be improved to a certain extent.
Below by with the embodiment done by different types of data to be replaced, only so that the specific implementation process of this data replacement method to be described.
When the type of data to be replaced is document, the specific implementation of this data replacement method, as it is shown on figure 3, create and name the container of storage document, different types of document is stored in the container of correspondence; When document replaced by needs, first look for the target container of document to be replaced, then whether detection target container exists the old value document identical with this document title to be replaced; When old value document exists, document to be replaced is replaced this old value document, it is achieved the renewal operation of document; When old value document is absent from, document to be replaced is inserted in target container, forms new document, it is achieved the update of document; So renewal and update are merged into an operation, when a large amount of replacement document request, decreases once-through operation, the concurrency of affairs can be improved to a certain extent.
Alternatively, the type of document to be replaced includes: XML file, server end exist file or/and client exist file etc. multiple Doctype; To increase the grammer support replacing document as specific implementation in the present embodiment, increase following grammer support:
1) ReplaceDoccontainernamedocumentname-sxmlstring;
Wherein, what ReplaceDoc represented this grammer act as replacement document; Containername represents the title of each container depositing document; Documentname represents that document is stored in the title in container, provides document title during for inquiry later;-s represents last parameters selection xmlstring; Xmlstring is the content of an XML file, fragment;
2) ReplaceDoccontainernamedocumentname fxmlfilename;
Wherein ,-f represents last parameters selection xmlfilename; Xmlfilename is the file that server end exists;
3) ReplaceDoccontainernamedocumentname lxmlfilename;
Wherein ,-l represents last parameters selection xmlfilename; Xmlfilename is the file that client exists.
When the type of data to be replaced is node, the specific implementation of this data replacement method, as shown in Figure 4, when node replaced by needs, first look for the destination path of node to be replaced, this destination path calculates according to path expression, and then whether detection destination path place exists old value node; When old value node exists, node to be replaced is replaced this old value node, it is achieved the renewal operation of node; When old value node is absent from, it may be judged whether receive insertion instruction, if receiving insertion instruction, by node city to be replaced to destination path place, it is achieved the update of node; If not receiving insertion instruction, then system sends error information; So renewal and update are merged into an operation, when a large amount of replacement node request, decreases once-through operation, the concurrency of affairs can be improved to a certain extent.
Alternatively, node to be replaced includes: XML path expression fragment or XML fragment; XML path expression fragment or XML fragment can be updated XML path expression fragment; XQueryUpdateFacility (XMLQuery, XML data query language) has been defined for replace associative operation, to strengthen the support of replace grammer as specific implementation in the present embodiment, increases following grammer support:
1) " replace " [" orinsert "]? " node " AwithB
Wherein, Replace represents replacement node; Orinsert represents insertion instruction; Node represents node; A represents that node is XML path expression fragment; B represents that node is XML path expression fragment or XML fragment; The function that this grammer realizes is:
If " node " A exists, then just replace A with B, otherwise
A.orinsert is designated, and inserts B
B.orinsert is not designated, and sends error information: Thesequencedoesnotcontainitems.
When the type of data to be replaced is nodal community, the specific implementation of this data replacement method, as shown in Figure 5, when nodal community replaced by needs, first looking for the destination path of nodal community to be replaced, then whether detection destination path place exists the old value nodal community consistent with nodal community title to be replaced; When old value nodal community exists, nodal community to be replaced is replaced this old value nodal community, it is achieved the renewal operation of nodal community; When old value nodal community is absent from, it may be judged whether receive insertion instruction, if receiving insertion instruction, nodal community to be replaced is inserted into destination path place, it is achieved the update of nodal community; If not receiving insertion instruction, then system sends error information; So renewal and update are merged into an operation, when a large amount of replacement node request, decreases once-through operation, the concurrency of affairs can be improved to a certain extent.
Alternatively, XQueryUpdateFacility has been defined for replace associative operation, to strengthen the support of replace grammer as specific implementation in the present embodiment, increases following grammer support:
1) " replace " [" orvalue "]? " value " " of " " node " A/attributionwith " newvalue "
Wherein, Replace represents replacement nodal community; Orinsert represents insertion instruction; Value is expressed as node definition; Node represents node; A represents path expression; Attribution represents the nodal community of A; Newvalue represents new attribute definition; The function that this grammer realizes is:
If the nodal community of " node " A exists, then update the nodal community of " node " A at destination path place, otherwise
A.orinsert is designated, and inserts A/attribution=newvalue, namely inserts new nodal community;
B.orinsert is not designated, then send error information: Thesequencedoesnotcontainitems.
According to another aspect of the present invention, additionally provide a kind of data replacement system, be applied to XML database; As shown in Figure 6, this data replacement system includes:
Enquiry module, for searching the destination address of data to be replaced;
Whether detection module, exist the old value data identical with data name to be replaced for detecting in destination address;
Replacement module, for when there are old value data in destination address, replacing old value data by data to be replaced;
Insert module, for when destination address is absent from old value data, data to be replaced being inserted into destination address.
Alternatively, this data replacement system, also include:
Acquisition module, for obtaining the target address information of data to be replaced, searches destination address according to target address information.
Alternatively, enquiry module includes: the first enquiry module, for searching the target container of document to be replaced; Detection module includes: first detection module, for detecting whether there is the old value document identical with document title to be replaced in target container; Replacement module includes: the first replacement module, for when old value document exists, document to be replaced being replaced old value document; Insertion module includes: first inserts module, for when old value document is absent from, inserting document to be replaced in target container.
Alternatively, this data replacement system, also include:
Creation module, for creating and name the container of storage document, is stored in different types of document in the container of correspondence.
Alternatively, this enquiry module also includes: the second enquiry module, and for searching the destination path of node to be replaced, destination path calculates according to path expression; This detection module also includes: the second detection module, is used for detecting whether destination path place exists old value node; Replacement module also includes: the second replacement module, for when old value node exists, node to be replaced being replaced old value node; Insert module also to include: second inserts module, for when old value node is absent from, it may be judged whether receive insertion instruction, if receiving insertion instruction by node city to be replaced to destination path place; If not receiving insertion instruction, then send error information.
Alternatively, this enquiry module also includes: the 3rd enquiry module, for searching the destination path of nodal community to be replaced; This detection module also includes: the 3rd detection module, for detecting whether destination path place exists the old value nodal community consistent with nodal community title to be replaced, replacement module also includes: the 3rd replacement module, for when old value nodal community exists, nodal community to be replaced is replaced old value nodal community, insert module also to include: the 3rd inserts module, for when old value nodal community is absent from, judge whether to receive insertion instruction, if receiving insertion instruction, nodal community to be replaced is inserted into destination path place; If not receiving insertion instruction, then send error information.
Above-described is the preferred embodiment of the present invention; should be understood that the ordinary person for the art; can also making some improvements and modifications under without departing from principle premise of the present invention, these improvements and modifications are also in protection scope of the present invention.