[CalendarServer-changes] [6042] CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 10 19:43:02 PDT 2010


Revision: 6042
          http://trac.macosforge.org/projects/calendarserver/changeset/6042
Author:   glyph at apple.com
Date:     2010-08-10 19:43:01 -0700 (Tue, 10 Aug 2010)
Log Message:
-----------
notifications, most of invites

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py
    CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres_schema_v1.sql

Modified: CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py	2010-08-11 02:42:30 UTC (rev 6041)
+++ CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres.py	2010-08-11 02:43:01 UTC (rev 6042)
@@ -14,6 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
+from txdav.common.inotifications import INotificationCollection, \
+    INotificationObject
 
 """
 PostgreSQL data store.
@@ -78,6 +80,7 @@
 _BIND_STATUS_INVITED = 0
 _BIND_STATUS_ACCEPTED = 1
 _BIND_STATUS_DECLINED = 2
+_BIND_STATUS_INVALID = 3
 
 _ATTACHMENTS_MODE_WRITE = 1
 
@@ -511,7 +514,8 @@
             state = {
                 _BIND_STATUS_INVITED: "NEEDS-ACTION",
                 _BIND_STATUS_ACCEPTED: "ACCEPTED",
-                _BIND_STATUS_DECLINED: "DECLINED"
+                _BIND_STATUS_DECLINED: "DECLINED",
+                _BIND_STATUS_INVALID: "INVALID",
             }[bindStatus]
             access = {
                 _BIND_MODE_READ: "read-only",
@@ -545,6 +549,7 @@
             "NEEDS-ACTION": _BIND_STATUS_INVITED,
             "ACCEPTED": _BIND_STATUS_ACCEPTED,
             "DECLINED": _BIND_STATUS_DECLINED,
+            "INVALID": _BIND_STATUS_INVALID,
         }[record.state]
         # principalURL is derived from a directory record's principalURL() so
         # it will always contain the UID.
@@ -1150,13 +1155,61 @@
 
 
 
+class PostgresNotificationObject(object):
+    implements(INotificationObject)
+
+    def __init__(self, home, resourceID):
+        self._home = home
+        self._resourceID = resourceID
+
+
+    @property
+    def _txn(self):
+        return self._home.txn
+
+
+    def setData(self, uid, xmltype, xmldata):
+        return self._txn.execSQL(
+            """
+            update NOTIFICATION set NOTIFICATION_UID = %s, XML_TYPE = %s,
+            XML_DATA = %s where RESOURCE_ID = %s
+            """,
+            [uid, xmltype, xmldata, self._resourceID]
+        )
+
+
+    def _fieldQuery(self, field):
+        [[data]] = self._txn.execSQL(
+            "select " + field + " from NOTIFICATION where"
+            "RESOURCE_ID = %s",
+            [self._resourceID])
+        return data
+
+
+    def xmldata(self):
+        return self._fieldQuery("XML_DATA")
+
+
+    def uid(self):
+        return self._fieldQuery("NOTIFICATION_UID")
+
+
+    def properties(self):
+        return PropertyStore(self._home.uid(),
+                             self._home.uid(),
+                             self._txn,
+                             self._resourceID)
+
+
+
 class PostgresNotificationsCollection(object):
 
+    implements(INotificationCollection)
 
-    def __init__(self, txn, uid):
+    def __init__(self, txn, uid, resourceID):
         self._txn = txn
         self._uid = uid
-        self._resourceID = 'notifications for %s' % (uid,)
+        self._resourceID = resourceID
 
 
     def name(self):
@@ -1164,31 +1217,55 @@
 
 
     def notificationObjects(self):
-        return []
+        for [uid] in self._txn.execSQL(
+                "select (NOTIFICATION_UID) "
+                "from NOTIFICATION "
+                "where NOTIFICATION_HOME_RESOURCE_ID = %s",
+                [self._resourceID]):
+            yield self.notificationObjectWithUID(uid)
 
 
+    def _nameToUID(self, name):
+        """
+        Based on the file-backed implementation, the 'name' is just uid +
+        ".xml".
+        """
+        return name.rsplit(".", 1)[0]
+
+
     def notificationObjectWithName(self, name):
-        return None
+        return self.notificationObjectWithUID(self._nameToUID(name))
 
+
     def notificationObjectWithUID(self, uid):
-        return None
+        [[resourceID]] = self._txn.execSQL(
+            "select RESOURCE_ID from NOTIFICATION where NOTIFICATION_UID = %s"
+            " and NOTIFICATION_HOME_RESOURCE_ID = %s",
+            [uid, self._resourceID])
+        return PostgresNotificationObject(self, resourceID)
 
 
     def writeNotificationObject(self, uid, xmltype, xmldata):
-        return None
+        self._txn.execSQL(
+            "insert into NOTIFICATION (NOTIFICATION_UID, XML_TYPE, XML_DATA) "
+            "values (%s, %s, %s)", [uid, xmltype, xmldata])
 
 
     def removeNotificationObjectWithName(self, name):
-        return
+        self.removeNotificationObjectWithUID(self._nameToUID(name))
 
 
     def removeNotificationObjectWithUID(self, uid):
-        return
+        self._txn.execSQL(
+            "delete from NOTIFICATION where NOTIFICATION_UID = %s and "
+            "NOTIFICATION_HOME_RESOURCE_ID = %s",
+            [uid, self._resourceID])
 
 
     def syncToken(self):
         return 'dummy-sync-token'
 
+
     def notificationObjectsSinceToken(self, token):
         changed = []
         removed = []
@@ -1197,7 +1274,9 @@
 
 
     def properties(self):
-        return PropertyStore(self._uid, self._uid, self._txn, self._resourceID)
+        return PropertyStore(
+            self._uid, self._uid, self._txn, self._resourceID
+        )
 
 
 
@@ -1294,7 +1373,12 @@
         """
         Implement notificationsWithUID.
         """
-        return PostgresNotificationsCollection(self, uid)
+        [[resourceID]] = self._txn.execSQL(
+            """
+            select RESOURCE_ID from NOTIFICATION_HOME where
+            OWNER_UID = %s
+            """, [uid])
+        return PostgresNotificationsCollection(self, uid, resourceID)
 
 
     def abort(self):

Modified: CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres_schema_v1.sql
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres_schema_v1.sql	2010-08-11 02:42:30 UTC (rev 6041)
+++ CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/postgres_schema_v1.sql	2010-08-11 02:43:01 UTC (rev 6042)
@@ -30,14 +30,35 @@
 ------------------------
 
 create table INVITE (
-    INVITE_UID                  varchar(255) not null,
-    NAME                        varchar(255) not null,
-    SENDER_ADDRESS              varchar(255) not null,
+    INVITE_UID         varchar(255) not null,
+    NAME               varchar(255) not null,
+    SENDER_ADDRESS     varchar(255) not null,
     HOME_RESOURCE_ID   varchar(255) not null,
     RESOURCE_ID        varchar(255) not null
 );
 
 
+---------------------------
+-- Sharing Notifications --
+---------------------------
+
+create table NOTIFICATION_HOME (
+  RESOURCE_ID varchar(255) primary key default nextval('RESOURCE_ID_SEQ'),
+  OWNER_UID   varchar(255) not null unique
+);
+
+
+create table NOTIFICATION (
+  RESOURCE_ID varchar(255)
+        primary key default nextval('RESOURCE_ID_SEQ'),
+  NOTIFICATION_HOME_RESOURCE_ID
+        varchar(255) not null references NOTIFICATION_HOME,
+  NOTIFICATION_UID varchar(255) not null,
+  XML_TYPE varchar not null,
+  XML_DATA varchar not null
+);
+
+
 -------------------
 -- Calendar Bind --
 -------------------
@@ -83,6 +104,7 @@
 insert into CALENDAR_BIND_STATUS values (0, 'invited' );
 insert into CALENDAR_BIND_STATUS values (1, 'accepted');
 insert into CALENDAR_BIND_STATUS values (2, 'declined');
+insert into CALENDAR_BIND_STATUS values (3, 'invalid');
 
 
 ---------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100810/00c697c8/attachment.html>


More information about the calendarserver-changes mailing list