/**
* @param Contract $streamContract
* @param Identifier $streamId
* @param $expectedStreamRevision
* @throws \EventCentric\Persistence\OptimisticConcurrencyFailed
*/
protected function controlOptimisticConcurrency(Contract $streamContract, Identifier $streamId, $expectedStreamRevision)
{
$result = $this->connection->fetchArray(MaxStreamRevision::from(self::TABLE_NAME), ['streamContract' => $streamContract, 'streamId' => $streamId]);
$actualStreamRevision = (int) $result[0];
if ($actualStreamRevision != $expectedStreamRevision) {
throw OptimisticConcurrencyFailed::revisionDoesNotMatch($expectedStreamRevision, $actualStreamRevision);
}
}