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

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 16 06:32:33 PST 2011


Revision: 6966
          http://trac.macosforge.org/projects/calendarserver/changeset/6966
Author:   glyph at apple.com
Date:     2011-02-16 06:32:33 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
dalify objectWithID

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:32:22 UTC (rev 6965)
+++ CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py	2011-02-16 14:32:33 UTC (rev 6966)
@@ -1158,31 +1158,33 @@
         returnValue(child)
 
 
+    @classproperty
+    def _homeChildByIDQuery(cls):
+        """
+        DAL query that looks up home child names / bind modes by home child
+        resouce ID and home resource ID.
+        """
+        bind = cls._bindSchema
+        return Select([bind.RESOURCE_NAME, bind.BIND_MODE],
+                      From=bind,
+                      Where=(bind.RESOURCE_ID == Parameter("resourceID")
+                            ).And(bind.HOME_RESOURCE_ID == Parameter("homeID")))
+
+
     @classmethod
     @inlineCallbacks
     def objectWithID(cls, home, resourceID):
         """
-        Retrieve the child with the given C{resourceID} contained in this
+        Retrieve the child with the given C{resourceID} contained in the given
         C{home}.
 
         @param home: a L{CommonHome}.
         @param resourceID: a string.
-        @return: an L{CommonHomChild} or C{None} if no such child
+        @return: an L{CommonHomeChild} or C{None} if no such child
             exists.
         """
-
-        data = yield home._txn.execSQL("""
-            select %(column_RESOURCE_NAME)s, %(column_BIND_MODE)s from %(name)s
-            where
-              %(column_RESOURCE_ID)s = %%s and
-              %(column_HOME_RESOURCE_ID)s = %%s
-            """ % cls._bindTable,
-            [
-                resourceID,
-                home._resourceID,
-            ]
-        )
-
+        data = yield cls._homeChildByIDQuery.on(
+            home._txn, resourceID=resourceID, homeID=home._resourceID)
         if not data:
             returnValue(None)
         name, mode = data[0]
@@ -1190,6 +1192,7 @@
         yield child.initFromStore()
         returnValue(child)
 
+
     @classmethod
     @inlineCallbacks
     def create(cls, home, name):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/55f7568e/attachment-0001.html>


More information about the calendarserver-changes mailing list