def create(cls, txn, value=None):
     identifier = generate_identifier()
     version = generate_identifier()
     element = cls(txn, identifier, version, value)
     element.creation_ts(True)
     element.modified = True
     element.new = True
     txn.elements[element.identifier] = element
     return element
 def save(self):
     if self.modified:  # we only need to write on disk if the object
                        # was modified
         if not self.next:  # the version was/is a valid version
                            # for a write
             version = generate_identifier()
             previous = self.copy()
             copy = previous.copy()
             previous.next = version
             previous.expire_ts(True)
             # we still have the monopoly on the value of the element
             in_cache = copy.version in self.txn.database.cache
             if (in_cache and self.txn.database.cache.check_and_set(
                     copy.version,
                     copy,
                     previous
                 ) or not in_cache):
                 if in_cache:
                     # it's not a creation we need to edit
                     # old version to link to the new version
                     previous._write()
                     self.previous = previous.version
                 self.version = version
                 self.next = None
                 self._write()
                 # checkout this new version in the cache
                 self.txn.database.cache[self.version] = self
             else:
                 raise InvalidConcurrentTransaction
         else:
             # The problem with this is that we do all the commands in
             # the txn before invalidating it.
             raise InvalidConcurrentTransaction
Example #3
0
 def create(cls, txn, value=None):
     """Create an object for the given transaction and with the given
     value. This method *must* register the newly created element to
     the transaction."""
     identifier = generate_identifier()
     element = cls(txn, identifier, value)
     txn.add(element)
     return element
Example #4
0
 def add_task(self, data):
     identifier = generate_identifier()
     self.tasks.add(identifier, data)
     return identifier
Example #5
0
 def create(cls, root):
     identifier = generate_identifier()
     value = PersistentDict()
     root[cls.name()][identifier] = value
     element = cls(identifier, value, root)
     return element