Diff for /parser3/src/main/pa_sql_driver_manager.C between versions 1.49 and 1.57

version 1.49, 2001/11/05 10:21:28 version 1.57, 2001/12/13 15:13:57
Line 2 Line 2
         Parser: sql driver manager implementation.          Parser: sql driver manager implementation.
   
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)          Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
   
         $Id$          $Id$
 */  */
Line 88  static void expire_connections(const Has Line 88  static void expire_connections(const Has
   
 // SQL_Driver_manager  // SQL_Driver_manager
   
 SQL_Driver_manager::SQL_Driver_manager(Pool& apool) : Pooled(apool),  SQL_Driver_manager::SQL_Driver_manager(Pool& apool) : Cache_manager(apool),
                 driver_cache(apool),                  driver_cache(apool),
                 connection_cache(apool),                  connection_cache(apool),
                 prev_expiration_pass_time(0) {                  prev_expiration_pass_time(0) {
   
         status_providers->put(*NEW String(pool(), "sql"), this);  
 }  }
   
 SQL_Driver_manager::~SQL_Driver_manager() {  SQL_Driver_manager::~SQL_Driver_manager() {
         connection_cache.for_each(expire_connections,           connection_cache.for_each(expire_connections, 
                 reinterpret_cast<void *>((time_t)0/*=in past=expire all*/));                  reinterpret_cast<void *>(time(0)+1/*=in future=expire all*/));
 }  }
   
 /// @param request_url protocol://[driver-dependent]  /// @param request_url protocol://[driver-dependent]
Line 155  SQL_Connection& SQL_Driver_manager::get_ Line 153  SQL_Connection& SQL_Driver_manager::get_
                         global_protocol_cstr);                          global_protocol_cstr);
   
                 SQL_Driver *driver;                  SQL_Driver *driver;
                 const String *dlopen_file_spec=0;  
                 // first trying to get cached driver                  // first trying to get cached driver
                 if(!(driver=get_driver_from_cache(global_protocol))) {                  if(!(driver=get_driver_from_cache(global_protocol))) {
                         // no cached                          // no cached
                         const String *library=0;                          const String *library=0;
                           const String *dlopen_file_spec=0;
                         if(protocol2driver_and_client->locate(0, global_protocol)) {                          if(protocol2driver_and_client->locate(0, global_protocol)) {
                                 if(!(library=protocol2driver_and_client->item(1)) || library->size()==0)                                  if(!(library=protocol2driver_and_client->item(1)) || library->size()==0)
                                         throw Exception(0, 0,                                          throw Exception(0, 0,
Line 204  SQL_Connection& SQL_Driver_manager::get_ Line 202  SQL_Connection& SQL_Driver_manager::get_
                                                 driver_api_version, SQL_DRIVER_API_VERSION);                                                  driver_api_version, SQL_DRIVER_API_VERSION);
   
                         // initialise by connecting to sql client dynamic link library                          // initialise by connecting to sql client dynamic link library
                         bool specified_dlopen_file_spec=dlopen_file_spec && dlopen_file_spec->size();                          char *dlopen_file_spec_cstr=
                         const char *dlopen_file_spec_cstr=                                  dlopen_file_spec && dlopen_file_spec->size()?
                                 specified_dlopen_file_spec?                                  dlopen_file_spec->cstr(String::UL_AS_IS):0;
                                 dlopen_file_spec->cstr(String::UL_FILE_SPEC):0;  
                         if(const char *error=driver->initialize(                          if(const char *error=driver->initialize(
                                 dlopen_file_spec_cstr))                                  dlopen_file_spec_cstr))
                                 throw Exception(0, 0,                                  throw Exception(0, 0,
                                         library,                                          library,
                                         "driver failed to initialize client library '%s', %s",                                          "driver failed to initialize client library '%s', %s",
                                                 specified_dlopen_file_spec?dlopen_file_spec_cstr:"unspecifed",                                                   dlopen_file_spec_cstr?dlopen_file_spec_cstr:"unspecifed", 
                                                 error);                                                  error);
   
                         // cache it                          // cache it
Line 263  void SQL_Driver_manager::put_driver_to_c Line 260  void SQL_Driver_manager::put_driver_to_c
 SQL_Connection *SQL_Driver_manager::get_connection_from_cache(const String& url) {   SQL_Connection *SQL_Driver_manager::get_connection_from_cache(const String& url) { 
         SYNCHRONIZED;          SYNCHRONIZED;
   
         maybe_expire_connection_cache();  
   
         if(Stack *connections=static_cast<Stack *>(connection_cache.get(url)))          if(Stack *connections=static_cast<Stack *>(connection_cache.get(url)))
                 while(connections->top_index()>=0) { // there are cached connections to that 'url'                  while(connections->top_index()>=0) { // there are cached connections to that 'url'
                         SQL_Connection *result=static_cast<SQL_Connection *>(connections->pop());                          SQL_Connection *result=static_cast<SQL_Connection *>(connections->pop());
Line 287  void SQL_Driver_manager::put_connection_ Line 282  void SQL_Driver_manager::put_connection_
         connections->push(&connection);          connections->push(&connection);
 }  }
   
 void SQL_Driver_manager::maybe_expire_connection_cache() {  void SQL_Driver_manager::maybe_expire_cache() {
         time_t now=time(0);          time_t now=time(0);
   
         if(prev_expiration_pass_time<now-CHECK_EXPIRED_CONNECTIONS_SECONDS) {          if(prev_expiration_pass_time<now-CHECK_EXPIRED_CONNECTIONS_SECONDS) {
Line 304  static void add_connection_to_status_cac Line 299  static void add_connection_to_status_cac
   
         if(connection.connected()) {          if(connection.connected()) {
                 Pool& pool=table.pool();                  Pool& pool=table.pool();
                 Array& row=*new(pool) Array(pool, 3);                  Array& row=*new(pool) Array(pool);
   
                   // url
                 row+=&url_without_login(pool, connection.get_url());                  row+=&url_without_login(pool, connection.get_url());
                   // time
                 time_t time_stamp=connection.get_time_stamp();                  time_t time_stamp=connection.get_time_stamp();
                 const char *unsafe_time_cstr=ctime(&time_stamp);                  const char *unsafe_time_cstr=ctime(&time_stamp);
                 int time_buf_size=strlen(unsafe_time_cstr);                  int time_buf_size=strlen(unsafe_time_cstr);
Line 323  static void add_connections_to_status_ca Line 320  static void add_connections_to_status_ca
         for(int countdown=stack.top_index(); countdown-->=0; )          for(int countdown=stack.top_index(); countdown-->=0; )
                 add_connection_to_status_cache_table(iter.next(), info);                  add_connection_to_status_cache_table(iter.next(), info);
 }  }
   
   
 Value& SQL_Driver_manager::get_status(Pool& pool, const String *source) {  Value& SQL_Driver_manager::get_status(Pool& pool, const String *source) {
         VHash& result=*new(pool) VHash(pool);          VHash& result=*new(pool) VHash(pool);
                   
         // cache          // cache
         {          {
                 Array& columns=*new(pool) Array(pool, 3);                  Array& columns=*new(pool) Array(pool);
                 columns+=new(pool) String(pool, "url");                  columns+=new(pool) String(pool, "url");
                 columns+=new(pool) String(pool, "time");                  columns+=new(pool) String(pool, "time");
                 Table& table=*new(pool) Table(pool, 0, &columns, connection_cache.size());                  Table& table=*new(pool) Table(pool, 0, &columns, connection_cache.size());
Line 341  Value& SQL_Driver_manager::get_status(Po Line 336  Value& SQL_Driver_manager::get_status(Po
         }          }
   
         return result;          return result;
 }  
   
   }

Removed from v.1.49  
changed lines
  Added in v.1.57


E-mail: