--- parser3/src/main/Attic/pa_db_manager.C 2001/10/27 13:00:09 1.9 +++ parser3/src/main/Attic/pa_db_manager.C 2001/11/05 11:46:27 1.12 @@ -2,9 +2,9 @@ Parser: sql driver manager implementation. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_db_manager.C,v 1.9 2001/10/27 13:00:09 paf Exp $ + $Id: pa_db_manager.C,v 1.12 2001/11/05 11:46:27 paf Exp $ */ #include "pa_config_includes.h" @@ -15,6 +15,7 @@ #include "pa_exception.h" #include "pa_threads.h" #include "pa_stack.h" +#include "pa_vhash.h" // globals @@ -38,10 +39,11 @@ static void expire_connection(const Hash // DB_Manager -DB_Manager::DB_Manager(Pool& pool) : Pooled(pool), - connection_cache(pool), +DB_Manager::DB_Manager(Pool& apool) : Pooled(apool), + connection_cache(apool), prev_expiration_pass_time(0) { + status_providers->put(*NEW String(pool(), "db"), this); } DB_Manager::~DB_Manager() { @@ -62,7 +64,7 @@ DB_Connection_ptr DB_Manager::get_connec DB_Connection *result=get_connection_from_cache(request_db_home); if(!result) { // no cached connection // make global_db_home C-string on global pool - const char *request_db_home_cstr=request_db_home.cstr(String::UL_AS_IS); + const char *request_db_home_cstr=request_db_home.cstr(); char *global_db_home_cstr=(char *)malloc(strlen(request_db_home_cstr)+1); strcpy(global_db_home_cstr, request_db_home_cstr); // make global_db_home string on global pool @@ -107,4 +109,26 @@ void DB_Manager::maybe_expire_connection } } +static void add_connection_to_status_status_cache(const Hash::Key& key, Hash::Val *value, void *info) { + DB_Connection& connection=*static_cast(value); + VHash& status_cache=*static_cast(info); + Pool& pool=status_cache.pool(); + + // file => tables table + status_cache.hash(0).put(connection.db_home(), &connection.get_status(pool, 0)); +} +Value& DB_Manager::get_status(Pool& pool, const String *source) { + VHash& result=*new(pool) VHash(pool); + + // db_homes + { + VHash& status_cache=*new(pool) VHash(pool); + connection_cache.for_each(add_connection_to_status_status_cache, &status_cache); + + result.hash(source).put(*new(pool) String(pool, "cache"), &status_cache); + } + + return result; +} + #endif