Changeset 3209

Show
Ignore:
Timestamp:
06/23/07 10:22:52 (2 years ago)
Author:
ed
Message:

John Fabiani noticed a problem that was due to an incomplete chain of settings between the bizobj and its cursors. It was only updating one cursor at a time, instead of all cursors. This change makes sure that in any property setting of the bizobj that is passed to the cursor, it is passed to *all* cursors, not just _CurrentCursor.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/biz/dBizobj.py

    r3201 r3209  
    9292 
    9393    def setConnection(self, conn): 
    94         """Normally connections are established before bizobj creation, but  
    95         for those cases where connections are created later, use this method to  
     94        """Normally connections are established before bizobj creation, but 
     95        for those cases where connections are created later, use this method to 
    9696        establish the connection used by the bizobj. 
    9797        """ 
     
    119119        crs.setCursorFactory(cf.getCursor, cursorClass) 
    120120        return crs 
    121          
     121 
    122122 
    123123    def createCursor(self, key=None): 
     
    267267            # Tell the cursor to begin a transaction, if needed. 
    268268            cursor.beginTransaction() 
    269          
     269 
    270270        try: 
    271271            self.scanChangedRows(self.save, includeNewUnchanged=self.SaveNewUnchanged, 
     
    342342 
    343343        except dException.ConnectionLostException, e: 
    344             raise  
     344            raise 
    345345 
    346346        except dException.NoRecordsException, e: 
     
    390390            raise dException.BusinessRuleViolation, errMsg 
    391391        if ignoreNoRecords is None: 
    392             # Canceling changes when there are no records should  
     392            # Canceling changes when there are no records should 
    393393            # normally not be a problem. 
    394394            ignoreNoRecords = True 
     
    398398            child.cancelAll(ignoreNoRecords=ignoreNoRecords) 
    399399        self.afterCancel() 
    400          
    401      
     400 
     401 
    402402    def deleteAllChildren(self, startTransaction=False): 
    403403        """Delete all children associated with the current record without 
     
    464464                    child.cancelAll() 
    465465                    child.requery() 
    466                      
     466 
    467467            if startTransaction: 
    468468                cursor.commitTransaction() 
    469                  
    470             # Some backends (Firebird particularly) need to be told to write  
     469 
     470            # Some backends (Firebird particularly) need to be told to write 
    471471            # their changes even if no explicit transaction was started. 
    472472            cursor.flush() 
    473              
     473 
    474474            self.afterPointerMove() 
    475475            self.afterChange() 
     
    507507 
    508508    def getChangedRows(self, includeNewUnchanged=False): 
    509         """ Returns a list of row numbers for which isChanged() returns True. The  
    510         changes may therefore not be in the record itself, but in a dependent child  
     509        """ Returns a list of row numbers for which isChanged() returns True. The 
     510        changes may therefore not be in the record itself, but in a dependent child 
    511511        record. If includeNewUnchanged is True, the presence of a new unsaved 
    512512        record that has not been modified from its defaults will suffice to mark the 
     
    550550        """ 
    551551        return _bizIterator(self) 
    552          
    553          
     552 
     553 
    554554    def scan(self, func, *args, **kwargs): 
    555555        """Iterate over all records and apply the passed function to each. 
     
    558558 
    559559        If self.ScanRestorePosition is True, the position of the current 
    560         record in the recordset is restored after the iteration. If  
     560        record in the recordset is restored after the iteration. If 
    561561        self.ScanReverse is True, the records are processed in reverse order. 
    562562        """ 
     
    593593                        if row >= 0: 
    594594                            self.RowNumber = row 
    595                  
     595 
    596596        try: 
    597597            if self.ScanReverse: 
     
    606606            raise 
    607607        restorePosition() 
    608          
     608 
    609609 
    610610    def scanChangedRows(self, func, allCursors=False, includeNewUnchanged=False, 
     
    612612        """Move the record pointer to each changed row, and call func. 
    613613 
    614         If allCursors is True, all other cursors for different parent records will  
     614        If allCursors is True, all other cursors for different parent records will 
    615615        be iterated as well. 
    616          
     616 
    617617        If includeNewUnchanged is True, new unsaved records that have not been 
    618618        edited from their default values will be counted as 'changed'. 
     
    649649                    self._positionUsingPK(old_pk) 
    650650                    raise 
    651          
     651 
    652652        self._CurrentCursor = old_currentCursorKey 
    653653        if old_pk is not None: 
     
    761761            # we still need to pass the exception to the UI 
    762762            uiException = dException.NoRecordsException 
    763              
     763 
    764764        except dException.dException, e: 
    765765            # Something failed; reset things. 
     
    974974            # No cursor, no changes. 
    975975            return False 
    976          
     976 
    977977        if cc.isChanged(allRows=True, includeNewUnchanged=self.SaveNewUnchanged): 
    978978            return True 
    979      
     979 
    980980        # Nothing's changed in the top level, so we need to recurse the children: 
    981981        try: 
     
    984984            # If there are no records, there can be no changes 
    985985            return False 
    986              
     986 
    987987        for child in self.__children: 
    988988            if child.isAnyChanged(parentPK=pk): 
     
    10731073 
    10741074    def onNew(self): 
    1075         """Called when a new record is added.  
    1076  
    1077         Use this hook to add additional default field values, or anything else  
     1075        """Called when a new record is added. 
     1076 
     1077        Use this hook to add additional default field values, or anything else 
    10781078        you need. If you change field values here, the memento system will not 
    10791079        catch it (the record will not be marked 'dirty'). Use afterNew() if you 
     
    12231223 
    12241224    def getParentPK(self): 
    1225         """ Return the value of the parent bizobjs' PK field. 
    1226  
    1227         Alternatively, user code can just call self.Parent.getPK(). 
     1225        """ Return the value of the parent bizobjs' PK field. Alternatively,  
     1226        user code can just call self.Parent.getPK(). 
    12281227        """ 
    12291228        try: 
     
    12491248            except dException.NoRecordsException: 
    12501249                ret = False 
    1251         return ret  
     1250        return ret 
    12521251 
    12531252 
     
    14241423    def beforeCreateCursor(self): return "" 
    14251424    ########## Post-hook interface section ############## 
    1426     def afterNew(self):  
    1427         """Called after a new record is added.  
     1425    def afterNew(self): 
     1426        """Called after a new record is added. 
    14281427 
    14291428        Use this hook to change field values, or anything else you need. If you 
     
    14531452 
    14541453    def _setAutoCommit(self, val): 
    1455         self._CurrentCursor.AutoCommit = val 
     1454        for crs in self.__cursors.values(): 
     1455            crs.AutoCommit = val 
    14561456 
    14571457 
     
    14641464    def _setAutoPopulatePK(self, val): 
    14651465        self._autoPopulatePK = bool(val) 
    1466         if self._CurrentCursor
    1467             self._CurrentCursor.AutoPopulatePK = val 
     1466        for crs in self.__cursors.values()
     1467            crs.AutoPopulatePK = val 
    14681468 
    14691469 
     
    14731473    def _setAutoQuoteNames(self, val): 
    14741474        self._autoQuoteNames = val 
    1475         if self._CurrentCursor
    1476             self._CurrentCursor.AutoQuoteNames = val 
     1475        for crs in self.__cursors.values()
     1476            crs.AutoQuoteNames = val 
    14771477 
    14781478 
     
    15261526    def _setDataSource(self, val): 
    15271527        self._dataSource = str(val) 
    1528         cursor = self._CurrentCursor 
    1529         if cursor is not None: 
    1530             cursor.Table = val 
     1528        for crs in self.__cursors.values(): 
     1529            crs.Table = val 
    15311530 
    15321531 
     
    15601559 
    15611560    def _setVirtualFields(self, val): 
    1562         for key, cursor in self.__cursors.items(): 
    1563             cursor.VirtualFields = val 
     1561        for crs in self.__cursors.values(): 
     1562            crs.VirtualFields = val 
    15641563        self._virtualFields = val 
    15651564 
     
    15781577 
    15791578    def _setEncoding(self, val): 
    1580         cursor = self._CurrentCursor 
    1581         if cursor is not None: 
    1582             cursor.Encoding = val 
     1579        for crs in self.__cursors.values(): 
     1580            crs.Encoding = val 
    15831581 
    15841582 
     
    16051603    def _setKeyField(self, val): 
    16061604        self._keyField = val 
    1607         cursor = self._CurrentCursor 
    1608         if cursor is not None: 
    1609             cursor.KeyField = val 
     1605        for crs in self.__cursors.values(): 
     1606            crs.KeyField = val 
    16101607 
    16111608 
     
    16541651        if fldList is None: 
    16551652            fldList = [] 
    1656         self._CurrentCursor.setNonUpdateFields(fldList) 
     1653        for crs in self.__cursors.values(): 
     1654            crs.setNonUpdateFields(fldList) 
    16571655 
    16581656 
     
    18221820 
    18231821    AutoQuoteNames = property(_getAutoQuoteNames, _setAutoQuoteNames, None, 
    1824             _("""When True (default), table and column names are enclosed with  
     1822            _("""When True (default), table and column names are enclosed with 
    18251823            quotes during SQL creation in the cursor.  (bool)""")) 
    1826      
     1824 
    18271825    AutoSQL = property(_getAutoSQL, None, None, 
    18281826            _("Returns the SQL statement automatically generated by the sql manager.")) 
     
    18531851                1) The explicitly-set DataStructure property 
    18541852                2) The backend table method""")) 
    1855   
     1853 
    18561854    DefaultValues = property(_getDefaultValues, _setDefaultValues, None, 
    18571855            _("""A dictionary specifying default values for fields when a new record is added. 
     
    18661864    FillLinkFromParent = property(_getFillLinkFromParent, _setFillLinkFromParent, None, 
    18671865            _("""In the onNew() method, do we fill in the foreign key field specified by the 
    1868             LinkField property with the value returned by calling the bizobj's  getParentPK()  
     1866            LinkField property with the value returned by calling the bizobj's  getParentPK() 
    18691867            method? (bool)""")) 
    18701868 
     
    19011899            _("""Represents a record in the data set. You can address individual 
    19021900            columns by referring to 'self.Record.fieldName' (read-only) (no type)""")) 
    1903      
     1901 
    19041902    RequeryChildOnSave = property(_getRequeryChildOnSave, _setRequeryChildOnSave, None, 
    19051903            _("Do we requery child bizobjs after a Save()? (bool)")) 
     
    19291927 
    19301928    SaveNewUnchanged = property(_getSaveNewUnchanged, _setSaveNewUnchanged, None, 
    1931             _("""Normally new, unmodified records are not saved. If you need  
     1929            _("""Normally new, unmodified records are not saved. If you need 
    19321930            this behavior, set this to True.  (bool)""")) 
    1933      
     1931 
    19341932    ScanRestorePosition = property(_getScanRestorePosition, _setScanRestorePosition, None, 
    1935             _("""After running a scan, do we attempt to restore the record position to  
    1936             where it was before the scan (True, default), or do we leave the pointer  
     1933            _("""After running a scan, do we attempt to restore the record position to 
     1934            where it was before the scan (True, default), or do we leave the pointer 
    19371935            at the end of the recordset (False). (bool)""")) 
    1938      
     1936 
    19391937    ScanReverse = property(_getScanReverse, _setScanReverse, None, 
    19401938            _("""Do we scan the records in reverse order? (Default: False) (bool)""")) 
     
    19521950            _("""A dictionary mapping virtual_field_name to function to call. 
    19531951 
    1954             The specified function will be called when getFieldVal() is called on  
     1952            The specified function will be called when getFieldVal() is called on 
    19551953            the specified virtual field name.""")) 
    19561954 
     
    19681966        self.__nextfunc = self._prior 
    19691967        return self 
    1970          
     1968 
    19711969 
    19721970    def _prior(self): 
     
    19831981                raise StopIteration 
    19841982        return self.obj.RowNumber 
    1985                  
     1983 
    19861984 
    19871985    def _next(self): 
     
    19981996                raise StopIteration 
    19991997        return self.obj.RowNumber 
    2000      
    2001      
     1998 
     1999 
    20022000    def next(self): 
    20032001        return self.__nextfunc() 
    2004          
     2002 
    20052003 
    20062004    def __iter__(self):