# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""
AdaptorContext
CVS information
$Id: AdaptorContext.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
# Interfaces
from Modeling.interfaces.AdaptorContext import IAdaptorContext
# Notifications
AdaptorContextBeginTransactionNotification='AdaptorContextBeginTransactionNotification'
AdaptorContextCommitTransactionNotification='AdaptorContextCommitTransactionNotification'
AdaptorContextRollbackTransactionNotification='AdaptorContextRollbackTransactionNotification'
from NotificationFramework import NotificationCenter
NC=NotificationCenter
#
def defaultDelegate():
"See interfaces.AdaptorContext for details"
def setDefaultDelegate(aDelegate):
"See interfaces.AdaptorContext for details"
class AdaptorContext:
"See interfaces.AdaptorContext for details"
__implements__ = (IAdaptorContext,)
__raise_exception__='AbstractMethod'
__raise_msg__ ='Left intentionally unimplemented in this class, '\
'subclass should override this method'
## Attention: il y en a qui vont tre compltement rcrites et d'autres qui
## doivent faire appel l'implmentation de cette classe, donc bon.
def __init__(self, anAdaptor):
"See interfaces.AdaptorContext for details"
# internal state
self._adaptor=anAdaptor
self._channels=[]
self._delegate=defaultDelegate()
self._hasOpenTransaction=0
def adaptor(self):
"See interfaces.AdaptorContext for details"
return self._adaptor
def adaptorChannelDidClose(self, aChannel):
"""
Abstract method
See interfaces.AdaptorContext for details
"""
__abstract__()
def __addChannel__(self, aChannel):
"See interfaces.AdaptorContext for details"
if aChannel not in self._channels:
self._channels.append(aChannel)
def beginTransaction(self):
"See interfaces.AdaptorContext for details"
__abstract__()
def channels(self):
"See interfaces.AdaptorContext for details"
return tuple(self._channels)
def commitTransaction(self):
"See interfaces.AdaptorContext for details"
__abstract__()
def createAdaptorChannel(self):
"See interfaces.AdaptorContext for details"
__abstract__()
def delegate(self):
"See interfaces.AdaptorContext for details"
return self._delegate
def handleDroppedConnection(self):
"See interfaces.AdaptorContext for details"
def hasBusyChannels(self):
"See interfaces.AdaptorContext for details"
for channel in self._channels:
if channel.isFetchInProgress():
return 1
return 0
def hasOpenChannels(self):
"See interfaces.AdaptorContext for details"
for channel in self._channels:
if channel.isOpen():
return 1
return 0
def hasOpenTransaction(self):
"See interfaces.AdaptorContext for details"
return self._hasOpenTransaction
def rollbackTransaction(self):
"See interfaces.AdaptorContext for details"
__abstract__()
def setDelegate(self, aDelegate):
"See interfaces.AdaptorContext for details"
self._delegate=delegate
def transactionDidBegin(self):
"See interfaces.AdaptorContext for details"
self._hasOpenTransaction=1
NC.postNotification(AdaptorContextBeginTransactionNotification, self)
def transactionDidCommit(self):
"See interfaces.AdaptorContext for details"
self._hasOpenTransaction=0
NC.postNotification(AdaptorContextCommitTransactionNotification, self)
def transactionDidRollback(self):
"See interfaces.AdaptorContext for details"
self._hasOpenTransaction=0
NC.postNotification(AdaptorContextRollbackTransactionNotification, self)
def __abstract__():
raise 'AbstractMethod', 'Left intentionally unimplemented in this class, '\
'subclass should override this method'
|