Please note: this project is inactive since early 2006

 
5.2 Declaring and using a nested EditingContext

Creating a nested EditingContext

You create a nested EditingContext by simply supplying the parent EditingContext to the initializer:

>>> from Modeling.EditingContext import EditingContext
>>> parent_ec=EditingContext()
>>> child_ec=EditingContext(parent_ec)

Fetching objects

You fetch objects exactly the same way you do with a standard EditingContext, as described in section 4.5, ''Fetching objects''.

However, the result set you'll get will probably be different than the one you would get by asking a standard EditingContext, because:

Current operations

All currently supported operations on an EditingContext, such as inserting or deleting an object, making changes and validating them, are available in a child EditingContext without any modifications to your code.

Discarding or saving changes

You save the changes made in a child EditingContext to its parent just by calling saveChanges() on it. Remember: a nested EditingContext saves its changes to its parent, NOT to the database. If you want to make them persistent, you will need the two following steps:

>>> child_ec.saveChanges()  # save changes to the parent_ec
>>> parent_ec.saveChanges() # save the changes to the database

Note: That's the reason why the fourth of ACID properties, Durability is not supported: since the changes are saved in the parent EditingContext and not to the database itself, they will be obviously lost if the application terminates abruptly.

Discarding the changes made in a child EditingContext is as simple as forgetting the child (e.g. dy deleting it). Remember that a parent EditingContext will never see the changes made in its children until saveChanges() is explicitly called on them.

Grand-children of an EditingContext

Is it possible to declare a child of an already nested EditingContext? Yes! Every EditingContext can have children, irrespective of whether it is already nested; the depth of a hierarchy defined by parent/children EditingContext is indeed unlimited.

Comments are welcome: Sebastien Bigaret / Modeling Home Page
Hosted by:SourceForge.net Logo