[Checkins] SVN: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/ adjusted metadata retrieval

Adam Groszer agroszer at gmail.com
Tue Jul 1 04:41:02 EDT 2008


Log message for revision 87872:
  adjusted metadata retrieval
  - getAll: objects have to be retrieved always on call
  - interfaces can be retrieved from the registry

Changed:
  U   Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
  U   Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py

-=-
Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py	2008-07-01 08:26:55 UTC (rev 87871)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py	2008-07-01 08:41:01 UTC (rev 87872)
@@ -1,7 +1,7 @@
 
 from zope.interface import implements
 from zope.component import adapts
-from zope.component.interface import searchInterfaceUtilities 
+from zope.component.interface import searchInterfaceUtilities
 from zope.component import getUtility
 from zope.component import getUtilitiesFor
 from zope.app.catalog.interfaces import ICatalog
@@ -59,43 +59,42 @@
 class Metadata:
     implements(IDB)
     adapts(None)
-    
-    db= {}
 
-    classes = {}
-    
+    classes = None
+
     def __init__(self,context=None):
-        #all the interfaces are retrieved from the catalog
-        #items = list(searchInterfaceUtilities(self))
-        
+        #interfaces can be retrieved from the registry
+        #as they are unusual to change
+        self.classes = {}
+        items = list(searchInterfaceUtilities(None))
+        for name, iface in items:
+            self.classes[iface.__name__] = MClass(iface)
+
+        #catalogs = getUtilitiesFor(zc.relation.interfaces.ICatalog)
+        #for name, catalog in catalogs:
+        #    for index in catalog:
+        #        results = catalog.iterValueIndexInfo()
+        #        for result in results:
+        #            continue
+        #            #need to continue if this is required
+
+    def getAll(self, klassname):
+        #objects have to be retrieved always on call
+        #as they are subject to change
+
         catalogs = getUtilitiesFor(ICatalog)
         intids = getUtility(IIntIds)
         for name, catalog in catalogs:
-            for index in catalog:
-                if isinstance(catalog[index], AllIndex):                    
-                    interface = catalog[index].interface
-                    results = catalog.apply({index:(1,1)})
-                    obj_list = []
-                    for result in results:
-                        obj = intids.getObject(result)
-                        obj_list.append(obj)
-                    self.db.__setitem__(interface.__name__,obj_list)
-                    self.classes.__setitem__(interface.__name__,MClass(interface))
-        
-        catalogs = getUtilitiesFor(zc.relation.interfaces.ICatalog)
-        for name, catalog in catalogs:
-            for index in catalog:
-                results = catalog.iterValueIndexInfo()
-                for result in results:
-                    continue
-                    #need to continue if this is required
-                    
-        
+            for iname, index in catalog.items():
+                if isinstance(index, AllIndex):
+                    if index.interface.__name__ == klassname:
+                        interface = index.interface
+                        results = catalog.apply({iname:(1,1)})
+                        obj_list = [intids.getObject(result) for result in results]
+                        return obj_list
 
-    def getAll(self, klass):
-        return self.db[klass]
-    
-    def get_class(self, classname):
+        return None
+
+    def get_class(self, klassname):
         """Returns a MetaType instance for the class."""
-        return self.classes[classname]
-    
\ No newline at end of file
+        return self.classes[klassname]

Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py	2008-07-01 08:26:55 UTC (rev 87871)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py	2008-07-01 08:41:01 UTC (rev 87872)
@@ -11,7 +11,7 @@
 from ocql.database.metadata import Metadata
 from ocql.engine import OCQLEngine
 from ocql.interfaces import IDB
-from ocql.parser.queryparser import QueryParser, SymbolContainer 
+from ocql.parser.queryparser import QueryParser, SymbolContainer
 from ocql.qoptimizer.qoptimizer import QueryOptimizer
 from ocql.queryobject.queryobject import *
 from ocql.rewriter.rewriter import Rewriter
@@ -33,12 +33,12 @@
         provideAdapter(AlgebraOptimizer)
         provideAdapter(AlgebraCompiler)
         provideAdapter(Metadata)
-        
+
         setupInterfaces(self)
         setupCatalog(self)
-        
+
         self.engine = OCQLEngine()
-        
+
     #just copy following methods from test_old
     def doone(self, query, qo, expected):
         print "==============="
@@ -63,7 +63,7 @@
 
         self.assertEqual(expected, result)
 
-       
+
     def test_gsoc(self):
         metadata = IDB(None)
         symbols = SymbolContainer()
@@ -81,14 +81,14 @@
                             '') )
 
         self.doit(query, qo, set([]))
-        
-        
+
+
         symbols = SymbolContainer()
         #
         # Simple SELECT ALL
         #
         # set [ c in IStudent | c ]
-        #           
+        #
         query = "[c in IStudent | c]"
         qo = Query(
                 metadata, symbols,
@@ -99,10 +99,10 @@
                        Identifier(metadata,symbols,'c'),
                        Identifier(metadata,symbols,'IStudent'))
                 ], Identifier(metadata,symbols,'c'))
-        
-        self.doit(query, qo, set(metadata.db['IStudent']))
-        
-        
+
+        self.doit(query, qo, set(metadata.getAll('IStudent')))
+
+
         symbols = SymbolContainer()
         #
         # Selecting a property
@@ -119,9 +119,9 @@
                            Identifier(metadata, symbols,'c'),
                            Identifier(metadata, symbols, 'IStudent'))
                     ],Identifier(metadata, symbols, 'c.name'))
-        self.doit(query, qo, set(["Charith", "Jane", "Ann"]))                   
-        
-        
+        self.doit(query, qo, set(["Charith", "Jane", "Ann"]))
+
+
         symbols = SymbolContainer()
         #
         # Filtering --one result
@@ -142,10 +142,10 @@
                            Identifier(metadata, symbols, 'c.description'),
                            Identifier(metadata, symbols, '"test"'))
                    ], Identifier(metadata, symbols, 'c.name'))
-                   
+
         self.doit(query, qo, set(["Save the world"]))
-        
-        
+
+
 def test_suite():
     flags =  doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS
     return unittest.TestSuite((
@@ -154,5 +154,3 @@
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
-    
-    



More information about the Checkins mailing list