WO2015117429A1 - Method and device for merging database contents - Google Patents

Method and device for merging database contents Download PDF

Info

Publication number
WO2015117429A1
WO2015117429A1 PCT/CN2014/090271 CN2014090271W WO2015117429A1 WO 2015117429 A1 WO2015117429 A1 WO 2015117429A1 CN 2014090271 W CN2014090271 W CN 2014090271W WO 2015117429 A1 WO2015117429 A1 WO 2015117429A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
source
destination
merging
merge
Prior art date
Application number
PCT/CN2014/090271
Other languages
French (fr)
Chinese (zh)
Inventor
龙涛
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2015117429A1 publication Critical patent/WO2015117429A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • the present invention relates to the field of computers, and in particular, to a method and apparatus for merging database contents.
  • the data migration tool provided by the database management system itself is usually used for data merge migration.
  • this data migration tool is a generalized tool, it can only handle simple data migration logic, such as appending data from a table in database A to a table in database B.
  • Embodiments of the present invention provide a database content merging method and apparatus to at least solve the merging problem of an application for complex business logic in the prior art.
  • the present invention provides a database content merging method, including:
  • the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
  • the step of establishing a mirror database corresponding to the source database includes:
  • the step of combining the source information of the mirror database with the destination table of the destination database that needs to be merged with the source table according to the merge policy corresponding to the source table in the mirror database includes: :
  • the sql statement and/or the merge plug-in is selected to detect whether the table in the mirror database and the destination database can be combined with the form information, and if the detection is successful, according to the merge policy
  • the table merge strategy combines the source tables of the mirror database with the destination tables in the destination database that need to be merged with the source tables.
  • the step of combining the source table of the mirror database with the destination table of the destination database that needs to be merged with the source table according to the table merge policy in the merge policy includes:
  • the table information is merged in the priority table in the source table and the destination table in the destination database.
  • the step of merging the form information on the source table and the destination table in the destination database includes:
  • the table merging strategy is a specified merging strategy and the specified merging strategy type is merging or modifying the policy, it is determined whether there is a destination table with the same name as the source table in the destination database, and if present, the source table and the same name as the source table The destination form merges the form information. Otherwise, a destination form with the same name as the source form is created in the destination database, and the form information is merged between the source form and the destination form.
  • the steps of combining the form information of the source form and the destination form include:
  • the step of merging the form information with the source table and the destination table according to the specified merging policy of the source table includes:
  • the source table does not specify a merge policy, the total number of records of the source table is obtained;
  • the step of merging the form information with the source table and the destination table according to the specified merging policy of the source table includes:
  • the source table has a specified merge policy, modify the source table according to the specified merge policy to obtain a record of the modified source table;
  • the steps of modifying the source table to obtain the record of the modified source table include:
  • the dependent content table is also modified to obtain a record of the modified source table.
  • the step of inserting the record of the modified source table into the destination table includes:
  • the incremental ID of the record is automatically generated by the trigger when the record of the source table is inserted in the destination table; otherwise, when the record of the source table is inserted in the destination table , the trigger is disabled, and after the record insertion is completed, the trigger is restored to the state before the merge.
  • An embodiment of the present invention further provides a database content merging device, including:
  • Establishing a module configured to establish a mirror database corresponding to the source database, where the mirror database is the same as the source database;
  • the merging module is configured to merge the source table of the mirror database with the destination table of the target database that needs to be merged with the source table according to a merging policy corresponding to the source table in the mirror database.
  • the building module includes:
  • the backup sub-module is set as a backup source database to obtain a backup file carrying the form information
  • connection submodule is set to select a database management system to which the destination database belongs;
  • the merge module includes:
  • the merging sub-module is set to use the sql statement and/or the merge plug-in to detect whether the table in the mirror database and the destination database can be combined with the table information according to the detection policy, and if the detection is successful, According to the table merging strategy in the merging strategy, the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
  • the table records in the source database are appended to the table of the same name in the destination database by default by merging the main program; for the table containing the complex business logic data that is not recognized by the merge main program, by the policy configuration file Specify the corresponding merge strategy in the merged main program according to the merge strategy to merge the data; for most application scenarios, the developer only needs to configure some SQL statements in the policy configuration file to achieve the modification cannot be directly merged.
  • the purpose of the tabular data in the extremely complex application scenario, the developer can integrate the secondary development plug-in implemented by the encoding into the merge process; in addition, the present invention also adopts the processing mechanism of the concurrent thread to improve the processing of the merge. speed.
  • FIG. 1 is a flowchart of a method for merging database contents according to an embodiment of the present invention
  • FIG. 2 is a flowchart of a specific embodiment of a method for merging database content according to an embodiment of the present invention
  • FIG. 3 is a flowchart of table merging in a method for merging database contents according to an embodiment of the present invention
  • FIG. 4 is a structural block diagram of an apparatus for merging database contents according to an embodiment of the present invention.
  • an embodiment of the present invention provides a database content merging method, including:
  • Step 11 Establish a mirror database corresponding to the source database, where the mirror database is the same as the source database;
  • Step 12 According to the merging policy corresponding to the source table in the mirror database, merge the source table of the mirror database with the destination table in the destination database that needs to be merged with the source table, and merge the table information.
  • the embodiment of the present invention needs to merge with the source table in the source table and the destination database of the mirror database by establishing a mirror database identical to the source database and according to the merge policy corresponding to the source table in the mirror database.
  • the purpose table is used to merge the form information; thus, the two sets of independent database contents of the same application software can be combined into a set of database content solutions, which can adapt to various complicated business logics.
  • step 11 may include:
  • Step 111 Backing up the source database to obtain a backup file carrying the form information
  • Step 112 selecting a database management system to which the destination database belongs
  • Step 113 Establish a mirror database corresponding to the source database in the database management system, and add table information carried in the backup file to the mirror database.
  • a temporary mirror database is created in the database management system where the destination database is located, and the source database is restored to the temporary mirror database through the backup recovery function (or other data migration method), and then the temporary database is restored.
  • the mirror database is used as the source database. This allows the user to access both the source and destination databases in the sql statement.
  • step 12 may specifically include:
  • Step 121 Obtain a merge policy corresponding to the source table in the mirror database in the configuration file.
  • Step 122 When there is a detection policy in the merge policy, according to the detection policy, the sql statement and/or the merge plug-in is selected to detect whether the table in the mirror database and the destination database can be combined with the form information, and if the detection is successful, according to the The table merging strategy in the merging strategy merges the source table of the mirror database with the destination table in the destination database that needs to be merged with the source table.
  • the user in order to adapt to complex business logic, the user needs to configure some “merging policies” to intervene in the merge process.
  • Some scenarios in the merge process do not need to be merged. Therefore, before the merge, The detection is performed to identify some application scenarios that cannot be merged. For example, in the student registration information management system, two or more student records with the same identity card number are not allowed. If the two sets of database contents to be merged are detected before the merger, such conflicts should be prohibited.
  • the merge process for example, the contents of the two databases to be merged are generated by different versions of the application software, and the data structures are incompatible and should not be merged.
  • Performing detection before merging according to the table merging strategy in the merging strategy, merging the source table of the mirror database with the destination table of the destination database that needs to be merged with the source table, can improve service processing efficiency .
  • step 122 according to the table merging policy in the merging policy, the source table of the mirror database and the destination table in the destination database that need to be merged with the source table are used to perform table information.
  • the specific implementation process of the merger may include:
  • Step 1221 Obtain a set of all source tables in the mirror database.
  • Step 1222 Establish a correspondence between the table and the table merging strategy in the set of the source table that needs to be merged with the destination table in the destination database;
  • step 1223 the form information is merged in the source table and the destination table in the destination database in order of priority.
  • FIG. 2 The specific implementation of this embodiment is shown in FIG. 2, and the database content merge process as a whole includes:
  • step (9) Perform the pre-merger detection according to the detection strategy in the merge policy. If the return fails, go to step (9) to end the merge; if the return is successful, or if no detection policy is configured, continue with the subsequent steps. ;
  • the merge device sequence acquires all the table information sets in the source database to be merged, and combines all the merge policies obtained in step (2) to establish a mapping relationship between all the merged tables and the merge policy, where to be merged.
  • the table is: in the collection of source tables, the tables that need to be merged with the destination table in the destination database, and sorted according to the priority level defined in the merge strategy;
  • the merged device deletes the created temporary database
  • the specific implementation process for combining the form information in the source table and the destination table in the destination database includes:
  • Step 12231 Obtain a table merging policy corresponding to the source table in the set of source tables
  • Step 12232 If the table merge policy is a specified merge policy and the merge policy type is a merge or a modify policy, determine whether there is a destination table in the destination database having the same name as the source table in the set of the source table, if yes, Form information is merged between the source table and the destination database with the same name as the source table. Otherwise, a destination table with the same name as the source table is created in the destination database, and the table information is merged between the source table and the destination table.
  • step 12232 the step of merging the form information with the source form and the destination form includes:
  • step 12232 according to the specified merge policy of the source table, the step of combining the form information with the source form and the destination form includes:
  • Step 122321 If the source table does not specify a merge policy, obtain the total number of records in the source table; if the total number of records in the source table is not 0, execute an insert statement to insert all the records in the source table into the destination table.
  • Step 122322 If the source table has a specified merge policy, modify the source table according to the specified merge policy to obtain a record of the modified source table; insert the record of the modified source table into the destination table.
  • step 122322 the step of modifying the source table to obtain the record of the modified source table includes:
  • the dependent content table is also modified to obtain a record of the modified source table.
  • the step of inserting the record of the modified source table into the destination table includes:
  • the incremental ID of the record is automatically generated by the trigger when the record of the source table is inserted in the destination table; otherwise, when the record of the source table is inserted in the destination table , the trigger is disabled, and after the record insertion is completed, the trigger is restored to the state before the merge.
  • step 8 the total number of records in the source database is obtained. If the total number of records is 0, then go to step 8 to end the merge process of the table, otherwise go to step 6 to perform additional merge of the table records;
  • the merging device performs a series of steps of modifying the contents of the database according to the policy; if the merge policy is not set by the "merging processor" to complete the merge process of the modified data, then go to step 7, Otherwise continue the next steps;
  • the modified content merge policy of the table is a child node of the database policy, and is set to modify the data to be merged in the merge process, and includes the following contents:
  • the priority level is optional. If you do not specify a priority level, the default is to inherit the priority of the parent node database. After the table with the highest priority is merged, the table with the lower priority level can be merged. For tables with foreign key dependencies, the "Merge Processor" can be automatically identified from the system table of the database management system, and then the priority is automatically set, without the user having to set the priority.
  • child node optional, can be configured with multiple child nodes, set to modify the table structure or data content in the source database or destination database (not only limited to modify the currently processed table, but also modify other associated dependency tables);
  • the "merging processor” can be identified from the system table of the database management system, so the user can automatically process even if the specific column name is not specified; in some scenarios, a column is not defined. Adding columns, but using sequence or other business logic algorithms to achieve similar auto-increment functions, the "merge processor” does not recognize this situation, so the user must specify the corresponding column name; if a sequence is used, it also needs Specify the sequence name. Based on these two pieces of information, the "Merge Processor” can use some algorithms to automatically modify the value of the column to avoid the constraint of violating the uniqueness of the self-incrementing column and synchronize the current value of the sequence;
  • 9 self-additional association foreign key sub-table name and column name is a child node of 7, optional, can be configured with multiple child nodes. If the table has an associated child table, and the parent-child relationship is maintained by the uniqueness of the parent table self-incrementing column, the corresponding child table name and column name need to be specified in the parent table policy, so that the merge main program is modifying the self table.
  • the foreign key column of the associated sub-table can be automatically modified when the column is added;
  • Trigger names that need to be disabled optional, child nodes, configurable multiple child nodes. Whether the specified trigger is disabled in the process of merging the current table according to the business logic is determined by the user, and the original state is restored after the merge is completed.
  • all databases that need to participate in the merge are backed up in the database management system where the source database is located.
  • a common process for merging database content can be implemented. The overall merge process is completed by the merge main program; for tables that do not require special processing, the merge main program defaults the records in the source database.
  • the merge main program Append to the table of the same name in the destination database; for the table containing the complex business logic data that the merge main program cannot recognize, the developer specifies the merge policy in the policy configuration file, and the merge main program performs the data according to the merge strategy. Consolidation; in most application scenarios, developers only need to configure some SQL statements in the policy configuration file to modify the table data that cannot be directly merged. In extremely complex application scenarios, developers can implement their own coding.
  • the secondary development plug-in is integrated into the merge process; in addition, the merge device uses the processing mechanism of the concurrent thread to improve the processing speed of the merge.
  • An embodiment of the present invention further provides a database content merging device, including:
  • Establishing a module configured to establish a mirror database corresponding to the source database, where the mirror database is the same as the source database;
  • the merging module is configured to merge the source table of the mirror database with the destination table of the target database that needs to be merged with the source table according to a merging policy corresponding to the source table in the mirror database.
  • the building module includes:
  • the backup sub-module is set as a backup source database to obtain a backup file carrying the form information
  • connection submodule is set to select a database management system to which the destination database belongs;
  • the merge module includes:
  • the merging sub-module is set to use the sql statement and/or the merge plug-in to detect whether the table in the mirror database and the destination database can be merged with the form information according to the name of the detection policy when the detection policy has a detection policy. Then, according to the table merging strategy in the merging strategy, the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
  • the device is a device corresponding to the above method, and all the implementations in the foregoing method embodiments are applicable to the embodiment of the device, and the same technical effects can be achieved.
  • the specific structure of the device is as follows:
  • the above merge module may specifically be a merge processor, a merge processor built-in default merge process flow, and a set of alternative common merge policy process flow; the "merging main program" is responsible for parsing all "merger policy" information contained in the system. For the table in the system that does not specify the "merging policy”, use the default process to merge. For the table that specifies the "merging policy”, use the processing flow corresponding to the "merging policy” to merge. It should not rely on the business logic of a specific application, but only deal with data merging from the perspective of the database;
  • the merge policy some tables can not be merged correctly through the default processing flow, the user needs to specify a special table merge strategy, so that the "merging processor" according to this table merge strategy for data merge; the syntax definition of the table merge strategy is also not It should rely on the business logic of a specific application software, but provide a table consolidation strategy that can be used by various application software.
  • Merging plug-ins the complexity of the business logic merge process of some tables exceeds the scope that the "merging main program” can handle, and the user needs to specify the “merging plug-in” corresponding to the table in the "merging policy" for "merging the main program”
  • the plugin is called to complete the merge work; the "merging plugin” is implemented by the user according to the standard interface defined by the merge device.
  • the contents of the database A and the database A' are merged, and the merging device takes the database A as the source database and the database A' as the destination database, and the combined final result is embodied in the destination database A'.
  • the "Merge Processor" has a default processing flow:
  • the first scenario the table a in the source database A has a table a corresponding to the destination database A', and the table structure is the same. In this case, all the records of the table a in the source database A are all added by default. Go to table a in destination database A';
  • the second scenario table a in source database A has a table a corresponding to it in destination database A', and the table structure is different (if the design is reasonable, the application should try to avoid this situation), this case
  • the default is to convert the structure of table a in source database A to be the same as the structure of table a in destination database A' (provided the application allows this conversion), and then merge in the first scenario.
  • the processing flow of the conversion table structure may be automatically processed by the merge processor according to the difference of the table information obtained in the database system table, or may be processed according to the merge policy configured by the user.
  • the third scenario the table a in the source database A has no corresponding table a in the destination database A'.
  • the merge processor creates a table with the same name and the same structure in the destination database A'. And then merge in the manner of (1) scene;
  • Table a in the destination database A' has no table a corresponding to it in the source database A. In this case, no merge is required by default.
  • the fourth scenario can be ignored, and the other three can be converted into the first scenario to be processed.
  • the default processing method of the first scenario is the simplest merge mode (this is also the way the database management system comes with the data migration tool), which cannot adapt to complex business logic. Therefore, users need to configure some "merging strategies" to The merger process intervenes.
  • Some tables do not need to participate in the merger. Some tables that hold initialization data must have the same data in each set of database content, and only need to retain one content in the destination database. Such tables should not be involved in the merger; for example, in the student registration information management system There is a table for storing the types of student cadres. When each system is installed, the database stage is automatically filled in with the records of all types of student cadres, and the table will not be added, deleted or modified during the system operation; Then, when merging the table records in the source database into the destination database, there will be two sets of duplicate records in the table, which will lead to business logic errors, so the table should not be merged.
  • Some tables only need to merge part of the content in the source database, not the entire content.
  • the system does not delete the records during the system operation. And modify the operation, but some user input cadre job category records may be added; when merging, the new records added by the user in the source database should be merged, and the records initialized during system installation should be merged; in more complicated cases If the initialization data of the table is also deleted and modified during the system operation, then in theory, all the records of the source database and the cadre position in the destination database should be merged into the destination database, and the cadre positions have the same name. The records should not be merged.
  • Some tables may violate data constraints when merging—such as primary key conflicts, violation of uniqueness constraints, etc. (table structure definitions or business logic constraints, can be considered as violations of data constraints).
  • data constraints such as primary key conflicts, violation of uniqueness constraints, etc.
  • the application logic of the application software is different, and the adopted strategy may be different; the user may choose to delete the source database. After the unconstrained records are merged, you can also choose to modify the records in the source database that violate the constraints before merging.
  • Some tables have parent-child dependencies—such as foreign key dependencies (table structure definitions or business logic dependencies, can be regarded as existential dependencies), and the related content of the dependent parent table is increased during the merge. Pruning operations - such as the (4) and (5) scenarios described above, then the dependent subtable should also be modified accordingly to continue to satisfy the original dependencies; in the (6) scenario For example, if you add a dependency to a foreign key, if the dependent column of the dependent parent table adds a fixed value to avoid the constraint conflict, the associated column of the dependent child table needs to be the same when merging. Fixed value.
  • Some databases or tables have sequential dependencies in the order of merging, and need to be assigned a priority level.
  • the merging device should perform the merging process of multiple tables in a concurrent manner. There is no order between those tables before and after; if some tables specify more If the priority is high, the merge should be performed first. After all the tables in the priority are merged, the merge process of the lower priority table can be performed.
  • Some tables use triggers, and it is necessary to decide whether to disable triggers depending on the business logic. For example, in some applications, the use of triggers and sequences to simulate the effect of self-incrementing columns (there is no concept of self-incrementing columns in Oracle), each time a record is inserted into the corresponding table, the trigger is automatically called.
  • the user needs to specify the merge policy definition corresponding to the specific table in the "Merge Policy". If there is no table specifying the merge policy, all the records of the table in the source database are all added to the destination database by default. Inside the table.
  • the above various application scenarios in most cases, can be implemented by executing the sql statement, for example, the detection process before the merge in the first scenario, usually only needs to perform some cross-database connection query to judge;
  • the source database and the destination database are not in the same database management system, it is difficult to implement the detection function by simply using the sql statement, and the user needs to implement a special "merging plug-in" to complete this function, which will increase the user's use of the merge.
  • the difficulty of the device therefore, in order to simplify the merging process, as far as possible, the user only needs to understand sql knowledge to complete most of the merging functions, and the source database and the destination database need to be integrated in the same database management system. Therefore, the merging device is The first steps in your work are:
  • the merging device creates a temporary mirror database in the database management system where the destination database is located, restores the source database to the temporary mirror database through the backup recovery function (or other data migration method), and then uses the temporary mirror database as the source database. . This allows the user to access both the source and destination databases in the sql statement.
  • the merging device summarizes the corresponding merging strategy and built its function into the “merging processor" for the user to use various configuration files.
  • merger strategies There are mainly the following merger strategies:
  • Database policy specify the name of the database that needs to participate in the consolidation. If there are multiple databases that need to be merged, you need to configure multiple database policies.
  • the strategy includes the following:
  • Priority level optional. If you do not specify a priority level, the default is the lowest level; because the merge of the database is finally converted into the merging of the child elements of the database, so the set value of the database priority will be inherited by its child elements. Sub-elements with higher priority are merged first, sub-elements with lower priority are merged, and sub-elements of the same priority can be merged concurrently.
  • ⁇ ! --level specifies the priority level. The higher the value, the higher the level. If not specified, the default is 0-->
  • Detection strategy can configure multiple detection strategies, including the following:
  • child node optional, can be configured with multiple child nodes, the agreement to return a certain value is the detection failure;
  • the merging device can use an algorithm to generate a unique string.
  • the merged plug-in name is the user-developed secondary development Class name.
  • 3 and 4 can be selected either, or they can exist at the same time. If any one fails, the detection fails.
  • the non-merging policy of the table which is a child node of the database policy, includes the following contents:
  • the modified content merge policy of the table which is a child node of the database policy, is set to modify the data to be merged during the merge process, and includes the following contents:
  • the priority level is optional. If you do not specify a priority level, the default is to inherit the priority of the parent node database. After the table with the highest priority is merged, the table with the lower priority level can be merged. For tables with foreign key dependencies, The "Merge Processor" is automatically recognized from the system table of the database management system, and then the priority is automatically set, without the user having to set the priority.
  • child node optional, can be configured with multiple child nodes, set to modify the table structure or data content in the source database or destination database (not only limited to modify the currently processed table, but also modify other associated dependency tables);
  • the "merging processor” can be identified from the system table of the database management system, so the user can automatically process even if the specific column name is not specified; in some scenarios, a column is not defined. Adding columns, but using sequence or other business logic algorithms to achieve similar auto-increment functions, the "merge processor” does not recognize this situation, so the user must specify the corresponding column name; if a sequence is used, it also needs Specify the sequence name. Based on these two pieces of information, the "Merge Processor” can use some algorithms to automatically modify the value of the column to avoid the constraint of violating the uniqueness of the self-incrementing column and synchronize the current value of the sequence;
  • 9 self-additional association foreign key sub-table name and column name is a child node of 7, optional, can be configured with multiple child nodes. If the table has an associated child table, and the parent-child relationship is maintained by the uniqueness of the parent table self-incrementing column, the corresponding child table name and column name need to be specified in the parent table policy, so that the merge main program is modifying the self table.
  • the foreign key column of the associated sub-table can be automatically modified when the column is added;
  • Trigger names that need to be disabled optional, child nodes, configurable multiple child nodes. Whether the specified trigger is disabled in the process of merging the current table according to the business logic is determined by the user, and the original state is restored after the merge is completed.
  • the apparatus of the present invention can implement a general flow of database content merging.
  • the overall merge process is completed by the merge main program; for tables that do not require special processing, the merge main program defaults the table records in the source database to the same name table in the destination database; for complex business logic that is not recognized by the merge main program
  • the table of data the developer specifies its merge strategy in the policy configuration file, and the merged main program merges the data according to its merge strategy; in most application scenarios, the developer only needs to configure some SQL statements in the policy configuration file.
  • the purpose of modifying the table data that cannot be directly merged can be achieved.
  • the developer can integrate the secondary development plug-in implemented by the code into the merge process; in addition, the merge device adopts the processing mechanism of the concurrent thread. , improve the processing speed of the merger.
  • a database content merging method and apparatus provided by an embodiment of the present invention have the following beneficial effects: a general flow of database content merging can be implemented.
  • the table records in the source database are appended to the table of the same name in the destination database by default by merging the main program; for the table containing the complex business logic data that is not recognized by the merge main program, by the policy configuration file Specify the corresponding merge strategy in the merged main program according to the merge strategy to merge the data; for most application scenarios, the developer only needs to configure some SQL statements in the policy configuration file to achieve the modification cannot be directly merged.
  • the purpose of the tabular data in the extremely complex application scenario, the developer can integrate the secondary development plug-in implemented by the encoding into the merge process; in addition, the present invention also adopts the processing mechanism of the concurrent thread to improve the processing of the merge. speed.

Abstract

Provided are a method and device for merging database contents. The method comprises: establishing a mirror database corresponding to a source database, what is contained in the mirror database being completely identical to that in the source database (11); and according to a merging policy corresponding to a source table in the mirror database, conducting table information merging on the source table of the mirror database and a destination table, which is required to be merged with the source table, in a destination database (12). By means of the provided solution, the problem of merging application programs with complicated service logic in the prior art is solved, and the capability for processing the merging of database contents is improved.

Description

一种数据库内容合并方法及装置Database content merging method and device 技术领域Technical field
本发明涉及计算机领域,尤其涉及一种数据库内容合并方法及装置。The present invention relates to the field of computers, and in particular, to a method and apparatus for merging database contents.
背景技术Background technique
随着计算机技术的发展,数据库在主流软件系统中的使用越来越普遍,尤其在某些应用场景中,需要将同一应用软件的两套独立的数据库内容合并为一套数据库内容进行管理。With the development of computer technology, the use of databases in mainstream software systems is becoming more and more common. Especially in some application scenarios, it is necessary to combine two sets of independent database contents of the same application software into one set of database contents for management.
对于数据库的合并,通常使用数据库管理系统自身提供的数据迁移工具来进行数据合并迁移。然而,由于该种数据迁移工具是通用化的工具,它只能处理简单的数据迁移逻辑,比如将数据库A中一个表格的数据追加到数据库B中的某一个表格中。For the consolidation of the database, the data migration tool provided by the database management system itself is usually used for data merge migration. However, since this data migration tool is a generalized tool, it can only handle simple data migration logic, such as appending data from a table in database A to a table in database B.
而对于具有复杂业务逻辑的应用程序来说,这种迁移工具往往无能为力,具有很大的局限性。所以,如何实现对于复杂业务逻辑的应用程序的合并问题,是有待解决的问题。For applications with complex business logic, this migration tool is often powerless and has many limitations. Therefore, how to implement the merging of applications for complex business logic is a problem to be solved.
发明内容Summary of the invention
本发明实施例提供了一种数据库内容合并方法及装置,以至少解决现有技术中对于复杂业务逻辑的应用程序的合并问题。Embodiments of the present invention provide a database content merging method and apparatus to at least solve the merging problem of an application for complex business logic in the prior art.
为了实现上述目的,本发明提供了一种数据库内容合并方法,包括:In order to achieve the above object, the present invention provides a database content merging method, including:
建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Establishing a mirror database corresponding to the source database, where the mirror database is the same as the source database;
根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。And according to the merging policy corresponding to the source table in the mirror database, the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
其中,所述建立源数据库对应的镜像数据库的步骤包括:The step of establishing a mirror database corresponding to the source database includes:
备份源数据库,得到携带有表格信息的备份文件;Back up the source database to get a backup file carrying the form information;
选取目的数据库所属的数据库管理系统; Select the database management system to which the destination database belongs;
在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。Establishing a mirror database corresponding to the source database in the database management system, and adding table information carried in the backup file to the mirror database.
其中,所述根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的步骤包括:The step of combining the source information of the mirror database with the destination table of the destination database that needs to be merged with the source table according to the merge policy corresponding to the source table in the mirror database includes: :
获取配置文件中的所述镜像数据库中的源表格对应的合并策略;Obtaining a merge policy corresponding to the source table in the mirror database in the configuration file;
当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。When there is a detection policy in the merge policy, according to the detection strategy, the sql statement and/or the merge plug-in is selected to detect whether the table in the mirror database and the destination database can be combined with the form information, and if the detection is successful, according to the merge policy The table merge strategy combines the source tables of the mirror database with the destination tables in the destination database that need to be merged with the source tables.
其中,根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的步骤包括:The step of combining the source table of the mirror database with the destination table of the destination database that needs to be merged with the source table according to the table merge policy in the merge policy includes:
获得镜像数据库中所有源表格的集合;Obtain a collection of all source tables in the mirror database;
建立源表格的集合中需要和目的数据库中的目的表格进行合并的表格与表格合并策略的对应关系;Establishing a correspondence between the table of the source table and the table merge policy that needs to be merged with the destination table in the destination database;
按优先级顺序对源表格和目的数据库中的目的表格进行表格信息合并。The table information is merged in the priority table in the source table and the destination table in the destination database.
其中,对源表格和目的数据库中的目的表格进行表格信息合并的步骤包括:The step of merging the form information on the source table and the destination table in the destination database includes:
获得源表格的集合中的源表格对应的表格合并策略;Obtaining a table merging strategy corresponding to the source table in the collection of source tables;
若所述表格合并策略为指定合并策略且指定合并策略类型为合并或者为修改策略,则判断目的数据库中是否存在与源表格同名的目的表格,若存在,则对源表格和与源表格同名的目的表格进行表格信息合并,否则,在目的数据库中创建与源表格同名的目的表格,再对源表格和目的表格进行表格信息合并。If the table merging strategy is a specified merging strategy and the specified merging strategy type is merging or modifying the policy, it is determined whether there is a destination table with the same name as the source table in the destination database, and if present, the source table and the same name as the source table The destination form merges the form information. Otherwise, a destination form with the same name as the source form is created in the destination database, and the form information is merged between the source form and the destination form.
其中,对源表格和目的表格进行表格信息合并的步骤包括:The steps of combining the form information of the source form and the destination form include:
判断源表格与目的表格的表结构是否一致,若是,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并,否则,将源表格的表结构转换为与目的表格的表结构一致后,再根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并。 Determining whether the table structure of the source table and the destination table are consistent, and if so, combining the table information with the source table and the destination table according to the specified merge policy of the source table; otherwise, converting the table structure of the source table to the table with the destination table After the structure is consistent, the form information is merged between the source table and the destination table according to the specified merge policy of the source table.
其中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:The step of merging the form information with the source table and the destination table according to the specified merging policy of the source table includes:
若所述源表格没有指定合并策略,获得源表格的记录总数;If the source table does not specify a merge policy, the total number of records of the source table is obtained;
若所述源表格的记录总数不为0,执行插入语句,将源表格中的所有记录插入到目的表格中。If the total number of records in the source table is not 0, an insert statement is executed to insert all the records in the source table into the destination table.
其中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:The step of merging the form information with the source table and the destination table according to the specified merging policy of the source table includes:
若所述源表格具有指定合并策略,则按指定合并策略对源表格进行修改,获得修改后的源表格的记录;If the source table has a specified merge policy, modify the source table according to the specified merge policy to obtain a record of the modified source table;
将该修改后的源表格的记录插入到目的表格中。Insert the record of the modified source table into the destination table.
其中,对源表格进行修改,获得修改后的源表格的记录的步骤包括:The steps of modifying the source table to obtain the record of the modified source table include:
对所述源表格中违反约束规则的记录或者主键冲突的记录进行修改或者删除,得到修改后的源表格的记录;或者Modifying or deleting the record in the source table that violates the constraint rule or the record of the primary key conflict, and obtains the record of the modified source table; or
对所述源表格中的自增列或者序列加上一个固定值,得到修改后的源表格的记录;或者Adding a fixed value to the self-incrementing column or sequence in the source table to obtain a record of the modified source table; or
对所述源表格存在外键依赖,在对依赖父表进行修改的情况下,对依赖子表也进行相关内容的修改,得到修改后的源表格的记录。There is a foreign key dependency on the source table, and in the case of modifying the dependent parent table, the dependent content table is also modified to obtain a record of the modified source table.
其中,将该修改后的源表格的记录插入到目的表格中的步骤包括:The step of inserting the record of the modified source table into the destination table includes:
若目的表格使用了触发器且目的表格没有被其它表依赖,则在目的表格中插入源表格的记录时,利用触发器自动生成记录的递增ID;否则,在目的表格中插入源表格的记录时,禁用所述触发器,在记录插入完成后,再恢复触发器为合并前的状态。If the destination table uses a trigger and the destination table is not dependent on other tables, the incremental ID of the record is automatically generated by the trigger when the record of the source table is inserted in the destination table; otherwise, when the record of the source table is inserted in the destination table , the trigger is disabled, and after the record insertion is completed, the trigger is restored to the state before the merge.
本发明的实施例还提供一种数据库内容合并装置,包括:An embodiment of the present invention further provides a database content merging device, including:
建立模块,设置为建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同; Establishing a module, configured to establish a mirror database corresponding to the source database, where the mirror database is the same as the source database;
合并模块,设置为根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。The merging module is configured to merge the source table of the mirror database with the destination table of the target database that needs to be merged with the source table according to a merging policy corresponding to the source table in the mirror database.
其中,建立模块包括:Among them, the building module includes:
备份子模块,设置为备份源数据库,得到携带有表格信息的备份文件;The backup sub-module is set as a backup source database to obtain a backup file carrying the form information;
连接子模块,设置为选取目的数据库所属的数据库管理系统;The connection submodule is set to select a database management system to which the destination database belongs;
建立子模块,设置为在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。And establishing a sub-module, configured to establish a mirror database corresponding to the source database in the database management system, and add table information carried in the backup file to the mirror database.
其中,合并模块包括:Among them, the merge module includes:
获取子模块,设置为获取配置文件中的所述镜像数据库中的源表格对应的合并策略;Obtaining a submodule, configured to obtain a merge policy corresponding to the source table in the mirror database in the configuration file;
合并子模块,设置为当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。The merging sub-module is set to use the sql statement and/or the merge plug-in to detect whether the table in the mirror database and the destination database can be combined with the table information according to the detection policy, and if the detection is successful, According to the table merging strategy in the merging strategy, the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
本发明的上述技术方案具有如下技术效果:The above technical solution of the present invention has the following technical effects:
通过采用本发明所述方法,可以实现通用的数据库内容合并的流程。对于无需特殊处理的表格,直接通过合并主程序默认将源数据库中的表格记录追加到目的数据库中的同名表格中;对于包含合并主程序无法识别的复杂业务逻辑数据的表格,由在策略配置文件中指定其对应的合并策略,合并主程序按照该合并策略来进行数据的合并;对于绝大多数的应用场景,开发人员只需在策略配置文件中配置一些sql语句即可达到修改无法直接合并的表格数据的目的,而在极端复杂的应用场景中,开发人员可以把自己编码实现的二次开发插件整合到合并流程中;另外,本发明还采用了并发线程的处理机制,提高了合并的处理速度。By adopting the method of the present invention, a general process of merging database contents can be realized. For tables that do not require special processing, the table records in the source database are appended to the table of the same name in the destination database by default by merging the main program; for the table containing the complex business logic data that is not recognized by the merge main program, by the policy configuration file Specify the corresponding merge strategy in the merged main program according to the merge strategy to merge the data; for most application scenarios, the developer only needs to configure some SQL statements in the policy configuration file to achieve the modification cannot be directly merged. The purpose of the tabular data, in the extremely complex application scenario, the developer can integrate the secondary development plug-in implemented by the encoding into the merge process; in addition, the present invention also adopts the processing mechanism of the concurrent thread to improve the processing of the merge. speed.
附图说明DRAWINGS
图1为本发明实施例所提供的数据库内容合并的方法流程图;FIG. 1 is a flowchart of a method for merging database contents according to an embodiment of the present invention;
图2为本发明实施例所提供的数据库内容合并的方法具体实施例流程图; 2 is a flowchart of a specific embodiment of a method for merging database content according to an embodiment of the present invention;
图3为本发明实施例所提供的数据库内容合并的方法中表格合并的流程图;3 is a flowchart of table merging in a method for merging database contents according to an embodiment of the present invention;
图4为本发明的实施例所提供的数据库内容合并的装置结构框图。FIG. 4 is a structural block diagram of an apparatus for merging database contents according to an embodiment of the present invention.
具体实施方式detailed description
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合附图对具体实施例进行详细描述。The specific embodiments are described in detail below with reference to the accompanying drawings.
如图1所示,本发明的实施例提供一种数据库内容合并方法,包括:As shown in FIG. 1, an embodiment of the present invention provides a database content merging method, including:
步骤11,建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Step 11: Establish a mirror database corresponding to the source database, where the mirror database is the same as the source database;
步骤12,根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。Step 12: According to the merging policy corresponding to the source table in the mirror database, merge the source table of the mirror database with the destination table in the destination database that needs to be merged with the source table, and merge the table information.
本发明的该实施例通过建立与源数据库完全相同的镜像数据库,并根据镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格与目的数据库中需要与所述源表格进行合并的目的表格进行表格信息合并;从而可以将同一应用软件的两套独立的数据库内容合并为一套数据库内容的方案,能适应各种复杂的业务逻辑。The embodiment of the present invention needs to merge with the source table in the source table and the destination database of the mirror database by establishing a mirror database identical to the source database and according to the merge policy corresponding to the source table in the mirror database. The purpose table is used to merge the form information; thus, the two sets of independent database contents of the same application software can be combined into a set of database content solutions, which can adapt to various complicated business logics.
在本发明的一具体实施例中,上述步骤11可以包括:In a specific embodiment of the present invention, the foregoing step 11 may include:
步骤111,备份源数据库,得到携带有表格信息的备份文件;Step 111: Backing up the source database to obtain a backup file carrying the form information;
步骤112,选取目的数据库所属的数据库管理系统;Step 112, selecting a database management system to which the destination database belongs;
步骤113,在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。Step 113: Establish a mirror database corresponding to the source database in the database management system, and add table information carried in the backup file to the mirror database.
本发明的该实施例中,在目的数据库所在的数据库管理系统中创建一个临时镜像数据库,通过备份恢复功能(或其他数据迁移方法),把源数据库恢复到该临时镜像数据库中,然后以这个临时镜像数据库作为源数据库。这样就能够让用户在sql语句中同时访问源和目的数据库。In this embodiment of the present invention, a temporary mirror database is created in the database management system where the destination database is located, and the source database is restored to the temporary mirror database through the backup recovery function (or other data migration method), and then the temporary database is restored. The mirror database is used as the source database. This allows the user to access both the source and destination databases in the sql statement.
在本发明的另一具体实施例中,上述步骤12具体可以包括:In another embodiment of the present invention, the foregoing step 12 may specifically include:
步骤121,获取配置文件中的所述镜像数据库中的源表格对应的合并策略; Step 121: Obtain a merge policy corresponding to the source table in the mirror database in the configuration file.
步骤122,当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。Step 122: When there is a detection policy in the merge policy, according to the detection policy, the sql statement and/or the merge plug-in is selected to detect whether the table in the mirror database and the destination database can be combined with the form information, and if the detection is successful, according to the The table merging strategy in the merging strategy merges the source table of the mirror database with the destination table in the destination database that needs to be merged with the source table.
本发明的该实施例中,为适应复杂的业务逻辑,所以还需要用户配置一些“合并策略”来对合并流程进行干预需要,合并过程中有的场景不需要进行合并,因此,需要在合并前进行检测,识别出一些无法合并的应用场景。比如在学生登记信息管理系统中,不允许出现身份证号码完全相同的两条及以上的学生记录,如果合并之前检测到待合并的两套数据库内容中包含这种冲突的情况,应该禁止进行后续的合并流程;又比如,两个待合并的数据库内容是由不同版本的应用软件所产生的,数据结构不兼容,也不应该进行合并。在合并前进行检测,根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格与目的数据库中需要与所述源表格进行合并的目的表格进行表格信息合并,可以提高业务处理效率。In this embodiment of the present invention, in order to adapt to complex business logic, the user needs to configure some “merging policies” to intervene in the merge process. Some scenarios in the merge process do not need to be merged. Therefore, before the merge, The detection is performed to identify some application scenarios that cannot be merged. For example, in the student registration information management system, two or more student records with the same identity card number are not allowed. If the two sets of database contents to be merged are detected before the merger, such conflicts should be prohibited. The merge process; for example, the contents of the two databases to be merged are generated by different versions of the application software, and the data structures are incompatible and should not be merged. Performing detection before merging, according to the table merging strategy in the merging strategy, merging the source table of the mirror database with the destination table of the destination database that needs to be merged with the source table, can improve service processing efficiency .
在上述的实施例中,步骤122中,根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的具体实现过程可以包括:In the foregoing embodiment, in step 122, according to the table merging policy in the merging policy, the source table of the mirror database and the destination table in the destination database that need to be merged with the source table are used to perform table information. The specific implementation process of the merger may include:
步骤1221,获得镜像数据库中所有源表格的集合;Step 1221: Obtain a set of all source tables in the mirror database.
步骤1222,建立源表格的集合中,需要和目的数据库中的目的表格进行合并的表格与表格合并策略的对应关系;Step 1222: Establish a correspondence between the table and the table merging strategy in the set of the source table that needs to be merged with the destination table in the destination database;
步骤1223,按优先级顺序对源表格和目的数据库中的目的表格进行表格信息合并。In step 1223, the form information is merged in the source table and the destination table in the destination database in order of priority.
该实施例的具体实现如图2所示,数据库内容合并流程整体包括:The specific implementation of this embodiment is shown in FIG. 2, and the database content merge process as a whole includes:
(1)备份需要参与合并的所有源数据库,得到其备份文件;(1) Backup all source databases that need to participate in the merge to get their backup files;
(2)指定目的数据库所在的数据库管理系统,以系统管理员(或其他满足操作权限的角色)的身份成功连接进去;(2) Specify the database management system where the destination database is located, and successfully connect as the system administrator (or other role that satisfies the operation authority);
(3)指定所有需要参与合并的源数据库的备份文件,自动为每个源数据库创建对应的临时镜像数据库,并恢复所有源数据库的内容;(3) Specify all backup files of the source database that need to participate in the merge, automatically create a corresponding temporary mirror database for each source database, and restore the contents of all source databases;
(4)解析配置文件中的所有合并策略; (4) Parse all merge policies in the configuration file;
(5)根据合并策略中的检测策略,执行合并前的检测工作,如果返回失败,则转到步骤(9),结束合并工作;如果返回成功,或者没有配置任何检测策略,则继续处理后续步骤;(5) Perform the pre-merger detection according to the detection strategy in the merge policy. If the return fails, go to step (9) to end the merge; if the return is successful, or if no detection policy is configured, continue with the subsequent steps. ;
(6)合并装置序获取所有待合并的源数据库中的所有表信息集合,再结合第(2)步中得到的所有合并策略,建立所有待合并表与合并策略的映射关系,这里的待合并表为:源表格的集合中,需要和目的数据库中的目的表格进行合并的表格,并按照合并策略中定义的优先级别排序;(6) The merge device sequence acquires all the table information sets in the source database to be merged, and combines all the merge policies obtained in step (2) to establish a mapping relationship between all the merged tables and the merge policy, where to be merged. The table is: in the collection of source tables, the tables that need to be merged with the destination table in the destination database, and sorted according to the priority level defined in the merge strategy;
(7)按照优先级别从高到低的先后顺序,并发处理同一优先级别的所有表格,待该优先级别的表格都处理完毕后,再处理优先级别更低的表格,直到所有表格处理完毕;(7) All forms of the same priority level are processed concurrently according to the order of priority from high to low. After the form of the priority level is processed, the table with lower priority is processed until all the forms are processed;
(8)合并装置删除创建的临时数据库;(8) The merged device deletes the created temporary database;
(9)合并工作结束。(9) The merger work is over.
在本发明的上述实施例中,对源表格和目的数据库中的目的表格进行表格信息合并的具体实现流程包括:In the above embodiment of the present invention, the specific implementation process for combining the form information in the source table and the destination table in the destination database includes:
步骤12231,获得源表格的集合中的源表格对应的表格合并策略;Step 12231: Obtain a table merging policy corresponding to the source table in the set of source tables;
步骤12232,若所述表格合并策略为指定合并策略且指定合并策略类型为合并或者为修改策略,则判断目的数据库中是否存在与源表格的集合中的源表格同名的目的表格,若存在,则对源表格和目的数据库中与源表格同名的目的表格进行表格信息合并,否则,在目的数据库中创建与源表格同名的目的表格,再对源表格和目的表格进行表格信息合并。Step 12232: If the table merge policy is a specified merge policy and the merge policy type is a merge or a modify policy, determine whether there is a destination table in the destination database having the same name as the source table in the set of the source table, if yes, Form information is merged between the source table and the destination database with the same name as the source table. Otherwise, a destination table with the same name as the source table is created in the destination database, and the table information is merged between the source table and the destination table.
进一步的步骤12232中,对源表格和目的表格进行表格信息合并的步骤包括:In a further step 12232, the step of merging the form information with the source form and the destination form includes:
判断源表格与目的表格的表结构是否一致,若是,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并,否则,将源表格的表结构转换为与目的表格的表结构一致后,再根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并。Determining whether the table structure of the source table and the destination table are consistent, and if so, combining the table information with the source table and the destination table according to the specified merge policy of the source table; otherwise, converting the table structure of the source table to the table with the destination table After the structure is consistent, the form information is merged between the source table and the destination table according to the specified merge policy of the source table.
进一步的,步骤12232中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:Further, in step 12232, according to the specified merge policy of the source table, the step of combining the form information with the source form and the destination form includes:
步骤122321,若所述源表格没有指定合并策略,获得源表格的记录总数;若所述源表格的记录总数不为0,执行插入语句,将源表格中的所有记录插入到目的表格中。 Step 122321: If the source table does not specify a merge policy, obtain the total number of records in the source table; if the total number of records in the source table is not 0, execute an insert statement to insert all the records in the source table into the destination table.
步骤122322,若所述源表格具有指定合并策略,则按指定合并策略对源表格进行修改,获得修改后的源表格的记录;将该修改后的源表格的记录插入到目的表格中。Step 122322: If the source table has a specified merge policy, modify the source table according to the specified merge policy to obtain a record of the modified source table; insert the record of the modified source table into the destination table.
步骤122322中,对源表格进行修改,获得修改后的源表格的记录的步骤包括:In step 122322, the step of modifying the source table to obtain the record of the modified source table includes:
对所述源表格中违反约束规则的记录或者主键冲突的记录进行修改或者删除,得到修改后的源表格的记录;或者Modifying or deleting the record in the source table that violates the constraint rule or the record of the primary key conflict, and obtains the record of the modified source table; or
对所述源表格中的自增列或者序列加上一个固定值,得到修改后的源表格的记录;或者Adding a fixed value to the self-incrementing column or sequence in the source table to obtain a record of the modified source table; or
对所述源表格存在外键依赖,在对依赖父表进行修改的情况下,对依赖子表也进行相关内容的修改,得到修改后的源表格的记录。There is a foreign key dependency on the source table, and in the case of modifying the dependent parent table, the dependent content table is also modified to obtain a record of the modified source table.
其中,将该修改后的源表格的记录插入到目的表格中的步骤包括:The step of inserting the record of the modified source table into the destination table includes:
若目的表格使用了触发器且目的表格没有被其它表依赖,则在目的表格中插入源表格的记录时,利用触发器自动生成记录的递增ID;否则,在目的表格中插入源表格的记录时,禁用所述触发器,在记录插入完成后,再恢复触发器为合并前的状态。If the destination table uses a trigger and the destination table is not dependent on other tables, the incremental ID of the record is automatically generated by the trigger when the record of the source table is inserted in the destination table; otherwise, when the record of the source table is inserted in the destination table , the trigger is disabled, and after the record insertion is completed, the trigger is restored to the state before the merge.
该表格的合并具体实现流程如图3所示,包括:The specific implementation process of the consolidation of the table is shown in Figure 3, including:
①查找该表对应的表格合并策略,如果指定了表格合并策略且策略类型为不合并策略,则该表合并流程在此结束,转到步骤⑧;如果该表没有指定表格合并策略,或者策略类型为修改策略,则继续后面的合并流程;1 Find the table merge policy corresponding to the table. If the table merge policy is specified and the policy type is not merged, the table merge process ends here, go to step 8; if the table does not specify a table merge policy, or the policy type To modify the strategy, continue the subsequent merge process;
②如果目的数据库中不存在同名表,则在其中创建相同结构的同名表格,并转到步骤④;2 If the same name table does not exist in the destination database, create the same name table with the same structure in it, and go to step 4;
③获取源数据库和目的数据库中该表的结构信息,比较表结构是否一致;如果一致,则转下一步骤;如果不一致,判断该表是否指定了表格合并策略,如果没有指定表格合并策略,或者指定了表格合并策略且设定由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,则合并装置自动转换源数据库中表结构,使其与目的数据库中的表结构一致;如果指定了合并策略且合并策略设定不由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,则不作任何处理,转下一步骤; 3 Obtain the structure information of the table in the source database and the destination database, and compare whether the table structure is consistent; if they are consistent, go to the next step; if they are inconsistent, determine whether the table specifies the table merge policy, if no table merge policy is specified, or Specifying the table merge strategy and setting the conversion process of the table structure in the source database and the destination database by the "merging processor", the merging device automatically converts the table structure in the source database to be consistent with the table structure in the destination database. If the merge policy is specified and the merge policy is not set by the "merge processor" to complete the conversion process of the table structure in the source database and the destination database, then no processing is performed, and the next step is performed;
④如果该表没有指定表格合并策略,则获取源数据库该表的记录总数,如果记录总数为0,则转到步骤⑧结束该表的合并流程,否则转到步骤⑥进行表记录的追加合并;4 If the table does not specify a table merge policy, the total number of records in the source database is obtained. If the total number of records is 0, then go to step 8 to end the merge process of the table, otherwise go to step 6 to perform additional merge of the table records;
⑤如果该表指定了合并策略,则合并装置按照该策略执行一系列修改数据库内容的步骤;如果合并策略设定不由“合并处理器”来完成修改后数据的合并流程,则转到步骤⑦,否则继续后面的步骤;5 If the table specifies a merge policy, the merging device performs a series of steps of modifying the contents of the database according to the policy; if the merge policy is not set by the "merging processor" to complete the merge process of the modified data, then go to step 7, Otherwise continue the next steps;
⑥执行insert语句,将源数据库中该表的所有记录追加插入到目的数据库中的同名表中;6 Execute the insert statement to insert all the records of the table in the source database into the table of the same name in the destination database;
⑦如果该表指定了合并策略,且该策略设定禁用了某些触发器,则恢复目的数据库中的触发器为合并前的状态;7 If the table specifies a merge policy and the policy setting disables certain triggers, the triggers in the recovery destination database are in the pre-merge state;
⑧该表合并流程结束。8 The table merge process ends.
上述流程中,具体的,表的修改内容合并策略,为数据库策略的子节点,设置为在合并过程中修改待合并数据,包含以下内容:In the above process, specifically, the modified content merge policy of the table is a child node of the database policy, and is set to modify the data to be merged in the merge process, and includes the following contents:
①表名称,指定该策略对应的具体表;1 table name, specifying the specific table corresponding to the policy;
②策略类型,为“修改”类型;2 strategy type, which is the "modification" type;
③优先级别,可选,如果不指定优先级别,默认为继承父节点数据库的优先级别,优先级别高的表合并完成后,才能合并优先级别低的表。对于有外键依赖关系的表,“合并处理器”从数据库管理系统的系统表中可以自动识别出来,然后自动设置优先级,可以不需要用户进行优先级设置。The priority level is optional. If you do not specify a priority level, the default is to inherit the priority of the parent node database. After the table with the highest priority is merged, the table with the lower priority level can be merged. For tables with foreign key dependencies, the "Merge Processor" can be automatically identified from the system table of the database management system, and then the priority is automatically set, without the user having to set the priority.
④sql语句,子节点,可选,可配置多个子节点,设置为修改源数据库或目的数据库中的表结构或数据内容(不仅仅局限于修改当前处理的表,也可以修改其他关联依赖表);4sql statement, child node, optional, can be configured with multiple child nodes, set to modify the table structure or data content in the source database or destination database (not only limited to modify the currently processed table, but also modify other associated dependency tables);
⑤合并插件名称,子节点,可选,可配置多个子节点,设置为合并之前在sql语句无法处理的复杂业务逻辑的情况下,供合并主程序调用用户实现的二次开发合并插件进行处理;5 merge plug-in name, sub-node, optional, configurable multiple sub-nodes, set to the complex business logic that can not be processed by the sql statement before the merge, the secondary development merge plug-in for the merge main program call user to handle;
⑥是否由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,子节点,可选。默认为“是”,在源数据库和目的数据库中该表结构不一致时,由“合并处理器”来转换源数据库中表的结构,使之与目的数据库中表的结构相同;如 果为“否”的话,表示该转换由用户配置的sql语句或“合并插件”来完成,“合并处理器”不参与转换流程。6 Whether the "consolidation processor" is used to complete the conversion process of the table structure in the source database and the destination database, child nodes, optional. The default is "Yes". When the table structure is inconsistent in the source database and the destination database, the "merge processor" is used to convert the structure of the table in the source database to be the same as the structure of the table in the destination database; If it is "No", it means that the conversion is completed by the user-configured sql statement or "merging plug-in", and the "merging processor" does not participate in the conversion process.
⑦是否由“合并处理器”来完成修改后数据的合并流程,子节点,可选,默认为“是”,表示在“合并处理器”执行一系列用户配置的sql或“合并插件”来修改待合并数据之后,“合并处理器”最终将源数据库中的表内容简单追加到目的数据库的同名表中;如果配置为“否”,表示该表的合并过程已经在用户配置的sql或“合并插件”中完成,不再需要“合并处理器”参与,对于某些复杂的业务逻辑,不能通过简单追加的方式进行合并,则此时可以通过此方式屏蔽掉“合并处理器”的流程,完全由用户来主导某些表的合并流程;7 Whether the merge process of the modified data is completed by the "Merge Processor", the child node is optional, and the default is "Yes", which means that the "Merge Processor" executes a series of user-configured sql or "Merge Plugin" to modify After the data is to be merged, the "Merge Processor" finally simply appends the contents of the table in the source database to the table of the same name in the destination database; if the configuration is "No", it indicates that the merge process of the table has been configured in the user's SQL or "Merge" The "plug-in" is completed, and the "merging processor" is no longer required to participate. For some complex business logics, the merge process cannot be merged by simple appending. In this case, the process of "merging the processor" can be masked in this way, completely The user merges the process of merging certain tables;
⑧自增列及其对应序列名称,指定当前表中哪个列为自增列,子节点,可选。物理定义上的自增列,“合并处理器”可以从数据库管理系统的系统表中查询识别出来,所以用户即使不指定其具体列名称,也能自动处理;有些场景下,某列虽然没有定义成自增列,但是其使用序列或其他业务逻辑算法来实现类似的自增功能,“合并处理器”无法识别这种情况,因此必须由用户来指定对应列名称;如果使用了序列,还需要指定序列名称,“合并处理器”根据这两个个信息就能采用某些算法来自动修改该列的值,以避免违反自增列唯一性的约束,并同步序列的当前值;8 self-incrementing column and its corresponding sequence name, specify which column in the current table is an auto-increment column, child node, optional. The self-addition column on the physical definition, the "merging processor" can be identified from the system table of the database management system, so the user can automatically process even if the specific column name is not specified; in some scenarios, a column is not defined. Adding columns, but using sequence or other business logic algorithms to achieve similar auto-increment functions, the "merge processor" does not recognize this situation, so the user must specify the corresponding column name; if a sequence is used, it also needs Specify the sequence name. Based on these two pieces of information, the "Merge Processor" can use some algorithms to automatically modify the value of the column to avoid the constraint of violating the uniqueness of the self-incrementing column and synchronize the current value of the sequence;
⑨自增列关联外键子表名称及列名称,为⑦的子节点,可选,可配置多个子节点。如果该表还有关联子表,通过父表自增列的唯一性来维护父子关系,则需要在父表策略中指定对应的子表名称和列名称,这样合并主程序在修改主表的自增列时能够自动修改关联子表的外键列;9 self-additional association foreign key sub-table name and column name, is a child node of 7, optional, can be configured with multiple child nodes. If the table has an associated child table, and the parent-child relationship is maintained by the uniqueness of the parent table self-incrementing column, the corresponding child table name and column name need to be specified in the parent table policy, so that the merge main program is modifying the self table. The foreign key column of the associated sub-table can be automatically modified when the column is added;
⑩需要禁用的触发器名称,可选,子节点,可配置多个子节点。由用户根据业务逻辑决定合并当前表的过程中是否禁用指定触发器,合并完成后恢复其原有状态。10 Trigger names that need to be disabled, optional, child nodes, configurable multiple child nodes. Whether the specified trigger is disabled in the process of merging the current table according to the business logic is determined by the user, and the original state is restored after the merge is completed.
此策略适用面较广,针对本文上面所述的需要特殊处理的场景(3)、(4)、(5)、(6)、(7)、(8)、(9)。下面给出一个xml配置的例子:This strategy is applicable to a wide range of scenarios (3), (4), (5), (6), (7), (8), (9) that require special handling as described above. An example of an xml configuration is given below:
Figure PCTCN2014090271-appb-000001
Figure PCTCN2014090271-appb-000001
Figure PCTCN2014090271-appb-000002
Figure PCTCN2014090271-appb-000002
采用本发明所述方法,通过在源数据库所在的数据库管理系统中,对所有需要参与合并的数据库进行备份。设置连接目的数据库所在数据库管理系统的参数,以系统管理员身份登录进去。指定源数据库的备份文件路径,在目的数据库所在的数据库管理系统中,为每个源数据库创建临时数据库并恢复。解析策略配置文件。按照默认处理流程以及用户指定的合并策略并发合并完所有表。还原在合并过程中禁用的触发器状态。删除临时数据库。可以实现通用的数据库内容合并的流程。整体的合并流程由合并主程序来完成;对于无需特殊处理的表格,合并主程序默认将源数据库中的表记 录追加到目的数据库中的同名表中;对于包含合并主程序无法识别的复杂业务逻辑数据的表格,由开发人员在策略配置文件中指定其合并策略,合并主程序按照其合并策略来进行数据的合并;绝大多数应用场景中,开发人员只需在策略配置文件中配置一些sql语句即可达到修改无法直接合并的表数据的目的,在极端复杂的应用场景中,开发人员可以把自己编码实现的二次开发插件整合到合并流程中;另外,合并装置采用了并发线程的处理机制,提高合并的处理速度。With the method of the present invention, all databases that need to participate in the merge are backed up in the database management system where the source database is located. Set the parameters of the database management system where the destination database is connected, and log in as the system administrator. Specify the backup file path of the source database. In the database management system where the destination database is located, create a temporary database for each source database and restore it. Parse the policy configuration file. All tables are merged concurrently according to the default processing flow and the user-specified merge policy. Restores the trigger state that was disabled during the merge process. Delete the temporary database. A common process for merging database content can be implemented. The overall merge process is completed by the merge main program; for tables that do not require special processing, the merge main program defaults the records in the source database. Append to the table of the same name in the destination database; for the table containing the complex business logic data that the merge main program cannot recognize, the developer specifies the merge policy in the policy configuration file, and the merge main program performs the data according to the merge strategy. Consolidation; in most application scenarios, developers only need to configure some SQL statements in the policy configuration file to modify the table data that cannot be directly merged. In extremely complex application scenarios, developers can implement their own coding. The secondary development plug-in is integrated into the merge process; in addition, the merge device uses the processing mechanism of the concurrent thread to improve the processing speed of the merge.
本发明的实施例还提供一种数据库内容合并装置,包括:An embodiment of the present invention further provides a database content merging device, including:
建立模块,设置为建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Establishing a module, configured to establish a mirror database corresponding to the source database, where the mirror database is the same as the source database;
合并模块,设置为根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。The merging module is configured to merge the source table of the mirror database with the destination table of the target database that needs to be merged with the source table according to a merging policy corresponding to the source table in the mirror database.
其中,建立模块包括:Among them, the building module includes:
备份子模块,设置为备份源数据库,得到携带有表格信息的备份文件;The backup sub-module is set as a backup source database to obtain a backup file carrying the form information;
连接子模块,设置为选取目的数据库所属的数据库管理系统;The connection submodule is set to select a database management system to which the destination database belongs;
建立子模块,设置为在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。And establishing a sub-module, configured to establish a mirror database corresponding to the source database in the database management system, and add table information carried in the backup file to the mirror database.
其中,合并模块包括:Among them, the merge module includes:
获取子模块,设置为获取配置文件中的所述镜像数据库中的源表格对应的合并策略;Obtaining a submodule, configured to obtain a merge policy corresponding to the source table in the mirror database in the configuration file;
合并子模块,设置为当合并策略中有检测策略时,根据所述检测策略的名称,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。The merging sub-module is set to use the sql statement and/or the merge plug-in to detect whether the table in the mirror database and the destination database can be merged with the form information according to the name of the detection policy when the detection policy has a detection policy. Then, according to the table merging strategy in the merging strategy, the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
该装置是与上述方法对应的装置,上述方法实施例中的所有实现方式均适用于该装置的实施例中,也能达到相同的技术效果。The device is a device corresponding to the above method, and all the implementations in the foregoing method embodiments are applicable to the embodiment of the device, and the same technical effects can be achieved.
具体的,如图4所示,该装置的具体构架如下: Specifically, as shown in FIG. 4, the specific structure of the device is as follows:
上述的合并模块具体可以是合并处理器,合并处理器内置默认的合并处理流程,以及一套备选通用的合并策略处理流程;“合并主程序”负责解析系统中包含的所有“合并策略”信息,对于系统中没有指定“合并策略”的表,使用默认流程进行合并,对于指定了“合并策略”的表,使用该“合并策略”对应的处理流程进行合并。它不应该依赖具体某一个应用软件的业务逻辑,而只是仅仅从数据库的角度来处理数据合并;The above merge module may specifically be a merge processor, a merge processor built-in default merge process flow, and a set of alternative common merge policy process flow; the "merging main program" is responsible for parsing all "merger policy" information contained in the system. For the table in the system that does not specify the "merging policy", use the default process to merge. For the table that specifies the "merging policy", use the processing flow corresponding to the "merging policy" to merge. It should not rely on the business logic of a specific application, but only deal with data merging from the perspective of the database;
合并策略,某些表无法通过默认处理流程正确的进行合并,则需要用户指定特殊的表格合并策略,使“合并处理器”按照此表格合并策略来进行数据合并;表格合并策略的语法定义同样不应该依赖具体某一个应用软件的业务逻辑,而是提供各种应用软件可以通用的表格合并策略。The merge policy, some tables can not be merged correctly through the default processing flow, the user needs to specify a special table merge strategy, so that the "merging processor" according to this table merge strategy for data merge; the syntax definition of the table merge strategy is also not It should rely on the business logic of a specific application software, but provide a table consolidation strategy that can be used by various application software.
合并插件,某些表的业务逻辑合并流程的复杂程度超出了“合并主程序”能够处理的范围,需要用户在“合并策略”中指定该表对应的“合并插件”,供“合并主程序”调用该插件来完成合并工作;“合并插件”由用户按照合并装置定义的标准接口来实现。Merging plug-ins, the complexity of the business logic merge process of some tables exceeds the scope that the "merging main program" can handle, and the user needs to specify the "merging plug-in" corresponding to the table in the "merging policy" for "merging the main program" The plugin is called to complete the merge work; the "merging plugin" is implemented by the user according to the standard interface defined by the merge device.
例如,合并数据库A和数据库A'的内容,合并装置以数据库A为源数据库,以数据库A'为目的数据库,合并后的最终结果体现在目的数据库A'上。针对以下几种场景,“合并处理器“有默认的处理流程:For example, the contents of the database A and the database A' are merged, and the merging device takes the database A as the source database and the database A' as the destination database, and the combined final result is embodied in the destination database A'. For the following scenarios, the "Merge Processor" has a default processing flow:
第一种场景:源数据库A中的表a,在目的数据库A'中有与之对应的表a,且表结构相同,这种情况下,默认将源数据库A中表a的所有记录全部追加到目的数据库A'中的表a里面;The first scenario: the table a in the source database A has a table a corresponding to the destination database A', and the table structure is the same. In this case, all the records of the table a in the source database A are all added by default. Go to table a in destination database A';
第二种场景:源数据库A中的表a,在目的数据库A'中有与之对应的表a,且表结构不相同(如果设计合理,应用程序应该尽量避免出现此情况),这种情况下,默认需要转换源数据库A中表a的结构,使之与目的数据库A'中表a的结构相同(前提条件是应用程序允许这种转换),然后再以第一种场景的方式进行合并;转换表结构的处理流程,可以由合并处理器按照数据库系统表中获取的表信息的差异来自动处理,也可以根据用户配置的合并策略来处理。The second scenario: table a in source database A has a table a corresponding to it in destination database A', and the table structure is different (if the design is reasonable, the application should try to avoid this situation), this case Next, the default is to convert the structure of table a in source database A to be the same as the structure of table a in destination database A' (provided the application allows this conversion), and then merge in the first scenario. The processing flow of the conversion table structure may be automatically processed by the merge processor according to the difference of the table information obtained in the database system table, or may be processed according to the merge policy configured by the user.
第三种场景:源数据库A中的表a,在目的数据库A'中没有与之对应的表a,这种情况下,合并处理器在目的数据库A'中创建与之同名且结构相同的表,之后再以第(1)种场景的方式进行合并;The third scenario: the table a in the source database A has no corresponding table a in the destination database A'. In this case, the merge processor creates a table with the same name and the same structure in the destination database A'. And then merge in the manner of (1) scene;
第四种场景:目的数据库A'中的表a,在源数据库A中没有与之对应的表a,这种情况下,默认无需进行任何合并。 The fourth scenario: Table a in the destination database A' has no table a corresponding to it in the source database A. In this case, no merge is required by default.
可以看出,上面四种场景,第四种场景可以忽略掉,其他三种都可以转化为第一种场景来处理。但是第一种场景默认的处理方式是最简单的合并方式(这也是数据库管理系统自带数据迁移工具的处理方式),无法适应复杂的业务逻辑,所以还需要用户配置一些“合并策略”来对合并流程进行干预。It can be seen that in the above four scenarios, the fourth scenario can be ignored, and the other three can be converted into the first scenario to be processed. However, the default processing method of the first scenario is the simplest merge mode (this is also the way the database management system comes with the data migration tool), which cannot adapt to complex business logic. Therefore, users need to configure some "merging strategies" to The merger process intervenes.
合并过程中需要指定“合并策略”的特殊合并流程的场景大致有以下几种:There are several scenarios for the special merge process that needs to specify the merge policy during the merge process:
(1)合并前需要先进行检测,识别出一些无法合并的应用场景。比如在学生登记信息管理系统中,不允许出现身份证号码完全相同的两条及以上的学生记录,如果合并之前检测到待合并的两套数据库内容中包含这种冲突的情况,应该禁止进行后续的合并流程;又比如,两个待合并的数据库内容是由不同版本的应用软件所产生的,数据结构不兼容,也不应该进行合并。(1) Before the merge, it is necessary to detect and identify some application scenarios that cannot be merged. For example, in the student registration information management system, two or more student records with the same identity card number are not allowed. If the two sets of database contents to be merged are detected before the merger, such conflicts should be prohibited. The merge process; for example, the contents of the two databases to be merged are generated by different versions of the application software, and the data structures are incompatible and should not be merged.
(2)有些表不需要参与合并。一些保存初始化数据的表,在每套数据库内容中都必然存在相同的数据,而且只需要保留目的数据库中的一份内容即可,这类表不应该参与合并;比如,学生登记信息管理系统中有一个用于保存学生干部职位种类的表,在每个系统安装时,初始化数据库阶段就自动填入了所有学生干部职位种类的记录,系统运行期间也不会再对该表进行增删改操作;那么在合并时,如果把源数据库中该表记录合并到目的数据库中,会导致该表中存在两套重复的记录,进而导致业务逻辑错误,因此不应该合并该表。(2) Some tables do not need to participate in the merger. Some tables that hold initialization data must have the same data in each set of database content, and only need to retain one content in the destination database. Such tables should not be involved in the merger; for example, in the student registration information management system There is a table for storing the types of student cadres. When each system is installed, the database stage is automatically filled in with the records of all types of student cadres, and the table will not be added, deleted or modified during the system operation; Then, when merging the table records in the source database into the destination database, there will be two sets of duplicate records in the table, which will lead to business logic errors, so the table should not be merged.
(3)有些表在源数据库中的定义与目的数据库中的定义不一致,需要转换成一致后,再进行合并。(3) The definitions of some tables in the source database are inconsistent with the definitions in the destination database, and need to be converted to be consistent before being merged.
(4)有些表只需要合并源数据库中的部分内容,而不是全部内容。同样以学生登记信息管理系统中用于保存学生干部职位种类的表为例,如果该表中有一部分记录是在系统安装初始化数据库时自动填入的,系统运行期间不会对这部分记录做删除和修改操作,但是可能会新增一些用户输入的干部职位种类记录;在合并时,应该合并源数据库中用户新增的记录,而不应该合并系统安装时初始化的记录;在更复杂的情况下,如果系统运行期间对该表的初始化数据也会做删除和修改操作,那么理论上应该把所有源数据库与目的数据库中干部职位名称不相同的记录都合并到目的数据库中,而干部职位名称相同的记录不应该合并。(4) Some tables only need to merge part of the content in the source database, not the entire content. For example, in the table of the student registration information management system for storing the types of student cadres, if some records in the table are automatically filled in when the system is installed, the system does not delete the records during the system operation. And modify the operation, but some user input cadre job category records may be added; when merging, the new records added by the user in the source database should be merged, and the records initialized during system installation should be merged; in more complicated cases If the initialization data of the table is also deleted and modified during the system operation, then in theory, all the records of the source database and the cadre position in the destination database should be merged into the destination database, and the cadre positions have the same name. The records should not be merged.
(5)有些表在合并时可能违反数据约束——比如主键冲突、违反唯一性约束等(表结构定义或业务逻辑上的约束,都可以看做违反数据约束)。对于违反数据约束的记录,应用软件的业务逻辑不同,采取的策略也可能不同;用户可以选择删除源数据库中违 反约束的记录后再进行合并,也可以选择修改源数据库中违反约束的记录后再进行合并。(5) Some tables may violate data constraints when merging—such as primary key conflicts, violation of uniqueness constraints, etc. (table structure definitions or business logic constraints, can be considered as violations of data constraints). For records that violate data constraints, the application logic of the application software is different, and the adopted strategy may be different; the user may choose to delete the source database. After the unconstrained records are merged, you can also choose to modify the records in the source database that violate the constraints before merging.
(6)有些表使用了自增列(或序列),合并时可能存在冲突的ID。可以将源数据库中的自增列(或使用序列的列)统一加上一个固定值,就可以消除冲突的ID,然后再进行合并操作;这个固定值的获取,可以采用此算法:固定值=目的数据库中该列最大值+1-源数据库中该列最小值;对于自增列,在合并记录时应该开启自增列插入特性,这样才可保留插入记录的ID值;对于序列,因为其不会自动与表记录同步,所以还应该调整目的数据库中序列的当前值,也加上相同的固定值。(6) Some tables use self-incrementing columns (or sequences), and there may be conflicting IDs when merging. You can eliminate the conflicting ID by adding a fixed value to the self-incrementing column in the source database (or the column using the sequence), and then perform the merge operation; this fixed value can be obtained by using this algorithm: fixed value = The maximum value of the column in the destination database is +1 - the minimum value of the column in the source database; for the self-incrementing column, the self-incrementing column insertion feature should be turned on when merging records, so that the ID value of the inserted record can be retained; It is not automatically synchronized with the table record, so you should also adjust the current value of the sequence in the destination database, plus the same fixed value.
(7)有些表存在父子依赖关系——比如外键依赖等(表结构定义或业务逻辑上的依赖,都可以看做存在依赖关系),且被依赖父表的相关内容在合并时做了增删改操作——比如前面所述的第(4)种和第(5)种场景,那么依赖子表也应该做相应的修改,以便继续满足原有的依赖关系;以第(6)种场景中自增列为外键的依赖关系为例,如果被依赖父表的自增列在合并时加上了一个避免约束冲突的固定值,那么依赖子表的关联列在合并时也需要加上相同的固定值。(7) Some tables have parent-child dependencies—such as foreign key dependencies (table structure definitions or business logic dependencies, can be regarded as existential dependencies), and the related content of the dependent parent table is increased during the merge. Pruning operations - such as the (4) and (5) scenarios described above, then the dependent subtable should also be modified accordingly to continue to satisfy the original dependencies; in the (6) scenario For example, if you add a dependency to a foreign key, if the dependent column of the dependent parent table adds a fixed value to avoid the constraint conflict, the associated column of the dependent child table needs to be the same when merging. Fixed value.
(8)有些数据库或表在合并顺序上存在先后依赖关系,需要对其指定一个优先级别。默认情况下,为了提高合并的速度,对于同一优先级别的表,合并装置应该以并发方式进行多表的合并处理,这些表之间不存在谁先谁后的顺序;如果某些表指定了更高的优先级,则应该先进行合并,待该优先级下所有表格合并完毕后,才能进行优先级更低的表的合并流程。(8) Some databases or tables have sequential dependencies in the order of merging, and need to be assigned a priority level. By default, in order to increase the speed of merging, for the same priority level table, the merging device should perform the merging process of multiple tables in a concurrent manner. There is no order between those tables before and after; if some tables specify more If the priority is high, the merge should be performed first. After all the tables in the priority are merged, the merge process of the lower priority table can be performed.
(9)有些表使用了触发器,需要根据业务逻辑的不同来决定是否禁用触发器。比如,在有的应用软件中,使用触发器加序列的方式来模拟自增列的效果(oracle中没有自增列的概念),往对应表中每插入一条记录,就会自动调用触发器的逻辑,修改其ID为序列的递增整数;在合并该表时,如果该表没有被其他表依赖,则可以放心使用目的数据库中触发器的功能来自动为合并的记录生成递增ID;如果该表被其他表依赖,则推荐暂时禁用目的数据库中的触发器,而是使用第(6)种场景中描述的方式来合并记录,合并完毕后再还原目的数据库中的触发器状态,这么做的好处是在合并依赖子表时,只需要简单对依赖子表的关联列加上相同的固定值即可,效率更高,处理流程也更简单。(9) Some tables use triggers, and it is necessary to decide whether to disable triggers depending on the business logic. For example, in some applications, the use of triggers and sequences to simulate the effect of self-incrementing columns (there is no concept of self-incrementing columns in Oracle), each time a record is inserted into the corresponding table, the trigger is automatically called. Logic, modify the incrementing integer whose ID is a sequence; when merging the table, if the table is not dependent on other tables, you can safely use the function of the trigger in the destination database to automatically generate an incremental ID for the merged record; if the table Dependent on other tables, it is recommended to temporarily disable the trigger in the destination database, but use the method described in the (6) scenario to merge the records, and then restore the trigger state in the destination database after the merge, the benefits of doing so When merging dependent subtables, you only need to add the same fixed value to the associated columns of dependent subtables, which is more efficient and the processing flow is simpler.
(10)有些表在源数据库和目的数据库中定义的结构不一致,且合并处理器的默认转换源数据库表结构的流程无法适应业务逻辑,需要用户自己实现转换流程。 (10) Some tables have inconsistent structures defined in the source database and the destination database, and the process of the default conversion source database table structure of the merge processor cannot adapt to the business logic, and the user needs to implement the conversion process by himself.
针对上诉几种合并的特殊处理场景,需要用户在“合并策略”中指明具体表对应的合并策略定义,没有指定合并策略的表,则默认将源数据库中表的所有记录全部追加到目的数据库中的表里面。For the special processing scenarios of several combinations of appeals, the user needs to specify the merge policy definition corresponding to the specific table in the "Merge Policy". If there is no table specifying the merge policy, all the records of the table in the source database are all added to the destination database by default. Inside the table.
另外,上面各种应用场景,绝大多数情况下,通过执行sql语句就能够实现,比如第一种场景下进行合并前的检测过程,通常只需要执行一些跨库的连接查询即可判断出来;但是如果源数据库和目的数据库不在同一个数据库管理系统中,则单纯使用sql语句很难实现该检测功能,还需要用户去实现专门的“合并插件”来完成此功能,这样就会增加用户使用合并装置的难度;因此,为了简化合并过程,尽量使用户只需要了解sql知识就能完成大多数合并功能,就需要将源数据库和目的数据库整合在同一个数据库管理系统中,因此,本合并装置在工作时的首要步骤即为:In addition, the above various application scenarios, in most cases, can be implemented by executing the sql statement, for example, the detection process before the merge in the first scenario, usually only needs to perform some cross-database connection query to judge; However, if the source database and the destination database are not in the same database management system, it is difficult to implement the detection function by simply using the sql statement, and the user needs to implement a special "merging plug-in" to complete this function, which will increase the user's use of the merge. The difficulty of the device; therefore, in order to simplify the merging process, as far as possible, the user only needs to understand sql knowledge to complete most of the merging functions, and the source database and the destination database need to be integrated in the same database management system. Therefore, the merging device is The first steps in your work are:
合并装置在目的数据库所在的数据库管理系统中创建一个临时镜像数据库,通过备份恢复功能(或其他数据迁移方法),把源数据库恢复到该临时镜像数据库中,然后以这个临时镜像数据库做为源数据库。这样就能够让用户在sql语句中同时访问源和目的数据库。The merging device creates a temporary mirror database in the database management system where the destination database is located, restores the source database to the temporary mirror database through the backup recovery function (or other data migration method), and then uses the temporary mirror database as the source database. . This allows the user to access both the source and destination databases in the sql statement.
针对上面所述的几种需要指定“合并策略”的特殊合并流程的场景,本合并装置总结出对应的合并策略,并将其功能内置在“合并处理器”中,供用户以各种配置文件为载体来设定某些特殊表的“合并策略”。主要有以下几种合并策略:For the scenario of the special merge process that needs to specify the "merging policy" described above, the merging device summarizes the corresponding merging strategy and built its function into the "merging processor" for the user to use various configuration files. Set the "merging strategy" for some special tables for the carrier. There are mainly the following merger strategies:
(1)数据库策略,指定需要参与合并的数据库名称,如果有多个数据库需要进行合并,则需要配置多条数据库策略。该策略包含以下内容:(1) Database policy, specify the name of the database that needs to participate in the consolidation. If there are multiple databases that need to be merged, you need to configure multiple database policies. The strategy includes the following:
①源数据库名称;1 source database name;
②目的数据库名称;2 destination database name;
③优先级别,可选,如果不指定优先级别,默认为最低级别;因为数据库的合并最后都要转化为数据库的子元素的合并,因此数据库优先级的设定值,会被其子元素继承,优先级高的子元素先合并,优先级低的子元素后合并,相同优先级的子元素可以并发进行合并。3 Priority level, optional. If you do not specify a priority level, the default is the lowest level; because the merge of the database is finally converted into the merging of the child elements of the database, so the set value of the database priority will be inherited by its child elements. Sub-elements with higher priority are merged first, sub-elements with lower priority are merged, and sub-elements of the same priority can be merged concurrently.
下面给出一个xml配置的例子:An example of an xml configuration is given below:
<!--数据库策略:指定需要参与合并的源和目的数据库名称—><! --Database policy: Specify the source and destination database names that need to participate in the merge—>
<database source=”db1”destination="db1"> <database source=”db1”destination="db1">
</database></database>
<!--level指定优先级别,值越大级别越高,不指定则默认为0--><! --level specifies the priority level. The higher the value, the higher the level. If not specified, the default is 0-->
<database source=”db2”destination="db2"level="1"><database source=”db2”destination="db2"level="1">
</database></database>
(2)检测策略,可选,可配置多个检测策略,包含以下内容:(2) Detection strategy, optional, can configure multiple detection strategies, including the following:
①策略名称,可选;有些“合并插件”可能需要识别这个名称,根据该名称的不同来实现不同的处理流程;1 policy name, optional; some "merging plug-ins" may need to identify this name, according to the different names to achieve different processing procedures;
②检测不通过的提示信息,用于“合并处理器”记录日志或在显示给用户;2 detecting the failure information, for the "combining processor" to record the log or display it to the user;
③sql语句,子节点,可选,可配置多个子节点,约定返回某个值即为检测失败;3sql statement, child node, optional, can be configured with multiple child nodes, the agreement to return a certain value is the detection failure;
注意:对于sql需要重点说明一下,绝大多数情况下用户配置的sql需要同时访问源数据库和目的数据库,但是由于本合并装置是以临时镜像数据库来代替源数据库,所以真正的源数据库名称应该是临时镜像数据库名称,为了避免临时数据库名称与目的数据库中的数据库名称出现重名冲突(一个数据库管理系统中无法创建两个同名的数据库),合并装置可以使用某种算法生成某个唯一字符串来作为该临时镜像数据库的名称,对于用户来说是无法预知的,因此在sql语句中指定源数据库名称时,不要使用真实的数据库名称,而是以宏定义的方式来代替,例如使用%SOURCE(db1)%来表示源数据库db1的临时镜像数据库名称,“合并处理器”在执行sql时会将这种宏定义自动替换为实际的数据库名称。Note: For sql, it is important to explain that in most cases, the user-configured sql needs to access both the source database and the destination database. However, since the merge device replaces the source database with a temporary mirror database, the real source database name should be Temporary mirror database name, in order to avoid the duplicate name conflict between the temporary database name and the database name in the destination database (two databases with the same name cannot be created in a database management system), the merging device can use an algorithm to generate a unique string. As the name of the temporary mirror database, it is unpredictable for the user, so when specifying the source database name in the sql statement, do not use the real database name, but instead use the macro definition, for example, use %SOURCE ( Db1)% indicates the temporary mirror database name of the source database db1, and the "merge processor" will automatically replace this macro definition with the actual database name when executing sql.
④合并插件名称,可选,用于在sql语句无法检测的情况下,供“合并处理器”调用用户实现的“合并插件”进行检测;通常情况下,合并插件名称为用户实现的二次开发类名。4 merge plug-in name, optional, used in the case that the sql statement cannot be detected, for the "merging processor" to call the user-implemented "merging plug-in" for detection; usually, the merged plug-in name is the user-developed secondary development Class name.
③和④可任选其一,也可以同时存在,任意一个返回失败,则表示检测失败。3 and 4 can be selected either, or they can exist at the same time. If any one fails, the detection fails.
此策略针对本文上面所述的需要特殊处理的场景(1)。下面给出一个xml配置的例子:This strategy is for the scenario (1) described above that requires special handling. An example of an xml configuration is given below:
Figure PCTCN2014090271-appb-000003
Figure PCTCN2014090271-appb-000003
Figure PCTCN2014090271-appb-000004
Figure PCTCN2014090271-appb-000004
(3)表的不合并策略,为数据库策略的子节点,包含以下内容:(3) The non-merging policy of the table, which is a child node of the database policy, includes the following contents:
①表名称,指定该策略对应的具体表;1 table name, specifying the specific table corresponding to the policy;
②策略类型,为“不合并”类型。2 Strategy type, which is the "not merged" type.
此策略针对本文上面所述的需要特殊处理的场景(2),指定的表不参与合并,仅保留目的数据库中的同名表数据。下面给出一个xml配置的例子:This strategy is for the scenario (2) that needs special handling as described above in this article. The specified table does not participate in the merge, and only the table data of the same name in the destination database is retained. An example of an xml configuration is given below:
Figure PCTCN2014090271-appb-000005
Figure PCTCN2014090271-appb-000005
(4)表的修改内容合并策略,为数据库策略的子节点,设置为在合并过程中修改待合并数据,包含以下内容:(4) The modified content merge policy of the table, which is a child node of the database policy, is set to modify the data to be merged during the merge process, and includes the following contents:
①表名称,指定该策略对应的具体表;1 table name, specifying the specific table corresponding to the policy;
②策略类型,为“修改”类型;2 strategy type, which is the "modification" type;
③优先级别,可选,如果不指定优先级别,默认为继承父节点数据库的优先级别,优先级别高的表合并完成后,才能合并优先级别低的表。对于有外键依赖关系的表, “合并处理器”从数据库管理系统的系统表中可以自动识别出来,然后自动设置优先级,可以不需要用户进行优先级设置。The priority level is optional. If you do not specify a priority level, the default is to inherit the priority of the parent node database. After the table with the highest priority is merged, the table with the lower priority level can be merged. For tables with foreign key dependencies, The "Merge Processor" is automatically recognized from the system table of the database management system, and then the priority is automatically set, without the user having to set the priority.
④sql语句,子节点,可选,可配置多个子节点,设置为修改源数据库或目的数据库中的表结构或数据内容(不仅仅局限于修改当前处理的表,也可以修改其他关联依赖表);4sql statement, child node, optional, can be configured with multiple child nodes, set to modify the table structure or data content in the source database or destination database (not only limited to modify the currently processed table, but also modify other associated dependency tables);
⑤合并插件名称,子节点,可选,可配置多个子节点,设置为合并之前在sql语句无法处理的复杂业务逻辑的情况下,供合并主程序调用用户实现的二次开发合并插件进行处理;5 merge plug-in name, sub-node, optional, configurable multiple sub-nodes, set to the complex business logic that can not be processed by the sql statement before the merge, the secondary development merge plug-in for the merge main program call user to handle;
⑥是否由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,子节点,可选。默认为“是”,在源数据库和目的数据库中该表结构不一致时,由“合并处理器”来转换源数据库中表的结构,使之与目的数据库中表的结构相同;如果为“否”的话,表示该转换由用户配置的sql语句或“合并插件”来完成,“合并处理器”不参与转换流程。6 Whether the "consolidation processor" is used to complete the conversion process of the table structure in the source database and the destination database, child nodes, optional. The default is "Yes". When the table structure is inconsistent in the source database and the destination database, the "merge processor" is used to convert the structure of the table in the source database to be the same as the structure of the table in the destination database; if "No" If the conversion is indicated by the user-configured sql statement or "merging plug-in", the "merging processor" does not participate in the conversion process.
⑦是否由“合并处理器”来完成修改后数据的合并流程,子节点,可选,默认为“是”,表示在“合并处理器”执行一系列用户配置的sql或“合并插件”来修改待合并数据之后,“合并处理器”最终将源数据库中的表内容简单追加到目的数据库的同名表中;如果配置为“否”,表示该表的合并过程已经在用户配置的sql或“合并插件”中完成,不再需要“合并处理器”参与,对于某些复杂的业务逻辑,不能通过简单追加的方式进行合并,则此时可以通过此方式屏蔽掉“合并处理器”的流程,完全由用户来主导某些表的合并流程;7 Whether the merge process of the modified data is completed by the "Merge Processor", the child node is optional, and the default is "Yes", which means that the "Merge Processor" executes a series of user-configured sql or "Merge Plugin" to modify After the data is to be merged, the "Merge Processor" finally simply appends the contents of the table in the source database to the table of the same name in the destination database; if the configuration is "No", it indicates that the merge process of the table has been configured in the user's SQL or "Merge" The "plug-in" is completed, and the "merging processor" is no longer required to participate. For some complex business logics, the merge process cannot be merged by simple appending. In this case, the process of "merging the processor" can be masked in this way, completely The user merges the process of merging certain tables;
⑧自增列及其对应序列名称,指定当前表中哪个列为自增列,子节点,可选。物理定义上的自增列,“合并处理器”可以从数据库管理系统的系统表中查询识别出来,所以用户即使不指定其具体列名称,也能自动处理;有些场景下,某列虽然没有定义成自增列,但是其使用序列或其他业务逻辑算法来实现类似的自增功能,“合并处理器”无法识别这种情况,因此必须由用户来指定对应列名称;如果使用了序列,还需要指定序列名称,“合并处理器”根据这两个个信息就能采用某些算法来自动修改该列的值,以避免违反自增列唯一性的约束,并同步序列的当前值;8 self-incrementing column and its corresponding sequence name, specify which column in the current table is an auto-increment column, child node, optional. The self-addition column on the physical definition, the "merging processor" can be identified from the system table of the database management system, so the user can automatically process even if the specific column name is not specified; in some scenarios, a column is not defined. Adding columns, but using sequence or other business logic algorithms to achieve similar auto-increment functions, the "merge processor" does not recognize this situation, so the user must specify the corresponding column name; if a sequence is used, it also needs Specify the sequence name. Based on these two pieces of information, the "Merge Processor" can use some algorithms to automatically modify the value of the column to avoid the constraint of violating the uniqueness of the self-incrementing column and synchronize the current value of the sequence;
⑨自增列关联外键子表名称及列名称,为⑦的子节点,可选,可配置多个子节点。如果该表还有关联子表,通过父表自增列的唯一性来维护父子关系,则需要在父表策略中指定对应的子表名称和列名称,这样合并主程序在修改主表的自增列时能够自动修改关联子表的外键列; 9 self-additional association foreign key sub-table name and column name, is a child node of 7, optional, can be configured with multiple child nodes. If the table has an associated child table, and the parent-child relationship is maintained by the uniqueness of the parent table self-incrementing column, the corresponding child table name and column name need to be specified in the parent table policy, so that the merge main program is modifying the self table. The foreign key column of the associated sub-table can be automatically modified when the column is added;
⑩需要禁用的触发器名称,可选,子节点,可配置多个子节点。由用户根据业务逻辑决定合并当前表的过程中是否禁用指定触发器,合并完成后恢复其原有状态。10 Trigger names that need to be disabled, optional, child nodes, configurable multiple child nodes. Whether the specified trigger is disabled in the process of merging the current table according to the business logic is determined by the user, and the original state is restored after the merge is completed.
本发明的该装置可以实现通用的数据库内容合并的流程。整体的合并流程由合并主程序来完成;对于无需特殊处理的表格,合并主程序默认将源数据库中的表记录追加到目的数据库中的同名表中;对于包含合并主程序无法识别的复杂业务逻辑数据的表格,由开发人员在策略配置文件中指定其合并策略,合并主程序按照其合并策略来进行数据的合并;绝大多数应用场景中,开发人员只需在策略配置文件中配置一些sql语句即可达到修改无法直接合并的表数据的目的,在极端复杂的应用场景中,开发人员可以把自己编码实现的二次开发插件整合到合并流程中;另外,合并装置采用了并发线程的处理机制,提高合并的处理速度。The apparatus of the present invention can implement a general flow of database content merging. The overall merge process is completed by the merge main program; for tables that do not require special processing, the merge main program defaults the table records in the source database to the same name table in the destination database; for complex business logic that is not recognized by the merge main program The table of data, the developer specifies its merge strategy in the policy configuration file, and the merged main program merges the data according to its merge strategy; in most application scenarios, the developer only needs to configure some SQL statements in the policy configuration file. The purpose of modifying the table data that cannot be directly merged can be achieved. In an extremely complex application scenario, the developer can integrate the secondary development plug-in implemented by the code into the merge process; in addition, the merge device adopts the processing mechanism of the concurrent thread. , improve the processing speed of the merger.
以上所述仅是本发明的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本发明的保护范围。The above description is only a preferred embodiment of the present invention, and it should be noted that those skilled in the art can also make several improvements and retouchings without departing from the principles of the present invention. It should be considered as the scope of protection of the present invention.
工业实用性Industrial applicability
如上所述,本发明实施例提供的一种数据库内容合并方法及装置具有以下有益效果:可以实现通用的数据库内容合并的流程。对于无需特殊处理的表格,直接通过合并主程序默认将源数据库中的表格记录追加到目的数据库中的同名表格中;对于包含合并主程序无法识别的复杂业务逻辑数据的表格,由在策略配置文件中指定其对应的合并策略,合并主程序按照该合并策略来进行数据的合并;对于绝大多数的应用场景,开发人员只需在策略配置文件中配置一些sql语句即可达到修改无法直接合并的表格数据的目的,而在极端复杂的应用场景中,开发人员可以把自己编码实现的二次开发插件整合到合并流程中;另外,本发明还采用了并发线程的处理机制,提高了合并的处理速度。 As described above, a database content merging method and apparatus provided by an embodiment of the present invention have the following beneficial effects: a general flow of database content merging can be implemented. For tables that do not require special processing, the table records in the source database are appended to the table of the same name in the destination database by default by merging the main program; for the table containing the complex business logic data that is not recognized by the merge main program, by the policy configuration file Specify the corresponding merge strategy in the merged main program according to the merge strategy to merge the data; for most application scenarios, the developer only needs to configure some SQL statements in the policy configuration file to achieve the modification cannot be directly merged. The purpose of the tabular data, in the extremely complex application scenario, the developer can integrate the secondary development plug-in implemented by the encoding into the merge process; in addition, the present invention also adopts the processing mechanism of the concurrent thread to improve the processing of the merge. speed.

Claims (13)

  1. 一种数据库内容合并方法,包括:A database content merging method includes:
    建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Establishing a mirror database corresponding to the source database, where the mirror database is the same as the source database;
    根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。And according to the merging policy corresponding to the source table in the mirror database, the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
  2. 如权利要求1所述的方法,其中,所述建立源数据库对应的镜像数据库的步骤包括:The method of claim 1, wherein the step of establishing a mirror database corresponding to the source database comprises:
    备份源数据库,得到携带有表格信息的备份文件;Back up the source database to get a backup file carrying the form information;
    选取目的数据库所属的数据库管理系统;Select the database management system to which the destination database belongs;
    在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。Establishing a mirror database corresponding to the source database in the database management system, and adding table information carried in the backup file to the mirror database.
  3. 如权利要求1所述的方法,其中,所述根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的步骤包括:The method of claim 1, wherein the source table of the mirror database and the destination database need to be merged with the source table according to a merge policy corresponding to the source table in the mirror database Forms, the steps for merging the form information include:
    获取配置文件中的所述镜像数据库中的源表格对应的合并策略;Obtaining a merge policy corresponding to the source table in the mirror database in the configuration file;
    当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。When there is a detection policy in the merge policy, according to the detection strategy, the sql statement and/or the merge plug-in is selected to detect whether the table in the mirror database and the destination database can be combined with the form information, and if the detection is successful, according to the merge policy The table merge strategy combines the source tables of the mirror database with the destination tables in the destination database that need to be merged with the source tables.
  4. 如权利要求3所述的方法,其中,根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的步骤包括:The method according to claim 3, wherein, according to the table merging policy in the merging policy, the source table of the mirror database and the destination table in the destination database that need to be merged with the source table are used to perform table information. The steps to merge include:
    获得镜像数据库中所有源表格的集合;Obtain a collection of all source tables in the mirror database;
    建立源表格的集合中需要和目的数据库中的目的表格进行合并的表格,与表格合并策略的对应关系;Establishing a correspondence between the table of the source table and the table to be merged with the destination table in the destination database, and the correspondence with the table merging strategy;
    按优先级顺序对源表格和目的数据库中的目的表格进行表格信息合并。 The table information is merged in the priority table in the source table and the destination table in the destination database.
  5. 如权利要求4所述的方法,其中,对源表格和目的数据库中的目的表格进行表格信息合并的步骤包括:The method of claim 4 wherein the step of merging the form information for the destination form in the source form and the destination database comprises:
    获得源表格的集合中的源表格对应的表格合并策略;Obtaining a table merging strategy corresponding to the source table in the collection of source tables;
    若所述表格合并策略为指定合并策略且指定合并策略类型为合并或者为修改策略,则判断目的数据库中是否存在与源表格同名的目的表格,若存在,则对源表格和与源表格同名的目的表格进行表格信息合并,否则,在目的数据库中创建与源表格同名的目的表格,再对源表格和目的表格进行表格信息合并。If the table merging strategy is a specified merging strategy and the specified merging strategy type is merging or modifying the policy, it is determined whether there is a destination table with the same name as the source table in the destination database, and if present, the source table and the same name as the source table The destination form merges the form information. Otherwise, a destination form with the same name as the source form is created in the destination database, and the form information is merged between the source form and the destination form.
  6. 根据权利要求5所述的方法,其中,对源表格和目的表格进行表格信息合并的步骤包括:The method of claim 5 wherein the step of merging the form information with the source form and the destination form comprises:
    判断源表格与目的表格的表结构是否一致,若是,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并,否则,将源表格的表结构转换为与目的表格的表结构一致后,再根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并。Determining whether the table structure of the source table and the destination table are consistent, and if so, combining the table information with the source table and the destination table according to the specified merge policy of the source table; otherwise, converting the table structure of the source table to the table with the destination table After the structure is consistent, the form information is merged between the source table and the destination table according to the specified merge policy of the source table.
  7. 根据权利要求6所述的方法,其中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:The method of claim 6, wherein the step of merging the form information with the source form and the destination form according to the specified merge policy of the source form comprises:
    若所述源表格没有指定合并策略,获得源表格的记录总数;If the source table does not specify a merge policy, the total number of records of the source table is obtained;
    若所述源表格的记录总数不为0,执行插入语句,将源表格中的所有记录插入到目的表格中。If the total number of records in the source table is not 0, an insert statement is executed to insert all the records in the source table into the destination table.
  8. 根据权利要求6所述的方法,其中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:The method of claim 6, wherein the step of merging the form information with the source form and the destination form according to the specified merge policy of the source form comprises:
    若所述源表格具有指定合并策略,则按指定合并策略对源表格进行修改,获得修改后的源表格的记录;If the source table has a specified merge policy, modify the source table according to the specified merge policy to obtain a record of the modified source table;
    将该修改后的源表格的记录插入到目的表格中。Insert the record of the modified source table into the destination table.
  9. 根据权利要求8所述的方法,其中,对源表格进行修改,获得修改后的源表格的记录的步骤包括:The method of claim 8 wherein the step of modifying the source form to obtain a record of the modified source form comprises:
    对所述源表格中违反约束规则的记录或者主键冲突的记录进行修改或者删除,得到修改后的源表格的记录;或者Modifying or deleting the record in the source table that violates the constraint rule or the record of the primary key conflict, and obtains the record of the modified source table; or
    对所述源表格中的自增列或者序列加上一个固定值,得到修改后的源表格的记录;或者 Adding a fixed value to the self-incrementing column or sequence in the source table to obtain a record of the modified source table; or
    对所述源表格存在外键依赖,在对依赖父表进行修改的情况下,对依赖子表也进行相关内容的修改,得到修改后的源表格的记录。There is a foreign key dependency on the source table, and in the case of modifying the dependent parent table, the dependent content table is also modified to obtain a record of the modified source table.
  10. 根据权利要求8所述的方法,其中,将该修改后的源表格的记录插入到目的表格中的步骤包括:The method of claim 8 wherein the step of inserting the record of the modified source form into the destination form comprises:
    若目的表格使用了触发器且目的表格没有被其它表依赖,则在目的表格中插入源表格的记录时,利用触发器自动生成记录的递增ID;否则,在目的表格中插入源表格的记录时,禁用所述触发器,在记录插入完成后,再恢复触发器为合并前的状态。If the destination table uses a trigger and the destination table is not dependent on other tables, the incremental ID of the record is automatically generated by the trigger when the record of the source table is inserted in the destination table; otherwise, when the record of the source table is inserted in the destination table , the trigger is disabled, and after the record insertion is completed, the trigger is restored to the state before the merge.
  11. 一种数据库内容合并装置,包括:A database content merging device, comprising:
    建立模块,设置为建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Establishing a module, configured to establish a mirror database corresponding to the source database, where the mirror database is the same as the source database;
    合并模块,设置为根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。The merging module is configured to merge the source table of the mirror database with the destination table of the target database that needs to be merged with the source table according to a merging policy corresponding to the source table in the mirror database.
  12. 如权利要求11所述的装置,其中,建立模块包括:The apparatus of claim 11 wherein the establishing module comprises:
    备份子模块,设置为备份源数据库,得到携带有表格信息的备份文件;The backup sub-module is set as a backup source database to obtain a backup file carrying the form information;
    连接子模块,设置为选取目的数据库所属的数据库管理系统;The connection submodule is set to select a database management system to which the destination database belongs;
    建立子模块,设置为在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。And establishing a sub-module, configured to establish a mirror database corresponding to the source database in the database management system, and add table information carried in the backup file to the mirror database.
  13. 如权利要求11所述的装置,其中,合并模块包括:The apparatus of claim 11 wherein the merging module comprises:
    获取子模块,设置为获取配置文件中的所述镜像数据库中的源表格对应的合并策略;Obtaining a submodule, configured to obtain a merge policy corresponding to the source table in the mirror database in the configuration file;
    合并子模块,设置为当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。 The merging sub-module is set to use the sql statement and/or the merge plug-in to detect whether the table in the mirror database and the destination database can be combined with the table information according to the detection policy, and if the detection is successful, According to the table merging strategy in the merging strategy, the source table of the mirror database is merged with the destination table in the destination database that needs to be merged with the source table.
PCT/CN2014/090271 2014-07-16 2014-11-04 Method and device for merging database contents WO2015117429A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410339322.9A CN105320681B (en) 2014-07-16 2014-07-16 Database content merging method and device
CN201410339322.9 2014-07-16

Publications (1)

Publication Number Publication Date
WO2015117429A1 true WO2015117429A1 (en) 2015-08-13

Family

ID=53777244

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/090271 WO2015117429A1 (en) 2014-07-16 2014-11-04 Method and device for merging database contents

Country Status (2)

Country Link
CN (1) CN105320681B (en)
WO (1) WO2015117429A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109254969A (en) * 2018-08-31 2019-01-22 平安科技(深圳)有限公司 Tables of data processing method, device, equipment and storage medium

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108205559B (en) * 2016-12-19 2022-01-07 腾讯科技(深圳)有限公司 Data management method and equipment thereof
WO2018113580A1 (en) * 2016-12-19 2018-06-28 腾讯科技(深圳)有限公司 Data management method and server
CN110532254A (en) * 2018-05-25 2019-12-03 杭州海康威视数字技术股份有限公司 The method and apparatus of fused data table
CN111324624A (en) * 2018-12-17 2020-06-23 中兴通讯股份有限公司 Method, equipment and storage medium for compatibility of merge into function of database component
CN110334098A (en) * 2019-06-27 2019-10-15 烽火通信科技股份有限公司 A kind of database combining method and system based on script
CN117331963B (en) * 2023-11-28 2024-03-08 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103077242A (en) * 2013-01-11 2013-05-01 北京佳讯飞鸿电气股份有限公司 Method for hot standby of dual database servers
CN103309997A (en) * 2013-06-25 2013-09-18 上海航天测控通信研究所 Internal and external network parallel running system for database merging and method of database merging
US8543540B1 (en) * 2012-05-09 2013-09-24 Bertec Corporation System and method for the merging of databases

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7403958B2 (en) * 2005-01-19 2008-07-22 International Business Machines Corporation Synchronization-replication concurrency using non-shared snapshot query on a history table at read-uncommitted isolation level
CN101355726A (en) * 2007-07-25 2009-01-28 国际商业机器公司 Method and system for synchronizing data base based on multimedia information transference
CN102591666B (en) * 2012-01-04 2016-11-16 浪潮通用软件有限公司 A kind of metadata version management method of hierarchy

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8543540B1 (en) * 2012-05-09 2013-09-24 Bertec Corporation System and method for the merging of databases
CN103077242A (en) * 2013-01-11 2013-05-01 北京佳讯飞鸿电气股份有限公司 Method for hot standby of dual database servers
CN103309997A (en) * 2013-06-25 2013-09-18 上海航天测控通信研究所 Internal and external network parallel running system for database merging and method of database merging

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109254969A (en) * 2018-08-31 2019-01-22 平安科技(深圳)有限公司 Tables of data processing method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN105320681A (en) 2016-02-10
CN105320681B (en) 2020-06-30

Similar Documents

Publication Publication Date Title
WO2015117429A1 (en) Method and device for merging database contents
US9600193B2 (en) Replicating snapshots from a source storage system to a target storage system
US10528548B2 (en) Enforcing referential integrity for object data documents
TWI740901B (en) Method and device for performing data recovery operation
US10146532B2 (en) Apparatus and method for detecting code cloning of software
EP3072070B1 (en) Callpath finder
KR102054568B1 (en) Filtering Data Schematic Diagram
US8676752B2 (en) Techniques for the log-based replication of high-level procedures
US9229942B1 (en) Method and system for hard link handling for incremental file migration
WO2020207010A1 (en) Data backup method and device, and computer-readable storage medium
KR102001749B1 (en) Filtering data grid diagram
JP6239004B2 (en) Method, apparatus and computer readable medium for optimized data subsetting
US11531594B2 (en) Data recovery method and apparatus, server, and computer-readable storage medium
KR20130095250A (en) Processing related datasets
US9563628B1 (en) Method and system for deletion handling for incremental file migration
KR20160130256A (en) Managing data profiling operations related to data type
US20120047124A1 (en) Database query optimizations
US20120079454A1 (en) Expressing equivalency relationships with identity graphs
US20160140197A1 (en) Cross-system synchronization of hierarchical applications
CN103020318A (en) Method for maintenance of database tables in database
US20110137922A1 (en) Automatic generation of a query lineage
Mehnert et al. Formalized verification of snapshotable trees: Separation and sharing
US9965536B2 (en) Replication description model for data distribution
Abdulla et al. Approximated parameterized verification of infinite-state processes with global conditions
US11366658B1 (en) Seamless lifecycle stability for extensible software features

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14881633

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14881633

Country of ref document: EP

Kind code of ref document: A1