Package ru.bgcrm.dao

# Class CommonDAO

java.lang.Object
ru.bgcrm.dao.CommonDAO

Direct Known Subclasses:
  `AddressDAO`, `BGBillingDAO`, `Cleaner`, `CommonLinkDAO`, `ConfigDAO`, `ContractCustomerDAO`, `CustomerDAO`, `CustomerGroupDAO`, `CustomerParamSearchDAO`, `DatabaseDAO`, `DemoDAO`, `DispatchDAO`, `DocumentDAO`, `EMailDAO`, `EntityLogDAO`, `ExecuteSQL`, `FileDataDAO`, `Filter`, `GrplDAO`, `IfaceStateDAO`, `InvoiceNumberDAO`, `InvoiceSearchDAO`, `MessageDAO`, `MessagePossibleProcessSearch`, `MobileDAO`, `NewsDAO`, `OldParamSearchDAO`, `ParamDAO`, `ParamGroupDAO`, `ParamLogDAO`, `ParamValueDAO`, `ParamValueSelect`, `PartyDAO`, `PatternDAO`, `PeriodicDAO`, `ProcessCloneDAO`, `ProcessDAO`, `ProcessLinkSearchDAO`, `ProcessParamSearchDAO`, `ProcessSearchDAO`, `ProcessTypeDAO`, `PropertiesDAO`, `QueryDAO`, `QueryHistoryDAO`, `QueueDAO`, `ReportActionBase.Selector`, `SavedFilterDAO`, `SearchDAO`, `SecretDAO`, `ShiftDAO`, `StatusChangeDAO`, `StatusDAO`, `SubscriptionDAO`, `TabelDAO`, `TaskDAO`, `UserDAO`, `UserGroupDAO`, `WorkTaskDAO`, `WorkTypeDAO`

public class CommonDAO extends Object

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static interface`
  `CommonDAO.ObjectExtractor<T>`
  `protected class`
  `CommonDAO.RecordUpdater<T extends Id>`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Connection`
  `con`
  `protected final Log`
  `log`
  `protected static final String`
  `SQL_AND`
  `protected static final String`
  `SQL_DELETE`
  `protected static final String`
  `SQL_DELETE_FROM`
  `protected static final String`
  `SQL_DESC`
  `protected static final String`
  `SQL_DISTINCT`
  `protected static final String`
  `SQL_FROM`
  `protected static final String`
  `SQL_GROUP_BY`
  `protected static final String`
  `SQL_INNER_JOIN`
  `protected static final String`
  `SQL_INSERT_IGNORE_INTO`
  `protected static final String`
  `SQL_INSERT_INTO`
  `protected static final String`
  `SQL_LEFT_JOIN`
  `protected static final String`
  `SQL_LIMIT`
  `protected static final String`
  `SQL_ON_DUP_KEY_UPDATE`
  `protected static final String`
  `SQL_ORDER_BY`
  `protected static final String`
  `SQL_REPLACE`
  `protected static final String`
  `SQL_SELECT`
  `protected static final String`
  `SQL_SELECT_ALL_FROM`
  `protected static final String`
  `SQL_SELECT_COUNT_ROWS`
  `protected static final String`
  `SQL_SET`
  `protected static final String`
  `SQL_UNION_ALL`
  `protected static final String`
  `SQL_UPDATE`
  `protected static final String`
  `SQL_VALUES`
  `protected static final String`
  `SQL_VALUES_1`
  `protected static final String`
  `SQL_VALUES_2`
  `protected static final String`
  `SQL_VALUES_3`
  `protected static final String`
  `SQL_VALUES_4`
  `protected static final String`
  `SQL_VALUES_5`
  `protected static final String`
  `SQL_WHERE`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `CommonDAO()`
  `protected`
  `CommonDAO(Connection con)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `deleteById(String tableName, int id)`
  `static int`
  `foundRows(Statement st)`
  Selects `FOUND_ROWS()` for given statement.
  `protected <T> T`
  `getById(String tableName, int id, CommonDAO.ObjectExtractor<T> extractor)`
  `protected Map<Integer,Set<Integer>>`
  `getGroupedIds(String tableName, String linkColumn, String selectColumn)`
  `protected Map<Integer,List<Integer>>`
  `getGroupedIds(String tableName, String linkColumn, String selectColumn, String posColumn)`
  `protected Set<Integer>`
  `getIds(String tableName, String linkColumn, String selectColumn, int id)`
  `protected List<Integer>`
  `getIds(String tableName, String linkColumn, String selectColumn, String posColumn, int id)`
  Queries int list SELECT `selectColumn` FROM `tableName` WHERE `linkColumn` = `id` ORDER BY `posColumn`
  `protected String`
  `getPageLimit(Page page)`
  Deprecated.
  `protected String`
  `getPeriodSql(Period period, String fieldName)`
  Deprecated.
  `protected int`
  `lastInsertId(PreparedStatement ps)`
  Takes last generated key from `ps`.
  `protected int`
  `setPeriodParamValue(Period period, PreparedStatement ps, int index)`
  Deprecated.
  `protected void`
  `setRecordCount(Page page, PreparedStatement ps)`
  Deprecated.
  `protected <T extends Id>
  void`
  `update(T record, CommonDAO.RecordUpdater<T> updater)`
  `protected void`
  `updateColumn(String tableName, int id, String columnName, String value)`
  `protected void`
  `updateIds(String tableName, String linkColumn, String valueColumn, Object id, Set<Integer> values)`
  `protected void`
  `updateIds(String tableName, String linkColumn, String valueColumn, String posColumn, int id, List<Integer> values)`
  `protected int`
  `updateOrInsert(String updatePsQuery, String insertPsQuery, Object... params)`
  Updates and if no records updated then inserting a new one.

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

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

- ## Field Details

  - ### log

    protected final Log log

  - ### SQL_SELECT

    protected static final String SQL_SELECT
    See Also:
      - Constant Field Values

  - ### SQL_SELECT_ALL_FROM

    protected static final String SQL_SELECT_ALL_FROM
    See Also:
      - Constant Field Values

  - ### SQL_SELECT_COUNT_ROWS

    protected static final String SQL_SELECT_COUNT_ROWS
    See Also:
      - Constant Field Values

  - ### SQL_DISTINCT

    protected static final String SQL_DISTINCT
    See Also:
      - Constant Field Values

  - ### SQL_INSERT_IGNORE_INTO

    protected static final String SQL_INSERT_IGNORE_INTO
    See Also:
      - Constant Field Values

  - ### SQL_INSERT_INTO

    protected static final String SQL_INSERT_INTO
    See Also:
      - Constant Field Values

  - ### SQL_VALUES

    protected static final String SQL_VALUES
    See Also:
      - Constant Field Values

  - ### SQL_VALUES_1

    protected static final String SQL_VALUES_1
    See Also:
      - Constant Field Values

  - ### SQL_VALUES_2

    protected static final String SQL_VALUES_2
    See Also:
      - Constant Field Values

  - ### SQL_VALUES_3

    protected static final String SQL_VALUES_3
    See Also:
      - Constant Field Values

  - ### SQL_VALUES_4

    protected static final String SQL_VALUES_4
    See Also:
      - Constant Field Values

  - ### SQL_VALUES_5

    protected static final String SQL_VALUES_5
    See Also:
      - Constant Field Values

  - ### SQL_SET

    protected static final String SQL_SET
    See Also:
      - Constant Field Values

  - ### SQL_UPDATE

    protected static final String SQL_UPDATE
    See Also:
      - Constant Field Values

  - ### SQL_DELETE

    protected static final String SQL_DELETE
    See Also:
      - Constant Field Values

  - ### SQL_DELETE_FROM

    protected static final String SQL_DELETE_FROM
    See Also:
      - Constant Field Values

  - ### SQL_FROM

    protected static final String SQL_FROM
    See Also:
      - Constant Field Values

  - ### SQL_LEFT_JOIN

    protected static final String SQL_LEFT_JOIN
    See Also:
      - Constant Field Values

  - ### SQL_INNER_JOIN

    protected static final String SQL_INNER_JOIN
    See Also:
      - Constant Field Values

  - ### SQL_WHERE

    protected static final String SQL_WHERE
    See Also:
      - Constant Field Values

  - ### SQL_ORDER_BY

    protected static final String SQL_ORDER_BY
    See Also:
      - Constant Field Values

  - ### SQL_GROUP_BY

    protected static final String SQL_GROUP_BY
    See Also:
      - Constant Field Values

  - ### SQL_AND

    protected static final String SQL_AND
    See Also:
      - Constant Field Values

  - ### SQL_LIMIT

    protected static final String SQL_LIMIT
    See Also:
      - Constant Field Values

  - ### SQL_DESC

    protected static final String SQL_DESC
    See Also:
      - Constant Field Values

  - ### SQL_REPLACE

    protected static final String SQL_REPLACE
    See Also:
      - Constant Field Values

  - ### SQL_ON_DUP_KEY_UPDATE

    protected static final String SQL_ON_DUP_KEY_UPDATE
    See Also:
      - Constant Field Values

  - ### SQL_UNION_ALL

    protected static final String SQL_UNION_ALL
    See Also:
      - Constant Field Values

  - ### con

    protected Connection con

- ## Constructor Details

  - ### CommonDAO

    protected CommonDAO()

  - ### CommonDAO

    protected CommonDAO(Connection con)

- ## Method Details

  - ### foundRows

    public static int foundRows(Statement st) throws SQLException
    Selects `FOUND_ROWS()` for given statement.
    Parameters:
      `st` -
    Returns:
    Throws:
      `SQLException`

  - ### lastInsertId

    protected int lastInsertId(PreparedStatement ps) throws SQLException
    Takes last generated key from `ps`.
    Parameters:
      `ps` -
    Returns:
    Throws:
      `SQLException`

  - ### updateOrInsert

    protected int updateOrInsert(String updatePsQuery, String insertPsQuery, Object... params) throws SQLException
    Updates and if no records updated then inserting a new one.
    Parameters:
      `updatePsQuery` - UPDATE query with ? placeholders.
      `insertPsQuery` - INSERT query with ? placeholders.
      `params` - `PreparedQuery` parameters for both queries.
    Returns:
      ID of a newly inserted record, or `0`
    Throws:
      `SQLException`

  - ### getIds

    protected Set<Integer> getIds(String tableName, String linkColumn, String selectColumn, int id) throws SQLException
    Throws:
      `SQLException`

  - ### getIds

    protected List<Integer> getIds(String tableName, String linkColumn, String selectColumn, String posColumn, int id) throws SQLException
    Queries int list SELECT `selectColumn` FROM `tableName` WHERE `linkColumn` = `id` ORDER BY `posColumn`
    Parameters:
      `tableName` -
      `linkColumn` -
      `selectColumn` -
      `posColumn` -
      `id` -
    Returns:
    Throws:
      `SQLException`

  - ### getGroupedIds

    protected Map<Integer,Set<Integer>> getGroupedIds(String tableName, String linkColumn, String selectColumn) throws SQLException
    Throws:
      `SQLException`

  - ### getGroupedIds

    protected Map<Integer,List<Integer>> getGroupedIds(String tableName, String linkColumn, String selectColumn, String posColumn) throws SQLException
    Throws:
      `SQLException`

  - ### getById

    protected <T> T getById(String tableName, int id, CommonDAO.ObjectExtractor<T> extractor) throws SQLException
    Throws:
      `SQLException`

  - ### deleteById

    protected void deleteById(String tableName, int id) throws SQLException
    Throws:
      `SQLException`

  - ### update

    protected <T extends Id> void update(T record, CommonDAO.RecordUpdater<T> updater) throws SQLException
    Throws:
      `SQLException`

  - ### updateIds

    protected void updateIds(String tableName, String linkColumn, String valueColumn, Object id, Set<Integer> values) throws SQLException
    Throws:
      `SQLException`

  - ### updateIds

    protected void updateIds(String tableName, String linkColumn, String valueColumn, String posColumn, int id, List<Integer> values) throws SQLException
    Throws:
      `SQLException`

  - ### updateColumn

    protected void updateColumn(String tableName, int id, String columnName, String value) throws SQLException
    Throws:
      `SQLException`

  - ### getPageLimit

    @Deprecated protected String getPageLimit(Page page)
    Deprecated.

  - ### setRecordCount

    @Deprecated protected void setRecordCount(Page page, PreparedStatement ps) throws SQLException
    Deprecated.
    Throws:
      `SQLException`

  - ### getPeriodSql

    @Deprecated protected String getPeriodSql(Period period, String fieldName)
    Deprecated.

  - ### setPeriodParamValue

    @Deprecated protected int setPeriodParamValue(Period period, PreparedStatement ps, int index) throws SQLException
    Deprecated.
    Throws:
      `SQLException`