public function lock($document, $lockMode, $lockVersion = null)
{
if ($this->getDocumentState($document) != self::STATE_MANAGED) {
throw new \InvalidArgumentException('Document is not MANAGED.');
}
$documentName = get_class($document);
$class = $this->dm->getClassMetadata($documentName);
if ($lockMode == LockMode::OPTIMISTIC) {
if (!$class->isVersioned) {
throw LockException::notVersioned($documentName);
}
if ($lockVersion != null) {
$documentVersion = $class->reflFields[$class->versionField]->getValue($document);
if ($documentVersion != $lockVersion) {
throw LockException::lockFailedVersionMissmatch($document, $lockVersion, $documentVersion);
}
}
} elseif (in_array($lockMode, array(LockMode::PESSIMISTIC_READ, LockMode::PESSIMISTIC_WRITE))) {
$this->getDocumentPersister($class->name)->lock($document, $lockMode);
}
}