Exemple #1
0
	def destroy(self, storable, destroy_related_storables=False):
		"""
		Destroy the provided Storable.
		
		@see: L{IFactory.destroy()}
		
		@param storable: the object you wish to destroy
		@type storable: L{storable.Storable}
		
		@param destroy_related_storables: should the items returned by
			L{Storable.get_related_storables()} be automatically destroyed?
		@type destroy_related_storables: bool
		"""
		if not(storable.is_new()):
			child_list = storable.get_related_storables()
			id_list = []
			while(child_list and destroy_related_storables):
				child = child_list.pop()
				child_id = self.fetch_id(child)
				child_table = child.get_table()
				if(child_table not in self._factories):
					raise LookupError('There is no factory registered for the table `%s`' % child_table)
				factory = self._factories[child_table]
				if(child_id in id_list and factory.uses_guids()):
					#raise AssertionError('Found circular storable reference during destroy')
					continue
				child_list.extend(child.get_related_storables())
				self._destroy(child)
				id_list.append(child_id)
			self._destroy(storable)
Exemple #2
0
	def save(self, storable, save_related_storables=True):
		"""
		Save the provided Storable.
		
		@see: L{IFactory.save()}
		
		@param storable: the object you wish to save
		@type storable: L{storable.Storable}
		
		@param save_related_storables: should the items returned by
			L{Storable.get_related_storables()} be automatically saved?
		@type save_related_storables: bool
		
		@raises LookupError: if no factory has been registered for this Storable's table
		"""
		table = storable.get_table()
		if(table not in self._factories):
			raise LookupError('There is no factory registered for the table `%s`' % table)
		factory = self._factories[table]
		
		result = self._save(storable, factory)
		
		child_list = storable.get_related_storables()
		id_list = []
		while(child_list and save_related_storables):
			child = child_list.pop()
			child_id = self.fetch_id(child)
			child_table = child.get_table()
			if(child_table not in self._factories):
				raise LookupError('There is no factory registered for the table `%s`' % child_table)
			factory = self._factories[child_table]
			if(child_id in id_list and factory.uses_guids()):
				#raise AssertionError('Found circular storable reference during save')
				continue
			result = result and self._save(child, factory)
			child_list.extend(child.get_related_storables())
			id_list.append(child_id)
		
		return result