[Modeling-cvs] ProjectModeling/Modeling CHANGES,1.124,1.125 DatabaseChannel.py,1.13,1.14 DatabaseCon
Status: Abandoned
Brought to you by:
sbigaret
Update of /cvsroot/modeling/ProjectModeling/Modeling In directory sc8-pr-cvs1:/tmp/cvs-serv30582 Modified Files: CHANGES DatabaseChannel.py DatabaseContext.py FetchSpecification.py ObjectStoreCoordinator.py EditingContext.py Log Message: Added the ability to fetch raw rows (dictionaries instead of fully intialized objects) --see FetchSpecification.setFetchesRawRows() and EditingContext.fetch() 's parameter 'rawRows'. Also added the possibility to turn these rows into real objects --see EditingContext.faultForRawRow() Index: CHANGES =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/CHANGES,v retrieving revision 1.124 retrieving revision 1.125 diff -C2 -d -r1.124 -r1.125 *** CHANGES 16 Jul 2003 18:45:23 -0000 1.124 --- CHANGES 16 Jul 2003 19:16:00 -0000 1.125 *************** *** 8,13 **** -------------------------------------------------------- * Added CustomObject.snapshot_raw(), support for the future ability to fetch ! raw rows (dictionaries instead of fully initialized objects) * rewrote trace() statements in QualifierParser to avoid the unnecessary --- 8,18 ---- -------------------------------------------------------- + * Added the ability to fetch raw rows (dictionaries instead of fully + intialized objects) --see FetchSpecification.setFetchesRawRows() and + EditingContext.fetch() 's parameter 'rawRows'. Also added the possibility + to turn these rows into real objects --see EditingContext.faultForRawRow() + * Added CustomObject.snapshot_raw(), support for the future ability to fetch ! raw rows (see above) * rewrote trace() statements in QualifierParser to avoid the unnecessary Index: DatabaseChannel.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseChannel.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** DatabaseChannel.py 6 May 2003 13:21:29 -0000 1.13 --- DatabaseChannel.py 16 Jul 2003 19:16:00 -0000 1.14 *************** *** 85,88 **** --- 85,89 ---- self._isLocking=0 self._refreshesRefreshedObject=0 + self._rawRows=0 def adaptorChannel(self): *************** *** 100,104 **** --- 101,109 ---- self.setCurrentEditingContext(None) self.__isFetchInProgress=0 + self._editingContext=None + self._currentEntity='' self._isLocking=0 + self._refreshesRefreshedObject=0 + self._rawRows=0 def databaseContext(self): *************** *** 108,111 **** --- 113,121 ---- return self._dbContext + def fetchesRawRows(self): + """ + """ + return self._rawRows + def fetchObject(self): """ *************** *** 141,144 **** --- 151,162 ---- globalID=self._currentEntity.globalIDForRow(dict) + if self.fetchesRawRows(): + ec=self._editingContext + object=ec.objectForGlobalID(globalID) + if object is not None: + return object.snapshot_raw() + else: + return dict + # Get snapshot #snapshot=self._currentEntity.snapshotForRow(dict) *************** *** 357,360 **** --- 375,379 ---- self.setIsLocking(aFetchSpecification.locksObjects()) self.setIsRefreshingObjects(aFetchSpecification.refreshesRefetchedObjects()) + self.setFetchesRawRow(aFetchSpecification.fetchesRawRows()) # Get an adaptorChannel if not self._adaptorChannel.isOpen(): *************** *** 384,387 **** --- 403,413 ---- self._currentEntity=anEntity + def setFetchesRawRow(self, aBool): + """ + This is automatically called by selectObjectsWithFetchSpecification(), + according to the settings of the FetchSpecification the latter method got. + """ + self._rawRows=not not aBool + def setIsLocking(self, isLocking): """ Index: DatabaseContext.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseContext.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** DatabaseContext.py 12 Jun 2003 09:35:19 -0000 1.16 --- DatabaseContext.py 16 Jul 2003 19:16:00 -0000 1.17 *************** *** 346,349 **** --- 346,350 ---- def database(self): """ + returns Database object bound to this databaseContext """ return self._database *************** *** 1214,1221 **** def faultForRawRow(self, row, entityName, anEditingContext): """ ! Unimplemented ! """ ! self.__unimplemented__() def handlesObject(self, anObject): """ --- 1215,1245 ---- def faultForRawRow(self, row, entityName, anEditingContext): """ ! Turns a row (dictionary) into a real object. Any row, such as the one ! returned by a fetch when raw rows is activated, can be turned into a ! real object given that it contains the primary keys. ! ! Parameters: ! ! row -- a dictionary. This dictionary should have the entity's primary ! keys in its keys (and their corresponding values) ! ! entityName -- the name of the entity the row represents ! ! anEditingContext -- The EditingContext in which the object should be ! registered. Defaults to self if None or omitted. + See also: EditingContext.fetch(), FetchSpecification.setFetchesRawRows + + """ + entity=self._database.entityNamed(entityName) + pks_names=entity.primaryKeyAttributeNames() + pks={} + for pk in pks_names: + if not row.has_key(pk): + raise ValueError("Cannot convert row to object: row should at least contain entity %s's primary key(s) but pk '%s' is not there"%(entityName, pk)) + pks[pk]=row[pk] + gid=KeyGlobalID(entityName, pks) + return self.faultForGlobalID(gid, anEditingContext) + def handlesObject(self, anObject): """ *************** *** 1250,1258 **** snapshot=self._database.snapshotForGlobalID(aGlobalID) - #db=self.database() - #db.incrementSnapshotCountForGlobalID(aGlobalID) - #import pdb ; pdb.set_trace() - #attrsNames=map(lambda o: o.name(), attrs) aDatabaseObject.prepareForInitializationWithKeys(classPropsNames) for attr in attrs: --- 1274,1278 ---- *************** *** 1265,1271 **** # faults initialization ! cd=aDatabaseObject.classDescription() for rel in rels: ! destCD=cd.classDescriptionForDestinationKey(rel.name()) # Now we have to initialize the object's relationships --- 1285,1292 ---- # faults initialization ! ! #cd=aDatabaseObject.classDescription() for rel in rels: ! #destCD=cd.classDescriptionForDestinationKey(rel.name()) # Now we have to initialize the object's relationships Index: FetchSpecification.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/FetchSpecification.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FetchSpecification.py 14 Mar 2003 11:40:08 -0000 1.4 --- FetchSpecification.py 16 Jul 2003 19:16:00 -0000 1.5 *************** *** 59,62 **** --- 59,63 ---- self._refreshesRefreshedObject=0 self._locksObjects=0 + self._rawRows=0 def distinctFlag(self): *************** *** 66,69 **** --- 67,73 ---- return self._entityName + def fetchesRawRows(self): + return self._rawRows + def fetchLimit(self): return self._fetchLimit *************** *** 84,87 **** --- 88,94 ---- self._entityName=entityName + def setFetchesRawRows(self, aBool): + self._rawRows=not not aBool + def setFetchLimit(self, limit): assert(limit>=0) Index: ObjectStoreCoordinator.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/ObjectStoreCoordinator.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ObjectStoreCoordinator.py 14 Mar 2003 11:40:09 -0000 1.9 --- ObjectStoreCoordinator.py 16 Jul 2003 19:16:00 -0000 1.10 *************** *** 257,269 **** Private method returning the 1st cooperating store answering positively to message 'ownsGlobalID'. Called by 'objectStoreForGlobalID'. """ ! self.lock() ! try: ! for store in self._cooperatingObjectStores: ! if store.ownsGlobalID(aGlobalID): ! return store ! return None ! finally: ! self.unlock() def objectStoreForGlobalID(self, aGlobalID): --- 257,269 ---- Private method returning the 1st cooperating store answering positively to message 'ownsGlobalID'. Called by 'objectStoreForGlobalID'. + + Note: This method does not lock self. Do not call tyis by hand in a + mutli-threaded env. + """ ! for store in self._cooperatingObjectStores: ! if store.ownsGlobalID(aGlobalID): ! return store ! return None def objectStoreForGlobalID(self, aGlobalID): *************** *** 360,364 **** """ Forwards the message to the adequate CooperatingObjectStore, usually a ! DatabaseContext, and returns the result """ self.lock() --- 360,364 ---- """ Forwards the message to the adequate CooperatingObjectStore, usually a ! DatabaseContext, and returns the result. """ self.lock() *************** *** 368,372 **** finally: self.unlock() ! def initializeObject(self, anObject, aGlobalID, anEditingContext): "See ObjectStore for details" --- 368,386 ---- finally: self.unlock() ! ! def faultForRawRow(self, row, entityName, anEditingContext): ! """ ! Forwards the message to the adequate CooperatingObjectStore, usually a ! DatabaseContext, and returns the result. ! """ ! self.lock() ! try: ! from Modeling.FetchSpecification import FetchSpecification ! fs=FetchSpecification(entityName) ! store=self.objectStoreForFetchSpecification(fs) ! return store.faultForRawRow(row, entityName, anEditingContext) ! finally: ! self.unlock() ! def initializeObject(self, anObject, aGlobalID, anEditingContext): "See ObjectStore for details" Index: EditingContext.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/EditingContext.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** EditingContext.py 16 Jul 2003 08:45:45 -0000 1.25 --- EditingContext.py 16 Jul 2003 19:16:00 -0000 1.26 *************** *** 1064,1067 **** --- 1064,1092 ---- anEditingContext) + def faultForRawRow(self, row, entityName, anEditingContext=None): + """ + Turns a row (dictionary) into a real object. Any row, such as the one + returned by a fetch when raw rows is actvated, can be turned into a + real object given that it contains the primary keys. + + Parameters: + + row -- a dictionary. This dictionary should have the entity's primary + keys in its keys (and their corresponding values) + + entityName -- the name of the entity the row represents + + anEditingContext -- (optional) The EditingContext in which the object + should be registered. Defaults to self if None or omitted. + + """ + if anEditingContext is None: + anEditingContext=self + + # no particular action for the child, faultForGlobalID() will handle + # everything automatically + return self.parentObjectStore().faultForRawRow(row, entityName, + anEditingContext) + def initializeObject(self, anObject, aGlobalID, anEditingContext): """ *************** *** 1227,1248 **** # do not include deleted objects in the returned set of objects ! if ec.isaChildOf(self): ! ! # If we're returning objects for a child's use, we remove the one ! # that are marked for deletion in the parent (self) However, the ! # deleted objects in self and the ones in the child-ec are distinct, ! # but the GlobalIDs are the same and this is what we do here: ! # compare the gIDs and remove the apropriate objects from the result ! # set ec_deletedGids=self._deletedObjects+self._pendingDeletedObjects ! objects=[o for o in objects ! if ec.globalIDForObject(o) not in ec_deletedGids] ! ! else: ! # We work for self, so we just remove the ones that are already ! # marked as deleted ! ec_deletedObjects = self.allDeletedObjects() ! objects=[o for o in objects if o not in ec_deletedObjects] ! # now append inserted objects for entityName in entitiesNames: --- 1252,1292 ---- # do not include deleted objects in the returned set of objects ! if not fs.fetchesRawRows(): ! ! #TBD Implementation note: the two blocks below (if isaChildOf/else) ! #TBD are completely equivalent. Well, at least, the first one works ! #TBD for both. Is it slower/better than ! ! if ec.isaChildOf(self): ! # If we're returning objects for a child's use, we remove the one ! # that are marked for deletion in the parent (self) However, the ! # deleted objects in self and the ones in the child-ec are distinct, ! # but the GlobalIDs are the same and this is what we do here: ! # compare the gIDs and remove the apropriate objects from the result ! # set ! ec_deletedGids=self._deletedObjects+self._pendingDeletedObjects ! objects=[o for o in objects ! if ec.globalIDForObject(o) not in ec_deletedGids] ! else: ! # We work for self, so we just remove the ones that are already ! # marked as deleted ! ec_deletedObjects = self.allDeletedObjects() ! objects=[o for o in objects if o not in ec_deletedObjects] ! ! else: # We're fetching raw rows. Wow, now we have to remove from the ! # list the dictionaries corresponding to the deleted objects. ! # Note: we use the exact same code when we're working for us (self) ! # or for a child --this is basically manipulations of ! # GlobalIDs ec_deletedGids=self._deletedObjects+self._pendingDeletedObjects ! ec_deleted_raw_pks=[gid.keyValues() for gid in ec_deletedGids] ! #if ec_deletedGids: import pdb ; pdb.set_trace() ! for deleted_raw_pk in ec_deleted_raw_pks: ! for raw_obj in list(objects): ! raw_obj_copy=raw_obj.copy() ! raw_obj_copy.update(deleted_raw_pk) ! if raw_obj_copy==raw_obj: ! objects.remove(raw_obj) ! # now append inserted objects for entityName in entitiesNames: *************** *** 1262,1265 **** --- 1306,1312 ---- objs=fault_objs + if fs.fetchesRawRows(): + objs=[o.snapshot_raw() for o in objs] + objects.extend(objs) *************** *** 1275,1278 **** --- 1322,1326 ---- #page=None, # > slice parameters, not in core yet #offset=None, # / (page/offset: mutually exclusive) + rawRows=0 # should we return raw rows ): """ *************** *** 1297,1300 **** --- 1345,1349 ---- from Modeling.FetchSpecification import FetchSpecification fs=FetchSpecification(entityName, qualifier=qualifier, deepFlag=isDeep) + fs.setFetchesRawRows(rawRows) #fs.setLocksObject(lock) #fs.setRefreshesRefetchedObjects(refresh) |