[CalendarServer-changes] [7001] CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/ sql.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 16 06:39:11 PST 2011
Revision: 7001
http://trac.macosforge.org/projects/calendarserver/changeset/7001
Author: glyph at apple.com
Date: 2011-02-16 06:39:11 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
dalify _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:39:00 UTC (rev 7000)
+++ CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py 2011-02-16 14:39:11 UTC (rev 7001)
@@ -2086,37 +2086,59 @@
returnValue(objectResource)
+
+ @classmethod
+ def _allWithParentAnd(cls, column, paramName):
+ """
+ DAL query for all columns where PARENT_RESOURCE_ID matches a parentID
+ parameter and a given instance column matches a given parameter name.
+ """
+ return Select(
+ cls._allColumns, From=cls._objectSchema,
+ Where=(column == Parameter(paramName)).And(
+ cls._objectSchema.PARENT_RESOURCE_ID == Parameter("parentID"))
+ )
+
+
+ @classproperty
+ def _allWithParentAndName(cls):
+ return cls._allWithParentAnd(cls._objectSchema.RESOURCE_NAME, "name")
+
+
+ @classproperty
+ def _allWithParentAndUID(cls):
+ return cls._allWithParentAnd(cls._objectSchema.UID, "uid")
+
+
+ @classproperty
+ def _allWithParentAndID(cls):
+ return cls._allWithParentAnd(cls._objectSchema.RESOURCE_ID,
+ "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. Either the
- name or uid is present, so we have to tweak the query accordingly.
+ 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. Either the name or uid is present, so we have to
+ tweak the query accordingly.
@return: L{self} if object exists in the DB, else C{None}
"""
if self._name:
- rows = yield self._txn.execSQL(self._selectAllColumns() + """
- from %(name)s
- where %(column_RESOURCE_NAME)s = %%s and %(column_PARENT_RESOURCE_ID)s = %%s
- """ % self._objectTable,
- [self._name, self._parentCollection._resourceID]
- )
+ rows = yield self._allWithParentAndName.on(
+ self._txn, name=self._name,
+ parentID=self._parentCollection._resourceID)
elif self._uid:
- rows = yield self._txn.execSQL(self._selectAllColumns() + """
- from %(name)s
- where %(column_UID)s = %%s and %(column_PARENT_RESOURCE_ID)s = %%s
- """ % self._objectTable,
- [self._uid, self._parentCollection._resourceID]
- )
+ rows = yield self._allWithParentAndUID.on(
+ self._txn, uid=self._uid,
+ parentID=self._parentCollection._resourceID)
elif self._resourceID:
- rows = yield self._txn.execSQL(self._selectAllColumns() + """
- from %(name)s
- where %(column_RESOURCE_ID)s = %%s and %(column_PARENT_RESOURCE_ID)s = %%s
- """ % self._objectTable,
- [self._resourceID, self._parentCollection._resourceID]
- )
+ rows = yield self._allWithParentAndID.on(
+ self._txn, resourceID=self._resourceID,
+ parentID=self._parentCollection._resourceID)
if rows:
self._initFromRow(tuple(rows[0]))
yield self._loadPropertyStore()
@@ -2124,6 +2146,7 @@
else:
returnValue(None)
+
@classmethod
def _selectAllColumns(cls):
"""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/f9663a11/attachment.html>
More information about the calendarserver-changes
mailing list