Each EditingContext holds a different graph of objects, isolated from the other, where modifications, insertions and deletions can be made independently until they are saved in the database.
The state of a given EditingContext naturally have an impact on the objects you fetched. When nothing has been changed, you obviously get the objects as they are stored in the database. However, whenever you insert, modify or delete object, the result set of a fetch changes:
>>> from AuthorBooks.Book import Book >>> ec=EditingContext() >>> books=ec.fetch('Book') >>> pprint.pprint([b.getTitle() for b in books]) ['Gargantua', 'Bouge ton pied que je voie la mer', 'Le coup du pere Francois', "T'assieds pas sur le compte-gouttes"] >>> new_book=Book() >>> new_book.setTitle('The Great Book') >>> ec.insert(new_book) >>> books=ec.fetch('Book') >>> pprint.pprint([b.getTitle() for b in books]) ['Gargantua', 'Bouge ton pied que je voie la mer', 'Le coup du pere Francois', "T'assieds pas sur le compte-gouttes", 'The Great Book']
As exposed above, newly inserted objects automatically appear in the result set when applicable. Of course, you can still benefit from standard fetch techniques, such as qualifiers:
>>> books=ec.fetch('Book', 'title like "*G*"') >>> [b.getTitle() for b in books] ['Gargantua', 'The Great Book']
You get the expected result, even if the inserted book is not saved in the database yet.
If you modify your objects, these modifications will always be visible in your result set; continuing on the same example:
>>> gargantua=ec.fetch('Book', 'title == "Gargantua"')[0] >>> gargantua.setTitle('Gargantua et Pantagruel') >>> books=ec.fetch('Book', 'title like "*G*"') >>> [b.getTitle() for b in books] ['Gargantua et Pantagruel', 'The Great Book']
Your changes to objects are not persistent yet in the database, still, they appear as expected in the result set.
Last, the same principles apply to deleted object:
>>> ec.delete(gargantua) >>> pprint.pprint([b.getTitle() for b in ec.fetch('Book')]) ['Bouge ton pied que je voie la mer', 'Le coup du pere Francois', "T'assieds pas sur le compte-gouttes", 'The Great Book'] >>> [b.getTitle() for b in ec.fetch('Book', 'title like "*G*"')] ['The Great Book']
Objects marked as deleted do not appear in the result set, even if the object still exists in the database (it will only be deleted when the EditingContext receives the saveChanges() message, see 4.6).
Comments are welcome: Sebastien Bigaret / Modeling Home Page