for (final RequestValue param : request.getParameters()) {
for (final TableMetaData table : tables) {
final ColumnMetaData column = table.getColumns().get(param.getName());
if (column != null) {
if (column.isReadOnly()) {
throw new InvalidRequestException(InvalidRequestException.MESSAGE_READONLY_PARAM,
column.getColumnLabel());
}
if (column.isPrimaryKey()) {
// Add this to the res Ids - assume resIds is non null
resIds.add(param);
} else if (!column.isNonqueriedForeignKey()) {
SqlStruct sql = sqls.get(column.getQualifiedTableName());
if (sql == null) {
// Create new sql holder
sql = new SqlStruct(DEFAULT_UPDATE_SIZE, DEFAULT_UPDATE_SIZE / 2, true);
sqls.put(column.getQualifiedTableName(), sql);
sql.appendToBothMains("UPDATE ");
sql.appendToBothMains(column.getQualifiedTableName());
sql.appendToBothMains(" SET ");
} else {
sql.appendToBothMains(",");
}
validParamFound = true;
setNameValue(request.getType(), metaData, column, param, false, sql, true);
}
}
}
}
if (!validParamFound) {
throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
}
validParamFound = false;
for (final String qualifiedTableName : sqls.keySet()) {
final SqlStruct sql = sqls.get(qualifiedTableName);
if (sql == null) {
sqls.remove(qualifiedTableName);
} else {
// Iterate through the resourceIds and build the where clause sql for each table
for (final RequestValue resId : resIds) {
final TableMetaData table = metaData.getTableMap().get(qualifiedTableName);
final ColumnMetaData column = table.getColumns().get(resId.getName());
if (column != null) {
if (sql.getClause().length() == 0) {
sql.appendToBothClauses(" WHERE ");
} else { // sql.getClause().length() > 0
sql.appendToBothClauses(" AND ");
}
validParamFound = true;
setNameValue(request.getType(), metaData, column, resId, true, sql, false);
}
}
sql.compileStatements();
}
}
if (!validParamFound) {
throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
}
return sqls;
}