}
@Override
public void execute() throws MetaModelException {
final Table table = getTable();
final CouchDbConnector connector = _updateCallback.getConnector(table.getName());
// create a map which will act as a prototype for updated objects
final Map<String, Object> prototype = new HashMap<String, Object>();
final Column[] columns = getColumns();
final Object[] values = getValues();
for (int i = 0; i < columns.length; i++) {
final Column column = columns[i];
if (isSet(column)) {
final String columnName = column.getName();
final Object value = values[i];
prototype.put(columnName, value);
}
}
final CouchDbDataContext dc = _updateCallback.getDataContext();
final DataSet dataSet = dc.query().from(table).select(table.getColumns()).where(getWhereItems()).execute();
try {
while (dataSet.next()) {
final Map<String, Object> map = new HashMap<String, Object>(prototype);
final Row row = dataSet.getRow();
for (Column column : table.getColumns()) {
if (!map.containsKey(column.getName())) {
map.put(column.getName(), row.getValue(column));
}
}
// copy the prototype and set the not-updated values
connector.update(map);
}
} finally {
dataSet.close();
}
}