]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Sep 2005 03:49:37 +0000 (03:49 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Sep 2005 03:49:37 +0000 (03:49 +0000)
lib/sqlalchemy/objectstore.py [new file with mode: 0644]

diff --git a/lib/sqlalchemy/objectstore.py b/lib/sqlalchemy/objectstore.py
new file mode 100644 (file)
index 0000000..44a29e0
--- /dev/null
@@ -0,0 +1,70 @@
+# objectstore.py
+# Copyright (C) 2005 Michael Bayer mike_mp@zzzcomputing.com
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+import thread
+
+def get_id_key(ident, class_, table, selectable):
+    return (class_, table, tuple(ident))
+def get_instance_key(object, class_, table, selectable):
+    return (class_, table, tuple([getattr(object, column.key, None) for column in selectable.primary_keys]))
+def get_key(row, class_, table, selectable):
+    return (class_, table, tuple([row[column.label] for column in selectable.primary_keys]))
+
+identity_map = {}
+
+def get(key):
+    val = identity_map[key]
+    if isinstance(val, dict):
+        return val[thread.get_ident()]
+    else:
+        return val
+    
+def put(key, obj, scope='thread'):
+    if isinstance(obj, dict):
+        raise "cant put a dict in the object store"
+        
+    if scope == 'thread':
+        try:
+            d = identity_map[key]
+        except KeyError:
+            d = identity_map.setdefault(key, {})
+        d[thread.get_ident()] = obj
+    else:
+        identity_map[key] = obj
+
+def clear(scope='thread'):
+    if scope == 'thread':
+        for k in identity_map.keys():
+            if isinstance(identity_map[k], dict):
+                identity_map[k].clear()
+    else:
+        for k in identity_map.keys():
+            if not isinstance(identity_map[k], dict):
+                del identity_map[k]
+            
+def has_key(key):
+    if identity_map.has_key(key):
+        d = identity_map[key]
+        if isinstance(d, dict):
+            return d.has_key(thread.get_ident())
+        else:
+            return True
+    else:
+        return False
+    
+class UnitOfWork:
+    pass
\ No newline at end of file