}
ITableMetaData metaData = getOperationMetaData(connection, table.getTableMetaData());
BitSet ignoreMapping = null;
OperationData operationData = null;
IPreparedBatchStatement statement = null;
try
{
// For each row
int start = _reverseRowOrder ? table.getRowCount() - 1 : 0;
int increment = _reverseRowOrder ? -1 : 1;
try
{
for (int i = start; ; i = i + increment)
{
int row = i;
// If current row have a different ignore value mapping than
// previous one, we generate a new statement
if (ignoreMapping == null || !equalsIgnoreMapping(ignoreMapping, table, row))
{
// Execute and close previous statement
if (statement != null)
{
statement.executeBatch();
statement.clearBatch();
statement.close();
}
ignoreMapping = getIgnoreMapping(table, row);
operationData = getOperationData(metaData, ignoreMapping, connection);
statement = factory.createPreparedBatchStatement(
operationData.getSql(), connection);
}
// for each column
Column[] columns = operationData.getColumns();
for (int j = 0; j < columns.length; j++)
{
// Bind value only if not in ignore mapping
if (!ignoreMapping.get(j))
{
Column column = columns[j];
try
{
statement.addValue(table.getValue(row, column.getColumnName()), column.getDataType());
}
catch (TypeCastException e)
{
throw new TypeCastException("Error casting value for table '" + table.getTableMetaData().getTableName()
+"' and column '" + column.getColumnName() + "'", e);
}
}
}
statement.addBatch();
}
}
catch (RowOutOfBoundsException e)
{
// This exception occurs when records are exhausted
// and we reach the end of the table. Ignore this error
// end of table
}
statement.executeBatch();
statement.clearBatch();
}
finally
{
if (statement != null)
{
statement.close();
}
}
}
}