My Project
Public Member Functions | List of all members
ParaEngine::AttributeProvider Class Reference

Attribute fields data provider: it is a group of attribute stored in {name, value} value pair fasion in a single database table. More...

#include <AttributeProvider.h>

Public Member Functions

 AttributeProvider (void)
 perform test cases when reseting db. More...
 
bool IsValid ()
 whether db is opened. More...
 
void Cleanup ()
 delete the database and set everything to NULL
 
DBEntityGetDBEntity ()
 get the database object associated with this provider
 
void SetDBEntity (const string &sConnectionstring)
 replace the current database with current one. More...
 
void ValidateDatabase ()
 ensure that the database has been set up properly. More...
 
bool SaveAttributeObject (const char *sTableName, IAttributeFields *pAttributeObject)
 save the attribute object to the given table More...
 
bool LoadAttributeObject (const char *sTableName, IAttributeFields *pAttributeObject)
 load the attribute object from a given table. More...
 
void SetTableName (const char *sName)
 current attribute table name, if the table does not exists it will be created. More...
 
const string & GetTableName ()
 current attribute table name More...
 
bool ResetTable (const char *sName)
 reset a given table to blank. More...
 
bool DoesAttributeExists (const char *sName)
 current object name . More...
 
bool GetAttribute (const char *sName, string &sOut)
 get the attribute of the current attribute instance in the current table More...
 
bool GetAttribute (CAttributeDbItem &inout)
 get the complete attribute information in the current table More...
 
bool InsertAttribute (CAttributeDbItem &sIn)
 insert a new attribute field in the current table More...
 
bool InsertAttribute (const char *sName, const char *sValue)
 insert by simple name value pair More...
 
bool UpdateAttribute (const char *sName, const char *sIn)
 update the attribute of the current attribute instance in the current table insert the attribute if it is not created before. More...
 
bool DeleteAttribute (const char *sName)
 delete the attribute of the current attribute instance in the current table More...
 
bool CreateTableIfNotExists ()
 create the current table, if it does not exists. More...
 

Detailed Description

Attribute fields data provider: it is a group of attribute stored in {name, value} value pair fasion in a single database table.

The db table does not define the name, hence a table in the database is very similar to an intance of Iattributefields in ParaEngine. To be extensible, the table record has the following format: {name(prim key), InstanceName(indexed), value, type, description, schematics} in other word, the database table provides a serialization of IAttributeField (all fields are persistent except get/set function address). All instances sharing the same ClassName are usually stored in the same db table. In case of a singleton, we can default InstanceName field to NULL. e.g. game world class may store global information for a game in the database, such as the spawn points, last player position, etc. Besides serializing IAttributeField class, the data provider should also expose methods to add and remove dynamic fields.

Remarks
: Currently, instanced object is not supported. One table only matches to a single object.

Constructor & Destructor Documentation

§ AttributeProvider()

AttributeProvider::AttributeProvider ( void  )

perform test cases when reseting db.

Member Function Documentation

§ CreateTableIfNotExists()

bool AttributeProvider::CreateTableIfNotExists ( )

create the current table, if it does not exists.

This function is mostly called automatically when the SetTableName() function is called.

Returns
true if the table exists either created or just the old one.

§ DeleteAttribute()

bool AttributeProvider::DeleteAttribute ( const char *  sName)

delete the attribute of the current attribute instance in the current table

Parameters
sName: name of the attribute field
Returns
true if succeed.

§ DoesAttributeExists()

bool AttributeProvider::DoesAttributeExists ( const char *  sName)

current object name .

a table may save attribute for multiple objects. this may be empty string, in which case the table is assumed to be storing a singleton object.

Parameters
sNamewhether a given attribute exists. This function is usually used internally. One common use of this function is to test if a field exists, so that we know if a object has been saved before or not.
sName: name of the attribute field
Returns

§ GetAttribute() [1/2]

bool AttributeProvider::GetAttribute ( const char *  sName,
string &  sOut 
)

get the attribute of the current attribute instance in the current table

Parameters
sName: name of the attribute field
sOut: value of the field as a string.
Returns
true if succeed.

§ GetAttribute() [2/2]

bool AttributeProvider::GetAttribute ( CAttributeDbItem inout)

get the complete attribute information in the current table

Parameters
inout: [in|out] get the complete database information. CAttributeDbItem::m_sName and CAttributeDbItem::m_sInstanceName must be filled first. the rest of CAttributeDbItem will be filled when the function returns. Please note that if CAttributeDbItem::m_sInstanceName is empty then the current object name will used instead.
Returns
true if succeed.

§ GetTableName()

const string& ParaEngine::AttributeProvider::GetTableName ( )
inline

current attribute table name

Returns
current attribute table name

§ InsertAttribute() [1/2]

bool AttributeProvider::InsertAttribute ( CAttributeDbItem sIn)

insert a new attribute field in the current table

Parameters
sIn: [in] CAttributeDbItem::m_sName is always ignored.
Returns
true if succeed.

§ InsertAttribute() [2/2]

bool AttributeProvider::InsertAttribute ( const char *  sName,
const char *  sValue 
)

insert by simple name value pair

Parameters
sName
sValue
Returns

§ IsValid()

bool ParaEngine::AttributeProvider::IsValid ( )
inline

whether db is opened.

§ LoadAttributeObject()

bool AttributeProvider::LoadAttributeObject ( const char *  sTableName,
IAttributeFields pAttributeObject 
)

load the attribute object from a given table.

Parameters
sTableNameif table name is empty, the current table is used.
pAttributeObject[out]
Returns
true if succeeds

§ ResetTable()

bool AttributeProvider::ResetTable ( const char *  sName)

reset a given table to blank.

if the table does not exists a blank one will be created.

Parameters
sNametable name
Returns
true if succeeds

§ SaveAttributeObject()

bool AttributeProvider::SaveAttributeObject ( const char *  sTableName,
IAttributeFields pAttributeObject 
)

save the attribute object to the given table

Parameters
sTableNameif table name is empty, the current table is used.
pAttributeObject[in]
Returns
true if succeeds

§ SetDBEntity()

void AttributeProvider::SetDBEntity ( const string &  sConnectionstring)

replace the current database with current one.

the old one is closed and the new once will be opened.

Parameters
sConnectionstringthe file path

§ SetTableName()

void AttributeProvider::SetTableName ( const char *  sName)

current attribute table name, if the table does not exists it will be created.

Parameters
sName

§ UpdateAttribute()

bool AttributeProvider::UpdateAttribute ( const char *  sName,
const char *  sIn 
)

update the attribute of the current attribute instance in the current table insert the attribute if it is not created before.

Parameters
sName: name of the attribute field
sInvalue of the attribute field
Returns
true if succeed.

§ ValidateDatabase()

void AttributeProvider::ValidateDatabase ( )

ensure that the database has been set up properly.

If not, ResetDatabase() is called to reset the database to blank


The documentation for this class was generated from the following files: