[Checkins] SVN: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/ new 'transactional' flag (used by SQLAlchemyDA only)

Andreas Jung andreas at andreas-jung.com
Sat Jun 9 01:41:38 EDT 2007


Log message for revision 76520:
  new 'transactional' flag (used by SQLAlchemyDA only)
  

Changed:
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py

-=-
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt	2007-06-08 18:41:45 UTC (rev 76519)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt	2007-06-09 05:41:37 UTC (rev 76520)
@@ -1,6 +1,8 @@
 1.0.4 (unreleased)
 
+  - added new 'transactional' flag (used by SQLAlchemyDA only)
 
+
 1.0.3 (26.05.2007)
 
    - new 'cascade' parameter for the Model.add()

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py	2007-06-08 18:41:45 UTC (rev 76519)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py	2007-06-09 05:41:37 UTC (rev 76520)
@@ -48,12 +48,15 @@
 
     implements(ISQLAlchemyWrapper)
 
-    def __init__(self, dsn, model=None, **kw):
+    def __init__(self, dsn, model=None, transactional=True, **kw):
         """ 'dsn' - a RFC-1738-style connection string
 
             'model' - optional instance of model.Model
 
             'kw' - optional keyword arguments passed to create_engine()
+
+            'transactional' - True|False, only used by SQLAlchemyDA, 
+                              *don't touch it*
         """
 
         self.dsn = dsn
@@ -64,6 +67,7 @@
         self.password = self.url.password
         self.dbname = self.url.database 
         self.drivername = self.url.drivername
+        self.transactional = transactional
         self.kw = kw
         self.echo = kw.get('echo', False)
         self._model = None
@@ -179,18 +183,21 @@
 
     implements(IDataManager)
 
-    def __init__(self, connection):
+    def __init__(self, connection, transactional=True):
         self.connection = connection
+        self.transactional = transactional
         self.transaction = connection.begin()
 
     def abort(self, trans):
-        self.transaction.rollback()
+        if self.transactional:
+            self.transaction.rollback()
         self.connection.close()
         self.connection = None
         connection_cache.set(last_connection=None, last_transaction=None)
 
     def commit(self, trans):
-        self.transaction.commit()
+        if self.transactional:
+            self.transaction.commit()
         self.connection.close()
         self.connection = None
         connection_cache.set(last_connection=None, last_transaction=None)
@@ -252,7 +259,7 @@
         connection = self.engine.connect()
                                           
         # register a DataManager with the current transaction
-        transaction.get().join(ConnectionDataManager(connection))
+        transaction.get().join(ConnectionDataManager(connection, self.transactional))
 
         # update thread-local cache
         connection_cache.set(last_connection=connection)

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py	2007-06-08 18:41:45 UTC (rev 76519)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py	2007-06-09 05:41:37 UTC (rev 76520)
@@ -28,7 +28,7 @@
 
 registeredWrappers = {}
 
-def createSAWrapper(dsn, model=None, forZope=False, name=None, **kw):
+def createSAWrapper(dsn, model=None, forZope=False, name=None, transactional=True, **kw):
     """ Convenience method to generate a wrapper for a DSN and a model.
         This method hides all database related magic from the user. 
 
@@ -41,6 +41,8 @@
         '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
         to avoid a dedicated registerSAWrapper() call.
     """
@@ -53,7 +55,7 @@
     if driver == 'postgres':
         klass = forZope and ZopePostgresWrapper or PythonPostgresWrapper
 
-    wrapper = klass(dsn, model, **kw)
+    wrapper = klass(dsn, model, transactional, **kw)
     if name is not None:
         registerSAWrapper(wrapper, name)
 



More information about the Checkins mailing list