<div dir="ltr">Hello Tamer Higazi,<div>In bluebream the DB is not actually visible using open Interface, but it can be accessed. A few words before that, and code next.</div><div><ul><li>For each request there is a connection already opened. This connection is managed by a<i> transaction manager</i>, 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.<br>
</li><li>If you want to handle a separate connection to a database you can register a handler for <i>IDatabaseOpenedEvent</i> 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.</li>
</ul><div>To access connection from request you can do next: </div></div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>request.annotations['ZODB.interfaces.IConnection']</div>
<div><br></div></blockquote><div>or as a browser view:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>class SomeView(object):</div></div><div><div><br></div></div><div><div>
    def __init__(self, context, request):</div></div><div><div>        self.context = context</div></div><div><div>        self.request = request</div></div><div><div>        <b>self.connection = request.annotations['ZODB.interfaces.IConnection']</b></div>
</div></blockquote><div><br></div><div>To create a <b>IDatabaseOpenedEvent</b> handler do next:</div><div>in code <i>handler.py</i>:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div>
def some_handler(event):</div></div></div><div><div><div>    setDatabase(event.database)</div></div></div></blockquote><div><div>in zcml <i>configure.zcml</i>:</div><div><div><span class="" style="white-space:pre">  </span><subscriber</div>
<div><span class="" style="white-space:pre">      </span>handler=".handler.some_handler"</div><div><span class="" style="white-space:pre">          </span>for="zope.app.appsetup.IDatabaseOpenedEvent"</div><div><span class="" style="white-space:pre">     </span>/></div>
</div><div><br></div></div><div>There are other ways to access DB from code. </div><div>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. </div>
<div>Second, that DB can be accessed from request using <b>request.publication.db</b>. This can be useful if you want to start a job in a separate thread, that requires DB access, from a view. <i>But remember to close your connections properly, so they can return to <b>ConnectionPool</b>.</i></div>
<div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/11/18 Tamer Higazi <span dir="ltr"><<a href="mailto:th982a@googlemail.com" target="_blank">th982a@googlemail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Didn't seem to help very much.....<br>
<br>
<br>
<br>
2013-11-18T11:12:32 INFO zope.generations main db: evolving in mode<br>
EVOLVEMINIMUM<br>
Welcome to the interactive debug prompt.<br>
The 'root' variable contains the ZODB root folder.<br>
The 'app' variable contains the Debugger, 'app.publish(path)' simulates<br>
a request.<br>
>>> from zope.site import hooks<br>
>>> site = hooks.getSite()<br>
>>> print site<br>
None<br>
>>><br>
<br>
<br>
<br>
On 11/18/13 10:05, FLORAC, Thierry wrote:<br>
> Hi,<br>
><br>
> Did you tried:<br>
><br>
>   >>> from zope.site import hooks<br>
>   >>> site = hooks.getSite()<br>
><br>
> Regards,<br>
> Thierry<br>
<br>
_______________________________________________<br>
bluebream mailing list<br>
<a href="mailto:bluebream@zope.org">bluebream@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/bluebream" target="_blank">https://mail.zope.org/mailman/listinfo/bluebream</a><br>
</blockquote></div><br></div>