IDataSet databaseDataSet = connection.createDataSet();
DatabaseConfig databaseConfig = connection.getConfig();
IStatementFactory statementFactory = (IStatementFactory)databaseConfig.getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
IBatchStatement statement = statementFactory.createBatchStatement(connection);
try
{
int count = 0;
Stack tableNames = new Stack();
Set tablesSeen = new HashSet();
ITableIterator iterator = dataSet.iterator();
while (iterator.next())
{
String tableName = iterator.getTableMetaData().getTableName();
if (!tablesSeen.contains(tableName))
{
tableNames.push(tableName);
tablesSeen.add(tableName);
}
}
// delete tables once each in reverse order of seeing them.
while (!tableNames.isEmpty())
{
String tableName = (String)tableNames.pop();
// Use database table name. Required to support case sensitive database.
ITableMetaData databaseMetaData = databaseDataSet.getTableMetaData(tableName);
tableName = databaseMetaData.getTableName();
StringBuffer sqlBuffer = new StringBuffer(128);
sqlBuffer.append(getDeleteAllCommand());
sqlBuffer.append(getQualifiedName(connection.getSchema(), tableName, connection));
String sql = sqlBuffer.toString();
statement.addBatch(sql);
if(logger.isDebugEnabled())
logger.debug("Added SQL: {}", sql);
count++;
}
if (count > 0)
{
statement.executeBatch();
statement.clearBatch();
}
}
finally
{
statement.close();
}
}