Main Page Class Hierarchy Compound List File List Compound Members File Members

# dbmutableserver.cpp

Go to the documentation of this file.

    00001 /*
    00002  * dbmutableserverbase.cpp -- definition of a class which extends
    00003  *                            MutableServerBase with basic database
    00004  *                            functionality.
    00005  */
    00006
    00007 #include "dbmutableserver.h"
    00008
    00009 #include <oracleconfigsource.h>
    00010
    00011
    00012 //------------------------------------------------------------------------------
    00013 HANDLE_STATUS DBMutableServer::HandleConfigLine( ConfigSource * p_parser )
    00014 {
    00015    // BASE CLASSES MUST BE GIVEN THE CHANCE TO GET CONFIG VARIABLES:
    00016    HANDLE_STATUS r_status = MutableServerBase::HandleConfigLine(p_parser);
    00017
    00018
    00019    if ( r_status == HANDLER_UNUSED )
    00020    {
    00021       // Base class didn't use it, then it might belong to this
    00022       // derivative class
    00023
    00024       try
    00025       {
    00026          // this do-while is solely to allow a single return point,
    00027          // thus simplifying the code.
    00028
    00029          do
    00030          {
    00031             char * _token;
    00032
    00033
    00034             if ( p_parser->Its("DBConnection") )
    00035             {
    00036                _token = p_parser->String();
    00037                if ( strlen(_token) == 0 )
    00038                {
    00039                   throw worm_exception("Missing <DBConnection> User value");
    00040                }
    00041                DB_User = _token;
    00042
    00043                _token = p_parser->String();
    00044                if ( strlen(_token) == 0 )
    00045                {
    00046                   throw worm_exception("Missing <DBConnection> Password value");
    00047                }
    00048                DB_Password = _token;
    00049
    00050                _token = p_parser->String();
    00051                if ( strlen(_token) == 0 )
    00052                {
    00053                   throw worm_exception("Missing <DBConnection> Servicevalue");
    00054                }
    00055                DB_Service = _token;
    00056
    00057                r_status = HANDLER_USED;
    00058
    00059                continue;
    00060             }
    00061
    00062          } while ( false ) ;
    00063       }
    00064       catch( worm_exception & _we )
    00065       {
    00066          r_status = HANDLER_INVALID;
    00067          if( WORM_LOG_ERRORS <= LoggingLevel )
    00068          {
    00069             TLogger::Logit( LoggingOptions
    00070                          , "MLServer::HandleConfigLine(): configuration error:\n%s\n"
    00071                          , _we.what()
    00072                          );
    00073          }
    00074       }
    00075    }
    00076
    00077    return r_status;
    00078 }
    00079 //------------------------------------------------------------------------------
    00080 void DBMutableServer::CheckConfig()
    00081 {
    00082    MutableServerBase::CheckConfig();
    00083
    00084    if (   DB_User.length() == 0
    00085        || DB_Password.length() == 0
    00086        || DB_Service.length() == 0
    00087       )
    00088    {
    00089       TLogger::Logit( LoggingOptions
    00090                     , "DBMutableServer::CheckConfig(): <DBConnection> not complete for %s mode\n"
    00091                     , MSB_MODE_NAME[Mode]
    00092                     );
    00093       ConfigState = WORM_STAT_BADSTATE;
    00094    }
    00095 }
    00096 //------------------------------------------------------------------------------
    00097 bool DBMutableServer::PrepareToRun()
    00098 {
    00099    bool r_status = false;
    00100
    00101    try
    00102    {
    00103       if ( MutableServerBase::PrepareToRun() )
    00104       {
    00105          r_status = InitializeDB();
    00106       }
    00107    }
    00108    catch( worm_exception & _we )
    00109    {
    00110       if( WORM_LOG_ERRORS <= LoggingLevel )
    00111       {
    00112          TLogger::Logit( LoggingOptions
    00113                        , "DBMutableServer::PrepareToRun() Error: %s\n"
    00114                        , _we.what()
    00115                        );
    00116       }
    00117
    00118       r_status = false;
    00119    }
    00120    return r_status;
    00121 }
    00122
    00123 //------------------------------------------------------------------------------
    00124 bool DBMutableServer::InitializeDB()
    00125 {
    00126    bool r_status = false;
    00127
    00128    try
    00129    {
    00130       if (   DB_User.length()     == 0 || 39 < DB_User.length()
    00131           || DB_Password.length() == 0 || 19 < DB_Password.length()
    00132           || DB_Service.length()  == 0 || 19 < DB_Service.length()
    00133          )
    00134       {
    00135          throw worm_exception("Database connection parameter missing or too long");
    00136       }
    00137
    00138
    00139       char _user[40]
    00140          , _passwd[20]
    00141          , _service[20]
    00142          ;
    00143
    00144       strcpy( _user    , DB_User.c_str() );
    00145       strcpy( _passwd  , DB_Password.c_str() );
    00146       strcpy( _service , DB_Service.c_str() );
    00147
    00148       //
    00149       // Initialize the Ora_API
    00150       //
    00151       if ( ewdb_base_Init( _user, _passwd, _service ) == EWDB_RETURN_FAILURE )
    00152       {
    00153          throw worm_exception("Database connection initialization failed");
    00154       }
    00155
    00156       r_status = true;
    00157
    00158    }
    00159    catch( worm_exception & _we )
    00160    {
    00161       if( WORM_LOG_ERRORS <= LoggingLevel )
    00162       {
    00163          TLogger::Logit( LoggingOptions
    00164                        , "DBMutableServer::InitializeDB() Error: %s\n"
    00165                        , _we.what()
    00166                        );
    00167       }
    00168    }
    00169
    00170    return r_status;
    00171 }
    00172
    00173 //------------------------------------------------------------------------------
    00174 bool DBMutableServer::GetDefaultsFromDB( void * p_parmstruct )
    00175 {
    00176    bool r_status = true;
    00177
    00178    OracleConfigSource * _defaults = NULL;
    00179
    00180    try
    00181    {
    00182       //
    00183       // Get Default Parameters from the database
    00184       //
    00185 /*
    00186       if ( (_defaults = new OracleConfigSource()) == NULL )
    00187       {
    00188          throw worm_exception("Failed creating Oracle configuration datasource");
    00189       }
    00190
    00191 // EXACTLY HOW PASSPORTS ARE TO BE QUERIED FROM THE DATABASE HAS NOT YET BEEN
    00192 // DETERMINED
    00193
    00194 static const int SERVER_TYPE_ID = 47;
    00195
    00196       _defaults->LoadFromDB( SERVER_TYPE_ID );
    00197
    00198       HandleParameterLine( _defaults, p_parmstruct );
    00199
    00200 */
    00201
    00202   }
    00203    catch( worm_exception & _we )
    00204    {
    00205       r_status = false;
    00206
    00207       if( WORM_LOG_ERRORS <= LoggingLevel )
    00208       {
    00209          TLogger::Logit( LoggingOptions
    00210                        , "DBMutableServer::GetDefaultsFromDB() Error: %s\n"
    00211                        , _we.what()
    00212                        );
    00213       }
    00214    }
    00215
    00216    if ( _defaults != NULL )
    00217    {
    00218       delete _defaults;
    00219    }
    00220
    00221    return r_status;
    00222 }
    00223
    00224 //------------------------------------------------------------------------------