[CalendarServer-changes] [7017] CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/ sql.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 16 06:42:11 PST 2011


Revision: 7017
          http://trac.macosforge.org/projects/calendarserver/changeset/7017
Author:   glyph at apple.com
Date:     2011-02-16 06:42:11 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
share _changeRevision behavior

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py

Modified: CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py	2011-02-16 14:41:59 UTC (rev 7016)
+++ CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py	2011-02-16 14:42:11 UTC (rev 7017)
@@ -1192,9 +1192,16 @@
                         self._txn, homeID=self._home._resourceID,
                         resourceID=self._resourceID, name=name)
                 )[0][0]
+        self._maybeNotify()
 
 
+    def _maybeNotify(self):
+        """
+        Maybe notify changed.  (Overridden in NotificationCollection.)
+        """
 
+
+
 class CommonHomeChild(LoggingMixIn, FancyEqMixin, _SharedSyncLogic):
     """
     Common ancestor class of AddressBooks and Calendars.
@@ -2343,6 +2350,15 @@
     )
 
 
+    @property
+    def _home(self):
+        """
+        L{NotificationCollection} serves as its own C{_home} for the purposes of
+        working with L{_SharedSyncLogic}.
+        """
+        return self
+
+
     @classmethod
     @inlineCallbacks
     def notificationsWithUID(cls, txn, uid):
@@ -2506,60 +2522,6 @@
         returnValue("%s#%s" % (self._resourceID, self._syncTokenRevision))
 
 
-    @inlineCallbacks
-    def _changeRevision(self, action, name):
-
-        if action == "delete":
-            self._syncTokenRevision = (yield self._txn.execSQL("""
-                update %(name)s
-                set (%(column_REVISION)s, %(column_DELETED)s) = (nextval('%(sequence)s'), TRUE)
-                where %(column_HOME_RESOURCE_ID)s = %%s and %(column_RESOURCE_NAME)s = %%s
-                returning %(column_REVISION)s
-                """ % self._revisionsTable,
-                [self._resourceID, name]
-            ))[0][0]
-        elif action == "update":
-            self._syncTokenRevision = (yield self._txn.execSQL("""
-                update %(name)s
-                set (%(column_REVISION)s) = (nextval('%(sequence)s'))
-                where %(column_HOME_RESOURCE_ID)s = %%s and %(column_RESOURCE_NAME)s = %%s
-                returning %(column_REVISION)s
-                """ % self._revisionsTable,
-                [self._resourceID, name]
-            ))[0][0]
-        elif action == "insert":
-            # Note that an "insert" may happen for a resource that previously existed and then
-            # was deleted. In that case an entry in the REVISIONS table still exists so we have to
-            # detect that and do db INSERT or UPDATE as appropriate
-
-            found = bool( (yield self._txn.execSQL("""
-                select %(column_HOME_RESOURCE_ID)s from %(name)s
-                where %(column_HOME_RESOURCE_ID)s = %%s and %(column_RESOURCE_NAME)s = %%s
-                """ % self._revisionsTable,
-                [self._resourceID, name, ]
-            )))
-            if found:
-                self._syncTokenRevision = (yield self._txn.execSQL("""
-                    update %(name)s
-                    set (%(column_REVISION)s, %(column_DELETED)s) = (nextval('%(sequence)s'), FALSE)
-                    where %(column_HOME_RESOURCE_ID)s = %%s and %(column_RESOURCE_NAME)s = %%s
-                    returning %(column_REVISION)s
-                    """ % self._revisionsTable,
-                    [self._resourceID, name]
-                ))[0][0]
-            else:
-                self._syncTokenRevision = (yield self._txn.execSQL("""
-                    insert into %(name)s
-                    (%(column_HOME_RESOURCE_ID)s, %(column_RESOURCE_NAME)s, %(column_REVISION)s, %(column_DELETED)s)
-                    values (%%s, %%s, nextval('%(sequence)s'), FALSE)
-                    returning %(column_REVISION)s
-                    """ % self._revisionsTable,
-                    [self._resourceID, name,]
-                ))[0][0]
-
-        self.notifyChanged()
-
-
     def properties(self):
         return self._propertyStore
 
@@ -2591,7 +2553,25 @@
                 self._txn.postCommit(notifier.notify)
 
 
+    @classproperty
+    def _completelyNewRevisionQuery(cls):
+        rev = cls._revisionsSchema
+        return Insert({rev.HOME_RESOURCE_ID: Parameter("homeID"),
+                       # rev.RESOURCE_ID: Parameter("resourceID"),
+                       rev.RESOURCE_NAME: Parameter("name"),
+                       rev.REVISION: schema.REVISION_SEQ,
+                       rev.DELETED: False},
+                      Return=rev.REVISION)
 
+
+    def _maybeNotify(self):
+        """
+        Emit a push notification after C{_changeRevision}.
+        """
+        self.notifyChanged()
+
+
+
 class NotificationObject(LoggingMixIn, FancyEqMixin):
 
     implements(INotificationObject)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/ad6428c8/attachment.html>


More information about the calendarserver-changes mailing list