Package Modeling :: Module CustomObject :: Class CustomObject
[show private | hide private]
[frames | no frames]

Type CustomObject

      KeyValueCoding --+    
                       |    
          DatabaseObject --+
                           |
                  object --+
                           |
RelationshipManipulation --+
                           |
                          CustomObject


Validation

See Validation for details

Method Summary
  __editingContext(self)
  allPropertyKeys(self)
Returns the whole set of properties, made of attributesKeys(), toManyRelationshipKeys() and toOneRelationshipKeys().
  attributesKeys(self)
Forwards the message to the object's classDescription() and returns the result.
  awakeFromFetch(self, anEditingContext)
Automatically called by the framework when an object is initialized from its database row.
  awakeFromInsertion(self, anEditingContext)
Automatically called by the framework when an object is inserted in an EditingContext.
  classDescription(self)
Returns the object's corresponding ClassDescription ; in most cases this is an EntityClassDescription instance.
  classDescriptionForDestinationKey(self, aKey)
Returns the ClassDescription used for objects that can be referenced by the relationship 'aKey'.
  deleteRuleForRelationshipKey(self, aKey)
CustomObject's implementation simply forwards the message to the underlying classDescription() and returns the result.
  editingContext(self)
Returns the EditingContext in which the object was registered, or 'None'
  entityName(self)
Returns the corresponding entity's name.
  globalID(self)
Returns the object's globalID, or None if the object is not registered within an EditingContext
  inverseForRelationshipKey(self, aKey)
CustomObject's implementation simply forwards the message to the underlying classDescription() and returns the result.
  isToManyKey(self, aKey)
  propagateDeleteWithEditingContext(self, editingContext)
Handles the deletion of the current object according to the delete rules which apply to its relationships, as defined in the model.
  propagateInsertionWithEditingContext(self, editingContext)
Called by an EditingContext when a object is marked as inserted or updated.
  snapshot(self)
Returns the snapshot for the current object, i.e.
  snapshot_raw(self)
Returns the raw snapshot for the current object, i.e.
  toManyRelationshipKeys(self)
Forwards the message to the object's classDescription() and returns the result.
  toOneRelationshipKeys(self)
Forwards the message to the object's classDescription() and returns the result.
  updateFromSnapshot(self, aSnapshotDictionary)
Given a snapshot, update the current object ; note that if the object is a fault, that fault will be cleared and the object initialized before the changes are made.
  validateForDelete(self)
Default implementation simply sends validateObjectForDelete() to the receiver's ClassDescription.
  validateForInsert(self)
Simply calls validateForSave()
  validateForSave(self)
First forwards forwards the message to the object's ClassDescription, then iterates on class properties so that they are individually checked --this is done by sending the message 'validateValueForKey()' to oneself.
  validateForUpdate(self)
Simply calls validateForSave()
  validateValueForKey(self, aValue, aKey)
Validate the value hold by 'aKey' attribute/relationship in the object.
  willChange(self)
Notifies the observers that the object is about to change.
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)
    Inherited from RelationshipManipulation
  addObjectToBothSidesOfRelationshipWithKey(self, anObject, aKey)
See interfaces.RelationshipManipulating
  addObjectToPropertyWithKey(self, anObject, aKey)
See interfaces.RelationshipManipulating
  removeObjectFromBothSidesOfRelationshipWithKey(self, anObject, aKey)
See interfaces.RelationshipManipulating
  removeObjectFromPropertyWithKey(self, anObject, aKey)
See interfaces.RelationshipManipulating
    Inherited from DatabaseObject
  attributeNameForKey(self, key)
Returns the name of the attribute corresponding to the 'key', i.e.
  classAttributeNameForKey(self, key)
Returns the name of the object's class attribute corresponding to the 'key', i.e.
  clearFault(self)
Conformance to the Faulting interface.
  clearProperties(self)
See interfaces.DatabaseObject for details
  faultHandler(self)
Conformance to the Faulting interface.
  isFault(self)
Conformance to the Faulting interface.
  prepareForInitializationWithKeys(self, keys)
Creates in 'self' the list of attributes specified by keys, if they do not already exists.
  turnIntoFault(self, aFaultHandler)
Conformance to the Faulting interface.
  willRead(self)
Conformance to the Faulting interface.
    Inherited from KeyValueCoding
  handleAssignementForUnboundKey(self, value, key)
See interfaces.KeyValueCoding for details
  handleQueryWithUnboundKey(self, key)
See interfaces.KeyValueCoding for details
  setStoredValueForKey(self, value, key)
DEPRECATED -- alias for 'takeStoredValueForKey()'
  setValueForKey(self, value, key)
DEPRECATED -- alias for takeValueForKey()
  setValueForKeyPath(self, value, keypath)
DEPRECATED -- alias for takeValueForKeyPath()
  storedValueForKey(self, key)
See interfaces.KeyValueCoding for details
  takeStoredValueForKey(self, value, key)
See interfaces.KeyValueCoding for details
  takeStoredValuesFromDictionary(self, dictionary)
See interfaces.KeyValueCoding for details
  takeValueForKey(self, value, key)
See interfaces.KeyValueCoding for details
  takeValueForKeyPath(self, value, key)
See interfaces.KeyValueCoding for details
  takeValuesFromDictionary(self, dictionary)
See interfaces.KeyValueCoding for details
  valueForKey(self, key)
See interfaces.KeyValueCoding for details
  valueForKeyPath(self, keypath)
See interfaces.KeyValueCoding for details
  valuesForKeys(self, keys)
See interfaces.KeyValueCoding for details

Class Variable Summary
tuple __implements__ = (<class Modeling.interfaces.DatabaseObj...

Method Details

allPropertyKeys(self)

Returns the whole set of properties, made of attributesKeys(), toManyRelationshipKeys() and toOneRelationshipKeys().

attributesKeys(self)

Forwards the message to the object's classDescription() and returns the result.

In most cases, if not all, the underlying classDescription() is an EntityClassDescription instance, which only returns attributes that are marked as 'class properties' in the model.

See also: toOneRelationshipKeys, toManyRelationshipKeys

awakeFromFetch(self, anEditingContext)

Automatically called by the framework when an object is initialized from its database row.

Implementation simply sends 'awakeObjectFromFetch()' to the object's class description.

Subclasses can override this method ; if they do, they must make sure that this method is called before making their own initialization.

See also: ClassDescription.awakeObjectFromFetch(), awakeFromInsertion()

awakeFromInsertion(self, anEditingContext)

Automatically called by the framework when an object is inserted in an EditingContext.

Implementation simply sends 'awakeObjectFromInsertion()' to the object's class description.

Subclasses can override this method ; if they do, they must make sure that this method is called before making their own initialization.

See also: ClassDescription.awakeObjectFromInsertion(), awakeFromFetch()

classDescription(self)

Returns the object's corresponding ClassDescription ; in most cases this is an EntityClassDescription instance.
Overrides:
Modeling.DatabaseObject.DatabaseObject.classDescription

classDescriptionForDestinationKey(self, aKey)

Returns the ClassDescription used for objects that can be referenced by the relationship 'aKey'.

CustomObject's implementation simply forwards the message to the underlying classDescription() and returns the result.

deleteRuleForRelationshipKey(self, aKey)

CustomObject's implementation simply forwards the message to the underlying classDescription() and returns the result.

editingContext(self)

Returns the EditingContext in which the object was registered, or 'None'

entityName(self)

Returns the corresponding entity's name. Note that derived objects must override this. As a reminder this method raises 'MethodShouldBeOverridden'
Overrides:
Modeling.DatabaseObject.DatabaseObject.entityName (inherited documentation)

globalID(self)

Returns the object's globalID, or None if the object is not registered within an EditingContext

inverseForRelationshipKey(self, aKey)

CustomObject's implementation simply forwards the message to the underlying classDescription() and returns the result.

Sometimes the framework is not able to calculate the correct relationship. For example, it might be that a relationship and its inverse are not based on inverse joins, such as in a one-to-one association, say between a Writer and its PostalAddress, where both relationships store the primary key of the destination entity in a foreign key of their own (I do not want to argue here about such a design, this can happen if you have to work on an existing database). In such a case, you will need to override this method so that the framework can find the inverse relationship. This could be done that way in class Writer:

def inverseForRelationshipKey(self, aKey):
  """
  Overrides CustomObject.inverseForRelationshipKey() so that
  'toPostalAddress' relationship uses the inverse relationship
  'PostalAddress.toAuthor'
  """
  if aKey=='toPostalAddress': return 'toAuthor'
  else: # call super
    return CustomObject.inverseForRelationshipKey(self, aKey)

Of course, the same needs to be done in class PostalAddress.

Overrides:
Modeling.DatabaseObject.DatabaseObject.inverseForRelationshipKey

propagateDeleteWithEditingContext(self, editingContext)

Handles the deletion of the current object according to the delete rules which apply to its relationships, as defined in the model.

CustomObject's implementation simply forwards the message to the underlying classDescription() [using propagateDeleteForObject] and returns the result.

Subclasses overriding this method should call this (superclass) method.

See also: ClassDescription.propagateDeleteForObject()
Relationship.deleteRule()

propagateInsertionWithEditingContext(self, editingContext)

Called by an EditingContext when a object is marked as inserted or updated.

CustomObject's implementation simply forwards the method to the underlying classDescription() (sending it a propagateInsertionForObject message).

Subclasses overriding this method should call this (superclass) method.

See also: ClassDescription.propagateInsertionForObject()

snapshot(self)

Returns the snapshot for the current object, i.e. a dictionary whose keys are allPropertyKeys(), and whose values are :

  • for attribute, the corresponding value,

  • for toOne relationships, the GlobalID of the related object (or None). If you want to get the real object corresponding to that global id, simply call EditingContext.faultForGlobalID() on self.editingContext().

  • For toMany relationships, the returned value depends on whether the set of related objects is still a fault or not:

    • if it is still a to-many fault, you'll get an instance of Snapshot_ToManyFault. To get the real to-many fault (instance of FaultHandler.AccessArrayFaultHandler), simply call getToManyFault() on this instance,
    • otherwise, you get the list of the GlobalIDs of the related objects

    Why are to-many faults handled this way? We do not want snapshot() to trigger any round-trip to the database. One could say, okay, but then you could return the to-many fault as well. True, but this won't be consistent with the other values returned by snapshot: values for to-one relationship are globalIDs with which you must explicitely call ec.faultForGlobalID() to get the real object. Same for to-many faults: you also need to explicitely call Snapshot_ToManyFault's getToManyFault() to get the whole (faulted) array. Last, this also prevents a to-many fault to be cleared by mistake (because simply looking at one of the fault properties, such as itys length, triggers a round-trip to the database).

Raises ObjectNotRegisteredError if the object itself is not registered in
an EditingContext, or if any of the objects it is in relation w/ is not known to the object's editingContext().

snapshot_raw(self)

Returns the raw snapshot for the current object, i.e. a dictionary whose keys are allAttributesKeys() with their corresponding values.

Special care should be taken when examining the values for primary keys and foreign keys:

  • if your object and all its related objects are already saved in the database, you'll get the PK's and FKs' values, as expected (a special case exists where a FK value can get out-of-sync, see below)
  • if your object is inserted in an EditingContext but has not been saved yet, the PK value will be its TemporaryGlobalID, since there is no way to know the value it will get when it is saved,
  • if your object has a to-one relationship to an other object that is inserted in an EditingContext but not saved yet, the FK's value will be that related object's TemporaryGlobalID --for the same reason then above.
  • Last, if the object's entity defines a foreign key involved in a to-many relationship pointing to it but with no inverse (i.e. self's entity has no to-one relationship using this foreign key), the returned value will its value stored in the Database's cache managed by the framework. In other words, this value will be exact after each saveChanges(), and the first time the object is fetched; afterwards, if the object on the other side modifies its relation pointing to 'self' (e.g. removes it), the value will be out-of-sync with the object graph and will remain as-is until the EditingContext saves its changes again.

Note: this method does not care about PKs or FKs being marked as class properties. Even when they are class properties, it does NOT look at their values, instead the returned values are extracted by examining the objects related to 'self'.

Raises ObjectNotRegisteredError if the object itself is not registered in
an EditingContext, or if any of the objects it is in relation w/ is not known to the object's editingContext().

toManyRelationshipKeys(self)

Forwards the message to the object's classDescription() and returns the result.

In most cases, if not all, the underlying classDescription() is an EntityClassDescription instance, which only returns toMany relationships that are marked as 'class properties' in the model.

See also: attributesKeys, toOneRelationshipKeys

toOneRelationshipKeys(self)

Forwards the message to the object's classDescription() and returns the result.

In most cases, if not all, the underlying classDescription() is an EntityClassDescription instance, which only returns toOne relationships that are marked as 'class properties' in the model.

See also: attributesKeys, toManyRelationshipKeys

updateFromSnapshot(self, aSnapshotDictionary)

Given a snapshot, update the current object ; note that if the object is a fault, that fault will be cleared and the object initialized before the changes are made.

Parameter:

aSnapshotDictionary -- a dictionary, as returned by snapshot()

See also: snapshot

validateForDelete(self)

Default implementation simply sends validateObjectForDelete() to the receiver's ClassDescription.

Subclasses overriding this method should call it prior to any other checks, and exceptions raised here should be aggegated with custom validation.

See also: EntityClassDescription.validateObjectForDelete()

validateForInsert(self)

Simply calls validateForSave()

validateForSave(self)

First forwards forwards the message to the object's ClassDescription, then iterates on class properties so that they are individually checked --this is done by sending the message 'validateValueForKey()' to oneself.

Subclasses overriding this method must call it prior to any other checks, and exceptions raised here must be aggegated with custom validation.

See also: allPropertyKeys(), classDescription()
EntityClassDescription.validateObjectForSave(), EntityClassDescription.classProperties()

validateForUpdate(self)

Simply calls validateForSave()

validateValueForKey(self, aValue, aKey)

Validate the value hold by 'aKey' attribute/relationship in the object.

Default implementation first forwards the message to the object's ClassDescription, which checks that the constraints defined in the underlying model are respected.

Then it searches if the object defines a method named 'validate<AKey>' (e.g., with 'aKey=lastName', that method's name would be 'validateLastName': you have already noticed that the first letter of the key is capitalized in the name of the method). If such a method is actually defined by the object, then it is called. You will typically define such a method to define your own validation mechanism (per-key validation).

Subclasses should never override this method. If you want to specify your own validation mechanism for a given key, say 'name', you should define a method named 'validateName()' in your class instead, as described above.

See: EntityClassDescription.validateValueForKey()

willChange(self)

Notifies the observers that the object is about to change.

CustomObject's default implementation calls willRead() on itself before notifying the ObserverCenter


Class Variable Details

__implements__

Type:
tuple
Value:
(<class Modeling.interfaces.DatabaseObject.DatabaseObjectInterface at \
0xb7687dac>,
 <class Modeling.interfaces.RelationshipManipulation.RelationshipManip\
ulationInterface at 0xb79176bc>,
 <class Modeling.interfaces.KeyValueCoding.KeyValueCodingInterface at \
0xb791768c>,
 <class Modeling.interfaces.Faulting.FaultingInterface at 0xb791795c>) 

Generated by Epydoc 2.1 on Sat Mar 4 13:36:23 2006 http://epydoc.sf.net