[Zope-Checkins] CVS: Zope2 - Connection.py:1.53 DB.py:1.29 ZApplication.py:1.8
shane@digicool.com
shane@digicool.com
Thu, 17 May 2001 14:35:12 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/ZODB
In directory korak.digicool.com:/tmp/cvs-serv11564/lib/python/ZODB
Modified Files:
Connection.py DB.py ZApplication.py
Log Message:
The Refresh product.
--- Updated File Connection.py in package Zope2/lib/python/ZODB --
--- Connection.py 2001/05/16 20:47:38 1.52
+++ Connection.py 2001/05/17 18:35:10 1.53
@@ -99,6 +99,17 @@
from ConflictResolution import ResolvedSerial
from types import StringType
+global_code_timestamp = 0
+
+def updateCodeTimestamp():
+ '''
+ Called after changes are made to persistence-based classes.
+ Causes all connection caches to be re-created as the
+ connections are reopened.
+ '''
+ global global_code_timestamp
+ global_code_timestamp = time()
+
ExtensionKlass=Base.__class__
class HelperClass: pass
@@ -116,6 +127,7 @@
_tmp=None
_debug_info=()
_opened=None
+ _code_timestamp = 0
# Experimental. Other connections can register to be closed
# when we close by putting something here.
@@ -129,6 +141,7 @@
self._invalidated=d={}
self._invalid=d.has_key
self._committed=[]
+ self._code_timestamp = global_code_timestamp
def _breakcr(self):
try: del self._cache
@@ -218,14 +231,28 @@
"""Begin a new transaction.
Any objects modified since the last transaction are invalidated.
- """
+ """
self._db=odb
self._storage=s=odb._storage
self.new_oid=s.new_oid
- self._cache.invalidate(self._invalidated)
+ if self._code_timestamp != global_code_timestamp:
+ # New code is in place. Start a new cache.
+ self._resetCache()
+ else:
+ self._cache.invalidate(self._invalidated)
self._opened=time()
return self
+
+ def _resetCache(self):
+ '''
+ Creates a new cache, discarding the old.
+ '''
+ self._code_timestamp = global_code_timestamp
+ self._invalidated.clear()
+ orig_cache = self._cache
+ self._cache = PickleCache(self, orig_cache.cache_size,
+ orig_cache.cache_age)
def abort(self, object, transaction):
"""Abort the object in the transaction.
--- Updated File DB.py in package Zope2/lib/python/ZODB --
--- DB.py 2001/04/19 16:06:25 1.28
+++ DB.py 2001/05/17 18:35:10 1.29
@@ -104,6 +104,7 @@
or more connections, which manage object spaces. Most of the actual work
of managing objects is done by the connections.
"""
+ klass = Connection
def __init__(self, storage,
pool_size=7,
@@ -404,7 +405,7 @@
# This is a temporary connection.
# We won't bother with the pools. This will be
# a one-use connection.
- c=Connection(
+ c=self.klass(
version=version,
cache_size=self._version_cache_size,
cache_deactivate_after=
@@ -455,7 +456,7 @@
c=None
if version:
if self._version_pool_size > len(allocated) or force:
- c=Connection(
+ c=self.klass(
version=version,
cache_size=self._version_cache_size,
cache_deactivate_after=
@@ -463,7 +464,7 @@
allocated.append(c)
pool.append(c)
elif self._pool_size > len(allocated) or force:
- c=Connection(
+ c=self.klass(
version=version,
cache_size=self._cache_size,
cache_deactivate_after=
--- Updated File ZApplication.py in package Zope2/lib/python/ZODB --
--- ZApplication.py 1999/08/27 22:17:53 1.7
+++ ZApplication.py 2001/05/17 18:35:10 1.8
@@ -90,6 +90,7 @@
__version__='$Revision$'[11:-2]
StringType=type('')
+connection_open_hooks = []
class ZApplicationWrapper:
@@ -116,6 +117,10 @@
version=REQUEST.get(version_support,'')
else: version=''
conn=db.open(version)
+
+ if connection_open_hooks:
+ for hook in connection_open_hooks:
+ hook(conn)
# arrange for the connection to be closed when the request goes away
cleanup=Cleanup()
--- Updated File Connection.py in package Zope2 --
--- Connection.py 2001/05/16 20:47:38 1.52
+++ Connection.py 2001/05/17 18:35:10 1.53
@@ -99,6 +99,17 @@
from ConflictResolution import ResolvedSerial
from types import StringType
+global_code_timestamp = 0
+
+def updateCodeTimestamp():
+ '''
+ Called after changes are made to persistence-based classes.
+ Causes all connection caches to be re-created as the
+ connections are reopened.
+ '''
+ global global_code_timestamp
+ global_code_timestamp = time()
+
ExtensionKlass=Base.__class__
class HelperClass: pass
@@ -116,6 +127,7 @@
_tmp=None
_debug_info=()
_opened=None
+ _code_timestamp = 0
# Experimental. Other connections can register to be closed
# when we close by putting something here.
@@ -129,6 +141,7 @@
self._invalidated=d={}
self._invalid=d.has_key
self._committed=[]
+ self._code_timestamp = global_code_timestamp
def _breakcr(self):
try: del self._cache
@@ -218,14 +231,28 @@
"""Begin a new transaction.
Any objects modified since the last transaction are invalidated.
- """
+ """
self._db=odb
self._storage=s=odb._storage
self.new_oid=s.new_oid
- self._cache.invalidate(self._invalidated)
+ if self._code_timestamp != global_code_timestamp:
+ # New code is in place. Start a new cache.
+ self._resetCache()
+ else:
+ self._cache.invalidate(self._invalidated)
self._opened=time()
return self
+
+ def _resetCache(self):
+ '''
+ Creates a new cache, discarding the old.
+ '''
+ self._code_timestamp = global_code_timestamp
+ self._invalidated.clear()
+ orig_cache = self._cache
+ self._cache = PickleCache(self, orig_cache.cache_size,
+ orig_cache.cache_age)
def abort(self, object, transaction):
"""Abort the object in the transaction.
--- Updated File DB.py in package Zope2 --
--- DB.py 2001/04/19 16:06:25 1.28
+++ DB.py 2001/05/17 18:35:10 1.29
@@ -104,6 +104,7 @@
or more connections, which manage object spaces. Most of the actual work
of managing objects is done by the connections.
"""
+ klass = Connection
def __init__(self, storage,
pool_size=7,
@@ -404,7 +405,7 @@
# This is a temporary connection.
# We won't bother with the pools. This will be
# a one-use connection.
- c=Connection(
+ c=self.klass(
version=version,
cache_size=self._version_cache_size,
cache_deactivate_after=
@@ -455,7 +456,7 @@
c=None
if version:
if self._version_pool_size > len(allocated) or force:
- c=Connection(
+ c=self.klass(
version=version,
cache_size=self._version_cache_size,
cache_deactivate_after=
@@ -463,7 +464,7 @@
allocated.append(c)
pool.append(c)
elif self._pool_size > len(allocated) or force:
- c=Connection(
+ c=self.klass(
version=version,
cache_size=self._cache_size,
cache_deactivate_after=
--- Updated File ZApplication.py in package Zope2 --
--- ZApplication.py 1999/08/27 22:17:53 1.7
+++ ZApplication.py 2001/05/17 18:35:10 1.8
@@ -90,6 +90,7 @@
__version__='$Revision$'[11:-2]
StringType=type('')
+connection_open_hooks = []
class ZApplicationWrapper:
@@ -116,6 +117,10 @@
version=REQUEST.get(version_support,'')
else: version=''
conn=db.open(version)
+
+ if connection_open_hooks:
+ for hook in connection_open_hooks:
+ hook(conn)
# arrange for the connection to be closed when the request goes away
cleanup=Cleanup()