Dynamic Mapping of Instvars to Table columns

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic Mapping of Instvars to Table columns

Günther Schmidt
Hi,

I need to import data from excel files. Thanks to help from this group I
can access the data in the files via ODBC.

There is one catch though.

There are about 20 different files, they all contain book records, but
the names of the columns differs, slightly, with each file.

So I need to do some sort of dynamic mapping, ie. I will present the
user with a choice to map the fields to the columns.

I wonder how to do that, not GUI wise, but domain wise.

Would you create mapping objects, or use AspectAdapters, I'm just stuck
here.

Günther


Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Mapping of Instvars to Table columns

Chris Uppal-3
Günther,

> There are about 20 different files, they all contain book records, but
> the names of the columns differs, slightly, with each file.
>
> So I need to do some sort of dynamic mapping, ie. I will present the
> user with a choice to map the fields to the columns.
>
> I wonder how to do that, not GUI wise, but domain wise.

I'm not sure how much this will help, but...

I'd start with the place(s) where I use the column data.  I'd ask how that code
would look if I didn't have the problem of variable mapping, and write the code
as if that was true.  That would mean that I'd either have to have a layer of
adaptor objects to do some sort of mapping, or just massage the data from each
row into a standard form as I read it in.

The former is probably more suitable if you want to retain the flexibility of a
database containing more-or-less arbitrary data, and you want to retain the
ability to use /whatever/ data any given table contains.

The latter is more suitable if you are have a fixed set of data that you want
to work with, but the names of the columns where that data is stored are not
fixed.  In that case you can create your own objects which represent the
grouping of that data (a Book say, with #title, #author, #isbn).  You use the
user-supplied mapping of columns to real data only when you read the table,
thereafter all code works with Books themselves.

In either case, if Dolphin happened to contain a suitable implementation of
whatever helper classes I needed, then I'd use them.  But I wouldn't /expect/
them to exist, i.e. I wouldn't base my design around what was already
available -- it would just be a bit of luck if it there did happen to be
something suitable

    -- chris