// Cache for better performance by repeating the same lookup.
if (searchVals.equals(this.lastLookupVals)) {
return lastLookupRow;
}
// Iterate through the ViewObject rows to find the lookup-row.
final ViewObject vo = getTableModel().getViewOject();
final ViewCriteria oldCriteria = vo.getViewCriteria();
vo.applyViewCriteria(vo.createViewCriteria());
Map<String, Object> retval = null;
try {
final RowSetIterator iter = vo.createRowSetIterator("__lookup__");
iter.setRowValidation(false);
try {
while (iter.hasNext()) {
final Row row = iter.next();
boolean isLookup = true;
// Compare the values of all the lookup attributes.
for (String tableAttrName : lookups.keySet()) {
final Object rowVal = row.getAttribute(tableAttrName);
final Object bindingVal = searchVals.get(tableAttrName);
if (!new EqualsBuilder().append(rowVal,
bindingVal).isEquals()) { // Difference found, we stop the compare.
isLookup = false;
break;
}
}
if (isLookup) {
retval = new RowMapAdapter(row) {
@Override
public Object put(final String key, final Object value) { // Ignore the put operation, because the lookup row is always
// read only and we don't want to put.
return null;
}
};
}
}
} finally {
iter.closeRowSetIterator();
}
} finally {
vo.applyViewCriteria(oldCriteria);
}
if (retval == null) { // Row not found.
retval = Collections.emptyMap();
}
lastLookupVals = searchVals;