[CalendarServer-changes] [7120] CalendarServer/branches/users/glyph/oracle/txdav/common/datastore/ sql_legacy.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 7 19:00:53 PST 2011


Revision: 7120
          http://trac.macosforge.org/projects/calendarserver/changeset/7120
Author:   glyph at apple.com
Date:     2011-03-07 19:00:53 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
DALify remaining queries, except those generated by the 'sqlgenerator'.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/txdav/common/datastore/sql_legacy.py

Modified: CalendarServer/branches/users/glyph/oracle/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/txdav/common/datastore/sql_legacy.py	2011-03-08 03:00:40 UTC (rev 7119)
+++ CalendarServer/branches/users/glyph/oracle/txdav/common/datastore/sql_legacy.py	2011-03-08 03:00:53 UTC (rev 7120)
@@ -1088,13 +1088,7 @@
 
         # Perform the search
         if qualifiers is None:
-            rowiter = yield self._txn.execSQL(
-                """
-                select RESOURCE_NAME, ICALENDAR_UID, ICALENDAR_TYPE
-                from CALENDAR_OBJECT where CALENDAR_RESOURCE_ID = %s
-                """,
-                [self.calendar._resourceID],
-            )
+            rowiter = yield self.bruteForceSearch()
         else:
             if fbtype:
                 # For a free-busy time-range query we return all instances
@@ -1138,28 +1132,49 @@
         returnValue(results)
 
 
-    def bruteForceSearch(self):
-        return self._txn.execSQL(
-            "select RESOURCE_NAME, ICALENDAR_UID, ICALENDAR_TYPE from "
-            "CALENDAR_OBJECT where CALENDAR_RESOURCE_ID = %s",
-            [self.calendar._resourceID]
+    @classproperty
+    def _bruteForceQuery(cls):
+        """
+        DAL query for all C{CALENDAR_OBJECT} rows in the calendar represented by
+        this index.
+        """
+        obj = cls._objectSchema
+        return Select(
+            [obj.RESOURCE_NAME, obj.ICALENDAR_UID, obj.ICALENDAR_TYPE],
+            From=obj, Where=obj.PARENT_RESOURCE_ID == Parameter("resourceID")
         )
 
 
+    def bruteForceSearch(self):
+        return self._bruteForceQuery.on(
+            self._txn, resourceID=self.resource._resourceID)
+
+
     @inlineCallbacks
     def resourcesExist(self, names):
         returnValue(list(set(names).intersection(
             set((yield self.calendar.listCalendarObjects())))))
 
 
+    @classproperty
+    def _resourceExistsQuery(cls):
+        """
+        DAL query to determine whether a calendar object exists in the
+        collection represented by this index.
+        """
+        obj = cls._objectSchema
+        return Select(
+            [obj.RESOURCE_NAME], From=obj,
+            Where=(obj.RESOURCE_NAME == Parameter("name"))
+            .And(obj.PARENT_RESOURCE_ID == Parameter("resourceID"))
+        )
+
+
     @inlineCallbacks
     def resourceExists(self, name):
         returnValue((bool(
-            (yield self._txn.execSQL(
-                "select RESOURCE_NAME from CALENDAR_OBJECT where "
-                "RESOURCE_NAME = %s and CALENDAR_RESOURCE_ID = %s",
-                [name, self.calendar._resourceID]
-            ))
+            (yield self._resourceExistsQuery.on(
+                self._txn, name=name, resourceID=self.resource._resourceID))
         )))
 
 
@@ -1250,12 +1265,15 @@
         return "%%%s%%" % (arg,)
 
 
+
 class PostgresLegacyABIndexEmulator(LegacyIndexHelper):
     """
     Emulator for L{twistedcaldv.index.Index} and
     L{twistedcaldv.index.IndexSchedule}.
     """
 
+    _objectSchema = schema.ADDRESSBOOK_OBJECT
+
     def __init__(self, addressbook):
         self.resource = self.addressbook = addressbook
         if (
@@ -1337,26 +1355,8 @@
         raise IndexedSearchException()
 
 
-    def bruteForceSearch(self):
-        return self._txn.execSQL(
-            "select RESOURCE_NAME, VCARD_UID from "
-            "ADDRESSBOOK_OBJECT where ADDRESSBOOK_RESOURCE_ID = %s",
-            [self.addressbook._resourceID]
-        )
-
-
     @inlineCallbacks
     def resourcesExist(self, names):
         returnValue(list(set(names).intersection(
             set((yield self.addressbook.listAddressbookObjects())))))
 
-
-    @inlineCallbacks
-    def resourceExists(self, name):
-        returnValue(bool(
-            (yield self._txn.execSQL(
-                "select RESOURCE_NAME from ADDRESSBOOK_OBJECT where "
-                "RESOURCE_NAME = %s and ADDRESSBOOK_RESOURCE_ID = %s",
-                [name, self.addressbook._resourceID]
-            ))
-        ))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/96a322ad/attachment.html>


More information about the calendarserver-changes mailing list