sql = "select * from " + tableName;
sql += " where (" + primaryKeyName + "=?)";
Map columnMapTemp = (Map) queryRunner.query(conn, sql, columnMap.get(primaryKeyName), rsh);
if (columnMapTemp == null) {
throw new ControllerException("Cannot find record.");
}
Date oldDate = (java.util.Date) columnMap.get("date_updated");
Date newDate = (java.util.Date) columnMapTemp.get("date_updated");
if (!oldDate.equals(newDate)) {
throw new UpdaterException(); // Signal that record has already been changed
}
sql = "update " + tableName;
String parameter = null;
String columnName = null;
List columnNameList = null;
List paramList = new ArrayList();
// Iterate over columns
Set columnSet = columnMapTemp.keySet();
Iterator iterator = columnSet.iterator();
int i = 0;
while (iterator.hasNext()) {
columnName = (String) iterator.next();
if (columnName.equals("date_updated")) {
parameter = "CURRENT_TIMESTAMP";
} else {
parameter = "?";
paramList.add(columnMap.get(columnName));
}
if (i++ == 0) {
sql += " set " + columnName + " = " + parameter;
} else {
sql += " ," + columnName + " = " + parameter;
}
}
sql += " where (" + primaryKeyName + "=?)";
paramList.add(columnMap.get(primaryKeyName)); // Add primaryKey value to paramList
return queryRunner.update(conn, sql, paramList.toArray());
} catch (SQLException se) {
log.warning("SQL Exception: " + se.getMessage());
throw new ControllerException(se);
}
}