Ejemplo n.º 1
0
 public function formatRecord(array &$records = NULL, $record)
 {
     $result = parent::formatRecord($records, $record);
     if ($result) {
         $this->errorUnsupportedChainOfResultFormatters();
     }
     $recordKey = NULL;
     foreach ($this->keyColumnNames as $columnName) {
         $recordKey[] = isset($record[$columnName]) ? $record[$columnName] : NULL;
     }
     $key = ArrayHelper::prepareCompositeKey($recordKey);
     if (isset($records[$key])) {
         if ($this->isColumnValueUnique) {
             throw new IllegalArgumentException(t('Found several records for the key: @key', array('@key' => ArrayHelper::printArray($recordKey, ', ', TRUE, TRUE))));
         }
         $records[$key][] = $record;
     } else {
         if ($this->isColumnValueUnique) {
             $records[$key] = $record;
         } else {
             $records[$key][] = $record;
         }
     }
     return TRUE;
 }
 public function getValues(array $names)
 {
     $timeStart = microtime(TRUE);
     $values = parent::getValues($names);
     $nameCount = count($names);
     $loadedValueCount = count($values);
     LogHelper::log_debug(t('[@cacheType] Requested entries: @entryNames', array('@cacheType' => $this->getCacheType(), '@entryNames' => ArrayHelper::printArray(array_values($names), ', ', TRUE, FALSE))));
     LogHelper::log_debug(t('[@cacheType] Retrieved entries: @entryNames', array('@cacheType' => $this->getCacheType(), '@entryNames' => $nameCount == $loadedValueCount ? 'ALL' : (isset($values) ? ArrayHelper::printArray(array_keys($values), ', ', TRUE, FALSE) : 'NONE'))));
     LogHelper::log_info(t('[@cacheType] Execution time for retrieving @entryCount entries is !executionTime. @successFlag', array('@cacheType' => $this->getCacheType(), '@entryCount' => $nameCount, '!executionTime' => ExecutionPerformanceHelper::formatExecutionTime($timeStart), '@successFlag' => isset($values) ? $nameCount == $loadedValueCount ? 'Cache HIT' : "Cache hit for ONLY {$loadedValueCount} entries out of {$nameCount}" : 'Cache NOT hit')));
     return $values;
 }
Ejemplo n.º 3
0
 public function selectDataType(array $datatypes, $selectCompatible = TRUE)
 {
     // eliminating null records from the array
     if (isset($datatypes)) {
         foreach ($datatypes as $index => $datatype) {
             if (!isset($datatype)) {
                 unset($datatypes[$index]);
             }
         }
         if (count($datatypes) == 0) {
             $datatypes = NULL;
         }
     }
     if (!isset($datatypes)) {
         return NULL;
     }
     // checking if all elements are equal
     $selectedDataType = NULL;
     foreach ($datatypes as $datatype) {
         if (isset($selectedDataType)) {
             if ($selectedDataType != $datatype) {
                 $selectedDataType = NULL;
                 break;
             }
         } else {
             $selectedDataType = $datatype;
         }
     }
     if (isset($selectedDataType)) {
         return $selectedDataType;
     }
     // checking if we need to return compatible type
     if (!$selectCompatible) {
         // if some types are not compatible we need to return the lowest compatible type
         if (!$this->areCompatible($datatypes)) {
             $selectCompatible = TRUE;
         }
     }
     $selectedDataTypes = $datatypes;
     if ($selectCompatible) {
         do {
             $initialDataTypeCount = count($selectedDataTypes);
             $selectedDataTypes = $this->selectCompatible($selectedDataTypes);
             $selectedDataTypeCount = count($selectedDataTypes);
             if ($initialDataTypeCount > 1 && $initialDataTypeCount == $selectedDataTypeCount) {
                 throw new IncompatibleDataTypeException(t('Data types are inter-compatible. Single type could not be selected: @datatypes', array('@datatypes' => ArrayHelper::printArray($datatypes, ',', TRUE, FALSE))));
             }
         } while ($selectedDataTypeCount > 1);
     } else {
         // it is expected that we have only 2 types here
         while (($datatypeCount = count($selectedDataTypes)) >= 2) {
             $datatypeA = $selectedDataTypes[0];
             $datatypeB = $selectedDataTypes[1];
             $selectedByDataTypeA = $this->getHandler($datatypeA)->selectCompatible($datatypeB);
             $selectedByDataTypeB = $this->getHandler($datatypeB)->selectCompatible($datatypeA);
             $selectedDataType = NULL;
             if (isset($selectedByDataTypeA)) {
                 if (isset($selectedByDataTypeB)) {
                     throw new IncompatibleDataTypeException(t("Data types '@datatypeA' and '@datatypeB' are inter-compatible. Single type could not be selected", array('@datatypeA' => $datatypeA, '@datatypeB' => $datatypeB)));
                 } else {
                     $selectedDataType = $selectedByDataTypeA;
                 }
             } elseif (isset($selectedByDataTypeB)) {
                 $selectedDataType = $selectedByDataTypeB;
             } else {
                 throw new UnsupportedOperationException();
             }
             $selectedDataTypes = array_slice($selectedDataTypes, 2);
             // selecting opposite data type. We do not need the lowest compatible type
             $selectedDataTypes[] = $selectedDataType == $datatypeA ? $datatypeB : $datatypeA;
         }
     }
     if (count($selectedDataTypes) == 1) {
         return $selectedDataTypes[0];
     } else {
         throw new IncompatibleDataTypeException(t('Incompatible data types: @datatypes', array('@datatypes' => ArrayHelper::printArray($datatypes, ',', TRUE, FALSE))));
     }
 }
Ejemplo n.º 4
0
 public function findNestedLinkByDatasetNameAndParentColumnNames($datasetName, $parentColumnNames)
 {
     $selectedNestedLink = NULL;
     if (isset($this->nestedLinks)) {
         $parentColumnCount = count($parentColumnNames);
         foreach ($this->nestedLinks as $nestedLink) {
             if ($nestedLink->dataset->name !== $datasetName) {
                 continue;
             }
             $nestedLinkParentColumnCount = count($nestedLink->parentColumnNames);
             if ($nestedLinkParentColumnCount != $parentColumnCount) {
                 continue;
             }
             foreach ($nestedLink->parentColumnNames as $parentColumnIndex => $nestedLinkParentColumnName) {
                 if (!isset($parentColumnNames[$parentColumnIndex])) {
                     continue 2;
                 }
                 if ($nestedLinkParentColumnName != $parentColumnNames[$parentColumnIndex]) {
                     continue 2;
                 }
             }
             if (isset($selectedNestedLink)) {
                 throw new UnsupportedOperationException(t("Found several nested reference links for '@datasetName' dataset by the parent columns: @parentColumns", array('@datasetName' => $datasetName, '@parentColumns' => ArrayHelper::printArray($parentColumnNames, ', ', TRUE, FALSE))));
             }
             $selectedNestedLink = $nestedLink;
         }
     }
     return $selectedNestedLink;
 }