[Modeling-cvs] ProjectModeling/Modeling RelationshipManipulation.py,1.3,1.4 CHANGES,1.130,1.131
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-07-23 14:50:53
|
Update of /cvsroot/modeling/ProjectModeling/Modeling
In directory sc8-pr-cvs1:/tmp/cvs-serv10135
Modified Files:
RelationshipManipulation.py CHANGES
Log Message:
module has been optimized and is now about 1.2x faster
Index: RelationshipManipulation.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/RelationshipManipulation.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** RelationshipManipulation.py 10 Jan 2003 10:45:44 -0000 1.3
--- RelationshipManipulation.py 23 Jul 2003 14:50:50 -0000 1.4
***************
*** 24,28 ****
"""
! RelationshipManipulation default implementation
This modules consists of two parts:
--- 24,29 ----
"""
! Allows the generic manipulation of objects in relation by inspecting the
! underlying model and taking appropriate actions.
This modules consists of two parts:
***************
*** 62,72 ****
##
if aKey in toManys:
! self.addObjectToPropertyWithKey(anObject, aKey)
else:
# toOne relationship: is it already set?
_selfRelObj=self.valueForKey(aKey)
if _selfRelObj: # Yes: now remove it
! self.removeObjectFromBothSidesOfRelationshipWithKey(_selfRelObj, aKey)
! self.addObjectToPropertyWithKey(anObject, aKey)
## Second step: update the other side
--- 63,74 ----
##
if aKey in toManys:
! _addObjectToPropertyWithKey(self, anObject, aKey, toOnes, toManys)
else:
# toOne relationship: is it already set?
_selfRelObj=self.valueForKey(aKey)
if _selfRelObj: # Yes: now remove it
! _removeObjectFromBothSidesOfRelationshipWithKey(self, _selfRelObj, aKey,
! toOnes, toManys)
! _addObjectToPropertyWithKey(self, anObject, aKey, toOnes, toManys)
## Second step: update the other side
***************
*** 75,82 ****
if _backRelKey is None: return
destClassDesc=self.classDescription().\
classDescriptionForDestinationKey(aKey)
if _backRelKey in destClassDesc.toManyRelationshipKeys():
! anObject.addObjectToPropertyWithKey(self, _backRelKey)
else:
# toOne relationship: is it already set?
--- 77,87 ----
if _backRelKey is None: return
+ otoOnes = anObject.classDescription().toOneRelationshipKeys()
+ otoManys = anObject.classDescription().toManyRelationshipKeys()
+
destClassDesc=self.classDescription().\
classDescriptionForDestinationKey(aKey)
if _backRelKey in destClassDesc.toManyRelationshipKeys():
! _addObjectToPropertyWithKey(anObject, self, _backRelKey, otoOnes, otoManys)
else:
# toOne relationship: is it already set?
***************
*** 85,90 ****
if _backRelObj and _backRelObj!=self:
# Yes: now remove it
! anObject.removeObjectFromBothSidesOfRelationshipWithKey(_backRelObj, _backRelKey)
! anObject.addObjectToPropertyWithKey(self, _backRelKey)
def addObjectToPropertyWithKey(self, anObject, aKey):
--- 90,95 ----
if _backRelObj and _backRelObj!=self:
# Yes: now remove it
! _removeObjectFromBothSidesOfRelationshipWithKey(anObject, _backRelObj, _backRelKey, otoOnes, otoManys)
! _addObjectToPropertyWithKey(anObject, self, _backRelKey, otoOnes, otoManys)
def addObjectToPropertyWithKey(self, anObject, aKey):
***************
*** 92,95 ****
--- 97,130 ----
toOnes = self.classDescription().toOneRelationshipKeys()
toManys = self.classDescription().toManyRelationshipKeys()
+ return _addObjectToPropertyWithKey(self, anObject, aKey, toOnes, toManys)
+
+ def removeObjectFromBothSidesOfRelationshipWithKey(self, anObject, aKey):
+ "See interfaces.RelationshipManipulating"
+ toOnes = self.classDescription().toOneRelationshipKeys()
+ toManys = self.classDescription().toManyRelationshipKeys()
+ return _removeObjectFromBothSidesOfRelationshipWithKey(self, anObject, aKey,
+ toOnes, toManys)
+
+ def removeObjectFromPropertyWithKey(self, anObject, aKey):
+ "See interfaces.RelationshipManipulating"
+ toOnes = self.classDescription().toOneRelationshipKeys()
+ toManys = self.classDescription().toManyRelationshipKeys()
+ return _removeObjectFromPropertyWithKey(self,anObject,aKey,toOnes,toManys)
+
+ def _addObjectToPropertyWithKey(self, anObject, aKey, toOnes, toManys):
+ """
+ Private method used by the methods in this module to avoid the
+ re-computation of to-one and to-many relationships when it is not necessary.
+
+ Parameters are the same as for addObjectToPropertyWithKey, with the
+ additional parameters:
+
+ toOnes -- should equal to
+ self.classDescription().toOneRelationshipKeys()
+
+ toManys -- should equal to
+ self.classDescription().toManyRelationshipKeys()
+
+ """
if aKey not in toOnes+toManys:
raise ValueError, "Key %s is not a relationship's key"%aKey
***************
*** 110,115 ****
self.takeValueForKey(tuple(values), aKey)
! def removeObjectFromBothSidesOfRelationshipWithKey(self, anObject, aKey):
! "See interfaces.RelationshipManipulating"
if anObject is None:
warn('removeObjectFromBothSidesOfRelationshipWithKey', \
--- 145,164 ----
self.takeValueForKey(tuple(values), aKey)
! def _removeObjectFromBothSidesOfRelationshipWithKey(self, anObject, aKey,
! toOnes, toManys):
! """
! Private method used by the methods in this module to avoid the
! re-computation of to-one and to-many relationships when it is not necessary.
!
! Parameters are the same as for
! removeObjectFromBothSidesOfRelationshipWithKey, with the additional
! parameters:
!
! toOnes -- should equal to self.classDescription().toOneRelationshipKeys()
!
! toManys -- should equal to
! self.classDescription().toManyRelationshipKeys()
!
! """
if anObject is None:
warn('removeObjectFromBothSidesOfRelationshipWithKey', \
***************
*** 117,122 ****
return
- toOnes = self.classDescription().toOneRelationshipKeys()
- toManys = self.classDescription().toManyRelationshipKeys()
if aKey not in toOnes+toManys:
raise ValueError, "Key %s is not a relationship"%aKey
--- 166,169 ----
***************
*** 125,129 ****
##
if aKey in toManys:
! self.removeObjectFromPropertyWithKey(anObject, aKey)
else:
# toOne: check this is the one!
--- 172,176 ----
##
if aKey in toManys:
! _removeObjectFromPropertyWithKey(self,anObject, aKey, toOnes, toManys)
else:
# toOne: check this is the one!
***************
*** 131,135 ****
raise ValueError, 'anObject %s is not set for key %s'%(repr(anObject),
aKey)
! self.addObjectToPropertyWithKey(None, aKey)
## Second step: update the other side
--- 178,182 ----
raise ValueError, 'anObject %s is not set for key %s'%(repr(anObject),
aKey)
! _addObjectToPropertyWithKey(self,None, aKey, toOnes,toManys)
## Second step: update the other side
***************
*** 150,157 ****
anObject.addObjectToPropertyWithKey(None, _backRelKey)
! def removeObjectFromPropertyWithKey(self, anObject, aKey):
! "See interfaces.RelationshipManipulating"
! toOnes = self.classDescription().toOneRelationshipKeys()
! toManys = self.classDescription().toManyRelationshipKeys()
if aKey not in toOnes+toManys:
raise ValueError, "Key %s is not a relationship's key"%aKey
--- 197,214 ----
anObject.addObjectToPropertyWithKey(None, _backRelKey)
! def _removeObjectFromPropertyWithKey(self, anObject, aKey, toOnes, toManys):
! """
! Private method used by the methods in this module to avoid the
! re-computation of to-one and to-many relationships when it is not necessary.
!
! Parameters are the same as for removeObjectFromPropertyWithKey(), with the
! additional parameters:
!
! toOnes -- should equal to self.classDescription().toOneRelationshipKeys()
!
! toManys -- should equal to
! self.classDescription().toManyRelationshipKeys()
!
! """
if aKey not in toOnes+toManys:
raise ValueError, "Key %s is not a relationship's key"%aKey
***************
*** 177,181 ****
values.remove(anObject)
self.takeValueForKey(tuple(values), aKey)
-
class RelationshipManipulation:
--- 234,237 ----
Index: CHANGES
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/CHANGES,v
retrieving revision 1.130
retrieving revision 1.131
diff -C2 -d -r1.130 -r1.131
*** CHANGES 23 Jul 2003 12:17:41 -0000 1.130
--- CHANGES 23 Jul 2003 14:50:50 -0000 1.131
***************
*** 8,11 ****
--- 8,14 ----
--------------------------------------------------------
+ * Module RelationshipManipulation has been optimized and is now about 1.2x
+ faster.
+
* Model, Entity, Attribute, Relationship, Join: replaced 'Unimplemented'
exception with NotImplementedError
|