Annotation of parser3/src/include/pa_db_connection.h, revision 1.1

1.1     ! parser      1: /** @file
        !             2:        Parser: sql db decl.
        !             3: 
        !             4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             5:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
        !             6: 
        !             7:        $Id: pa_DB_connection.h,v 1.13 2001/09/26 10:32:25 parser Exp $
        !             8: */
        !             9: 
        !            10: #ifndef PA_DB_CONNECTION_H
        !            11: #define PA_DB_CONNECTION_H
        !            12: 
        !            13: #include "pa_config_includes.h"
        !            14: #include "pa_pool.h"
        !            15: #include "pa_db_manager.h"
        !            16: #include "pa_globals.h"
        !            17: 
        !            18: #ifdef HAVE_DB_H
        !            19: #      include <db.h>
        !            20: #endif
        !            21: 
        !            22: // defines
        !            23: 
        !            24: #define PA_DB_ACCESS_METHOD DB_BTREE
        !            25: 
        !            26: // class
        !            27: 
        !            28: /// DB connection. handy wrapper around low level DB_Driver
        !            29: class DB_Connection : public Pooled {
        !            30: 
        !            31: public:
        !            32: 
        !            33:        DB_Connection(Pool& pool, const String& afile_spec, DB_ENV& adbenv);
        !            34:        
        !            35:        //const String& url() { return ffile_spec; }
        !            36: 
        !            37:        void set_services(Pool *aservices_pool) {
        !            38:                time_used=time(0); // they started to use at this time
        !            39:                fservices_pool=aservices_pool;
        !            40:        }
        !            41:        bool expired(time_t older_dies) {
        !            42:                return time_used<older_dies;
        !            43:        }
        !            44: 
        !            45:        void close() {
        !            46:                DB_manager->close_connection(ffile_spec, *this);
        !            47:        }
        !            48: 
        !            49:        bool connected() { return db!=0; }
        !            50:        void connect();
        !            51: 
        !            52:        /// @todo this one of reasons of not having ^try for now
        !            53:        void DB_Connection::disconnect() { 
        !            54:                check("close", &ffile_spec, db->close(db, 0/*flags*/));  db=0; 
        !            55:        }
        !            56:        
        !            57:        void commit() { 
        !            58:                if(tid) {
        !            59:                        check("txn_commit", &ffile_spec, txn_commit(tid)); tid=0;
        !            60:                }
        !            61:        }
        !            62:        
        !            63:        void rollback() {
        !            64:                if(tid) {
        !            65:                        check("txn_abort", &ffile_spec, txn_abort(tid)); tid=0;
        !            66:                }
        !            67:        }
        !            68:        
        !            69:        void txn_begin() {
        !            70:                check("txn_begin", &ffile_spec, ::txn_begin(fdbenv.tx_info, 0/*parent*/, &tid));
        !            71:        }
        !            72:        
        !            73:        bool ping() { return !needs_recovery; }
        !            74: 
        !            75:        void put(const String& key, const String& data);
        !            76:        String *get(const String& key);
        !            77: 
        !            78: private:
        !            79: 
        !            80:        DB_ENV& fdbenv;
        !            81:        const String& ffile_spec;
        !            82:        Pool *fservices_pool;
        !            83:        DB *db;
        !            84:        bool needs_recovery;
        !            85:        DB_TXN *tid;
        !            86:        time_t time_used;
        !            87: 
        !            88: private:
        !            89: 
        !            90:        void check(const char *operation, const String *source, int error);
        !            91:        void *malloc(size_t size) { return fservices_pool->malloc(size); }
        !            92:        void *calloc(size_t size) { return fservices_pool->calloc(size); }
        !            93:        
        !            94: };
        !            95: 
        !            96: #endif

E-mail: