Changeset 1911

Show
Ignore:
Timestamp:
02/08/2006 02:39:33 PM (3 years ago)
Author:
ed
Message:

Added AutoCommit? as a property.

Cleaned up irregular spacing, and alphabetized the property get/set methods.

Files:

Legend:

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

    r1910 r1911  
    1010 
    1111class dBizobj(dObject): 
    12     """ The middle tier, where the business logic resides. 
    13     """ 
     12    """ The middle tier, where the business logic resides.""" 
    1413    # Class to instantiate for the cursor object 
    1514    dCursorMixinClass = dCursorMixin 
    16  
    1715    # Need to set this here 
    1816    useFieldProps = False 
    19  
    2017    # Tell dObject that we'll call before and afterInit manually: 
    2118    _call_beforeInit, _call_afterInit, _call_initProperties = False, False, False 
     19 
    2220 
    2321    def __init__(self, conn, properties=None, *args, **kwargs): 
     
    2523        self._beforeInit() 
    2624        self._conn = conn 
     25        # Do we use autocommit for transactions? 
     26        self._autoCommit = False 
    2727 
    2828        super(dBizobj, self).__init__(properties=properties, *args, **kwargs) 
     
    121121            err = True 
    122122        if err: 
    123             raise AttributeError, " '%s' object has no attribute '%s' " % (self.__class__.__name__, att) 
     123            raise AttributeError, _(" '%s' object has no attribute '%s' ") % (self.__class__.__name__, att) 
    124124        return ret 
    125125 
     
    172172        crs.BackendObject = cn.getBackendObject() 
    173173        crs.sqlManager = self.SqlManager 
     174        crs.AutoCommit = self.AutoCommit 
    174175        crs.setSQL(self.SQL) 
    175176        if self.RequeryOnLoad: 
     
    274275        useTransact = startTransaction or topLevel 
    275276        if useTransact: 
    276             # Tell the cursor to issue a BEGIN TRANSACTION command 
     277            # Tell the cursor to begin a transaction, if needed. 
    277278            cursor.beginTransaction() 
    278279         
     
    306307        called as well.  
    307308        """ 
     309         
     310        dabo.trace() 
     311 
     312 
    308313        cursor = self._CurrentCursor 
    309314        errMsg = self.beforeSave() 
     
    312317         
    313318        if self.KeyField is None: 
    314             raise dException.dException, "No key field defined for table: " + self.DataSource 
     319            raise dException.dException, _("No key field defined for table: ") + self.DataSource 
    315320 
    316321        # Validate any changes to the data. If there is data that fails 
     
    320325        useTransact = startTransaction or topLevel 
    321326        if useTransact: 
    322             # Tell the cursor to issue a BEGIN TRANSACTION command 
     327            # Tell the cursor to begin a transaction, if needed. 
    323328            cursor.beginTransaction() 
    324329 
     
    395400 
    396401    def delete(self, startTransaction=False): 
    397         """ Delete the current row of the data set. 
    398         """ 
     402        """ Delete the current row of the data set.""" 
    399403        cursor = self._CurrentCursor 
    400404        errMsg = self.beforeDelete() 
     
    405409         
    406410        if self.KeyField is None: 
    407             raise dException.dException, "No key field defined for table: " + self.DataSource 
     411            raise dException.dException, _("No key field defined for table: ") + self.DataSource 
    408412 
    409413        if self.deleteChildLogic == k.REFINTEG_RESTRICT: 
     
    443447 
    444448    def deleteAll(self, startTransaction=False): 
    445         """ Delete all rows in the data set. 
    446         """ 
     449        """ Delete all rows in the data set.""" 
    447450        while self.RowCount > 0: 
    448451            self.first() 
     
    599602            raise dException.dException, errMsg 
    600603        if self.KeyField is None: 
    601             errMsg = "No Primary Key defined in the Bizobj for " + self.DataSource 
     604            errMsg = _("No Primary Key defined in the Bizobj for %s") % self.DataSource 
    602605            raise dException.MissingPKException, errMsg 
    603606         
     
    835838         
    836839    def onDeleteLastRecord(self): 
    837         """ Hook called when the last record has been deleted from the data set. 
    838         """ 
     840        """ Hook called when the last record has been deleted from the data set.""" 
    839841        pass 
    840842 
    841843 
    842844    def _onSaveNew(self): 
    843         """ Called after successfully saving a new record. 
    844         """ 
     845        """ Called after successfully saving a new record.""" 
    845846        # If this is a new parent record with a new auto-generated PK, pass it on 
    846847        # to the children before they save themselves. 
     
    854855 
    855856    def onSaveNew(self): 
    856         """ Hook method called after successfully saving a new record. 
    857         """ 
     857        """ Hook method called after successfully saving a new record.""" 
    858858        pass 
    859859 
     
    866866        cursor = self._CurrentCursor 
    867867        cursor.setDefaults(self.DefaultValues) 
    868          
    869868        if self.AutoPopulatePK: 
    870869            # Provide a temporary PK so that any linked children can be properly 
    871870            # identified until the record is saved and a permanent PK is obtained. 
    872871            cursor.genTempAutoPK() 
    873          
    874872        # Fill in the link to the parent record 
    875873        if self.Parent and self.FillLinkFromParent and self.LinkField: 
    876874            self.setParentFK() 
    877  
    878875        # Call the custom hook method 
    879876        self.onNew() 
     
    881878 
    882879    def onNew(self): 
    883         """ Hook method called after the default values have been set in onNew().  
    884         """ 
     880        """ Hook method called after the default values have been set in onNew().""" 
    885881        pass 
    886882 
     
    10231019 
    10241020    def getPK(self): 
    1025         """ Return the value of the PK field. 
    1026         """ 
     1021        """ Return the value of the PK field.""" 
    10271022        if self.KeyField is None: 
    1028             raise dException.dException, "No key field defined for table: " + self.DataSource 
    1029  
     1023            raise dException.dException, _("No key field defined for table: ") + self.DataSource 
    10301024        return self._CurrentCursor.getFieldVal(self.KeyField) 
    10311025 
     
    10441038 
    10451039    def getFieldVal(self, fld, row=None): 
    1046         """ Return the value of the specified field in the current or specified row.  
    1047         """ 
     1040        """ Return the value of the specified field in the current or specified row.""" 
    10481041        cursor = self._CurrentCursor 
    10491042        if cursor is not None: 
     
    10541047 
    10551048    def setFieldVal(self, fld, val): 
    1056         """ Set the value of the specified field in the current row. 
    1057         """ 
     1049        """ Set the value of the specified field in the current row.""" 
    10581050        cursor = self._CurrentCursor 
    10591051        if cursor is not None: 
     
    11291121 
    11301122    def getChildren(self): 
    1131         """ Return a tuple of the child bizobjs. 
    1132         """ 
     1123        """ Return a tuple of the child bizobjs.""" 
    11331124        ret = [] 
    11341125        for child in self.__children: 
     
    11381129     
    11391130    def getChildByDataSource(self, dataSource): 
    1140         """ Return a reference to the child bizobj with the passed dataSource. 
    1141         """ 
     1131        """ Return a reference to the child bizobj with the passed dataSource.""" 
    11421132        ret = None 
    11431133        for child in self.getChildren(): 
     
    11701160 
    11711161 
    1172     def _getNonUpdateFields(self): 
    1173         return self._CurrentCursor.getNonUpdateFields() 
    1174          
    1175     def _setNonUpdateFields(self, fldList=None): 
    1176         if fldList is None: 
    1177             fldList = [] 
    1178         self._CurrentCursor.setNonUpdateFields(fldList) 
    1179      
    11801162    def getWordMatchFormat(self): 
    11811163        return self._CurrentCursor.getWordMatchFormat() 
     
    12461228 
    12471229 
     1230    def _getAutoCommit(self): 
     1231        return self._CurrentCursor.AutoCommit 
     1232 
     1233    def _setAutoCommit(self, val): 
     1234        self._CurrentCursor.AutoCommit = val 
     1235 
     1236 
     1237    def _getAutoPopulatePK(self): 
     1238        try: 
     1239            return self._autoPopulatePK 
     1240        except AttributeError: 
     1241            return True 
     1242 
     1243    def _setAutoPopulatePK(self, val): 
     1244        self._autoPopulatePK = bool(val) 
     1245 
     1246     
    12481247    def _getAutoSQL(self): 
    12491248        try: 
     
    13211320 
    13221321 
    1323     def _getRequeryOnLoad(self): 
    1324         try: 
    1325             ret = self._requeryOnLoad 
     1322    def _getFillLinkFromParent(self): 
     1323        try: 
     1324            return self._fillLinkFromParent 
    13261325        except AttributeError: 
    1327             ret = False 
    1328         return ret 
    1329  
    1330     def _setRequeryOnLoad(self, val): 
    1331         self._requeryOnLoad = bool(val) 
    1332  
    1333          
    1334     def _getParent(self): 
    1335         try: 
    1336             return self._parent 
    1337         except AttributeError: 
    1338             return None 
    1339  
    1340     def _setParent(self, val): 
    1341         if isinstance(val, dBizobj): 
    1342             self._parent = val 
    1343         else: 
    1344             raise TypeError, "Parent must descend from dBizobj" 
    1345  
    1346              
    1347     def _getAutoPopulatePK(self): 
    1348         try: 
    1349             return self._autoPopulatePK 
    1350         except AttributeError: 
    1351             return True 
    1352  
    1353     def _setAutoPopulatePK(self, val): 
    1354         self._autoPopulatePK = bool(val) 
    1355  
    1356      
     1326            return False 
     1327 
     1328    def _setFillLinkFromParent(self, val): 
     1329        self._fillLinkFromParent = bool(val) 
     1330 
     1331         
     1332    def _isAdding(self): 
     1333        return self._CurrentCursor.IsAdding 
     1334     
     1335 
    13571336    def _getKeyField(self): 
    13581337        try: 
     
    13681347     
    13691348 
    1370     def _getLinkField(self): 
    1371         try: 
    1372             return self._linkField 
    1373         except AttributeError: 
    1374             return "" 
    1375  
    1376     def _setLinkField(self, val): 
    1377         self._linkField = str(val) 
    1378  
    1379          
    1380     def _getParentLinkField(self): 
    1381         try: 
    1382             return self._parentLinkField 
    1383         except AttributeError: 
    1384             return "" 
    1385  
    1386     def _setParentLinkField(self, val): 
    1387         self._parentLinkField = str(val) 
    1388  
    1389          
    1390     def _getRequeryChildOnSave(self): 
    1391         try: 
    1392             return self._requeryChildOnSave 
    1393         except AttributeError: 
    1394             return False 
    1395  
    1396     def _setRequeryChildOnSave(self, val): 
    1397         self._requeryChildOnSave = bool(val) 
    1398  
    1399          
    1400     def _getNewRecordOnNewParent(self): 
    1401         try: 
    1402             return self._newRecordOnNewParent 
    1403         except AttributeError: 
    1404             return False 
    1405  
    1406     def _setNewRecordOnNewParent(self, val): 
    1407         self._newRecordOnNewParent = bool(val) 
    1408  
    1409          
    1410     def _getNewChildOnNew(self): 
    1411         try: 
    1412             return self._newChildOnNew 
    1413         except AttributeError: 
    1414             return False 
    1415  
    1416     def _setNewChildOnNew(self, val): 
    1417         self._newChildOnNew = bool(val) 
    1418  
    1419                      
    1420     def _getFillLinkFromParent(self): 
    1421         try: 
    1422             return self._fillLinkFromParent 
    1423         except AttributeError: 
    1424             return False 
    1425  
    1426     def _setFillLinkFromParent(self, val): 
    1427         self._fillLinkFromParent = bool(val) 
    1428  
    1429          
    1430     def _isAdding(self): 
    1431         return self._CurrentCursor.IsAdding 
    1432      
    1433  
    14341349    def _getLastSQL(self): 
    14351350        try: 
     
    14401355             
    14411356 
     1357    def _getLinkField(self): 
     1358        try: 
     1359            return self._linkField 
     1360        except AttributeError: 
     1361            return "" 
     1362 
     1363    def _setLinkField(self, val): 
     1364        self._linkField = str(val) 
     1365 
     1366         
     1367    def _getNewChildOnNew(self): 
     1368        try: 
     1369            return self._newChildOnNew 
     1370        except AttributeError: 
     1371            return False 
     1372 
     1373    def _setNewChildOnNew(self, val): 
     1374        self._newChildOnNew = bool(val) 
     1375 
     1376                     
     1377    def _getNewRecordOnNewParent(self): 
     1378        try: 
     1379            return self._newRecordOnNewParent 
     1380        except AttributeError: 
     1381            return False 
     1382 
     1383    def _setNewRecordOnNewParent(self, val): 
     1384        self._newRecordOnNewParent = bool(val) 
     1385 
     1386         
     1387    def _getNonUpdateFields(self): 
     1388        return self._CurrentCursor.getNonUpdateFields() 
     1389         
     1390    def _setNonUpdateFields(self, fldList=None): 
     1391        if fldList is None: 
     1392            fldList = [] 
     1393        self._CurrentCursor.setNonUpdateFields(fldList) 
     1394     
     1395 
     1396    def _getParent(self): 
     1397        try: 
     1398            return self._parent 
     1399        except AttributeError: 
     1400            return None 
     1401 
     1402    def _setParent(self, val): 
     1403        if isinstance(val, dBizobj): 
     1404            self._parent = val 
     1405        else: 
     1406            raise TypeError, _("Parent must descend from dBizobj") 
     1407 
     1408             
     1409    def _getParentLinkField(self): 
     1410        try: 
     1411            return self._parentLinkField 
     1412        except AttributeError: 
     1413            return "" 
     1414 
     1415    def _setParentLinkField(self, val): 
     1416        self._parentLinkField = str(val) 
     1417 
     1418         
     1419    def _getRequeryChildOnSave(self): 
     1420        try: 
     1421            return self._requeryChildOnSave 
     1422        except AttributeError: 
     1423            return False 
     1424 
     1425    def _setRequeryChildOnSave(self, val): 
     1426        self._requeryChildOnSave = bool(val) 
     1427 
     1428         
     1429    def _getRequeryOnLoad(self): 
     1430        try: 
     1431            ret = self._requeryOnLoad 
     1432        except AttributeError: 
     1433            ret = False 
     1434        return ret 
     1435 
     1436    def _setRequeryOnLoad(self, val): 
     1437        self._requeryOnLoad = bool(val) 
     1438 
     1439         
    14421440    def _getRestorePositionOnRequery(self): 
    14431441        try: 
     
    15171515     
    15181516    ### -------------- Property Definitions ------------------  ## 
     1517    AutoCommit = property(_getAutoCommit, _setAutoCommit, None, 
     1518            _("Do we need explicit begin/commit/rollback commands for transactions?  (bool)")) 
    15191519     
    15201520    AutoPopulatePK = property(_getAutoPopulatePK, _setAutoPopulatePK, None,