[z3-checkins] r32084 - in z3/sqlos/branch/kobold-sqlos/src/sqlos: . ftests
kobold at codespeak.net
kobold at codespeak.net
Fri Sep 8 15:10:29 CEST 2006
Author: kobold
Date: Fri Sep 8 15:10:28 2006
New Revision: 32084
Modified:
z3/sqlos/branch/kobold-sqlos/src/sqlos/container.py
z3/sqlos/branch/kobold-sqlos/src/sqlos/ftests/joins.txt
Log:
Added cache for join containers; modified all the containers to return parent-aware objects;
Modified: z3/sqlos/branch/kobold-sqlos/src/sqlos/container.py
==============================================================================
--- z3/sqlos/branch/kobold-sqlos/src/sqlos/container.py (original)
+++ z3/sqlos/branch/kobold-sqlos/src/sqlos/container.py Fri Sep 8 15:10:28 2006
@@ -113,7 +113,8 @@
""" Return a sequence-like object containing the names
associated with the objects that appear in the folder
"""
- for name, obj in self.items(): yield name
+ for name, obj in self.items():
+ yield name
def __iter__(self):
return iter(self.keys())
@@ -122,7 +123,8 @@
""" Return a sequence-like object containing the objects that
appear in the folder.
"""
- for name, obj in self.items(): yield obj
+ for name, obj in self.items():
+ yield contained(obj, parent=self, name=name)
def items(self):
"""Return a sequence-like object containing tuples of the form
@@ -190,7 +192,7 @@
KeyError is raised.
"""
try:
- return self[name]
+ return contained(self[name], parent=self, name=name)
except KeyError:
return default
@@ -275,7 +277,7 @@
obj = super(SQLIsolatedContainer, self).__getitem__(name)
if hasattr(obj, 'domains'):
if self.container_id in obj.domains:
- return obj
+ return contained(obj, parent=self, name=name)
raise KeyError, name
@@ -330,6 +332,7 @@
implements(ISQLObjectJoinContainer)
_allowed_joins = ()
+ _containers = ()
def __getitem__(self, name):
for j in self.sqlmeta.joins:
@@ -338,8 +341,14 @@
for i, container in self._allowed_joins:
if not i.implementedBy(j.otherClass):
continue
- c = container()
- c._filters = {j.joinColumn[:-3] + 'ID': self.id}
+ if name in self._containers:
+ c = self._containers[name]
+ else:
+ c = container()
+ c._filters = {j.joinColumn[:-3] + 'ID': self.id}
+ if not self._containers:
+ self._containers = {}
+ self._containers[name] = c
return contained(c, parent=self, name=name)
raise KeyError, name
@@ -349,11 +358,11 @@
def items(self):
for key in self.keys():
- yield (key, self[key])
+ yield (key, contained(self[key], parent=self, name=key))
def values(self):
for key, obj in self.items():
- yield obj
+ yield contained(obj, parent=self, name=key)
def __contains__(self, name):
return name in self.keys()
Modified: z3/sqlos/branch/kobold-sqlos/src/sqlos/ftests/joins.txt
==============================================================================
--- z3/sqlos/branch/kobold-sqlos/src/sqlos/ftests/joins.txt (original)
+++ z3/sqlos/branch/kobold-sqlos/src/sqlos/ftests/joins.txt Fri Sep 8 15:10:28 2006
@@ -61,6 +61,11 @@
>>> lessie.id in dogs
False
+Test the cache for the containers:
+
+ >>> john['dogs'] == john['dogs']
+ True
+
CleanUp:
>>> from sqlos.testing.sampleperson import dropTestingTables
More information about the z3-checkins
mailing list