summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/TransactionI.h
blob: 456e9f9b883242ce776e69ef723e4e1754b03794 (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-2012 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_TRANSACTIONI_H
#define FREEZE_TRANSACTIONI_H

#include <Ice/CommunicatorF.h>
#include <Freeze/Transaction.h>
#include <db_cxx.h>

namespace Freeze
{

class ConnectionI;
typedef IceUtil::Handle<ConnectionI> ConnectionIPtr;

struct SharedMutex;
typedef IceUtil::Handle<SharedMutex> SharedMutexPtr;

class SharedDbEnv;
typedef IceUtil::Handle<SharedDbEnv> SharedDbEnvPtr;

class PostCompletionCallback : public virtual IceUtil::Shared
{
public:

    virtual void postCompletion(bool, bool, const SharedDbEnvPtr&) = 0;
};
typedef IceUtil::Handle<PostCompletionCallback> PostCompletionCallbackPtr;

class TransactionI : public Transaction
{
public:

    virtual void commit();

    virtual void rollback();


    virtual ConnectionPtr getConnection() const;
    
    //
    // Custom refcounting implementation
    //
    virtual void __incRef();
    virtual void __decRef();
    virtual int __getRef() const;

    void rollbackInternal(bool);
    void setPostCompletionCallback(const PostCompletionCallbackPtr&);

    TransactionI(ConnectionI*);
    ~TransactionI();
    
    DbTxn*
    dbTxn() const
    {
        return _txn;
    }

private:

    friend class ConnectionI;
    
    int __getRefNoSync() const;
  
    void postCompletion(bool, bool);

    const Ice::CommunicatorPtr _communicator;
    ConnectionIPtr _connection;
    const Ice::Int _txTrace;
    const Ice::Int _warnRollback;
    DbTxn* _txn;
    PostCompletionCallbackPtr _postCompletionCallback;
    SharedMutexPtr _refCountMutex;
    int _refCount;
};

typedef IceUtil::Handle<TransactionI> TransactionIPtr;

}
#endif