public static function prepareDataset(MetaModel $metamodel, $datasetNode, array $datasetColumnNodes = NULL, DataSourceMetaData $datasource) {
        $dataset = new DatasetMetaData();
        $dataset->name = get_node_field_value($datasetNode, 'field_dataset_sysname', 0, 'value', TRUE);
        $dataset->publicName = $datasetNode->title;

        // preparing the dataset alternative names (aliases)
        $aliasIndex = 0;
        while (($alias = get_node_field_value($datasetNode, 'field_dataset_alias', $aliasIndex)) != NULL) {
            $dataset->aliases[] = $alias;

            $aliasIndex++;
        }

        $dataset->description = get_node_field_value($datasetNode, 'field_dataset_desc');

        $dataset->datasourceName = $datasource->name;

        // preparing source configuration properties
        $dataset->sourceType = get_node_field_value($datasetNode, 'field_dataset_source_type', 0, 'value', TRUE);
        $dataset->source = get_node_field_value($datasetNode, 'field_dataset_source', 0, 'value', TRUE);
        // preparing source properties as an associative array
        $dataset->configuration = get_node_field_object_value($datasetNode, 'field_dataset_source_properties');

        // dataset system properties
        $dataset->uuid = get_node_field_value($datasetNode, 'field_dataset_uuid', 0, 'value', TRUE);
        $dataset->nid = $datasetNode->nid;

        // preparing dataset columns
        if (isset($datasetColumnNodes)) {
            foreach ($datasetColumnNodes as $columnNode) {
                $column = $dataset->initiateColumn();
                $column->used = $columnNode->status == NODE_PUBLISHED;

                $column->name = get_node_field_value($columnNode, 'field_column_sysname', 0, 'value', TRUE);
                $column->publicName = $columnNode->title;
                $column->description = get_node_field_value($columnNode, 'field_column_desc');
                $column->key = get_node_field_boolean_value($columnNode, 'field_column_key');

                // column data type
                $column->type->applicationType = get_node_field_value($columnNode, 'field_column_datatype', 0, 'value', $column->used);
                if (isset($column->type->applicationType) && ($column->type->getReferencedDatasetName() == NULL)) {
                    $column->type->logicalApplicationType = NameSpaceHelper::addNameSpace(NAME_SPACE__STAR_SCHEMA, $column->type->applicationType);
                }
                $format = get_node_field_object_value($columnNode, 'field_column_format');
                if (isset($format->scale)) {
                    $column->type->scale = $format->scale;
                }

                $column->columnIndex = get_node_field_int_value($columnNode, 'field_column_index', 0, 'value', TRUE);
                $column->source = get_node_field_value($columnNode, 'field_column_source');
                $column->persistence = get_node_field_int_value($columnNode, 'field_column_persistence', 0, 'value', TRUE);

                // attribute system properties
                $column->nid = $columnNode->nid;

                $dataset->registerColumnInstance($column);
            }
        }

        // marking that the dataset object contains complete meta data
        $dataset->markAsComplete();

        $metamodel->registerDataset($dataset);

        return $dataset;
    }
    protected function generateLogicalDatasets(SystemTableMetaModelLoaderCallContext $callcontext, AbstractMetaModel $metamodel) {
        $datasetCount = 0;

        foreach ($callcontext->datasets as $tableAccessKey => $dataset) {
            $logicalDataset = new DatasetMetaData();
            $logicalDataset->name = $this->generateLogicalDatasetName($dataset->name);
            $logicalDataset->publicName = $dataset->publicName;
            $logicalDataset->description = $dataset->description;
            $logicalDataset->datasourceName = $dataset->datasourceName;
            $logicalDataset->sourceType = StarSchemaDatasetSourceTypeHandler::SOURCE_TYPE;

            $callcontext->logicalDatasetNameMappings[$logicalDataset->name] = $tableAccessKey;

            foreach ($dataset->columns as $column) {
                $logicalColumn = $logicalDataset->initiateColumn();
                $logicalColumn->name = $column->name;
                $logicalColumn->publicName = $column->publicName;
                $logicalColumn->description = $column->description;
                $logicalColumn->persistence = $column->persistence;
                $logicalColumn->columnIndex = $column->columnIndex;
                $logicalColumn->key = $column->key;
                $logicalColumn->visible = $column->visible;
                $logicalColumn->used = $column->used;

                if (isset($column->type->logicalApplicationType)) {
                    list($refDatasetName, $refColumnName) = ReferencePathHelper::splitReference($column->type->logicalApplicationType);

                    $refDataset = $metamodel->getDataset($refDatasetName);
                    $refColumn = $refDataset->getColumn($refColumnName);

                    $logicalColumn->type->databaseType = $refColumn->type->databaseType;
                    $logicalColumn->type->length = $refColumn->type->length;
                    $logicalColumn->type->precision = $refColumn->type->precision;
                    $logicalColumn->type->scale = $refColumn->type->scale;

                    $logicalColumn->type->applicationType = ReferencePathHelper::assembleReference(
                        $this->generateLogicalDatasetName($refDataset->name), $refColumnName);
                }
                else {
                    $logicalColumn->initializeTypeFrom($column->type);
                }

                $logicalDataset->registerColumnInstance($logicalColumn);
            }

            $callcontext->logicalDatasets[$tableAccessKey] = $logicalDataset;
            $datasetCount++;
        }

        LogHelper::log_info(t('Generated @datasetCount logical datasets', array('@datasetCount' => $datasetCount)));
    }
    protected function prepareSystemColumnCreateStatements(DataSourceHandler $handler, DatasetMetaData $dataset) {
        $columnSQLs = NULL;

        // preparing 'version' system column
        $columnVersion = $dataset->initiateColumn();
        $columnVersion->name = DatasetSystemColumnNames::VERSION;
        $columnVersion->description = t('System column to store version of a record');
        $columnVersion->type->applicationType = IntegerDataTypeHandler::DATA_TYPE;
        $columnSQLs[] = $this->prepareColumnCreateStatement($handler, $columnVersion, FALSE);

        // preparing 'state' system column
        $columnState = $dataset->initiateColumn();
        $columnState->name = DatasetSystemColumnNames::STATE;
        $columnState->description = t('System column to store internal state of a record');
        $columnState->type->applicationType = IntegerDataTypeHandler::DATA_TYPE;
        $columnSQLs[] = $this->prepareColumnCreateStatement($handler, $columnState, FALSE);

        return $columnSQLs;
    }