Changeset 3093

Show
Ignore:
Timestamp:
04/27/07 12:53:21 (2 years ago)
Author:
ed
Message:

Factored out the code that handles connections from init() to a separate 'setConnection()' method.

Files:

Legend:

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

    r3074 r3093  
    1818 
    1919 
    20     def __init__(self, conn, properties=None, *args, **kwargs): 
     20    def __init__(self, conn=None, properties=None, *args, **kwargs): 
    2121        """ User code should override beforeInit() and/or afterInit() instead.""" 
    2222        self.__att_try_setFieldVal = False 
     
    3232 
    3333        self._beforeInit() 
    34         cf = self._cursorFactory = conn 
    35         if cf: 
    36             # Base cursor class : the cursor class from the db api 
    37             self.dbapiCursorClass = cf.getDictCursorClass() 
    38  
    39             # If there are any problems in the createCursor process, an 
    40             # exception will be raised in that method. 
    41             self.createCursor() 
    42  
     34        self.setConnection(conn) 
    4335        # We need to make sure the cursor is created *before* the call to 
    4436        # initProperties() 
     
    9890 
    9991        self.beforeInit() 
     92 
     93 
     94    def setConnection(self, conn): 
     95        """Normally connections are established before bizobj creation, but  
     96        for those cases where connections are created later, use this method to  
     97        establish the connection used by the bizobj. 
     98        """ 
     99        self._cursorFactory = conn 
     100        if conn: 
     101            # Base cursor class : the cursor class from the db api 
     102            self.dbapiCursorClass = self._cursorFactory.getDictCursorClass() 
     103            # If there are any problems in the createCursor process, an 
     104            # exception will be raised in that method. 
     105            self.createCursor() 
    100106 
    101107