[CalendarServer-changes] [7019] CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/ sql.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 16 06:42:32 PST 2011
Revision: 7019
http://trac.macosforge.org/projects/calendarserver/changeset/7019
Author: glyph at apple.com
Date: 2011-02-16 06:42:32 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
dalify NotificationObject.setData
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:42:21 UTC (rev 7018)
+++ CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py 2011-02-16 14:42:32 UTC (rev 7019)
@@ -2717,6 +2717,36 @@
return self.uid() + ".xml"
+ @classproperty
+ def _newNotificationQuery(cls):
+ no = cls._objectSchema
+ return Insert(
+ {
+ no.NOTIFICATION_HOME_RESOURCE_ID: Parameter("homeID"),
+ no.NOTIFICATION_UID: Parameter("uid"),
+ no.XML_TYPE: Parameter("xmlType"),
+ no.XML_DATA: Parameter("xmlData"),
+ no.MD5: Parameter("md5"),
+ },
+ Return=[no.RESOURCE_ID, no.CREATED, no.MODIFIED]
+ )
+
+
+ @classproperty
+ def _updateNotificationQuery(cls):
+ no = cls._objectSchema
+ return Update(
+ {
+ no.XML_TYPE: Parameter("xmlType"),
+ no.XML_DATA: Parameter("xmlData"),
+ no.MD5: Parameter("md5"),
+ },
+ Where=(no.NOTIFICATION_HOME_RESOURCE_ID == Parameter("homeID")).And(
+ no.NOTIFICATION_UID == Parameter("uid")),
+ Return=no.MODIFIED
+ )
+
+
@inlineCallbacks
def setData(self, uid, xmltype, xmldata, inserting=False):
"""
@@ -2727,30 +2757,18 @@
self._md5 = hashlib.md5(xmldata).hexdigest()
self._size = len(xmldata)
if inserting:
- rows = yield self._txn.execSQL("""
- insert into NOTIFICATION
- (NOTIFICATION_HOME_RESOURCE_ID, NOTIFICATION_UID, XML_TYPE, XML_DATA, MD5)
- values
- (%s, %s, %s, %s, %s)
- returning
- RESOURCE_ID,
- CREATED,
- MODIFIED
- """,
- [self._home._resourceID, uid, self._xmlType.toxml(), xmldata, self._md5]
+ rows = yield self._newNotificationQuery.on(
+ self._txn, homeID=self._home._resourceID, uid=uid,
+ xmlType=self._xmlType.toxml(), xmlData=xmldata, md5=self._md5
)
self._resourceID, self._created, self._modified = rows[0]
self._loadPropertyStore()
else:
- rows = yield self._txn.execSQL("""
- update NOTIFICATION
- set XML_TYPE = %s, XML_DATA = %s, MD5 = %s
- where NOTIFICATION_HOME_RESOURCE_ID = %s and NOTIFICATION_UID = %s
- returning MODIFIED
- """,
- [self._xmlType.toxml(), xmldata, self._md5, self._home._resourceID, uid])
+ rows = yield self._updateNotificationQuery.on(
+ self._txn, homeID=self._home._resourceID, uid=uid,
+ xmlType=self._xmlType.toxml(), xmlData=xmldata, md5=self._md5
+ )
self._modified = rows[0][0]
-
self._objectText = xmldata
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/4081590e/attachment.html>
More information about the calendarserver-changes
mailing list