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

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


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

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:33:07 UTC (rev 6969)
+++ CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py	2011-02-16 14:33:18 UTC (rev 6970)
@@ -1254,21 +1254,30 @@
         returnValue(child)
 
 
+    @classproperty
+    def _datesByIDQuery(cls):
+        """
+        DAL query to retrieve created/modified dates based on a resource ID.
+        """
+        child = cls._homeChildSchema
+        return Select([child.CREATED, child.MODIFIED],
+                      From=child,
+                      Where=child.RESOURCE_ID == Parameter("resourceID"))
+
+
     @inlineCallbacks
     def initFromStore(self):
         """
-        Initialise this object from the store. We read in and cache all the extra metadata
-        from the DB to avoid having to do DB queries for those individually later.
+        Initialise this object from the store, based on its already-populated
+        resource ID. We read in and cache all the extra metadata from the DB to
+        avoid having to do DB queries for those individually later.
         """
+        self._created, self._modified = (
+            yield self._datesByIDQuery.on(self._txn,
+                                          resourceID=self._resourceID))[0]
+        yield self._loadPropertyStore()
 
-        self._created, self._modified = (yield self._txn.execSQL(
-            "select %(column_CREATED)s, %(column_MODIFIED)s from %(name)s "
-            "where %(column_RESOURCE_ID)s = %%s" % self._homeChildTable,
-            [self._resourceID]
-        ))[0]
 
-        yield self._loadPropertyStore()
-
     @property
     def _txn(self):
         return self._home._txn
@@ -1296,6 +1305,7 @@
         """
         return self._resourceID is not None
 
+
     def name(self):
         return self._name
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/c1cd09e3/attachment.html>


More information about the calendarserver-changes mailing list