{
try
{
while (tri.hasNext())
{
TableRow tr = tri.next();
// Check the item mappings to see if it contains this mapping
boolean itemIsMapped = false;
int trDistinctID = tr.getIntColumn("distinct_id");
for (int i = 0; i < distinctIDs.length; i++)
{
// Found this mapping
if (distinctIDs[i] == trDistinctID)
{
// Flag it, and remove (-1) from the item mappings
itemIsMapped = true;
distinctIDs[i] = -1;
}
}
// The item is no longer mapped to this community, so remove the database record
if (!itemIsMapped)
DatabaseManager.delete(context, tr);
}
}
finally
{
tri.close();
}
}
// Any remaining mappings need to be added to the database
for (int i = 0; i < distinctIDs.length; i++)
{
if (distinctIDs[i] > -1)
{
TableRow row = DatabaseManager.create(context, table);
row.setColumn("item_id", itemID);
row.setColumn("distinct_id", distinctIDs[i]);
DatabaseManager.update(context, row);
}
}
}
catch (SQLException e)