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;
//bug3307, should use columnDefinition if it was defined.
if(field.getColumnDefinition().length() == 0){
fieldDef = new FieldDefinition(field.getName(), ConversionManager.getObjectClass(field.getType()));
}else{
fieldDef = new FieldDefinition(field.getName(), field.getColumnDefinition());
}
if(pkFields.contains(field) && shouldTempTableSpecifyPrimaryKeys()) {
fieldDef.setIsPrimaryKey(true);
}
tableDef.addField(fieldDef);
}
tableDef.setCreationPrefix(getCreateTempTableSqlPrefix());
tableDef.setName(getTempTableForTable(table).getQualifiedName());
tableDef.setCreationSuffix(getCreateTempTableSqlSuffix());
tableDef.buildCreationWriter(session, writer);
} else {
writer.write(getCreateTempTableSqlPrefix());
writer.write(getTempTableForTable(table).getQualifiedName());
writer.write(body);
writer.write(getCreateTempTableSqlSuffix());