[CalendarServer-changes] [9615] CalendarServer/branches/users/glyph/q

source_changes at macosforge.org source_changes at macosforge.org
Sat Aug 11 01:54:54 PDT 2012


Revision: 9615
          http://trac.macosforge.org/projects/calendarserver/changeset/9615
Author:   glyph at apple.com
Date:     2012-08-11 01:54:53 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
adjust the implementation to give better failures

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/q/

Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py	2012-08-11 08:54:53 UTC (rev 9614)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/record.py	2012-08-11 08:54:53 UTC (rev 9615)
@@ -40,6 +40,16 @@
 
 
 class _RecordBase(object):
+    """
+    Superclass for all database-backed record classes.  (i.e.  an object mapped
+    from a database record).
+
+    @cvar __colmap__: map of L{ColumnSyntax} objects to attribute names.
+    @type __colmap__: L{dict}
+
+    @cvar __attrmap__: map of attribute names to L{ColumnSyntax} objects.
+    @type __attrmap__: L{dict}
+    """
     @classmethod
     @inlineCallbacks
     def load(cls, txn, *primaryKey):
@@ -52,8 +62,7 @@
         row = rows[0]
         self = cls()
         for (column, value) in zip(allColumns, row):
-            attrname = column.model.name.lower()
-            setattr(self, attrname, value)
+            setattr(self, cls.__colmap__[column], value)
         returnValue(self)
 
 
@@ -63,13 +72,9 @@
         """
         Create a row.
         """
-        tbl = cls.__tbl__
         self = cls()
         colmap = {}
-        allColumns = list(tbl)
-        attrtocol = {}
-        for column in allColumns:
-            attrtocol[column.model.name.lower()] = column
+        attrtocol = cls.__attrmap__
         for attr in k:
             setattr(self, attr, k[attr])
             # FIXME: better error reporting
@@ -78,7 +83,15 @@
         returnValue(self)
 
 
+    def update(self, **kw):
+        """
+        Update the given attributes in the database.
 
+        @return: a L{Deferred} that fires when the updates have been completed.
+        """
+
+
+
 def fromTable(table):
     """
     Create a L{type} that maps the columns from a particular table.
@@ -89,8 +102,15 @@
     @param table: The table.
     @type table: L{twext.enterprise.dal.syntax.TableSyntax}
     """
+    attrmap = {}
+    colmap = {}
+    allColumns = list(table)
+    for column in allColumns:
+        attrname = column.model.name.lower()
+        attrmap[attrname] = column
+        colmap[column] = attrname
     return type(table.model.name, tuple([_RecordBase]),
-                dict(__tbl__=table))
+                dict(__tbl__=table, __attrmap__=attrmap, __colmap__=colmap))
 
 
 __all__ = [
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/5f8b7de1/attachment.html>


More information about the calendarserver-changes mailing list