Collection usedFields,
Collection allFields) throws IOException
{
String body = getCreateTempTableSqlBodyForTable(table);
if(body == null) {
TableDefinition tableDef = new TableDefinition();
Collection fields;
if(supportsLocalTempTables()) {
fields = usedFields;
} else {
// supportsGlobalTempTables() == true
fields = allFields;
}
Iterator itFields = fields.iterator();
while (itFields.hasNext()) {
DatabaseField field = (DatabaseField)itFields.next();
FieldDefinition fieldDef;
//gfbug3307, should use columnDefinition if it was defined.
if ((field.getColumnDefinition()!= null) && (field.getColumnDefinition().length() == 0)) {
Class type = ConversionManager.getObjectClass(field.getType());
// Default type to VARCHAR, if unknown.
if (type == null) {
type = ClassConstants.STRING;
}
fieldDef = new FieldDefinition(field.getNameDelimited(this), type);
} else {
fieldDef = new FieldDefinition(field.getNameDelimited(this), field.getColumnDefinition());
}
if (pkFields.contains(field) && shouldTempTableSpecifyPrimaryKeys()) {
fieldDef.setIsPrimaryKey(true);
}
tableDef.addField(fieldDef);
}
tableDef.setCreationPrefix(getCreateTempTableSqlPrefix());
tableDef.setName(getTempTableForTable(table).getQualifiedNameDelimited(this));
tableDef.setCreationSuffix(getCreateTempTableSqlSuffix());
tableDef.buildCreationWriter(session, writer);
} else {
writer.write(getCreateTempTableSqlPrefix());
writer.write(getTempTableForTable(table).getQualifiedNameDelimited(this));
writer.write(body);
writer.write(getCreateTempTableSqlSuffix());