context.getCommentGenerator().addComment(answer);
GeneratedKey gk = introspectedTable.getGeneratedKey();
if (gk != null && gk.isPlacedBeforeInsertInIbatis2()) {
IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
// if the column is null, then it's a configuration error. The
// warning has already been reported
if (introspectedColumn != null) {
// pre-generated key
answer.addElement(getSelectKey(introspectedColumn, gk));
}
}
StringBuilder insertClause = new StringBuilder();
StringBuilder valuesClause = new StringBuilder();
insertClause.append("insert into "); //$NON-NLS-1$
insertClause.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
insertClause.append(" ("); //$NON-NLS-1$
valuesClause.append("values ("); //$NON-NLS-1$
List<String> valuesClauses = new ArrayList<String>();
Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns().iterator();
while (iter.hasNext()) {
IntrospectedColumn introspectedColumn = iter.next();
if (introspectedColumn.isIdentity()) {
// cannot set values on identity fields
continue;
}
insertClause.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
valuesClause.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn));
if (iter.hasNext()) {
insertClause.append(", "); //$NON-NLS-1$
valuesClause.append(", "); //$NON-NLS-1$
}
if (valuesClause.length() > 80) {
answer.addElement(new TextElement(insertClause.toString()));
insertClause.setLength(0);
OutputUtilities.xmlIndent(insertClause, 1);
valuesClauses.add(valuesClause.toString());
valuesClause.setLength(0);
OutputUtilities.xmlIndent(valuesClause, 1);
}
}
insertClause.append(')');
answer.addElement(new TextElement(insertClause.toString()));
valuesClause.append(')');
valuesClauses.add(valuesClause.toString());
for (String clause : valuesClauses) {
answer.addElement(new TextElement(clause));
}
if (gk != null && !gk.isPlacedBeforeInsertInIbatis2()) {
IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
// if the column is null, then it's a configuration error. The
// warning has already been reported
if (introspectedColumn != null) {
// pre-generated key
answer.addElement(getSelectKey(introspectedColumn, gk));