[Checkins] SVN: Product.ZSQLAlchemy/trunk/ZSQLAlchemy.py caching
the engine
Andreas Jung
andreas at andreas-jung.com
Thu Feb 1 06:53:33 EST 2007
Log message for revision 72291:
caching the engine
Changed:
U Product.ZSQLAlchemy/trunk/ZSQLAlchemy.py
-=-
Modified: Product.ZSQLAlchemy/trunk/ZSQLAlchemy.py
===================================================================
--- Product.ZSQLAlchemy/trunk/ZSQLAlchemy.py 2007-02-01 11:37:40 UTC (rev 72290)
+++ Product.ZSQLAlchemy/trunk/ZSQLAlchemy.py 2007-02-01 11:53:33 UTC (rev 72291)
@@ -78,8 +78,10 @@
security = ClassSecurityInfo()
+ security.declarePrivate('_getConnection')
def _getConnection(self):
""" connection factory """
+
db = psycopg.connect(database=self.database,
user=self.username,
password=self.password,
@@ -87,11 +89,19 @@
return db
- def _createEngine(self):
+ security.declarePrivate('_getEngine')
+ def _getEngine(self):
""" create an engine """
-
- p = sqlalchemy.pool.QueuePool(self._getConnection, max_overflow=10, pool_size=10, use_threadlocal=True)
- engine = sqlalchemy.create_engine('postgres://', pool=p)
+
+ engine = getattr(self, '_v_sqlalchemy_engine', None)
+ if engine is None:
+ p = sqlalchemy.pool.QueuePool(self._getConnection,
+ max_overflow=10,
+ pool_size=10,
+ use_threadlocal=True)
+ engine = sqlalchemy.create_engine('postgres://', pool=p)
+ self._v_sqlalchemy_engine = engine
+
return engine
@@ -99,7 +109,7 @@
def getSession(self):
""" return a session proxy """
- engine = self._createEngine()
+ engine = self._getEngine()
proxy = SessionProxy(engine)
return proxy
More information about the Checkins
mailing list