NCBI C++ ToolKit
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
CDbapiSampleApp Class Referenceabstract

Search Toolkit Book for CDbapiSampleApp

#include "dbapi_sample_base.hpp"
(Private to src/dbapi/driver/samples.)

+ Inheritance diagram for CDbapiSampleApp:
+ Collaboration diagram for CDbapiSampleApp:

Public Types

enum  EUseSampleDatabase { eUseSampleDatabase, eDoNotUseSampleDatabase }
 
- Public Types inherited from CNcbiApplication
enum  EAppNameType { eBaseName, eFullName, eRealName }
 

Public Member Functions

 CDbapiSampleApp (EUseSampleDatabase sd=eUseSampleDatabase)
 
virtual ~CDbapiSampleApp (void)
 
- Public Member Functions inherited from CNcbiApplication
 CNcbiApplication (const SBuildInfo &build_info=SBuildInfo())
 Constructor. More...
 
virtual ~CNcbiApplication (void)
 Destructor. More...
 
int AppMain (int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
 Main function (entry point) for the NCBI application. More...
 
virtual int DryRun (void)
 Test run the application. More...
 
const CNcbiArgumentsGetArguments (void) const
 Get the application's cached unprocessed command-line arguments. More...
 
virtual const CArgsGetArgs (void) const
 Get parsed command line arguments. More...
 
const CNcbiEnvironmentGetEnvironment (void) const
 Get the application's cached environment. More...
 
CNcbiEnvironmentSetEnvironment (void)
 Get a non-const copy of the application's cached environment. More...
 
void SetEnvironment (const string &name, const string &value)
 Set a specified environment variable by name. More...
 
bool HasLoadedConfig (void) const
 Check if the config file has been loaded. More...
 
bool FinishedLoadingConfig (void) const
 Check if the application has finished loading config file (successfully or not). More...
 
const CNcbiRegistryGetConfig (void) const
 Get the application's cached configuration parameters (read-only). More...
 
CNcbiRegistryGetConfig (void)
 
const stringGetConfigPath (void) const
 Get the full path to the configuration file (if any) we ended up using. More...
 
bool ReloadConfig (CMetaRegistry::TFlags flags=CMetaRegistry::fReloadIfChanged, IRegistry::TFlags reg_flags=IRegistry::fWithNcbirc)
 Reload the configuration file. More...
 
SIZE_TYPE FlushDiag (CNcbiOstream *os, bool close_diag=false)
 Flush the in-memory diagnostic stream (for "eDS_ToMemory" case only). More...
 
const stringGetProgramDisplayName (void) const
 Get the application's "display" name. More...
 
const stringGetProgramExecutablePath (EFollowLinks follow_links=eIgnoreLinks) const
 Get the application's executable path. More...
 
CVersionInfo GetVersion (void) const
 Get the program version information. More...
 
const CVersionGetFullVersion (void) const
 Get the program version information. More...
 
bool IsDryRun (void) const
 Check if it is a test run. More...
 
virtual bool SetupDiag_AppSpecific (void)
 Setup application specific diagnostic stream. More...
 
template<class TFunc >
void AddOnExitAction (TFunc func)
 Add callback to be executed from CNcbiApplication destructor. More...
 

Protected Types

enum  EServerType { eUnknown, eSybase, eMsSql }
 
typedef map< string, stringTDatabaseParameters
 
- Protected Types inherited from CNcbiApplication
enum  EPreparseArgs { ePreparse_Continue, ePreparse_Exit }
 Result of PreparseArgs() More...
 
enum  EDisableArgDesc { fDisableStdArgs = 0x01 }
 Disable argument descriptions. More...
 
enum  EHideStdArgs {
  fHideLogfile = 0x01, fHideConffile = 0x02, fHideVersion = 0x04, fHideFullVersion = 0x08,
  fHideDryRun = 0x10, fHideHelp = 0x20, fHideFullHelp = 0x40, fHideXmlHelp = 0x80,
  fHideAll = 0xFF
}
 Which standard flag's descriptions should not be displayed in the usage message. More...
 
enum  EStdioSetup { fDefault_SyncWithStdio = 0x01, fDefault_CinBufferSize = 0x02, fBinaryCin = 0x04, fBinaryCout = 0x08 }
 Flags to adjust standard I/O streams' behaviour. More...
 
enum  EExitMode { eNoExits, eExceptionalExits, eAllExits }
 When to return a user-set exit code. More...
 
typedef int TDisableArgDesc
 Binary OR of "EDisableArgDesc". More...
 
typedef int THideStdArgs
 Binary OR of "EHideStdArgs". More...
 
typedef int TStdioSetupFlags
 Binary OR of "EStdioSetup". More...
 

Protected Member Functions

virtual void InitSample (CArgDescriptions &arg_desc)
 Override these 3 to suit your test's needs. More...
 
virtual int RunSample (void)=0
 
virtual void ExitSample (void)
 
CDB_ConnectionGetConnection (void)
 Get connection created using server, username and password specified in the application command line. More...
 
void ShowResults (const string &query)
 Delete table if it exists ShowResults is printing resuts on screen. More...
 
void DeleteTable (const string &table_name)
 
void CreateTable (const string &table_name)
 function CreateTable is creating table in the database More...
 
I_DriverContextGetDriverContext (void)
 Get the driver context (for the driver specified in the command line) More...
 
CDB_ConnectionCreateConnection (IConnValidator *validator=NULL, I_DriverContext::TConnectionMode mode=I_DriverContext::fBcpIn, bool reusable=false, const string &pool_name=kEmptyStr)
 Create new connection using server, username and password specified in the application command line. More...
 
void DeleteLostTables (void)
 Delete tables which are lost after previous tests. More...
 
const stringGetTableUID (void) const
 Return an unique identificatot which contains host name, process id and current date. More...
 
const stringGetDriverName (void) const
 Return current driver name. More...
 
void SetDriverName (const string &name)
 Set driver name. More...
 
const stringGetServerName (void) const
 Return current server name. More...
 
EServerType GetServerType (void) const
 Return current server type. More...
 
const stringGetUserName (void) const
 Return current user name. More...
 
const stringGetPassword (void) const
 Return current password. More...
 
void SetDatabaseParameter (const string &name, const string &value)
 Set database connection parameter. More...
 
const TDatabaseParametersGetDatabaseParameters (void) const
 Return database conection parameters. More...
 
bool UseSvcMapper (void) const
 
- Protected Member Functions inherited from CNcbiApplication
virtual EPreparseArgs PreparseArgs (int argc, const char *const *argv)
 Check the command line arguments before parsing them. More...
 
void DisableArgDescriptions (TDisableArgDesc disable=fDisableStdArgs)
 
void HideStdArgs (THideStdArgs hide_mask)
 Set the hide mask for the Hide Std Flags. More...
 
void SetStdioFlags (TStdioSetupFlags stdio_flags)
 Adjust the behavior of standard I/O streams. More...
 
void SetVersion (const CVersionInfo &version)
 Set the version number for the program. More...
 
void SetVersion (const CVersionInfo &version, const SBuildInfo &build_info)
 
void SetVersionByBuild (int major)
 
void SetFullVersion (CRef< CVersion > version)
 Set version data for the program. More...
 
virtual void SetupArgDescriptions (CArgDescriptions *arg_desc)
 Setup the command line argument descriptions. More...
 
const CArgDescriptionsGetArgDescriptions (void) const
 Get argument descriptions (set by SetupArgDescriptions) More...
 
bool SetupDiag (EAppDiagStream diag)
 Setup the application diagnostic stream. More...
 
virtual bool LoadConfig (CNcbiRegistry &reg, const string *conf, CNcbiRegistry::TFlags reg_flags)
 Load settings from the configuration file to the registry. More...
 
virtual bool LoadConfig (CNcbiRegistry &reg, const string *conf)
 Load settings from the configuration file to the registry. More...
 
CNcbiRegistryGetRWConfig (void)
 Get the application's cached configuration parameters, accessible to read-write for an application only. More...
 
void SetProgramDisplayName (const string &app_name)
 Set program's display name. More...
 
virtual void AppStart (void)
 Method to be called before application start. More...
 
virtual void AppStop (int exit_code)
 Method to be called before application exit. More...
 
void SetExitCode (int exit_code, EExitMode when=eExceptionalExits)
 Force the program to return a specific exit code later, either when it exits due to an exception or unconditionally. More...
 

Private Member Functions

virtual void Init ()
 Initialize the application. More...
 
virtual int Run ()
 Run the application. More...
 
virtual void Exit ()
 Cleanup on application exit. More...
 

Private Attributes

unique_ptr< I_DriverContextm_DriverContext
 
unique_ptr< CDB_Connectionm_Connection
 
string m_TableUID
 
EUseSampleDatabase m_UseSampleDatabase
 
string m_DriverName
 
string m_ServerName
 
string m_UserName
 
string m_Password
 
string m_TDSVersion
 
bool m_UseSvcMapper
 
TDatabaseParameters m_DatabaseParameters
 

Additional Inherited Members

- Static Public Member Functions inherited from CNcbiApplication
static CNcbiApplicationInstance (void)
 Singleton method. More...
 
static SSystemMutex & GetInstanceMutex (void)
 Mutex for application singleton object. More...
 
static string GetAppName (EAppNameType name_type=eBaseName, int argc=0, const char *const *argv=NULL)
 
- Static Protected Member Functions inherited from CNcbiApplication
static string FindProgramExecutablePath (int argc, const char *const *argv, string *real_path=0)
 Find the application's executable file. More...
 

Detailed Description

Definition at line 61 of file dbapi_sample_base.hpp.

Member Typedef Documentation

Definition at line 120 of file dbapi_sample_base.hpp.

Member Enumeration Documentation

Enumerator
eUnknown 
eSybase 
eMsSql 

Definition at line 115 of file dbapi_sample_base.hpp.

Enumerator
eUseSampleDatabase 
eDoNotUseSampleDatabase 

Definition at line 64 of file dbapi_sample_base.hpp.

Constructor & Destructor Documentation

CDbapiSampleApp::CDbapiSampleApp ( EUseSampleDatabase  sd = eUseSampleDatabase)
CDbapiSampleApp::~CDbapiSampleApp ( void  )
virtual

Definition at line 109 of file dbapi_sample_base.cpp.

Member Function Documentation

CDB_Connection * CDbapiSampleApp::CreateConnection ( IConnValidator validator = NULL,
I_DriverContext::TConnectionMode  mode = I_DriverContext::fBcpIn,
bool  reusable = false,
const string pool_name = kEmptyStr 
)
protected
void CDbapiSampleApp::CreateTable ( const string table_name)
protected

function CreateTable is creating table in the database

Definition at line 518 of file dbapi_sample_base.cpp.

Referenced by CDbapiQueryApp::RunSample(), CDbapiSendDataApp::RunSample(), CDbapiTestSpeedApp::RunSample(), and CDbapiBcpApp::RunSample().

void CDbapiSampleApp::DeleteLostTables ( void  )
protected
void CDbapiSampleApp::DeleteTable ( const string table_name)
protected
void CDbapiSampleApp::Exit ( void  )
privatevirtual

Cleanup on application exit.

Perform cleanup before exiting. The default behavior of this is "do nothing". If you have special cleanup logic that needs to be performed, then you must override this method with your own logic.

Reimplemented from CNcbiApplication.

Definition at line 268 of file dbapi_sample_base.cpp.

References ExitSample().

void CDbapiSampleApp::ExitSample ( void  )
protectedvirtual

Definition at line 124 of file dbapi_sample_base.cpp.

Referenced by Exit().

CDB_Connection & CDbapiSampleApp::GetConnection ( void  )
protected
const TDatabaseParameters& CDbapiSampleApp::GetDatabaseParameters ( void  ) const
inlineprotected

Return database conection parameters.

Definition at line 165 of file dbapi_sample_base.hpp.

References m_DatabaseParameters.

Referenced by GetDriverContext().

I_DriverContext & CDbapiSampleApp::GetDriverContext ( void  )
protected

Get the driver context (for the driver specified in the command line)

Definition at line 275 of file dbapi_sample_base.cpp.

References ERR_POST_X, Fatal(), GetDatabaseParameters(), C_DriverMgr::GetDriverContext(), GetDriverName(), and m_DriverContext.

Referenced by CreateConnection(), CDbapiCursorApp::RunOneSample(), and CDbapiSendDataApp::RunSample().

const string& CDbapiSampleApp::GetDriverName ( void  ) const
inlineprotected

Return current driver name.

Definition at line 124 of file dbapi_sample_base.hpp.

References _ASSERT, and m_DriverName.

Referenced by GetDriverContext(), Run(), CLangQueryApp::RunSample(), CDbapiCursorApp::RunSample(), and CDbapiTestSpeedApp::RunSample().

const string& CDbapiSampleApp::GetPassword ( void  ) const
inlineprotected

Return current password.

Definition at line 150 of file dbapi_sample_base.hpp.

References _ASSERT, and m_Password.

Referenced by CreateConnection().

const string& CDbapiSampleApp::GetServerName ( void  ) const
inlineprotected

Return current server name.

Definition at line 136 of file dbapi_sample_base.hpp.

References _ASSERT, and m_ServerName.

Referenced by CreateConnection(), GetServerType(), and CLangQueryApp::RunSample().

CDbapiSampleApp::EServerType CDbapiSampleApp::GetServerType ( void  ) const
protected
const string& CDbapiSampleApp::GetTableUID ( void  ) const
inlineprotected

Return an unique identificatot which contains host name, process id and current date.

Definition at line 109 of file dbapi_sample_base.hpp.

References m_TableUID.

const string& CDbapiSampleApp::GetUserName ( void  ) const
inlineprotected

Return current user name.

Definition at line 144 of file dbapi_sample_base.hpp.

References _ASSERT, and m_UserName.

Referenced by CreateConnection().

void CDbapiSampleApp::Init ( void  )
privatevirtual

Initialize the application.

The default behavior of this is "do nothing". If you have special initialization logic that needs to be peformed, then you must override this method with your own logic.

Reimplemented from CNcbiApplication.

Definition at line 145 of file dbapi_sample_base.cpp.

References ALL_DRIVERS, DEF_DRIVER, DEF_SERVER, CArgDescriptions::eInteger, CArgDescriptions::eString, CNcbiApplication::GetArguments(), InitSample(), and CNcbiApplication::SetupArgDescriptions().

void CDbapiSampleApp::InitSample ( CArgDescriptions arg_desc)
protectedvirtual

Override these 3 to suit your test's needs.

Reimplemented in CDbapiTestSpeedApp, and CLangQueryApp.

Definition at line 117 of file dbapi_sample_base.cpp.

Referenced by Init().

int CDbapiSampleApp::Run ( )
privatevirtual

Run the application.

It is defined as a pure virtual method – so you must(!) supply the Run() method to implement the application-specific logic.

Returns
Exit code.

Implements CNcbiApplication.

Definition at line 208 of file dbapi_sample_base.cpp.

References DBLB_INSTALL_DEFAULT, ERR_POST_X, eSybase, CNcbiApplication::GetArgs(), CDB_UserHandler::GetDefault(), GetDriverName(), CRandom::GetRand(), GetServerType(), CDB_UserHandler::HandleIt(), LOG_POST_X, m_DriverName, m_Password, m_ServerName, m_TDSVersion, m_UserName, m_UseSvcMapper, NULL, RunSample(), SetDatabaseParameter(), and UseSvcMapper().

virtual int CDbapiSampleApp::RunSample ( void  )
protectedpure virtual
void CDbapiSampleApp::SetDatabaseParameter ( const string name,
const string value 
)
inlineprotected

Set database connection parameter.

NOTE: Database parameters will affect a connection only is you set them before actual connect.

Definition at line 159 of file dbapi_sample_base.hpp.

References _ASSERT, m_DatabaseParameters, and value.

Referenced by Run(), CDbapiCursorApp::RunSample(), and CDbapiTestSpeedApp::RunSample().

void CDbapiSampleApp::SetDriverName ( const string name)
inlineprotected

Set driver name.

Definition at line 130 of file dbapi_sample_base.hpp.

References _ASSERT, and m_DriverName.

Referenced by CDbapiTestSpeedApp::RunSample().

void CDbapiSampleApp::ShowResults ( const string query)
protected

Delete table if it exists ShowResults is printing resuts on screen.

Definition at line 426 of file dbapi_sample_base.cpp.

References eDB_RowResult, GetConnection(), and r().

Referenced by CDbapiCursorApp::RunOneSample(), CLangQueryApp::RunSample(), CDbapiQueryApp::RunSample(), CDbapiSendDataApp::RunSample(), and CDbapiBcpApp::RunSample().

bool CDbapiSampleApp::UseSvcMapper ( void  ) const
inlineprotected

Definition at line 170 of file dbapi_sample_base.hpp.

References m_UseSvcMapper.

Referenced by Run().

Member Data Documentation

unique_ptr<CDB_Connection> CDbapiSampleApp::m_Connection
private

Definition at line 182 of file dbapi_sample_base.hpp.

TDatabaseParameters CDbapiSampleApp::m_DatabaseParameters
private

Definition at line 193 of file dbapi_sample_base.hpp.

Referenced by GetDatabaseParameters(), and SetDatabaseParameter().

unique_ptr<I_DriverContext> CDbapiSampleApp::m_DriverContext
private

Definition at line 181 of file dbapi_sample_base.hpp.

Referenced by GetDriverContext().

string CDbapiSampleApp::m_DriverName
private

Definition at line 186 of file dbapi_sample_base.hpp.

Referenced by GetDriverName(), Run(), and SetDriverName().

string CDbapiSampleApp::m_Password
private

Definition at line 189 of file dbapi_sample_base.hpp.

Referenced by GetPassword(), and Run().

string CDbapiSampleApp::m_ServerName
private

Definition at line 187 of file dbapi_sample_base.hpp.

Referenced by GetServerName(), and Run().

string CDbapiSampleApp::m_TableUID
private

Definition at line 183 of file dbapi_sample_base.hpp.

Referenced by CDbapiSampleApp(), and GetTableUID().

string CDbapiSampleApp::m_TDSVersion
private

Definition at line 190 of file dbapi_sample_base.hpp.

Referenced by Run().

string CDbapiSampleApp::m_UserName
private

Definition at line 188 of file dbapi_sample_base.hpp.

Referenced by GetUserName(), and Run().

EUseSampleDatabase CDbapiSampleApp::m_UseSampleDatabase
private

Definition at line 184 of file dbapi_sample_base.hpp.

Referenced by CreateConnection().

bool CDbapiSampleApp::m_UseSvcMapper
private

Definition at line 191 of file dbapi_sample_base.hpp.

Referenced by Run(), and UseSvcMapper().


The documentation for this class was generated from the following files:
Modified on Thu Dec 14 18:16:07 2017 by modify_doxy.py rev. 546573