[Modeling-cvs] ProjectModeling/Modeling DatabaseContext.py,1.20,1.21
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2004-02-15 14:25:13
|
Update of /cvsroot/modeling/ProjectModeling/Modeling In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6460/Modeling Modified Files: DatabaseContext.py Log Message: Applied patch #771009: DatabaseContext.batchFetchRelationship() Index: DatabaseContext.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseContext.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** DatabaseContext.py 14 Feb 2004 18:27:03 -0000 1.20 --- DatabaseContext.py 15 Feb 2004 14:17:57 -0000 1.21 *************** *** 347,351 **** """ """ ! self.__unimplemented__() def database(self): --- 347,402 ---- """ """ ! #- fetch the objects / fire the faults, whatever ! #- get their Gids ! #- build qualifier to fetch related objects 'pk in %s'%pks ! # (cf. msg Lazy Initialization Part II) ! #- fetch related objects ! #- now we *know* we've got them all: populate them in the db cache w/ ! # Database.recordSnapshotForSourceGlobalID() ! #--> logically AccessArrayFaultHandler do not need to fetch the db any more ! if not objects: return ! ec=anEditingContext ! ! if aRelationship.isToOne(): ! src_entityName=objects[0].entityName() ! dst_pk_name=aRelationship.destinationAttributes()[0].name() ! src_gids=[o.globalID() for o in objects] ! src_fk_name=aRelationship.sourceAttributes()[0].name() ! src_fks=[self.database().snapshotForGlobalID(gid)[src_fk_name] ! for gid in src_gids] ! from Modeling.Qualifier import KeyValueQualifier, QualifierOperatorIn ! q=KeyValueQualifier(dst_pk_name, ! QualifierOperatorIn, ! src_fks) ! dst_objs=ec.fetch(aRelationship.destinationEntityName(), q) ! ! else: # to many ! src_entityName=objects[0].entityName() ! dst_attr_name=aRelationship.destinationAttributes()[0].name() ! src_gids=[o.globalID() for o in objects] ! src_pk_name=aRelationship.sourceAttributes()[0].name() ! src_pks=[gid.keyValues()[src_pk_name] for gid in src_gids] ! ! inv_rel=aRelationship.inverseRelationship() ! if inv_rel is None: # TBD: anyInverseRelationship ! raise 'aRelationship should have an inverse' ! ! from Modeling.Qualifier import KeyValueQualifier, QualifierOperatorIn ! q=KeyValueQualifier(inv_rel.name()+'.'+src_pk_name, ! QualifierOperatorIn, ! src_pks) ! dst_objs=ec.fetch(aRelationship.destinationEntityName(), q) ! db=self.database() ! d={} #key: srcGlobalID, rel: [list of rel_objs] ! for dst_obj in dst_objs: ! dst_gid=dst_obj.globalID() ! snap=db.snapshotForGlobalID(dst_gid) ! src_gid=KeyGlobalID(src_entityName, {src_pk_name: snap[dst_attr_name]}) ! l=d.setdefault(src_gid, []) ! l.append(dst_gid) ! ! rel_name=aRelationship.name() ! for src_gid in d.keys(): ! db.recordSnapshotForSourceGlobalID(d[src_gid], src_gid, rel_name) def database(self): |