Menu

#246 DefaultDataSet is incompatible w/ AbstractDataSet's IDataSet

closed-fixed
Bug (232)
5
2009-06-01
2009-05-28
No

DefaultDataSet's implementation is incompatible w/ AbstractDataSet's implementation of getTable, getTables, and getTableName methods.

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 the tables, 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've created a patch to fix this that passes all 2.4.4 unit tests. I have not created a unit test that demonstrates the problem, however.

I have changed AbstractDataSet's _orderedTableNameMap. to protected.
I have replaced references with _tableMap with _orderedTableNameMap.
I have called initialize() at the appropriate places, and provided a dumbed-down implementation of initialize (since the one in AbstractDataSet does work that is unnecessary for DefaultDataSet).

Discussion

  • matthias g

    matthias g - 2009-05-28

    Hi Mike,

    first of all thanks for submitting the bug report and the patch. I am very much willing to commit but: could you add some unit tests that fail with the old version but do not with your patched version?

    Thanks in advance,
    matthias

     
  • Mike Kienenberger

    Revised fix for getTable* methods, also unit test

     
  • Mike Kienenberger

    I was hoping to avoid having to write the unit test, but I guess that was unrealistic :-)

    In any case, I see I uploaded my first draft of a fix, and not my final fix.

    Here's a new patch that matches my previous description of changes and also includes a test that fails before the patch and succeeds after the patch.

     
  • matthias g

    matthias g - 2009-06-01

    Hi Mike,

    I committed your patch to the current trunk (rev. 1014). Thanks for your contribution!

    regards,
    matthias

     
  • matthias g

    matthias g - 2009-06-01
    • assigned_to: slecallonnec --> gommma
    • status: open --> closed-fixed
     

Log in to post a comment.