public function dropDatasetStorage(DataControllerCallContext $callcontext, DropDatasetStorageRequest $request) { $environment_metamodel = data_controller_get_environment_metamodel(); $dataset = DatasetTypeHelper::getTableDataset($request->datasetName); $datasource = $environment_metamodel->getDataSource($dataset->datasourceName); $sql = $this->getExtension('dropTable')->generate($this, $dataset); LogHelper::log_info(new StatementLogMessage('table.drop', $sql)); $this->executeStatement($datasource, $sql); }
public function load(AbstractMetaModelFactory $factory, AbstractMetaModel $metamodel, array $filters = NULL, $finalAttempt) { $selectedDataSourceType = $this->selectedDataSourceType(); LogHelper::log_notice(t("Finalizing Dataset Meta Data for '@databaseType' database connections ...", array('@databaseType' => $selectedDataSourceType))); if ($finalAttempt === FALSE) { return self::LOAD_STATE__POSTPONED; } $finalizedDatasetCount = 0; $environment_metamodel = data_controller_get_environment_metamodel(); // processing all database connections foreach ($environment_metamodel->datasources as $datasource) { if ($datasource->type !== $selectedDataSourceType) { continue; } // selecting datasets which could be processed for the selected connection $selectedSources = NULL; foreach ($metamodel->datasets as $dataset) { // the dataset should belong to the selected data source if ($dataset->datasourceName !== $datasource->name) { continue; } // the dataset has to be of type table if (DatasetTypeHelper::detectDatasetSourceType($dataset) !== DatasetTypeHelper::DATASET_SOURCE_TYPE__TABLE) { continue; } // whole dataset meta data was prepared using different method. There is nothing else can be done if ($dataset->isComplete()) { continue; } $tableName = strtolower($dataset->source); // invalidating existing column indexes $dataset->invalidateColumnIndexes(); // there could be several datasets for one table $selectedSources[$tableName][] = $dataset; } if (!isset($selectedSources)) { continue; } $datasourceHandler = DataSourceQueryFactory::getInstance()->getHandler($datasource->type); $metadataCallback = $datasourceHandler->prepareQueryStatementExecutionCallbackInstance(); // processing meta data for selected datasets $columnsMetaDataProperties = $this->prepareColumnsMetaDataProperties($datasource, array_keys($selectedSources)); if (isset($columnsMetaDataProperties)) { foreach ($columnsMetaDataProperties as $columnMetaDataProperties) { $tableName = strtolower($columnMetaDataProperties[self::PROPERTY__TABLE_NAME]); $datasets = $selectedSources[$tableName]; foreach ($datasets as $dataset) { $column = new ColumnMetaData(); $column->name = strtolower($columnMetaDataProperties[self::PROPERTY__COLUMN_NAME]); $column->columnIndex = $columnMetaDataProperties[self::PROPERTY__COLUMN_INDEX]; // preparing column type $column->type->databaseType = $columnMetaDataProperties[self::PROPERTY__COLUMN_TYPE]; $column->type->applicationType = $metadataCallback->calculateApplicationDataType($column); // checking if the column is a system column which should be invisible if (substr_compare($column->name, DatasetSystemColumnNames::COLUMN_NAME_PREFIX, 0, strlen(DatasetSystemColumnNames::COLUMN_NAME_PREFIX)) === 0) { $column->visible = FALSE; } $dataset->initializeColumnFrom($column); } } } // marking all selected datasets as completed foreach ($selectedSources as $datasets) { foreach ($datasets as $dataset) { $dataset->markAsComplete(); $finalizedDatasetCount++; } } } LogHelper::log_info(t('Finalized @datasetCount dataset meta data configurations', array('@datasetCount' => $finalizedDatasetCount))); return self::LOAD_STATE__SUCCESSFUL; }
protected function assembleForeignKeyConstraints(DataSourceHandler $handler, DatasetMetaData $dataset, $indent, &$sql) { $metamodel = data_controller_get_metamodel(); foreach ($dataset->getColumns() as $column) { $columnName = $column->name; if (!isset($column->type->sourceApplicationType)) { continue; } // the column has to contain a reference to another dataset $dimensionLookupHandler = DimensionLookupFactory::getInstance()->getHandler($column->type->sourceApplicationType); list($referencedDatasetName) = $dimensionLookupHandler->adjustReferencePointColumn($metamodel, $dataset->name, $column->name); if ($dataset->name == $referencedDatasetName) { continue; } $referencedDataset = $metamodel->getDataset($referencedDatasetName); // we can create a foreign key constraint referenced to a table only $referencedDatasetSourceType = DatasetTypeHelper::detectDatasetSourceType($referencedDataset); if ($referencedDatasetSourceType != DatasetTypeHelper::DATASET_SOURCE_TYPE__TABLE) { continue; } $referencedOwner = NULL; if ($dataset->datasourceName != $referencedDataset->datasourceName) { // if we cannot join datasets we cannot create a foreign key constraint $datasourceQueryHandler = DataSourceQueryFactory::getInstance()->getHandler($handler->getDataSourceType()); if (!$datasourceQueryHandler->isJoinSupported($dataset->datasourceName, $referencedDataset->datasourceName)) { continue; } $referencedOwner = $handler->getDataSourceOwner($referencedDataset->datasourceName); } $referencedTableName = $referencedDataset->source; $referencedColumnName = $referencedDataset->getKeyColumn()->name; $sql .= ",\n{$indent}CONSTRAINT fk_{$dataset->source}_{$columnName} FOREIGN KEY ({$columnName}) REFERENCES " . (isset($referencedOwner) ? $referencedOwner . '.' : '') . "{$referencedTableName} ({$referencedColumnName})"; } }
public function assembleDatasetSourceStatement(DataControllerCallContext $callcontext, DatasetMetaData $dataset, array $columnNames = NULL) { $datasetSourceType = DatasetTypeHelper::detectDatasetSourceType($dataset); switch ($datasetSourceType) { case DatasetTypeHelper::DATASET_SOURCE_TYPE__TABLE: $statement = new Statement(); $table = new DatasetSection($dataset); if (isset($columnNames)) { foreach ($columnNames as $columnName) { $table->columns[] = new ColumnSection($columnName); } } $statement->tables[] = $table; break; case DatasetTypeHelper::DATASET_SOURCE_TYPE__SUBQUERY: // FIXME Statement::assemble should indirectly resolve the issue $TABLE_ALIAS__SUBQUERY = 'b'; $statement = new Statement(); // FIXME do not duplicate code $table = new SubquerySection($dataset->source, $TABLE_ALIAS__SUBQUERY); if (isset($columnNames)) { foreach ($columnNames as $columnName) { $table->columns[] = new ColumnSection($columnName); } } $statement->tables[] = $table; break; case DatasetTypeHelper::DATASET_SOURCE_TYPE__DYNAMIC: $assembler = $dataset->assembler; $handler = DatasetSourceAssemblerFactory::getInstance()->getHandler($assembler->type, isset($assembler->config) ? $assembler->config : NULL); $statement = $handler->assemble($this, $callcontext, $dataset, $columnNames); break; default: throw new IllegalStateException(t('Unsupported dataset source type: @datasetSourceType', array('@datasetSourceType' => $datasetSourceType))); } if (!isset($statement)) { throw new IllegalStateException(t('Could not prepare source statement for the dataset: @datasetName', array('@datasetName' => $dataset->publicName))); } return $statement; }