[CalendarServer-changes] [14187] CalendarServer/branches/users/sagen/trashcan/txdav

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 20 13:16:25 PST 2014


Revision: 14187
          http://trac.calendarserver.org//changeset/14187
Author:   sagen at apple.com
Date:     2014-11-20 13:16:24 -0800 (Thu, 20 Nov 2014)
Log Message:
-----------
Store childType in the DB; childWithName() uses the childType to pick the right class

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py
    CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py
    CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py	2014-11-20 19:51:36 UTC (rev 14186)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py	2014-11-20 21:16:24 UTC (rev 14187)
@@ -995,6 +995,7 @@
             cls._homeChildMetaDataSchema.SUPPORTED_COMPONENTS,
             cls._homeChildMetaDataSchema.CREATED,
             cls._homeChildMetaDataSchema.MODIFIED,
+            cls._homeChildMetaDataSchema.CHILD_TYPE,
         )
 
 
@@ -1012,6 +1013,7 @@
             "_supportedComponents",
             "_created",
             "_modified",
+            "_childType",
         )
 
 

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py	2014-11-20 19:51:36 UTC (rev 14186)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py	2014-11-20 21:16:24 UTC (rev 14187)
@@ -3443,11 +3443,7 @@
         @param name: a string.
         @return: an L{ICalendar} or C{None} if no such child exists.
         """
-        # FIXME: should determine the class from the collection_type column
-        if name == "trash":
-            return self._trashClass.objectWithName(self, name)
-        else:
-            return self._childClass.objectWithName(self, name)
+        return self._childClass.objectWithName(self, name)
 
 
     def anyObjectWithShareUID(self, shareUID):
@@ -5569,6 +5565,11 @@
         else:
             ownerName = None
 
+        if metadataData:
+            collectionType = metadataData[3]
+            if collectionType == "trash":  # FIXME: make this an enumeration
+                cls = home._trashClass
+
         c = cls._externalClass if ownerHome.external() else cls
         child = c(
             home=home,
@@ -5829,7 +5830,6 @@
         return Insert(
             {
                 child.RESOURCE_ID: schema.RESOURCE_ID_SEQ,
-                child.COLLECTION_TYPE: Parameter("childType"),
             },
             Return=(child.RESOURCE_ID)
         )
@@ -5844,6 +5844,7 @@
         return Insert(
             {
                 child.RESOURCE_ID: Parameter("resourceID"),
+                child.CHILD_TYPE: Parameter("childType"),
             },
             Return=(child.CREATED, child.MODIFIED)
         )
@@ -5860,10 +5861,14 @@
             raise HomeChildNameNotAllowedError(name)
 
         # Create this object
-        resourceID = (yield cls._insertHomeChild.on(home._txn, childType=cls._childType))[0][0]
+        resourceID = (yield cls._insertHomeChild.on(home._txn))[0][0]
 
         # Initialize this object
-        _created, _modified = (yield cls._insertHomeChildMetaData.on(home._txn, resourceID=resourceID))[0]
+        _created, _modified = (
+            yield cls._insertHomeChildMetaData.on(
+                home._txn, resourceID=resourceID, childType=cls._childType
+            )
+        )[0]
         # Bind table needs entry
         yield cls._bindInsertQuery.on(
             home._txn, homeID=home._resourceID, resourceID=resourceID, externalID=externalID,

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql	2014-11-20 19:51:36 UTC (rev 14186)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql	2014-11-20 21:16:24 UTC (rev 14187)
@@ -92,8 +92,7 @@
 --------------
 
 create table CALENDAR (
-  RESOURCE_ID integer   primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
-  COLLECTION_TYPE       varchar(10) default null -- None, inbox, trash (FIXME: convert this to enumeration)
+  RESOURCE_ID integer   primary key default nextval('RESOURCE_ID_SEQ') -- implicit index
 );
 
 
@@ -132,7 +131,9 @@
   RESOURCE_ID           integer      primary key references CALENDAR on delete cascade, -- implicit index
   SUPPORTED_COMPONENTS  varchar(255) default null,
   CREATED               timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
-  MODIFIED              timestamp    default timezone('UTC', CURRENT_TIMESTAMP)
+  MODIFIED              timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  CHILD_TYPE            varchar(10)  default null -- None, inbox, trash (FIXME: convert this to enumeration)
+
 );
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141120/8d18eef2/attachment.html>


More information about the calendarserver-changes mailing list