/**
  * INTERNAL:
  * Adds a sql result set mapping to this class.
  *
  * @throws MappingException
  * @param array $resultMapping
  */
 public function addSqlResultSetMapping(array $resultMapping)
 {
     if (!isset($resultMapping['name'])) {
         throw MappingException::nameIsMandatoryForSqlResultSetMapping($this->name);
     }
     if (isset($this->sqlResultSetMappings[$resultMapping['name']])) {
         throw MappingException::duplicateResultSetMapping($this->name, $resultMapping['name']);
     }
     if (isset($resultMapping['entities'])) {
         foreach ($resultMapping['entities'] as $key => $entityResult) {
             if (!isset($entityResult['entityClass'])) {
                 throw MappingException::missingResultSetMappingEntity($this->name, $resultMapping['name']);
             }
             $entityResult['isSelfClass'] = false;
             if ($entityResult['entityClass'] === '__CLASS__') {
                 $entityResult['isSelfClass'] = true;
                 $entityResult['entityClass'] = $this->name;
             } else {
                 if (strlen($this->namespace) > 0 && strpos($entityResult['entityClass'], '\\') === false) {
                     $entityResult['entityClass'] = $this->namespace . '\\' . $entityResult['entityClass'];
                 }
             }
             $resultMapping['entities'][$key]['entityClass'] = ltrim($entityResult['entityClass'], '\\');
             $resultMapping['entities'][$key]['isSelfClass'] = $entityResult['isSelfClass'];
             if (isset($entityResult['fields'])) {
                 foreach ($entityResult['fields'] as $k => $field) {
                     if (!isset($field['name'])) {
                         throw MappingException::missingResultSetMappingFieldName($this->name, $resultMapping['name']);
                     }
                     if (!isset($field['column'])) {
                         $fieldName = $field['name'];
                         if (strpos($fieldName, '.')) {
                             list(, $fieldName) = explode('.', $fieldName);
                         }
                         $resultMapping['entities'][$key]['fields'][$k]['column'] = $fieldName;
                     }
                 }
             }
         }
     }
     $this->sqlResultSetMappings[$resultMapping['name']] = $resultMapping;
 }