Commit 7ae774af authored by Shane Hathaway's avatar Shane Hathaway

The Refresh product.

parent bc0b6cca
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
"""Database connection support """Database connection support
$Id: Connection.py,v 1.52 2001/05/16 20:47:38 jeremy Exp $""" $Id: Connection.py,v 1.53 2001/05/17 18:35:10 shane Exp $"""
__version__='$Revision: 1.52 $'[11:-2] __version__='$Revision: 1.53 $'[11:-2]
from cPickleCache import PickleCache from cPickleCache import PickleCache
from POSException import ConflictError, ExportError from POSException import ConflictError, ExportError
...@@ -99,6 +99,17 @@ from coptimizations import new_persistent_id ...@@ -99,6 +99,17 @@ from coptimizations import new_persistent_id
from ConflictResolution import ResolvedSerial from ConflictResolution import ResolvedSerial
from types import StringType 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__ ExtensionKlass=Base.__class__
class HelperClass: pass class HelperClass: pass
...@@ -116,6 +127,7 @@ class Connection(ExportImport.ExportImport): ...@@ -116,6 +127,7 @@ class Connection(ExportImport.ExportImport):
_tmp=None _tmp=None
_debug_info=() _debug_info=()
_opened=None _opened=None
_code_timestamp = 0
# Experimental. Other connections can register to be closed # Experimental. Other connections can register to be closed
# when we close by putting something here. # when we close by putting something here.
...@@ -129,6 +141,7 @@ class Connection(ExportImport.ExportImport): ...@@ -129,6 +141,7 @@ class Connection(ExportImport.ExportImport):
self._invalidated=d={} self._invalidated=d={}
self._invalid=d.has_key self._invalid=d.has_key
self._committed=[] self._committed=[]
self._code_timestamp = global_code_timestamp
def _breakcr(self): def _breakcr(self):
try: del self._cache try: del self._cache
...@@ -218,15 +231,29 @@ class Connection(ExportImport.ExportImport): ...@@ -218,15 +231,29 @@ class Connection(ExportImport.ExportImport):
"""Begin a new transaction. """Begin a new transaction.
Any objects modified since the last transaction are invalidated. Any objects modified since the last transaction are invalidated.
""" """
self._db=odb self._db=odb
self._storage=s=odb._storage self._storage=s=odb._storage
self.new_oid=s.new_oid 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() self._opened=time()
return self 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): def abort(self, object, transaction):
"""Abort the object in the transaction. """Abort the object in the transaction.
......
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
"""Database objects """Database objects
$Id: DB.py,v 1.28 2001/04/19 16:06:25 jeremy Exp $""" $Id: DB.py,v 1.29 2001/05/17 18:35:10 shane Exp $"""
__version__='$Revision: 1.28 $'[11:-2] __version__='$Revision: 1.29 $'[11:-2]
import cPickle, cStringIO, sys, POSException, UndoLogCompatible import cPickle, cStringIO, sys, POSException, UndoLogCompatible
from Connection import Connection from Connection import Connection
...@@ -104,6 +104,7 @@ class DB(UndoLogCompatible.UndoLogCompatible): ...@@ -104,6 +104,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
or more connections, which manage object spaces. Most of the actual work or more connections, which manage object spaces. Most of the actual work
of managing objects is done by the connections. of managing objects is done by the connections.
""" """
klass = Connection
def __init__(self, storage, def __init__(self, storage,
pool_size=7, pool_size=7,
...@@ -404,7 +405,7 @@ class DB(UndoLogCompatible.UndoLogCompatible): ...@@ -404,7 +405,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
# This is a temporary connection. # This is a temporary connection.
# We won't bother with the pools. This will be # We won't bother with the pools. This will be
# a one-use connection. # a one-use connection.
c=Connection( c=self.klass(
version=version, version=version,
cache_size=self._version_cache_size, cache_size=self._version_cache_size,
cache_deactivate_after= cache_deactivate_after=
...@@ -455,7 +456,7 @@ class DB(UndoLogCompatible.UndoLogCompatible): ...@@ -455,7 +456,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
c=None c=None
if version: if version:
if self._version_pool_size > len(allocated) or force: if self._version_pool_size > len(allocated) or force:
c=Connection( c=self.klass(
version=version, version=version,
cache_size=self._version_cache_size, cache_size=self._version_cache_size,
cache_deactivate_after= cache_deactivate_after=
...@@ -463,7 +464,7 @@ class DB(UndoLogCompatible.UndoLogCompatible): ...@@ -463,7 +464,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
allocated.append(c) allocated.append(c)
pool.append(c) pool.append(c)
elif self._pool_size > len(allocated) or force: elif self._pool_size > len(allocated) or force:
c=Connection( c=self.klass(
version=version, version=version,
cache_size=self._cache_size, cache_size=self._cache_size,
cache_deactivate_after= cache_deactivate_after=
......
...@@ -87,9 +87,10 @@ ...@@ -87,9 +87,10 @@
This module provides a wrapper that causes a database connection to be created This module provides a wrapper that causes a database connection to be created
and used when bobo publishes a bobo_application object. and used when bobo publishes a bobo_application object.
""" """
__version__='$Revision: 1.7 $'[11:-2] __version__='$Revision: 1.8 $'[11:-2]
StringType=type('') StringType=type('')
connection_open_hooks = []
class ZApplicationWrapper: class ZApplicationWrapper:
...@@ -117,6 +118,10 @@ class ZApplicationWrapper: ...@@ -117,6 +118,10 @@ class ZApplicationWrapper:
else: version='' else: version=''
conn=db.open(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 # arrange for the connection to be closed when the request goes away
cleanup=Cleanup() cleanup=Cleanup()
cleanup.__del__=conn.close cleanup.__del__=conn.close
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment