diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2005-10-22 22:57:32 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2005-10-22 22:57:32 +0000 |
commit | f313c15e5f61c78bc1ed0cc8deb47e0e652848c6 (patch) | |
tree | 729a155b1618dc6678f6c1130325296a8cd8a06f /lib/sqlalchemy/objectstore.py | |
parent | fe12e56166ba6da0466fb36c2bf499005f2746d7 (diff) | |
download | sqlalchemy-f313c15e5f61c78bc1ed0cc8deb47e0e652848c6.tar.gz |
oids rows insert sort orders galore
Diffstat (limited to 'lib/sqlalchemy/objectstore.py')
-rw-r--r-- | lib/sqlalchemy/objectstore.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/sqlalchemy/objectstore.py b/lib/sqlalchemy/objectstore.py index 7cc9a69fb..3e216a768 100644 --- a/lib/sqlalchemy/objectstore.py +++ b/lib/sqlalchemy/objectstore.py @@ -54,20 +54,42 @@ def get_row_key(row, class_, table, primary_keys): """ return (class_, table, tuple([row[column.label] for column in primary_keys])) +def begin(): + """begins a new UnitOfWork transaction. the next commit will affect only + objects that are created, modified, or deleted following the begin statement.""" + uow().begin() + def commit(*obj): + """commits the current UnitOfWork transaction. if a transaction was begun + via begin(), commits only those objects that were created, modified, or deleted + since that begin statement. otherwise commits all objects that have been + changed.""" uow().commit(*obj) def clear(): + """removes all current UnitOfWorks and IdentityMaps for this thread and + establishes a new one. It is probably a good idea to discard all + current mapped object instances, as they are no longer in the Identity Map.""" uow.set(UnitOfWork()) def delete(*obj): + """registers the given objects as to be deleted upon the next commit""" uw = uow() for o in obj: uw.register_deleted(o) def has_key(key): + """returns True if the current thread-local IdentityMap contains the given instance key""" return uow().identity_map.has_key(key) +def has_instance(instance): + """returns True if the current thread-local IdentityMap contains the given instance""" + return uow().identity_map.has_key(instance_key(instance)) + +def instance_key(instance): + """returns the IdentityMap key for the given instance""" + return object_mapper(instance).instance_key(instance) + class UOWListElement(attributes.ListElement): def __init__(self, obj, key, data=None, deleteremoved=False): attributes.ListElement.__init__(self, obj, key, data=data) |