[BlueBream] problems working with ZODB in bluebream....

Войнаровський Тарас voyn1991 at gmail.com
Mon Nov 18 11:56:55 CET 2013


Hello Tamer Higazi,
In bluebream the DB is not actually visible using open Interface, but it
can be accessed. A few words before that, and code next.

   - For each request there is a connection already opened. This connection
   is managed by a* transaction manager*, that will be commited after
   successfully finished processing request. So if you will be using the same
   connection you should let bluebream commit it to avoid problems.
   - If you want to handle a separate connection to a database you can
   register a handler for *IDatabaseOpenedEvent* and get access to db from
   it. Be careful to manage your connections wise. Do not create connections,
   that never close, this can lead to high memory consumption.

To access connection from request you can do next:

request.annotations['ZODB.interfaces.IConnection']

or as a browser view:

class SomeView(object):

    def __init__(self, context, request):
        self.context = context
        self.request = request
        *self.connection =
request.annotations['ZODB.interfaces.IConnection']*


To create a *IDatabaseOpenedEvent* handler do next:
in code *handler.py*:

def some_handler(event):
    setDatabase(event.database)

in zcml *configure.zcml*:
<subscriber
handler=".handler.some_handler"
for="zope.app.appsetup.IDatabaseOpenedEvent"
/>

There are other ways to access DB from code.
At first all objects, that are Persistend have access to connection, that
manages it by _p_jar, but its private, so I advise against using it.
Second, that DB can be accessed from request using *request.publication.db*.
This can be useful if you want to start a job in a separate thread, that
requires DB access, from a view. *But remember to close your connections
properly, so they can return to ConnectionPool.*




2013/11/18 Tamer Higazi <th982a at googlemail.com>

> Didn't seem to help very much.....
>
>
>
> 2013-11-18T11:12:32 INFO zope.generations main db: evolving in mode
> EVOLVEMINIMUM
> Welcome to the interactive debug prompt.
> The 'root' variable contains the ZODB root folder.
> The 'app' variable contains the Debugger, 'app.publish(path)' simulates
> a request.
> >>> from zope.site import hooks
> >>> site = hooks.getSite()
> >>> print site
> None
> >>>
>
>
>
> On 11/18/13 10:05, FLORAC, Thierry wrote:
> > Hi,
> >
> > Did you tried:
> >
> >   >>> from zope.site import hooks
> >   >>> site = hooks.getSite()
> >
> > Regards,
> > Thierry
>
> _______________________________________________
> bluebream mailing list
> bluebream at zope.org
> https://mail.zope.org/mailman/listinfo/bluebream
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/bluebream/attachments/20131118/6fc7761d/attachment.html>


More information about the bluebream mailing list