src/ztfy/utils/zodb.py
branchZTK-1.1
changeset 179 612a350cc660
parent 176 a7275e2a9252
child 181 3bdaee25ec3a
equal deleted inserted replaced
177:b9ad5a9614c4 179:612a350cc660
    43 class ZEOConnectionInfo(object):
    43 class ZEOConnectionInfo(object):
    44     """ZEO connection info"""
    44     """ZEO connection info"""
    45 
    45 
    46     implements(IZEOConnection)
    46     implements(IZEOConnection)
    47 
    47 
       
    48     _storage = None
       
    49     _db = None
       
    50     _connection = None
       
    51 
    48     server_name = FieldProperty(IZEOConnection['server_name'])
    52     server_name = FieldProperty(IZEOConnection['server_name'])
    49     server_port = FieldProperty(IZEOConnection['server_port'])
    53     server_port = FieldProperty(IZEOConnection['server_port'])
    50     storage = FieldProperty(IZEOConnection['storage'])
    54     storage = FieldProperty(IZEOConnection['storage'])
    51     username = FieldProperty(IZEOConnection['username'])
    55     username = FieldProperty(IZEOConnection['username'])
    52     password = FieldProperty(IZEOConnection['password'])
    56     password = FieldProperty(IZEOConnection['password'])
    77                                               shared_blob_dir=self.shared_blob_dir,
    81                                               shared_blob_dir=self.shared_blob_dir,
    78                                               wait=wait)
    82                                               wait=wait)
    79         db = DB(storage)
    83         db = DB(storage)
    80         return (storage, db) if get_storage else db
    84         return (storage, db) if get_storage else db
    81 
    85 
       
    86     @property
       
    87     def connection(self):
       
    88         return self._connection
       
    89 
       
    90     def __enter__(self):
       
    91         self._storage, self._db = self.getConnection(get_storage=True)
       
    92         self._connection = self._db.open()
       
    93         return self
       
    94 
       
    95     def __exit__(self, exc_type, exc_value, traceback):
       
    96         if self._connection is not None:
       
    97             self._connection.close()
       
    98         if self._storage is not None:
       
    99             self._storage.close()
       
   100 
    82 
   101 
    83 class ZEOConnectionUtility(ZEOConnectionInfo, Persistent, Contained):
   102 class ZEOConnectionUtility(ZEOConnectionInfo, Persistent, Contained):
    84     """Persistent ZEO connection settings utility"""
   103     """Persistent ZEO connection settings utility"""
    85 
   104 
    86 
   105