]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 3 Sep 2005 00:41:41 +0000 (00:41 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 3 Sep 2005 00:41:41 +0000 (00:41 +0000)
lib/sqlalchemy/engine.py
lib/sqlalchemy/util.py

index db1191a9bc89b8fa6f73fd0f79605c05723a1969..758f805bcff1271e44a4c67100745311c25ce1f0 100644 (file)
@@ -126,7 +126,6 @@ class SQLEngine(schema.SchemaEngine):
             self.rollback()
             raise
         self.commit()
-
         
     def begin(self):
         if getattr(self.context, 'transaction', None) is None:
index 2eda7a1cbf0767f838d7bf674553b7ed1e185ad3..ea6befba8fb7d9cb630f93075fdecb8d45e51c30 100644 (file)
@@ -16,7 +16,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 __ALL__ = ['OrderedProperties', 'OrderedDict']
-import thread
+import thread, weakref
 
 class OrderedProperties(object):
 
@@ -119,4 +119,41 @@ class Set(object):
         del self.map[key]
         
     def __getitem__(self, key):
-        return self.map[key]
\ No newline at end of file
+        return self.map[key]
+        
+        
+class ScopedRegistry(object):
+    def __init__(self, createfunc):
+        self.createfunc = createfunc
+        self.application = createfunc()
+        self.threadlocal = {}
+        self.scopes = {
+                    'application' : {'call' : self._call_application, 'clear' : self._clear_application}, 
+                    'thread' : {'call' : self._call_thread, 'clear':self._clear_thread}
+                    }
+
+    def __call__(self, scope):
+        return self.scopes[scope]['call']()
+
+    def clear(self, scope):
+        return self.scopes[scope]['clear']()
+        
+    def _call_thread(self):
+        try:
+            return self.threadlocal[thread.get_ident()]
+        except KeyError:
+            return self.threadlocal.setdefault(thread.get_ident(), self.createfunc())
+
+    def _clear_thread(self):
+        try:
+            del self.threadlocal[thread.get_ident()]
+        except KeyError:
+            pass
+
+    def _call_application(self):
+        return self.application
+
+    def _clear_application(self):
+        self.application = createfunc()
+                
+            
\ No newline at end of file