Package org.silverpeas.components.mydb.model

# Class DbTable

java.lang.Object
org.silverpeas.components.mydb.model.DbTable

public class DbTable extends Object
Table loaded from the database referred by a `MyDBConnectionInfo` instance.

Author:
  mmoquillon

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(TableRow row)`
  Adds the specified row into this table.
  `static Optional<DbTable>`
  `defaultTable(MyDBConnectionInfo dsInfo)`
  Loads the default table defined in the specified `MyDBConnectionInfo` instance.
  `long`
  `delete(TableRow row)`
  Deletes the specified row.
  `Optional<DbColumn>`
  `getColumn(String name)`
  Gets the column with the specified name.
  `List<DbColumn>`
  `getColumns()`
  Gets all the columns that made up this table.
  `String`
  `getName()`
  Gets this table's name.
  `org.silverpeas.core.util.SilverpeasList<TableRow>`
  `getRows(ColumnValuePredicate filter, String orderBy, org.silverpeas.core.admin.PaginationPage pagination)`
  Gets the contents of this table as a list of rows, each of them being a tuple valuing all the columns of this table.
  `static List<String>`
  `list(MyDBConnectionInfo dsInfo)`
  Gets a listing of the names of all the business tables in the database.
  `static Optional<DbTable>`
  `table(String tableName, MyDBConnectionInfo dsInfo)`
  Gets the table with the specified name from the database referenced by the given connection information.
  `long`
  `update(TableRow actualRow, TableRow updatedRow)`
  Updates the specified row with the specified other row.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### defaultTable

    public static Optional<DbTable> defaultTable(MyDBConnectionInfo dsInfo)
    Loads the default table defined in the specified `MyDBConnectionInfo` instance. If no default table is defined then nothing is returned. If the default table doesn't exist then a `MyDBRuntimeException` is thrown.
    Parameters:
      `dsInfo` - the `MyDBConnectionInfo` instance with information to access the database and to get the name of the table load.
    Returns:
      optionally a `DbTable` instance or nothing if no default table is set in the specified `MyDBConnectionInfo` instance.

  - ### table

    public static Optional<DbTable> table(String tableName, MyDBConnectionInfo dsInfo)
    Gets the table with the specified name from the database referenced by the given connection information. If no such a table doesn't exist, then nothing is returned.
    Parameters:
      `tableName` - the name of a table in the database.
      `dsInfo` - the `MyDBConnectionInfo` instance with information to access the database
    Returns:
      optionally a `DbTable` instance or nothing if no such a table exist in the database.

  - ### list

    public static List<String> list(MyDBConnectionInfo dsInfo)
    Gets a listing of the names of all the business tables in the database. The database is identified by the specified `MyDBConnectionInfo` instance. (The system and technical tables aren't get.)
    Parameters:
      `dsInfo` - the `MyDBConnectionInfo` instance with information to access the database.
    Returns:
      a list with the name of all the business tables in the database.

  - ### getName

    public String getName()
    Gets this table's name.
    Returns:
      the name of this table.

  - ### getColumns

    public List<DbColumn> getColumns()
    Gets all the columns that made up this table. If no columns were specified for this table, then an empty list is returned.
    Returns:
      a list of columns.

  - ### getColumn

    public Optional<DbColumn> getColumn(String name)
    Gets the column with the specified name.
    Parameters:
      `name` - the name of the column.
    Returns:
      optionally the asked column. If no such column exists then an empty optional is returned.

  - ### getRows

    public org.silverpeas.core.util.SilverpeasList<TableRow> getRows(ColumnValuePredicate filter, String orderBy, org.silverpeas.core.admin.PaginationPage pagination)
    Gets the contents of this table as a list of rows, each of them being a tuple valuing all the columns of this table. If the table is empty, then an empty list is returned.
    Parameters:
      `filter` - a predicate to use for filtering the table content.
      `orderBy` - an order by directive already built (without the clause keywords).
      `pagination` - a pagination in order to avoid bad performances.
    Returns:
      a list of table rows. If a filter is set, it is then applied when requesting the content of this table. The number of table rows is limited by the `MyDBConnectionInfo.getDataMaxNumber()` property.

  - ### delete

    public long delete(TableRow row)
    Deletes the specified row.
    Parameters:
      `row` - the row to delete in this database table.

  - ### update

    public long update(TableRow actualRow, TableRow updatedRow)
    Updates the specified row with the specified other row.
    Parameters:
      `actualRow` - the row currently in this table.
      `updatedRow` - the row that will replace the actual one in this table.

  - ### add

    public void add(TableRow row)
    Adds the specified row into this table. The row will be inserted into the database table.
    Parameters:
      `row` - the row to add into the database table.