[z3-checkins] r27821 - in z3/sqlos/branch/jinty-sqlobject2/src/sqlos: . testing

jinty at codespeak.net jinty at codespeak.net
Mon May 29 09:52:34 CEST 2006


Author: jinty
Date: Mon May 29 09:52:19 2006
New Revision: 27821

Added:
   z3/sqlos/branch/jinty-sqlobject2/src/sqlos/events.py   (contents, props changed)
Modified:
   z3/sqlos/branch/jinty-sqlobject2/src/sqlos/__init__.py
   z3/sqlos/branch/jinty-sqlobject2/src/sqlos/_transaction.py
   z3/sqlos/branch/jinty-sqlobject2/src/sqlos/configure.zcml
   z3/sqlos/branch/jinty-sqlobject2/src/sqlos/testing/sampleperson.py
Log:
Enable lazy updates and connect up SQLObject events to SQLOS events. This breaks everything, not sure why yet.

Modified: z3/sqlos/branch/jinty-sqlobject2/src/sqlos/__init__.py
==============================================================================
--- z3/sqlos/branch/jinty-sqlobject2/src/sqlos/__init__.py	(original)
+++ z3/sqlos/branch/jinty-sqlobject2/src/sqlos/__init__.py	Mon May 29 09:52:19 2006
@@ -9,3 +9,27 @@
 """
 $Id$
 """
+
+from sqlobject import SQLObject
+import sqlobject.events
+
+import sqlos.events
+
+#
+# Connect SQLObject events to Zope3 events
+#
+SQLObject.event_hub.listen(sqlobject.events.RowCreateSignal,
+                           sqlos.events.notifySQLObjectCreated,
+                           weak=False)
+SQLObject.event_hub.listen(sqlobject.events.RowDestroySignal,
+                           sqlos.events.notifySQLObjectDirtied,
+                           weak=False)
+SQLObject.event_hub.listen(sqlobject.events.RowUpdateSignal,
+                           sqlos.events.notifySQLObjectDirtied,
+                           weak=False)
+#
+# Clean up the __init__.py
+#
+del SQLObject
+del sqlos.events
+del sqlobject.events

Modified: z3/sqlos/branch/jinty-sqlobject2/src/sqlos/_transaction.py
==============================================================================
--- z3/sqlos/branch/jinty-sqlobject2/src/sqlos/_transaction.py	(original)
+++ z3/sqlos/branch/jinty-sqlobject2/src/sqlos/_transaction.py	Mon May 29 09:52:19 2006
@@ -224,3 +224,6 @@
             self._registered = False
 
 dirty_object_registry = DirtyObjectRegistry()
+
+def dirtyObjectSubscriber(event):
+    dirty_object_registry.register(event.object)

Modified: z3/sqlos/branch/jinty-sqlobject2/src/sqlos/configure.zcml
==============================================================================
--- z3/sqlos/branch/jinty-sqlobject2/src/sqlos/configure.zcml	(original)
+++ z3/sqlos/branch/jinty-sqlobject2/src/sqlos/configure.zcml	Mon May 29 09:52:19 2006
@@ -110,4 +110,9 @@
       handler=".connection.clearCacheSubscriber"
       />
 
+  <subscriber
+      for=".events.ISQLObjectDirtiedEvent"
+      handler="._transaction.dirtyObjectSubscriber"
+      />
+
 </configure>

Added: z3/sqlos/branch/jinty-sqlobject2/src/sqlos/events.py
==============================================================================
--- (empty file)
+++ z3/sqlos/branch/jinty-sqlobject2/src/sqlos/events.py	Mon May 29 09:52:19 2006
@@ -0,0 +1,28 @@
+from zope.interface import implements
+from zope.component.interfaces import ObjectEvent, IObjectEvent
+from zope.event import notify
+from sqlobject import SQLObject
+
+from sqlos.interfaces import ISQLObject
+
+class ISQLObjectDirtiedEvent(IObjectEvent):
+    """Event notifying of an SQLObject that was dirtied."""
+    pass
+
+class SQLObjectDirtiedEvent(ObjectEvent):
+
+    implements(ISQLObjectDirtiedEvent)
+
+#
+# Functions to translate events from SQLObject events to zope events.
+#
+# In Zope we only have one event type, ISQLObjectDirtiedEvent. This can
+# be further sub classed in future.
+#
+
+def notifySQLObjectCreated(kwargs, post_funcs):
+    post_funcs.append(notifySQLObjectDirtied)
+
+def notifySQLObjectDirtied(object, *args):
+    assert ISQLObject.providedBy(object) # let's just be a bit suspicious
+    notify(SQLObjectDirtiedEvent(object))

Modified: z3/sqlos/branch/jinty-sqlobject2/src/sqlos/testing/sampleperson.py
==============================================================================
--- z3/sqlos/branch/jinty-sqlobject2/src/sqlos/testing/sampleperson.py	(original)
+++ z3/sqlos/branch/jinty-sqlobject2/src/sqlos/testing/sampleperson.py	Mon May 29 09:52:19 2006
@@ -63,6 +63,7 @@
 
     class sqlmeta:
         connection_hub = test_hub
+        lazy = True
 
     fullname = StringCol(length=50, notNull=1)
     username = StringCol(length=20, notNull=1)
@@ -76,6 +77,7 @@
 
     class sqlmeta:
         connection_hub = test_hub
+        lazy = True
 
     # Using a StringCol for a list is probably not the right way to do things
     # from a Relational Database point of view, better would be some kind of
@@ -138,6 +140,7 @@
 
     class sqlmeta:
         connection_hub = test_hub
+        lazy = True
 
     fullname = StringCol(length=50, notNull=1)
     owner = StringCol(length=20, notNull=1)


More information about the z3-checkins mailing list