[Commits] (twl) Support for queries over ref-collections

commits at osafoundation.org commits at osafoundation.org
Thu Aug 26 17:30:07 PDT 2004


Commit by: twl
Modified files:
chandler/repository/query/Query.py 1.6 1.7
chandler/repository/query/tests/TestSimpleQueries.py 1.6 1.7

Log message:
Support for queries over ref-collections
Add tests for
    queries over ref-collections
    queries involving enumerations


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/repository/query/Query.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7
http://cvs.osafoundation.org/index.cgi/chandler/repository/query/tests/TestSimpleQueries.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7

Index: chandler/repository/query/Query.py
diff -u chandler/repository/query/Query.py:1.6 chandler/repository/query/Query.py:1.7
--- chandler/repository/query/Query.py:1.6	Thu Aug 26 15:43:15 2004
+++ chandler/repository/query/Query.py	Thu Aug 26 17:30:04 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.6 $"
-__date__      = "$Date: 2004/08/26 22:43:15 $"
+__revision__  = "$Revision: 1.7 $"
+__date__      = "$Date: 2004/08/27 00:30:04 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -149,9 +149,9 @@
                 name = name[1:-1]
             kind = self.__rep.findPath(name)
             if kind is not None:
-                return kind
+                return ('kind', kind)
             if name.startswith('$'): # variable argument
-                return self.args[int(name[1:])-1]
+                return ('arg',self.args[int(name[1:])-1])
             assert False, "lookup_source couldn't handle %s" % name
 
         def compile_predicate(ast):
@@ -294,11 +294,15 @@
         @type param: tuple (source collection, compiled predicate)
         """
         source = plan[0]
-        self._kind = source
-        self._predicate = plan[1]
 
-        import repository.item.Query as RepositoryQuery
-        items = RepositoryQuery.KindQuery(recursive=self.recursive).run([source])
+        if source[0] == 'kind':
+            self._kind = source[1]
+            self._predicate = plan[1]
+
+            import repository.item.Query as RepositoryQuery
+            items = RepositoryQuery.KindQuery(recursive=self.recursive).run([source[1]])
+        else: # it = 'arg'
+            items = source[1]
 
         for i in items:
             if eval(self._predicate):

Index: chandler/repository/query/tests/TestSimpleQueries.py
diff -u chandler/repository/query/tests/TestSimpleQueries.py:1.6 chandler/repository/query/tests/TestSimpleQueries.py:1.7
--- chandler/repository/query/tests/TestSimpleQueries.py:1.6	Mon Aug 23 19:06:25 2004
+++ chandler/repository/query/tests/TestSimpleQueries.py	Thu Aug 26 17:30:05 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.6 $"
-__date__      = "$Date: 2004/08/24 02:06:25 $"
+__revision__  = "$Revision: 1.7 $"
+__date__      = "$Date: 2004/08/27 00:30:05 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -61,7 +61,7 @@
         results = self._executeQuery(u'for i in "//Schema/Core/Kind" where i.hasAttributeValue("superKinds")')
         self._checkQuery(lambda i: not i.hasAttributeValue("superKinds"), results)
 
-    def testWithData(self):
+    def testItemTraversalQuery(self):
         """ Test a multiple item path traversal in the query predicate """
         tools.timing.reset()
         tools.timing.begin("Setup Infrastructure")
@@ -91,6 +91,49 @@
         results = self._executeQuery(u"for i in '//parcels/osaf/contentmodel/contacts/Contact' where contains(i.contactName.firstName,'a')")
         self._checkQuery(lambda i: not 'a' in i.contactName.firstName, results)
 
+    def testEnumerationQuery(self):
+        """ Test an enumeration attribute in the query predicate """
+        tools.timing.reset()
+        tools.timing.begin("Setup Infrastructure")
+        import application
+        import application.Globals as Globals
+        import osaf.contentmodel.tests.GenerateItems as GenerateItems
+        from osaf.framework.notifications.NotificationManager import NotificationManager
+        Globals.repository = self.rep
+        Globals.notificationManager = NotificationManager()
+        tools.timing.end("Setup Infrastructure")
+
+        tools.timing.begin("Load Calendar Parcel")
+        self.loadParcels(
+         ['http://osafoundation.org/parcels/osaf/contentmodel/calendar']
+        )
+        tools.timing.end("Load Calendar Parcel")
+
+        tools.timing.begin("Generate Calendar Events")
+        GenerateItems.generateCalendarEventItems(100,30)
+        tools.timing.end("Generate Calendar Events")
+
+        tools.timing.begin("Commit Calendar Events")
+        self.rep.commit()
+        tools.timing.end("Commit Calendar Events")
+#        tools.timing.results()
+        
+        results = self._executeQuery(u"for i in '//parcels/osaf/contentmodel/calendar/CalendarEvent' where i.importance == 'fyi'")
+        self._checkQuery(lambda i: not i.importance == 'fyi', results)
+
+    def testRefCollectionQuery(self):
+        """ Test a query over ref collections """
+        import repository.query.Query as Query
+        kind = self.rep.findPath('//Schema/Core/Kind')
+        refcol = kind.attributes
+
+        queryString = u"for i in $0 where contains(i.itsName,'ttributes')"
+        q = Query.Query(self.rep, queryString)
+        q.args = [ refcol ]
+        q.execute()
+
+        self._checkQuery(lambda i: not 'ttributes' in i.itsName, q)
+
 if __name__ == "__main__":
 #    import hotshot
 #    profiler = hotshot.Profile('/tmp/TestItems.hotshot')



More information about the Commits mailing list