예제 #1
0
    def mark_dirty(self, entity):
        """
        Marks the given entity for the given class as DIRTY.

        :raises ValueError: If the given entity does not hold state.
        """
        EntityState.get_state(entity).status = ENTITY_STATUS.DIRTY
예제 #2
0
    def mark_deleted(self, entity):
        """
        Marks the given entity as DELETED.

        :raises ValueError: If the given entity does not hold state.
        """
        EntityState.get_state(entity).status = ENTITY_STATUS.DELETED
예제 #3
0
파일: uow.py 프로젝트: helixyte/everest
    def mark_dirty(self, entity):
        """
        Marks the given entity for the given class as DIRTY.

        :raises ValueError: If the given entity does not hold state.
        """
        EntityState.get_state(entity).status = ENTITY_STATUS.DIRTY
예제 #4
0
파일: uow.py 프로젝트: helixyte/everest
    def mark_deleted(self, entity):
        """
        Marks the given entity as DELETED.

        :raises ValueError: If the given entity does not hold state.
        """
        EntityState.get_state(entity).status = ENTITY_STATUS.DELETED
예제 #5
0
    def mark_new(self, entity):
        """
        Marks the given entity as NEW.

        This is done when an entity is re-associated with a session after
        having been removed before.
        """
        EntityState.get_state(entity).status = ENTITY_STATUS.NEW
예제 #6
0
파일: uow.py 프로젝트: helixyte/everest
    def mark_pending(self, entity):
        """
        Sets the flag indicating if the state of the given entity has been
        persisted to `False`.

        :note: The persistency flag is orthogonal to the status flag.
        """
        EntityState.get_state(entity).is_persisted = False
예제 #7
0
파일: uow.py 프로젝트: helixyte/everest
    def mark_new(self, entity):
        """
        Marks the given entity as NEW.

        This is done when an entity is re-associated with a session after
        having been removed before.
        """
        EntityState.get_state(entity).status = ENTITY_STATUS.NEW
예제 #8
0
    def mark_pending(self, entity):
        """
        Sets the flag indicating if the state of the given entity has been
        persisted to `False`.

        :note: The persistency flag is orthogonal to the status flag.
        """
        EntityState.get_state(entity).is_persisted = False
예제 #9
0
    def register_clean(self, entity_class, entity):
        """
        Registers the given entity for the given class as CLEAN.

        :returns: Cloned entity.
        """
        EntityState.manage(entity, self)
        EntityState.get_state(entity).status = ENTITY_STATUS.CLEAN
        self.__entity_set_map[entity_class].add(entity)
예제 #10
0
파일: uow.py 프로젝트: helixyte/everest
    def is_marked_pending(self, entity):
        """
        Checks if the flag indicating that the state for the given entity
        has been persisted is `False`.

        :note: Use only after checking if the given entity is registered.
        :raises ValueError: If the entity has no state information.
        """
        return not EntityState.get_state(entity).is_persisted
예제 #11
0
파일: uow.py 프로젝트: helixyte/everest
 def __object_iterator(self, status, ent_cls):
     if ent_cls is None:
         ent_clss = self.__entity_set_map.keys()
     else:
         ent_clss = [ent_cls]
     for ent_cls in ent_clss:
         for ent in self.__entity_set_map[ent_cls]:
             if EntityState.get_state(ent).status == status:
                 yield ent
예제 #12
0
파일: uow.py 프로젝트: helixyte/everest
    def register_clean(self, entity_class, entity):
        """
        Registers the given entity for the given class as CLEAN.

        :returns: Cloned entity.
        """
        EntityState.manage(entity, self)
        EntityState.get_state(entity).status = ENTITY_STATUS.CLEAN
        self.__entity_set_map[entity_class].add(entity)
예제 #13
0
파일: uow.py 프로젝트: helixyte/everest
 def iterator(self):
     """
     Returns an iterator over all entity states held by this Unit Of Work.
     """
     # FIXME: There is no dependency tracking; objects are iterated in
     #        random order.
     for ent_cls in list(self.__entity_set_map.keys()):
         for ent in self.__entity_set_map[ent_cls]:
             yield EntityState.get_state(ent)
예제 #14
0
    def is_marked_pending(self, entity):
        """
        Checks if the flag indicating that the state for the given entity
        has been persisted is `False`.

        :note: Use only after checking if the given entity is registered.
        :raises ValueError: If the entity has no state information.
        """
        return not EntityState.get_state(entity).is_persisted
예제 #15
0
 def __object_iterator(self, status, ent_cls):
     if ent_cls is None:
         ent_clss = self.__entity_set_map.keys()
     else:
         ent_clss = [ent_cls]
     for ent_cls in ent_clss:
         for ent in self.__entity_set_map[ent_cls]:
             if EntityState.get_state(ent).status == status:
                 yield ent
예제 #16
0
 def iterator(self):
     """
     Returns an iterator over all entity states held by this Unit Of Work.
     """
     # FIXME: There is no dependency tracking; objects are iterated in
     #        random order.
     for ent_cls in list(self.__entity_set_map.keys()):
         for ent in self.__entity_set_map[ent_cls]:
             yield EntityState.get_state(ent)
예제 #17
0
파일: uow.py 프로젝트: helixyte/everest
    def mark_clean(self, entity):
        """
        Marks the given entity as CLEAN.

        This is done when an entity is loaded fresh from the repository or
        after a commit.
        """
        state = EntityState.get_state(entity)
        state.status = ENTITY_STATUS.CLEAN
        state.is_persisted = True
예제 #18
0
 def test_state_data(self):
     data = dict(text='FOO',
                 number=-1,
                 parent=MyEntityParent(),
                 children=[MyEntityChild()])
     entity = MyEntity(**data)
     # We don't want to test the required unit of work here.
     uow = MagicMock()
     self.assert_raises(ValueError, EntityState.get_state, entity)
     entity.__everest__ = EntityState(entity, uow)
     state_data = EntityState.get_state(entity).data
     for attr, value in state_data.items():
         if attr.resource_attr == 'number':
             number_attr = attr
         elif attr.resource_attr == 'parent':
             parent_attr = attr
         elif attr.resource_attr == 'parent_text':
             parent_text_attr = attr
         if attr.resource_attr in data:
             self.assert_equal(value, data[attr.resource_attr])
     new_number = -2
     state_data[number_attr] = new_number
     EntityState.get_state(entity).data = state_data
     self.assert_equal(entity.number, new_number)
     new_entity = MyEntity()
     self.assert_not_equal(new_entity.number, new_number)
     new_entity.__everest__ = EntityState(new_entity, uow)
     EntityState.transfer_state_data(entity, new_entity)
     self.assert_equal(new_entity.number, new_number)
     # Make setting invalid attribute fail.
     invalid_number_attr = terminal_attribute(str, 'grmbl')
     del state_data[number_attr]
     state_data[invalid_number_attr] = -2
     with self.assert_raises(ValueError) as cm:
         EntityState.get_state(entity).data = state_data
     self.assert_true(cm.exception.args[0].startswith('Can not set'))
     # Make set nested attribute fail.
     entity.parent = None
     del state_data[invalid_number_attr]
     del state_data[parent_attr]
     state_data[parent_text_attr] = 'FOO PARENT'
     state = EntityState.get_state(entity)
     self.assert_raises(AttributeError, setattr, state, 'data', state_data)
예제 #19
0
 def is_marked_new(self, entity):
     """
     Checks if the given entity is marked with status NEW. Returns `False`
     if the entity has no state information.
     """
     try:
         result = EntityState.get_state(entity).status == ENTITY_STATUS.NEW
     except ValueError:
         result = False
     return result
예제 #20
0
    def mark_clean(self, entity):
        """
        Marks the given entity as CLEAN.

        This is done when an entity is loaded fresh from the repository or
        after a commit.
        """
        state = EntityState.get_state(entity)
        state.status = ENTITY_STATUS.CLEAN
        state.is_persisted = True
예제 #21
0
    def register_deleted(self, entity_class, entity):
        """
        Registers the given entity for the given class as DELETED.

        :raises ValueError: If the given entity already holds state that was
          created by another Unit Of Work.
        """
        EntityState.manage(entity, self)
        EntityState.get_state(entity).status = ENTITY_STATUS.DELETED
        self.__entity_set_map[entity_class].add(entity)
예제 #22
0
파일: uow.py 프로젝트: helixyte/everest
 def is_marked_new(self, entity):
     """
     Checks if the given entity is marked with status NEW. Returns `False`
     if the entity has no state information.
     """
     try:
         result = EntityState.get_state(entity).status == ENTITY_STATUS.NEW
     except ValueError:
         result = False
     return result
예제 #23
0
파일: test_state.py 프로젝트: b8va/everest
 def test_state_data(self):
     data = dict(text='FOO',
                 number=-1,
                 parent=MyEntityParent(),
                 children=[MyEntityChild()])
     entity = MyEntity(**data)
     # We don't want to test the required unit of work here.
     uow = MagicMock()
     self.assert_raises(ValueError, EntityState.get_state, entity)
     entity.__everest__ = EntityState(entity, uow)
     state_data = EntityState.get_state(entity).data
     for attr, value in state_data.items():
         if attr.resource_attr == 'number':
             number_attr = attr
         elif attr.resource_attr == 'parent':
             parent_attr = attr
         elif attr.resource_attr == 'parent_text':
             parent_text_attr = attr
         if attr.resource_attr in data:
             self.assert_equal(value, data[attr.resource_attr])
     new_number = -2
     state_data[number_attr] = new_number
     EntityState.get_state(entity).data = state_data
     self.assert_equal(entity.number, new_number)
     new_entity = MyEntity()
     self.assert_not_equal(new_entity.number, new_number)
     new_entity.__everest__ = EntityState(new_entity, uow)
     EntityState.transfer_state_data(entity, new_entity)
     self.assert_equal(new_entity.number, new_number)
     # Make setting invalid attribute fail.
     invalid_number_attr = terminal_attribute(str, 'grmbl')
     del state_data[number_attr]
     state_data[invalid_number_attr] = -2
     with self.assert_raises(ValueError) as cm:
         EntityState.get_state(entity).data = state_data
     self.assert_true(cm.exception.args[0].startswith('Can not set'))
     # Make set nested attribute fail.
     entity.parent = None
     del state_data[invalid_number_attr]
     del state_data[parent_attr]
     state_data[parent_text_attr] = 'FOO PARENT'
     state = EntityState.get_state(entity)
     self.assert_raises(AttributeError, setattr, state, 'data', state_data)
예제 #24
0
파일: uow.py 프로젝트: helixyte/everest
    def register_deleted(self, entity_class, entity):
        """
        Registers the given entity for the given class as DELETED.

        :raises ValueError: If the given entity already holds state that was
          created by another Unit Of Work.
        """
        EntityState.manage(entity, self)
        EntityState.get_state(entity).status = ENTITY_STATUS.DELETED
        self.__entity_set_map[entity_class].add(entity)
예제 #25
0
파일: uow.py 프로젝트: b8va/everest
 def is_marked_pending(self, entity):
     """
     Checks if the flag indicating that the state for the given entity
     has been persisted is `False`. Returns `False` if the entity has no
     state information.
     """
     try:
         result = not EntityState.get_state(entity).is_persisted
     except ValueError:
         result = False
     return result
예제 #26
0
 def test_basics(self):
     ent = _MyEntity(id=0)
     self._uow.register_new(_MyEntity, ent)
     self.assert_equal(EntityState.get_state(ent).status, ENTITY_STATUS.NEW)
     self.assert_equal([item.entity for item in self._uow.iterator()],
                       [ent])
     self.assert_equal(list(self._uow.get_new(_MyEntity)), [ent])
     self._uow.mark_clean(ent)
     self.assert_equal(list(self._uow.get_clean(_MyEntity)), [ent])
     self._uow.mark_dirty(ent)
     self.assert_equal(list(self._uow.get_dirty(_MyEntity)), [ent])
     self._uow.mark_deleted(ent)
     self.assert_equal(list(self._uow.get_deleted(_MyEntity)), [ent])
     self._uow.unregister(_MyEntity, ent)
     self.assert_equal(list(self._uow.iterator()), [])
     self._uow.reset()
예제 #27
0
파일: test_uow.py 프로젝트: b8va/everest
 def test_basics(self):
     ent = _MyEntity(id=0)
     self._uow.register_new(_MyEntity, ent)
     self.assert_equal(EntityState.get_state(ent).status,
                       ENTITY_STATUS.NEW)
     self.assert_equal([item.entity for item in self._uow.iterator()],
                       [ent])
     self.assert_equal(list(self._uow.get_new(_MyEntity)), [ent])
     self._uow.mark_clean(ent)
     self.assert_equal(list(self._uow.get_clean(_MyEntity)), [ent])
     self._uow.mark_dirty(ent)
     self.assert_equal(list(self._uow.get_dirty(_MyEntity)), [ent])
     self._uow.mark_deleted(ent)
     self.assert_equal(list(self._uow.get_deleted(_MyEntity)), [ent])
     self._uow.unregister(_MyEntity, ent)
     self.assert_equal(list(self._uow.iterator()), [])
     self._uow.reset()
예제 #28
0
파일: test_uow.py 프로젝트: b8va/everest
 def test_get_state_unregistered_fails(self):
     ent = _MyEntity()
     with self.assert_raises(ValueError) as cm:
         EntityState.get_state(ent)
     msg = 'Trying to obtain state for un-managed entity'
     self.assert_true(cm.exception.args[0].startswith(msg))
예제 #29
0
 def test_get_state_unregistered_fails(self):
     ent = _MyEntity()
     with self.assert_raises(ValueError) as cm:
         EntityState.get_state(ent)
     msg = 'Trying to obtain state for un-managed entity'
     self.assert_true(cm.exception.args[0].startswith(msg))