有助于提高移民计划 [英] Help to improve a migration program
问题描述
我们有200多个意见,甲骨文应该transfomed到200+平面文件具有固定长度的字段。
We have 200+ views in Oracle that should be transfomed to 200+ flat files with fixed length fields.
希望能得到的想法做了更好的设计,下面的迁移程序的。
Hoping to get ideas to do a better design of the following migration routine.
迁移程序的原型如下名为VIEWNAME1视图(和是相同的,在原型其它视图):
The prototype of migration program looks like this for the view named VIEWNAME1 (and are the same for other views in the prototype):
StronglyTypedDataSet views = new StronglyTypedDataSet();
ViewName1TableAdapter tableAdapter = new ViewName1TableAdapter();
tableAdapter.Fill(views.VIEWNAME1 );
mapFromViewToFlatFile(views.VIEWNAME1);
目前,我们正在使用ODT(Oracle开发工具)对于.NET与C#。
Currently we are using ODT (Oracle Developer Tools) for .Net with c#.
映射程序为每个视图:
private void mapFromViewToFlatFile(DataTable table)
{
StringBuilder format = BuildFormat();
StringBuilder outBuf = new StringBuilder();
foreach (views.VIEWNAME1Row row in table.Rows)
{
OneRow(outBuf, format, row);
}
SerializeToFile(outBuf, FILENAME);
}
private void OneRow(StringBuilder outBuf, StringBuilder format,views.VIEWNAME1Row row)
{
outBuf.AppendFormat(format.ToString(),
row.COLUMNNAME1.Trim(),
row.IsCOLUMNNAME2Null() ? string.Empty : row.COLUMNNAME2.Trim()
);
OutBuf.AppendLine();
}
private StringBuilder BuildFormat()
{
StringBuilder format = new StringBuilder();
format.Append("{0,-14}");
format.Append("{1,-36}");
return format;
}
写
后
10日私募OneRow()函数
和10日的私人BuildFormat()函数(一个用于在Oracle中每个视图中,code气味)。
我知道这是可以做到更好,更快,这将使新的观点更容易设置和处理的变化更容易。
After writing the
10th private OneRow() function
and 10th private BuildFormat() function (one for each view in Oracle, the code smells).
And I know this can be done better and faster that would enable easier setup of new views, and handles changes easier.
任何建议,欢迎。
谢谢你。
Any suggestions are welcome.
Thanks.
推荐答案
如果在表中的列的固定长度相匹配的文件中的长度,然后就可以一般查询 USER_TAB_COLUMNS
看到列的大小。然后,你可以自动从数据库中的元数据建立自己的格式。
If the fixed lengths of the columns in the table match the lengths in the file, then you can generically query the user_tab_columns
to see the column sizes. Then you could build your format automatically from the database metadata.
这篇关于有助于提高移民计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!