customdb_samples: createdbsample


Introduction

This Custom Database sample demonstrates how to:

Syntax:

createdbsample <dca-redist-folder> <ticket> <product> 
        <custom-db-folder>
custom-db-folder
The folder where the newly created database file will be saved in.
See also:
dca::UrlCustomDbModule
customdb_samples: customdbsample_extended
customdb_samples: customdbsample
Package: Custom Database Module Toolbox
Samples Main Documentation: Samples

Files

file  customdb_samples/createdbsample/main.cpp
 

Custom Database sample - create a database program.


Defines

#define DCA_BINDIR   "bin/linux"
 DCA subdirectory of the DCA binaries.
#define DCA_INITDIR   "init"
 DCA subdirectory of the DCA initialization data.
#define DCA_LOGDIR   "./logs"
 Relative directory for logfile(s).

Functions

static void SetupInitData (const std::string &redist_folder, InitData &initData)
 Sets up the given initData by substituting the given redist_folder with DCA subdirectories.
static void SetupLicense (const std::string &ticket, const std::string &product, LicenseData &licenseData)
 Sets up the given licenseData by copying the given ticket and product strings.
static void SetupConnectionData (const std::string &custom_db_folder, DbConnectionData &cData)
 Sets up the given cData to use a custom URL database.
static void PrintToolHeader ()
 Prints out the name and the version of this sample.
static void PrintUsage (const char *name)
 Prints out the syntax of the sample.
static void PrintLicenseInfo (const License &aLicense)
 Prints out the information about the provided License.
void AddUrlAndCategories (UrlCustomDb &aUrlCustomDb, const std::string &aUrlString, const CategorySet &aCategories)
 Adds a given UrlString and given CategorySet to the custom database.
void RemoveUrl (UrlCustomDb &aUrlCustomDb, const std::string &aUrlString)
 Removes a given UrlString from the custom database.
bool LookupUrl (const DcaInstance &theDca, const UrlDbClassifier &aUrlDbClassifier, const std::string &aUrlString, UrlClassificationResults &aUrlClassificationResults)
 Retrieves the UrlClassificationResults for a given UrlString.
bool CreateCustomDbFile (UrlCustomDbModule &aUrlCustomDbModule, const std::string &dbfolder)
 Creates physically a custom database in the given folder.
bool CreateCustomDbInstances (const DcaInstance &theDca, const License &aLicense, UrlCustomDbModule &aUrlCustomDbModule, DbConnection &aDbConnection, const std::string &dbfolder, UrlCustomDb &aUrlCustomDb)
 Creates the given DbConnection and UrlCustomDb instances and returns true on success or false on failure.
bool CreateUrlClassificationInstances (const DcaInstance &theDca, const License &aLicense, const DbConnection &aDbConnection, UrlClassification &aUrlClassification, UrlDbClassifier &aUrlDbClassifier)
 Creates the UrlClassification and UrlDbClassifier instances using the provided initialized DcaInstance, DbConnection and License instances.
bool ProcessCustomDatabase (const DcaInstance &theDca, const License &aLicense)
 Performs the following steps:

  • Initializes the CustomDbModule
  • Creates a custom database file
  • Connects to the custom database
  • Adds an URL with categorizations to the custom database
  • Retrieves the categorization for that URL and print it out
  • Removes the URL from the custom database and verifies that
  • Adds the URL again to the custom database
  • Retrieves the categorization by using the UrlDbClassifier and print it out.

int main (int argc, char *argv[])
 The main routine.

Variables

const std::string S_UsageString
 Usage string, displayed if a parameter is missing.

Function Documentation

static void SetupInitData ( const std::string &  redist_folder,
InitData initData 
) [static]

Sets up the given initData by substituting the given redist_folder with DCA subdirectories.

Parameters:
[in] redist_folder This is the folder where the DCA has been installed to (assuming trailing fileslash)
[out] initData The InitData structure to set up
Note:
Only DCA_BINDIR differs between Windows and Linux
The directory ./logs will be used for the logfile(s)

Definition at line 101 of file customdb_samples/createdbsample/main.cpp.

static void SetupLicense ( const std::string &  ticket,
const std::string &  product,
LicenseData licenseData 
) [static]

Sets up the given licenseData by copying the given ticket and product strings.

Parameters:
[in] ticket This is the ticket data as provided with your DCA license
[in] product This is the product shortcut e.g. DC oder MS etc
[out] licenseData The LicenseData structure to set up

Definition at line 116 of file customdb_samples/createdbsample/main.cpp.

static void SetupConnectionData ( const std::string &  custom_db_folder,
DbConnectionData cData 
) [static]

Sets up the given cData to use a custom URL database.

Parameters:
[in] custom_db_folder The folder where the Custom Database is located
[out] cData The DbConnectionData structure to set up
Note:
In the main() routine we first ensure that a database exists in the given custom_db_folder. If not, an empty database will be created.

Definition at line 131 of file customdb_samples/createdbsample/main.cpp.

static void PrintUsage ( const char *  name  )  [static]

Prints out the syntax of the sample.

Parameters:
[in] name The name of the executable

Definition at line 154 of file customdb_samples/createdbsample/main.cpp.

static void PrintLicenseInfo ( const License aLicense  )  [static]

Prints out the information about the provided License.

Parameters:
[in] aLicense The license for which information should be displayed

Definition at line 166 of file customdb_samples/createdbsample/main.cpp.

void AddUrlAndCategories ( UrlCustomDb aUrlCustomDb,
const std::string &  aUrlString,
const CategorySet &  aCategories 
)

Adds a given UrlString and given CategorySet to the custom database.

Parameters:
[in] aUrlCustomDb An already initialized UrlCustomDb
[in] aUrlString The URL that should be added to the custom database
[in] aCategories The categories that should stored together with the given UrlString

Definition at line 195 of file customdb_samples/createdbsample/main.cpp.

void RemoveUrl ( UrlCustomDb aUrlCustomDb,
const std::string &  aUrlString 
)

Removes a given UrlString from the custom database.

Parameters:
[in] aUrlCustomDb An already initialized UrlCustomDb
[in] aUrlString The URL that should be removed from the custom database

Definition at line 232 of file customdb_samples/createdbsample/main.cpp.

bool LookupUrl ( const DcaInstance theDca,
const UrlDbClassifier aUrlDbClassifier,
const std::string &  aUrlString,
UrlClassificationResults aUrlClassificationResults 
)

Retrieves the UrlClassificationResults for a given UrlString.

Parameters:
[in] theDca The initialized DcaInstance that will be used to create Url objects
[in] aUrlDbClassifier The classifier will be used for the classify() call
[in] aUrlString The URL for the lookup
[out] aUrlClassificationResults The results of the classify call
Returns:
true if the URL could be found in the custom database else false

Definition at line 249 of file customdb_samples/createdbsample/main.cpp.

bool CreateCustomDbFile ( UrlCustomDbModule aUrlCustomDbModule,
const std::string &  dbfolder 
)

Creates physically a custom database in the given folder.

Parameters:
[in] aUrlCustomDbModule An already initialized UrlCustomDbModule
[in] dbfolder The folder a new custom db file should be created in.
Returns:
true if the custom database could be created in the given dbfolder - else it returns false
Note:
Calling this function a second time will lead to an error, since the database already exists and could not be created. Only one database per folder is allowed.

Definition at line 277 of file customdb_samples/createdbsample/main.cpp.

bool CreateCustomDbInstances ( const DcaInstance theDca,
const License aLicense,
UrlCustomDbModule aUrlCustomDbModule,
DbConnection aDbConnection,
const std::string &  dbfolder,
UrlCustomDb aUrlCustomDb 
)

Creates the given DbConnection and UrlCustomDb instances and returns true on success or false on failure.

Parameters:
[in] theDca The initialized DcaInstance
[in] aLicense An already initialized License instance
[out] aUrlCustomDbModule The module will be initialized in this function and returned to the caller
[out] aDbConnection The database connection will be created in this function and returned to the caller
[in] dbfolder The folder of the custom database file
[out] aUrlCustomDb The UrlCustomDb will be created in this function and returned to the caller
Returns:
true if all instances could be created successfully, else false
Note:
Calling this function assumes a prior successful call to CreateCustomDbFile() or that a custom database file already exists in the given dbfolder

Definition at line 316 of file customdb_samples/createdbsample/main.cpp.

bool CreateUrlClassificationInstances ( const DcaInstance theDca,
const License aLicense,
const DbConnection aDbConnection,
UrlClassification aUrlClassification,
UrlDbClassifier aUrlDbClassifier 
)

Creates the UrlClassification and UrlDbClassifier instances using the provided initialized DcaInstance, DbConnection and License instances.

Parameters:
[in] theDca The initialized DcaInstance
[in] aLicense An already initialized License instance
[in] aDbConnection An already initialized DbConnection instance
[out] aUrlClassification The UrlClassification instance will be created in this function and returned to the caller
[out] aUrlDbClassifier The The UrlDbClassifier instance wll be created in this function and returned to the caller
Returns:
true if all instances could be created successfully else false

Definition at line 359 of file customdb_samples/createdbsample/main.cpp.

bool ProcessCustomDatabase ( const DcaInstance theDca,
const License aLicense 
)

Performs the following steps:

  • Initializes the CustomDbModule
  • Creates a custom database file
  • Connects to the custom database
  • Adds an URL with categorizations to the custom database
  • Retrieves the categorization for that URL and print it out
  • Removes the URL from the custom database and verifies that
  • Adds the URL again to the custom database
  • Retrieves the categorization by using the UrlDbClassifier and print it out.

Parameters:
[in] theDca The initialized DcaInstance object
[in] aLicense An already initialized License object
Returns:
true if no error occured else false

Definition at line 404 of file customdb_samples/createdbsample/main.cpp.

int main ( int  argc,
char *  argv[] 
)

The main routine.

Parameters:
[in] argc The count of arguments provided
[in] argv An array of provided arguments
Returns:
1 on usage error
10 on exception
5 if internal function fails
0 on success

Definition at line 545 of file customdb_samples/createdbsample/main.cpp.


Variable Documentation

const std::string S_UsageString
Initial value:
        "<redist-folder> <ticket> <product> <custom-db-folder>\n"
        "  redist-folder - the folder where the DCA is installed to\n"
        "  ticket - a valid ticket\n"
        "  product - the product associated with your ticket\n"
        "  custom-db-folder - the folder where the Custom Database should be created in\n\n"

Usage string, displayed if a parameter is missing.

Definition at line 62 of file customdb_samples/createdbsample/main.cpp.


Generated on 26 Sep 2016 for dca_interface by  doxygen 1.6.1