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.
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);
Currently we are using ODT (Oracle Developer Tools) for .Net with c#.
The mapping routine for each view:
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;
}
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.