[Checkins] SVN: z3c.zalchemy/trunk/src/z3c/zalchemy/ Made the
engine persistent.
Jürgen Kartnaller
juergen at kartnaller.at
Tue Dec 19 11:34:19 EST 2006
Log message for revision 71604:
Made the engine persistent.
Now it is possible to use it as a local utility.
Changed:
U z3c.zalchemy/trunk/src/z3c/zalchemy/README.txt
U z3c.zalchemy/trunk/src/z3c/zalchemy/datamanager.py
U z3c.zalchemy/trunk/src/z3c/zalchemy/testing/__init__.py
U z3c.zalchemy/trunk/src/z3c/zalchemy/tests/TRANSACTION.txt
U z3c.zalchemy/trunk/src/z3c/zalchemy/tests/test_zalchemy.py
-=-
Modified: z3c.zalchemy/trunk/src/z3c/zalchemy/README.txt
===================================================================
--- z3c.zalchemy/trunk/src/z3c/zalchemy/README.txt 2006-12-19 12:31:30 UTC (rev 71603)
+++ z3c.zalchemy/trunk/src/z3c/zalchemy/README.txt 2006-12-19 16:34:18 UTC (rev 71604)
@@ -71,8 +71,9 @@
To let zalchemy do its work we need to register our database utility.
+ >>> from z3c.zalchemy.interfaces import IAlchemyEngineUtility
>>> from zope.component import provideUtility
- >>> provideUtility(engineUtility)
+ >>> provideUtility(engineUtility, IAlchemyEngineUtility)
Tables can be created without an open transaction or session.
If no session is created then the table creation is deffered to the next
@@ -148,7 +149,7 @@
Because there is already a default engine we must provide a name for the
new engine.
- >>> provideUtility(engine2Util, name='engine2')
+ >>> provideUtility(engine2Util, IAlchemyEngineUtility, name='engine2')
>>> bTable = sqlalchemy.Table(
... 'bTable',
Modified: z3c.zalchemy/trunk/src/z3c/zalchemy/datamanager.py
===================================================================
--- z3c.zalchemy/trunk/src/z3c/zalchemy/datamanager.py 2006-12-19 12:31:30 UTC (rev 71603)
+++ z3c.zalchemy/trunk/src/z3c/zalchemy/datamanager.py 2006-12-19 16:34:18 UTC (rev 71604)
@@ -14,6 +14,7 @@
import thread
from threading import local
+import persistent
import transaction
from zope.interface import implements
from zope.component import queryUtility, getUtility, getUtilitiesFor
@@ -25,7 +26,7 @@
import sqlalchemy
-class AlchemyEngineUtility(object):
+class AlchemyEngineUtility(persistent.Persistent):
"""A utility providing a database engine.
"""
implements(IAlchemyEngineUtility)
@@ -36,7 +37,6 @@
self.echo = echo
self.kw={}
self.kw.update(kwargs)
- self.storage = local()
def getEngine(self):
engine = getattr(self.storage,'engine',None)
@@ -54,7 +54,13 @@
def _resetEngine(self):
self.storage.engine=None
+ @property
+ def storage(self):
+ if not hasattr(self, '_v_storage'):
+ self._v_storage = local()
+ return self._v_storage
+
metadata = sqlalchemy.MetaData()
_tableToEngine = {}
Modified: z3c.zalchemy/trunk/src/z3c/zalchemy/testing/__init__.py
===================================================================
--- z3c.zalchemy/trunk/src/z3c/zalchemy/testing/__init__.py 2006-12-19 12:31:30 UTC (rev 71603)
+++ z3c.zalchemy/trunk/src/z3c/zalchemy/testing/__init__.py 2006-12-19 16:34:18 UTC (rev 71604)
@@ -16,6 +16,7 @@
import z3c.zalchemy
from zope.app.testing import setup
from z3c.zalchemy.datamanager import AlchemyEngineUtility
+from z3c.zalchemy.interfaces import IAlchemyEngineUtility
from zope import component
import os, tempfile, shutil
@@ -46,7 +47,7 @@
'database',
'sqlite:///%s' % dbFile,
echo=echo)
- component.provideUtility(engineUtil)
+ component.provideUtility(engineUtil, IAlchemyEngineUtility)
test.globs['engineUtil'] = engineUtil
def placefulTearDown(test):
Modified: z3c.zalchemy/trunk/src/z3c/zalchemy/tests/TRANSACTION.txt
===================================================================
--- z3c.zalchemy/trunk/src/z3c/zalchemy/tests/TRANSACTION.txt 2006-12-19 12:31:30 UTC (rev 71603)
+++ z3c.zalchemy/trunk/src/z3c/zalchemy/tests/TRANSACTION.txt 2006-12-19 16:34:18 UTC (rev 71604)
@@ -9,11 +9,12 @@
>>> import os
>>> from zope.component import provideUtility
+ >>> from z3c.zalchemy.interfaces import IAlchemyEngineUtility
>>> from z3c.zalchemy.datamanager import AlchemyEngineUtility
>>> engineUtility = AlchemyEngineUtility('database',
... 'sqlite:///%s'%dbTrFilename,
... echo=False)
- >>> provideUtility(engineUtility)
+ >>> provideUtility(engineUtility, IAlchemyEngineUtility)
Setup a sqlalchemy table and class :
Modified: z3c.zalchemy/trunk/src/z3c/zalchemy/tests/test_zalchemy.py
===================================================================
--- z3c.zalchemy/trunk/src/z3c/zalchemy/tests/test_zalchemy.py 2006-12-19 12:31:30 UTC (rev 71603)
+++ z3c.zalchemy/trunk/src/z3c/zalchemy/tests/test_zalchemy.py 2006-12-19 16:34:18 UTC (rev 71604)
@@ -62,11 +62,12 @@
def testDefaultEngine(self):
from zope.component import provideUtility
+ from z3c.zalchemy.interfaces import IAlchemyEngineUtility
from z3c.zalchemy.datamanager import AlchemyEngineUtility
engineUtility = z3c.zalchemy.datamanager.AlchemyEngineUtility(
'database',
'sqlite:///:memory:')
- provideUtility(engineUtility)
+ provideUtility(engineUtility, IAlchemyEngineUtility)
session = z3c.zalchemy.getSession()
self.assertNotEqual(session, None)
self.assertNotEqual(session.get_bind(None), None)
More information about the Checkins
mailing list