# -*- 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.
#-----------------------------------------------------------------------------
"""
AdaptorOperation
CVS information
$Id: AdaptorOperation.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
from DatabaseOperation import \
ADAPTOR_LOCK_OPERATOR,\
ADAPTOR_INSERT_OPERATOR,\
ADAPTOR_UPDATE_OPERATOR,\
ADAPTOR_DELETE_OPERATOR,\
ADAPTOR_STORED_PROCEDURE_OPERATOR,\
ADAPTOR_OPERATORS
#
class AdaptorOperation:
"""
"""
def __init__(self, anEntity, adaptorOperator):
"""
"""
self.__entity=anEntity
self.setAdaptorOperator(adaptorOperator)
self.__changedValues=None
self.__qualifier=None
def adaptorOperator(self):
"""
Returns the type of the operation the AdaptorOperation performs
"""
return self.__operator
def attributes(self):
"""
__TBD for lock only
"""
self.__unimplemented__()
def changedValues(self):
"""
See setChangedValues() for details
"""
return self.__changedValues
def entity(self):
"""
Returns the Entity corresponding to the object concerned by this
AdaptorOperation.
See also: setEntity()
"""
return self.__entity
def exception(self):
"""
"""
def qualifier(self):
"""
Returns the qualifier that should be used for LOCK, UPDATE or DELETE
operations.
See also: setQualifier()
"""
return self.__qualifier
def setAdaptorOperator(self, anAdaptorOperator):
"""
Sets the type of the operation the AdaptorOperation performs
Raises ValueError in anAdaptorOperator is not in ADAPTOR_OPERATORS.
"""
if anAdaptorOperator not in ADAPTOR_OPERATORS:
raise ValueError, 'Invalid adaptor operator (%s)'%str(anAdaptorOperator)
self.__operator=anAdaptorOperator
def setAttributes(self, attributes):
"""
__TBD for lock only
"""
self.__unimplemented__()
def setChangedValues(self, changedValues):
"""
INSERT: the full set of value to be inserted within the underlying database
UPDATE: the values to changed
LOCK: the values to be compared with the row in the database
Parameter:
changedValues -- a dictionary made of attributes' names and their
corresponding values.
"""
self.__changedValues=changedValues
def setException(self, anException):
"""
"""
self.__unimplemented__()
def setQualifier(self, aQualifier):
"""
Sets the object's quelifier
Used by for LOCK, UPDATE and DELETE.
"""
self.__qualifier=aQualifier
def setStoredProcedure(self, aStoredProcedure):
"""
Unimplemented yet
"""
self.__unimplemented__()
def storedProcedure(self):
"""
Unimplemented yet
"""
self.__unimplemented__()
def __cmp__(self, anAdaptorOperation):
"""
Compares 'self' to 'anAdaptorOperation'. Comparison is based on the
AdaptorOperations' adaptorOperators, whose order is:
LOCK, INSERT, UPDATE, DELETE, STORED_PROCEDURE (the latter is not supported
yet).
"""
return cmp(self.__operator, anAdaptorOperation.adaptorOperator())
def __str__(self):
"""
Returns a string representation for this object, made of:
'repr(self)', the operator and the entity's name.
"""
return '[%s at %s operator: %s, entity: %s]'%(str(self.__class__),
hex(id(self)),
self.__operatorToString(),
self.__entity.name())
def __repr__(self):
return self.__str__()
def __operatorToString(self):
"""
Internally used by __str__
"""
op=self.__operator
if op is ADAPTOR_LOCK_OPERATOR: return 'LOCK'
elif op is ADAPTOR_INSERT_OPERATOR: return 'INSERT'
elif op is ADAPTOR_UPDATE_OPERATOR: return 'UPDATE'
elif op is ADAPTOR_DELETE_OPERATOR: return 'DELETE'
elif op is ADAPTOR_STORED_PROCEDURE_OPERATOR: return 'STORED_PROCEDURE'
else: return '<Unknown operator>'
def __unimplemented__(self):
"-"
raise 'Unimplemented'
|