Table: Deleted Row (discarding, resuming) [message #677255] |
Tue, 07 June 2011 18:57  |
Eclipse User |
|
|
|
I have a ITableRow r.
When I delete this row in a Table t:
It disappears from the array returned by t.getRows().
And as long as I have AutoDiscardOnDelete ==> false, it appears in the array returned by t.getDeletedRows(). And r.getStatus() == STATUS_DELETED
So far so good.
How can I "resume" the deleted row ?
I have try:
It changes the status of the row returned by t.getDeletedRows() but the row is not visible and to in the array t.getRow().
If I add a new row r1 (with the same primary key):
r1 = addRowsByMatrix(new Object[]{new Object[]{
categoryId, //== t.getCategoryIdColumn().getValue(r)
t.getNameColumn().getValue(r)
}}); I have r1 in the array returned by t.getRows() with r1 status == STATUS_INSERTED
I have r in the array returned by t.getDeleteRows() with r == STATUS_DELETED
I also have tried to discard the deleted row: this doesn't seems to be possible: nothing append. t.deleteRow(r)
t.discardRow(r) => r is still in t.getDeletedRow().
This is not the the behavior I have expected.
|
|
|
|
|
|
Re: Table: Deleted Row (discarding, resuming) [message #685621 is a reply to message #685314] |
Fri, 17 June 2011 17:43   |
Eclipse User |
|
|
|
Thanks for your answer...
I manage to solve my problem server-side: for the "primary key" Column (index defined by valueColumn), I check if there is a STATUS_INSERTED and STATUS_DELETED row. If yes I update the status to change it to STATUS_UPDATED (=> Nothing changed in the database for STATUS_UPDATED rows). On the client side I ensure that I do not have multiple STATUS_INSERTED rows for the same primary key Value. Multiple deletes are not a problem with my database query.
private void cleanupTable(AbstractTableFieldData table, int valueColumn) {
HashMap<Object, Integer> deletedMap = new HashMap<Object, Integer>();
HashMap<Object, Integer> insertedMap = new HashMap<Object, Integer>();
for (int i = 0; i < table.getRowCount(); i++) {
switch (table.getRowState(i)) {
case ITableHolder.STATUS_INSERTED:
if (deletedMap.containsKey(table.getValueAt(i, valueColumn))) {
Integer index = deletedMap.get(table.getValueAt(i, valueColumn));
table.setRowState(index.intValue(), ITableHolder.STATUS_UPDATED);
table.setRowState(i, ITableHolder.STATUS_UPDATED);
}
else {
insertedMap.put(table.getValueAt(i, valueColumn), Integer.valueOf(i));
}
break;
case ITableHolder.STATUS_DELETED:
if (insertedMap.containsKey(table.getValueAt(i, valueColumn))) {
Integer index = insertedMap.get(table.getValueAt(i, valueColumn));
table.setRowState(index.intValue(), ITableHolder.STATUS_UPDATED);
table.setRowState(i, ITableHolder.STATUS_UPDATED);
}
else {
deletedMap.put(table.getValueAt(i, valueColumn), Integer.valueOf(i));
}
break;
case ITableHolder.STATUS_NON_CHANGED:
case ITableHolder.STATUS_UPDATED:
default:
//Do nothing
break;
}
}
}
This should work... until there is a discaredDeletedRow(ITableRow) in the AbstractTable in the client.
|
|
|
Re: Table: Deleted Row (discarding, resuming) [message #750299 is a reply to message #685621] |
Tue, 25 October 2011 14:26   |
Eclipse User |
|
|
|
Jeremie Bresson wrote on Fri, 17 June 2011 23:43This should work... until there is a discaredDeletedRow(ITableRow) in the AbstractTable in the client.
I opened a bug: Bug 361985
Jeremie Bresson wrote on Fri, 17 June 2011 23:43the "primary key" Column (index defined by valueColumn)
Writing such utility functions that rely on an index as int is dangerous, because they are called with:
cleanupTable(formData.getActorsTable(), 0);
If a column is inserted before the first column (ActorIdColumn), the code is still valid, but the code do not work as expected. It would be better to call it with:
cleanupTable(formData.getActorsTable(), ActorsTable.ACTOR_ID_COLUMN_ID);
In order to change the SDK to insert the column indexes as constant, I opened and proposed a patch: Bug 356426
|
|
|
|
Re: Table: Deleted Row (discarding, resuming) [message #774873 is a reply to message #773044] |
Wed, 04 January 2012 15:30  |
Eclipse User |
|
|
|
Jeremie Bresson wrote on Sat, 31 December 2011 10:43How can I test this modification (and write a test) to ensure that the methods work as expected ?
I added some tests for my patch (in order to ensure it works as expected)... The patch itself also needed an update...
Everything is in Bugzilla...
|
|
|
Powered by
FUDForum. Page generated in 0.05221 seconds