C # programming practices for detecting data migration plug-ins,
This blog is based on a small plug-in currently written. Simply put, some data in a table in a database is migrated to another location in the table, two different IDs are passed in to verify whether the migration is successful. In this process, I have gained a lot of practical knowledge, which is summarized in the following two aspects: the first is the implementation process, and how to design it to implement the function. The second is from the code: How to call appropriate implementation methods (dictionary and factory) and how to encapsulate appropriate alternative classes. Third, it comes from the configuration file: how to compile appropriate xml files and parse them out. In the future, if Bloggers can access more design methods, they will continue to be updated.
Practical scenarios of data migration plug-ins
Two modes: one is used as a tool. Therefore, you need to traverse each table in the entire database and obtain two sub-tables based on the two user IDs in each table, and so on. The second method is to use it as a business operation. I want to select a few items for comparison. Currently, only operations in the first mode are supported.
Overall Design data Scope
For the two modes with different data ranges, You have to reserve different methods for different scenarios.
Data Matching
Difficulties 1:The number and sequence of two subtables are different, so it is difficult to match
Solution 1:Method to obtain the signature:
1. Get the ing splicing id1-id2 through valueMapping
2. Use xml to configure certain fields as features. The table name and the feature set of this field are spliced into the table-field name set of signatures.
Difficulties 2:The table does not necessarily have the Application field.
Solution 2:Configure the associated foreign key attribute in the table and splice the SQL statement as the query condition. Because each migration is targeted at an application, the application name is required. In order to use tables with different application names, different methods (1, application, or applicationcode have application name segments. 2. Use a foreign key and its associated tables ).Pass the condition as a string
Data comparison
Difficulties:The comparison rules for different fields may be different.
Solution:For different field comparison rules, you can specify the comparison rules during configuration.
Specific work data acquisition level
Write the corresponding stored procedure to obtain the required data
Code Processing Layer
1. encapsulate appropriate classes to re-encapsulate the data obtained from the database for ease of use
2. corresponding to different signature acquisition methods, a general method and their respective implementation form should be written.
3. corresponding to different field matching rules, a general method and their implementation form should be written.
Xml document writing level
You need to design xml documents that meet the requirements so that they can play a matching role.
Code Writing Process file structure design
The subject structure is designed first to get twice the result with half the effort.
1. First, consider that I need to have different matching rules, so I need interfaces and implementation classes that match the rules. I also have different ways to create signatures, therefore, corresponding interfaces and implementation classes are also required.
2. Considering entity design, I need to create comparison information result encapsulation classes from three different levels: Library, table, and field. In order to re-encapsulate the data table, I need to prepare re-encapsulate classes, another is encapsulation of input parameters.(Here, for input parameters that may change, it is better to encapsulate these parameters into classes, which is very convenient to expand)
3. In addition to compiling xml files, the xml parsing class is also essential. Put it in the configuration folder.
4. Of course, the core is the provision of external services.
5. As mentioned in the previous articles, test-driven development and test portals must be prepared in advance.
Core Process
I will not repeat the configuration file, the configuration file parsing class, and other code writing here. I will mainly explain how the core process goes.
The subject does not involve any logical structure. The subdivision function calls auxiliary methods for implementation.This is the biggest conclusion I have drawn in this code writing, so that you can quickly grasp the subject and it will not be too messy. WhileThe auxiliary methods are also written in order according to the calling sequence of the subject.In this way, the code is clear and the reading experience is very good.