Package org.dbunit.dataset
Class Columns
java.lang.Object
org.dbunit.dataset.Columns
This class exclusively provides static methods that operate on
Column objects.- Since:
- 2.3.0
- Version:
- $Revision$
- Author:
- gommma
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDescribes theColumns that are different in two tables. -
Method Summary
Modifier and TypeMethodDescriptionstatic Column[]findColumnsByName(String[] columnNames, ITableMetaData tableMetaData) static Column[]findColumnsByName(Column[] columns, ITableMetaData tableMetaData) static ColumnSearch and return the specified column from the specified column array.static Columns.ColumnDiffgetColumnDiff(ITableMetaData expectedMetaData, ITableMetaData actualMetaData) Returns the column difference of the two givenITableMetaDataobjectsstatic String[]getColumnNames(Column[] columns) Returns the names of the given column objects as string arraystatic StringgetColumnNamesAsString(Column[] columns) Creates a pretty string representation of the given column namesstatic Column[]getColumns(String[] columnNames, Column[] columns) Search and return theColumns from the specified column array that match one of the givencolumnNames.static Column[]getColumns(String tableName, Column[] columns, IColumnFilter columnFilter) Search and return the columns from the specified column array which are accepted by the givenIColumnFilter.static ColumngetColumnValidated(String columnName, Column[] columns, String tableName) Search and return the specified column from the specified column array.static Column[]getSortedColumns(ITableMetaData metaData) Returns a sorted array of column objectsstatic Column[]mergeColumnsByName(Column[] referenceColumns, Column[] columnsToMerge) Merges the two arrays of columns so that all of the columns are available in the result array.
-
Method Details
-
getColumns
Search and return theColumns from the specified column array that match one of the givencolumnNames.
Note that this method has a bad performance compared tofindColumnsByName(String[], ITableMetaData)because it iterates over all columns.- Parameters:
columnNames- the names of the columns to search.columns- the array of columns in which thecolumnNameswill be searched.- Returns:
- the column array which is empty if no column has been found or no column names have been given
- See Also:
-
findColumnsByName
public static Column[] findColumnsByName(String[] columnNames, ITableMetaData tableMetaData) throws NoSuchColumnException, DataSetException - Parameters:
columnNames- The column names that are searched in the given table metadatatableMetaData- The table metadata in which the columns are searched by name- Returns:
- The column objects from the given
tableMetaData - Throws:
NoSuchColumnException- if the given column has not been foundDataSetException- if something goes wrong when trying to retrieve the columns
-
findColumnsByName
public static Column[] findColumnsByName(Column[] columns, ITableMetaData tableMetaData) throws NoSuchColumnException, DataSetException - Parameters:
columns- The columns whose names are searched in the given table metadatatableMetaData- The table metadata in which the columns are searched by name- Returns:
- The column objects from the given
tableMetaData - Throws:
NoSuchColumnException- if the given column has not been foundDataSetException- if something goes wrong when trying to retrieve the columns
-
getColumn
Search and return the specified column from the specified column array.
Note that this method has a bad performance compared toITableMetaData.getColumnIndex(String)because it iterates over all columns.- Parameters:
columnName- the name of the column to search.columns- the array of columns in which thecolumnNamewill be searched.- Returns:
- the column or
nullif the column is not found
-
getColumnValidated
public static Column getColumnValidated(String columnName, Column[] columns, String tableName) throws NoSuchColumnException Search and return the specified column from the specified column array.- Parameters:
columnName- the name of the column to search.columns- the array of columns in which thecolumnNamewill be searched.tableName- The name of the table to which the column array belongs - only needed for the exception message in case of a validation failure- Returns:
- the valid column
- Throws:
NoSuchColumnException- If no column exists with the given name
-
getColumns
Search and return the columns from the specified column array which are accepted by the givenIColumnFilter.- Parameters:
tableName- The name of the table which is needed for the filter invocationcolumns- All available columns to which the filter will be appliedcolumnFilter- The column filter that is applied to the givencolumns- Returns:
- The columns that are accepted by the given filter
-
getSortedColumns
Returns a sorted array of column objects- Parameters:
metaData- The metaData needed to get the columns to be sorted- Returns:
- The columns sorted by their column names, ignoring the case of the column names
- Throws:
DataSetException
-
getColumnNames
Returns the names of the given column objects as string array- Parameters:
columns- The column objects- Returns:
- The names of the given column objects
- Since:
- 2.4
-
getColumnNamesAsString
Creates a pretty string representation of the given column names- Parameters:
columns- The columns to be formatted- Returns:
- The string representation of the given column names
-
mergeColumnsByName
Merges the two arrays of columns so that all of the columns are available in the result array. The first array is considered as master and if a column with a specific name is available in both arrays the one from the first array is used.- Parameters:
referenceColumns- reference columns treated as master columns during the mergecolumnsToMerge- potentially new columns to be merged if they do not yet exist in the referenceColumns- Returns:
- Array of merged columns
-
getColumnDiff
public static Columns.ColumnDiff getColumnDiff(ITableMetaData expectedMetaData, ITableMetaData actualMetaData) throws DataSetException Returns the column difference of the two givenITableMetaDataobjects- Parameters:
expectedMetaData-actualMetaData-- Returns:
- The columns that differ in the both given
ITableMetaDataobjects - Throws:
DataSetException
-