Class ResultSetTableMetaData

java.lang.Object
org.dbunit.dataset.AbstractTableMetaData
org.dbunit.database.ResultSetTableMetaData
All Implemented Interfaces:
ITableMetaData

public class ResultSetTableMetaData extends AbstractTableMetaData
ResultSet based ITableMetaData implementation.

The lookup for the information needed to create the Column objects is retrieved in two phases:

  1. Try to find the information from the given ResultSet via a DatabaseMetaData object. Therefore the ResultSetMetaData is used to get the catalog/schema/table/column names which in turn are used to get column information via DatabaseMetaData.getColumns(String, String, String, String). The reason for this is that the DatabaseMetaData is more precise and contains more information about columns than the ResultSetMetaData does. Another reason is that some JDBC drivers (currently known from MYSQL driver) provide an inconsistent implementation of those two MetaData objects and the DatabaseMetaData is hence considered to be the master by dbunit.
  2. Since some JDBC drivers (one of them being Oracle) cannot (or just do not) provide the catalog/schema/table/column values on a ResultSetMetaData instance the second step will create the dbunit Column using the ResultSetMetaData methods directly (for example ResultSetMetaData.getColumnType(int). (This is also the way dbunit worked until the 2.4 release)
Since:
2.3.0
Version:
$Revision$ $Date$
Author:
gommma (gommma AT users.sourceforge.net), Last changed by: $Author$
  • Constructor Details

    • ResultSetTableMetaData

      public ResultSetTableMetaData(String tableName, ResultSet resultSet, IDatabaseConnection connection, boolean caseSensitiveMetaData) throws DataSetException, SQLException
      Creates the metadata for a result set, resolving column data types via the given connection.
      Parameters:
      tableName - The name of the database table
      resultSet - The JDBC result set that is used to retrieve the columns
      connection - The connection which is needed to retrieve some configuration values
      caseSensitiveMetaData - Whether or not the metadata is case sensitive
      Throws:
      DataSetException - if metadata retrieval fails.
      SQLException - if a database access error occurs.
    • ResultSetTableMetaData

      public ResultSetTableMetaData(String tableName, ResultSet resultSet, IDataTypeFactory dataTypeFactory, boolean caseSensitiveMetaData) throws DataSetException, SQLException
      Parameters:
      tableName - The name of the database table
      resultSet - The JDBC result set that is used to retrieve the columns
      dataTypeFactory - the data type factory used to resolve column data types.
      caseSensitiveMetaData - Whether or not the metadata is case sensitive
      Throws:
      DataSetException - if metadata retrieval fails.
      SQLException - if a database access error occurs.
  • Method Details

    • getColumns

      public Column[] getColumns() throws DataSetException
      Description copied from interface: ITableMetaData
      Returns this table columns as recognized by dbunit. In cases where columns are resolved using database metadata it can happen that an empty array is returned when a table does not have a single column that is recognized by the configured IDataTypeFactory. Note that it is not an exceptional case within dbunit when a ITableMetaData does not have a column.
      Returns:
      The columns for this table
      Throws:
      DataSetException - if the columns cannot be determined.
    • getPrimaryKeys

      public Column[] getPrimaryKeys() throws DataSetException
      Description copied from interface: ITableMetaData
      Returns this table primary key columns.
      Returns:
      this table primary key columns.
      Throws:
      DataSetException - if the primary key columns cannot be determined.
    • getTableName

      public String getTableName()
      Description copied from interface: ITableMetaData
      Returns this table name.
      Returns:
      this table name
    • toString

      public String toString()
      Overrides:
      toString in class Object