summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/SharedDb.h
blob: 9aa2b9a776e25c37b5136965fbd1fc02dee98cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// **********************************************************************
//
// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef FREEZE_SHARED_DB_H
#define FREEZE_SHARED_DB_H

#include <IceUtil/Config.h>
#include <db_cxx.h>
#include <Freeze/ConnectionI.h>
#include <IceUtil/Handle.h>
#include <map>

namespace Freeze
{

class SharedDb;
typedef IceUtil::Handle<SharedDb> SharedDbPtr;

class SharedDb : public ::Db
{
public:
    
    using Db::get;

    static SharedDbPtr get(const ConnectionIPtr&, const std::string&, bool);

    ~SharedDb();

    void __incRef();
    void __decRef();

    const std::string& 
    dbName() const;

#ifdef __HP_aCC
    
    virtual int 
    get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags)
    {
	::Db::get(txnid, key, data, flags);
    }
#endif

private:

    struct MapKey
    {
	std::string envName;
	Ice::CommunicatorPtr communicator;
	std::string dbName;

	inline bool
	operator<(const MapKey& rhs) const;
    };

    typedef std::map<MapKey, Freeze::SharedDb*> Map;
   
    SharedDb(const MapKey&, const ConnectionIPtr&, bool);
    
    MapKey _key;
    int _refCount;
    Ice::Int _trace;

    static Map* sharedDbMap;
};

inline const std::string& 
SharedDb::dbName() const
{
    return _key.dbName;
}

inline bool 
SharedDb::MapKey::operator<(const MapKey& rhs) const
{
    return (communicator < rhs.communicator) ||
	((communicator == rhs.communicator) && (dbName < rhs.dbName)) ||
	((communicator == rhs.communicator) && (dbName == rhs.dbName) && (envName < rhs.envName));
}
    
}
#endif