[Zope] RE: Holding ref to database connection

MKinsley@empirecorp.org MKinsley@empirecorp.org
Thu, 22 Aug 2002 11:43:45 -0400


Thank you Alan! The example below does match our structure. A big help!

-----Original Message-----
From: alan runyan [mailto:runyaga@runyaga.com]
Sent: Thursday, August 22, 2002 10:40 AM
To: MKinsley@empirecorp.org
Subject: Re: Holding ref to database connection


no you dont have to import anything.. the ZODB and the Ext Mount has done
everything you want.
create a python script, say in the root of your ZODB.  (it could be
anywhere).   lets assume your structure is
  / - root of ZODB aka 'app'
  --- / mcif (a Folder)
       --- / externalDB (a External Mount)

in a Python Script that in the root of your ZODB you can get to the
externalDB object by simply

print context.mcif.externalDB.getId()
return printed

if you are in mcif you would write
print context.externalDB.getId()
return printed

lets say you wanted to recurssively print all the stuff in your externalDB,
create a python script
called 'printChildren' and it has a parameter called obj you script would
look like
#parameters: obj (in a text input)
if obj.isPrincipiaFolderish:
    for o in obj.objectValues():
        context.printChildren(obj)
else:
    print obj.getPhysicalPath()
return printed

now you simply create a Script lets say in mcif that calls the printChildren
we can call
the script doPrintExternalDBTree (assuming that printChildren is in this
folder)

for zopeobject in context.externalDB.objectValues():
    context.printChildren(zopeobject)
return 'fin'

~runyaga

----- Original Message -----
From: <MKinsley@empirecorp.org>
To: <runyaga@runyaga.com>
Sent: Thursday, August 22, 2002 8:33 AM
Subject: RE: Holding ref to database connection


> Hi alan,
>
> Thanks for your reply. I have a folder called "mcif" with a subfolder
> "externalDB" which is the mount point to my database. Do I place the line
of
> code in Python script within Zope or an External Method?
> Do I have to import the app module?
>
> Thanks again for your support.
>
> -----Original Message-----
> From: alan runyan [mailto:runyaga@runyaga.com]
> Sent: Wednesday, August 21, 2002 3:27 PM
> To: MKinsley@empirecorp.org
> Subject: Re: Holding ref to database connection
>
>
> thats the point.. you dont "grab the ZODB DB object"
>
> you just traverse to it. everything is a big graph.
>
> o=app.somefolder.somesubfolder.somesubsubfolder.object
> print o.getId()
>
> ~runyaga
>
> ----- Original Message -----
> From: <MKinsley@empirecorp.org>
> To: <runyaga@runyaga.com>
> Sent: Wednesday, August 21, 2002 11:20 AM
> Subject: RE: Holding ref to database connection
>
>
> > Hi alan,
> >
> > I have successfully mounted the mcif.fs using the ExternalMount product
to
> > our Zope instance. Thanks for your help. So, its mounted to my Zope
> > instance, How do I grab the ZODB "DB" object it supposedly returns and
> open
> > a database connection?
> >
> > Thank you again!
> >
> > -----Original Message-----
> > From: alan runyan [mailto:runyaga@runyaga.com]
> > Sent: Friday, August 16, 2002 5:30 PM
> > To: MKinsley@empirecorp.org
> > Subject: Re: Holding ref to database connection
> >
> >
> > if that is the case you need to Mount the mcif.fs into a node in the
> Data.fs
> > ZODB.
> > http://www.zope.org/About <- note the exMount
> > http://www.zope.org/Members/jim/ZODB/MountedDatabases <- Wiki
> >
> > this is waht you want.. this way you have one logical ODB you are
dealing
> > with.
> >
> > ~runyaga
> >
> > ----- Original Message -----
> > From: <MKinsley@empirecorp.org>
> > To: <runyaga@runyaga.com>
> > Sent: Friday, August 16, 2002 4:08 PM
> > Subject: RE: Holding ref to database connection
> >
> >
> > > Thanks again Alan. Please reply one more time.
> > >
> > > Yes. Zope is built/operates using ZODB. We are also using ZODB outside
> of
> > > Zope , to store data, our data, about our products, services,
membership
> > > info etc. I am using a different file storage than Data.fs, namely
> > mcif.fs.
> > > We are using Zope
> > > as a web management tool for our web application infrastructure mostly
> > > written in Python and DTML.
> > >
> > > Does this shed some more light?
> > >
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: alan runyan [mailto:runyaga@runyaga.com]
> > > Sent: Friday, August 16, 2002 4:51 PM
> > > To: MKinsley@empirecorp.org
> > > Subject: Re: Holding ref to database connection
> > >
> > >
> > > > Thank you for your reply.  We would like to use  Zope and ZODB to
> > > > intelligently query data. There will be several DTML document pages
> > > involved
> > > > using external methods to query ZODB, particularly for ad-hoc
> querying.
> > > > Instead of opening the data connection each time I call an external
> > > method,
> > > > we had hoped to keep the connection to the data open so performance
is
> > > > maximized during ONE CLIENT's session. Openning a connection to the
> data
> > > is
> > > > slow, approximately 15 seconds a try for us.
> > >
> > > yes.  you do not open/close connetions.  I dont know enough about your
> > > application.
> > > it sounds like you are going against the grain.  and it doesnt.  If
you
> > are
> > > using ZOPE
> > > you are using the ZODB.  You dont need to open up another connection.
> > > When you are in the /manage interface -- you are looking at ZODB.
> Please
> > > read Zope Bible.
> > >
> > > > Does this clear up some of the confusion? By the way, I am an
> > experienced
> > > > software developer assigned to learn, validate, and potentially
> > implement
> > > this technology for the
> > > > organization.
> > >
> > > ZOPE is an incredible technology.  But its vastly different from other
> > > technologies.  Mainly
> > > because ZOPE is based on and uses a Object Databse to store its
> > application
> > > space data.
> > > Your application defnition *has* to be in the ZODB in some way.
> > >
> > > > I'm new to the whole environment but I clearly know this is an
> > > > issue that should be a simple answer from anyone more familiar than
> > myself
> > > > with Zope and ZODB. Heck, I've got this working on one page already.
I
> > > just
> > > > need to push this through to other pages.
> > >
> > > please.  take a second.  maybe you are approaching this (as everyone
> said)
> > > in such a way
> > > that is not "Pythonic" or "Zopeful" .  You really need to give me more
> > > information for me to
> > > help.  and I'm rather busy.  But please understand if you are *using*
> ZOPE
> > > you are *using*
> > > the ZODB and do not need to have a connection open to the Database.
> > >
> > > > I appreciate your response and sincerity.
> > >
> > > sure.  I am a consultant and I believe you may need a hour or two to
> clear
> > > up your confusions
> > > about the Zope Application Server.  External Methods *live* in the
ZODB.
> > If
> > > you want
> > > another ZODB (physical) -- basically a point in the ZODB can be
mounted
> to
> > > another ZODB.
> > > This can be done by "Mounting" another ZODB inside a point.  ZODBs can
> > > connect to each other.
> > >
> > > cheers,
> > > ~runyaga
> > > p.s. alot of people fail with ZOPE becasue they are not open to the
> > > paradigm.  Unless you are a
> > > smalltalk or OO fanatic -- you can easily be lose on the paradigm of
> ZOPE.
> > >
> >
>