예제 #1
0
 def __rollback(self, state):
     source_entity = state.entity
     ent_cls = type(source_entity)
     status = state.status
     if status != ENTITY_STATUS.CLEAN:
         mongo_coll = self.__get_mongo_collection(ent_cls)
         ent_oid = getattr(source_entity, '_id')
         if status == ENTITY_STATUS.NEW:
             mongo_coll.remove(ent_oid)
             if __debug__:
                 self.__logger.debug("Rollback INSERT entity OID %s."
                                     % ent_oid)
         else:
             if status == ENTITY_STATUS.DELETED:
                 data = transform_incoming(ent_cls, source_entity)
                 mongo_coll.insert(data)
                 if __debug__:
                     self.__logger.debug('Rollback REMOVE entity OID %s: '
                                         '%s.' % (ent_oid, data.items()))
             else:
                 assert status == ENTITY_STATUS.DIRTY
                 EntityState.set_state_data(source_entity,
                                            state.clean_data)
                 data = transform_incoming(ent_cls, source_entity)
                 mongo_coll.update({'_id':ent_oid}, data)
                 if __debug__:
                     self.__logger.debug('Rollback UPDATE entity OID %s: '
                                         '%s.' % (ent_oid, data.items()))
예제 #2
0
파일: cache.py 프로젝트: helixyte/everest
    def update(self, source_data, target_entity):
        """
        Updates the state of the target entity with the given source data.

        :param target_entity: Entity to update.
        :type target_entity: Object implementing
          :class:`everest.interfaces.IEntity`.
        """
        EntityState.set_state_data(target_entity, source_data)
예제 #3
0
파일: cache.py 프로젝트: papagr/everest
    def update(self, source_data, target_entity):
        """
        Updates the state of the target entity with the given source data.

        :param target_entity: Entity to update.
        :type target_entity: Object implementing
          :class:`everest.interfaces.IEntity`.
        """
        EntityState.set_state_data(target_entity, source_data)
예제 #4
0
 def __clone(self, entity, cache):
     clone = object.__new__(entity.__class__)
     # We add the clone with its ID set to the cache *before* we load it
     # so that circular references will work.
     clone.id = entity.id
     cache.add(clone)
     state = EntityState.get_state_data(entity)
     id_attr = None
     for attr, value in iteritems_(state):
         if attr.entity_attr == 'id':
             id_attr = attr
             continue
         attr_type = attr.attr_type
         if attr.kind != RESOURCE_ATTRIBUTE_KINDS.TERMINAL \
            and not self.__repository.is_registered_resource(attr_type):
             # Prevent loading of entities from other repositories.
             # FIXME: Doing this here is inconsistent, since e.g. the RDB
             #        session does not perform this kind of check.
             continue
         elif attr.kind == RESOURCE_ATTRIBUTE_KINDS.MEMBER \
            and not value is None:
             ent_cls = get_entity_class(attr_type)
             new_value = self.load(ent_cls, value)
             state[attr] = new_value
         elif attr.kind == RESOURCE_ATTRIBUTE_KINDS.COLLECTION \
              and len(value) > 0:
             value_type = type(value)
             new_value = value_type.__new__(value_type)
             if issubclass(value_type, MutableSequence):
                 add_op = new_value.append
             elif issubclass(value_type, MutableSet):
                 add_op = new_value.add
             else:
                 raise ValueError('Do not know how to clone value of type '
                                  '%s for resource attribute %s.' %
                                  (type(new_value), attr))
             ent_cls = get_entity_class(attr_type)
             for child in value:
                 child_clone = self.load(ent_cls, child)
                 add_op(child_clone)
             state[attr] = new_value
     # We set the ID already above.
     if not id_attr is None:
         del state[id_attr]
     EntityState.set_state_data(clone, state)
     return clone
예제 #5
0
파일: session.py 프로젝트: helixyte/everest
 def __clone(self, entity, cache):
     clone = object.__new__(entity.__class__)
     # We add the clone with its ID set to the cache *before* we load it
     # so that circular references will work.
     clone.id = entity.id
     cache.add(clone)
     state = EntityState.get_state_data(entity)
     id_attr = None
     for attr, value in iteritems_(state):
         if attr.entity_attr == 'id':
             id_attr = attr
             continue
         attr_type = attr.attr_type
         if attr.kind != RESOURCE_ATTRIBUTE_KINDS.TERMINAL \
            and not self.__repository.is_registered_resource(attr_type):
             # Prevent loading of entities from other repositories.
             # FIXME: Doing this here is inconsistent, since e.g. the RDB
             #        session does not perform this kind of check.
             continue
         elif attr.kind == RESOURCE_ATTRIBUTE_KINDS.MEMBER \
            and not value is None:
             ent_cls = get_entity_class(attr_type)
             new_value = self.load(ent_cls, value)
             state[attr] = new_value
         elif attr.kind == RESOURCE_ATTRIBUTE_KINDS.COLLECTION \
              and len(value) > 0:
             value_type = type(value)
             new_value = value_type.__new__(value_type)
             if issubclass(value_type, MutableSequence):
                 add_op = new_value.append
             elif issubclass(value_type, MutableSet):
                 add_op = new_value.add
             else:
                 raise ValueError('Do not know how to clone value of type '
                                  '%s for resource attribute %s.'
                                  % (type(new_value), attr))
             ent_cls = get_entity_class(attr_type)
             for child in value:
                 child_clone = self.load(ent_cls, child)
                 add_op(child_clone)
             state[attr] = new_value
     # We set the ID already above.
     if not id_attr is None:
         del state[id_attr]
     EntityState.set_state_data(clone, state)
     return clone
예제 #6
0
파일: session.py 프로젝트: papagr/everest
 def __update(self, source_data, target_entity, path): # pylint: disable=W0613
     EntityState.set_state_data(target_entity, source_data)
예제 #7
0
 def __update(self, source_data, target_entity):  # pylint: disable=W0613
     EntityState.set_state_data(target_entity, source_data)
     if self.__unit_of_work.is_marked_persisted(target_entity):
         self.__unit_of_work.mark_pending(target_entity)
예제 #8
0
파일: session.py 프로젝트: helixyte/everest
 def __update(self, source_data, target_entity): # pylint: disable=W0613
     EntityState.set_state_data(target_entity, source_data)
     if self.__unit_of_work.is_marked_persisted(target_entity):
         self.__unit_of_work.mark_pending(target_entity)