00001
00002
00003
00004
00005
00006
00007
00008 #include "config.h"
00009
00010 #ifndef lint
00011 static const char revid[] = "$Id: xa__db_8c-source.html,v 1.1 2008/06/08 10:25:49 sebdiaz Exp $";
00012 #endif
00013
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 #endif
00017
00018 #include "db_int.h"
00019 #include "xa.h"
00020 #include "xa_ext.h"
00021 #include "txn.h"
00022
00023 static int __xa_close __P((DB *, u_int32_t));
00024 static int __xa_cursor __P((DB *, DB_TXN *, DBC **, u_int32_t));
00025 static int __xa_del __P((DB *, DB_TXN *, DBT *, u_int32_t));
00026 static int __xa_get __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00027 static int __xa_put __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00028
00029 typedef struct __xa_methods {
00030 int (*close) __P((DB *, u_int32_t));
00031 int (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
00032 int (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
00033 int (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00034 int (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00035 } XA_METHODS;
00036
00037
00038
00039
00040
00041
00042
00043 int
00044 CDB___db_xa_create(dbp)
00045 DB *dbp;
00046 {
00047 XA_METHODS *xam;
00048 int ret;
00049
00050
00051
00052
00053
00054 if ((ret = CDB___os_calloc(dbp->dbenv, 1, sizeof(XA_METHODS), &xam)) != 0)
00055 return (ret);
00056
00057 dbp->xa_internal = xam;
00058 xam->close = dbp->close;
00059 xam->cursor = dbp->cursor;
00060 xam->del = dbp->del;
00061 xam->get = dbp->get;
00062 xam->put = dbp->put;
00063 dbp->close = __xa_close;
00064 dbp->cursor = __xa_cursor;
00065 dbp->del = __xa_del;
00066 dbp->get = __xa_get;
00067 dbp->put = __xa_put;
00068
00069 return (0);
00070 }
00071
00072 static int
00073 __xa_cursor(dbp, txn, dbcp, flags)
00074 DB *dbp;
00075 DB_TXN *txn;
00076 DBC **dbcp;
00077 u_int32_t flags;
00078 {
00079 DB_TXN *t;
00080
00081 t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
00082 if (t->txnid == TXN_INVALID)
00083 t = NULL;
00084
00085 return (((XA_METHODS *)dbp->xa_internal)->cursor (dbp, t, dbcp, flags));
00086 }
00087
00088 static int
00089 __xa_del(dbp, txn, key, flags)
00090 DB *dbp;
00091 DB_TXN *txn;
00092 DBT *key;
00093 u_int32_t flags;
00094 {
00095 DB_TXN *t;
00096
00097 t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
00098 if (t->txnid == TXN_INVALID)
00099 t = NULL;
00100
00101 return (((XA_METHODS *)dbp->xa_internal)->del(dbp, t, key, flags));
00102 }
00103
00104 static int
00105 __xa_close(dbp, flags)
00106 DB *dbp;
00107 u_int32_t flags;
00108 {
00109 int (*real_close) __P((DB *, u_int32_t));
00110
00111 real_close = ((XA_METHODS *)dbp->xa_internal)->close;
00112
00113 CDB___os_free(dbp->xa_internal, sizeof(XA_METHODS));
00114 dbp->xa_internal = NULL;
00115
00116 return (real_close(dbp, flags));
00117 }
00118
00119 static int
00120 __xa_get(dbp, txn, key, data, flags)
00121 DB *dbp;
00122 DB_TXN *txn;
00123 DBT *key, *data;
00124 u_int32_t flags;
00125 {
00126 DB_TXN *t;
00127
00128 t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
00129 if (t->txnid == TXN_INVALID)
00130 t = NULL;
00131
00132 return (((XA_METHODS *)dbp->xa_internal)->get
00133 (dbp, t, key, data, flags));
00134 }
00135
00136 static int
00137 __xa_put(dbp, txn, key, data, flags)
00138 DB *dbp;
00139 DB_TXN *txn;
00140 DBT *key, *data;
00141 u_int32_t flags;
00142 {
00143 DB_TXN *t;
00144
00145 t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
00146 if (t->txnid == TXN_INVALID)
00147 t = NULL;
00148
00149 return (((XA_METHODS *)dbp->xa_internal)->put
00150 (dbp, t, key, data, flags));
00151 }