Update of /cvsroot/webware/Webware/MiddleKit/Run
In directory usw-pr-cvs1:/tmp/cvs-serv15692/Run
Modified Files:
ObjectStore.py
Log Message:
get rid of double doDeleteObject() work. turn verbose delete prints off by default
Index: ObjectStore.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Run/ObjectStore.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** ObjectStore.py 15 Mar 2002 22:04:48 -0000 1.15
--- ObjectStore.py 16 Mar 2002 19:29:48 -0000 1.16
***************
*** 79,82 ****
--- 79,83 ----
self._changedObjects = {} # a set
self._newSerialNum = -1
+ self._verboseDelete = 0
***************
*** 126,130 ****
# Recursively add referenced objects to the store
object.addReferencedObjectsToStore(self)
!
# 2000-10-07 ce: Decided not to allow keys for non-persisted objects
# Because the serial num, and therefore the key, will change
--- 127,131 ----
# Recursively add referenced objects to the store
object.addReferencedObjectsToStore(self)
!
# 2000-10-07 ce: Decided not to allow keys for non-persisted objects
# Because the serial num, and therefore the key, will change
***************
*** 136,156 ****
#self._objects[key] = object
! def deleteObject(self, object, checkOnly=0):
"""
Restrictions: The object must be contained in the store and obviously
! you cannot remove it more than once. If checkOnly is true, then
! only do the check, don't actually change anything.
"""
# First check if the delete is possible. Then do the actual delete. This avoids partially deleting
# objects only to have an exception halt the process in the middle.
! self.doDeleteObject(object, 1)
! if not checkOnly:
! self.doDeleteObject(object, 0)
!
! def doDeleteObject(self, object, checkOnly, cascaded=[]):
"""
! Do the work of deleting the object. If checkOnly is true then only do the checks, don't actually delete anything.
! If checkOnly is false then go ahead and delete, assuming all checks have already been done.
! cascaded is a list of objects that have already been deleted higher up in a cascade-delete.
"""
# Some basic assertions
--- 137,168 ----
#self._objects[key] = object
! def deleteObject(self, object):
"""
Restrictions: The object must be contained in the store and obviously
! you cannot remove it more than once.
"""
# First check if the delete is possible. Then do the actual delete. This avoids partially deleting
# objects only to have an exception halt the process in the middle.
! objectsToDel = []
! detaches = []
! self._deleteObject(object, objectsToDel, detaches)
! self.willChange()
! self._deletedObjects.extend(objectsToDel)
! for obj in objectsToDel:
! del self._objects[obj.key()]
! for obj, attr in detaches:
! setattr(obj, '_'+attr.name(), None)
! # Can't use setValueForAttr() because that invokes the setter method which will raise an exception if the attribute is required.
! #obj.setValueForAttr(attr, None)
!
! def _deleteObject(self, object, objectsToDel, detaches, superobject=None):
"""
! Compile the list of objects to be deleted. This is a recursive
! method since deleting one object might be deleting others.
!
! object - the object to delete
! objectsToDel - a running list of all objects to delete
! detaches - a running list of all detaches (eg, obj.attr=None)
! superobject - the object that was the cause of this invocation
"""
# Some basic assertions
***************
*** 158,170 ****
assert object.key() is not None
! if cascaded:
! cascadeString = 'cascade-'
! dueTo = ' due to deletion of ' + ', '.join(['%s.%d' % (o.klass().name(), o.serialNum()) for o in cascaded])
! else:
! cascadeString = dueTo = ''
! if checkOnly:
print 'checking %sdelete of %s.%d%s' % (cascadeString, object.klass().name(), object.serialNum(), dueTo)
! else:
! print '%sdeleting %s.%d%s' % (cascadeString, object.klass().name(), object.serialNum(), dueTo)
# Deal with all other objects that reference or are referenced by this object. By default, you are not allowed
--- 170,184 ----
assert object.key() is not None
! v = self._verboseDelete
!
! if v:
! if superobject:
! cascadeString = 'cascade-'
! dueTo = ' due to deletion of %s.%i' % (superobject.klass().name(), superobject.serialNum())
! else:
! cascadeString = dueTo = ''
print 'checking %sdelete of %s.%d%s' % (cascadeString, object.klass().name(), object.serialNum(), dueTo)
!
! objectsToDel.append(object)
# Deal with all other objects that reference or are referenced by this object. By default, you are not allowed
***************
*** 181,185 ****
referencingObjectsAndAttrs = object.referencingObjectsAndAttrs()
# Remove from that list anything in the cascaded list
! referencingObjectsAndAttrs = [(o,a) for o,a in referencingObjectsAndAttrs if o not in cascaded]
# Determine all referenced objects, constructing a list of (attr, referencedObject) tuples.
--- 195,199 ----
referencingObjectsAndAttrs = object.referencingObjectsAndAttrs()
# Remove from that list anything in the cascaded list
! referencingObjectsAndAttrs = [(o,a) for o,a in referencingObjectsAndAttrs if o not in objectsToDel]
# Determine all referenced objects, constructing a list of (attr, referencedObject) tuples.
***************
*** 194,198 ****
referencedAttrsAndObjects.append((attr, obj))
# Remove from that list anything in the cascaded list
! referencedAttrsAndObjects = [(a,o) for a,o in referencedAttrsAndObjects if o not in cascaded]
# Check for onDeleteOther=deny
--- 208,212 ----
referencedAttrsAndObjects.append((attr, obj))
# Remove from that list anything in the cascaded list
! referencedAttrsAndObjects = [(a,o) for a,o in referencedAttrsAndObjects if o not in objectsToDel]
# Check for onDeleteOther=deny
***************
*** 228,232 ****
onDeleteOther = referencingAttr.get('onDeleteOther', 'deny')
if onDeleteOther == 'cascade':
! self.doDeleteObject(referencingObject, checkOnly=checkOnly, cascaded=cascaded+[object])
# Check if it's possible to cascade-delete objects with onDeleteSelf=cascade
--- 242,246 ----
onDeleteOther = referencingAttr.get('onDeleteOther', 'deny')
if onDeleteOther == 'cascade':
! self._deleteObject(referencingObject, objectsToDel, detaches, object)
# Check if it's possible to cascade-delete objects with onDeleteSelf=cascade
***************
*** 234,257 ****
onDeleteSelf = referencedAttr.get('onDeleteSelf', 'detach')
if onDeleteSelf == 'cascade':
! self.doDeleteObject(referencedObject, checkOnly=checkOnly, cascaded=cascaded+[object])
# Detach objects with onDeleteOther=detach
! if not checkOnly:
! for referencingObject, referencingAttr in referencingObjectsAndAttrs:
! onDeleteOther = referencingAttr.get('onDeleteOther', 'deny')
! if onDeleteOther == 'detach':
! print 'setting %s.%d.%s to None' % (referencingObject.klass().name(), referencingObject.serialNum(), referencingAttr.name())
! setattr(referencingObject, '_'+referencingAttr.name(), None)
! # Can't use setValueForAttr() because that invokes the setter method which will raise an exception if the attribute is required.
! #referencingObject.setValueForAttr(referencingAttr, None)
# Detach objects with onDeleteSelf=detach
# This is actually a no-op. There is nothing that needs to be set to zero.
-
- # Ok, now that that's all taken care of, do the delete of this object.
- if not checkOnly:
- self.willChange()
- self._deletedObjects.append(object)
- del self._objects[object.key()]
--- 248,262 ----
onDeleteSelf = referencedAttr.get('onDeleteSelf', 'detach')
if onDeleteSelf == 'cascade':
! self._deleteObject(referencedObject, objectsToDel, detaches, object)
# Detach objects with onDeleteOther=detach
! for referencingObject, referencingAttr in referencingObjectsAndAttrs:
! onDeleteOther = referencingAttr.get('onDeleteOther', 'deny')
! if onDeleteOther == 'detach':
! if v: print 'will set %s.%d.%s to None' % (referencingObject.klass().name(), referencingObject.serialNum(), referencingAttr.name())
! detaches.append((referencingObject, referencingAttr))
# Detach objects with onDeleteSelf=detach
# This is actually a no-op. There is nothing that needs to be set to zero.
|