protected function createReference ( $reference ) {
        $node = new stdClass();
        $node->type = NODE_TYPE_REFERENCE;
        $node->language = LANGUAGE_NONE;
        $node->status = NODE_PUBLISHED;
        node_object_prepare($node);

        $node->title = $reference->title;
        $node->field_reference_sysname[$node->language][0]['value'] = GD_NamingConvention::generateReferenceName();

        $node->field_reference_point[$node->language] = array();
        foreach ( $reference->referencePoints as $referencePoint ) {
            $referencePointNode = $this->createReferencePoint($referencePoint);
            if ( empty($referencePointNode->nid ) ) {
                throw new Exception('Reference Point node creation failed');
            }
            $node->field_reference_point[$node->language][] = array('nid'=>$referencePointNode->nid);
        }

        node_save($node);
        return $node;
    }
    protected function prepareTestDatabase() {
        $environment_metamodel = data_controller_get_environment_metamodel();

        // registering test data source and creating corresponding database
        $datasource = $environment_metamodel->findDataSource(DATASOURCE_NAME__TEST);
        if (!isset($datasource)) {
            $databaseNameSuffix = GD_NamingConvention::generateDataMartName() . '_ts';
            $datasourceInfo = array('name' => DATASOURCE_NAME__TEST, 'publicName' => 'Test Suite', 'database' => $databaseNameSuffix);
            gd_datasource_create($datasourceInfo);

            // creating test tables
            $this->createDatasetStorage(TABLE_NAME__LEAF);
            $this->createDatasetStorage(TABLE_NAME__BRANCH);
            $this->createDatasetStorage(TABLE_NAME__MAIN);

            // populating the datasets
            $this->populateDatasets();
        }
    }
    protected function update(Import\ImportStream $stream, Import\ImportContext $context) {
        $datasets = $stream->get('datasets');
        if (empty($datasets)) {
            return;
        }

        gd_datasource_set_active($context->get('datasourceName'));
        $metamodel = data_controller_get_metamodel();

        $environment_metamodel = data_controller_get_environment_metamodel();
        $datasource = $environment_metamodel->getDataSource($context->get('datasourceName'));

        foreach ( $datasets as $dataset ) {
            $existingDataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($metamodel->datasets, $dataset->uuid);
            if ( !$existingDataset ) {

                // map for re-linking dependent objects
                $dataset->originalName = $dataset->name;

                // create new name
                $newDatasetName = GD_NamingConvention::generateDatasetName();
                $dataset->name = $newDatasetName;
                $dataset->source = $newDatasetName;
                $dataset->datasourceName = $datasource->name;
            } else {
                // map for re-linking dependent objects
                $dataset->originalName = $dataset->name;

                $dataset->name = $existingDataset->name;
                $dataset->source = $existingDataset->source;
                $dataset->datasourceName = $existingDataset->datasourceName;
            }
        }

        // prepare dataset columns for import
        $this->prepareColumns($datasets);

        // prepares the metadata object, has to be of type RecordMetaData
        foreach ( $datasets as $key => $dataset ) {
            $metadata = new DatasetMetaData();
            $metadata->initializeFrom($dataset);
            $datasets[$key] = $metadata;
        }

        // ensure datasets are created in order to satisfy dependencies
        usort($datasets, array(new ReferencedDatasetComparator(), 'compare'));

        foreach ( $datasets as $dataset ) {
            $existingDataset = GD_DatasetMetaModelLoaderHelper::findDatasetByUUID($metamodel->datasets, $dataset->uuid);
            if ($existingDataset) {
                gd_data_controller_ddl_modify_dataset($dataset);
            } else {
                MetaModelFactory::getInstance()->startGlobalModification();
                try {
                    $transaction = db_transaction();
                    try {
                        gd_data_controller_ddl_create_dataset($dataset);
                    } catch (Exception $e) {
                        $transaction->rollback();
                        throw $e;
                    }
                } catch (Exception $e) {
                    MetaModelFactory::getInstance()->finishGlobalModification(false);
                    throw $e;
                }
                MetaModelFactory::getInstance()->finishGlobalModification(true);
            }
        }

        $stream->set('datasets',$datasets);
    }