Database layer
Posted: Mon Dec 31, 2007 8:07 am
Hello people, I would like to propose a new reflection based database layer:
(reflection is also known as RTTI):
Every database stored object inherits from DatabaseObject and Iserializable .
DatabaseObject provides methods for Reflection ( if the reflection system we choose to use needs them) , a bool bSavetoDb member to allow temporary objects , and a longlong primary ID field.
Its constructor references every database object in a global collection ( such as a list)
The ISerializable interface provides serialization.
When the server saves the world , it iterates the collection , serializes and stores every object and the type information into a database.
When the server restores the world , it selects all objects from the database , with their types , and recreates(deserializes) them (which automatically adds them to the Collection) based on this RTTI.
The Database is implemented as an abstract class, DatabaseProvider , which has to provide methods for inserting / updating / selecting database objects.
Internally it could for example be implemented as a database based on postgreSQL with 2 tables , one storing Unique ID , typeid and data of an object , one storing typeids and type strings .
For providing upgrade compatibility , serialization in the database is binary, whereas there is also the option to serialize to XML data.
The only problem is that a) everything would need to be OO
and b) we would need to build int he reflection API , which is quite easy...
c) Editing requires an editor program, which loads the server core , deserializes the binary data, and presents them in XML (on Win32 or .NET(Mono) , this could be done as a PropertyGrid)
But we got the advantages
a) Totally customisable , custom types and databases possible without core changes
b) New types can be added without modifying the database layer or database schema
c) Database is much faster - PostgreSQL can easily handle up to 32TB of data
d) much less code - the database layer stays sleek
e) much less data - binary serialization data instead of slow mixed data in DB schemas
(reflection is also known as RTTI):
Every database stored object inherits from DatabaseObject and Iserializable .
DatabaseObject provides methods for Reflection ( if the reflection system we choose to use needs them) , a bool bSavetoDb member to allow temporary objects , and a longlong primary ID field.
Its constructor references every database object in a global collection ( such as a list)
The ISerializable interface provides serialization.
When the server saves the world , it iterates the collection , serializes and stores every object and the type information into a database.
When the server restores the world , it selects all objects from the database , with their types , and recreates(deserializes) them (which automatically adds them to the Collection) based on this RTTI.
The Database is implemented as an abstract class, DatabaseProvider , which has to provide methods for inserting / updating / selecting database objects.
Internally it could for example be implemented as a database based on postgreSQL with 2 tables , one storing Unique ID , typeid and data of an object , one storing typeids and type strings .
For providing upgrade compatibility , serialization in the database is binary, whereas there is also the option to serialize to XML data.
The only problem is that a) everything would need to be OO
and b) we would need to build int he reflection API , which is quite easy...
c) Editing requires an editor program, which loads the server core , deserializes the binary data, and presents them in XML (on Win32 or .NET(Mono) , this could be done as a PropertyGrid)
But we got the advantages
a) Totally customisable , custom types and databases possible without core changes
b) New types can be added without modifying the database layer or database schema
c) Database is much faster - PostgreSQL can easily handle up to 32TB of data
d) much less code - the database layer stays sleek
e) much less data - binary serialization data instead of slow mixed data in DB schemas