/**
* @param dialect
* @return
*/
public String getCreateSql(Dialect dialect, String newSchema) {
TableGrammar grammar = dialect.getTableGrammar();
StringBuilder buf = new StringBuilder(grammar.getCreateString()).append(' ')
.append(identifier(newSchema)).append(" (");
Iterator<Column> iter = columns.values().iterator();
while (iter.hasNext()) {
Column col = iter.next();
buf.append(col.getName()).append(' ');
buf.append(col.getSqlType(dialect));
String defaultValue = col.getDefaultValue();
if (defaultValue != null) {
buf.append(" default ").append(defaultValue);
}
if (col.isNullable()) {
buf.append(grammar.getNullColumnString());
} else {
buf.append(" not null");
}
boolean useUniqueConstraint = col.isUnique()
&& (!col.isNullable() || grammar.isSupportsNullUnique());
if (useUniqueConstraint) {
if (grammar.isSupportsUnique()) {
buf.append(" unique");
} else {
UniqueKey uk = getOrCreateUniqueKey(col.getName() + '_');
uk.addColumn(col);
}
}
if (col.hasCheckConstraint() && grammar.isSupportsColumnCheck()) {
buf.append(" check (").append(col.getCheckConstraint()).append(")");
}
String columnComment = col.getComment();
if (columnComment != null) {
buf.append(grammar.getColumnComment(columnComment));
}
if (iter.hasNext()) {
buf.append(", ");
}
}
if (hasPrimaryKey()) {
buf.append(", ").append(getPrimaryKey().sqlConstraintString());
}
buf.append(')');
if (StringUtils.isNotBlank(comment)) {
buf.append(grammar.getComment(comment));
}
return buf.toString();
}