def delete_item(self, item): try: self._itemdb.delete( pack_value(item._pid) + b'_' + pack_value(item._id), context._trans.txn) except (db.DBLockDeadlockError, db.DBLockNotGrantedError): context._trans.abort() raise exceptions.DBRetryTransaction
def get_child_by_name(self, container_id, name): try: return self._indices['displayName'].db.get( pack_value(container_id) + b'_' + pack_value(name), txn=context._trans and context._trans.txn) except (db.DBLockDeadlockError, db.DBLockNotGrantedError): if context._trans is not None: context._trans.abort() raise exceptions.DBRetryTransaction
def put_item(self, item): try: self._itemdb.put( pack_value(item._pid) + b'_' + pack_value(item._id), persist.dumps(item), context._trans.txn) except (db.DBLockDeadlockError, db.DBLockNotGrantedError): context._trans.abort() raise exceptions.DBRetryTransaction except db.DBError as e: if e.args[0] == _err_unsupported_index_type: raise db.DBError('Unsupported indexed data type') else: raise
def set_lower_bound(self, lower_bound): if lower_bound is not None: value, inclusive = lower_bound self._lower_value = pack_value(value) self._lower_inclusive = inclusive else: self._lower_value = None self._lower_inclusive = False
def set_upper_bound(self, upper_bound): if upper_bound is not None: value, inclusive = upper_bound self._upper_value = pack_value(value) self._upper_inclusive = inclusive else: self._upper_value = None self._upper_inclusive = False
def callback(key, value): item = _cache.get(value, persist.loads(value)) index_value = None if item._isDeleted and not self.name == "_id": # do not index attributes of deleted objects return None if self.name == "_id" or (hasattr(item, self.name) and hasattr(item, "_owner")): # if item is composite index only the _id attribute # otherwise allow indexing of all attr = getattr(item, self.name) if attr.__class__.__module__ != None.__class__.__module__: attr = attr.value if self.name == "_id": index_value = pack_value(attr) else: index_value = pack_value(item._pid) + b"_" + pack_value(attr) _cache[value] = item return index_value
def callback(key, value): item = _cache.get(value, persist.loads(value)) index_value = None if item._isDeleted and not self.name == '_id': # do not index attributes of deleted objects return None if self.name == '_id' or \ (hasattr(item, self.name) and hasattr(item, '_owner')): # if item is composite index only the _id attribute # otherwise allow indexing of all attr = getattr(item, self.name) if attr.__class__.__module__ != None.__class__.__module__: attr = attr.value if self.name == '_id': index_value = pack_value(attr) else: index_value = (pack_value(item._pid) + b'_' + pack_value(attr)) _cache[value] = item return index_value
def _eval(self, item): if hasattr(item, self.name): attr = getattr(item, self.name) if attr.__class__.__module__ != None.__class__.__module__: attr = attr.value packed = pack_value(attr) if self._value is not None: return self._value == packed else: return packed in self._range return False
def set(self, v): val = pack_value(v) self._value = val self._range = None