For the complete documentation index, see llms.txt. This page is also available as Markdown.

Accessing Toolpack DB

The CAF library provides DAOs (Data Access Objects) for all tables in the Toolpack configuration database.

Where to find these DAOs

These DAO objects are defined in the "tbcmc" source packages, for example tbcmc_2.5.89_common.tgz, under:

  • tb/inc/tbcaf/dao/oam

Prerequisites to use the DAOs

To access the Toolpack database, an application needs to:

  • Attach to Toolpack OAM "CM" (configuration management), by binding an object of type CTBCAFServiceCmMgmtClient to the application

  • Connect to the database using object of type CTBCAFDb initialized using the DB connection string received on OnReloadConfig (see CTBCAFServiceCmMgmtClient)

  • Use appropriate DAO access object to query the desired table

  • Optionally use a custom SQL query string to query specific elements from a table

How to use the DAOs

  • Initialize the DAO access object that corresponds to the table you want to read from (CTBCAFOam_virtual_adapters_db_acc for example) CTBCAFOam_virtual_adapters_db_acc AccessVirtualAdapters; AccessVirtualAdapters.Init( pConfigDb );

  • Use one of the DAO functions to retrieve one or multiple entries: CTBCAFOam_virtual_adapters VirtualAdapter = AccessVirtualAdapters.GetById( un32MyVirtualAdapterId ); std::vector<CTBCAFOam_virtual_adapters> AllVirtualAdapters = AccessVirtualAdapters.GetAllBy_configuration_id( un32ConfigurationId );

  • Access the information from returned classes VirtualAdapter.str_serial VirtualAdapter.un32_last_upgrade_time ...

Example code

The following code shows how to use the DAO objects, taken from the "simple_call" sample application:

  • --------------------------------------------------------------------------------------------------------------------------*/ CAFCODE( CTBS2GWSimpleCall::ExampleDbAccess ) { // Initialize the DAO access objects Result = ConfigurationsAdapters.Init( mpConfigDb ); TBCAF_EXIT_ON_ERROR( Result, "Cannot init ConfigurationsAdapters" );

    Result = AccessVirtualAdapters.Init( mpConfigDb ); TBCAF_EXIT_ON_ERROR( Result, "Cannot init AccessVirtualAdapters" );

    Result = AccessLineServices.Init( mpConfigDb ); TBCAF_EXIT_ON_ERROR( Result, "Cannot init AccessVirtualAdapters" );

    // Implementation note: // Database queries below should be done "in background" using a background thread of this application, outside // the lock of mMutex, in order to avoid blocking the whole application in case the database is // temporarily unavailable (backup database about to be activated, for example). // In this simple example, we do it inline, however...

    // Example get the name of current configuration (this function will 'throw' if not found) CurrentConfiguration = ConfigurationsAdapters.GetById( mun32ConfigurationId );

    // Example: Get all virtual adapters from current configuration AllVirtualAdapters = AccessVirtualAdapters.GetAllBy_configuration_id( mun32ConfigurationId );

    // Example: Print the serial number of all adapters of current configuration LogTrace ( TBCAF_TRACE_LEVEL_ALWAYS, "Adapters from current configuration %s", CurrentConfiguration.str_name.c_str() ); for( un32Index = 0; un32Index < AllVirtualAdapters.size(); un32Index++ ) { CTBCAFString strQuery; std::vector<CTBCAFOam_line_services> AllE1LineServices; std::vector<CTBCAFOam_line_services> AllT1LineServices;

    // Example custom SQL query to get E1 line services in current configuration strQuery.Format ( "SELECT * FROM %s WHERE %s="E1LineService"", TBTBL_LINE_SERVICES, TBCOL_LINE_SERVICES_COMMON_LINE_SERVICE_TYPE ); AllE1LineServices = AccessLineServices.GetAll( strQuery );

    // Example custom SQL query to get T1 line services in current configuration strQuery.Format ( "SELECT * FROM %s WHERE %s="T1LineService"", TBTBL_LINE_SERVICES, TBCOL_LINE_SERVICES_COMMON_LINE_SERVICE_TYPE ); AllT1LineServices = AccessLineServices.GetAll( strQuery );

    LogTrace ( TBCAF_TRACE_LEVEL_ALWAYS, " %s (%u E1, %u T1 line services)", AllVirtualAdapters[ un32Index ].str_serial.c_str(), AllE1LineServices.size(), AllT1LineServices.size() ); }

    ExampleDbQuery();

    TBX_EXIT_SUCCESS( TBX_RESULT_OK ); }

    /*--------------------------------------------------------------------------------------------------------------------------- | Exception handling section

  • --------------------------------------------------------------------------------------------------------------------------*/ CAF_EXCEPTION_HANDLING

    /*--------------------------------------------------------------------------------------------------------------------------- | Error handling section

  • --------------------------------------------------------------------------------------------------------------------------*/ CAF_ERROR_HANDLING( CAF_VERBOSE ) { }

    /*--------------------------------------------------------------------------------------------------------------------------- | Cleanup section

  • --------------------------------------------------------------------------------------------------------------------------*/ CAF_CLEANUP { AccessLineServices.Uninit(); AccessVirtualAdapters.Uninit(); ConfigurationsAdapters.Uninit(); }

    RETURN; }

Last updated

Was this helpful?