final List<TableMetaData> tables = metaData.getWriteTables(request.getType(), doParent);
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());
}
final String qualifiedTableName = column.getQualifiedTableName();
SqlStruct sql = sqls.get(qualifiedTableName);
if (sql == null) {
// Create new sql holder
sql = new SqlStruct(DEFAULT_INSERT_SIZE, DEFAULT_INSERT_SIZE / 2);
sqls.put(qualifiedTableName, sql);
sql.getMain().append("INSERT INTO ");
sql.getMain().append(qualifiedTableName);
sql.getMain().append(" (");
sql.appendToBothClauses(" VALUES (");
} else {
sql.getMain().append(',');
sql.appendToBothClauses(",");
}
sql.getMain().append(column.getColumnName()); // since parameter may use column label
// Begin quote the column value
if (column.isCharOrDateTimeType()) {
sql.getClause().append('\'');
}
// Convert String to appropriate object
column.normalizeValue(param);
// Set the value in the printable clause, the ? in the prepared clause, and prepared clause value
sql.getClause().append(param.getValue().toString());
sql.getPreparedClause().append(buildPreparedParameterSql(column));
sql.getPreparedValues().add(param.getValue());
// End quote the column value
if (column.isCharOrDateTimeType()) {
sql.getClause().append('\'');
}
}
}
}
for (final String tableName : sqls.keySet()) {
final SqlStruct sql = sqls.get(tableName);
if (sql == null) {
sqls.remove(tableName);
} else {
sql.getMain().append(')');
sql.appendToBothClauses(")");
sql.compileStatements();
}
}
if (sqls.size() == 0) {
throw new InvalidRequestException(InvalidRequestException.MESSAGE_INVALID_PARAMS);
}
return sqls;
}