Prev | |||
Expressions |
Persist Objects
When it comes to persistence you have to deal with sessions and transactions. You have to create a session for a specific database and wrap a transaction around your insertions or modifications.
After created a session objects you can either create the database schema ...
... or load the data from database.
Once the schema is created or the data is loaded you can start and insert, update or delete your data. Therefor create a transaction object with the current session and start the transaction by calling oos::transaction::begin(). After completing your modifications call oos::transaction::commit() to commit all your modifications to the database. If in error occurred while doing your modifications catch the exception. In the catch block you can call oos::transaction::rollback() to rollback all your modifications.
Supported Databases
There're currently three supported databases and the in memory database. But more databases will follow. Next is the description of the database connection string for the supported databases.
MS SQL Server
MySQL
SQLite
Relations on Database
In short: All kinds of supported relations (list, vector and linked_list) are working out of the box. You don't have to worry about saving and loading relations.
The long description: When loading a relation from database at least two object types/tables are involved the parent and the children. With theses two participans we deal with two scenarios: The parent is loaded before its children and the children are loaded first.
Scenario 1: Parents are loaded first. Everything is fine. We mark the parent as loaded and when the children table is loaded all parent objects can be filled with their children.
Scenario 2: Children are loaded first. Because the parents aren't available placeholders with their ids are created from the id stored in the concrete children. Furthermore temporary lists are build up holding all children for each parent. When finally the parents are loaded these lists are used to the concrete parent container.
Prev | |||
Expressions |