Hello~~ I am playing with using the Catalog class in ZCatalog along with CatalogQuery to create a generic object layer on top of ZODB. I can index and search til I am blue in the face, and I always get the correct answers. Now for the problems... Say I have the following obj: class test(Persistent): variable = 1 def function(self): print self.__dict__ now if I do: catalog = Catalog() catalog.addIndex('variable', Fieldindex('variable')) catalog.addColumn('variable') obj = test() catalog.catalogObject(obj, id(obj)) catalog_query = CatalogQuery(catalog, "variable==1") results = catalog_query() for r in results: print r.variable # ok print r.getRID() # ok print r.function # NameError ...so I can get an object (a mybrains instance )back that allows me to print r.variable, but I cannot get r.function(). How does one do this? Is there a mapping between RIDs in the catalog and real objects somewhere? Do I need to do that mapping in an IOBtree (it would make the most sense since I am using id(obj) as the uid in the catalog)? Is there somewhere in Zope/google/web that does this? Thanks for any help!! Nic
try: ob = r.getObject() ob.function() or if that doesn't work: ob = catalog.getobject(r.data_record_id_) ob.function() Bear in mind that getObject traverses to the object which is expensive both in time and memory if the number of results is large. hth, -Casey On Wednesday 29 May 2002 04:05 pm, Nicholas Henke wrote:
Hello~~ I am playing with using the Catalog class in ZCatalog along with CatalogQuery to create a generic object layer on top of ZODB. I can index and search til I am blue in the face, and I always get the correct answers. Now for the problems...
Say I have the following obj: class test(Persistent): variable = 1 def function(self): print self.__dict__
now if I do: catalog = Catalog() catalog.addIndex('variable', Fieldindex('variable')) catalog.addColumn('variable') obj = test() catalog.catalogObject(obj, id(obj))
catalog_query = CatalogQuery(catalog, "variable==1") results = catalog_query() for r in results: print r.variable # ok print r.getRID() # ok print r.function # NameError
...so I can get an object (a mybrains instance )back that allows me to print r.variable, but I cannot get r.function(). How does one do this? Is there a mapping between RIDs in the catalog and real objects somewhere? Do I need to do that mapping in an IOBtree (it would make the most sense since I am using id(obj) as the uid in the catalog)? Is there somewhere in Zope/google/web that does this?
Thanks for any help!! Nic
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
On Wednesday 29 May 2002 04:20 pm, Casey Duncan wrote:
try:
ob = r.getObject() ob.function()
ob gets returned as None -- I think this is due to AbstractCatalogBrain::getObject(). I don't believe self.aq_parent is set correctly -- how is it supposed to be set ?
or if that doesn't work:
ob = catalog.getobject(r.data_record_id_)
AttributeError -- getobject doesnt exist?
ob.function()
Bear in mind that getObject traverses to the object which is expensive both in time and memory if the number of results is large.
OK -- is there a better way to do all of this ? What I am trying to do is have ZODB store objects and Catalog maintain indexes on them. Now I can come back and do a 'SELECT' on the objects, say for variable != 1, and somehow get access to the original objects if I wish to. Is there somewhere that documents using Catalog and PluginIndexes without all of the other Zope stuff? Any documents on using it with the Zope stuff ? Nic
hth,
-Casey
On Wednesday 29 May 2002 04:05 pm, Nicholas Henke wrote:
Hello~~ I am playing with using the Catalog class in ZCatalog along with
CatalogQuery
to create a generic object layer on top of ZODB. I can index and search til
I
am blue in the face, and I always get the correct answers. Now for the problems...
Say I have the following obj: class test(Persistent): variable = 1 def function(self): print self.__dict__
now if I do: catalog = Catalog() catalog.addIndex('variable', Fieldindex('variable')) catalog.addColumn('variable') obj = test() catalog.catalogObject(obj, id(obj))
catalog_query = CatalogQuery(catalog, "variable==1") results = catalog_query() for r in results: print r.variable # ok print r.getRID() # ok print r.function # NameError
...so I can get an object (a mybrains instance )back that allows me to print r.variable, but I cannot get r.function(). How does one do this? Is there a mapping between RIDs in the catalog and
real
objects somewhere? Do I need to do that mapping in an IOBtree (it would make the most sense since I am using id(obj) as the uid in the catalog)? Is there somewhere in Zope/google/web that does this?
Thanks for any help!! Nic
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
[removed zodb-dev, don't cross post!] If you are using plain catalogs then you need to store the path to the object somewhere (as metadata or as Zope does as the uid of the catalog record). Then traverse to it based on this path. In Zope you use (restrictedTraverse (or unrestrictedTraverse) to do this). You might need to roll your own traverser, but it shouldn't be too hard. hth, Casey On Wednesday 29 May 2002 04:30 pm, Nicholas Henke wrote:
On Wednesday 29 May 2002 04:20 pm, Casey Duncan wrote:
try:
ob = r.getObject() ob.function()
ob gets returned as None -- I think this is due to AbstractCatalogBrain::getObject(). I don't believe self.aq_parent is set correctly -- how is it supposed to be set ?
or if that doesn't work:
ob = catalog.getobject(r.data_record_id_)
AttributeError -- getobject doesnt exist?
ob.function()
Bear in mind that getObject traverses to the object which is expensive both in time and memory if the number of results is large.
OK -- is there a better way to do all of this ? What I am trying to do is have ZODB store objects and Catalog maintain indexes on them. Now I can come back and do a 'SELECT' on the objects, say for variable != 1, and somehow get access to the original objects if I wish to. Is there somewhere that documents using Catalog and PluginIndexes without all of the other Zope stuff? Any documents on using it with the Zope stuff ?
Nic
I think you must call getObject() on the mybrains instance first to get the object! Andreas ----- Original Message ----- From: "Nicholas Henke" <henken@unholymess.com> To: <zope-dev@zope.org>; <zodb-dev@zope.org> Sent: Wednesday, May 29, 2002 16:05 Subject: [ZODB-Dev] ZODB, Catalog and actually using it Hello~~ I am playing with using the Catalog class in ZCatalog along with CatalogQuery to create a generic object layer on top of ZODB. I can index and search til I am blue in the face, and I always get the correct answers. Now for the problems... Say I have the following obj: class test(Persistent): variable = 1 def function(self): print self.__dict__ now if I do: catalog = Catalog() catalog.addIndex('variable', Fieldindex('variable')) catalog.addColumn('variable') obj = test() catalog.catalogObject(obj, id(obj)) catalog_query = CatalogQuery(catalog, "variable==1") results = catalog_query() for r in results: print r.variable # ok print r.getRID() # ok print r.function # NameError ...so I can get an object (a mybrains instance )back that allows me to print r.variable, but I cannot get r.function(). How does one do this? Is there a mapping between RIDs in the catalog and real objects somewhere? Do I need to do that mapping in an IOBtree (it would make the most sense since I am using id(obj) as the uid in the catalog)? Is there somewhere in Zope/google/web that does this? Thanks for any help!! Nic _______________________________________________ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org http://lists.zope.org/mailman/listinfo/zodb-dev
participants (3)
-
Andreas Jung -
Casey Duncan -
Nicholas Henke