class txn(object):
def __init__(self, env, flags=bd.DB_TXN_WRITE_NOSYNC):
- self.tx = env.txn_begin(None, flags)
+ self.tx = env.env.txn_begin(None, flags)
+ self.env = env
self.done = False
self.pcommit = set()
finally:
run1(list[1:])
run1(list(self.pcommit))
+ self.env.maint()
def abort(self):
self.done = True
self.cf = self._opendb("cf", bd.DB_HASH, fl)
self.ob = self._opendb("ob", bd.DB_HASH, fl)
- @txnfun(lambda self: self.env.env)
+ @txnfun(lambda self: self.env)
def _opendb(self, dnm, typ, fl, init=None, *, tx):
ret = bd.DB(self.env.env)
if init: init(ret)
ret.open(self.fnm, dnm, typ, fl, self.mode, txn=tx.tx)
return ret
- @txnfun(lambda self: self.env.env)
+ @txnfun(lambda self: self.env)
def _nextseq(self, *, tx):
if self.cf.has_key(b"seq", txn=tx.tx):
seq = struct.unpack(">Q", self.cf.get(b"seq", txn=tx.tx))[0]
self.cf.put(b"seq", struct.pack(">Q", seq + 1), txn=tx.tx)
return seq
- @txnfun(lambda self: self.env.env)
+ @txnfun(lambda self: self.env)
def add(self, ob, *, tx):
seq = self._nextseq(tx=tx)
self.ob.put(struct.pack(">Q", seq), ob, txn=tx.tx, flags=bd.DB_NOOVERWRITE)
return seq
- @txnfun(lambda self: self.env.env)
+ @txnfun(lambda self: self.env)
def replace(self, id, ob, *, tx):
key = struct.pack(">Q", id)
if not self.ob.has_key(key, txn=tx.tx):
raise KeyError(id)
self.ob.put(key, ob, txn=tx.tx)
- @txnfun(lambda self: self.env.env)
+ @txnfun(lambda self: self.env)
def get(self, id, *, tx):
ret = self.ob.get(struct.pack(">Q", id), None)
if ret is None:
raise KeyError(id)
return ret
- @txnfun(lambda self: self.env.env)
+ @txnfun(lambda self: self.env)
def remove(self, id, *, tx):
key = struct.pack(">Q", id)
if not self.ob.has_key(key, txn=tx.tx):
if not done:
cur.close()
- @txnfun(lambda self: self.db.env.env)
+ @txnfun(lambda self: self.db.env)
def put(self, key, id, *, tx):
obid = struct.pack(">Q", id)
if not self.db.ob.has_key(obid, txn=tx.tx):
return False
return True
- @txnfun(lambda self: self.db.env.env)
+ @txnfun(lambda self: self.db.env)
def remove(self, key, id, *, tx):
obid = struct.pack(">Q", id)
if not self.db.ob.has_key(obid, txn=tx.tx):
def _encode(self, obj):
return pickle.dumps(obj)
- @txnfun(lambda self: self.db().env.env)
+ @txnfun(lambda self: self.db().env)
def _load(self, id, *, tx):
loaded = self._decode(self.db().get(id, tx=tx))
if hasattr(loaded, "__didex_loaded__"):
def get(self, id, *, load=True):
return self.cache.get(id, load=load)
- @txnfun(lambda self: self.db().env.env)
+ @txnfun(lambda self: self.db().env)
def register(self, obj, *, tx):
id = self.db().add(self._encode(obj), tx=tx)
for nm, attr in storedescs(obj):
self.cache.put(id, obj)
return id
- @txnfun(lambda self: self.db().env.env)
+ @txnfun(lambda self: self.db().env)
def unregister(self, id, *, vfy=None, tx):
obj = self.get(id)
if vfy is not None and obj is not vfy:
self.db().remove(id, tx=tx)
self.cache.remove(id)
- @txnfun(lambda self: self.db().env.env)
+ @txnfun(lambda self: self.db().env)
def update(self, id, *, vfy=None, tx):
obj = self.get(id, load=False)
if vfy is not None and obj is not vfy: