Package org.dbunit.database.statement

Examples of org.dbunit.database.statement.IPreparedBatchStatement


            }

            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();
                }
            }
        }
    }
View Full Code Here


            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 diffrent 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)
                {
                    // end of table
                }

                statement.executeBatch();
                statement.clearBatch();
            }
            finally
            {
              if (statement != null)
                {
                    statement.close();
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.dbunit.database.statement.IPreparedBatchStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.