Package org.dbunit.database.statement

Examples of org.dbunit.database.statement.IBatchStatement


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


    {
        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));
                statement.addBatch(sqlBuffer.toString());

                count++;
            }

            if (count > 0)
            {
                statement.executeBatch();
                statement.clearBatch();
            }
        }
        finally
        {
            statement.close();
        }
    }
View Full Code Here

TOP

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

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.