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

The Refresh product.

parent bc0b6cca
......@@ -84,8 +84,8 @@
##############################################################################
"""Database connection support
$Id: Connection.py,v 1.52 2001/05/16 20:47:38 jeremy Exp $"""
__version__='$Revision: 1.52 $'[11:-2]
$Id: Connection.py,v 1.53 2001/05/17 18:35:10 shane Exp $"""
__version__='$Revision: 1.53 $'[11:-2]
from cPickleCache import PickleCache
from POSException import ConflictError, ExportError
......@@ -99,6 +99,17 @@ from coptimizations import new_persistent_id
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 @@ class Connection(ExportImport.ExportImport):
_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 @@ class Connection(ExportImport.ExportImport):
self._invalidated=d={}
self._invalid=d.has_key
self._committed=[]
self._code_timestamp = global_code_timestamp
def _breakcr(self):
try: del self._cache
......@@ -218,15 +231,29 @@ class Connection(ExportImport.ExportImport):
"""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.
......
......@@ -84,8 +84,8 @@
##############################################################################
"""Database objects
$Id: DB.py,v 1.28 2001/04/19 16:06:25 jeremy Exp $"""
__version__='$Revision: 1.28 $'[11:-2]
$Id: DB.py,v 1.29 2001/05/17 18:35:10 shane Exp $"""
__version__='$Revision: 1.29 $'[11:-2]
import cPickle, cStringIO, sys, POSException, UndoLogCompatible
from Connection import Connection
......@@ -104,6 +104,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
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 @@ class DB(UndoLogCompatible.UndoLogCompatible):
# 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 @@ class DB(UndoLogCompatible.UndoLogCompatible):
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 @@ class DB(UndoLogCompatible.UndoLogCompatible):
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=
......
......@@ -87,9 +87,10 @@
This module provides a wrapper that causes a database connection to be created
and used when bobo publishes a bobo_application object.
"""
__version__='$Revision: 1.7 $'[11:-2]
__version__='$Revision: 1.8 $'[11:-2]
StringType=type('')
connection_open_hooks = []
class ZApplicationWrapper:
......@@ -117,6 +118,10 @@ class ZApplicationWrapper:
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()
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