# -*- 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.
#-----------------------------------------------------------------------------
"""
EditingContext API
CVS information
$Id: EditingContext.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
try:
from Interface import Base
except:
class Base:
pass
from Modeling.interfaces.ObjectStoreInterface import ObjectStoreInterface
from Modeling.interfaces.ObservingInterface import ObservingInterface
def defaultParentObjectStore():
"""
If unset, defaults to 'CooperatingObjectStore.defaultCoordinator()'.
See EditingContext.__init__
"""
def setDefaultParentObjectStore():
"""
Returns the parent 'ObjectStore' to be used by EditingContexts.
See EditingContext.__init__
"""
class IEditingContext(ObjectStoreInterface, ObservingInterface):
"""
EditingContext: an in-memory world/graph of objects, with the ability
to ensure its own persistance, to check its consistency, etc.
"""
# initializer
def __init__(self, parentObjectStore=None):
"""
Initializes an 'EditingContext'.
Parameter 'parentObjectStore'
determines which 'ObjectStore' the receiver will use to fetch its data
and to save changes made in it ; the default (i.e. when the parameter is
omitted or equals to 'None') is to use the one returned by
'defaultParentObjectStore()' --which in turn defaults to the
application-wide shared 'CooperatingObjectStore.defaultCoordinator()'.
Note that the parent 'ObjectStore' of an 'EditingContext' cannot be
changed during the whole object's lifetime.
You will typically use the default behaviour, or provide an parent
'EditingContext' to make the newly created 'EditingContext' a child of
the former one (not supported yet __TBD).
"""
# Changes within the editing context
def deletedObjects(self):
"""
"""
def insertedObjects(self):
"""
"""
def updatedObjects(self):
"""
"""
def hasChanges(self):
"""
"""
# Processing changes
def saveChanges(self):
"""
"""
# Object identification
def objectForGlobalID(self, aGlobalID):
"""
Returns the object corresponding to the given 'aGlobalID', or 'None' if
it cannot be found in the receiver's uniquing table.
"""
def globalIDForObject(self, anObject):
"""
Returns the GlobalID for 'anObject', or 'None' if 'anObject' is not
under the receiver's control.
"""
# Object and graph of objects manipulation
def deleteObject(self, anObject):
"""
Informs the 'EditingContext' that the supplied object should be marked as
deleted, so that it will actually be deleted when the receiver saves
changes. This is n ot an error to mark an object as deleted more than
once: this will be silently ignored.
Parameter 'anObject' should already be registered within the
'EditingContext' ; if not, 'ValueError' is raised.
"""
def forgetObject(self, aDatabaseObject):
"""
_TBD
Do not call this: for internal use.
"""
def insertObject(self, anObject):
"""
Inserts a new object within the graph of objects. The 'EditingContext'
builds a 'TemporaryGlobalID' for that object, registers the object as
a new one in its graph of objects and registers itself as an observer for
that object (see ObserverCenter).
An object should not be inserted more than once. The only valid situation
where an object can be re-inserted is when this object has previously been
marked as deleted (hence un-deleting the object), otherwise 'ValueError'
is raised.
"""
def insertObjectWithGlobalID(self, anObject, aTemporaryGlobalID):
"""
You should normally not call this method directly.
Parameter 'aTemporaryGlobalID' must respond 'true' to message 'isTemporary'
(raises 'ValueError' otherwise)
"""
def recordObject(self, anObject, aGlobalID):
"""
"""
def registeredObjects(self):
"Returns all objects managed by the EditingContext"
# ObjectStore hierarchy related methods
def parentObjectStore(self):
"""
Returns the parent ObjectStore for the receiver
See the initializer '__init__' for details ; note that the parent
ObjectStore cannot be changed during the whole object's lifetime.
"""
# ObjectStore API
def initializeObject(self, anObject, aGlobalID, anEditingContext):
"""
Forwards the message to the parentObjectStore(), with the following
exception: if 'anEditingContext' 's 'parentObjectStore()' is 'self', i.e.
it is a child of 'self', and if 'self' already has an real object (not a
fault) with that globalID, the values of this object is used to initialize
'anObject'.
Conformance to the ObjectStore API
Parameters:
anObject -- a DatabaseObject instance
aGlobalID -- the GlobalID of 'anObject'
anEditingContext -- the EditingContext which holds 'anObject'
"""
def objectsWithFetchSpecification(self, aFetchSpecification,
anEditingContext=None):
"""
If parameter 'anEditingContext' is omitted or 'None', it defaults to
'self', then the message is forwarded down the hierarchy of ObjectStores,
i.e. to the 'parentObjectStore()'
Conformance to the ObjectStore API
"""
def rootObjectStore(self):
"""
Returns the 'ObjectStoreCoordinator' in the underlying hierarchy of
'ObjectStore'.
Works by forwarding the 'rootObjectStore' message to the
'parentObjectStore()'.
Conformance to the ObjectStore API
"""
# ObservingInterface
def objectWillChange(self, anObject):
"""
ObservingInterface implementation
"""
# Behaviour when garbage-collected
def invalidatesObjectsWhenFinalized(self):
"""
default==true==when finalized, sends 'clearProperties' to all objects
"""
def setInvalidatesObjectsWhenFinalized(self, aBool):
"-"
def __del__(self):
"cf. invalidatesObjectsWhenFinalized()"
|