/**
  * Checks whether the given managed entity exists in the database.
  *
  * @param object $entity
  * @return boolean TRUE if the entity exists in the database, FALSE otherwise.
  */
 public function exists($entity, array $extraConditions = array())
 {
     $criteria = $this->_class->getIdentifierValues($entity);
     if ($extraConditions) {
         $criteria = array_merge($criteria, $extraConditions);
     }
     $sql = 'SELECT 1 FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($this->_class->name) . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
     return (bool) $this->_conn->fetchColumn($sql, array_values($criteria));
 }
 /**
  * Retrieves the default version value which was created
  * by the preceding INSERT statement and assigns it back in to the 
  * entities version field.
  *
  * @param $class
  * @param $entity
  * @param $id
  */
 protected function _assignDefaultVersionValue($class, $entity, $id)
 {
     $versionField = $this->_class->versionField;
     $identifier = $this->_class->getIdentifierColumnNames();
     $versionFieldColumnName = $this->_class->getColumnName($versionField);
     //FIXME: Order with composite keys might not be correct
     $sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform) . " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
     $value = $this->_conn->fetchColumn($sql, array_values((array) $id));
     $this->_class->setFieldValue($entity, $versionField, $value);
 }