protected function packageDataModels()
    {
        static $packagedDataModels;

        if (is_null($packagedDataModels)) {

            $dataModels = $this->getDataModels();
            $dataModel = array_shift($dataModels);
            $packagedDataModels = array();

            $platform = $this->getGeneratorConfig()->getConfiguredPlatform();

            foreach ($dataModel->getDatabases() as $db) {
                foreach ($db->getTables() as $table) {
                    $package = $table->getPackage();
                    if (!isset($packagedDataModels[$package])) {
                        $dbClone = $this->cloneDatabase($db);
                        $dbClone->setPackage($package);
                        $ad = new AppData($platform);
                        $ad->setGeneratorConfig($this->getGeneratorConfig());
                        $ad->setName($dataModel->getName());
                        $ad->addDatabase($dbClone);
                        $packagedDataModels[$package] = $ad;
                    }
                    $packagedDataModels[$package]->getDatabase($db->getName())->addTable($table);
                }
            }
        }

        return $packagedDataModels;
    }