Annotation of parser3/src/include/pa_db_connection.h, revision 1.9
1.1 parser 1: /** @file
1.9 ! paf 2: Parser: sql driver connection decl.
! 3: global sql driver connection, must be thread-safe
1.1 parser 4:
5: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7:
1.9 ! paf 8: $Id: pa_db_connection.h,v 1.2 2001/10/23 12:41:05 parser Exp $
1.1 parser 9: */
10:
11: #ifndef PA_DB_CONNECTION_H
12: #define PA_DB_CONNECTION_H
13:
14: #include "pa_config_includes.h"
15: #include "pa_pool.h"
1.9 ! paf 16: #include "pa_hash.h"
1.1 parser 17: #include "pa_db_manager.h"
18:
19: #ifdef HAVE_DB_H
20: # include <db.h>
21: #endif
22:
23: // defines
24:
1.2 parser 25: // forwards
26:
1.9 ! paf 27: class DB_Table;
1.1 parser 28:
1.9 ! paf 29: /// sql driver connection
1.1 parser 30: class DB_Connection : public Pooled {
1.9 ! paf 31: friend DB_Table;
1.1 parser 32: public:
33:
1.9 ! paf 34: DB_Connection(Pool& pool, const String& db_home);
1.1 parser 35:
36: void set_services(Pool *aservices_pool) {
37: time_used=time(0); // they started to use at this time
38: fservices_pool=aservices_pool;
39: }
40: bool expired(time_t older_dies) {
41: return time_used<older_dies;
42: }
43:
44: void close() {
1.9 ! paf 45: DB_manager->close_connection(fdb_home, *this);
1.1 parser 46: }
1.9 ! paf 47: bool connected() { return fconnected; }
1.1 parser 48: void connect();
1.2 parser 49: void disconnect();
1.9 ! paf 50: bool ping() { return errors==0; }
1.1 parser 51:
1.9 ! paf 52: /**
! 53: connect to specified file_name,
! 54: using driver dynamic library found in table, if not loaded yet
! 55: checks driver version
! 56: */
! 57: DB_Table& get_table(const String& file_name, const String& request_origin);
! 58: void clear_dbfile(const String& file_name);
! 59:
! 60: private: // table cache
! 61:
! 62: DB_Table *get_table_from_cache(const String& file_name);
! 63: void put_table_to_cache(const String& file_name, DB_Table& table);
! 64: void maybe_expire_table_cache();
1.1 parser 65: private:
1.9 ! paf 66: time_t prev_expiration_pass_time;
1.1 parser 67:
1.9 ! paf 68: private: // for DB_Table
1.1 parser 69:
1.9 ! paf 70: /// caches table
! 71: void close_table(const String& file_name, DB_Table& table);
1.2 parser 72:
1.9 ! paf 73: private:
1.2 parser 74:
1.9 ! paf 75: time_t time_used;
! 76: Pool *fservices_pool;
1.2 parser 77:
1.9 ! paf 78: const String& fdb_home;
! 79: bool fconnected;
! 80: DB_ENV dbenv;
! 81: int errors;
! 82: Hash table_cache;
1.2 parser 83:
1.1 parser 84: private:
85:
86: void check(const char *operation, const String *source, int error);
87: };
88:
89: #endif
E-mail: