Beispiel #1
0
/**
 * Release a row in a table
 * \param index is the table/row to release
 * Return true if succeded
 */
bool	CDatabase::release(const RY_PDS::CObjectIndex &index)
{
	if (!initialised())
	{
		PDS_WARNING("release(): database not initialised");
		return false;
	}

	if (!index.isValid())
	{
		PDS_WARNING("release(): index '%s' is not valid", index.toString().c_str());
		return false;
	}

	CTable	*table = getNonConstTable(index.table());

	if (table == NULL || !table->initialised())
	{
		PDS_WARNING("release(): table '%d' is not initialised", index.table());
		return false;
	}

	bool	success = table->release(index.row());

	if (success)
		PDS_FULL_DEBUG("released '%s' successfully", index.toString().c_str());

	return success;
}
Beispiel #2
0
/*
 * Map a row in a table
 * \param index is the table/row to allocate
 * \param key is the 64 bits row key
 * Return true if succeded
 */
bool	CDatabase::mapRow(const RY_PDS::CObjectIndex &index, uint64 key)
{
	if (!initialised())
	{
		PDS_WARNING("mapRow(): database not initialised");
		return false;
	}

	if (!index.isValid())
	{
		PDS_WARNING("mapRow(): index '%s' is not valid", index.toString().c_str());
		return false;
	}

	CTable	*table = getNonConstTable(index.table());

	if (table == NULL || !table->initialised())
	{
		PDS_WARNING("deallocate(): table '%d' is not initialised", index.table());
		return false;
	}

	bool	success = table->mapRow(index, key);

	if (success)
		PDS_FULL_DEBUG("mapped '%016"NL_I64"X' to '%s' successfully", key, index.toString().c_str());

	return success;
}
Beispiel #3
0
/*
 * Search object in database using its key
 * \param key is the 64 bits row key to search through all tables
 */
bool	CDatabase::searchObjectIndex(uint64 key, std::set<RY_PDS::CObjectIndex>& indexes) const
{
	indexes.clear();

	uint	i;
	for (i=0; i<_Tables.size(); ++i)
	{
		if (_Tables[i] == NULL || !_Tables[i]->initialised() || !_Tables[i]->isMapped())
			continue;

		RY_PDS::CObjectIndex	index = _Tables[i]->getMappedRow(key);

		if (index.isValid())
			indexes.insert(index);
	}

	return !indexes.empty();
}
Beispiel #4
0
/*
 * Fetch data
 */
bool	CDbManager::fetch(TDatabaseId id, RY_PDS::TTableIndex tableIndex, uint64 key, RY_PDS::CPData &data)
{
	CHECK_DB_MGR_INIT(fetch, false);

	CDatabase*	db = getDatabase(id);
	if (db == NULL)
	{
		nlwarning("Unable to fetch(), db '%d' not created yet", id);
		return false;
	}

	RY_PDS::CObjectIndex	index = db->getMappedRow(tableIndex, key);
	if (!index.isValid())
	{
		// row is not mapped
		return false;
	}

	return db->fetch(index, data);
}
Beispiel #5
0
/*
 * Get value as a string
 * \param path is of the form '[tableindex|tablename].[$key|index].attrib1.attrib2'
 */
string	CDatabase::getValue(const CLocatePath::TLocatePath &path)
{
	if (path.size() < 3)
	{
		PDS_WARNING("getValue(): path is too short");
		return "";
	}

	uint	node = 0;

	// select table
	const CTable*	table;
	uint			tableId;
	if (sscanf(path[node].Name.c_str(), "%d", &tableId) == 1)
		table = getTable(tableId);
	else
		table = getTable(path[node].Name);

	if (table == NULL)
	{
		PDS_WARNING("getValue(): unable to select table '%s'", path[node].Name.c_str());
		return "";
	}

	++node;

	// select row
	RY_PDS::CObjectIndex	object;

	if (path[node].Name[0] == '$')
	{
		uint64	key;
		if (sscanf(path[node].Name.c_str()+1, "%"NL_I64"X", &key) != 1)
		{
			PDS_WARNING("getValue(): unable to select mapped row '%s'", path[node].Name.c_str());
			return "";
		}

		object = table->getMappedRow(key);
	}
	else
	{
		RY_PDS::TRowIndex	row;

		if (sscanf(path[node].Name.c_str(), "%u", &row) != 1)
		{
			PDS_WARNING("getValue(): unable to select row '%s'", path[node].Name.c_str());
			return "";
		}

		object = RY_PDS::CObjectIndex((RY_PDS::TTableIndex)table->getId(), row);
	}

	if (!object.isValid() || !isAllocated(object))
	{
		PDS_WARNING("getValue(): object '%s' not accessible", path[node].Name.c_str());
		return "";
	}

	++node;

	const CTable*	subTable = table;

	// browse through row
	while (node < path.size())
	{
		const CAttribute*	attribute = subTable->getAttribute(path[node].Name);

		if (attribute == NULL)
		{
			PDS_WARNING("getValue(): '%s' is not an attribute of '%s'", path[node].Name.c_str(), subTable->getName().c_str());
			return "";
		}

		++node;
	}

	return "";
}