[go: up one dir, main page]

CN105320681A - Database content combination method and device - Google Patents

Database content combination method and device Download PDF

Info

Publication number
CN105320681A
CN105320681A CN201410339322.9A CN201410339322A CN105320681A CN 105320681 A CN105320681 A CN 105320681A CN 201410339322 A CN201410339322 A CN 201410339322A CN 105320681 A CN105320681 A CN 105320681A
Authority
CN
China
Prior art keywords
source
database
merging
strategy
merge
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN201410339322.9A
Other languages
Chinese (zh)
Other versions
CN105320681B (en
Inventor
龙涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZTE Corp
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CN201410339322.9A priority Critical patent/CN105320681B/en
Priority to PCT/CN2014/090271 priority patent/WO2015117429A1/en
Publication of CN105320681A publication Critical patent/CN105320681A/en
Application granted granted Critical
Publication of CN105320681B publication Critical patent/CN105320681B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明提供了一种数据库内容合并方法及装置,其中方法包括:建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库完全相同;根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格与目的数据库中需要与所述源表格进行合并的目的表格进行表格信息合并。通过本发明所提供的方案,解决了现有技术中对于复杂业务逻辑的应用程序的合并问题,提高了处理数据库内容合并的能力。

The present invention provides a database content merging method and device, wherein the method includes: establishing a mirror database corresponding to the source database, the mirror database is completely the same as the source database; according to the merge A strategy for merging table information between the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table. Through the solution provided by the invention, the problem of merging application programs of complex business logic in the prior art is solved, and the capability of processing database content merging is improved.

Description

一种数据库内容合并方法及装置Method and device for merging database content

技术领域technical field

本发明涉及计算机领域,尤其涉及一种数据库内容合并方法及装置。The invention relates to the field of computers, in particular to a database content merging method and device.

背景技术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 merge two sets of independent database contents of the same application software into one set of database contents for management.

对于数据库的合并,通常使用数据库管理系统自身提供的数据迁移工具来进行数据合并迁移。然而,由于该种数据迁移工具是通用化的工具,它只能处理简单的数据迁移逻辑,比如将数据库A中一个表格的数据追加到数据库B中的某一个表格中。For the merging of databases, the data migration tools provided by the database management system are usually used for data merging and migration. However, since this data migration tool is a general tool, it can only handle simple data migration logic, such as appending data from a table in database A to a certain table in database B.

而对于具有复杂业务逻辑的应用程序来说,这种迁移工具往往无能为力,具有很大的局限性。所以,如何实现对于复杂业务逻辑的应用程序的合并问题,是有待解决的问题。However, for applications with complex business logic, this kind of migration tool is often powerless and has great limitations. Therefore, how to implement the merging of applications with complex business logic is a problem to be solved.

发明内容Contents of the invention

本发明的目的是提供一种数据库内容合并方法及装置,解决了现有技术中对于复杂业务逻辑的应用程序的合并问题。The object of the present invention is to provide a method and device for merging database content, which solves the problem of merging application programs for complex business logic in the prior art.

为了实现上述目的,本发明提供了一种数据库内容合并方法,包括:In order to achieve the above object, the present invention provides a method for merging database content, comprising:

建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Establish a mirror database corresponding to the source database, which is the same as the source database in the mirror database;

根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。According to the merging strategy 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.

其中,所述建立源数据库对应的镜像数据库的步骤包括:Wherein, the step of establishing a mirror image database corresponding to the source database includes:

备份源数据库,得到携带有表格信息的备份文件;Back up the source database to obtain a backup file with table information;

选取目的数据库所属的数据库管理系统;Select the database management system to which the target database belongs;

在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。A mirror database corresponding to the source database is established in the database management system, and the table information carried in the backup file is added to the mirror database.

其中,所述根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的步骤包括:Wherein, according to the merging strategy corresponding to the source table in the mirror database, the step of merging table information on the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table includes :

获取配置文件中的所述镜像数据库中的源表格对应的合并策略;Obtain the merge strategy corresponding to the source table in the mirror database in the configuration file;

当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。When there is a detection strategy in the merging strategy, according to the detection strategy, select the sql statement and/or merge plug-in to detect whether the tables in the mirror database and the destination database can perform table information merging, if the detection is successful, then according to the merging strategy A table merging strategy is used to merge table information between the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table.

其中,根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的步骤包括:Wherein, according to the table merging strategy in the merging strategy, the step of merging table information for the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table includes:

获得镜像数据库中所有源表格的集合;Obtain the collection of all source tables in the mirror database;

建立源表格的集合中需要和目的数据库中的目的表格进行合并的表格与表格合并策略的对应关系;Establish the corresponding relationship between the tables in the set of source tables that need to be merged with the destination table in the destination database and the table merge strategy;

按优先级顺序对源表格和目的数据库中的目的表格进行表格信息合并。The source table and the destination table in the destination database are merged according to the order of priority.

其中,对源表格和目的数据库中的目的表格进行表格信息合并的步骤包括:Wherein, the step of merging table information on the source table and the destination table in the destination database includes:

获得源表格的集合中的源表格对应的表格合并策略;Obtain the table merging strategy corresponding to the source table in the set of source tables;

若所述表格合并策略为指定合并策略且指定合并策略类型为合并或者为修改策略,则判断目的数据库中是否存在与源表格同名的目的表格,若存在,则对源表格和与源表格同名的目的表格进行表格信息合并,否则,在目的数据库中创建与源表格同名的目的表格,再对源表格和目的表格进行表格信息合并。If the table merging strategy is a designated merging strategy and the designated merging strategy type is a merge or a modification strategy, then it is judged whether there is a destination table with the same name as the source table in the destination database, and if it exists, the source table and the source table with the same name as the source table Merge the table information of the destination table, otherwise, create a destination table with the same name as the source table in the destination database, and then merge the table information of the source table and the destination table.

其中,对源表格和目的表格进行表格信息合并的步骤包括:Wherein, the steps of merging the table information of the source table and the destination table include:

判断源表格与目的表格的表结构是否一致,若是,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并,否则,将源表格的表结构转换为与目的表格的表结构一致后,再根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并。Determine whether the table structure of the source table and the destination table are consistent, if so, merge the table information of the source table and the destination table according to the specified merge strategy of the source table, otherwise, convert the table structure of the source table into the table structure of the destination table After the structures are consistent, the table information of the source table and the destination table are merged according to the specified merging strategy of the source table.

其中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:Wherein, according to the specified merging strategy of the source table, the step of merging the table information of the source table and the destination table includes:

若所述源表格没有指定合并策略,获得源表格的记录总数;If the source table does not specify a merge strategy, obtain the total number of records in the source table;

若所述源表格的记录总数不为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.

其中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:Wherein, according to the specified merging strategy of the source table, the step of merging the table information of the source table and the destination table includes:

若所述源表格具有指定合并策略,则按指定合并策略对源表格进行修改,获得修改后的源表格的记录;If the source table has a specified merging strategy, modify the source table according to the specified merging strategy to obtain a record of the modified source table;

将该修改后的源表格的记录插入到目的表格中。Insert the modified records of the source table into the destination table.

其中,对源表格进行修改,获得修改后的源表格的记录的步骤包括:Wherein, the steps of modifying the source table and obtaining the records of the modified source table include:

对所述源表格中违反约束规则的记录或者主键冲突的记录进行修改或者删除,得到修改后的源表格的记录;或者Modifying or deleting the records in the source table that violate the constraint rules or the records with primary key conflicts to obtain the modified records in the source table; or

对所述源表格中的自增列或者序列加上一个固定值,得到修改后的源表格的记录;或者Adding a fixed value to an auto-increment column or sequence in the source table to obtain a modified record in the source table; or

对所述源表格存在外键依赖,在对依赖父表进行修改的情况下,对依赖子表也进行相关内容的修改,得到修改后的源表格的记录。There is a foreign key dependency on the source table, and in the case of modifying the dependent parent table, relevant content is also modified on the dependent child table to obtain the modified source table record.

其中,将该修改后的源表格的记录插入到目的表格中的步骤包括:Wherein, the step of inserting the record of the modified source table into the destination table includes:

若目的表格使用了触发器且目的表格没有被其它表依赖,则在目的表格中插入源表格的记录时,利用触发器自动生成记录的递增ID;否则,在目的表格中插入源表格的记录时,禁用所述触发器,在记录插入完成后,再恢复触发器为合并前的状态。If the target table uses a trigger and the target table is not dependent on other tables, when inserting the record of the source table in the target table, use the trigger to automatically generate the incremental ID of the record; otherwise, when inserting the record of the source table in the target table , disable the trigger, and restore the trigger to the state before the merge after the record insertion is completed.

本发明的实施例还提供一种数据库内容合并装置,包括:Embodiments of the present invention also provide a database content merging device, including:

建立模块,用于建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Establishing a module for establishing 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, according to the merging strategy corresponding to the source table in the mirror database, merge table information between the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table.

其中,建立模块包括:Among them, building modules include:

备份子模块,用于备份源数据库,得到携带有表格信息的备份文件;The backup sub-module is used to back up the source database to obtain a backup file carrying table information;

连接子模块,用于选取目的数据库所属的数据库管理系统;The connection sub-module is used to select the database management system to which the target database belongs;

建立子模块,用于在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。The establishment sub-module is used to establish a mirror database corresponding to the source database in the database management system, and add the table information carried in the backup file to the mirror database.

其中,合并模块包括:Among them, the merge module includes:

获取子模块,用于获取配置文件中的所述镜像数据库中的源表格对应的合并策略;The obtaining submodule is used to obtain the merge strategy corresponding to the source table in the mirror database in the configuration file;

合并子模块,用于当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。The merging submodule is used for when there is a detection strategy in the merging strategy, according to the detection strategy, select the sql statement and/or merge plug-in to detect whether the tables in the mirror database and the destination database can perform table information merging, if the detection is successful, 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.

本发明的上述技术方案具有如下技术效果:Above-mentioned technical scheme of the present invention has following technical effect:

通过采用本发明所述方法,可以实现通用的数据库内容合并的流程。对于无需特殊处理的表格,直接通过合并主程序默认将源数据库中的表格记录追加到目的数据库中的同名表格中;对于包含合并主程序无法识别的复杂业务逻辑数据的表格,由在策略配置文件中指定其对应的合并策略,合并主程序按照该合并策略来进行数据的合并;对于绝大多数的应用场景,开发人员只需在策略配置文件中配置一些sql语句即可达到修改无法直接合并的表格数据的目的,而在极端复杂的应用场景中,开发人员可以把自己编码实现的二次开发插件整合到合并流程中;另外,本发明还采用了并发线程的处理机制,提高了合并的处理速度。By adopting the method of the present invention, a general flow of database content merging can be realized. For tables that do not require special processing, the table records in the source database are appended to the table with the same name in the destination database by default directly through the merge main program; Specify the corresponding merging strategy in , and the merging main program will merge data according to the merging strategy; for most application scenarios, developers only need to configure some sql statements in the strategy configuration file to modify the data that cannot be directly merged In extremely complex application scenarios, developers can integrate the secondary development plug-ins implemented by their own codes into the merge process; in addition, the present invention also adopts a concurrent thread processing mechanism to improve the merge process speed.

附图说明Description of drawings

图1为本发明实施例所提供的数据库内容合并的方法流程图;FIG. 1 is a flowchart of a method for merging database content provided by an embodiment of the present invention;

图2为本发明实施例所提供的数据库内容合并的方法具体实施例流程图;2 is a flow chart of a specific embodiment of a method for merging database content provided by an embodiment of the present invention;

图3为本发明实施例所提供的数据库内容合并的方法中表格合并的流程图;FIG. 3 is a flow chart of table merging in the method for merging database content provided by an embodiment of the present invention;

图4为本发明的实施例所提供的数据库内容合并的装置结构框图。Fig. 4 is a structural block diagram of a device for merging database content provided by an embodiment of the present invention.

具体实施方式detailed description

为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合附图对具体实施例进行详细描述。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention more clear, specific embodiments will be described in detail below with reference to the accompanying drawings.

如图1所示,本发明的实施例提供一种数据库内容合并方法,包括:As shown in Figure 1, an embodiment of the present invention provides a method for merging database content, including:

步骤11,建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Step 11, establishing a mirror database corresponding to the source database, wherein the mirror database is the same as the source database;

步骤12,根据所述镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。Step 12: According to the merging strategy corresponding to the source table in the mirror database, perform table information merging on the source table in the mirror database and the destination table in the destination database that needs to be merged with the source table.

本发明的该实施例通过建立与源数据库完全相同的镜像数据库,并根据镜像数据库中的源表格对应的合并策略,对所述镜像数据库的源表格与目的数据库中需要与所述源表格进行合并的目的表格进行表格信息合并;从而可以将同一应用软件的两套独立的数据库内容合并为一套数据库内容的方案,能适应各种复杂的业务逻辑。In this embodiment of the present invention, by establishing a mirror database exactly the same as the source database, and according to the merge strategy corresponding to the source table in the mirror database, the source table of the mirror database and the destination database need to be merged with the source table The purpose of the table is to merge table information; thus, it is possible to merge two sets of independent database contents of the same application software into one set of database contents, which can adapt to various complex business logics.

在本发明的一具体实施例中,上述步骤11可以包括:In a specific embodiment of the present invention, the above step 11 may include:

步骤111,备份源数据库,得到携带有表格信息的备份文件;Step 111, backing up the source database to obtain a backup file carrying table information;

步骤112,选取目的数据库所属的数据库管理系统;Step 112, selecting the database management system to which the target database belongs;

步骤113,在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。Step 113, establishing a mirror database corresponding to the source database in the database management system, and adding the 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 methods), and then the temporary The mirror database acts as the source database. This enables users to simultaneously access the source and destination databases in SQL statements.

在本发明的另一具体实施例中,上述步骤12具体可以包括:In another specific embodiment of the present invention, the above step 12 may specifically include:

步骤121,获取配置文件中的所述镜像数据库中的源表格对应的合并策略;Step 121, obtaining the merge strategy corresponding to the source table in the mirror database in the configuration file;

步骤122,当合并策略中有检测策略时,根据所述检测策略,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。Step 122, when there is a detection strategy in the merging strategy, according to the detection strategy, select the sql statement and/or merge plug-in to detect whether the tables in the mirror database and the destination database can perform table information merging, if the detection is successful, then according to the described The table merging strategy in the merging strategy is to merge table information between the source table of the mirror database and 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, users need to configure some "merging strategies" to intervene in the merging process. Some scenarios during the merging process do not need to be merged. Therefore, it is necessary to Perform detection to identify some application scenarios that cannot be merged. For example, in the student registration information management system, two or more student records with identical ID numbers are not allowed to appear. If such conflicts are detected in the contents of the two databases to be merged before the merger, follow-up should be prohibited. The merging process; for another example, the contents of two databases to be merged are generated by different versions of application software, and the data structures are incompatible, so they should not be merged. Detect before merging, and according to the table merging strategy in the merging strategy, perform table information merging on the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table, which can improve business processing efficiency .

在上述的实施例中,步骤122中,根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并的具体实现过程可以包括:In the above-mentioned embodiment, in step 122, according to the table merging strategy in the merging strategy, the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table are processed for table information. The specific implementation process of the merger may include:

步骤1221,获得镜像数据库中所有源表格的集合;Step 1221, obtaining the set of all source tables in the mirror database;

步骤1222,建立源表格的集合中,需要和目的数据库中的目的表格进行合并的表格与表格合并策略的对应关系;Step 1222, establishing the corresponding relationship between the table that needs to be merged with the destination table in the destination database and the table merge strategy in the set of source tables;

步骤1223,按优先级顺序对源表格和目的数据库中的目的表格进行表格信息合并。Step 1223, performing table information merging on 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 Figure 2, and the database content merging process as a whole includes:

(1)备份需要参与合并的所有源数据库,得到其备份文件;(1) Back up all source databases that need to participate in the merger, and obtain their backup files;

(2)指定目的数据库所在的数据库管理系统,以系统管理员(或其他满足操作权限的角色)的身份成功连接进去;(2) The database management system where the specified target database is located is successfully connected as a system administrator (or other roles that meet the operating authority);

(3)指定所有需要参与合并的源数据库的备份文件,自动为每个源数据库创建对应的临时镜像数据库,并恢复所有源数据库的内容;(3) Specify the backup files of all source databases that need to be merged, automatically create a corresponding temporary mirror database for each source database, and restore the contents of all source databases;

(4)解析配置文件中的所有合并策略;(4) Parsing all merge strategies in the configuration file;

(5)根据合并策略中的检测策略,执行合并前的检测工作,如果返回失败,则转到步骤(9),结束合并工作;如果返回成功,或者没有配置任何检测策略,则继续处理后续步骤;(5) According to the detection strategy in the merge strategy, perform the detection work before merging. If the return fails, go to step (9) to end the merge work; if the return is successful, or if no detection strategy is configured, continue to process the subsequent steps ;

(6)合并装置序获取所有待合并的源数据库中的所有表信息集合,再结合第(2)步中得到的所有合并策略,建立所有待合并表与合并策略的映射关系,这里的待合并表为:源表格的集合中,需要和目的数据库中的目的表格进行合并的表格,并按照合并策略中定义的优先级别排序;(6) The merging device sequence obtains all table information collections in all source databases to be merged, and then combines all the merging strategies obtained in step (2) to establish a mapping relationship between all tables to be merged and the merging strategy. Here, to be merged The table is: in the set of source tables, the table that needs to be merged with the destination table in the destination database, and sorted according to the priority defined in the merge strategy;

(7)按照优先级别从高到低的先后顺序,并发处理同一优先级别的所有表格,待该优先级别的表格都处理完毕后,再处理优先级别更低的表格,直到所有表格处理完毕;(7) Concurrently process all forms of the same priority level in the order of priority from high to low, and after the forms of this priority level are all processed, then process the forms with lower priority levels until all forms are processed;

(8)合并装置删除创建的临时数据库;(8) The temporary database created by the merge device deletes;

(9)合并工作结束。(9) The merger work is over.

在本发明的上述实施例中,对源表格和目的数据库中的目的表格进行表格信息合并的具体实现流程包括:In the above-mentioned embodiments of the present invention, the specific implementation process of merging table information on the source table and the destination table in the destination database includes:

步骤12231,获得源表格的集合中的源表格对应的表格合并策略;Step 12231, obtain the table merging strategy corresponding to the source table in the set of source tables;

步骤12232,若所述表格合并策略为指定合并策略且指定合并策略类型为合并或者为修改策略,则判断目的数据库中是否存在与源表格的集合中的源表格同名的目的表格,若存在,则对源表格和目的数据库中与源表格同名的目的表格进行表格信息合并,否则,在目的数据库中创建与源表格同名的目的表格,再对源表格和目的表格进行表格信息合并。Step 12232, if the table merging strategy is a specified merging strategy and the specified merging strategy type is merging or modification strategy, then judge whether there is a target table with the same name as the source table in the set of source tables in the destination database, and if so, then Merge the table information of the source table and the destination table with the same name as the source table in the source table and the destination database, otherwise, create a destination table with the same name as the source table in the destination database, and then merge the source table and the destination table.

进一步的步骤12232中,对源表格和目的表格进行表格信息合并的步骤包括:In a further step 12232, the step of merging the form information of the source form and the destination form includes:

判断源表格与目的表格的表结构是否一致,若是,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并,否则,将源表格的表结构转换为与目的表格的表结构一致后,再根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并。Determine whether the table structure of the source table and the destination table are consistent, if so, merge the table information of the source table and the destination table according to the specified merge strategy of the source table, otherwise, convert the table structure of the source table into the table structure of the destination table After the structures are consistent, the table information of the source table and the destination table are merged according to the specified merging strategy of the source table.

进一步的,步骤12232中,根据所述源表格的指定合并策略,对源表格和目的表格进行表格信息合并的步骤包括:Further, in step 12232, according to the specified merging policy of the source table, the step of merging the source table and the destination table includes:

步骤122321,若所述源表格没有指定合并策略,获得源表格的记录总数;若所述源表格的记录总数不为0,执行插入语句,将源表格中的所有记录插入到目的表格中。Step 122321, if the source table does not specify a merge strategy, 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 merging strategy, modify the source table according to the specified merging strategy to obtain the modified records of the source table; insert the modified records of the source table into the destination table.

步骤122322中,对源表格进行修改,获得修改后的源表格的记录的步骤包括:In step 122322, the source table is modified, and the steps of obtaining the modified source table records include:

对所述源表格中违反约束规则的记录或者主键冲突的记录进行修改或者删除,得到修改后的源表格的记录;或者Modifying or deleting the records in the source table that violate the constraint rules or the records with primary key conflicts to obtain the modified records in the source table; or

对所述源表格中的自增列或者序列加上一个固定值,得到修改后的源表格的记录;或者Adding a fixed value to an auto-increment column or sequence in the source table to obtain a modified record in the source table; or

对所述源表格存在外键依赖,在对依赖父表进行修改的情况下,对依赖子表也进行相关内容的修改,得到修改后的源表格的记录。There is a foreign key dependency on the source table, and in the case of modifying the dependent parent table, relevant content is also modified on the dependent child table to obtain the modified source table record.

其中,将该修改后的源表格的记录插入到目的表格中的步骤包括:Wherein, the step of inserting the record of the modified source table into the destination table includes:

若目的表格使用了触发器且目的表格没有被其它表依赖,则在目的表格中插入源表格的记录时,利用触发器自动生成记录的递增ID;否则,在目的表格中插入源表格的记录时,禁用所述触发器,在记录插入完成后,再恢复触发器为合并前的状态。If the target table uses a trigger and the target table is not dependent on other tables, when inserting the record of the source table in the target table, use the trigger to automatically generate the incremental ID of the record; otherwise, when inserting the record of the source table in the target table , disable the trigger, and restore the trigger to the state before the merge after the record insertion is completed.

该表格的合并具体实现流程如图3所示,包括:The specific implementation process of merging the tables is shown in Figure 3, including:

①查找该表对应的表格合并策略,如果指定了表格合并策略且策略类型为不合并策略,则该表合并流程在此结束,转到步骤⑧;如果该表没有指定表格合并策略,或者策略类型为修改策略,则继续后面的合并流程;① Find the table merging strategy corresponding to the table. If the table merging strategy is specified and the strategy type is no merging strategy, the table merging process ends here, and go to step ⑧; if the table does not specify a table merging strategy, or the strategy type To modify the strategy, continue the subsequent merge process;

②如果目的数据库中不存在同名表,则在其中创建相同结构的同名表格,并转到步骤④;②If the table with the same name does not exist in the destination database, create a table with the same name in the same structure and go to step ④;

③获取源数据库和目的数据库中该表的结构信息,比较表结构是否一致;如果一致,则转下一步骤;如果不一致,判断该表是否指定了表格合并策略,如果没有指定表格合并策略,或者指定了表格合并策略且设定由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,则合并装置自动转换源数据库中表结构,使其与目的数据库中的表结构一致;如果指定了合并策略且合并策略设定不由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,则不作任何处理,转下一步骤;③ Obtain the structure information of the table in the source database and the target database, and compare whether the table structure is consistent; if they are consistent, go to the next step; if they are not consistent, determine whether the table has specified a table merge strategy, if no table merge strategy is specified, or If the table merging strategy is specified and the "merging processor" is set to complete the conversion process where the table structures in the source database and the destination database are inconsistent, the merging device will automatically convert the table structure in the source database to make it consistent with the table structure in the destination database ; If a merge strategy is specified and the merge strategy setting does not allow the "merge processor" to complete the conversion process of inconsistent table structures in the source database and the destination database, do nothing and go to the next step;

④如果该表没有指定表格合并策略,则获取源数据库该表的记录总数,如果记录总数为0,则转到步骤⑧结束该表的合并流程,否则转到步骤⑥进行表记录的追加合并;④ If the table does not specify a table merging strategy, then obtain the total number of records of the table in the source database, if the total number of records is 0, then go to step ⑧ to end the merging process of the table, otherwise go to step ⑥ to perform additional merging of table records;

⑤如果该表指定了合并策略,则合并装置按照该策略执行一系列修改数据库内容的步骤;如果合并策略设定不由“合并处理器”来完成修改后数据的合并流程,则转到步骤⑦,否则继续后面的步骤;⑤ If the table specifies a merging strategy, the merging device executes a series of steps to modify the database content according to the strategy; if the merging strategy setting does not allow the "merging processor" to complete the merging process of the modified data, then go to step ⑦, Otherwise, continue to the following steps;

⑥执行insert语句,将源数据库中该表的所有记录追加插入到目的数据库中的同名表中;⑥ Execute the insert statement, and insert all the records of the table in the source database into the table with the same name in the destination database;

⑦如果该表指定了合并策略,且该策略设定禁用了某些触发器,则恢复目的数据库中的触发器为合并前的状态;⑦If the table specifies a merge strategy, and the strategy setting disables certain triggers, restore the triggers in the destination database to the state before the merge;

⑧该表合并流程结束。⑧ The table merging process ends.

上述流程中,具体的,表的修改内容合并策略,为数据库策略的子节点,用于在合并过程中修改待合并数据,包含以下内容:In the above process, specifically, the table modification content merge policy is a child node of the database policy, which is used to modify the data to be merged during the merge process, including the following content:

①表名称,指定该策略对应的具体表;① Table name, specify the specific table corresponding to the strategy;

②策略类型,为“修改”类型;②Strategy type, which is "Modify" type;

③优先级别,可选,如果不指定优先级别,默认为继承父节点数据库的优先级别,优先级别高的表合并完成后,才能合并优先级别低的表。对于有外键依赖关系的表,“合并处理器”从数据库管理系统的系统表中可以自动识别出来,然后自动设置优先级,可以不需要用户进行优先级设置。③Priority level, optional. If no priority level is specified, the default is to inherit the priority level of the parent node database. After the table with high priority level is merged, the table with low priority level can be merged. For tables with foreign key dependencies, the "merge processor" can automatically identify them from the system tables of the database management system, and then automatically set the priority, which does not require the user to set the priority.

④sql语句,子节点,可选,可配置多个子节点,用于修改源数据库或目的数据库中的表结构或数据内容(不仅仅局限于修改当前处理的表,也可以修改其他关联依赖表);④sql statement, sub-node, optional, multiple sub-nodes can be configured, used to modify the table structure or data content in the source database or the destination database (not only limited to modifying the currently processed table, but also other associated dependent tables);

⑤合并插件名称,子节点,可选,可配置多个子节点,用于合并之前在sql语句无法处理的复杂业务逻辑的情况下,供合并主程序调用用户实现的二次开发合并插件进行处理;⑤Merge plug-in name, sub-node, optional, multiple sub-nodes can be configured, used for merging the main program to call the secondary development merging plug-in implemented by the user in the case of complex business logic that cannot be processed by the sql statement before merging;

⑥是否由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,子节点,可选。默认为“是”,在源数据库和目的数据库中该表结构不一致时,由“合并处理器”来转换源数据库中表的结构,使之与目的数据库中表的结构相同;如果为“否”的话,表示该转换由用户配置的sql语句或“合并插件”来完成,“合并处理器”不参与转换流程。⑥Whether the "merge processor" completes the conversion process of inconsistent table structures in the source database and the destination database, child nodes, optional. The default is "Yes", when the structure of the table in the source database and the destination database are inconsistent, the "merge processor" will convert the structure of the table in the source database to make it the same as the structure of the table in the destination database; if it is "No" If , it means that the conversion is completed by the sql statement configured by the user or the "merge plug-in", and the "merge processor" does not participate in the conversion process.

⑦是否由“合并处理器”来完成修改后数据的合并流程,子节点,可选,默认为“是”,表示在“合并处理器”执行一系列用户配置的sql或“合并插件”来修改待合并数据之后,“合并处理器”最终将源数据库中的表内容简单追加到目的数据库的同名表中;如果配置为“否”,表示该表的合并过程已经在用户配置的sql或“合并插件”中完成,不再需要“合并处理器”参与,对于某些复杂的业务逻辑,不能通过简单追加的方式进行合并,则此时可以通过此方式屏蔽掉“合并处理器”的流程,完全由用户来主导某些表的合并流程;⑦Whether the merge process of the modified data is completed by the "merge processor", sub-node, optional, the default is "Yes", which means that the "merge processor" executes a series of user-configured sql or "merge plug-in" to modify After the data is to be merged, the "merge processor" will simply append the contents of the table in the source database to the table with the same name in the destination database; if the configuration is "No", it means that the merge process of the table has been configured in the user-configured sql or "merge "plug-in", no longer need "merge processor" to participate, for some complex business logic, can not be merged by simple appending, then you can block the process of "merge processor" in this way at this time, completely The merge process of some tables is led by the user;

⑧自增列及其对应序列名称,指定当前表中哪个列为自增列,子节点,可选。物理定义上的自增列,“合并处理器”可以从数据库管理系统的系统表中查询识别出来,所以用户即使不指定其具体列名称,也能自动处理;有些场景下,某列虽然没有定义成自增列,但是其使用序列或其他业务逻辑算法来实现类似的自增功能,“合并处理器”无法识别这种情况,因此必须由用户来指定对应列名称;如果使用了序列,还需要指定序列名称,“合并处理器”根据这两个个信息就能采用某些算法来自动修改该列的值,以避免违反自增列唯一性的约束,并同步序列的当前值;⑧Auto-increment column and its corresponding sequence name, specify which column in the current table is an auto-increment column, child node, optional. The auto-increment column in the physical definition can be identified by the "merge processor" from the system table of the database management system, so even if the user does not specify the specific column name, it can be automatically processed; in some scenarios, although a column is not defined As self-increment column, but it uses sequence or other business logic algorithm to achieve similar self-increment function, "merge processor" cannot recognize this situation, so the corresponding column name must be specified by the user; if sequence is used, also need Specify the sequence name, and the "merge processor" can use some algorithms to automatically modify the value of the column based on these two pieces of information, so as to avoid violating the uniqueness constraint of the auto-increment column and synchronize the current value of the sequence;

⑨自增列关联外键子表名称及列名称,为⑦的子节点,可选,可配置多个子节点。如果该表还有关联子表,通过父表自增列的唯一性来维护父子关系,则需要在父表策略中指定对应的子表名称和列名称,这样合并主程序在修改主表的自增列时能够自动修改关联子表的外键列;⑨The name and column name of the self-incrementing column-associated foreign key sub-table, which is a sub-node of ⑦, optional, and multiple sub-nodes can be configured. If the table has an associated child table, and the parent-child relationship is maintained through the uniqueness of the auto-increment column of the parent table, you need to specify the corresponding When adding a column, it can automatically modify the foreign key column of the associated subtable;

⑩需要禁用的触发器名称,可选,子节点,可配置多个子节点。由用户根据业务逻辑决定合并当前表的过程中是否禁用指定触发器,合并完成后恢复其原有状态。⑩The name of the trigger that needs to be disabled, optional, sub-node, multiple sub-nodes can be configured. It is up to the user to decide whether to disable the specified trigger during the process of merging the current table according to the business logic, and restore its original state after the merging 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), and (9) described above that require special handling. An example of xml configuration is given below:

<databasesource=”db1”destination="db1"><databasesource="db1"destination="db1">

<!--需要修改内容的合并表策略,name指定表名称,strategy指定策略类型,<! -- Merge table strategy that needs to be modified, name specifies the table name, strategy specifies the strategy type,

level指定优先级别,level specifies the priority level,

-->-->

<tablename="table_c"strategy="modify"level="1"><tablename="table_c" strategy="modify" level="1">

<!--sql语句,修改数据内容,删除源数据库中id重复的记录--><! --sql statement, modify the data content, delete the record with duplicate id in the source database -->

<sql>deletefrom%SOURCE(db1)%.table_cwhereidin(selectidfromdb1.table_c)</sql><sql>deletefrom%SOURCE(db1)%.table_cwhereidin(selectidfromdb1.table_c)</sql>

<!—合并插件名称--><! -- merge plugin name -->

<plugin>com.merge.plugin.table.test</plugin><plugin>com.merge.plugin.table.test</plugin>

<!--指定合并处理器来完成表结构差异的转换流程--><! -- Specify the merge processor to complete the conversion process of table structure differences -->

<transformByTool>true</transformByTool><transformByTool>true</transformByTool>

<!--指定合并处理器来完成修改后数据的合并流程--><! -- Specify the merge processor to complete the merge process of the modified data -->

<mergeByTool>true</mergeByTool><mergeByTool>true</mergeByTool>

<!—coluemn指定自增列名,sequence指定序列名称--><! --coluemn specifies the auto-increment column name, sequence specifies the sequence name -->

<identitycolumn=”c1”sequence=”seq1”><identitycolumn="c1"sequence="seq1">

<!—关联自增列的子表,指定源数据库名、表名、列名--><! —Associate the sub-table of the auto-increment column, specify the source database name, table name, column name-->

<childTabledb=”db1”name=”table_d”column=”cc1”></><childTabledb="db1" name="table_d"column="cc1"></>

</identity></identity>

<!--指定需要禁用的触发器名称--><! -- Specify the name of the trigger to be disabled -->

<disableTriggerdb=”db1”name=”tg1”></disableTrigger><disableTriggerdb="db1" name="tg1"></disableTrigger>

</table></table>

</database></database>

采用本发明所述方法,通过在源数据库所在的数据库管理系统中,对所有需要参与合并的数据库进行备份。设置连接目的数据库所在数据库管理系统的参数,以系统管理员身份登录进去。指定源数据库的备份文件路径,在目的数据库所在的数据库管理系统中,为每个源数据库创建临时数据库并恢复。解析策略配置文件。按照默认处理流程以及用户指定的合并策略并发合并完所有表。还原在合并过程中禁用的触发器状态。删除临时数据库。可以实现通用的数据库内容合并的流程。整体的合并流程由合并主程序来完成;对于无需特殊处理的表格,合并主程序默认将源数据库中的表记录追加到目的数据库中的同名表中;对于包含合并主程序无法识别的复杂业务逻辑数据的表格,由开发人员在策略配置文件中指定其合并策略,合并主程序按照其合并策略来进行数据的合并;绝大多数应用场景中,开发人员只需在策略配置文件中配置一些sql语句即可达到修改无法直接合并的表数据的目的,在极端复杂的应用场景中,开发人员可以把自己编码实现的二次开发插件整合到合并流程中;另外,合并装置采用了并发线程的处理机制,提高合并的处理速度。By adopting the method of the present invention, all databases that need to be merged are backed up in the database management system where the source database is located. Set the parameters of the database management system where the connection target database is located, and log in as a system administrator. Specify the backup file path of the source database, and create and restore a temporary database for each source database in the database management system where the target database is located. Parse policy configuration files. Merge all tables concurrently according to the default processing flow and user-specified merge strategy. Restores the state of triggers that were disabled during the merge. Delete the temporary database. A common flow of database content merging can be implemented. The overall merging process is completed by the merging main program; for tables that do not require special processing, the merging main program will append the table records in the source database to the table with the same name in the destination database by default; for complex business logic that cannot be recognized by the merging main program For the data table, the developer specifies its merging strategy in the strategy configuration file, and the merging main program merges the data according to its merging strategy; in most application scenarios, developers only need to configure some sql statements in the strategy configuration file The purpose of modifying table data that cannot be directly merged can be achieved. In extremely complex application scenarios, developers can integrate the secondary development plug-in implemented by their own coding into the merge process; in addition, the merge device adopts a concurrent thread processing mechanism , to improve the processing speed of merging.

本发明的实施例还提供一种数据库内容合并装置,包括:Embodiments of the present invention also provide a database content merging device, including:

建立模块,用于建立源数据库对应的镜像数据库,所述镜像数据库中与所述源数据库相同;Establishing a module for establishing 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, according to the merging strategy corresponding to the source table in the mirror database, merge table information between the source table of the mirror database and the destination table in the destination database that needs to be merged with the source table.

其中,建立模块包括:Among them, building modules include:

备份子模块,用于备份源数据库,得到携带有表格信息的备份文件;The backup sub-module is used to back up the source database to obtain a backup file carrying table information;

连接子模块,用于选取目的数据库所属的数据库管理系统;The connection sub-module is used to select the database management system to which the target database belongs;

建立子模块,用于在所述数据库管理系统中建立所述源数据库对应的镜像数据库,并将所述备份文件中携带的表格信息添加到所述镜像数据库中。The establishment sub-module is used to establish a mirror database corresponding to the source database in the database management system, and add the table information carried in the backup file to the mirror database.

其中,合并模块包括:Among them, the merge module includes:

获取子模块,用于获取配置文件中的所述镜像数据库中的源表格对应的合并策略;The obtaining submodule is used to obtain the merge strategy corresponding to the source table in the mirror database in the configuration file;

合并子模块,用于当合并策略中有检测策略时,根据所述检测策略的名称,选取sql语句和/或合并插件检测镜像数据库和目的数据库中的表格能否进行表格信息合并,若检测成功,则根据所述合并策略中的表格合并策略,对所述镜像数据库的源表格,与目的数据库中需要与所述源表格进行合并的目的表格,进行表格信息合并。The merging submodule is used for when there is a detection strategy in the merging strategy, according to the name of the detection strategy, select the sql statement and/or the merging plug-in to detect whether the tables in the mirror database and the destination database can perform table information merging, 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 device is a device corresponding to the above-mentioned method, and all the implementation modes in the above-mentioned method embodiments are applicable to the embodiments of the device, and can also achieve the same technical effect.

具体的,如图4所示,该装置的具体构架如下:Specifically, as shown in Figure 4, the specific framework of the device is as follows:

上述的合并模块具体可以是合并处理器,合并处理器内置默认的合并处理流程,以及一套备选通用的合并策略处理流程;“合并主程序”负责解析系统中包含的所有“合并策略”信息,对于系统中没有指定“合并策略”的表,使用默认流程进行合并,对于指定了“合并策略”的表,使用该“合并策略”对应的处理流程进行合并。它不应该依赖具体某一个应用软件的业务逻辑,而只是仅仅从数据库的角度来处理数据合并;The above-mentioned merging module can specifically be a merging processor, which has a built-in default merging process flow and a set of alternative general merging strategy processing flows; the "merging main program" is responsible for parsing all the "merging strategy" information contained in the system , for tables that do not specify a "merge strategy" in the system, use the default process for merging, and for tables that specify a "merge strategy", use the process flow corresponding to the "merge strategy" for merging. It should not rely on the business logic of a specific application software, but only handle data merging from the perspective of the database;

合并策略,某些表无法通过默认处理流程正确的进行合并,则需要用户指定特殊的表格合并策略,使“合并处理器”按照此表格合并策略来进行数据合并;表格合并策略的语法定义同样不应该依赖具体某一个应用软件的业务逻辑,而是提供各种应用软件可以通用的表格合并策略。Merge strategy, some tables cannot be merged correctly through the default processing flow, users need to specify a special table merge strategy, so that the "merge processor" performs data merge according to this table merge strategy; the syntax definition of the table merge strategy is also different It should rely on the business logic of a specific application software, but provide a common table merging strategy for various application software.

合并插件,某些表的业务逻辑合并流程的复杂程度超出了“合并主程序”能够处理的范围,需要用户在“合并策略”中指定该表对应的“合并插件”,供“合并主程序”调用该插件来完成合并工作;“合并插件”由用户按照合并装置定义的标准接口来实现。Merge plug-in, the complexity of the business logic merge process of some tables is beyond the range that the "merge main program" can handle, and the user needs to specify the "merge plug-in" corresponding to the table in the "merge strategy" for the "merge main program" Call the plug-in to complete the merge work; the "merge plug-in" is implemented by the user according to the standard interface defined by the merge device.

例如,合并数据库A和数据库A'的内容,合并装置以数据库A为源数据库,以数据库A'为目的数据库,合并后的最终结果体现在目的数据库A'上。针对以下几种场景,“合并处理器“有默认的处理流程:For example, to merge the contents of database A and database A', the merging device uses database A as the source database and database A' as the destination database, and the final merged result is reflected 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里面;Scenario 1: Table a in source database A has a corresponding table a in destination database A' with the same table structure. In this case, all records in table a in source database A are appended by default. Go to the table a in the destination database A';

第二种场景:源数据库A中的表a,在目的数据库A'中有与之对应的表a,且表结构不相同(如果设计合理,应用程序应该尽量避免出现此情况),这种情况下,默认需要转换源数据库A中表a的结构,使之与目的数据库A'中表a的结构相同(前提条件是应用程序允许这种转换),然后再以第一种场景的方式进行合并;转换表结构的处理流程,可以由合并处理器按照数据库系统表中获取的表信息的差异来自动处理,也可以根据用户配置的合并策略来处理。The second scenario: table a in the source database A has a corresponding table a in the destination database A', and the table structure is different (if the design is reasonable, the application should try to avoid this situation), this situation By default, the structure of table a in the source database A needs to be converted to make it the same as the structure of table a in the destination database A' (the prerequisite is that the application allows this conversion), and then merge in the first scenario ; The processing flow of converting the table structure can be processed automatically by the merge processor according to the difference of the table information obtained from the database system table, or according to the merge strategy configured by the user.

第三种场景:源数据库A中的表a,在目的数据库A'中没有与之对应的表a,这种情况下,合并处理器在目的数据库A'中创建与之同名且结构相同的表,之后再以第(1)种场景的方式进行合并;The third scenario: 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 them in the way of the (1) scenario;

第四种场景:目的数据库A'中的表a,在源数据库A中没有与之对应的表a,这种情况下,默认无需进行任何合并。The fourth scenario: table a in the target database A' has no corresponding table a in the source database A. In this case, no merging is required by default.

可以看出,上面四种场景,第四种场景可以忽略掉,其他三种都可以转化为第一种场景来处理。但是第一种场景默认的处理方式是最简单的合并方式(这也是数据库管理系统自带数据迁移工具的处理方式),无法适应复杂的业务逻辑,所以还需要用户配置一些“合并策略”来对合并流程进行干预。It can be seen that among the above four scenarios, the fourth scenario can be ignored, and the other three can be transformed into the first scenario for processing. However, the default processing method of the first scenario is the simplest merge method (this is also the processing method of the built-in data migration tool of the database management system), which cannot adapt to complex business logic, so users need to configure some "merge strategies" to Merge process to intervene.

合并过程中需要指定“合并策略”的特殊合并流程的场景大致有以下几种:Scenarios of a special merge process that require specifying a "merge strategy" during the merge process generally include the following:

(1)合并前需要先进行检测,识别出一些无法合并的应用场景。比如在学生登记信息管理系统中,不允许出现身份证号码完全相同的两条及以上的学生记录,如果合并之前检测到待合并的两套数据库内容中包含这种冲突的情况,应该禁止进行后续的合并流程;又比如,两个待合并的数据库内容是由不同版本的应用软件所产生的,数据结构不兼容,也不应该进行合并。(1) Before merging, detection is required to identify some application scenarios that cannot be merged. For example, in the student registration information management system, two or more student records with identical ID numbers are not allowed to appear. If such conflicts are detected in the contents of the two databases to be merged before the merger, follow-up should be prohibited. The merging process; for another example, the contents of two databases to be merged are generated by different versions of application software, and the data structures are incompatible, so they should not be merged.

(2)有些表不需要参与合并。一些保存初始化数据的表,在每套数据库内容中都必然存在相同的数据,而且只需要保留目的数据库中的一份内容即可,这类表不应该参与合并;比如,学生登记信息管理系统中有一个用于保存学生干部职位种类的表,在每个系统安装时,初始化数据库阶段就自动填入了所有学生干部职位种类的记录,系统运行期间也不会再对该表进行增删改操作;那么在合并时,如果把源数据库中该表记录合并到目的数据库中,会导致该表中存在两套重复的记录,进而导致业务逻辑错误,因此不应该合并该表。(2) Some tables do not need to participate in the merge. Some tables that store initialized data must have the same data in each set of database content, and only one content in the target database needs to be reserved. Such tables should not participate in the merger; for example, in the student registration information management system There is a table used to save the types of student cadre positions. When each system is installed, the records of all student cadre position types are automatically filled in during the database initialization stage, and the table will not be added, deleted or modified during the system operation; Then when merging, if the table records in the source database are merged 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 definition of some tables in the source database is inconsistent with the definition in the destination database, and needs to be converted to be consistent before merging.

(4)有些表只需要合并源数据库中的部分内容,而不是全部内容。同样以学生登记信息管理系统中用于保存学生干部职位种类的表为例,如果该表中有一部分记录是在系统安装初始化数据库时自动填入的,系统运行期间不会对这部分记录做删除和修改操作,但是可能会新增一些用户输入的干部职位种类记录;在合并时,应该合并源数据库中用户新增的记录,而不应该合并系统安装时初始化的记录;在更复杂的情况下,如果系统运行期间对该表的初始化数据也会做删除和修改操作,那么理论上应该把所有源数据库与目的数据库中干部职位名称不相同的记录都合并到目的数据库中,而干部职位名称相同的记录不应该合并。(4) Some tables only need to merge part of the content in the source database, not all of the content. Also take the table used to store student cadre positions in the student registration information management system as an example. If some records in this table are automatically filled in when the system is installed and initialized the database, these records will not be deleted during system operation. and modification operations, but some records of cadre position types input by users may be added; when merging, the records added by users in the source database should be merged instead of the records initialized during system installation; in more complicated cases , if the initialization data of the table will also be deleted and modified during system operation, then theoretically all records with different cadre position names in the source database and the target database should be merged into the target database, but the cadre position names are the same records should not be merged.

(5)有些表在合并时可能违反数据约束——比如主键冲突、违反唯一性约束等(表结构定义或业务逻辑上的约束,都可以看做违反数据约束)。对于违反数据约束的记录,应用软件的业务逻辑不同,采取的策略也可能不同;用户可以选择删除源数据库中违反约束的记录后再进行合并,也可以选择修改源数据库中违反约束的记录后再进行合并。(5) Some tables may violate data constraints when merging - such as primary key conflicts, violations of unique constraints, etc. (Table structure definition or business logic constraints can be regarded as violations of data constraints). For records that violate data constraints, the business logic of the application software is different, and the strategies adopted may be different; users can choose to delete the records that violate the constraints in the source database before merging, or choose to modify the records that violate the constraints in the source database before merging. to merge.

(6)有些表使用了自增列(或序列),合并时可能存在冲突的ID。可以将源数据库中的自增列(或使用序列的列)统一加上一个固定值,就可以消除冲突的ID,然后再进行合并操作;这个固定值的获取,可以采用此算法:固定值=目的数据库中该列最大值+1-源数据库中该列最小值;对于自增列,在合并记录时应该开启自增列插入特性,这样才可保留插入记录的ID值;对于序列,因为其不会自动与表记录同步,所以还应该调整目的数据库中序列的当前值,也加上相同的固定值。(6) Some tables use self-incrementing columns (or sequences), and there may be conflicting IDs when merging. You can uniformly add a fixed value to the self-incrementing columns (or columns using sequences) in the source database to eliminate conflicting IDs, and then perform the merge operation; this algorithm can be used to obtain this fixed value: fixed value = The maximum value of the column in the destination database + 1 - the minimum value of the column in the source database; for auto-increment columns, the auto-increment column insertion feature should be enabled when merging records, so that the ID value of the inserted record can be retained; for sequences, because its It will not be automatically synchronized with the table records, so the current value of the sequence in the destination database should also be adjusted, and the same fixed value should also be added.

(7)有些表存在父子依赖关系——比如外键依赖等(表结构定义或业务逻辑上的依赖,都可以看做存在依赖关系),且被依赖父表的相关内容在合并时做了增删改操作——比如前面所述的第(4)种和第(5)种场景,那么依赖子表也应该做相应的修改,以便继续满足原有的依赖关系;以第(6)种场景中自增列为外键的依赖关系为例,如果被依赖父表的自增列在合并时加上了一个避免约束冲突的固定值,那么依赖子表的关联列在合并时也需要加上相同的固定值。(7) Some tables have parent-child dependencies—such as foreign key dependencies, etc. (table structure definition or business logic dependencies can be regarded as dependencies), and the relevant content of the dependent parent table is added when merging Deletion operation - such as the above-mentioned (4) and (5) scenarios, then the dependent sub-table should also be modified accordingly so as to continue to meet the original dependencies; in the (6) scenario For example, if the auto-increment column is a foreign key dependency, if the auto-increment column of the dependent parent table is added with a fixed value to avoid constraint conflicts when merging, then the associated column of the dependent child table also needs to be added with the same value when merging. fixed value.

(8)有些数据库或表在合并顺序上存在先后依赖关系,需要对其指定一个优先级别。默认情况下,为了提高合并的速度,对于同一优先级别的表,合并装置应该以并发方式进行多表的合并处理,这些表之间不存在谁先谁后的顺序;如果某些表指定了更高的优先级,则应该先进行合并,待该优先级下所有表格合并完毕后,才能进行优先级更低的表的合并流程。(8) Some databases or tables have sequential dependencies in the order of merging, and a priority level needs to be assigned to them. By default, in order to improve the speed of merging, for tables of the same priority level, the merging device should perform multi-table merging processing in a concurrent manner, and there is no order of who comes first among these tables; if some tables specify a higher If the priority is higher, it should be merged first. After all the tables under this priority are merged, the process of merging the tables with lower priority can be carried out.

(9)有些表使用了触发器,需要根据业务逻辑的不同来决定是否禁用触发器。比如,在有的应用软件中,使用触发器加序列的方式来模拟自增列的效果(oracle中没有自增列的概念),往对应表中每插入一条记录,就会自动调用触发器的逻辑,修改其ID为序列的递增整数;在合并该表时,如果该表没有被其他表依赖,则可以放心使用目的数据库中触发器的功能来自动为合并的记录生成递增ID;如果该表被其他表依赖,则推荐暂时禁用目的数据库中的触发器,而是使用第(6)种场景中描述的方式来合并记录,合并完毕后再还原目的数据库中的触发器状态,这么做的好处是在合并依赖子表时,只需要简单对依赖子表的关联列加上相同的固定值即可,效率更高,处理流程也更简单。(9) Some tables use triggers, and it is necessary to decide whether to disable triggers according to different business logics. For example, in some application software, the effect of adding a sequence to a trigger is used to simulate the effect of an auto-increment column (there is no concept of an auto-increment column in Oracle), and each time a record is inserted into the corresponding table, the trigger will be automatically invoked. Logic, modify its ID to a sequence of incremental integers; when merging the table, if the table is not dependent on other tables, you can safely use the trigger function in the destination database to automatically generate an incremental ID for the merged record; if the table If it is dependent on other tables, it is recommended to temporarily disable the triggers in the destination database. Instead, use the method described in the (6) scenario to merge records, and then restore the trigger status in the destination database after the merger is complete. The benefits of doing so When merging dependent subtables, you only need to simply add the same fixed value to the associated columns of the 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 default process of converting the table structure of the source database by 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 types of merging, the user needs to specify the merging strategy definition corresponding to the specific table in the "Merging Strategy". If no merging strategy is specified for the table, all the records of the table in the source database will be appended to the destination database by default. inside the table.

另外,上面各种应用场景,绝大多数情况下,通过执行sql语句就能够实现,比如第一种场景下进行合并前的检测过程,通常只需要执行一些跨库的连接查询即可判断出来;但是如果源数据库和目的数据库不在同一个数据库管理系统中,则单纯使用sql语句很难实现该检测功能,还需要用户去实现专门的“合并插件”来完成此功能,这样就会增加用户使用合并装置的难度;因此,为了简化合并过程,尽量使用户只需要了解sql知识就能完成大多数合并功能,就需要将源数据库和目的数据库整合在同一个数据库管理系统中,因此,本合并装置在工作时的首要步骤即为:In addition, in most cases, the various application scenarios above can be realized by executing SQL statements. For example, in the first scenario, the detection process before merging usually only needs to execute some cross-database connection queries to determine; 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 simply by using SQL statements, and the user needs to implement a special "merge plug-in" to complete this function, which will increase the user's use of merge The difficulty of installation; therefore, in order to simplify the merging process and make the user only need to understand sql knowledge to complete most of the merging functions, it is necessary to integrate the source database and the target database in the same database management system. Therefore, this merging device is in The first steps at 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 methods), and then uses the temporary mirror database as the source database . This enables users to simultaneously access the source and destination databases in SQL statements.

针对上面所述的几种需要指定“合并策略”的特殊合并流程的场景,本合并装置总结出对应的合并策略,并将其功能内置在“合并处理器”中,供用户以各种配置文件为载体来设定某些特殊表的“合并策略”。主要有以下几种合并策略:Aiming at the above-mentioned scenarios that need to specify the special merging process of the "merging strategy", this merging device summarizes the corresponding merging strategy, and builds its functions into the "merging processor" for users to use various configuration files Set the "merge strategy" of some special tables for the carrier. There are mainly the following merging strategies:

(1)数据库策略,指定需要参与合并的数据库名称,如果有多个数据库需要进行合并,则需要配置多条数据库策略。该策略包含以下内容:(1) Database strategy, specify the name of the database that needs to be merged. If there are multiple databases that need to be merged, you need to configure multiple database strategies. The policy includes the following:

①源数据库名称;①The name of the source database;

②目的数据库名称;②The name of the target database;

③优先级别,可选,如果不指定优先级别,默认为最低级别;因为数据库的合并最后都要转化为数据库的子元素的合并,因此数据库优先级的设定值,会被其子元素继承,优先级高的子元素先合并,优先级低的子元素后合并,相同优先级的子元素可以并发进行合并。③Priority level, optional, if no priority level is specified, it will be the lowest level by default; because the merging of databases will eventually be converted into the merging of sub-elements of the database, the set value of the priority of the database will be inherited by its sub-elements, Sub-elements with high priority are merged first, sub-elements with low priority are merged later, and sub-elements with the same priority can be merged concurrently.

下面给出一个xml配置的例子:An example of xml configuration is given below:

<!--数据库策略:指定需要参与合并的源和目的数据库名称—><! --Database strategy: Specify the source and destination database names that need to participate in the merge —>

<databasesource=”db1”destination="db1"><databasesource="db1"destination="db1">

</database></database>

<!--level指定优先级别,值越大级别越高,不指定则默认为0--><! --level specifies the priority level, the larger the value, the higher the level, if not specified, the default is 0-->

<databasesource=”db2”destination="db2"level="1"><databasesource="db2"destination="db2"level="1">

</database></database>

(2)检测策略,可选,可配置多个检测策略,包含以下内容:(2) Detection strategy, optional, multiple detection strategies can be configured, including the following:

①策略名称,可选;有些“合并插件”可能需要识别这个名称,根据该名称的不同来实现不同的处理流程;①Strategy name, optional; some "merge plug-ins" may need to recognize this name, and implement different processing procedures according to the name;

②检测不通过的提示信息,用于“合并处理器”记录日志或在显示给用户;②Prompt message for failed detection, used for "merge processor" to record logs or display to users;

③sql语句,子节点,可选,可配置多个子节点,约定返回某个值即为检测失败;③sql statement, sub-node, optional, multiple sub-nodes can be configured, and it is agreed that the detection fails if a certain value is returned;

注意:对于sql需要重点说明一下,绝大多数情况下用户配置的sql需要同时访问源数据库和目的数据库,但是由于本合并装置是以临时镜像数据库来代替源数据库,所以真正的源数据库名称应该是临时镜像数据库名称,为了避免临时数据库名称与目的数据库中的数据库名称出现重名冲突(一个数据库管理系统中无法创建两个同名的数据库),合并装置可以使用某种算法生成某个唯一字符串来作为该临时镜像数据库的名称,对于用户来说是无法预知的,因此在sql语句中指定源数据库名称时,不要使用真实的数据库名称,而是以宏定义的方式来代替,例如使用%SOURCE(db1)%来表示源数据库db1的临时镜像数据库名称,“合并处理器”在执行sql时会将这种宏定义自动替换为实际的数据库名称。Note: It is important to explain about sql. In most cases, the sql configured by the user needs to access the source database and the destination database at the same time. However, since this merging device replaces the source database with a temporary mirror database, the real name of the source database should be Temporary mirror database name, in order to avoid duplicate name conflicts between the temporary database name and the database name in the destination database (two databases with the same name cannot be created in one database management system), the merging device can use a certain algorithm to generate a certain unique string to As the name of the temporary mirror database, it is unpredictable for the user, so when specifying the name of the source database in the sql statement, do not use the real database name, but replace it with a macro definition, for example, use %SOURCE( db1)% to represent 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语句无法检测的情况下,供“合并处理器”调用用户实现的“合并插件”进行检测;通常情况下,合并插件名称为用户实现的二次开发类名。④Merge plug-in name, optional, used for the "merge processor" to call the user-implemented "merge plug-in" for detection when the sql statement cannot be detected; usually, the name of the merge plug-in is the secondary development implemented by the user class name.

③和④可任选其一,也可以同时存在,任意一个返回失败,则表示检测失败。③ and ④ can choose one of them, and they can also exist at the same time. If any one returns a failure, it means that the detection fails.

此策略针对本文上面所述的需要特殊处理的场景(1)。下面给出一个xml配置的例子:This strategy addresses the scenario (1) described above in this article that requires special handling. An example of xml configuration is given below:

(3)表的不合并策略,为数据库策略的子节点,包含以下内容:(3) The non-merging strategy of the table is a child node of the database strategy, including the following content:

①表名称,指定该策略对应的具体表;① Table name, specify the specific table corresponding to the strategy;

②策略类型,为“不合并”类型。②Strategy type, which is the "non-merge" type.

此策略针对本文上面所述的需要特殊处理的场景(2),指定的表不参与合并,仅保留目的数据库中的同名表数据。下面给出一个xml配置的例子:This strategy is aimed at the scenario (2) that requires special handling described above in this article. The specified table does not participate in the merge, and only the data of the table with the same name in the destination database is retained. An example of xml configuration is given below:

(4)表的修改内容合并策略,为数据库策略的子节点,用于在合并过程中修改待合并数据,包含以下内容:(4) The modification content of the table The merge strategy is a child node of the database strategy, which is used to modify the data to be merged during the merge process, including the following content:

①表名称,指定该策略对应的具体表;① Table name, specify the specific table corresponding to the strategy;

②策略类型,为“修改”类型;②Strategy type, which is "Modify" type;

③优先级别,可选,如果不指定优先级别,默认为继承父节点数据库的优先级别,优先级别高的表合并完成后,才能合并优先级别低的表。对于有外键依赖关系的表,“合并处理器”从数据库管理系统的系统表中可以自动识别出来,然后自动设置优先级,可以不需要用户进行优先级设置。③Priority level, optional. If no priority level is specified, the default is to inherit the priority level of the parent node database. After the table with high priority level is merged, the table with low priority level can be merged. For tables with foreign key dependencies, the "merge processor" can automatically identify them from the system tables of the database management system, and then automatically set the priority, which does not require the user to set the priority.

④sql语句,子节点,可选,可配置多个子节点,用于修改源数据库或目的数据库中的表结构或数据内容(不仅仅局限于修改当前处理的表,也可以修改其他关联依赖表);④sql statement, sub-node, optional, multiple sub-nodes can be configured, used to modify the table structure or data content in the source database or the destination database (not only limited to modifying the currently processed table, but also other associated dependent tables);

⑤合并插件名称,子节点,可选,可配置多个子节点,用于合并之前在sql语句无法处理的复杂业务逻辑的情况下,供合并主程序调用用户实现的二次开发合并插件进行处理;⑤Merge plug-in name, sub-node, optional, multiple sub-nodes can be configured, used for merging the main program to call the secondary development merging plug-in implemented by the user in the case of complex business logic that cannot be processed by the sql statement before merging;

⑥是否由“合并处理器”来完成源数据库和目的数据库中表结构不一致的转换流程,子节点,可选。默认为“是”,在源数据库和目的数据库中该表结构不一致时,由“合并处理器”来转换源数据库中表的结构,使之与目的数据库中表的结构相同;如果为“否”的话,表示该转换由用户配置的sql语句或“合并插件”来完成,“合并处理器”不参与转换流程。⑥Whether the "merge processor" completes the conversion process of inconsistent table structures in the source database and the destination database, child nodes, optional. The default is "Yes", when the structure of the table in the source database and the destination database are inconsistent, the "merge processor" will convert the structure of the table in the source database to make it the same as the structure of the table in the destination database; if it is "No" If , it means that the conversion is completed by the sql statement configured by the user or the "merge plug-in", and the "merge processor" does not participate in the conversion process.

⑦是否由“合并处理器”来完成修改后数据的合并流程,子节点,可选,默认为“是”,表示在“合并处理器”执行一系列用户配置的sql或“合并插件”来修改待合并数据之后,“合并处理器”最终将源数据库中的表内容简单追加到目的数据库的同名表中;如果配置为“否”,表示该表的合并过程已经在用户配置的sql或“合并插件”中完成,不再需要“合并处理器”参与,对于某些复杂的业务逻辑,不能通过简单追加的方式进行合并,则此时可以通过此方式屏蔽掉“合并处理器”的流程,完全由用户来主导某些表的合并流程;⑦Whether the merge process of the modified data is completed by the "merge processor", sub-node, optional, the default is "Yes", which means that the "merge processor" executes a series of user-configured sql or "merge plug-in" to modify After the data is to be merged, the "merge processor" will simply append the contents of the table in the source database to the table with the same name in the destination database; if the configuration is "No", it means that the merge process of the table has been configured in the user-configured sql or "merge "plug-in", no longer need "merge processor" to participate, for some complex business logic, can not be merged by simple appending, then you can block the process of "merge processor" in this way at this time, completely The merge process of some tables is led by the user;

⑧自增列及其对应序列名称,指定当前表中哪个列为自增列,子节点,可选。物理定义上的自增列,“合并处理器”可以从数据库管理系统的系统表中查询识别出来,所以用户即使不指定其具体列名称,也能自动处理;有些场景下,某列虽然没有定义成自增列,但是其使用序列或其他业务逻辑算法来实现类似的自增功能,“合并处理器”无法识别这种情况,因此必须由用户来指定对应列名称;如果使用了序列,还需要指定序列名称,“合并处理器”根据这两个个信息就能采用某些算法来自动修改该列的值,以避免违反自增列唯一性的约束,并同步序列的当前值;⑧Auto-increment column and its corresponding sequence name, specify which column in the current table is an auto-increment column, child node, optional. The auto-increment column in the physical definition can be identified by the "merge processor" from the system table of the database management system, so even if the user does not specify the specific column name, it can be automatically processed; in some scenarios, although a column is not defined As self-increment column, but it uses sequence or other business logic algorithm to achieve similar self-increment function, "merge processor" cannot recognize this situation, so the corresponding column name must be specified by the user; if sequence is used, also need Specify the sequence name, and the "merge processor" can use some algorithms to automatically modify the value of the column based on these two pieces of information, so as to avoid violating the uniqueness constraint of the auto-increment column and synchronize the current value of the sequence;

⑨自增列关联外键子表名称及列名称,为⑦的子节点,可选,可配置多个子节点。如果该表还有关联子表,通过父表自增列的唯一性来维护父子关系,则需要在父表策略中指定对应的子表名称和列名称,这样合并主程序在修改主表的自增列时能够自动修改关联子表的外键列;⑨The name and column name of the self-incrementing column-associated foreign key sub-table, which is a sub-node of ⑦, optional, and multiple sub-nodes can be configured. If the table has an associated child table, and the parent-child relationship is maintained through the uniqueness of the auto-increment column of the parent table, you need to specify the corresponding When adding a column, it can automatically modify the foreign key column of the associated subtable;

⑩需要禁用的触发器名称,可选,子节点,可配置多个子节点。由用户根据业务逻辑决定合并当前表的过程中是否禁用指定触发器,合并完成后恢复其原有状态。⑩The name of the trigger that needs to be disabled, optional, sub-node, multiple sub-nodes can be configured. It is up to the user to decide whether to disable the specified trigger during the process of merging the current table according to the business logic, and restore its original state after the merging is completed.

本发明的该装置可以实现通用的数据库内容合并的流程。整体的合并流程由合并主程序来完成;对于无需特殊处理的表格,合并主程序默认将源数据库中的表记录追加到目的数据库中的同名表中;对于包含合并主程序无法识别的复杂业务逻辑数据的表格,由开发人员在策略配置文件中指定其合并策略,合并主程序按照其合并策略来进行数据的合并;绝大多数应用场景中,开发人员只需在策略配置文件中配置一些sql语句即可达到修改无法直接合并的表数据的目的,在极端复杂的应用场景中,开发人员可以把自己编码实现的二次开发插件整合到合并流程中;另外,合并装置采用了并发线程的处理机制,提高合并的处理速度。The device of the present invention can realize the common flow of database content merging. The overall merging process is completed by the merging main program; for tables that do not require special processing, the merging main program will append the table records in the source database to the table with the same name in the destination database by default; for complex business logic that cannot be recognized by the merging main program For the data table, the developer specifies its merging strategy in the strategy configuration file, and the merging main program merges the data according to its merging strategy; in most application scenarios, developers only need to configure some sql statements in the strategy configuration file The purpose of modifying table data that cannot be directly merged can be achieved. In extremely complex application scenarios, developers can integrate the secondary development plug-in implemented by their own coding into the merge process; in addition, the merge device adopts a concurrent thread processing mechanism , to improve the processing speed of merging.

以上所述仅是本发明的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本发明的保护范围。The above is only a preferred embodiment of the present invention, it should be pointed out that, for those of ordinary skill in the art, without departing from the principle of the present invention, some improvements and modifications can also be made, and these improvements and modifications can also be made. It should be regarded as the protection scope of the present invention.

Claims (13)

1. a data-base content merging method, is characterized in that, comprising:
Set up the mirror database that source database is corresponding, identical with described source database in described mirror database;
The consolidation strategy corresponding according to the source form in described mirror database, to the source form of described mirror database, the object form with needing in destination data storehouse to carry out with described source form merging, carries out form data merging.
2. the method for claim 1, is characterized in that, the described step setting up mirror database corresponding to source database comprises:
Backup source database, obtains the backup file carrying form data;
Choose the data base management system (DBMS) belonging to destination data storehouse;
In described data base management system (DBMS), set up mirror database corresponding to described source database, and the form data of carrying in described backup file is added in described mirror database.
3. the method for claim 1, it is characterized in that, the described consolidation strategy corresponding according to the source form in described mirror database, to the source form of described mirror database, with the object form needing in destination data storehouse to carry out with described source form merging, the step of carrying out form data merging comprises:
The consolidation strategy that source form in described mirror database in acquisition configuration file is corresponding;
When there being inspection policies in consolidation strategy, according to described inspection policies, choose sql statement and/or merge the form that plug-in unit detects in mirror database and destination data storehouse and can carry out form data merging, if detect successfully, then according to the form consolidation strategy in described consolidation strategy, to the source form of described mirror database, the object form with needing in destination data storehouse to carry out with described source form merging, carries out form data merging.
4. method as claimed in claim 3, it is characterized in that, according to the form consolidation strategy in described consolidation strategy, to the source form of described mirror database, with the object form needing in destination data storehouse to carry out with described source form merging, the step of carrying out form data merging comprises:
To obtain in mirror database the set of active form;
Set up in the set of source form the form needing to carry out with the object form in destination data storehouse merging, with the corresponding relation of form consolidation strategy;
According to priority order carries out form data merging to the object form in source form and destination data storehouse.
5. method as claimed in claim 4, it is characterized in that, the step of the object form in source form and destination data storehouse being carried out to form data merging comprises:
The form consolidation strategy that source form in the set of acquisition source form is corresponding;
If described form consolidation strategy is for specifying consolidation strategy and specifying consolidation strategy type for merging or being amendment strategy, then judge in destination data storehouse, whether to there is the object form of the same name with source form, if exist, then to source form and and source form object form of the same name carry out form data merging, otherwise, in destination data storehouse, create the object form of the same name with source form, then form data merging is carried out to source form and object form.
6. method according to claim 5, is characterized in that, the step of source form and object form being carried out to form data merging comprises:
Judge that whether source form is consistent with the list structure of object form, if, according to the appointment consolidation strategy of described source form, form data merging is carried out to source form and object form, otherwise, the list structure of source form is converted to consistent with the list structure of object form after, then according to the appointment consolidation strategy of described source form, form data merging is carried out to source form and object form.
7. method according to claim 6, is characterized in that, according to the appointment consolidation strategy of described source form, the step of source form and object form being carried out to form data merging comprises:
If described source form does not specify consolidation strategy, obtain the record sum of source form;
If the record sum of described source form is not 0, performs and insert statement, all records in the form of source are inserted in object form.
8. method according to claim 6, is characterized in that, according to the appointment consolidation strategy of described source form, the step of source form and object form being carried out to form data merging comprises:
If described source form has appointment consolidation strategy, then by appointment consolidation strategy, source form is modified, obtain the record of amended source form;
The record of this amended source form is inserted in object form.
9. method according to claim 8, is characterized in that, modifies to source form, and the step obtaining the record of amended source form comprises:
The record of the record or major key conflict of violating constraint rule in the form of described source is modified or deleted, obtains the record of amended source form; Or
To in the form of described source certainly add or sequence adds a fixed value, obtain the record of amended source form; Or
There is external key to described source form to rely on, when modifying to dependence parent table, dependence sublist also being carried out to the amendment of related content, obtaining the record of amended source form.
10. method according to claim 8, is characterized in that, the step that the record of this amended source form is inserted in object form is comprised:
If object form employs trigger and object form is not relied on by other table, then, when inserting the record of source form in object form, what utilize trigger automatically to generate record increases progressively ID; Otherwise when inserting the record of source form in object form, forbid described trigger, after at record, insertion completes, then to recover trigger be state before merging.
11. 1 kinds of data-base contents merge device, it is characterized in that, comprising:
Set up module, for setting up mirror database corresponding to source database, identical with described source database in described mirror database;
Merge module, for the consolidation strategy corresponding according to the source form in described mirror database, to the source form of described mirror database, the object form with needing in destination data storehouse to carry out with described source form merging, carries out form data merging.
12. devices as claimed in claim 11, is characterized in that, set up module and comprise:
Backup submodule, for backup source database, obtains the backup file carrying form data;
Connexon module, for choosing the data base management system (DBMS) belonging to destination data storehouse;
Setting up submodule, for setting up mirror database corresponding to described source database in described data base management system (DBMS), and the form data of carrying in described backup file being added in described mirror database.
13. devices as claimed in claim 11, is characterized in that, merge module and comprise:
Obtain submodule, for obtaining consolidation strategy corresponding to source form in the described mirror database in configuration file;
Merge submodule, for when there being inspection policies in consolidation strategy, according to described inspection policies, choose sql statement and/or merge the form that plug-in unit detects in mirror database and destination data storehouse and can carry out form data merging, if detect successfully, then according to the form consolidation strategy in described consolidation strategy, to the source form of described mirror database, object form with needing in destination data storehouse to carry out with described source form merging, carries out form data merging.
CN201410339322.9A 2014-07-16 2014-07-16 A kind of database content merging method and device Active CN105320681B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201410339322.9A CN105320681B (en) 2014-07-16 2014-07-16 A kind of database content merging method and device
PCT/CN2014/090271 WO2015117429A1 (en) 2014-07-16 2014-11-04 Method and device for merging database contents

Applications Claiming Priority (1)

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

Publications (2)

Publication Number Publication Date
CN105320681A true CN105320681A (en) 2016-02-10
CN105320681B CN105320681B (en) 2020-06-30

Family

ID=53777244

Family Applications (1)

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

Country Status (2)

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

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108205559A (en) * 2016-12-19 2018-06-26 腾讯科技(深圳)有限公司 A kind of data managing method and its equipment
CN110334098A (en) * 2019-06-27 2019-10-15 烽火通信科技股份有限公司 A kind of database combining method and system based on script
CN110532254A (en) * 2018-05-25 2019-12-03 杭州海康威视数字技术股份有限公司 Method and device for fusing data tables
WO2020125537A1 (en) * 2018-12-17 2020-06-25 中兴通讯股份有限公司 Database component merge into function compatibility method, device and storage medium
CN114428773A (en) * 2022-02-08 2022-05-03 夏之泉 Database structure generation method and device
CN114492338A (en) * 2020-11-13 2022-05-13 永中软件股份有限公司 Method for realizing on-line combination and export of Excel based on java
CN114691653A (en) * 2022-04-24 2022-07-01 金蝶蝶金云计算有限公司 Account set migration method and device, computer equipment and storage medium
US11500832B2 (en) * 2016-12-19 2022-11-15 Tencent Technology (Shenzhen) Company Limited Data management method and server
CN115510824A (en) * 2022-10-08 2022-12-23 网易(杭州)网络有限公司 Table merging method and device, electronic equipment and readable storage medium
CN115576985A (en) * 2022-09-22 2023-01-06 南方电网数字电网研究院有限公司 A cross-library access method and system
CN117331963A (en) * 2023-11-28 2024-01-02 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium

Families Citing this family (3)

* 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
CN115357655A (en) * 2022-08-24 2022-11-18 奇瑞汽车股份有限公司 Method and device for automatically integrating change information, electronic equipment and storage medium
US12423191B1 (en) 2024-05-22 2025-09-23 Hewlett Packard Enterprise Development Lp Remote data merge system and method

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060161606A1 (en) * 2005-01-19 2006-07-20 Biswal Dilip K 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
CN102591666A (en) * 2012-01-04 2012-07-18 浪潮集团山东通用软件有限公司 Metadata management method for version of hierarchy structure
CN103309997A (en) * 2013-06-25 2013-09-18 上海航天测控通信研究所 Internal and external network parallel running system for database merging and method of database merging

Family Cites Families (2)

* 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
CN103077242B (en) * 2013-01-11 2016-03-09 北京佳讯飞鸿电气股份有限公司 The method of a kind of fulfillment database server two-node cluster hot backup

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060161606A1 (en) * 2005-01-19 2006-07-20 Biswal Dilip K 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
CN102591666A (en) * 2012-01-04 2012-07-18 浪潮集团山东通用软件有限公司 Metadata management method for version of hierarchy structure
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 (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11500832B2 (en) * 2016-12-19 2022-11-15 Tencent Technology (Shenzhen) Company Limited Data management method and server
CN108205559A (en) * 2016-12-19 2018-06-26 腾讯科技(深圳)有限公司 A kind of data managing method and its equipment
CN110532254A (en) * 2018-05-25 2019-12-03 杭州海康威视数字技术股份有限公司 Method and device for fusing data tables
WO2020125537A1 (en) * 2018-12-17 2020-06-25 中兴通讯股份有限公司 Database component merge into function compatibility method, device and storage medium
CN110334098A (en) * 2019-06-27 2019-10-15 烽火通信科技股份有限公司 A kind of database combining method and system based on script
CN114492338A (en) * 2020-11-13 2022-05-13 永中软件股份有限公司 Method for realizing on-line combination and export of Excel based on java
CN114428773A (en) * 2022-02-08 2022-05-03 夏之泉 Database structure generation method and device
CN114691653A (en) * 2022-04-24 2022-07-01 金蝶蝶金云计算有限公司 Account set migration method and device, computer equipment and storage medium
CN115576985A (en) * 2022-09-22 2023-01-06 南方电网数字电网研究院有限公司 A cross-library access method and system
CN115576985B (en) * 2022-09-22 2025-07-08 南方电网数字电网研究院股份有限公司 Cross-library access method and system
CN115510824A (en) * 2022-10-08 2022-12-23 网易(杭州)网络有限公司 Table merging method and device, electronic equipment and readable storage medium
CN117331963A (en) * 2023-11-28 2024-01-02 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium
CN117331963B (en) * 2023-11-28 2024-03-08 恒生电子股份有限公司 Data access processing method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
WO2015117429A1 (en) 2015-08-13
CN105320681B (en) 2020-06-30

Similar Documents

Publication Publication Date Title
CN105320681B (en) A kind of database content merging method and device
JP7170701B2 (en) Methods and Apparatus for Efficiently Implementing Fast Copyable Databases
US10324909B2 (en) Omega names: name generation and derivation utilizing nested three or more attributes
US9659051B2 (en) Enforcing referential integrity for object data documents
US9390124B2 (en) Version control system using commit manifest database tables
US20160205101A1 (en) Distributed Storage and Distributed Processing Query Statement Reconstruction in Accordance with a Policy
US8667027B2 (en) Directed graph transitive closure
US9563628B1 (en) Method and system for deletion handling for incremental file migration
JP2006244498A (en) Data model for object relational data
CN104965735A (en) Apparatus for generating upgrade SQL script
Ikeda et al. Provenance-based debugging and drill-down in data-oriented workflows
US9483508B1 (en) Omega names: name generation and derivation
US20120079454A1 (en) Expressing equivalency relationships with identity graphs
CN111966633A (en) Method, device, electronic equipment and medium for inquiring child nodes under directory
CN113515303B (en) Project transformation method, device and equipment
CN104992083A (en) Code obfuscation method and system for application program
CN116069669B (en) Fully automatic distributed consistency analysis method, system, device and storage medium
CN114443699A (en) Information query method, apparatus, computer equipment, and computer-readable storage medium
US20160140197A1 (en) Cross-system synchronization of hierarchical applications
CN111259082A (en) Method for realizing full data synchronization in big data environment
CN103020318A (en) Method for maintenance of database tables in database
CN104679510A (en) Fault tree generation method for extended UML class diagram model of safety-critical system
CN114756579B (en) Method and system for automatically generating database query rewriting rules
CN104391845B (en) A method and device for generating database scripts
US20150347402A1 (en) System and method for enabling a client system to generate file system operations on a file system data set using a virtual namespace

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant