Method to lock the database table for writing.

@return  boolean  True on success.
@since   2.1.12
@throws  Exception
977090
protected function _lock()
	{
		$this->_db->lockTable($this->_tbl);
		$this->_locked = true;

		return true;
	}
980427
public function lock()
    {
        //Prevent lock take over, only an saved and unlocked row and be locked
        if(!$this->isNew() && !$this->isLocked())
        {
            $this->locked_by = (int) $this->getObject('user')->getId();
            $this->locked_on = gmdate('Y-m-d H:i:s');
            $this->save();
        }

        return true;
    }
1223237
public static function isLockPrivilegeGranted()
    {
        if (is_null(self::$lockPrivilegeGranted)) {
            try {
                Db::lockTables(Common::prefixTable('log_visit'));
                Db::unlockAllTables();

                self::$lockPrivilegeGranted = true;
            } catch (Exception $ex) {
                self::$lockPrivilegeGranted = false;
            }
        }

        return self::$lockPrivilegeGranted;
    }
787849
public function save()
    {
        if (!$entityMgr = $this->getEntityManager()) {
            throw new \Exception('Model can not be inserted without an Entity Manager (setEntityManager).');
        }

        if (!$this->getTableName()) {
            throw new \Exception('Model can not be inserted without a defined table name.');
        }

        $stmtManager = $entityMgr->getStatementManager(Simple::class);

        /** @var InsertModel $stmtBuilder */
        $stmtBuilder = $stmtManager->getStatementBuilder(InsertModel::class);

        return $stmtManager
            ->setStatement($stmtBuilder->setModel($this))
            ->setConsistency(\Cassandra::CONSISTENCY_LOCAL_ONE)
            ->execute();
    }
225799
public function lock($tables) {
        $lock = '';
        foreach (explode(',', $tables) as $tab) {
            $lock .= tablename(trim($tab)) . " WRITE,";
        }
        return $this->execute("LOCK TABLES " . substr($lock, 0, -1));
    }
1318953
public function lock()
    {
        $user = UserHelper::getUser($this->getUserResource());

        if ($this->getUserLocksService()->lockUser($user)) {
            $this->returnJson(['success' => true, 'message' => __('User %s successfully locked', UserHelper::getUserLogin(UserHelper::getUser($user)))]);
        } else {
            $this->returnJson(['success' => false, 'message' => __('User %s can not be locked', UserHelper::getUserLogin(UserHelper::getUser($user)))]);
        }
    }
275726
protected function _ensureWritable()
    {
        if (!$this->valid()) {
            throw new RuntimeException('Cannot write on a closed stream.');
        }
        if (!$this->isWritable()) {
            $mode = $this->meta('mode');
            throw new RuntimeException("Cannot write on a non-writable stream (mode is `'{$mode}'`).");
        }
    }
914196
public function lock()
    {
        if (!$this->isLocked()) {
            $file = fopen($this->getFilePath(), 'w');
            if ($file) {
                fwrite($file, getmypid());
                fclose($file);
                return true;
            }
        }
        return false;
    }
472961
private function rollBack(\Exception $exception)
    {
        try {
            $this->pdo->rollBack();
        } catch (\PDOException $e2) {
            throw new LockAcquireException(
                "Could not roll back transaction: {$e2->getMessage()})",
                0,
                $exception
            );
        }
    }
1294480
public function write($showDebug = false, $forceInsert = false, $forceWrite = false, $writeComponents = false)
    {
        throw new Exception("{$this->ClassName} can not be written back to the database.");
    }
253742
public function lockTables($tables)
    {
        /**
         * Unlock any previously locked tables
         * This is done to provide consistency across different modes, as mysql only allows one single lock over multiple tables
         * Also the odbc only allows all locks to be released, not individual tables. So it makes sense to force the batching of lock/unlock operations
         */
        $this->unlockTables();

        $tables = Helper::toArray($tables);

        if ($this->mode == "odbc") {
            foreach ($tables as $table) {
                $table = $this->getTableName($table);
                $query = "LOCK TABLE " . $table . " IN EXCLUSIVE MODE ALLOW READ";
                $this->query($query);
            }

            # If none of the locks failed then report success
            return true;
        }

        foreach ($tables as &$table) {
            $table = $this->getTableName($table);
        }
        unset($table);

        if ($this->mode == "mysql") {
            $query = "LOCK TABLES " . implode(",", $tables) . " WRITE";
            return $this->query($query);
        }

        if (in_array($this->mode, ["postgres", "redshift"], true)) {
            $query = "LOCK TABLE " . implode(",", $tables) . " IN EXCLUSIVE MODE";
            return $this->query($query);
        }

        throw new \Exception("lockTables() not supported in this mode (" . $this->mode . ")");
    }
1086382
public function init() {
        if (!$this->database->session_lock_supported()) {
            throw new exception('sessionhandlerproblem', 'error', '', null, 'Database does not support session locking');
        }

        $result = session_set_save_handler(array($this, 'handler_open'),
            array($this, 'handler_close'),
            array($this, 'handler_read'),
            array($this, 'handler_write'),
            array($this, 'handler_destroy'),
            array($this, 'handler_gc'));
        if (!$result) {
            throw new exception('dbsessionhandlerproblem', 'error');
        }
    }
383026
public boolean writeLocked (@Nonnull final BooleanSupplier aSupplier)
  {
    writeLock ().lock ();
    try
    {
      return aSupplier.getAsBoolean ();
    }
    finally
    {
      writeLock ().unlock ();
    }
  }
1192423
private function createTable(): void
    {
        $statement = 'CREATE TABLE tests (
                          id INTEGER PRIMARY KEY,
                          command TEXT NOT NULL UNIQUE,
                          file_name TEXT NOT NULL,
                          reserved_by_process_id INTEGER,
                          completed INTEGER DEFAULT 0
                        )';

        if ($this->db->exec($statement) === false) {
            throw new Exception('Error while creating sqlite database table: ' . $this->db->errorCode());
        }
    }
825971
public function rollback()
    {
        switch ($this->mode) {

            case "mysql":
                $result = $this->server->rollback();
                break;

            case "postgres":
            case "redshift":
                $result = $this->query("ROLLBACK");
                break;

            case "odbc":
                $result = odbc_rollback($this->server);
                break;

            default:
                throw new \Exception("rollback() not supported in this mode (" . $this->mode . ")");
        }

        if (!$result) {
            $this->error();
        }

        return true;
    }
322927
public function check()
	{
		// Check if the db connector has been set.
		if (!($this->db instanceof MysqlDriver))
		{
			throw new \Exception('Database connection wrong type.');
		}

		// Check if the tables have been specified.
		if (empty($this->from))
		{
			throw new \Exception('ERROR: No Tables Specified');
		}

		return $this;
	}
324736
public function commit()
    {
        if ($this->_active && $this->_db->getActive()) {
            $this->_db->getPdoInstance()->commit();
            $this->_active = false;
        } else {
            throw new Exception('"Transaction"尚属未激活状态，不能执行"commit"和"rollback"操作', 101300601);
        }
    }