public function delete($document, array $options = array())
{
$id = $this->uow->getDocumentIdentifier($document);
$query = array('_id' => $this->class->getDatabaseIdentifierValue($id));
if ($this->class->isVersioned) {
$query['locked'] = array($this->cmd . 'exists' => false);
$options['safe'] = true;
}
$result = $this->collection->remove($query, $options);
if (($this->class->isVersioned || $this->class->isLockable) && ! $result['n']) {
throw LockException::lockFailed($document);
}
}