[Commits] (vajda) - Kind.iterAttributes() now caches inherited attributes along the way

commits at osafoundation.org commits at osafoundation.org
Thu Mar 25 11:09:19 PST 2004


Commit by: vajda
Modified files:
osaf/chandler/Chandler/repository/item/Item.py 1.113 1.114
osaf/chandler/Chandler/repository/item/PersistentCollections.py 1.7 1.8
osaf/chandler/Chandler/repository/item/Query.py 1.6 1.7
osaf/chandler/Chandler/repository/schema/Kind.py 1.57 1.58

Log message:
   - Kind.iterAttributes() now caches inherited attributes along the way
   - 'initialValue' aspect values now added to items upon construction
   - added Kind.flushCaches()


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/item/Item.py.diff?r1=text&tr1=1.113&r2=text&tr2=1.114
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/item/PersistentCollections.py.diff?r1=text&tr1=1.7&r2=text&tr2=1.8
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/item/Query.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/repository/schema/Kind.py.diff?r1=text&tr1=1.57&r2=text&tr2=1.58

Index: osaf/chandler/Chandler/repository/item/Item.py
diff -u osaf/chandler/Chandler/repository/item/Item.py:1.113 osaf/chandler/Chandler/repository/item/Item.py:1.114
--- osaf/chandler/Chandler/repository/item/Item.py:1.113	Tue Mar 23 21:08:27 2004
+++ osaf/chandler/Chandler/repository/item/Item.py	Thu Mar 25 11:08:48 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.113 $"
-__date__      = "$Date: 2004/03/24 05:08:27 $"
+__revision__  = "$Revision: 1.114 $"
+__date__      = "$Date: 2004/03/25 19:08:48 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -60,6 +60,9 @@
 
         self._setParent(parent)
 
+        if kind is not None:
+            kind.getInitialValues(self, self._values, self._references)
+
     def _fillItem(self, name, parent, kind, **kwds):
 
         self._uuid = kwds['uuid']
@@ -454,10 +457,6 @@
         except KeyError:
             pass
 
-        value = self.getAttributeAspect(name, 'initialValue', default=Item.Nil)
-        if value is not Item.Nil:
-            return self.setAttributeValue(name, value)
-
         inherit = self.getAttributeAspect(name, 'inheritFrom', default=None)
         if inherit is not None:
             value = self
@@ -863,12 +862,6 @@
 
         isItem = isinstance(value, Item)
         attrValue = _attrDict.get(attribute, Item.Nil)
-
-        if attrValue is Item.Nil:
-            attrValue = self.getAttributeAspect(attribute, 'initialValue',
-                                                default=Item.Nil)
-            if attrValue is not Item.Nil:
-                attrValue = self.setAttributeValue(attribute, attrValue)
 
         if attrValue is Item.Nil:
             return self.setValue(attribute, value, key, alias, _attrDict)

Index: osaf/chandler/Chandler/repository/item/PersistentCollections.py
diff -u osaf/chandler/Chandler/repository/item/PersistentCollections.py:1.7 osaf/chandler/Chandler/repository/item/PersistentCollections.py:1.8
--- osaf/chandler/Chandler/repository/item/PersistentCollections.py:1.7	Tue Mar 23 21:08:27 2004
+++ osaf/chandler/Chandler/repository/item/PersistentCollections.py	Thu Mar 25 11:08:48 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.7 $"
-__date__      = "$Date: 2004/03/24 05:08:27 $"
+__revision__  = "$Revision: 1.8 $"
+__date__      = "$Date: 2004/03/25 19:08:48 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -109,6 +109,10 @@
         if args:
             self.extend(args)
 
+    def copy(self, item, attribute, companion, original):
+
+        return PersistentList(item, attribute, companion, *original)
+
     def __setitem__(self, index, value):
 
         self._storeValue(value)
@@ -231,6 +235,10 @@
 
         if kwds:
             self.update(kwds)
+
+    def copy(self, item, attribute, companion, original):
+
+        return PersistentDict(item, attribute, companion, **original)
 
     def __delitem__(self, key):
 

Index: osaf/chandler/Chandler/repository/item/Query.py
diff -u osaf/chandler/Chandler/repository/item/Query.py:1.6 osaf/chandler/Chandler/repository/item/Query.py:1.7
--- osaf/chandler/Chandler/repository/item/Query.py:1.6	Tue Mar 23 21:08:27 2004
+++ osaf/chandler/Chandler/repository/item/Query.py	Thu Mar 25 11:08:48 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.6 $"
-__date__      = "$Date: 2004/03/24 05:08:27 $"
+__revision__  = "$Revision: 1.7 $"
+__date__      = "$Date: 2004/03/25 19:08:48 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -33,7 +33,7 @@
 
 
 class KindQuery(Query):
-    'A query that returns all items of certain kinds or subkind thereof'
+    'A query that returns all items of certain kinds or subkinds thereof'
 
     def __init__(self, recursive=True):
 

Index: osaf/chandler/Chandler/repository/schema/Kind.py
diff -u osaf/chandler/Chandler/repository/schema/Kind.py:1.57 osaf/chandler/Chandler/repository/schema/Kind.py:1.58
--- osaf/chandler/Chandler/repository/schema/Kind.py:1.57	Tue Mar 23 21:08:51 2004
+++ osaf/chandler/Chandler/repository/schema/Kind.py	Thu Mar 25 11:08:49 2004
@@ -1,12 +1,13 @@
 
-__revision__  = "$Revision: 1.57 $"
-__date__      = "$Date: 2004/03/24 05:08:51 $"
+__revision__  = "$Revision: 1.58 $"
+__date__      = "$Date: 2004/03/25 19:08:49 $"
 __copyright__ = "Copyright (c) 2002 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
 
 from repository.item.Item import Item
-from repository.item.ItemRef import RefDict
+from repository.item.ItemRef import RefDict, NoneRef
+from repository.item.PersistentCollections import PersistentCollection
 from repository.util.Path import Path
 from repository.util.UUID import UUID
 from repository.util.SingleRef import SingleRef
@@ -17,6 +18,9 @@
     def __init__(self, name, parent, kind):
 
         super(Kind, self).__init__(name, parent, kind)
+        self.__init()
+
+    def __init(self):
 
         # recursion avoidance
         self._values['notFoundAttributes'] = []
@@ -28,19 +32,13 @@
         # will allow schema items to live anywhere
         self._status |= Item.SCHEMA
 
+        self._initialValues = None
+        self._initialReferences = None
+
     def _fillItem(self, name, parent, kind, **kwds):
 
         super(Kind, self)._fillItem(name, parent, kind, **kwds)
-
-        # recursion avoidance
-        self._values['notFoundAttributes'] = []
-        refDict = self._refDict('inheritedAttributes',
-                                'inheritingKinds', False)
-        self._references['inheritedAttributes'] = refDict
-        self._status |= Item.SCHEMA
-
-        # will allow schema items to live anywhere
-        self._status |= Item.SCHEMA
+        self.__init()
 
     def newItem(self, name, parent):
         """Create an item of this kind.
@@ -128,10 +126,14 @@
         """
 
         if inherited:
+            inheritedAttributes = self.inheritedAttributes
             for superKind in self._getSuperKinds():
-                for pair in superKind.iterAttributes(inherited,
-                                                     localOnly, globalOnly):
-                    yield pair
+                for name, attribute in superKind.iterAttributes(inherited,
+                                                                localOnly,
+                                                                globalOnly):
+                    if not attribute.itsUUID in inheritedAttributes:
+                        inheritedAttributes.append(attribute, alias=name)
+                    yield (name, attribute)
 
         attributes = self.getAttributeValue('attributes', default=None)
         if attributes is not None:
@@ -201,6 +203,43 @@
 
         return False
 
+    def getInitialValues(self, item, values, references):
+
+        # setup cache
+        if self._initialValues is None:
+            self._initialValues = {}
+            self._initialReferences = {}
+            for name, attribute in self.iterAttributes():
+                value = attribute.getAspect('initialValue', default=Item.Nil)
+                if value is not Item.Nil:
+                    otherName = attribute.getAspect('otherName')
+                    if otherName is None:
+                        self._initialValues[name] = value
+                    else:
+                        self._initialReferences[name] = value
+
+        for name, value in self._initialValues.iteritems():
+            if isinstance(value, PersistentCollection):
+                value = value.copy(item, name, value._companion, value)
+            values[name] = value
+
+        # only initialValue of None for refs is supported at the moment
+        for name, value in self._initialReferences.iteritems():
+            if value is None:
+                value = NoneRef
+            references[name] = value
+
+    def flushCaches(self):
+
+        self.inheritedAttributes.clear()
+        del self.notFoundAttributes[:]
+        self._initialValues = None
+        self._initialReferences = None
+
+        for subKind in self.getAttributeValue('subKinds',
+                                              _attrDict=self._references,
+                                              default=[]):
+            subKind.flushCaches()
 
     # begin typeness of Kind as SingleRef
     



More information about the Commits mailing list