public function load(AbstractMetaModel $environment_metamodel, array $filters = NULL) {
        LogHelper::log_notice(t('Generating Environment Meta Model for Drupal database connections ...'));

        global $databases;

        $datasourceCount = 0;
        foreach ($databases as $namespace => $connections) {
            foreach ($connections as $datasourceNameOnly => $connection) {
                $datasource = new DataSourceMetaData();
                $datasource->name = NameSpaceHelper::addNameSpace($namespace, $datasourceNameOnly);
                $datasource->markAsPrivate();
                $datasource->readonly = FALSE;
                // setting required properties
                $this->setDataSourceProperty($datasource, $connection, 'type', 'driver');
                // setting other provided properties
                $this->setDataSourceExtensionProperties($datasource, $connection);

                // registering the data source
                $environment_metamodel->registerDataSource($datasource);
                $datasourceCount++;
            }
        }

        // Default database connection is shared because we store common utilities and dimensions there
        $defaultDataSource = $environment_metamodel->getDataSource(self::$DATASOURCE_NAME__DEFAULT);
        $defaultDataSource->shared = TRUE;

        LogHelper::log_info(t('Generated @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
    }
    public function load(AbstractMetaModel $environment_metamodel, array $filters = NULL) {
        LogHelper::log_notice(t('Loading Environment Meta Model from settings.php ...'));

        $datasourceCount = 0;

        $configurationDataSources = Environment::getInstance()->getConfigurationSection('Data Sources');
        if (isset($configurationDataSources)) {
            foreach ($configurationDataSources as $namespace => $sourceDataSources) {
                foreach ($sourceDataSources as $datasourceName => $sourceDataSource) {
                    $datasourceName = NameSpaceHelper::resolveNameSpace($namespace, $datasourceName);

                    $datasource = new DataSourceMetaData();
                    $datasource->name = $datasourceName;
                    $datasource->initializeFrom($sourceDataSource);
                    // it is possible that configuration contains 'readonly' property. We need to honor it
                    // ... and only when it is not set we mark the data source as read only
                    if (!isset($datasource->readonly)) {
                        $datasource->readonly = TRUE;
                    }

                    $environment_metamodel->registerDataSource($datasource);

                    $datasourceCount++;
                }
            }
        }

        LogHelper::log_info(t('Processed @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
    }
 public static function adjustReferencePointColumn(MetaModelLoader $metamodelLoader, AbstractMetaModel $metamodel, DatasetReferencePointColumn $referencePointColumn)
 {
     if (!isset($referencePointColumn->columnName)) {
         $dataset = $metamodel->getDataset($referencePointColumn->datasetName);
         // FIXME eliminate this logic. Support configuration postprocessing
         $referencePointColumn->columnName = $dataset->getKeyColumn()->name;
     }
     if ($metamodelLoader instanceof ReferenceMetaModelLoader) {
         $metamodelLoader->adjustReferencePointColumn($metamodel, $referencePointColumn);
     }
 }
 public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $environment_metamodel, array $filters = NULL, $finalAttempt)
 {
     LogHelper::log_notice(t('Generating Environment Meta Model for APC cache ...'));
     $datasourceCount = 0;
     $datasource = new DataSourceMetaData();
     $datasource->name = NameSpaceHelper::addNameSpace(APCHandler::$CACHE__TYPE, DefaultCacheFactory::$DATASOURCE_NAME__DEFAULT);
     $datasource->type = APCHandler::$CACHE__TYPE;
     $environment_metamodel->registerDataSource($datasource);
     $datasourceCount++;
     LogHelper::log_info(t('Generated @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
     return self::LOAD_STATE__SUCCESSFUL;
 }
    public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $environment_metamodel, array $filters = NULL) {
        LogHelper::log_notice(t('Generating Environment Meta Model for PHP dataset functionality ...'));

        $datasourceCount = 0;

        $datasource = new DataSourceMetaData();
        $datasource->name = PHPDataSourceHandler::$DATASOURCE_NAME__DEFAULT;
        $datasource->type = PHPDataSourceHandler::$DATASOURCE__TYPE;
        $environment_metamodel->registerDataSource($datasource);
        $datasourceCount++;

        LogHelper::log_info(t('Generated @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
    }
    public function finishGlobalModification($commit) {
        if (!$this->globalModificationStarted) {
            throw new IllegalStateException(t('Meta Model modification has not been started'));
        }

        $this->globalModificationStarted = FALSE;

        if (isset($this->cachedMetaModel)) {
            if ($commit) {
                $this->cachedMetaModel->markAsAssembled();

                // checking if someone updated the meta model while we were in global modification transaction
                $externalCachedMetaModel = $this->loadCachedMetaModel();
                if (isset($externalCachedMetaModel)) {
                    if ($externalCachedMetaModel->version == $this->cachedMetaModel->version) {
                        $this->cacheMetaModel($this->cachedMetaModel);
                    }
                    else {
                        // we need to remove data from external cache
                        // because different version of the meta model was changed and the cached meta model became obsolete
                        $this->releaseFromSharedCache();
                    }
                }
            }
            else {
                // rolling back whatever we tried to change without removing external cache
                $this->releaseFromLocalCache();
            }
        }
    }
    protected function validate() {
        parent::validate();

        $this->validateDatasets($this->datasets);
        $this->validateReferences($this->references);
        $this->validateCubes($this->cubes);
    }
    public function load(AbstractMetaModel $environment_metamodel, array $filters = NULL) {
        LogHelper::log_notice(t('Generating Environment Meta Model for APC cache ...'));

        $datasourceCount = 0;

        $datasource = new DataSourceMetaData();
        $datasource->name = NameSpaceHelper::addNameSpace(APCHandler::CACHE__TYPE, 'default');
        $datasource->type = APCHandler::CACHE__TYPE;
        $datasource->category = CacheFactory::$DATASOURCE__CATEGORY;
        $datasource->markAsPrivate();

        $environment_metamodel->registerDataSource($datasource);
        $datasourceCount++;

        LogHelper::log_info(t('Generated @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
    }
 public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $environment_metamodel, array $filters = NULL, $finalAttempt)
 {
     LogHelper::log_notice(t('Loading Environment Meta Model from settings.php ...'));
     $datasourceCount = 0;
     $configurationDataSources = Environment::getInstance()->getConfigurationSection('Data Sources');
     if (isset($configurationDataSources)) {
         foreach ($configurationDataSources as $namespace => $sourceDataSources) {
             foreach ($sourceDataSources as $datasourceName => $sourceDataSource) {
                 $datasourceName = NameSpaceHelper::resolveNameSpace($namespace, $datasourceName);
                 $datasource = new DataSourceMetaData();
                 $datasource->name = $datasourceName;
                 $datasource->system = TRUE;
                 $datasource->readonly = TRUE;
                 $datasource->initializeFrom($sourceDataSource);
                 $environment_metamodel->registerDataSource($datasource);
                 $datasourceCount++;
             }
         }
     }
     LogHelper::log_info(t('Processed @datasourceCount data sources', array('@datasourceCount' => $datasourceCount)));
     return self::LOAD_STATE__SUCCESSFUL;
 }
    protected function validate() {
        parent::validate();

        $this->validateDataSources($this->datasources);
    }
    protected function registerLogicalDatasets(SystemTableMetaModelLoaderCallContext $callcontext, AbstractMetaModel $metamodel) {
        $datasetCount = 0;

        $loaderName = $this->getName();

        // registering logical datasets
        foreach ($callcontext->logicalDatasets as $logicalDataset) {
            $logicalDataset->loaderName = $loaderName;
            $logicalDataset->markAsComplete();

            $metamodel->registerDataset($logicalDataset);
            $datasetCount++;
        }

        LogHelper::log_info(t('Registered @datasetCount logical datasets', array('@datasetCount' => $datasetCount)));
    }
Ejemplo n.º 12
0
 protected function mergeWithCube(AbstractMetaModel $metamodel, array $filters = NULL, $namespace, $sourceCubeName, $sourceCube)
 {
     $cubeName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCubeName);
     // cube/sourceDataset/Name
     if (!isset($sourceCube->sourceDatasetName)) {
         throw new IllegalStateException(t("'@cubeName' cube definition does not contain a reference to source dataset", array('@cubeName' => isset($sourceCube->publicName) ? $sourceCube->publicName : $cubeName)));
     }
     $sourceCube->sourceDatasetName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCube->sourceDatasetName);
     // fix dimensions
     if (isset($sourceCube->dimensions)) {
         foreach ($sourceCube->dimensions as $dimension) {
             if (isset($dimension->levels)) {
                 foreach ($dimension->levels as $level) {
                     // cube/dimension/level/dataset/name
                     if (!isset($level->datasetName)) {
                         continue;
                     }
                     $level->datasetName = NameSpaceHelper::resolveNameSpace($namespace, $level->datasetName);
                 }
             }
         }
     }
     // cube/region/dataset/name
     if (isset($sourceCube->regions)) {
         foreach ($sourceCube->regions as $regionName => $region) {
             if (!isset($region->datasetName)) {
                 throw new IllegalStateException(t("'@regionName' region of '@cubeName' cube does not contain a reference to dataset", array('@cubeName' => isset($sourceCube->publicName) ? $sourceCube->publicName : $cubeName, '@regionName' => $regionName)));
             }
             $region->datasetName = NameSpaceHelper::resolveNameSpace($namespace, $region->datasetName);
         }
     }
     $cube = new CubeMetaData();
     $cube->name = $cubeName;
     $cube->initializeFrom($sourceCube);
     $metamodel->registerCube($cube);
     return $cube;
 }
    public function adjustReferencePointColumn(AbstractMetaModel $metamodel, $datasetName, $columnName) {
        // FIXME we should work only with one way to find a cube
        $cube = $metamodel->findCubeByDatasetName($datasetName);
        if (!isset($cube)) {
            $cube = $metamodel->getCube($datasetName);
        }

        $dimension = $cube->getDimension($columnName);

        $shared = FALSE;

        return array($dimension->datasetName, 'value', $shared);
    }
    protected function mergeWithCube(AbstractMetaModel $metamodel, array $filters = NULL, $namespace, $sourceCubeName, $sourceCube) {
        $cubeName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCubeName);

        // cube/sourceDataset/Name
        if (!isset($sourceCube->factsDatasetName)) {
            throw new IllegalStateException(t(
                '%cubeName cube definition does not contain a reference to facts dataset',
                array('%cubeName' => (isset($sourceCube->publicName) ? $sourceCube->publicName : $cubeName))));
        }
        $sourceCube->factsDatasetName = NameSpaceHelper::resolveNameSpace($namespace, $sourceCube->factsDatasetName);

        // fix dimensions
        if (isset($sourceCube->dimensions)) {
            foreach ($sourceCube->dimensions as $dimension) {
                // cube/dimension/dataset/name
                if (!isset($dimension->datasetName)) {
                    continue;
                }
                $dimension->datasetName = NameSpaceHelper::resolveNameSpace($namespace, $dimension->datasetName);
            }
        }

        $cube = new CubeMetaData();
        $cube->name = $cubeName;
        $cube->initializeFrom($sourceCube);

        $isCubeAcceptable = $this->isMetaDataAcceptable($cube, $filters);

        // TODO eliminate this check in the future. Use different approach
        if ($isCubeAcceptable) {
            $isCubeAcceptable = $metamodel->findDataset($cube->factsDatasetName) !== NULL;
        }

        if ($isCubeAcceptable) {
            $metamodel->registerCube($cube);
        }

        return $cube;
    }
    public function adjustReferencePointColumn(AbstractMetaModel $metamodel, $datasetName, $columnName) {
        // FIXME we should work only with one way to find a cube
        $cube = $metamodel->findCubeByDatasetName($this->datasetName);
        if (!isset($cube)) {
            $cube = $metamodel->getCube($this->datasetName);
        }

        $adjustedDatasetName = $cube->factsDatasetName;
        $adjustedDataset = $metamodel->getDataset($adjustedDatasetName);

        $adjustedColumnName = $adjustedDataset->getKeyColumn()->name;

        $shared = TRUE;
        return array($adjustedDatasetName, $adjustedColumnName, $shared);
    }
 public static function adjustReferencePointColumn(AbstractMetaModel $metamodel, DatasetReferencePointColumn $referencePointColumn)
 {
     $datasetName = $referencePointColumn->datasetName;
     $dataset = $metamodel->getDataset($datasetName);
     $column = $dataset->getColumn($referencePointColumn->columnName);
     $handler = DimensionLookupFactory::getInstance()->getHandler($column->type->getLogicalApplicationType());
     list($adjustedDatasetName, $adjustedColumnName, $shared) = $handler->adjustReferencePointColumn($metamodel, $dataset->name, $referencePointColumn->columnName);
     if ($adjustedDatasetName === $referencePointColumn->datasetName) {
         if ($adjustedColumnName === $referencePointColumn->columnName) {
             // we do not need to change anything
         } else {
             throw new UnsupportedOperationException();
         }
     } else {
         $referencePointColumn->datasetName = $adjustedDatasetName;
         $referencePointColumn->columnName = $adjustedColumnName;
     }
     $referencePointColumn->shared = $shared;
 }
 public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $metamodel, array $filters = NULL, $finalAttempt)
 {
     LogHelper::log_notice(t('Creating Meta Model using Drupal Content Types...'));
     $datasetCounter = 0;
     $contentTypes = content_types();
     if (isset($contentTypes)) {
         foreach ($contentTypes as $contentTypeName => $contentType) {
             // preparing list of tables which could be supported by our code
             $supportedTables = NULL;
             foreach ($contentType['fields'] as $field) {
                 $fieldName = $field['field_name'];
                 if ($field['multiple'] > 0) {
                     $message = t('Multiple values are not supported yet: @contentTypeName.@fieldName', array('@contentTypeName' => $contentTypeName, '@fieldName' => $fieldName));
                     LogHelper::log_warn($message);
                     continue;
                     // UnsupportedOperationException
                 }
                 // preparing table name where the field is stored
                 $fieldStorage = $field['db_storage'];
                 switch ($fieldStorage) {
                     case CONTENT_DB_STORAGE_PER_CONTENT_TYPE:
                         $tableName = _content_tablename($field['type_name'], $fieldStorage);
                         break;
                     case CONTENT_DB_STORAGE_PER_FIELD:
                         break;
                         $tableName = _content_tablename($fieldName, $fieldStorage);
                     default:
                         $message = t("Unsupported storage type - '@fieldStorage' for the field: @fieldName", array('@fieldStorage' => $fieldStorage, '@fieldName' => $fieldName));
                         LogHelper::log_warn($message);
                         continue;
                         // UnsupportedOperationException
                 }
                 // calculating number of 'visible' suffixes
                 $visibleSuffixCount = 0;
                 foreach ($field['columns'] as $columnAttributes) {
                     if (isset($columnAttributes['views'])) {
                         if ($columnAttributes['views'] === TRUE) {
                             $visibleSuffixCount++;
                         }
                     } else {
                         $visibleSuffixCount++;
                     }
                 }
                 // generating fields for all 'visible' suffixes
                 foreach ($field['columns'] as $columnSuffix => $columnAttributes) {
                     if (isset($columnAttributes['views']) && $columnAttributes['views'] === FALSE) {
                         continue;
                     }
                     $supportedField = new stdClass();
                     // required flag
                     $supportedField->required = $field->required == 1;
                     // original name of the field
                     $supportedField->original_name = $fieldName;
                     // calculating name of database column
                     $supportedField->column = $fieldName . '_' . $columnSuffix;
                     // field name
                     if ($visibleSuffixCount === 1) {
                         $supportedField->name = $fieldName;
                     } else {
                         $supportedField->name = $supportedField->column;
                     }
                     if (isset($supportedTables[$tableName]->storage)) {
                         $previousStorage = $supportedTables[$tableName]->storage;
                         if ($fieldStorage != $previousStorage) {
                             $message = t("Inconsistent storage for '@tableName' table([@fieldStorage1, @fieldStorage2]) for the field: @fieldName", array('@tableName' => $tableName, '@fieldName' => $fieldName, '@fieldStorage1' => $previousStorage, '@fieldStorage2' => $fieldStorage));
                             LogHelper::log_warn($message);
                             continue;
                             // IllegalStateException
                         }
                     } else {
                         $supportedTables[$tableName]->storage = $fieldStorage;
                     }
                     $supportedTables[$tableName]->supportedFields[$supportedField->name] = $supportedField;
                 }
             }
             // preparing dataset source
             $datasetSource = new stdClass();
             $datasetSource->assembler->type = ContentTypeDatasetSourceAssembler::$DATASET_SOURCE_ASSEMBLER__TYPE;
             $datasetSource->assembler->config->drupal = $contentType;
             if (isset($supportedTables)) {
                 $datasetSource->assembler->config->supportedTables = $supportedTables;
             }
             // preparing & registering dataset
             $dataset = new DatasetMetaData();
             $dataset->name = $this->getDatasetName($contentTypeName);
             $dataset->description = $contentType['description'];
             $dataset->datasourceName = AbstractDrupalDataSourceQueryProxy::$DATASOURCE_NAME__DEFAULT;
             $dataset->source = $datasetSource;
             // FIXME Populate list of columns and mark the dataset as complete
             $dataset->registerColumn('nid')->key = TRUE;
             $metamodel->registerDataset($dataset);
             $datasetCounter++;
         }
     }
     LogHelper::log_info(t('Processed @datasetCount datasets', array('@datasetCount' => $datasetCounter)));
     return self::LOAD_STATE__SUCCESSFUL;
 }