[Modeling-cvs] ProjectModeling/Modeling CHANGES,1.87,1.88 EditingContext.py,1.21,1.22
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-03-27 11:48:01
|
Update of /cvsroot/modeling/ProjectModeling/Modeling In directory sc8-pr-cvs1:/tmp/cvs-serv15541 Modified Files: CHANGES EditingContext.py Log Message: Fixed: an newly inserted object with a PK attribute marked as class property did not get its value after EditingContext.saveChanges(). Details in: - EditingContext.handleNotification() - test_EC_Global.test_17_insertedObject_and_PK_as_classProperty() - testPackages.AuthorBooks: entity Book now has its PK 'id' set as class property Index: CHANGES =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/CHANGES,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** CHANGES 17 Mar 2003 12:43:22 -0000 1.87 --- CHANGES 27 Mar 2003 11:47:57 -0000 1.88 *************** *** 8,11 **** --- 8,15 ---- -------------------------------------------------------- + * Fixed: an newly inserted object with a PK, say, 'id', marked as class + property did not get its value after EditingContext.saveChanges(). + [Details in: EditingContext.handleNotification()] + * Fixed SQLExpression.sqlStringForAttributeNamed(): now raises ValueError with an explicit message when it receives an invalid attribute's name Index: EditingContext.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/EditingContext.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** EditingContext.py 12 Mar 2003 15:45:54 -0000 1.21 --- EditingContext.py 27 Mar 2003 11:47:57 -0000 1.22 *************** *** 1361,1364 **** --- 1361,1390 ---- db=self.rootObjectStore().objectStoreForObject(obj).database() db.incrementSnapshotCountForGlobalID(key_gid) + + # Time to update the object if a PK is set as class properties + + # Note: One might say this could have been done earlier, e.g. in + # DatabaseContext.prepareForSaveWithCoordinator() where PK values + # are requested and assigned to the inserted objects + + # THIS IS INTENTIONAL: until finalizeCommitChanges() is called by + # the ObjectStoreCoordinator, we can't be sure that no exception + # will be raised in the process of saving changes. If an exception + # is actually raised, the transaction is rolled back and the object + # is not saved and as a consequence should NOT appear as if it + # received a valid PK value. + + # Now, since DBContext.finalizeCommitChanges() does notify the EC + # that inserted objects did receive a valid GlobalID (thus a valid + # PK value) after all changes were supplied and committed to the + # database, we know it is safe here to assign the inserted & saved + # object its PK value --if the PK is a class property, obviously! + + from ModelSet import defaultModelSet + entity=defaultModelSet().entityNamed(obj.entityName()) + pk_values=key_gid.keyValues() + for pk in entity.primaryKeyAttributes(): + if pk.isClassProperty(): + obj.takeStoredValueForKey(pk_values[pk.name()], pk.name()) else: obj=self.objectForGlobalID(gid) |