At 02:22 PM 5/23/01 +0200, J�rn Schrader wrote:
>Hello,
>
>I would like to use MiddleKit in a WebKit Application. Can anyone describe
>the best way to embed a middlekit store in the WebKit Application, so that I
>dont have to open it for each request.
>
>Thanks a lot, Joern.

Create a module that opens up the MiddleKit store when it is 
imported.  Then any servlet that needs the store can just import the module 
and use the store.  For example (untested code):


# MyObjectStore.py
from MiddleKit.Run.MySQLObjectStore import MySQLObjectStore
store = MySQLObjectStore()
store.readModelFileNamed('MyMiddleKitModel')


# MyPage.py
from MyObjectStore import store
from WebKit.Page import Page
class MyPage(Page):
     def writeContent(self):
         # Here you can just use the store.


Python's import statement ensures that code inside of it only gets executed 
once (unless you use reload).  And it also locks the threads so that so 
other thread can import the same module at the same time.  So this solution 
is safe even in a threaded environment like WebKit.


--

- Geoff Talvola
   [EMAIL PROTECTED]

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to