summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-03-10 05:03:17 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-03-10 05:03:17 +0000
commit2ce45d70c7e499fd6c239d963f50cd839b28629b (patch)
treed803d773642b9512edb7623a149cd2a8ca1fd5ee /lib/sqlalchemy
parentd333168e00cd8c56425afce3906e8f7439f1427a (diff)
downloadsqlalchemy-2ce45d70c7e499fd6c239d963f50cd839b28629b.tar.gz
added expire() function + unit test fixes [ticket:95]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/attributes.py10
-rw-r--r--lib/sqlalchemy/mapping/objectstore.py13
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py
index a402a9e91..a41cdac9d 100644
--- a/lib/sqlalchemy/attributes.py
+++ b/lib/sqlalchemy/attributes.py
@@ -353,10 +353,20 @@ class AttributeManager(object):
try:
attr = obj.__dict__['_managed_attributes']
except KeyError:
+ trigger = obj.__dict__.pop('_managed_trigger', None)
+ if trigger:
+ trigger()
attr = {}
obj.__dict__['_managed_attributes'] = attr
return attr
+ def trigger_history(self, obj, callable):
+ try:
+ del obj.__dict__['_managed_attributes']
+ except KeyError:
+ pass
+ obj.__dict__['_managed_trigger'] = callable
+
def reset_history(self, obj, key):
"""removes the history object for the given attribute on the given object.
When the attribute is next accessed, a new container will be created via the
diff --git a/lib/sqlalchemy/mapping/objectstore.py b/lib/sqlalchemy/mapping/objectstore.py
index d2aca8b06..be3d96934 100644
--- a/lib/sqlalchemy/mapping/objectstore.py
+++ b/lib/sqlalchemy/mapping/objectstore.py
@@ -145,9 +145,17 @@ class Session(object):
self.uow.commit()
def refresh(self, *obj):
+ """reloads the attributes for the given objects from the database, clears
+ any changes made."""
for o in obj:
self.uow.refresh(o)
+ def expire(self, *obj):
+ """invalidates the data in the given objects and sets them to refresh themselves
+ the next time they are requested."""
+ for o in obj:
+ global_attributes.trigger_history(o, lambda: refresh(o))
+
def register_clean(self, obj):
self._bind_to(obj)
self.uow.register_clean(obj)
@@ -229,6 +237,11 @@ def refresh(*obj):
"""reloads the state of this object from the database, and cancels any in-memory
changes."""
get_session().refresh(*obj)
+
+def expire(*obj):
+ """invalidates the data in the given objects and sets them to refresh themselves
+ the next time they are requested."""
+ get_session().expire(*obj)
def delete(*obj):
"""registers the given objects as to be deleted upon the next commit"""