~ubuntu-branches/ubuntu/precise/gnat-gps/precise

« back to all changes in this revision

Viewing changes to kernel/src_info/sn/snsrc/db-2.7.7/cxx/cxx_txn.cpp

  • Committer: Package Import Robot
  • Author(s): Ludovic Brenta
  • Date: 2012-01-15 15:42:21 UTC
  • mfrom: (10.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120115154221-ccysuzvh02pkhuwq
Tags: 5.0-6
Rebuild against libgtkada 2.24.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1997, 1998
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
 
8
 
#include "config.h"
9
 
 
10
 
#ifndef lint
11
 
static const char sccsid[] = "@(#)cxx_txn.cpp   10.8 (Sleepycat) 4/10/98";
12
 
#endif /* not lint */
13
 
 
14
 
#include "db_cxx.h"
15
 
#include "cxx_int.h"
16
 
#include <errno.h>
17
 
 
18
 
////////////////////////////////////////////////////////////////////////
19
 
//                                                                    //
20
 
//                            DbTxnMgr                                //
21
 
//                                                                    //
22
 
////////////////////////////////////////////////////////////////////////
23
 
 
24
 
DbTxnMgr::DbTxnMgr()
25
 
:   imp_(0)
26
 
{
27
 
}
28
 
 
29
 
DbTxnMgr::~DbTxnMgr()
30
 
{
31
 
}
32
 
 
33
 
int DbTxnMgr::begin(DbTxn *pid, DbTxn **tid)
34
 
{
35
 
    int err;
36
 
    DB_TXNMGR *mgr = unwrap(this);
37
 
    DB_TXN *txn;
38
 
 
39
 
    if ((err = txn_begin(mgr, unwrap(pid), &txn)) != 0) {
40
 
        DB_ERROR("DbTxn::begin", err);
41
 
        return err;
42
 
    }
43
 
    DbTxn *result = new DbTxn();
44
 
    result->imp_ = wrap(txn);
45
 
    *tid = result;
46
 
    return err;
47
 
}
48
 
 
49
 
int DbTxnMgr::checkpoint(u_int32_t kbyte, u_int32_t min) const
50
 
{
51
 
    int err;
52
 
    const DB_TXNMGR *mgr = unwrapConst(this);
53
 
    if ((err = txn_checkpoint(mgr, kbyte, min)) != 0) {
54
 
        DB_ERROR("DbTxnMgr::checkpoint", err);
55
 
        return err;
56
 
    }
57
 
    return 0;
58
 
}
59
 
 
60
 
int DbTxnMgr::close()
61
 
{
62
 
    int err;
63
 
    DB_TXNMGR *mgr = unwrap(this);
64
 
    if ((err = txn_close(mgr)) != 0) {
65
 
        DB_ERROR("DbTxnMgr::close", err);
66
 
        return err;
67
 
    }
68
 
    imp_ = 0;                   // extra safety
69
 
 
70
 
    // This may seem weird, but is legal as long as we don't access
71
 
    // any data before returning.
72
 
    //
73
 
    delete this;
74
 
    return 0;
75
 
}
76
 
 
77
 
// static method
78
 
int DbTxnMgr::open(const char *dir, u_int32_t flags, int mode,
79
 
                  DbEnv *dbenv, DbTxnMgr **regionp)
80
 
{
81
 
    *regionp = 0;
82
 
    DB_TXNMGR *result = 0;
83
 
    int err;
84
 
    if ((err = txn_open(dir, flags, mode, dbenv, &result)) != 0) {
85
 
        DB_ERROR("DbTxnMgr::open", err);
86
 
        return err;
87
 
    }
88
 
 
89
 
    *regionp = new DbTxnMgr();
90
 
    (*regionp)->imp_ = wrap(result);
91
 
    return 0;
92
 
}
93
 
 
94
 
int DbTxnMgr::stat(DB_TXN_STAT **statp, void *(*db_malloc)(size_t))
95
 
{
96
 
    int err;
97
 
    DB_TXNMGR *mgr = unwrap(this);
98
 
    if ((err = txn_stat(mgr, statp, db_malloc)) != 0) {
99
 
        DB_ERROR("DbTxnMgr::stat", err);
100
 
        return err;
101
 
    }
102
 
    return 0;
103
 
}
104
 
 
105
 
// static method
106
 
int DbTxnMgr::unlink(const char *dir, int force, DbEnv *dbenv)
107
 
{
108
 
    int err;
109
 
    if ((err = txn_unlink(dir, force, dbenv)) != 0) {
110
 
        DB_ERROR("DbTxnMgr::unlink", err);
111
 
        return err;
112
 
    }
113
 
    return err;
114
 
}
115
 
 
116
 
////////////////////////////////////////////////////////////////////////
117
 
//                                                                    //
118
 
//                            DbTxn                                   //
119
 
//                                                                    //
120
 
////////////////////////////////////////////////////////////////////////
121
 
 
122
 
DbTxn::DbTxn()
123
 
:  imp_(0)
124
 
{
125
 
}
126
 
 
127
 
DbTxn::~DbTxn()
128
 
{
129
 
}
130
 
 
131
 
int DbTxn::abort()
132
 
{
133
 
    int err;
134
 
    DB_TXN *txn = unwrap(this);
135
 
    if ((err = txn_abort(txn)) != 0) {
136
 
        DB_ERROR("DbTxn::abort", err);
137
 
        return err;
138
 
    }
139
 
 
140
 
    // This may seem weird, but is legal as long as we don't access
141
 
    // any data before returning.
142
 
    //
143
 
    delete this;
144
 
    return 0;
145
 
}
146
 
 
147
 
int DbTxn::commit()
148
 
{
149
 
    int err;
150
 
    DB_TXN *txn = unwrap(this);
151
 
    if ((err = txn_commit(txn)) != 0) {
152
 
        DB_ERROR("DbTxn::commit", err);
153
 
        return err;
154
 
    }
155
 
 
156
 
    // This may seem weird, but is legal as long as we don't access
157
 
    // any data before returning.
158
 
    //
159
 
    delete this;
160
 
    return 0;
161
 
}
162
 
 
163
 
u_int32_t DbTxn::id()
164
 
{
165
 
    DB_TXN *txn = unwrap(this);
166
 
    return txn_id(txn);         // no error
167
 
}
168
 
 
169
 
int DbTxn::prepare()
170
 
{
171
 
    int err;
172
 
    DB_TXN *txn = unwrap(this);
173
 
    if ((err = txn_prepare(txn)) != 0) {
174
 
        DB_ERROR("DbTxn::prepare", err);
175
 
        return err;
176
 
    }
177
 
    return 0;
178
 
}