Class AbstractDbData<D extends AbstractDbData<D>>

java.lang.Object
org.assertj.db.type.AbstractDbElement<D>
org.assertj.db.type.AbstractDbData<D>
Type Parameters:
D - Class of the subclass (an implementation of AbstractDbData) : useful for the fluent methods (setters).
All Implemented Interfaces:
DbElement, WithColumnLetterCase, WithLetterCase, WithPrimaryKeyLetterCase, WithTableLetterCase
Direct Known Subclasses:
Request, Table

public abstract class AbstractDbData<D extends AbstractDbData<D>> extends AbstractDbElement<D>
This class represents data from the database (either a Table or a Request).

That could be data from a Table or from a Request.
So this class contains the list of columns name (getColumnsNameList()), the list of primary keys name (getPksNameList()) and the list of the rows (getRowsList()). The first call to one of these methods triggers a loading from the database.

Author:
Régis Pouiller, Julien Roy
  • Constructor Details

    • AbstractDbData

      protected AbstractDbData(Class<D> selfType, DataType dataType, ConnectionProvider connectionProvider)
      Constructor with a JdbcUrlConnectionProvider.
      Parameters:
      selfType - Class of this element : a subclass of AbstractDbData.
      dataType - The type of the data on which is the change.
      connectionProvider - The JdbcUrlConnectionProvider to connect to the database (must be not null).
      Throws:
      NullPointerException - If connectionProvider is null.
    • AbstractDbData

      protected AbstractDbData(Class<D> selfType, DataType dataType)
      Only used for tests.
      Parameters:
      selfType - Class of DbElement.
      dataType - Type of DbData.
  • Method Details

    • getDataType

      public DataType getDataType()
      Returns the type of the data on which is the change.
      Returns:
      The type of the data on which is the change.
    • getRequest

      public abstract String getRequest()
      Returns the SQL request.
      Returns:
      The SQL request.
      See Also:
    • sortRows

      protected void sortRows()
      Sorts the list of rows.
    • loadImpl

      protected abstract void loadImpl(Connection connection) throws SQLException
      Implementation of the loading that depends of the kind of data.

      In fact it is like in the Skeleton Design Pattern : this method is called by the load() method but loadImpl() is abstract here and it is implemented in the sub-classes depending of the need of the sub-class.

      Parameters:
      connection - Connection to the database provided by load() method.
      Throws:
      SQLException - SQL Exception.
      See Also:
    • collectRowsFromResultSet

      protected void collectRowsFromResultSet(ResultSet resultSet) throws SQLException
      Collects rows from a ResultSet.

      This method browse the ResultSet in parameter to get the data and fill the list of Row ( rowsList) with these data.

      Parameters:
      resultSet - The ResultSet.
      Throws:
      SQLException - A SQL Exception.
    • getColumnsNameList

      public List<String> getColumnsNameList()
      Return the list of the columns name for the data from database.

      If it is the first call to getColumnsNameList(), the data are loaded from database by calling the load() private method.

      Returns:
      The list of the columns name.
      Throws:
      NullPointerException - If the connectionProvider fields are null.
      AssertJDBException - If triggered, this exception wrap a possible SQLException during the loading.
    • setColumnsNameList

      protected void setColumnsNameList(List<String> columnsNameList)
      Sets the list of the columns name.
      Parameters:
      columnsNameList - The list of the columns name.
    • getPksNameList

      public List<String> getPksNameList()
      Return the list of the primary key name for the data from database.

      If it is the first call to getIdsNameList(), the data are loaded from database by calling the load() private method.

      Returns:
      The list of the primary key name.
      Throws:
      NullPointerException - If the AbstractDbElement.getConnectionProvider() fields are null.
      AssertJDBException - If triggered, this exception wrap a possible SQLException during the loading.
    • setPksNameList

      protected void setPksNameList(List<String> pksNameList)
      Sets the list of the primary key name.
      Parameters:
      pksNameList - The list of the primary keys name.
      Throws:
      AssertJDBException - If one the primary keys do not exist in the columns name, the exception is triggered.
    • controlIfAllThePksNameExistInTheColumns

      protected void controlIfAllThePksNameExistInTheColumns()
      Controls that all the primary keys name exist in the columns.
    • getRowsList

      public List<Row> getRowsList()
      Returns the list of the values in rows for the data from database.

      If it is the first call to getRowsList(), the data are loaded from database by calling the load() private method.

      Returns:
      The list of the values.
      Throws:
      NullPointerException - If the connectionProvider fields are null.
      AssertJDBException - If triggered, this exception wrap a possible SQLException during the loading.
    • getColumnsList

      public List<Column> getColumnsList()
      Returns the list of the values in columns for the data from database.

      This method calls getColumnsNameList() and getValuesList(int) which calls getRowsList().
      If it is the first call to getColumnsNameList() or getRowsList(), the data are loaded from database by calling the load() private method.

      Returns:
      The list of the values in columns.
      Throws:
      NullPointerException - If the connectionProvider fields are null.
      AssertJDBException - If triggered, this exception wrap a possible SQLException during the loading.
    • getColumn

      public Column getColumn(int index)
      Returns the column corresponding to the column index in parameter and the values inside the column.

      This method calls getColumnsNameList() and getValuesList(int) which calls getRowsList().
      If it is the first call to getColumnsNameList() or getRowsList(), the data are loaded from database by calling the load() private method.

      Parameters:
      index - The column index.
      Returns:
      The column and the values
      Throws:
      NullPointerException - If the connectionProvider fields are null.
      AssertJDBException - If triggered, this exception wrap a possible SQLException during the loading.
    • getRow

      public Row getRow(int index)
      Returns the row corresponding to the index.

      This method calls getRowsList().
      If it is the first call to getRowsList(), the data are loaded from database by calling the load() private method.

      Parameters:
      index - The index
      Returns:
      The Row
      Throws:
      NullPointerException - If the connectionProvider fields are null.
      AssertJDBException - If triggered, this exception wrap a possible SQLException during the loading.
    • getRowFromPksValues

      public Row getRowFromPksValues(Value... pksValues)
      Returns the Row with the primary keys values in parameter.
      Parameters:
      pksValues - The primary keys values.
      Returns:
      The Row with the same primary keys values.