VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
DtVrfDatabaseConnection Class Referenceabstract

The base class for all database connections. The database connection is responsible for reading queued up events from the database logger, and then recording those events to the connected database. This is normally done by a dedicated thread that is launched during initialization.

By default the DtVrfNoDatabaseConnection will be created, which does not connect to any database. VR-Forces can be configured to create a DtVrfSqliteDatabaseConnection instead, which will open and write to an SQLite database. Other database implementations could be added via plugins. The databaseConnection example shows how to add a new type of database connection. It adds support for MySQL. The database connection used can be configured in appData/settings/databaseConfig.mtl.

Inheritance diagram for DtVrfDatabaseConnection:
Inheritance graph
[legend]

Public Member Functions

virtual ~DtVrfDatabaseConnection ()
 
virtual bool initialize (const DtRwDatabaseLoggerConfig &config, DtVrfDatabaseLoggerInterface *dbLogger)
 
virtual void run ()
 

Protected Member Functions

 DtVrfDatabaseConnection ()
 
virtual bool processConfiguration (const DtRwDatabaseLoggerConfig &config)
 
virtual bool connect ()=0
 
virtual bool createDatabase ()=0
 
virtual bool stop ()
 
virtual bool createTableForEvent (const DtVrfDatabaseEvent &event)=0
 
virtual bool insertOrIgnoreEntriesForEvents (const DtVrfDatabaseEventVector &events)=0
 
virtual bool insertOrUpdateEntriesForEvents (const DtVrfDatabaseEventVector &events)=0
 
virtual bool updateEntryForEvent (const DtVrfDatabaseEvent &event)=0
 
virtual std::string escapeString (std::string str)
 

Protected Attributes

DtVrfDatabaseLoggerInterfacemyDatabaseLogger
 
double myLogPeriod
 
std::unique_ptr< std::thread > myThread
 
std::vector< boolmyCreatedTables
 
std::atomic< boolmyTimeToStop
 
std::atomic< boolmyStopped
 
LogToDatabaseTask * myTask
 

Private Member Functions

 DtVrfDatabaseConnection (const DtVrfDatabaseConnection &other)
 
DtVrfDatabaseConnectionoperator= (const DtVrfDatabaseConnection &other)
 

Constructor & Destructor Documentation

virtual DtVrfDatabaseConnection::~DtVrfDatabaseConnection ( )
virtual

Destructor.

DtVrfDatabaseConnection::DtVrfDatabaseConnection ( )
protected

Constructor.

DtVrfDatabaseConnection::DtVrfDatabaseConnection ( const DtVrfDatabaseConnection other)
private

Copy Constructor not implemented – Do Not copy.

Member Function Documentation

virtual bool DtVrfDatabaseConnection::initialize ( const DtRwDatabaseLoggerConfig config,
DtVrfDatabaseLoggerInterface dbLogger 
)
virtual

Initializes the connection to the database server. Stores the database logger pointer and calls processConfiguration(), connect(), and createDatabase().

virtual void DtVrfDatabaseConnection::run ( )
virtual

The main processing loop executed by the connection thread. This function will loop until the connection is stopped.

virtual bool DtVrfDatabaseConnection::processConfiguration ( const DtRwDatabaseLoggerConfig config)
protectedvirtual

Processes the configuration for this connection.

Reimplemented in DtVrfNoDatabaseConnection, DtVrfSqliteDatabaseConnection, and DtVrfMySqlDatabaseConnection.

virtual bool DtVrfDatabaseConnection::connect ( )
protectedpure virtual

Connects to the configured server.

Implemented in DtVrfNoDatabaseConnection, DtVrfSqliteDatabaseConnection, and DtVrfMySqlDatabaseConnection.

virtual bool DtVrfDatabaseConnection::createDatabase ( )
protectedpure virtual
virtual bool DtVrfDatabaseConnection::stop ( )
protectedvirtual

Stops the thread.

virtual bool DtVrfDatabaseConnection::createTableForEvent ( const DtVrfDatabaseEvent event)
protectedpure virtual

Creates a table a database table, if necessary.

Implemented in DtVrfNoDatabaseConnection, DtVrfSqliteDatabaseConnection, and DtVrfMySqlDatabaseConnection.

virtual bool DtVrfDatabaseConnection::insertOrIgnoreEntriesForEvents ( const DtVrfDatabaseEventVector events)
protectedpure virtual

Logs the given events to the database, ignoring duplicates. NOTE: All events in the list must be of the same event type!

Implemented in DtVrfNoDatabaseConnection, DtVrfSqliteDatabaseConnection, and DtVrfMySqlDatabaseConnection.

virtual bool DtVrfDatabaseConnection::insertOrUpdateEntriesForEvents ( const DtVrfDatabaseEventVector events)
protectedpure virtual

Logs the given events to the database, updating duplicates. NOTE: All events in the list must be of the same event type!

Implemented in DtVrfNoDatabaseConnection, DtVrfSqliteDatabaseConnection, and DtVrfMySqlDatabaseConnection.

virtual bool DtVrfDatabaseConnection::updateEntryForEvent ( const DtVrfDatabaseEvent event)
protectedpure virtual

Updates the given event in the database.

Implemented in DtVrfNoDatabaseConnection, DtVrfSqliteDatabaseConnection, and DtVrfMySqlDatabaseConnection.

virtual std::string DtVrfDatabaseConnection::escapeString ( std::string  str)
inlineprotectedvirtual

Takes the given string and escapes it for use in an SQL statement. Default implementation just returns the input string with no change. Subclasses may implement this.

Reimplemented in DtVrfSqliteDatabaseConnection, and DtVrfMySqlDatabaseConnection.

DtVrfDatabaseConnection& DtVrfDatabaseConnection::operator= ( const DtVrfDatabaseConnection other)
private

Assignment Operator not implemented – Do Not copy.

Member Data Documentation

DtVrfDatabaseLoggerInterface* DtVrfDatabaseConnection::myDatabaseLogger
protected
double DtVrfDatabaseConnection::myLogPeriod
protected
std::unique_ptr<std::thread> DtVrfDatabaseConnection::myThread
protected
std::vector<bool> DtVrfDatabaseConnection::myCreatedTables
protected
std::atomic<bool> DtVrfDatabaseConnection::myTimeToStop
protected
std::atomic<bool> DtVrfDatabaseConnection::myStopped
protected
LogToDatabaseTask* DtVrfDatabaseConnection::myTask
protected

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

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)