Class AbstractDbData<D extends AbstractDbData<D>>
- Type Parameters:
D- Class of the subclass (an implementation ofAbstractDbData) : useful for the fluent methods (setters).
- All Implemented Interfaces:
DbElement,WithColumnLetterCase,WithLetterCase,WithPrimaryKeyLetterCase,WithTableLetterCase
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
-
Field Summary
Fields inherited from class org.assertj.db.type.AbstractDbElement
myself -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDbData(Class<D> selfType, DataType dataType) Only used for tests.protectedAbstractDbData(Class<D> selfType, DataType dataType, ConnectionProvider connectionProvider) Constructor with aJdbcUrlConnectionProvider. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcollectRowsFromResultSet(ResultSet resultSet) Collects rows from aResultSet.protected voidControls that all the primary keys name exist in the columns.getColumn(int index) Returns the column corresponding to the column index in parameter and the values inside the column.Returns the list of the values in columns for the data from database.Return the list of the columns name for the data from database.Returns the type of the data on which is the change.Return the list of the primary key name for the data from database.abstract StringReturns the SQL request.getRow(int index) Returns the row corresponding to the index.getRowFromPksValues(Value... pksValues) Returns theRowwith the primary keys values in parameter.Returns the list of the values in rows for the data from database.protected abstract voidloadImpl(Connection connection) Implementation of the loading that depends of the kind of data.protected voidsetColumnsNameList(List<String> columnsNameList) Sets the list of the columns name.protected voidsetPksNameList(List<String> pksNameList) Sets the list of the primary key name.protected voidsortRows()Sorts the list of rows.Methods inherited from class org.assertj.db.type.AbstractDbElement
getColumnLetterCase, getConnection, getConnectionProvider, getMetaData, getPrimaryKeyLetterCase, getTableLetterCase
-
Constructor Details
-
AbstractDbData
protected AbstractDbData(Class<D> selfType, DataType dataType, ConnectionProvider connectionProvider) Constructor with aJdbcUrlConnectionProvider.- Parameters:
selfType- Class of this element : a subclass ofAbstractDbData.dataType- The type of the data on which is the change.connectionProvider- TheJdbcUrlConnectionProviderto connect to the database (must be notnull).- Throws:
NullPointerException- IfconnectionProviderisnull.
-
AbstractDbData
Only used for tests.- Parameters:
selfType- Class of DbElement.dataType- Type of DbData.
-
-
Method Details
-
getDataType
Returns the type of the data on which is the change.- Returns:
- The type of the data on which is the change.
-
getRequest
Returns the SQL request.- Returns:
- The SQL request.
- See Also:
-
sortRows
protected void sortRows()Sorts the list of rows. -
loadImpl
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 butloadImpl()is abstract here and it is implemented in the sub-classes depending of the need of the sub-class.- Parameters:
connection-Connectionto the database provided byload()method.- Throws:
SQLException- SQL Exception.- See Also:
-
collectRowsFromResultSet
Collects rows from aResultSet.This method browse the
ResultSetin parameter to get the data and fill the list ofRow(rowsList) with these data.- Parameters:
resultSet- TheResultSet.- Throws:
SQLException- A SQL Exception.
-
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 theload()private method.- Returns:
- The list of the columns name.
- Throws:
NullPointerException- If theconnectionProviderfields arenull.AssertJDBException- If triggered, this exception wrap a possibleSQLExceptionduring the loading.
-
setColumnsNameList
Sets the list of the columns name.- Parameters:
columnsNameList- The list of the columns name.
-
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 theload()private method.- Returns:
- The list of the primary key name.
- Throws:
NullPointerException- If theAbstractDbElement.getConnectionProvider()fields arenull.AssertJDBException- If triggered, this exception wrap a possibleSQLExceptionduring the loading.
-
setPksNameList
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
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 theload()private method.- Returns:
- The list of the values.
- Throws:
NullPointerException- If theconnectionProviderfields arenull.AssertJDBException- If triggered, this exception wrap a possibleSQLExceptionduring the loading.
-
getColumnsList
Returns the list of the values in columns for the data from database.This method calls
getColumnsNameList()andgetValuesList(int)which callsgetRowsList().
If it is the first call togetColumnsNameList()orgetRowsList(), the data are loaded from database by calling theload()private method.- Returns:
- The list of the values in columns.
- Throws:
NullPointerException- If theconnectionProviderfields arenull.AssertJDBException- If triggered, this exception wrap a possibleSQLExceptionduring the loading.
-
getColumn
Returns the column corresponding to the column index in parameter and the values inside the column.This method calls
getColumnsNameList()andgetValuesList(int)which callsgetRowsList().
If it is the first call togetColumnsNameList()orgetRowsList(), the data are loaded from database by calling theload()private method.- Parameters:
index- The column index.- Returns:
- The column and the values
- Throws:
NullPointerException- If theconnectionProviderfields arenull.AssertJDBException- If triggered, this exception wrap a possibleSQLExceptionduring the loading.
-
getRow
Returns the row corresponding to the index.This method calls
getRowsList().
If it is the first call togetRowsList(), the data are loaded from database by calling theload()private method.- Parameters:
index- The index- Returns:
- The
Row - Throws:
NullPointerException- If theconnectionProviderfields arenull.AssertJDBException- If triggered, this exception wrap a possibleSQLExceptionduring the loading.
-
getRowFromPksValues
Returns theRowwith the primary keys values in parameter.- Parameters:
pksValues- The primary keys values.- Returns:
- The
Rowwith the same primary keys values.
-