[Zope] help with zodb
Pavlos Christoforou
pavlos@gaaros.com
Thu, 2 Mar 2000 17:11:19 -0500 (EST)
I have not followed the thread but reading this particular posting, seems
to me that you cannot do what you want to do (at least in a
straightforward way). Importing ZODB declares all kind of global
variables/methods, an important one being get_transaction() which returns
the current transaction. So if you do a get-transaction() in your external
method which transaction should it return? And how would the two
transaction managers interact? Couldn't you just register your root object
with the current ZODB (the one Zope is running), by just setting it as an
attribute to the root object?
Again I have not followed the thread so I may be way off topic.
Pavlos
On Thu, 2 Mar 2000, Garrett G. Hodgson wrote:
>
> thank you for your help. forgive my being obtuse,
> but i'm still not getting it.
>
> Jeff K. Hoffman jeff.hoffman@goingv.com wrote:
>
> > Only one process can access a ZODB at a time. You have two. The first is
> > Zope, and the second is the external method.
>
> ok. by "a ZODB" do you mean that the call in my external method
> is trying to reopen the ZODB zope is using? i'd assumed i was
> crating another one, with a separate FileStorage.
>
> > You don't need to re-open the ZODB inside your external method. By the
> > time you've gotten there, Zope already has it open.
>
> ok, then how does code in my external method get at that?
> that is, how do i create an object and stuff it in the DB?
> all the code examples i've seen follow the pattern in GetPeople().
>
> > AFAIK, you simply need to create an instance of your object and set it as
> > an attribute of another persistent object. The persistence should happen
> > automatically.
>
> how do i do this?
>
> i get the feeling i'm just missing something, perhaps thinking like
> a python programmer rather than a zope guru. i feel like there's
> some big obvious point that has escaped me, and i'm waiting for the
> big "AHA!".
>
> so, one more try. given the following external method:
>
> import ZODB, ZODB.FileStorage
>
>
> def GetPeople( self ):
> "Return list of people in DB"
>
> db = ZODB.DB( ZODB.FileStorage.FileStorage( 'TestDB.fs' ) )
> connection = db.open()
> root = connection.root()
> people = []
> for key in root.keys():
> people.append( root[ key ] )
> return people
>
> if __name__ == '__main__':
> for person in GetPeople( None ):
> print person.name, 'is', person.age, 'years old'
>
>
> referenced from a DTML Method:
>
> <dtml-in "GetPeople()">
> <dtml-var name> is <dtml-var age> years old.<br>
> </dtml-in>
>
> when i restart zope and view the method, it works once, but shows
> no persons. the second time, it fails with the traceback.
>
> what do i change to make it work?
>
> thank you for your patience.
>
> --
> Garry Hodgson Every night
> garry@sage.att.com a child is born
> Software Innovation Services is a Holy Night.
> AT&T Labs - Sophia Lyon Fahs
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>