[CalendarServer-changes] [6046] CalendarServer/branches/users/glyph/sql-store

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 11 08:19:17 PDT 2010


Revision: 6046
          http://trac.macosforge.org/projects/calendarserver/changeset/6046
Author:   glyph at apple.com
Date:     2010-08-11 08:19:16 -0700 (Wed, 11 Aug 2010)
Log Message:
-----------
ctag

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py
    CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/util.py
    CalendarServer/branches/users/glyph/sql-store/txdav/common/datastore/file.py

Modified: CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py	2010-08-11 05:05:59 UTC (rev 6045)
+++ CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py	2010-08-11 15:19:16 UTC (rev 6046)
@@ -52,7 +52,7 @@
     ObjectResourceNameAlreadyExistsError, HomeChildNameAlreadyExistsError,
     NoSuchHomeChildError, NoSuchObjectResourceError)
 from txcaldav.calendarstore.util import (validateCalendarComponent,
-    validateAddressBookComponent, dropboxIDFromCalendarObject)
+    validateAddressBookComponent, dropboxIDFromCalendarObject, SyncTokenHelper)
 
 
 from txcaldav.icalendarstore import (ICalendarTransaction, ICalendarHome,
@@ -266,6 +266,8 @@
             "where RESOURCE_ID = %s", [calendarText, self._resourceID]
         )
         self._calendarText = calendarText
+        self._calendar._updateSyncToken()
+
         if self._calendar._notifier:
             self._calendar._home._txn.postCommit(self._calendar._notifier.notify)
 
@@ -541,7 +543,9 @@
 
 
     def recordForInviteUID(self, inviteUID):
-        raise NotImplementedError("recordForInviteUID")
+        for record in self.allRecords():
+            if record.inviteuid == inviteUID:
+                return record
 
 
     def addOrUpdateRecord(self, record):
@@ -618,10 +622,7 @@
 
     def removeRecordForUserID(self, userid):
         rec = self.recordForUserID(userid)
-        self._txn.execSQL(
-            "delete from INVITE where INVITE_UID = %s",
-            [rec.inviteuid]
-        )
+        self.removeRecordForInviteUID(rec.inviteuid)
 
 
     def removeRecordForPrincipalURL(self, principalURL):
@@ -629,8 +630,18 @@
 
 
     def removeRecordForInviteUID(self, inviteUID):
-        self._txn.execSQL("delete from INVITE where INVITE_UID = %s",
-                          [inviteUID])
+        rows = self._txn.execSQL("""
+                select HOME_RESOURCE_ID, RESOURCE_ID from INVITE where
+                INVITE_UID = %s
+            """, [inviteUID])
+        if rows:
+            [[homeID, resourceID]] = rows
+            self._txn.execSQL(
+                "delete from CALENDAR_BIND where "
+                "CALENDAR_HOME_RESOURCE_ID = %s and CALENDAR_RESOURCE_ID = %s",
+                [homeID, resourceID])
+            self._txn.execSQL("delete from INVITE where INVITE_UID = %s",
+                [inviteUID])
 
 
 
@@ -773,7 +784,7 @@
 
 
 
-class PostgresCalendar(object):
+class PostgresCalendar(SyncTokenHelper):
 
     implements(ICalendar)
 
@@ -872,6 +883,8 @@
         if rows:
             raise ObjectResourceNameAlreadyExistsError()
 
+        self._updateSyncToken()
+
         calendarObject = PostgresCalendarObject(self, name, None)
         calendarObject.component = lambda : component
 
@@ -905,6 +918,9 @@
         if self._txn._cursor.rowcount == 0:
             raise NoSuchObjectResourceError()
         self._objects.pop(name, None)
+
+        self._updateSyncToken()
+
         if self._notifier:
             self._txn.postCommit(self._notifier.notify)
 
@@ -924,6 +940,8 @@
             [uid, self._resourceID]
         )
         self._objects.pop(name, None)
+        self._updateSyncToken()
+
         if self._notifier:
             self._home._txn.postCommit(self._notifier.notify)
 
@@ -1102,8 +1120,11 @@
         )
 
         calendarType = ResourceType.calendar #@UndefinedVariable
-        self.calendarWithName(name).properties()[
+        newCalendar = self.calendarWithName(name)
+        newCalendar.properties()[
             PropertyName.fromElement(ResourceType)] = calendarType
+        newCalendar._updateSyncToken(True)
+
         if self._notifier:
             self._txn.postCommit(self._notifier.notify)
 

Modified: CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/util.py
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/util.py	2010-08-11 05:05:59 UTC (rev 6045)
+++ CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/util.py	2010-08-11 15:19:16 UTC (rev 6046)
@@ -13,9 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
-from txdav.common.icommondatastore import InvalidObjectResourceError,\
-    NoSuchObjectResourceError
-
 """
 Utility logic common to multiple backend implementations.
 """
@@ -25,6 +22,13 @@
 from twistedcaldav.vcard import Component as VCard
 from twistedcaldav.vcard import InvalidVCardDataError
 
+from txdav.common.icommondatastore import InvalidObjectResourceError,\
+    NoSuchObjectResourceError
+from twistedcaldav.customxml import GETCTag
+from uuid import uuid4
+from txdav.propertystore.base import PropertyName
+
+
 def validateCalendarComponent(calendarObject, calendar, component):
     """
     Validate a calendar component for a particular calendar.
@@ -120,3 +124,32 @@
     except InvalidVCardDataError, e:
         raise InvalidObjectResourceError(e)
 
+
+
+class SyncTokenHelper(object):
+    """
+    Implement a basic _updateSyncToken in terms of an object with a property
+    store.  This is a mixin for use by data store implementations.
+    """
+
+    def _updateSyncToken(self, reset=False):
+        # FIXME: add locking a-la CalDAVResource.bumpSyncToken
+        # FIXME: tests for desired concurrency properties
+        ctag = PropertyName.fromString(GETCTag.sname())
+        props = self.properties()
+        token = props.get(ctag)
+        if token is None or reset:
+            tokenuuid = uuid4()
+            revision = 1
+        else:
+            # FIXME: no direct tests for update
+            token = str(token)
+            tokenuuid, revision = token.split("#", 1)
+            revision = int(revision) + 1
+        token = "%s#%d" % (tokenuuid, revision)
+        props[ctag] = GETCTag(token)
+        # FIXME: no direct tests for commit
+        return revision
+
+
+

Modified: CalendarServer/branches/users/glyph/sql-store/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/txdav/common/datastore/file.py	2010-08-11 05:05:59 UTC (rev 6045)
+++ CalendarServer/branches/users/glyph/sql-store/txdav/common/datastore/file.py	2010-08-11 15:19:16 UTC (rev 6046)
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
+from txcaldav.calendarstore.util import SyncTokenHelper
 
 """
 Common utility functions for a file based datastore.
@@ -26,7 +27,7 @@
 from twisted.python.util import FancyEqMixin
 
 from twistedcaldav import customxml
-from twistedcaldav.customxml import GETCTag, NotificationType
+from twistedcaldav.customxml import NotificationType
 from twistedcaldav.notifications import NotificationRecord
 from twistedcaldav.notifications import NotificationsDatabase as OldNotificationIndex
 from twistedcaldav.sharing import SharedCollectionsDatabase
@@ -44,7 +45,6 @@
 from txdav.propertystore.xattr import PropertyStore
 
 from errno import EEXIST, ENOENT
-from uuid import uuid4
 from zope.interface import implements, directlyProvides
 
 ECALENDARTYPE = 0
@@ -475,8 +475,10 @@
             return None
 
 
-class CommonHomeChild(FileMetaDataMixin, LoggingMixIn, FancyEqMixin):
+class CommonHomeChild(FileMetaDataMixin, LoggingMixIn, FancyEqMixin,
+                      SyncTokenHelper):
     """
+    Common ancestor class of AddressBooks and Calendars.
     """
 
     compareAttributes = '_name _home _transaction'.split()
@@ -678,26 +680,6 @@
         raise NotImplementedError()
 
 
-    def _updateSyncToken(self, reset=False):
-        # FIXME: add locking a-la CalDAVResource.bumpSyncToken
-        # FIXME: tests for desired concurrency properties
-        ctag = PropertyName.fromString(GETCTag.sname())
-        props = self.properties()
-        token = props.get(ctag)
-        if token is None or reset:
-            tokenuuid = uuid4()
-            revision = 1
-        else:
-            # FIXME: no direct tests for update
-            token = str(token)
-            tokenuuid, revision = token.split("#", 1)
-            revision = int(revision) + 1
-        token = "%s#%d" % (tokenuuid, revision)
-        props[ctag] = GETCTag(token)
-        # FIXME: no direct tests for commit
-        return revision
-
-
     def objectResourcesSinceToken(self, token):
         raise NotImplementedError()
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100811/5202ebe1/attachment.html>


More information about the calendarserver-changes mailing list