The database switch can be used if one needs multiple UDatabase user instances which work within the same logical database transaction, as one database transaction just processes requests from the same UDatabase user.
This implementation stores the UDatabase user from the application inside a queue and always uses the own UDatabase pointer.
File | common/lib/database_switch.h |
Classes |
DatabaseSwitch |
Examples |
DatabaseSwitch |
class DatabaseSwitch : public IDatabase, public UDatabase {
public:
DatabaseSwitch(class IDatabase * database);
};
class IDatabase * database | The IDatabase instance to be used by the switch. |
All other functions are the functions from IDatabase and can be used in exactly the same manner.
class IDatabase * database = databaseProvider->CreateDatabase(iomux, this, this);
class IDatabase * databaseSwitch = new DatabaseSwitch(database);
databaseSwitch->BeginTransaction(databaseUserA); // databaseUserA gets the BeginTransactionResult callback
databaseSwitch->ExecSQL(databaseUserB, "..."); // databaseUserB gets the ExecSQLResult callback
databaseSwitch->ExecSQL(databaseUserC, "..."); // databaseUserC gets the ExecSQLResult callback
databaseSwitch->EndTransaction(databaseUserA); // databaseUserA gets the EndTransactionResult callback