开发者

Write DB information to a file - good appraoch?

I have a DB and a mapping framework which was written by the company Im working for. So I have a class for each table in the DB and those classes allow to call the DB and get various information in DataSets or DataTables for example. Now I am supposed to write that information to a TXT file in a 开发者_JAVA技巧certain format (I have the specs how it should look like). Its about estates, there will be many estates in a file and for each estates there are about 40 lines in the file. I know how to write to a file and stuff, what I am looking for is a good approach how to build this functionality in general.

This might be too general to give good advice, but is there a proven way to do such things?

Thanks :-)


Let's call the classes that give you table info TableInfo objects

I'd create an interface IDBInfoWriter, with a method WriteDBInfo(TableInfo ti)

Then an implementation of IDBInfoWriter, say DBInfoFileWriter, with a FileWriter as a private member. Each call to WriteDBInfo would dump whatever in the file writer

Finally a DBInfoWalker object, which would take a list of instantiated TableInfo and a IDbInfoWriter

class DBInfoWalker
function new(TableInfo[] tis, IDBInfoWriter idbiw)
{...}

function process()
{
    for each TableInfo ti in tis
    {
        idbiw.WriteDBInfo(ti);
    }
}

This way you can

  • Work on any subset of TableInfo you want (lets say you want just a list of TableInfo beginning with "S", pass only this list in the constructor of DBInfoWalker
  • Create as many output styles for your tableInfo, just create the correct implementation of IDBInfoWriter (network, unique file, multiple files, etc)

Of course, that's just one possibility :)

Good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜