[Checkins]
SVN: z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/
preliminary integration, 2 tests failing, not bad
Andreas Jung
andreas at andreas-jung.com
Thu May 8 14:22:13 EDT 2008
Log message for revision 86543:
preliminary integration, 2 tests failing,not bad
Changed:
U z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/base.py
U z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/postgres.py
U z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/tests/testSQLAlchemy.py
U z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/util.py
-=-
Modified: z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/base.py
===================================================================
--- z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/base.py 2008-05-08 18:09:35 UTC (rev 86542)
+++ z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/base.py 2008-05-08 18:22:12 UTC (rev 86543)
@@ -31,8 +31,10 @@
import transaction
-class BaseWrapper(object):
+TEST_TWOPHASE = False
+class ZopeWrapper(object):
+
implements(ISQLAlchemyWrapper)
def __init__(self, dsn, model=None, transactional=True, engine_options={}, session_options={}, **kw):
@@ -126,33 +128,10 @@
def _createEngine(self):
self._engine = sqlalchemy.create_engine(self.dsn, **self.engine_options)
- self._sessionmaker = sqlalchemy.orm.sessionmaker(bind=self._engine,
- autoflush=True,
- transactional=True,
- **self.session_options)
-
-
-
-class ZopeBaseWrapper(BaseWrapper):
- """ A wrapper to be used from within Zope. It connects
- the session with the transaction management of Zope.
- """
-
-
- def __getOrCreateConnectionCacheItem(self, cache_id):
- pass
-
- @property
- def session(self):
- """ Return a (cached) session object for the current transaction """
- return self.__getOrCreateConnectionCacheItem(self._id)['session']
-
-
- @property
- def connection(self):
- """ This property is _private_ and only intented to be used
- by SQLAlchemyDA and therefore it is not part of the
- public API.
- """
-
- return self.__getOrCreateConnectionCacheItem(self._id)['connection']
+ self._sessionmaker = scoped_session(sessionmaker(bind=self._engine,
+ twophase=TEST_TWOPHASE,
+ transactional=True,
+ autoflush=True,
+ extension=ZopeTransactionExtension(),
+ **self.session_options
+ ))
Modified: z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/postgres.py
===================================================================
--- z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/postgres.py 2008-05-08 18:09:35 UTC (rev 86542)
+++ z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/postgres.py 2008-05-08 18:22:12 UTC (rev 86543)
@@ -15,7 +15,7 @@
from zope.interface import implements
from z3c.sqlalchemy.interfaces import ISQLAlchemyWrapper
-from z3c.sqlalchemy.base import BaseWrapper, ZopeBaseWrapper
+from z3c.sqlalchemy.base import ZopeWrapper
_cache = threading.local() # module-level cache
@@ -68,12 +68,7 @@
return _cache.ref_mapping
-class PythonPostgresWrapper(BaseWrapper, PostgresMixin):
- """ Wrapper to be used with Python with extended
- Postgres functionality.
- """
-
-class ZopePostgresWrapper(ZopeBaseWrapper, PostgresMixin):
+class ZopePostgresWrapper(ZopeWrapper, PostgresMixin):
""" A wrapper to be used from within Zope. It connects
the session with the transaction management of Zope.
"""
Modified: z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/tests/testSQLAlchemy.py
===================================================================
--- z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/tests/testSQLAlchemy.py 2008-05-08 18:09:35 UTC (rev 86542)
+++ z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/tests/testSQLAlchemy.py 2008-05-08 18:22:12 UTC (rev 86543)
@@ -22,8 +22,7 @@
from zope.interface.verify import verifyClass
from z3c.sqlalchemy.interfaces import ISQLAlchemyWrapper, IModel
-from z3c.sqlalchemy.postgres import PythonPostgresWrapper, ZopePostgresWrapper
-from z3c.sqlalchemy.base import BaseWrapper
+from z3c.sqlalchemy.postgres import ZopePostgresWrapper
from z3c.sqlalchemy.mapper import MappedClassBase
from z3c.sqlalchemy import createSAWrapper, Model, registerSAWrapper, getSAWrapper
@@ -48,15 +47,6 @@
metadata.create_all()
-
- def testIFaceBaseWrapper (self):
- verifyClass(ISQLAlchemyWrapper , BaseWrapper)
-
-
- def testIFacePythonPostgres(self):
- verifyClass(ISQLAlchemyWrapper , PythonPostgresWrapper)
-
-
def testIFaceZopePostgres(self):
verifyClass(ISQLAlchemyWrapper , ZopePostgresWrapper)
Modified: z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/util.py
===================================================================
--- z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/util.py 2008-05-08 18:09:35 UTC (rev 86542)
+++ z3c.sqlalchemy/branches/zope.sqlalchemy-integration/src/z3c/sqlalchemy/util.py 2008-05-08 18:22:12 UTC (rev 86543)
@@ -20,15 +20,15 @@
from zope.component.servicenames import Utilities
from z3c.sqlalchemy.interfaces import ISQLAlchemyWrapper
-from z3c.sqlalchemy.postgres import ZopePostgresWrapper, PythonPostgresWrapper
-from z3c.sqlalchemy.base import BaseWrapper, ZopeBaseWrapper
+from z3c.sqlalchemy.postgres import ZopePostgresWrapper
+from z3c.sqlalchemy.base import ZopeWrapper
__all__ = ('createSQLAlchemyWrapper', 'registerSQLAlchemyWrapper', 'allRegisteredSQLAlchemyWrappers', 'getSQLAlchemyWrapper',
'createSAWrapper', 'registerSAWrapper', 'allRegisteredSAWrappers', 'getSAWrapper', 'allSAWrapperNames')
registeredWrappers = {}
-def createSAWrapper(dsn, model=None, forZope=False, name=None, transactional=True,
+def createSAWrapper(dsn, model=None, name=None, transactional=True,
engine_options={}, session_options={}, **kw):
""" Convenience method to generate a wrapper for a DSN and a model.
This method hides all database related magic from the user.
@@ -39,9 +39,6 @@
a named utility implementing IModelProvider or a method/callable returning an
instance of model.Model.
- 'forZope' - set this to True in order to obtain a Zope-transaction-aware
- wrapper.
-
'transactional' - True|False, only used for SQLAlchemyDA *don't change it*
'name' can be set to register the wrapper automatically in order
@@ -57,10 +54,10 @@
url = make_url(dsn)
driver = url.drivername
- klass = forZope and ZopeBaseWrapper or BaseWrapper
+ klass = ZopeWrapper
if driver == 'postgres':
- klass = forZope and ZopePostgresWrapper or PythonPostgresWrapper
+ klass = ZopePostgresWrapper
wrapper = klass(dsn, model,
transactional=transactional,
More information about the Checkins
mailing list