--- parser3/src/main/pa_sql_driver_manager.C 2003/03/20 14:19:10 1.69.2.17.2.3 +++ parser3/src/main/pa_sql_driver_manager.C 2003/04/02 10:10:01 1.69.2.17.2.12 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_SQL_DRIVER_MANAGER_C="$Date: 2003/03/20 14:19:10 $"; +static const char* IDENT_SQL_DRIVER_MANAGER_C="$Date: 2003/04/02 10:10:01 $"; #include "pa_sql_driver_manager.h" #include "ltdl.h" @@ -28,12 +28,12 @@ const time_t CHECK_EXPIRED_CONNECTIONS_S // helpers const String& SQL_Driver_services_impl::url_without_login() const { - const String& result(new String); - *result << furl->mid(0, furl->pos(":")) << "://****"; + String& result=*new String; + result << furl->mid(0, furl->pos(':')) << "://****"; - int at_pos=furl->pos("@"); - if(at_pos>0) - *result << furl->mid(at_pos, furl->length()); + size_t at_pos=furl->pos('@'); + if(at_pos!=STRING_NOT_FOUND) + result << furl->mid(at_pos, furl->length()); return result; } @@ -45,10 +45,10 @@ static void expire_connection(SQL_Connec connection.disconnect(); } static void expire_connections( - SQL_Driver_manager::connection_cache_type::key_type /*key*/, - SQL_Driver_manager::connection_cache_type::value_type stack, - time_t older_dies) { - for(int i=0; i<=stack->top_index(); i++) + SQL_Driver_manager::connection_cache_type::key_type /*key*/, + SQL_Driver_manager::connection_cache_type::value_type stack, + time_t older_dies) { + for(size_t i=0; i<=stack->top_index(); i++) expire_connection(*stack->get(i), older_dies); } @@ -57,7 +57,7 @@ static void expire_connections( SQL_Driver_manager::SQL_Driver_manager(): prev_expiration_pass_time(0), is_dlinited(false) { - cache_managers.put(String* (new String("sql")), this); + cache_managers.put(StringBody("sql"), this); } SQL_Driver_manager::~SQL_Driver_manager() { @@ -68,64 +68,59 @@ SQL_Driver_manager::~SQL_Driver_manager( } /// @param aurl protocol://[driver-dependent] -SQL_ConnectionPtr SQL_Driver_manager::get_connection(const String& arequest_url, - const String& aorigin, - Table *protocol2driver_and_client) { +SQL_Connection* SQL_Driver_manager::get_connection(const String& aurl, + Table *protocol2driver_and_client) { // we have table for locating protocol's library if(!protocol2driver_and_client) throw Exception("parser.runtime", - arequest_url, + &aurl, "$"MAIN_SQL_NAME":"MAIN_SQL_DRIVERS_NAME" table must be defined"); // first trying to get cached connection - SQL_ConnectionPtr connection=get_connection_from_cache(arequest_url); + SQL_Connection* connection=get_connection_from_cache(aurl); if(connection) { - connection->set_pool(&apool); + connection->set_url(); if(!connection->ping()) { // we have some cached connection, is it pingable? connection->disconnect(); // kill unpingabe=dead connection - connection=SQL_ConnectionPtr(0); + connection=0; } } - const char* request_url_cstr_ptr; - char *request_url_cstr; + char *url_cstr; if(connection) - request_url_cstr=0; // calm, compiler + url_cstr=0; // calm, compiler else { // no cached connection or it were unpingabe: connect/reconnect - if(arequest_url->pos("://")<0) + url_cstr=aurl.cstrm(); + if(!strstr(url_cstr, "://")) throw Exception("parser.runtime", - arequest_url->length()?arequest_url:aorigin, + aurl.length()?&aurl:0, "connection string must start with protocol://"); - // make global_url C-string on driver_cache_pool pool - const String& global_url(new String(arequest_url->cstr(driver_cache_pool))); - - request_url_cstr=request_url_cstr_ptr=arequest_url->cstr(); - char *request_protocol_cstr=lsplit(&request_url_cstr, ':'); + + char *protocol_cstr=lsplit(&url_cstr, ':'); // skip "//" after ':' - while(*request_url_cstr=='/') - request_url_cstr++; - // make global_protocol C-string on driver_cache_pool pool - const String& global_protocol(new String(driver_cache_pool.copy(request_protocol_cstr))); + while(*url_cstr=='/') + url_cstr++; + const String& protocol=*new String(protocol_cstr); SQL_Driver *driver; // first trying to get cached driver - if(!(driver=get_driver_from_cache(global_protocol))) { + if(!(driver=get_driver_from_cache(protocol))) { // no cached - const String& library(0); - const String& dlopen_file_spec(0); - if(protocol2driver_and_client->locate(0, global_protocol)) { + const String* library=0; + const String* dlopen_file_spec=0; + if(protocol2driver_and_client->locate(0, protocol)) { if(!(library=protocol2driver_and_client->item(1)) || library->length()==0) throw Exception("parser.runtime", - protocol2driver_and_client->origin_string(), + 0, "driver library column for protocol '%s' is empty", - request_protocol_cstr); + protocol_cstr); dlopen_file_spec=protocol2driver_and_client->item(2); } else throw Exception("parser.runtime", - arequest_url, + &aurl, "undefined protocol '%s'", - request_protocol_cstr); + protocol_cstr); if(!is_dlinited) { if(lt_dlinit()) @@ -136,7 +131,7 @@ SQL_ConnectionPtr SQL_Driver_manager::ge is_dlinited=true; } - const char* filename=library->cstr(String::UL_FILE_SPEC); + const char* filename=library->cstr(String::L_FILE_SPEC); lt_dlhandle handle=lt_dlopen(filename); if (!handle) throw Exception(0, @@ -162,37 +157,34 @@ SQL_ConnectionPtr SQL_Driver_manager::ge driver_api_version, SQL_DRIVER_API_VERSION); // initialise by connecting to sql client dynamic link library - const char* dlopen_file_spec_cstr= + char* dlopen_file_spec_cstr= dlopen_file_spec && dlopen_file_spec->length()? - dlopen_file_spec->cstr(String::UL_AS_IS):CharPtr(0); - if(const char* error=driver->initialize( - dlopen_file_spec_cstr)) + dlopen_file_spec->cstrm(String::L_AS_IS):0; + if(const char* error=driver->initialize(dlopen_file_spec_cstr)) throw Exception(0, library, "driver failed to initialize client library '%s', %s", - dlopen_file_spec_cstr?dlopen_file_spec_cstr.get():"unspecifed", + dlopen_file_spec_cstr?dlopen_file_spec_cstr:"unspecifed", error); // cache it - put_driver_to_cache(global_protocol, driver); + put_driver_to_cache(protocol, driver); } - connection=SQL_ConnectionPtr(new SQL_Connection(global_url, *driver)); + connection=new SQL_Connection(aurl, *driver); // associate with pool[request] (deassociates at close) - connection->set_pool(&apool); + connection->set_url(); } // if not connected yet, do that now, when connection has services if(!connection->connected()) - connection->connect(request_url_cstr); + connection->connect(url_cstr); // return autoclosing object for it - return SQL_ConnectionPtr(connection); + return connection; } void SQL_Driver_manager::close_connection(connection_cache_type::key_type url, - SQL_ConnectionPtr connection) { - // deassociate from pool[request] - connection->set_pool(0); + SQL_Connection* connection) { put_connection_to_cache(url, connection); } @@ -215,28 +207,28 @@ void SQL_Driver_manager::put_driver_to_c // connection cache /// @todo get rid of memory spending Stack [zeros deep inside got accumulated] -SQL_ConnectionPtr SQL_Driver_manager::get_connection_from_cache( +SQL_Connection* SQL_Driver_manager::get_connection_from_cache( connection_cache_type::key_type url) { SYNCHRONIZED; if(connection_cache_type::value_type connections=connection_cache.get(url)) while(connections->top_index()>=0) { // there are cached connections to that 'url' - SQL_ConnectionPtr result=connections->pop(); + SQL_Connection* result=connections->pop(); if(result->connected()) // not expired? return result; } - return SQL_ConnectionPtr(0); + return 0; } void SQL_Driver_manager::put_connection_to_cache( - connection_cache_type::key_type url, - SQL_ConnectionPtr connection) { + connection_cache_type::key_type url, + SQL_Connection* connection) { SYNCHRONIZED; connection_cache_type::value_type connections=connection_cache.get(url); if(!connections) { // there are no cached connections to that 'url' yet? - connections=connection_cache_type::value_type(new connection_cache_type::value_type::element_type); + connections=new connection_cache_element_base_type; connection_cache.put(url, connections); } connections->push(connection); @@ -253,11 +245,10 @@ void SQL_Driver_manager::maybe_expire_ca } /* static void add_connection_to_status_cache_table(Array::Item *value, void *info) { - SQL_Connection& connection=*static_cast(value); + SQL_Connection& connection=*static_cast(value); Table& table=*static_cast(info); if(connection.connected()) { - =table.pool(); Array& row=*new Array(); // url @@ -279,8 +270,8 @@ static void add_connections_to_status_ca add_connection_to_status_cache_table(iter.next(), info); }*/ /// @todo convert to object_ptr -ValuePtr SQL_Driver_manager::get_statusconst String* source) { - ValuePtr result(new VHash); +Value* SQL_Driver_manager::get_status() { + Value* result=new VHash; /* // cache {