views:

91

answers:

2

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.

+2  A: 

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.

Adam Hawkes
@Adam Hawkes: Good idea. Thanks +1
Kb
+1  A: 

I think that I'd automate the building of views on top of those views, based as Adam says on the metadata. Make each view a single column by converting all the fields to text (using explicit conversion for dates) and concatanating the fields together, and just dump that single column to a text file.

David Aldridge
@David Aldridge: +1. Thanks
Kb