Class DataSetUtils

java.lang.Object
org.dbunit.dataset.DataSetUtils

public class DataSetUtils extends Object
This class contains various methods for manipulating datasets.
Since:
Feb 19, 2002
Version:
$Revision$
Author:
Manuel Laflamme
  • Method Details

    • assertEquals

      public static void assertEquals(IDataSet expectedDataSet, IDataSet actualDataSet) throws Exception
      Deprecated.
      Use Assertion.assertEquals
      Asserts that the two specified dataset are equals. This method ignore the tables order.
      Parameters:
      expectedDataSet - the dataset containing all expected results.
      actualDataSet - the dataset containing all actual results.
      Throws:
      Exception - if an error occurs during comparison.
    • assertEquals

      public static void assertEquals(ITable expectedTable, ITable actualTable) throws Exception
      Deprecated.
      Use Assertion.assertEquals
      Asserts that the two specified tables are equals. This method ignore the table names, the columns order, the columns data type and the primary keys.
      Parameters:
      expectedTable - the table containing all expected results.
      actualTable - the table containing all actual results.
      Throws:
      Exception - if an error occurs during comparison.
    • getQualifiedName

      public static String getQualifiedName(String prefix, String name)
      Deprecated.
      since 2.3.0. Prefer usage of QualifiedTableName.getQualifiedName() creating a new QualifiedTableName object
      Returns the specified name qualified with the specified prefix. The name is not modified if the prefix is null or if the name is already qualified.

      Example:
      getQualifiedName(null, "NAME") returns "NAME". getQualifiedName("PREFIX", "NAME") returns "PREFIX.NAME" and getQualifiedName("PREFIX2", "PREFIX1.NAME") returns "PREFIX1.NAME".

      Parameters:
      prefix - the prefix that qualifies the name and is prepended if the name is not qualified yet
      name - the name The name to be qualified if it is not qualified already
      Returns:
      the qualified name
    • getQualifiedName

      public static String getQualifiedName(String prefix, String name, String escapePattern)
      Deprecated.
      since 2.3.0. Prefer usage of QualifiedTableName.getQualifiedName() creating a new QualifiedTableName object
      Parameters:
      prefix - the prefix that qualifies the name and is prepended if the name is not qualified yet
      name - the name The name to be qualified if it is not qualified already
      escapePattern - The escape pattern to be applied on the prefix and the name. Can be null.
      Returns:
      The qualified name
    • getEscapedName

      public static String getEscapedName(String name, String escapePattern)
      Deprecated.
      since 2.3.0. Prefer usage of QualifiedTableName.getQualifiedName() creating a new QualifiedTableName object
      Escapes the given name using the given escape pattern.
      Parameters:
      name - the name to escape.
      escapePattern - the escape pattern to apply, may be null.
      Returns:
      The escaped name if the escape pattern is not null
    • getSqlValueString

      public static String getSqlValueString(Object value, DataType dataType) throws TypeCastException
      Returns the specified value as a string to be use in an SQL Statement. For example the string myValue is returned as 'myValue'.
      Parameters:
      value - the value
      dataType - the value data type
      Returns:
      the SQL string value
      Throws:
      TypeCastException - if the value cannot be cast to a string using the given data type.
    • getColumn

      public static Column getColumn(String columnName, Column[] columns)
      Deprecated.
      since 2.3.0 - prefer usage of Columns.getColumn(String, Column[])
      Search and returns the specified column from the specified column array.
      Parameters:
      columnName - the name of the column to search.
      columns - the array of columns from which the column must be searched.
      Returns:
      the column or null if the column is not found
    • getTables

      public static ITable[] getTables(String[] names, IDataSet dataSet) throws DataSetException
      Search and returns the specified tables from the specified dataSet.
      Parameters:
      names - the names of the tables to search.
      dataSet - the dataset from which the tables must be searched.
      Returns:
      the tables or an empty array if no tables are found.
      Throws:
      DataSetException - if a named table cannot be retrieved from the dataset.
    • getTables

      public static ITable[] getTables(IDataSet dataSet) throws DataSetException
      Returns the tables from the specified dataset.
      Parameters:
      dataSet - the dataset to get the tables from.
      Returns:
      the tables from the specified dataset.
      Throws:
      DataSetException - if the tables cannot be retrieved.
    • getTables

      public static ITable[] getTables(ITableIterator iterator) throws DataSetException
      Returns the tables from the specified iterator.
      Parameters:
      iterator - the iterator to get the tables from.
      Returns:
      the tables from the specified iterator.
      Throws:
      DataSetException - if the tables cannot be retrieved.
    • getReverseTableNames

      public static String[] getReverseTableNames(IDataSet dataSet) throws DataSetException
      Returns the table names from the specified dataset in reverse order.
      Parameters:
      dataSet - the dataset to get the table names from.
      Returns:
      the table names from the specified dataset, in reverse order.
      Throws:
      DataSetException - if the table names cannot be retrieved.
    • reverseStringArray

      public static String[] reverseStringArray(String[] array)
      reverses a String array.
      Parameters:
      array - the array to reverse.
      Returns:
      String[] - reversed array.