You are here

protected function MerciDefaultEntityController::buildQuery in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Override of DrupalDefaultEntityController::buildQuery().

Handle pessimistic locking.

Overrides DrupalDefaultEntityController::buildQuery

File

merci_line_item/includes/merci_line_item.controller.inc, line 28
Provides a central controller for Drupal Commerce.

Class

MerciDefaultEntityController
@file Provides a central controller for Drupal Commerce.

Code

protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
  $query = parent::buildQuery($ids, $conditions, $revision_id);
  if (isset($this->entityInfo['locking mode']) && $this->entityInfo['locking mode'] == 'pessimistic') {

    // In pessimistic locking mode, we issue the load query with a FOR UPDATE
    // clause. This will block all other load queries to the loaded objects
    // but requires us to start a transaction.
    if (empty($this->controllerTransaction)) {
      $this->controllerTransaction = db_transaction();
    }
    $query
      ->forUpdate();

    // Store the ids of the entities in the lockedEntities array for later
    // tracking, flipped for easier management via unset() below.
    if (is_array($ids)) {
      $this->lockedEntities += array_flip($ids);
    }
  }
  return $query;
}