# -*- 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.
#-----------------------------------------------------------------------------
"""
GlobalID API
This interface defines the API of classes GlobalID and TemporaryGlobalID.
Notification:
'GlobalIDChangedNotification' -- Posted by objects which change
'TemporaryGlobalID' to 'KeyGlobalID' ; notification contains the following
fileds: object: 'None', userInfo: a dictionary mapping temporary global
ids to their corresponding 'KeyGlobalID'
CVS information
$Id: GlobalID.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
try:
from Interface import Base
except:
class Base:
pass
def globalIDWithEntityName(entityName, informations):
"""
Returns a new GlobalID based on the supplied informations.
Parameter 'informations' can be either:
- None, in which case a 'TemporaryGlobalID' is returned, or
- an object implementing XXX,
- a dictionary '{PK_name: value}', containing all entities' PKs
In the two latter cases a 'KeyGlobalID' is returned.
"""
class GlobalIDInterface(Base):
"""
GlobalID
A GlobalID uniquely identifies an object. It is used within EditingContexts
so that objects are kept unique.
More precisely, a object fetched from a database (either ZODB or --later--
any other DB) will be referenced by the same GlobalID in every
EditingContexts it is referenced into, wherever these EditingContexts were
instanciated, i.e. they could be within the same application/process or even
distributed over the network (with multiple application instances, for
load-balancing e.g.).
On the other hand, a newly created object which has not been stored yet will
receive a TemporaryGlobalID. This temporary global ID will be turned into
a solid GlobalID as soon as it is made persistent.
Implemented by: KeyGlobalID, TemporaryGlobalID
"""
def __init__(self, entityName, informations):
"""
(called by 'globalIDWithEntityName()')
"""
# NB: do we need to add this to the root interface??
# only if a TemporaryGlobalID is a valid object to be passed along with
# the ObjectStoreCoordinator.CooperatingObjectStoreWasAddedNotification
#def entityName(self):
# "Returns the name of the underlying entity"
def isTemporary(self):
"""
Returns 'true' if the receiver is a TemporaryGlobalID, 'false' otherwise
"""
def __str__(self):
"""
Returns a string representation of the GlobalID. This string representation
has the same properties as a GlobalID in terms of uniquing.
"""
class IKeyGlobalID(GlobalIDInterface):
"""
KeyGlobalID
Implements: GlobalIDInterface
You should not create a GlobalID by yourself. Instead, use:
- either 'globalIDWithEntityName()',
- or (better) Entity.globalIDForRow() __TBD
"""
def __init__(self, entityName, keyValues):
"""
Initializes a KeyGlobalID with the following parameters:
- 'entityName' ('string')
- 'keyValues' ('dictionary'), a mapping between PKs' names and values.
"""
class ITemporaryGlobalID(GlobalIDInterface):
"""
TemporaryGlobalID
Implements: GlobalIDInterface
You should not create a GlobalID by yourself. Instead, use:
- either 'globalIDWithEntityName()',
- or (better) Entity.globalIDForRow() __TBD
"""
def __init__(self, *args, **kw):
"""
NB: all arguments are ignored.
__TBD
"""
def __str__(self):
"""
Returns a string representation of the GlobalID. This string representation
is unique among GlobalIDs.
"""
|