1/* DO NOT EDIT: automatically built by dist/s_windows. */ 2/*- 3 * See the file LICENSE for redistribution information. 4 * 5 * Copyright (c) 1997-2009 Oracle. All rights reserved. 6 * 7 * $Id$ 8 */ 9 10#ifndef _DB_CXX_H_ 11#define _DB_CXX_H_ 12// 13// C++ assumptions: 14// 15// To ensure portability to many platforms, both new and old, we make 16// few assumptions about the C++ compiler and library. For example, 17// we do not expect STL, templates or namespaces to be available. The 18// "newest" C++ feature used is exceptions, which are used liberally 19// to transmit error information. Even the use of exceptions can be 20// disabled at runtime, to do so, use the DB_CXX_NO_EXCEPTIONS flags 21// with the DbEnv or Db constructor. 22// 23// C++ naming conventions: 24// 25// - All top level class names start with Db. 26// - All class members start with lower case letter. 27// - All private data members are suffixed with underscore. 28// - Use underscores to divide names into multiple words. 29// - Simple data accessors are named with get_ or set_ prefix. 30// - All method names are taken from names of functions in the C 31// layer of db (usually by dropping a prefix like "db_"). 32// These methods have the same argument types and order, 33// other than dropping the explicit arg that acts as "this". 34// 35// As a rule, each DbFoo object has exactly one underlying DB_FOO struct 36// (defined in db.h) associated with it. In some cases, we inherit directly 37// from the DB_FOO structure to make this relationship explicit. Often, 38// the underlying C layer allocates and deallocates these structures, so 39// there is no easy way to add any data to the DbFoo class. When you see 40// a comment about whether data is permitted to be added, this is what 41// is going on. Of course, if we need to add data to such C++ classes 42// in the future, we will arrange to have an indirect pointer to the 43// DB_FOO struct (as some of the classes already have). 44// 45 46//////////////////////////////////////////////////////////////// 47//////////////////////////////////////////////////////////////// 48// 49// Forward declarations 50// 51 52#include <stdarg.h> 53 54#define HAVE_CXX_STDHEADERS 1 55#ifdef HAVE_CXX_STDHEADERS 56#include <iostream> 57#include <exception> 58#define __DB_STD(x) std::x 59#else 60#include <iostream.h> 61#include <exception.h> 62#define __DB_STD(x) x 63#endif 64 65#include "db.h" 66 67class Db; // forward 68class Dbc; // forward 69class DbEnv; // forward 70class DbInfo; // forward 71class DbLock; // forward 72class DbLogc; // forward 73class DbLsn; // forward 74class DbMpoolFile; // forward 75class DbPreplist; // forward 76class DbSequence; // forward 77class Dbt; // forward 78class DbTxn; // forward 79 80class DbMultipleIterator; // forward 81class DbMultipleKeyDataIterator; // forward 82class DbMultipleRecnoDataIterator; // forward 83class DbMultipleDataIterator; // forward 84 85class DbException; // forward 86class DbDeadlockException; // forward 87class DbLockNotGrantedException; // forward 88class DbMemoryException; // forward 89class DbRepHandleDeadException; // forward 90class DbRunRecoveryException; // forward 91 92//////////////////////////////////////////////////////////////// 93//////////////////////////////////////////////////////////////// 94// 95// Turn off inappropriate compiler warnings 96// 97 98#ifdef _MSC_VER 99 100// These are level 4 warnings that are explicitly disabled. 101// With Visual C++, by default you do not see above level 3 unless 102// you use /W4. But we like to compile with the highest level 103// warnings to catch other errors. 104// 105// 4201: nameless struct/union 106// triggered by standard include file <winnt.h> 107// 108// 4514: unreferenced inline function has been removed 109// certain include files in MSVC define methods that are not called 110// 111#pragma warning(push) 112#pragma warning(disable: 4201 4514) 113 114#endif 115 116//////////////////////////////////////////////////////////////// 117//////////////////////////////////////////////////////////////// 118// 119// Mechanisms for declaring classes 120// 121 122// 123// Every class defined in this file has an _exported next to the class name. 124// This is needed for WinTel machines so that the class methods can 125// be exported or imported in a DLL as appropriate. Users of the DLL 126// use the define DB_USE_DLL. When the DLL is built, DB_CREATE_DLL 127// must be defined. 128// 129#if defined(_MSC_VER) 130 131# if defined(DB_CREATE_DLL) 132# define _exported __declspec(dllexport) // creator of dll 133# elif defined(DB_USE_DLL) 134# define _exported __declspec(dllimport) // user of dll 135# else 136# define _exported // static lib creator or user 137# endif 138 139#else /* _MSC_VER */ 140 141# define _exported 142 143#endif /* _MSC_VER */ 144 145// Some interfaces can be customized by allowing users to define 146// callback functions. For performance and logistical reasons, some 147// callback functions must be declared in extern "C" blocks. For others, 148// we allow you to declare the callbacks in C++ or C (or an extern "C" 149// block) as you wish. See the set methods for the callbacks for 150// the choices. 151// 152extern "C" { 153 typedef void * (*db_malloc_fcn_type) 154 (size_t); 155 typedef void * (*db_realloc_fcn_type) 156 (void *, size_t); 157 typedef void (*db_free_fcn_type) 158 (void *); 159 typedef int (*bt_compare_fcn_type) /*C++ version available*/ 160 (DB *, const DBT *, const DBT *); 161 typedef size_t (*bt_prefix_fcn_type) /*C++ version available*/ 162 (DB *, const DBT *, const DBT *); 163 typedef int (*dup_compare_fcn_type) /*C++ version available*/ 164 (DB *, const DBT *, const DBT *); 165 typedef int (*h_compare_fcn_type) /*C++ version available*/ 166 (DB *, const DBT *, const DBT *); 167 typedef u_int32_t (*h_hash_fcn_type) /*C++ version available*/ 168 (DB *, const void *, u_int32_t); 169 typedef int (*pgin_fcn_type) 170 (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie); 171 typedef int (*pgout_fcn_type) 172 (DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie); 173} 174 175// 176// Represents a database table = a set of keys with associated values. 177// 178class _exported Db 179{ 180 friend class DbEnv; 181 182public: 183 Db(DbEnv*, u_int32_t); // Create a Db object. 184 virtual ~Db(); // Calls close() if the user hasn't. 185 186 // These methods exactly match those in the C interface. 187 // 188 virtual int associate(DbTxn *txn, Db *secondary, int (*callback) 189 (Db *, const Dbt *, const Dbt *, Dbt *), u_int32_t flags); 190 virtual int associate_foreign(Db *foreign, int (*callback) 191 (Db *, const Dbt *, Dbt *, const Dbt *, int *), u_int32_t flags); 192 virtual int close(u_int32_t flags); 193 virtual int compact(DbTxn *txnid, Dbt *start, 194 Dbt *stop, DB_COMPACT *c_data, u_int32_t flags, Dbt *end); 195 virtual int cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags); 196 virtual int del(DbTxn *txnid, Dbt *key, u_int32_t flags); 197 virtual void err(int, const char *, ...); 198 virtual void errx(const char *, ...); 199 virtual int exists(DbTxn *txnid, Dbt *key, u_int32_t flags); 200 virtual int fd(int *fdp); 201 virtual int get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags); 202 virtual int get_alloc( 203 db_malloc_fcn_type *, db_realloc_fcn_type *, db_free_fcn_type *); 204 virtual int get_append_recno(int (**)(Db *, Dbt *, db_recno_t)); 205 virtual int get_bt_compare(int (**)(Db *, const Dbt *, const Dbt *)); 206 virtual int get_bt_compress( 207 int (**)( 208 Db *, const Dbt *, const Dbt *, const Dbt *, const Dbt *, Dbt *), 209 int (**)(Db *, const Dbt *, const Dbt *, Dbt *, Dbt *, Dbt *)); 210 virtual int get_bt_minkey(u_int32_t *); 211 virtual int get_bt_prefix(size_t (**)(Db *, const Dbt *, const Dbt *)); 212 virtual int get_byteswapped(int *); 213 virtual int get_cachesize(u_int32_t *, u_int32_t *, int *); 214 virtual int get_create_dir(const char **); 215 virtual int get_dbname(const char **, const char **); 216 virtual int get_dup_compare(int (**)(Db *, const Dbt *, const Dbt *)); 217 virtual int get_encrypt_flags(u_int32_t *); 218 virtual void get_errcall( 219 void (**)(const DbEnv *, const char *, const char *)); 220 virtual void get_errfile(FILE **); 221 virtual void get_errpfx(const char **); 222 virtual int get_feedback(void (**)(Db *, int, int)); 223 virtual int get_flags(u_int32_t *); 224 virtual int get_h_compare(int (**)(Db *, const Dbt *, const Dbt *)); 225 virtual int get_h_ffactor(u_int32_t *); 226 virtual int get_h_hash(u_int32_t (**)(Db *, const void *, u_int32_t)); 227 virtual int get_h_nelem(u_int32_t *); 228 virtual int get_lorder(int *); 229 virtual void get_msgcall(void (**)(const DbEnv *, const char *)); 230 virtual void get_msgfile(FILE **); 231 virtual int get_multiple(); 232 virtual int get_open_flags(u_int32_t *); 233 virtual int get_pagesize(u_int32_t *); 234 virtual int get_partition_callback( 235 u_int32_t *, u_int32_t (**)(Db *, Dbt *key)); 236 virtual int get_partition_dirs(const char ***); 237 virtual int get_partition_keys(u_int32_t *, Dbt **); 238 virtual int get_priority(DB_CACHE_PRIORITY *); 239 virtual int get_q_extentsize(u_int32_t *); 240 virtual int get_re_delim(int *); 241 virtual int get_re_len(u_int32_t *); 242 virtual int get_re_pad(int *); 243 virtual int get_re_source(const char **); 244 virtual int get_transactional(); 245 virtual int get_type(DBTYPE *); 246 virtual int join(Dbc **curslist, Dbc **dbcp, u_int32_t flags); 247 virtual int key_range(DbTxn *, Dbt *, DB_KEY_RANGE *, u_int32_t); 248 virtual int open(DbTxn *txnid, 249 const char *, const char *subname, DBTYPE, u_int32_t, int); 250 virtual int pget(DbTxn *txnid, 251 Dbt *key, Dbt *pkey, Dbt *data, u_int32_t flags); 252 virtual int put(DbTxn *, Dbt *, Dbt *, u_int32_t); 253 virtual int remove(const char *, const char *, u_int32_t); 254 virtual int rename(const char *, const char *, const char *, u_int32_t); 255 virtual int set_alloc( 256 db_malloc_fcn_type, db_realloc_fcn_type, db_free_fcn_type); 257 virtual void set_app_private(void *); 258 virtual int set_append_recno(int (*)(Db *, Dbt *, db_recno_t)); 259 virtual int set_bt_compare(bt_compare_fcn_type); /*deprecated*/ 260 virtual int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *)); 261 virtual int set_bt_compress( 262 int (*) 263 (Db *, const Dbt *, const Dbt *, const Dbt *, const Dbt *, Dbt *), 264 int (*)(Db *, const Dbt *, const Dbt *, Dbt *, Dbt *, Dbt *)); 265 virtual int set_bt_minkey(u_int32_t); 266 virtual int set_bt_prefix(bt_prefix_fcn_type); /*deprecated*/ 267 virtual int set_bt_prefix(size_t (*)(Db *, const Dbt *, const Dbt *)); 268 virtual int set_cachesize(u_int32_t, u_int32_t, int); 269 virtual int set_create_dir(const char *); 270 virtual int set_dup_compare(dup_compare_fcn_type); /*deprecated*/ 271 virtual int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *)); 272 virtual int set_encrypt(const char *, u_int32_t); 273 virtual void set_errcall( 274 void (*)(const DbEnv *, const char *, const char *)); 275 virtual void set_errfile(FILE *); 276 virtual void set_errpfx(const char *); 277 virtual int set_feedback(void (*)(Db *, int, int)); 278 virtual int set_flags(u_int32_t); 279 virtual int set_h_compare(h_compare_fcn_type); /*deprecated*/ 280 virtual int set_h_compare(int (*)(Db *, const Dbt *, const Dbt *)); 281 virtual int set_h_ffactor(u_int32_t); 282 virtual int set_h_hash(h_hash_fcn_type); /*deprecated*/ 283 virtual int set_h_hash(u_int32_t (*)(Db *, const void *, u_int32_t)); 284 virtual int set_h_nelem(u_int32_t); 285 virtual int set_lorder(int); 286 virtual void set_msgcall(void (*)(const DbEnv *, const char *)); 287 virtual void set_msgfile(FILE *); 288 virtual int set_pagesize(u_int32_t); 289 virtual int set_paniccall(void (*)(DbEnv *, int)); 290 virtual int set_partition( 291 u_int32_t, Dbt *, u_int32_t (*)(Db *, Dbt *)); 292 virtual int set_partition_dirs(const char **); 293 virtual int set_priority(DB_CACHE_PRIORITY); 294 virtual int set_q_extentsize(u_int32_t); 295 virtual int set_re_delim(int); 296 virtual int set_re_len(u_int32_t); 297 virtual int set_re_pad(int); 298 virtual int set_re_source(const char *); 299 virtual int sort_multiple(Dbt *, Dbt *, u_int32_t); 300 virtual int stat(DbTxn *, void *sp, u_int32_t flags); 301 virtual int stat_print(u_int32_t flags); 302 virtual int sync(u_int32_t flags); 303 virtual int truncate(DbTxn *, u_int32_t *, u_int32_t); 304 virtual int upgrade(const char *name, u_int32_t flags); 305 virtual int verify( 306 const char *, const char *, __DB_STD(ostream) *, u_int32_t); 307 308 // These additional methods are not in the C interface, and 309 // are only available for C++. 310 // 311 virtual void *get_app_private() const; 312 virtual __DB_STD(ostream) *get_error_stream(); 313 virtual void set_error_stream(__DB_STD(ostream) *); 314 virtual __DB_STD(ostream) *get_message_stream(); 315 virtual void set_message_stream(__DB_STD(ostream) *); 316 317 virtual DbEnv *get_env(); 318 virtual DbMpoolFile *get_mpf(); 319 320 virtual ENV *get_ENV() 321 { 322 return imp_->env; 323 } 324 325 virtual DB *get_DB() 326 { 327 return imp_; 328 } 329 330 virtual const DB *get_const_DB() const 331 { 332 return imp_; 333 } 334 335 static Db* get_Db(DB *db) 336 { 337 return (Db *)db->api_internal; 338 } 339 340 static const Db* get_const_Db(const DB *db) 341 { 342 return (const Db *)db->api_internal; 343 } 344 345 u_int32_t get_create_flags() const 346 { 347 return construct_flags_; 348 } 349 350private: 351 // no copying 352 Db(const Db &); 353 Db &operator = (const Db &); 354 355 void cleanup(); 356 int initialize(); 357 int error_policy(); 358 359 // instance data 360 DB *imp_; 361 DbEnv *dbenv_; 362 DbMpoolFile *mpf_; 363 int construct_error_; 364 u_int32_t flags_; 365 u_int32_t construct_flags_; 366 367public: 368 // These are public only because they need to be called 369 // via C callback functions. They should never be used by 370 // external users of this class. 371 // 372 int (*append_recno_callback_)(Db *, Dbt *, db_recno_t); 373 int (*associate_callback_)(Db *, const Dbt *, const Dbt *, Dbt *); 374 int (*associate_foreign_callback_) 375 (Db *, const Dbt *, Dbt *, const Dbt *, int *); 376 int (*bt_compare_callback_)(Db *, const Dbt *, const Dbt *); 377 int (*bt_compress_callback_)( 378 Db *, const Dbt *, const Dbt *, const Dbt *, const Dbt *, Dbt *); 379 int (*bt_decompress_callback_)( 380 Db *, const Dbt *, const Dbt *, Dbt *, Dbt *, Dbt *); 381 size_t (*bt_prefix_callback_)(Db *, const Dbt *, const Dbt *); 382 u_int32_t (*db_partition_callback_)(Db *, Dbt *); 383 int (*dup_compare_callback_)(Db *, const Dbt *, const Dbt *); 384 void (*feedback_callback_)(Db *, int, int); 385 int (*h_compare_callback_)(Db *, const Dbt *, const Dbt *); 386 u_int32_t (*h_hash_callback_)(Db *, const void *, u_int32_t); 387}; 388 389// 390// Cursor 391// 392class _exported Dbc : protected DBC 393{ 394 friend class Db; 395 396public: 397 int close(); 398 int cmp(Dbc *other_csr, int *result, u_int32_t flags); 399 int count(db_recno_t *countp, u_int32_t flags); 400 int del(u_int32_t flags); 401 int dup(Dbc** cursorp, u_int32_t flags); 402 int get(Dbt* key, Dbt *data, u_int32_t flags); 403 int get_priority(DB_CACHE_PRIORITY *priorityp); 404 int pget(Dbt* key, Dbt* pkey, Dbt *data, u_int32_t flags); 405 int put(Dbt* key, Dbt *data, u_int32_t flags); 406 int set_priority(DB_CACHE_PRIORITY priority); 407 408private: 409 // No data is permitted in this class (see comment at top) 410 411 // Note: use Db::cursor() to get pointers to a Dbc, 412 // and call Dbc::close() rather than delete to release them. 413 // 414 Dbc(); 415 ~Dbc(); 416 417 // no copying 418 Dbc(const Dbc &); 419 Dbc &operator = (const Dbc &); 420}; 421 422// 423// Berkeley DB environment class. Provides functions for opening databases. 424// User of this library can use this class as a starting point for 425// developing a DB application - derive their application class from 426// this one, add application control logic. 427// 428// Note that if you use the default constructor, you must explicitly 429// call appinit() before any other db activity (e.g. opening files) 430// 431class _exported DbEnv 432{ 433 friend class Db; 434 friend class DbLock; 435 friend class DbMpoolFile; 436 437public: 438 // After using this constructor, you can set any needed 439 // parameters for the environment using the set_* methods. 440 // Then call open() to finish initializing the environment 441 // and attaching it to underlying files. 442 // 443 DbEnv(u_int32_t flags); 444 445 virtual ~DbEnv(); 446 447 // These methods match those in the C interface. 448 // 449 virtual int add_data_dir(const char *); 450 virtual int cdsgroup_begin(DbTxn **tid); 451 virtual int close(u_int32_t); 452 virtual int dbremove(DbTxn *txn, const char *name, const char *subdb, 453 u_int32_t flags); 454 virtual int dbrename(DbTxn *txn, const char *name, const char *subdb, 455 const char *newname, u_int32_t flags); 456 virtual void err(int, const char *, ...); 457 virtual void errx(const char *, ...); 458 virtual int failchk(u_int32_t); 459 virtual int fileid_reset(const char *, u_int32_t); 460 virtual int get_alloc(db_malloc_fcn_type *, db_realloc_fcn_type *, 461 db_free_fcn_type *); 462 virtual void *get_app_private() const; 463 virtual int get_home(const char **); 464 virtual int get_open_flags(u_int32_t *); 465 virtual int open(const char *, u_int32_t, int); 466 virtual int remove(const char *, u_int32_t); 467 virtual int stat_print(u_int32_t flags); 468 469 virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type, 470 db_free_fcn_type); 471 virtual void set_app_private(void *); 472 virtual int get_cachesize(u_int32_t *, u_int32_t *, int *); 473 virtual int set_cachesize(u_int32_t, u_int32_t, int); 474 virtual int get_cache_max(u_int32_t *, u_int32_t *); 475 virtual int set_cache_max(u_int32_t, u_int32_t); 476 virtual int get_create_dir(const char **); 477 virtual int set_create_dir(const char *); 478 virtual int get_data_dirs(const char ***); 479 virtual int set_data_dir(const char *); 480 virtual int get_encrypt_flags(u_int32_t *); 481 virtual int get_intermediate_dir_mode(const char **); 482 virtual int set_intermediate_dir_mode(const char *); 483 virtual int get_isalive( 484 int (**)(DbEnv *, pid_t, db_threadid_t, u_int32_t)); 485 virtual int set_isalive( 486 int (*)(DbEnv *, pid_t, db_threadid_t, u_int32_t)); 487 virtual int set_encrypt(const char *, u_int32_t); 488 virtual void get_errcall( 489 void (**)(const DbEnv *, const char *, const char *)); 490 virtual void set_errcall( 491 void (*)(const DbEnv *, const char *, const char *)); 492 virtual void get_errfile(FILE **); 493 virtual void set_errfile(FILE *); 494 virtual void get_errpfx(const char **); 495 virtual void set_errpfx(const char *); 496 virtual int set_event_notify(void (*)(DbEnv *, u_int32_t, void *)); 497 virtual int get_flags(u_int32_t *); 498 virtual int set_flags(u_int32_t, int); 499 virtual bool is_bigendian(); 500 virtual int lsn_reset(const char *, u_int32_t); 501 virtual int get_feedback(void (**)(DbEnv *, int, int)); 502 virtual int set_feedback(void (*)(DbEnv *, int, int)); 503 virtual int get_lg_bsize(u_int32_t *); 504 virtual int set_lg_bsize(u_int32_t); 505 virtual int get_lg_dir(const char **); 506 virtual int set_lg_dir(const char *); 507 virtual int get_lg_filemode(int *); 508 virtual int set_lg_filemode(int); 509 virtual int get_lg_max(u_int32_t *); 510 virtual int set_lg_max(u_int32_t); 511 virtual int get_lg_regionmax(u_int32_t *); 512 virtual int set_lg_regionmax(u_int32_t); 513 virtual int get_lk_conflicts(const u_int8_t **, int *); 514 virtual int set_lk_conflicts(u_int8_t *, int); 515 virtual int get_lk_detect(u_int32_t *); 516 virtual int set_lk_detect(u_int32_t); 517 virtual int get_lk_max_lockers(u_int32_t *); 518 virtual int set_lk_max_lockers(u_int32_t); 519 virtual int get_lk_max_locks(u_int32_t *); 520 virtual int set_lk_max_locks(u_int32_t); 521 virtual int get_lk_max_objects(u_int32_t *); 522 virtual int set_lk_max_objects(u_int32_t); 523 virtual int get_lk_partitions(u_int32_t *); 524 virtual int set_lk_partitions(u_int32_t); 525 virtual int get_mp_mmapsize(size_t *); 526 virtual int set_mp_mmapsize(size_t); 527 virtual int get_mp_max_openfd(int *); 528 virtual int set_mp_max_openfd(int); 529 virtual int get_mp_max_write(int *, db_timeout_t *); 530 virtual int set_mp_max_write(int, db_timeout_t); 531 virtual int get_mp_pagesize(u_int32_t *); 532 virtual int set_mp_pagesize(u_int32_t); 533 virtual int get_mp_tablesize(u_int32_t *); 534 virtual int set_mp_tablesize(u_int32_t); 535 virtual void get_msgcall(void (**)(const DbEnv *, const char *)); 536 virtual void set_msgcall(void (*)(const DbEnv *, const char *)); 537 virtual void get_msgfile(FILE **); 538 virtual void set_msgfile(FILE *); 539 virtual int set_paniccall(void (*)(DbEnv *, int)); 540 virtual int set_rpc_server(void *, char *, long, long, u_int32_t); 541 virtual int get_shm_key(long *); 542 virtual int set_shm_key(long); 543 virtual int get_timeout(db_timeout_t *, u_int32_t); 544 virtual int set_timeout(db_timeout_t, u_int32_t); 545 virtual int get_tmp_dir(const char **); 546 virtual int set_tmp_dir(const char *); 547 virtual int get_tx_max(u_int32_t *); 548 virtual int set_tx_max(u_int32_t); 549 virtual int get_app_dispatch( 550 int (**)(DbEnv *, Dbt *, DbLsn *, db_recops)); 551 virtual int set_app_dispatch(int (*)(DbEnv *, 552 Dbt *, DbLsn *, db_recops)); 553 virtual int get_tx_timestamp(time_t *); 554 virtual int set_tx_timestamp(time_t *); 555 virtual int get_verbose(u_int32_t which, int *); 556 virtual int set_verbose(u_int32_t which, int); 557 558 // Version information. A static method so it can be obtained anytime. 559 // 560 static char *version(int *major, int *minor, int *patch); 561 562 // Convert DB errors to strings 563 static char *strerror(int); 564 565 // If an error is detected and the error call function 566 // or stream is set, a message is dispatched or printed. 567 // If a prefix is set, each message is prefixed. 568 // 569 // You can use set_errcall() or set_errfile() above to control 570 // error functionality. Alternatively, you can call 571 // set_error_stream() to force all errors to a C++ stream. 572 // It is unwise to mix these approaches. 573 // 574 virtual __DB_STD(ostream) *get_error_stream(); 575 virtual void set_error_stream(__DB_STD(ostream) *); 576 virtual __DB_STD(ostream) *get_message_stream(); 577 virtual void set_message_stream(__DB_STD(ostream) *); 578 579 // used internally 580 static void runtime_error(DbEnv *dbenv, const char *caller, int err, 581 int error_policy); 582 static void runtime_error_dbt(DbEnv *dbenv, const char *caller, Dbt *dbt, 583 int error_policy); 584 static void runtime_error_lock_get(DbEnv *dbenv, const char *caller, 585 int err, db_lockop_t op, db_lockmode_t mode, 586 Dbt *obj, DbLock lock, int index, 587 int error_policy); 588 589 // Lock functions 590 // 591 virtual int lock_detect(u_int32_t flags, u_int32_t atype, int *aborted); 592 virtual int lock_get(u_int32_t locker, u_int32_t flags, Dbt *obj, 593 db_lockmode_t lock_mode, DbLock *lock); 594 virtual int lock_id(u_int32_t *idp); 595 virtual int lock_id_free(u_int32_t id); 596 virtual int lock_put(DbLock *lock); 597 virtual int lock_stat(DB_LOCK_STAT **statp, u_int32_t flags); 598 virtual int lock_stat_print(u_int32_t flags); 599 virtual int lock_vec(u_int32_t locker, u_int32_t flags, 600 DB_LOCKREQ list[], int nlist, DB_LOCKREQ **elistp); 601 602 // Log functions 603 // 604 virtual int log_archive(char **list[], u_int32_t flags); 605 static int log_compare(const DbLsn *lsn0, const DbLsn *lsn1); 606 virtual int log_cursor(DbLogc **cursorp, u_int32_t flags); 607 virtual int log_file(DbLsn *lsn, char *namep, size_t len); 608 virtual int log_flush(const DbLsn *lsn); 609 virtual int log_get_config(u_int32_t, int *); 610 virtual int log_put(DbLsn *lsn, const Dbt *data, u_int32_t flags); 611 virtual int log_printf(DbTxn *, const char *, ...); 612 virtual int log_set_config(u_int32_t, int); 613 virtual int log_stat(DB_LOG_STAT **spp, u_int32_t flags); 614 virtual int log_stat_print(u_int32_t flags); 615 616 // Mpool functions 617 // 618 virtual int memp_fcreate(DbMpoolFile **dbmfp, u_int32_t flags); 619 virtual int memp_register(int ftype, 620 pgin_fcn_type pgin_fcn, 621 pgout_fcn_type pgout_fcn); 622 virtual int memp_stat(DB_MPOOL_STAT 623 **gsp, DB_MPOOL_FSTAT ***fsp, u_int32_t flags); 624 virtual int memp_stat_print(u_int32_t flags); 625 virtual int memp_sync(DbLsn *lsn); 626 virtual int memp_trickle(int pct, int *nwrotep); 627 628 // Mpool functions 629 // 630 virtual int mutex_alloc(u_int32_t, db_mutex_t *); 631 virtual int mutex_free(db_mutex_t); 632 virtual int mutex_get_align(u_int32_t *); 633 virtual int mutex_get_increment(u_int32_t *); 634 virtual int mutex_get_max(u_int32_t *); 635 virtual int mutex_get_tas_spins(u_int32_t *); 636 virtual int mutex_lock(db_mutex_t); 637 virtual int mutex_set_align(u_int32_t); 638 virtual int mutex_set_increment(u_int32_t); 639 virtual int mutex_set_max(u_int32_t); 640 virtual int mutex_set_tas_spins(u_int32_t); 641 virtual int mutex_stat(DB_MUTEX_STAT **, u_int32_t); 642 virtual int mutex_stat_print(u_int32_t); 643 virtual int mutex_unlock(db_mutex_t); 644 645 // Transaction functions 646 // 647 virtual int txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags); 648 virtual int txn_checkpoint(u_int32_t kbyte, u_int32_t min, 649 u_int32_t flags); 650 virtual int txn_recover(DbPreplist *preplist, u_int32_t count, 651 u_int32_t *retp, u_int32_t flags); 652 virtual int txn_stat(DB_TXN_STAT **statp, u_int32_t flags); 653 virtual int txn_stat_print(u_int32_t flags); 654 655 // Replication functions 656 // 657 virtual int rep_elect(u_int32_t, u_int32_t, u_int32_t); 658 virtual int rep_flush(); 659 virtual int rep_process_message(Dbt *, Dbt *, int, DbLsn *); 660 virtual int rep_start(Dbt *, u_int32_t); 661 virtual int rep_stat(DB_REP_STAT **statp, u_int32_t flags); 662 virtual int rep_stat_print(u_int32_t flags); 663 virtual int rep_get_clockskew(u_int32_t *, u_int32_t *); 664 virtual int rep_set_clockskew(u_int32_t, u_int32_t); 665 virtual int rep_get_limit(u_int32_t *, u_int32_t *); 666 virtual int rep_set_limit(u_int32_t, u_int32_t); 667 virtual int rep_set_transport(int, int (*)(DbEnv *, 668 const Dbt *, const Dbt *, const DbLsn *, int, u_int32_t)); 669 virtual int rep_set_request(u_int32_t, u_int32_t); 670 virtual int rep_get_request(u_int32_t *, u_int32_t *); 671 virtual int get_thread_count(u_int32_t *); 672 virtual int set_thread_count(u_int32_t); 673 virtual int get_thread_id_fn( 674 void (**)(DbEnv *, pid_t *, db_threadid_t *)); 675 virtual int set_thread_id(void (*)(DbEnv *, pid_t *, db_threadid_t *)); 676 virtual int get_thread_id_string_fn( 677 char *(**)(DbEnv *, pid_t, db_threadid_t, char *)); 678 virtual int set_thread_id_string(char *(*)(DbEnv *, 679 pid_t, db_threadid_t, char *)); 680 virtual int rep_set_config(u_int32_t, int); 681 virtual int rep_get_config(u_int32_t, int *); 682 virtual int rep_sync(u_int32_t flags); 683 684 // Advanced replication functions 685 // 686 virtual int rep_get_nsites(u_int32_t *n); 687 virtual int rep_set_nsites(u_int32_t n); 688 virtual int rep_get_priority(u_int32_t *priorityp); 689 virtual int rep_set_priority(u_int32_t priority); 690 virtual int rep_get_timeout(int which, db_timeout_t *timeout); 691 virtual int rep_set_timeout(int which, db_timeout_t timeout); 692 virtual int repmgr_add_remote_site(const char * host, u_int16_t port, 693 int *eidp, u_int32_t flags); 694 virtual int repmgr_get_ack_policy(int *policy); 695 virtual int repmgr_set_ack_policy(int policy); 696 virtual int repmgr_set_local_site(const char * host, u_int16_t port, 697 u_int32_t flags); 698 virtual int repmgr_site_list(u_int *countp, DB_REPMGR_SITE **listp); 699 virtual int repmgr_start(int nthreads, u_int32_t flags); 700 virtual int repmgr_stat(DB_REPMGR_STAT **statp, u_int32_t flags); 701 virtual int repmgr_stat_print(u_int32_t flags); 702 703 // Conversion functions 704 // 705 virtual ENV *get_ENV() 706 { 707 return imp_->env; 708 } 709 710 virtual DB_ENV *get_DB_ENV() 711 { 712 return imp_; 713 } 714 715 virtual const DB_ENV *get_const_DB_ENV() const 716 { 717 return imp_; 718 } 719 720 static DbEnv* get_DbEnv(DB_ENV *dbenv) 721 { 722 return dbenv ? (DbEnv *)dbenv->api1_internal : 0; 723 } 724 725 static const DbEnv* get_const_DbEnv(const DB_ENV *dbenv) 726 { 727 return dbenv ? (const DbEnv *)dbenv->api1_internal : 0; 728 } 729 730 u_int32_t get_create_flags() const 731 { 732 return construct_flags_; 733 } 734 735 // For internal use only. 736 static DbEnv* wrap_DB_ENV(DB_ENV *dbenv); 737 738 // These are public only because they need to be called 739 // via C functions. They should never be called by users 740 // of this class. 741 // 742 static int _app_dispatch_intercept(DB_ENV *dbenv, DBT *dbt, DB_LSN *lsn, 743 db_recops op); 744 static void _paniccall_intercept(DB_ENV *dbenv, int errval); 745 static void _feedback_intercept(DB_ENV *dbenv, int opcode, int pct); 746 static void _event_func_intercept(DB_ENV *dbenv, u_int32_t, void *); 747 static int _isalive_intercept(DB_ENV *dbenv, pid_t pid, 748 db_threadid_t thrid, u_int32_t flags); 749 static int _rep_send_intercept(DB_ENV *dbenv, const DBT *cntrl, 750 const DBT *data, const DB_LSN *lsn, int id, u_int32_t flags); 751 static void _stream_error_function(const DB_ENV *dbenv, 752 const char *prefix, const char *message); 753 static void _stream_message_function(const DB_ENV *dbenv, 754 const char *message); 755 static void _thread_id_intercept(DB_ENV *dbenv, pid_t *pidp, 756 db_threadid_t *thridp); 757 static char *_thread_id_string_intercept(DB_ENV *dbenv, pid_t pid, 758 db_threadid_t thrid, char *buf); 759 760private: 761 void cleanup(); 762 int initialize(DB_ENV *dbenv); 763 int error_policy(); 764 765 // For internal use only. 766 DbEnv(DB_ENV *, u_int32_t flags); 767 768 // no copying 769 DbEnv(const DbEnv &); 770 void operator = (const DbEnv &); 771 772 // instance data 773 DB_ENV *imp_; 774 int construct_error_; 775 u_int32_t construct_flags_; 776 __DB_STD(ostream) *error_stream_; 777 __DB_STD(ostream) *message_stream_; 778 779 int (*app_dispatch_callback_)(DbEnv *, Dbt *, DbLsn *, db_recops); 780 int (*isalive_callback_)(DbEnv *, pid_t, db_threadid_t, u_int32_t); 781 void (*error_callback_)(const DbEnv *, const char *, const char *); 782 void (*feedback_callback_)(DbEnv *, int, int); 783 void (*message_callback_)(const DbEnv *, const char *); 784 void (*paniccall_callback_)(DbEnv *, int); 785 void (*event_func_callback_)(DbEnv *, u_int32_t, void *); 786 int (*rep_send_callback_)(DbEnv *, const Dbt *, const Dbt *, 787 const DbLsn *, int, u_int32_t); 788 void (*thread_id_callback_)(DbEnv *, pid_t *, db_threadid_t *); 789 char *(*thread_id_string_callback_)(DbEnv *, pid_t, db_threadid_t, 790 char *); 791}; 792 793// 794// Lock 795// 796class _exported DbLock 797{ 798 friend class DbEnv; 799 800public: 801 DbLock(); 802 DbLock(const DbLock &); 803 DbLock &operator = (const DbLock &); 804 805protected: 806 // We can add data to this class if needed 807 // since its contained class is not allocated by db. 808 // (see comment at top) 809 810 DbLock(DB_LOCK); 811 DB_LOCK lock_; 812}; 813 814// 815// Log cursor 816// 817class _exported DbLogc : protected DB_LOGC 818{ 819 friend class DbEnv; 820 821public: 822 int close(u_int32_t _flags); 823 int get(DbLsn *lsn, Dbt *data, u_int32_t _flags); 824 int version(u_int32_t *versionp, u_int32_t _flags); 825 826private: 827 // No data is permitted in this class (see comment at top) 828 829 // Note: use Db::cursor() to get pointers to a Dbc, 830 // and call Dbc::close() rather than delete to release them. 831 // 832 DbLogc(); 833 ~DbLogc(); 834 835 // no copying 836 DbLogc(const Dbc &); 837 DbLogc &operator = (const Dbc &); 838}; 839 840// 841// Log sequence number 842// 843class _exported DbLsn : public DB_LSN 844{ 845 friend class DbEnv; // friendship needed to cast to base class 846 friend class DbLogc; // friendship needed to cast to base class 847}; 848 849// 850// Memory pool file 851// 852class _exported DbMpoolFile 853{ 854 friend class DbEnv; 855 friend class Db; 856 857public: 858 int close(u_int32_t flags); 859 int get(db_pgno_t *pgnoaddr, DbTxn *txn, u_int32_t flags, void *pagep); 860 int get_clear_len(u_int32_t *len); 861 int get_fileid(u_int8_t *fileid); 862 int get_flags(u_int32_t *flagsp); 863 int get_ftype(int *ftype); 864 int get_last_pgno(db_pgno_t *pgnop); 865 int get_lsn_offset(int32_t *offsetp); 866 int get_maxsize(u_int32_t *gbytes, u_int32_t *bytes); 867 int get_pgcookie(DBT *dbt); 868 int get_priority(DB_CACHE_PRIORITY *priorityp); 869 int get_transactional(void); 870 int open(const char *file, u_int32_t flags, int mode, size_t pagesize); 871 int put(void *pgaddr, DB_CACHE_PRIORITY priority, u_int32_t flags); 872 int set_clear_len(u_int32_t len); 873 int set_fileid(u_int8_t *fileid); 874 int set_flags(u_int32_t flags, int onoff); 875 int set_ftype(int ftype); 876 int set_lsn_offset(int32_t offset); 877 int set_maxsize(u_int32_t gbytes, u_int32_t bytes); 878 int set_pgcookie(DBT *dbt); 879 int set_priority(DB_CACHE_PRIORITY priority); 880 int sync(); 881 882 virtual DB_MPOOLFILE *get_DB_MPOOLFILE() 883 { 884 return imp_; 885 } 886 887 virtual const DB_MPOOLFILE *get_const_DB_MPOOLFILE() const 888 { 889 return imp_; 890 } 891 892private: 893 DB_MPOOLFILE *imp_; 894 895 // We can add data to this class if needed 896 // since it is implemented via a pointer. 897 // (see comment at top) 898 899 // Note: use DbEnv::memp_fcreate() to get pointers to a DbMpoolFile, 900 // and call DbMpoolFile::close() rather than delete to release them. 901 // 902 DbMpoolFile(); 903 904 // Shut g++ up. 905protected: 906 virtual ~DbMpoolFile(); 907 908private: 909 // no copying 910 DbMpoolFile(const DbMpoolFile &); 911 void operator = (const DbMpoolFile &); 912}; 913 914// 915// This is filled in and returned by the DbEnv::txn_recover() method. 916// 917class _exported DbPreplist 918{ 919public: 920 DbTxn *txn; 921 u_int8_t gid[DB_GID_SIZE]; 922}; 923 924// 925// A sequence record in a database 926// 927class _exported DbSequence 928{ 929public: 930 DbSequence(Db *db, u_int32_t flags); 931 virtual ~DbSequence(); 932 933 int open(DbTxn *txnid, Dbt *key, u_int32_t flags); 934 int initial_value(db_seq_t value); 935 int close(u_int32_t flags); 936 int remove(DbTxn *txnid, u_int32_t flags); 937 int stat(DB_SEQUENCE_STAT **sp, u_int32_t flags); 938 int stat_print(u_int32_t flags); 939 940 int get(DbTxn *txnid, int32_t delta, db_seq_t *retp, u_int32_t flags); 941 int get_cachesize(int32_t *sizep); 942 int set_cachesize(int32_t size); 943 int get_flags(u_int32_t *flagsp); 944 int set_flags(u_int32_t flags); 945 int get_range(db_seq_t *minp, db_seq_t *maxp); 946 int set_range(db_seq_t min, db_seq_t max); 947 948 Db *get_db(); 949 Dbt *get_key(); 950 951 virtual DB_SEQUENCE *get_DB_SEQUENCE() 952 { 953 return imp_; 954 } 955 956 virtual const DB_SEQUENCE *get_const_DB_SEQUENCE() const 957 { 958 return imp_; 959 } 960 961 static DbSequence* get_DbSequence(DB_SEQUENCE *seq) 962 { 963 return (DbSequence *)seq->api_internal; 964 } 965 966 static const DbSequence* get_const_DbSequence(const DB_SEQUENCE *seq) 967 { 968 return (const DbSequence *)seq->api_internal; 969 } 970 971 // For internal use only. 972 static DbSequence* wrap_DB_SEQUENCE(DB_SEQUENCE *seq); 973 974private: 975 DbSequence(DB_SEQUENCE *seq); 976 // no copying 977 DbSequence(const DbSequence &); 978 DbSequence &operator = (const DbSequence &); 979 980 DB_SEQUENCE *imp_; 981 DBT key_; 982}; 983 984// 985// Transaction 986// 987class _exported DbTxn 988{ 989 friend class DbEnv; 990 991public: 992 int abort(); 993 int commit(u_int32_t flags); 994 int discard(u_int32_t flags); 995 u_int32_t id(); 996 int get_name(const char **namep); 997 int prepare(u_int8_t *gid); 998 int set_name(const char *name); 999 int set_timeout(db_timeout_t timeout, u_int32_t flags); 1000 1001 virtual DB_TXN *get_DB_TXN() 1002 { 1003 return imp_; 1004 } 1005 1006 virtual const DB_TXN *get_const_DB_TXN() const 1007 { 1008 return imp_; 1009 } 1010 1011 static DbTxn* get_DbTxn(DB_TXN *txn) 1012 { 1013 return (DbTxn *)txn->api_internal; 1014 } 1015 1016 static const DbTxn* get_const_DbTxn(const DB_TXN *txn) 1017 { 1018 return (const DbTxn *)txn->api_internal; 1019 } 1020 1021 // For internal use only. 1022 static DbTxn* wrap_DB_TXN(DB_TXN *txn); 1023 void remove_child_txn(DbTxn *kid); 1024 void add_child_txn(DbTxn *kid); 1025 1026 void set_parent(DbTxn *ptxn) 1027 { 1028 parent_txn_ = ptxn; 1029 } 1030 1031private: 1032 DB_TXN *imp_; 1033 1034 // We use a TAILQ to store this object's kids of DbTxn objects, and 1035 // each kid has a "parent_txn_" to point to this DbTxn object. 1036 // 1037 // If imp_ has a parent transaction which is not wrapped by DbTxn 1038 // class, parent_txn_ will be NULL since we don't need to maintain 1039 // this parent-kid relationship. This relationship only helps to 1040 // delete unresolved kids when the parent is resolved. 1041 DbTxn *parent_txn_; 1042 1043 // We can add data to this class if needed 1044 // since it is implemented via a pointer. 1045 // (see comment at top) 1046 1047 // Note: use DbEnv::txn_begin() to get pointers to a DbTxn, 1048 // and call DbTxn::abort() or DbTxn::commit rather than 1049 // delete to release them. 1050 // 1051 DbTxn(DbTxn *ptxn); 1052 // For internal use only. 1053 DbTxn(DB_TXN *txn, DbTxn *ptxn); 1054 virtual ~DbTxn(); 1055 1056 // no copying 1057 DbTxn(const DbTxn &); 1058 void operator = (const DbTxn &); 1059 1060 /* 1061 * !!! 1062 * Explicit representations of structures from queue.h. 1063 * TAILQ_HEAD(__children, DbTxn) children; 1064 */ 1065 struct __children { 1066 DbTxn *tqh_first; 1067 DbTxn **tqh_last; 1068 } children; 1069 1070 /* 1071 * !!! 1072 * Explicit representations of structures from queue.h. 1073 * TAILQ_ENTRY(DbTxn) child_entry; 1074 */ 1075 struct { 1076 DbTxn *tqe_next; 1077 DbTxn **tqe_prev; 1078 } child_entry; 1079}; 1080 1081// 1082// A chunk of data, maybe a key or value. 1083// 1084class _exported Dbt : private DBT 1085{ 1086 friend class Db; 1087 friend class Dbc; 1088 friend class DbEnv; 1089 friend class DbLogc; 1090 friend class DbSequence; 1091 1092public: 1093 // key/data 1094 void *get_data() const { return data; } 1095 void set_data(void *value) { data = value; } 1096 1097 // key/data length 1098 u_int32_t get_size() const { return size; } 1099 void set_size(u_int32_t value) { size = value; } 1100 1101 // RO: length of user buffer. 1102 u_int32_t get_ulen() const { return ulen; } 1103 void set_ulen(u_int32_t value) { ulen = value; } 1104 1105 // RO: get/put record length. 1106 u_int32_t get_dlen() const { return dlen; } 1107 void set_dlen(u_int32_t value) { dlen = value; } 1108 1109 // RO: get/put record offset. 1110 u_int32_t get_doff() const { return doff; } 1111 void set_doff(u_int32_t value) { doff = value; } 1112 1113 // flags 1114 u_int32_t get_flags() const { return flags; } 1115 void set_flags(u_int32_t value) { flags = value; } 1116 1117 // Conversion functions 1118 DBT *get_DBT() { return (DBT *)this; } 1119 const DBT *get_const_DBT() const { return (const DBT *)this; } 1120 1121 static Dbt* get_Dbt(DBT *dbt) { return (Dbt *)dbt; } 1122 static const Dbt* get_const_Dbt(const DBT *dbt) 1123 { return (const Dbt *)dbt; } 1124 1125 Dbt(void *data, u_int32_t size); 1126 Dbt(); 1127 ~Dbt(); 1128 Dbt(const Dbt &); 1129 Dbt &operator = (const Dbt &); 1130 1131private: 1132 // Note: no extra data appears in this class (other than 1133 // inherited from DBT) since we need DBT and Dbt objects 1134 // to have interchangable pointers. 1135 // 1136 // When subclassing this class, remember that callback 1137 // methods like bt_compare, bt_prefix, dup_compare may 1138 // internally manufacture DBT objects (which later are 1139 // cast to Dbt), so such callbacks might receive objects 1140 // not of your subclassed type. 1141}; 1142 1143//////////////////////////////////////////////////////////////// 1144//////////////////////////////////////////////////////////////// 1145// 1146// multiple key/data/recno iterator classes 1147// 1148 1149// DbMultipleIterator is a shared private base class for the three types 1150// of bulk-return Iterator; it should never be instantiated directly, 1151// but it handles the functionality shared by its subclasses. 1152class _exported DbMultipleIterator 1153{ 1154public: 1155 DbMultipleIterator(const Dbt &dbt); 1156protected: 1157 u_int8_t *data_; 1158 u_int32_t *p_; 1159}; 1160 1161class _exported DbMultipleKeyDataIterator : private DbMultipleIterator 1162{ 1163public: 1164 DbMultipleKeyDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {} 1165 bool next(Dbt &key, Dbt &data); 1166}; 1167 1168class _exported DbMultipleRecnoDataIterator : private DbMultipleIterator 1169{ 1170public: 1171 DbMultipleRecnoDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {} 1172 bool next(db_recno_t &recno, Dbt &data); 1173}; 1174 1175class _exported DbMultipleDataIterator : private DbMultipleIterator 1176{ 1177public: 1178 DbMultipleDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {} 1179 bool next(Dbt &data); 1180}; 1181 1182//////////////////////////////////////////////////////////////// 1183//////////////////////////////////////////////////////////////// 1184// 1185// multiple key/data/recno builder classes 1186// 1187 1188// DbMultipleBuilder is a shared private base class for the three types 1189// of bulk buffer builders; it should never be instantiated directly, 1190// but it handles the functionality shared by its subclasses. 1191class _exported DbMultipleBuilder 1192{ 1193public: 1194 DbMultipleBuilder(Dbt &dbt); 1195protected: 1196 Dbt &dbt_; 1197 void *p_; 1198}; 1199 1200class _exported DbMultipleDataBuilder : DbMultipleBuilder 1201{ 1202public: 1203 DbMultipleDataBuilder(Dbt &dbt) : DbMultipleBuilder(dbt) {} 1204 bool append(void *dbuf, size_t dlen); 1205 bool reserve(void *&ddest, size_t dlen); 1206}; 1207 1208class _exported DbMultipleKeyDataBuilder : DbMultipleBuilder 1209{ 1210public: 1211 DbMultipleKeyDataBuilder(Dbt &dbt) : DbMultipleBuilder(dbt) {} 1212 bool append(void *kbuf, size_t klen, void *dbuf, size_t dlen); 1213 bool reserve(void *&kdest, size_t klen, void *&ddest, size_t dlen); 1214}; 1215 1216class _exported DbMultipleRecnoDataBuilder 1217{ 1218public: 1219 DbMultipleRecnoDataBuilder(Dbt &dbt); 1220 bool append(db_recno_t recno, void *dbuf, size_t dlen); 1221 bool reserve(db_recno_t recno, void *&ddest, size_t dlen); 1222protected: 1223 Dbt &dbt_; 1224 void *p_; 1225}; 1226 1227//////////////////////////////////////////////////////////////// 1228//////////////////////////////////////////////////////////////// 1229// 1230// Exception classes 1231// 1232 1233// Almost any error in the DB library throws a DbException. 1234// Every exception should be considered an abnormality 1235// (e.g. bug, misuse of DB, file system error). 1236// 1237class _exported DbException : public __DB_STD(exception) 1238{ 1239public: 1240 virtual ~DbException() throw(); 1241 DbException(int err); 1242 DbException(const char *description); 1243 DbException(const char *description, int err); 1244 DbException(const char *prefix, const char *description, int err); 1245 int get_errno() const; 1246 virtual const char *what() const throw(); 1247 DbEnv *get_env() const; 1248 void set_env(DbEnv *dbenv); 1249 1250 DbException(const DbException &); 1251 DbException &operator = (const DbException &); 1252 1253private: 1254 void describe(const char *prefix, const char *description); 1255 1256 char *what_; 1257 int err_; // errno 1258 DbEnv *dbenv_; 1259}; 1260 1261// 1262// A specific sort of exception that occurs when 1263// an operation is aborted to resolve a deadlock. 1264// 1265class _exported DbDeadlockException : public DbException 1266{ 1267public: 1268 virtual ~DbDeadlockException() throw(); 1269 DbDeadlockException(const char *description); 1270 1271 DbDeadlockException(const DbDeadlockException &); 1272 DbDeadlockException &operator = (const DbDeadlockException &); 1273}; 1274 1275// 1276// A specific sort of exception that occurs when 1277// a lock is not granted, e.g. by lock_get or lock_vec. 1278// Note that the Dbt is only live as long as the Dbt used 1279// in the offending call. 1280// 1281class _exported DbLockNotGrantedException : public DbException 1282{ 1283public: 1284 virtual ~DbLockNotGrantedException() throw(); 1285 DbLockNotGrantedException(const char *prefix, db_lockop_t op, 1286 db_lockmode_t mode, const Dbt *obj, const DbLock lock, int index); 1287 DbLockNotGrantedException(const char *description); 1288 1289 DbLockNotGrantedException(const DbLockNotGrantedException &); 1290 DbLockNotGrantedException &operator = 1291 (const DbLockNotGrantedException &); 1292 1293 db_lockop_t get_op() const; 1294 db_lockmode_t get_mode() const; 1295 const Dbt* get_obj() const; 1296 DbLock *get_lock() const; 1297 int get_index() const; 1298 1299private: 1300 db_lockop_t op_; 1301 db_lockmode_t mode_; 1302 const Dbt *obj_; 1303 DbLock *lock_; 1304 int index_; 1305}; 1306 1307// 1308// A specific sort of exception that occurs when 1309// user declared memory is insufficient in a Dbt. 1310// 1311class _exported DbMemoryException : public DbException 1312{ 1313public: 1314 virtual ~DbMemoryException() throw(); 1315 DbMemoryException(Dbt *dbt); 1316 DbMemoryException(const char *prefix, Dbt *dbt); 1317 1318 DbMemoryException(const DbMemoryException &); 1319 DbMemoryException &operator = (const DbMemoryException &); 1320 1321 Dbt *get_dbt() const; 1322private: 1323 Dbt *dbt_; 1324}; 1325 1326// 1327// A specific sort of exception that occurs when a change of replication 1328// master requires that all handles be re-opened. 1329// 1330class _exported DbRepHandleDeadException : public DbException 1331{ 1332public: 1333 virtual ~DbRepHandleDeadException() throw(); 1334 DbRepHandleDeadException(const char *description); 1335 1336 DbRepHandleDeadException(const DbRepHandleDeadException &); 1337 DbRepHandleDeadException &operator = (const DbRepHandleDeadException &); 1338}; 1339 1340// 1341// A specific sort of exception that occurs when 1342// recovery is required before continuing DB activity. 1343// 1344class _exported DbRunRecoveryException : public DbException 1345{ 1346public: 1347 virtual ~DbRunRecoveryException() throw(); 1348 DbRunRecoveryException(const char *description); 1349 1350 DbRunRecoveryException(const DbRunRecoveryException &); 1351 DbRunRecoveryException &operator = (const DbRunRecoveryException &); 1352}; 1353 1354// 1355// A specific sort of exception that occurs when 1356 1357//////////////////////////////////////////////////////////////// 1358//////////////////////////////////////////////////////////////// 1359// 1360// Restore default compiler warnings 1361// 1362#ifdef _MSC_VER 1363#pragma warning(pop) 1364#endif 1365 1366#endif /* !_DB_CXX_H_ */ 1367