DefaultDataSet / AbstractDataSet

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

DefaultDataSet / AbstractDataSet

Mike Kienenberger
What's the point of DefaultDataSet inheriting from AbstractDataSet?

AbstractDataSet uses "private OrderedTableNameMap
_orderedTableNameMap;" for table management.

DefaultDataSet uses "private final OrderedTableNameMap _tableMap;" for
table management.

That works fine so long as DefaultDataSet overrides every method of
AbstractDataSet, but it fails to override the getTable(String),
getTables(), and getTableNames() methods, which is half of the
IDataSet interface.

What this means is that if you construct a DefaultDataSet using the
DefaultDataSet methods, your constructed data set is stored in
_tableMap, but when you then refetch those values using the getters,
you're fetching out of the empty  _orderedTableNameMap.

Ie, the following method fails because the previously-added tables are
not found, yet when we try to re-add them, we get an exception to that
effect.

    public static DefaultTable getOrCreateTable(DefaultDataSet
aDataSet, String tableName) throws DataSetException,
FileNotFoundException, IOException
    {
        DefaultTable table = null;
        try
        {
            table = (DefaultTable)aDataSet.getTable(tableName);
        }
        catch (NoSuchTableException e)
        {
            ITableMetaData userTableMetaData =
BaseDBunit.getMetaData().getTableMetaData(tableName);
            table = new DefaultTable(userTableMetaData, new ArrayList());
            aDataSet.addTable(table);
        }

        return table;
    }

The solution would be to either override every method of
AbstractDataSet or to make  _orderedTableNameMap protected and allow
subclasses to use it.  Ie, replace  _tableMap in DefaultDataSet with
_orderedTableNameMap.

I'm willing to do the work; only tell me how you want it handled.  My
choice would be to change _orderedTableNameMap. to protected --
there's not much point in having an abstract class which doesn't
expose the necessary data structures of the implementation to
subclasses.

-Mike

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user