Example #1
0
/*
 * Load a database and adapt to the description if needed
 */
CDatabase*	CDbManager::loadDatabase(TDatabaseId id, const string& description, CLog* log)
{
	CHECK_DB_MGR_INIT(loadDatabase, false);

	nlinfo("CDbManager::loadDatabase(): load/setup database '%d'", id);

	CDatabase*	db = getDatabase(id);

	// database not loaded yet?
	if (db == NULL)
	{
		// create a memory image
		db = createDatabase(id, log);
		if (db == NULL)
		{
			log->displayNL("failed to create database '%d'", id);
			return NULL;
		}

		// if can't load database
		if (!db->loadState())
		{
			nlinfo("CDbManager::loadDatabase(): database '%d' doesn't exist, create new", id);

			// create a new database with the new description
			if (!db->createFromScratch(description))
			{
				log->displayNL("failed to create database '%d' from scratch", id);
				return NULL;
			}

			return db;
		}
	}

	CDatabase*	adapted = db->adapt(description);
	if (adapted ==  NULL)
	{
		log->displayNL("failed to adapt database '%s' to new description", db->getName().c_str());
		return NULL;
	}

	// database changed?
	if (db != adapted)
	{
		// replace old on with new one
		_DatabaseMap[id] = adapted;
		// and delete old
		delete db;
	}

	return adapted;
}
Example #2
0
/*
 * load a database
 */
bool	CDbManager::loadDatabase(TDatabaseId id, CLog* log)
{
	CHECK_DB_MGR_INIT(loadDatabase, false);

	// check db doesn't exist yet
	CDatabase*	db = getDatabase(id);
	if (db == NULL)
	{
		log->displayNL("Unable to loadDatabase() %d, not created yet", id);
		return false;
	}

	// check database not init'ed
	if (db->initialised())
	{
		log->displayNL("Unable to loadDatabase() %d, already initialised as '%s'", id, db->getName().c_str());
		return false;
	}

	return db->loadState();
}