Commit e6c1e00d authored by Jim Fulton's avatar Jim Fulton

alpha1

parent 618a2277
...@@ -48,12 +48,12 @@ ...@@ -48,12 +48,12 @@
__doc__='''Python implementation of persistent base types __doc__='''Python implementation of persistent base types
$Id: PersistentMapping.py,v 1.2 1998/10/23 21:40:59 jim Exp $''' $Id: PersistentMapping.py,v 1.3 1998/11/11 02:00:56 jim Exp $'''
__version__='$Revision: 1.2 $'[11:-2] __version__='$Revision: 1.3 $'[11:-2]
import Persistence import Persistence
class PersistentMapping(Persistence.Persistent): class PM(Persistence.Persistent):
"""A persistent wrapper for mapping objects. """A persistent wrapper for mapping objects.
This class allows wrapping of mapping objects so that This class allows wrapping of mapping objects so that
...@@ -65,22 +65,36 @@ class PersistentMapping(Persistence.Persistent): ...@@ -65,22 +65,36 @@ class PersistentMapping(Persistence.Persistent):
if container is None: container={} if container is None: container={}
self._container=container self._container=container
def __delitem__(self, key):
del self._container[key]
try: del self._v_keys
except: pass
self.__changed__(1)
def __getitem__(self, key): def __getitem__(self, key):
return self._container[key] return self._container[key]
def __len__(self): return len(self._container)
def __setitem__(self, key, v): def __setitem__(self, key, v):
self._container[key]=v self._container[key]=v
try: del self._v_keys try: del self._v_keys
except: pass except: pass
self.__changed__(1) self.__changed__(1)
def __delitem__(self, key): def clear(self):
del self._container[key] self._container.clear()
try: del self._v_keys self._p_changed=1
except: pass if hasattr(self,'_v_keys'): del self._v_keys
self.__changed__(1)
def __len__(self): return len(self._container) def copy(self): return self.__class__(self._container.copy())
def get(self, key, default): return self._container.get(key, default)
def has_key(self,key): return self._container.has_key(key)
def items(self):
return map(lambda k, d=self: (k,d[k]), self.keys())
def keys(self): def keys(self):
try: return self._v_keys try: return self._v_keys
...@@ -91,14 +105,12 @@ class PersistentMapping(Persistence.Persistent): ...@@ -91,14 +105,12 @@ class PersistentMapping(Persistence.Persistent):
keys.sort() keys.sort()
return keys return keys
def clear(self): def update(self, b):
self._container={} a=self._container
if hasattr(self,'_v_keys'): del self._v_keys for k, v in b.items(): a[k] = v
self._p_changed=1
def values(self): def values(self):
return map(lambda k, d=self: d[k], self.keys()) return map(lambda k, d=self: d[k], self.keys())
def items(self): PersistentMapping=PM
return map(lambda k, d=self: (k,d[k]), self.keys())
def has_key(self,key): return self._container.has_key(key)
This diff is collapsed.
/* /*
$Id: cPersistence.h,v 1.9 1997/12/15 15:55:16 jim Exp $ $Id: cPersistence.h,v 1.10 1998/11/11 02:00:56 jim Exp $
Definitions to facilitate making cPersistent subclasses in C. Definitions to facilitate making cPersistent subclasses in C.
Copyright
Copyright 1996 Digital Creations, L.C., 910 Princess Anne
Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
rights reserved. Copyright in this software is owned by DCLC,
unless otherwise indicated. Permission to use, copy and
distribute this software is hereby granted, provided that the
above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear. Note that
any product, process or technology described in this software
may be the subject of other Intellectual Property rights
reserved by Digital Creations, L.C. and are not licensed
hereunder.
Trademarks
Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
All other trademarks are owned by their respective companies.
No Warranty
The software is provided "as is" without warranty of any kind,
either express or implied, including, but not limited to, the
implied warranties of merchantability, fitness for a particular
purpose, or non-infringement. This software could include
technical inaccuracies or typographical errors. Changes are
periodically made to the software; these changes will be
incorporated in new editions of the software. DCLC may make
improvements and/or changes in this software at any time
without notice.
Limitation Of Liability
In no event will DCLC be liable for direct, indirect, special,
incidental, economic, cover, or consequential damages arising
out of the use of or inability to use this software even if
advised of the possibility of such damages. Some states do not
allow the exclusion or limitation of implied warranties or
limitation of liability for incidental or consequential
damages, so the above limitation or exclusion may not apply to
you.
If you have questions regarding this software,
contact:
Digital Creations L.C.
info@digicool.com
(540) 371-6909
$Log: cPersistence.h,v $
Revision 1.9 1997/12/15 15:55:16 jim
Changed persistent object header layout. This will require recompile
of all C Persistent objects.
Revision 1.8 1997/12/10 22:19:24 jim
Added PER_USE macro.
Revision 1.7 1997/07/18 14:15:39 jim
Added PER_DEL so that subclasses can handle deallocation correctly.
Revision 1.6 1997/06/06 19:13:32 jim
Changed/fixed convenience macros.
Revision 1.5 1997/05/19 17:51:20 jim
Added macros to simplify C PO implementation.
Revision 1.4 1997/05/19 13:49:36 jim
Added include of time.h.
Revision 1.3 1997/04/27 09:18:23 jim
Added to the CAPI to support subtypes (like Record) that want to
extend attr functions.
Revision 1.2 1997/04/22 02:40:28 jim
Changed object header layout.
Revision 1.1 1997/04/01 17:15:48 jim
*** empty log message ***
*/ */
...@@ -96,24 +15,19 @@ ...@@ -96,24 +15,19 @@
#define cPersistent_HEAD PyObject_HEAD \ #define cPersistent_HEAD PyObject_HEAD \
PyObject *jar; \ PyObject *jar; \
int oid; \ char oid[8]; \
time_t atime; \ unsigned short atime; \
signed char state; \ signed char state; \
#define cPersistent_GHOST_STATE -1 #define cPersistent_GHOST_STATE -1
#define cPersistent_UPTODATE_STATE 0 #define cPersistent_UPTODATE_STATE 0
#define cPersistent_CHANGED_STATE 1 #define cPersistent_CHANGED_STATE 1
#define cPersistent_STICKY_STATE 2
typedef struct { typedef struct {
cPersistent_HEAD cPersistent_HEAD
} cPersistentObject; } cPersistentObject;
typedef struct {
PyObject_HEAD
cPersistentObject *object;
} PATimeobject;
typedef int (*persetattr)(PyObject *, PyObject*, PyObject *, setattrofunc); typedef int (*persetattr)(PyObject *, PyObject*, PyObject *, setattrofunc);
typedef PyObject *(*pergetattr)(PyObject *, PyObject*, char *, getattrofunc); typedef PyObject *(*pergetattr)(PyObject *, PyObject*, char *, getattrofunc);
...@@ -121,7 +35,7 @@ typedef struct { ...@@ -121,7 +35,7 @@ typedef struct {
PyMethodChain *methods; PyMethodChain *methods;
getattrofunc getattro; getattrofunc getattro;
setattrofunc setattro; setattrofunc setattro;
int (*changed)(PyObject*); int (*changed)(cPersistentObject*);
int (*setstate)(PyObject*); int (*setstate)(PyObject*);
pergetattr pergetattro; pergetattr pergetattro;
persetattr persetattro; persetattr persetattro;
...@@ -129,16 +43,20 @@ typedef struct { ...@@ -129,16 +43,20 @@ typedef struct {
static cPersistenceCAPIstruct *cPersistenceCAPI; static cPersistenceCAPIstruct *cPersistenceCAPI;
#define PER_USE_OR_RETURN(O,R) { \
if ((O)->state==cPersistent_GHOST_STATE && \
cPersistenceCAPI->setstate((PyObject*)(O)) < 0) \
return (R); \
else if ((O)->state==cPersistent_UPTODATE_STATE) \
(O)->state=cPersistent_STICKY_STATE; \
}
#define PER_USE_OR_RETURN(O,R) \ #define PER_CHANGED(O) (cPersistenceCAPI->changed((cPersistentObject*)(O)))
if(cPersistenceCAPI->setstate((PyObject*)(O)) < 0) return (R)
#define PER_USE(O) (cPersistenceCAPI->setstate((PyObject*)(O)))
#define PER_CHANGED(O) (cPersistenceCAPI->changed((PyObject*)(O))) #define PER_ALLOW_DEACTIVATION(O) \
((O)->state==cPersistent_STICKY_STATE && \
((O)->state=cPersistent_UPTODATE_STATE))
#define PER_PREVENT_DEACTIVATION(O) ((O)->atime=(time_t)1);
#define PER_ALLOW_DEACTIVATION(O) ((O)->atime=time(NULL));
#define PER_DEL(O) Py_XDECREF((O)->jar) #define PER_DEL(O) Py_XDECREF((O)->jar)
#endif #endif
......
This diff is collapsed.
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
static char BTree_module_documentation[] = static char BTree_module_documentation[] =
"" ""
"\n$Id: BTree.c,v 1.16 1998/03/24 15:17:44 jim Exp $" "\n$Id: BTree.c,v 1.17 1998/11/11 02:00:55 jim Exp $"
; ;
#define PERSISTENT #define PERSISTENT
...@@ -22,7 +22,7 @@ static char BTree_module_documentation[] = ...@@ -22,7 +22,7 @@ static char BTree_module_documentation[] =
#include "ExtensionClass.h" #include "ExtensionClass.h"
#define PER_USE_OR_RETURN(self, NULL) #define PER_USE_OR_RETURN(self, NULL)
#define PER_ALLOW_DEACTIVATION(self) #define PER_ALLOW_DEACTIVATION(self)
#define PER_PREVENT_DEACTIVATION(self) #define PER_DEL(self)
#endif #endif
...@@ -170,7 +170,7 @@ BTreeItems_item_BTree(char kind, int i, BTree *btree) ...@@ -170,7 +170,7 @@ BTreeItems_item_BTree(char kind, int i, BTree *btree)
if(Bucket_Check(d->value)) if(Bucket_Check(d->value))
{ {
PER_USE_OR_RETURN(d->value, NULL); PER_USE_OR_RETURN((Bucket*)(d->value), NULL);
switch(kind) switch(kind)
{ {
case 'k': case 'k':
...@@ -867,7 +867,7 @@ BTree_grow(BTree *self, int index) ...@@ -867,7 +867,7 @@ BTree_grow(BTree *self, int index)
v=d->value; v=d->value;
UNLESS(e=PyObject_CallObject(OBJECT(v->ob_type), NULL)) return -1; UNLESS(e=PyObject_CallObject(OBJECT(v->ob_type), NULL)) return -1;
PER_USE_OR_RETURN(v, -1); PER_USE_OR_RETURN((Bucket*)v, -1);
if(Bucket_Check(v)) if(Bucket_Check(v))
{ {
...@@ -1273,8 +1273,6 @@ bucket_setstate(Bucket *self, PyObject *args) ...@@ -1273,8 +1273,6 @@ bucket_setstate(Bucket *self, PyObject *args)
char *cv; char *cv;
#endif #endif
PER_PREVENT_DEACTIVATION(self);
UNLESS(PyArg_ParseTuple(args,"O",&r)) goto err; UNLESS(PyArg_ParseTuple(args,"O",&r)) goto err;
UNLESS(PyArg_ParseTuple(r,"OO",&keys,&values)) goto err; UNLESS(PyArg_ParseTuple(r,"OO",&keys,&values)) goto err;
...@@ -1452,8 +1450,6 @@ BTree_setstate(BTree *self, PyObject *args) ...@@ -1452,8 +1450,6 @@ BTree_setstate(BTree *self, PyObject *args)
UNLESS(PyArg_ParseTuple(args,"O",&state)) return NULL; UNLESS(PyArg_ParseTuple(args,"O",&state)) return NULL;
if((l=PyTuple_Size(state))<0) return NULL; if((l=PyTuple_Size(state))<0) return NULL;
PER_PREVENT_DEACTIVATION(self);
if(l>self->size) if(l>self->size)
{ {
if(self->data) if(self->data)
...@@ -1610,6 +1606,7 @@ Bucket_dealloc(Bucket *self) ...@@ -1610,6 +1606,7 @@ Bucket_dealloc(Bucket *self)
DECREF_VALUE(self->data[i].value); DECREF_VALUE(self->data[i].value);
} }
free(self->data); free(self->data);
PER_DEL(self);
PyMem_DEL(self); PyMem_DEL(self);
} }
...@@ -1625,6 +1622,8 @@ BTree_dealloc(BTree *self) ...@@ -1625,6 +1622,8 @@ BTree_dealloc(BTree *self)
Py_DECREF(self->data[i].value); Py_DECREF(self->data[i].value);
} }
free(self->data); free(self->data);
PER_DEL(self);
PyMem_DEL(self); PyMem_DEL(self);
} }
...@@ -1762,7 +1761,7 @@ initBTree() ...@@ -1762,7 +1761,7 @@ initBTree()
#endif #endif
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.16 $"; char *rev="$Revision: 1.17 $";
UNLESS(PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI")) UNLESS(PyExtensionClassCAPI=PyCObject_Import("ExtensionClass","CAPI"))
return; return;
...@@ -1798,74 +1797,8 @@ initBTree() ...@@ -1798,74 +1797,8 @@ initBTree()
PyDict_SetItemString(d, "__version__", PyDict_SetItemString(d, "__version__",
PyString_FromStringAndSize(rev+11,strlen(rev+11)-2)); PyString_FromStringAndSize(rev+11,strlen(rev+11)-2));
#include "dcprotect.h"
/* Check for errors */ /* Check for errors */
if (PyErr_Occurred()) if (PyErr_Occurred())
Py_FatalError("can't initialize module BTree"); Py_FatalError("can't initialize module BTree");
} }
/*
PER_USE_OR_RETURN(self, NULL);
PER_ALLOW_DEACTIVATION(self);
*/
/*****************************************************************************
Revision Log:
$Log: BTree.c,v $
Revision 1.16 1998/03/24 15:17:44 jim
Brought reinit/deactivate machinery up to date.
Revision 1.15 1998/02/18 22:19:50 jim
Fixed C inheritence problem. Waaaaaaa.
Revision 1.14 1998/02/05 17:46:17 jim
Added get methods.
Revision 1.13 1998/02/04 21:11:26 jim
Fixed two leaks in bucket values.
Revision 1.12 1997/12/31 17:18:04 jim
Fixed bugs related to deleting items.
Revision 1.11 1997/12/12 23:43:05 jim
Added basicnew support.
Revision 1.10 1997/11/13 20:45:51 jim
Fixed some bad return values.
Revision 1.9 1997/11/13 20:38:35 jim
added dcprotect
Revision 1.8 1997/11/03 15:17:53 jim
Fixed stupid bug in has_key methods.
Revision 1.7 1997/10/30 20:58:43 jim
Upped bucket sizes.
Revision 1.6 1997/10/10 18:21:45 jim
Fixed bug in range queries.
Revision 1.5 1997/10/01 02:47:06 jim
Fixed bug in setstate that allocates too much memory.
Revision 1.4 1997/09/17 17:20:32 jim
Fixed bug in deleting members from BTree.
Revision 1.3 1997/09/12 18:35:45 jim
Fixed bug leading to random core dumps.
Revision 1.2 1997/09/10 17:24:47 jim
*** empty log message ***
Revision 1.1 1997/09/08 18:42:21 jim
initial BTree
$Revision 1.1 1997/02/24 23:25:42 jim
$initial
$
*****************************************************************************/
##############################################################################
#
# Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# o Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the disclaimer that follows.
#
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# o Neither the name of Digital Creations nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS IS*
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
"""Implement an bobo_application object that is BoboPOS3 aware
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.1 $'[11:-2]
class BoboApplication:
def __init__(self, db, name, klass= None, klass_args= (),
version_cookie_name=None):
self._stuff = db, name, version_cookie_name
if klass is not None:
conn=db.open()
root=conn.root()
if not root.has_key(name):
root[name]=klass()
get_transaction().commit()
conn.close()
self._klass=klass
# This hack is to overcome a bug in Bobo!
def __getattr__(self, name):
return getattr(self._klass, name)
def __bobo_traverse__(self, REQUEST=None, name=None):
db, aname, version_support = self._stuff
if version_support is not None and REQUEST is not None:
version=REQUEST.get(version_support,'')
else: version=''
conn=db.open(version)
# arrange for the connection to be closed when the request goes away
cleanup=Cleanup()
cleanup.__del__=conn.close
REQUEST[Cleanup]=cleanup
v=conn.root()[aname]
if name is not None:
if hasattr(v,name): return getattr(v,name)
return v[name]
return v
__call__=__bobo_traverse__ # A convenience for command-line use
class Cleanup: pass
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
##############################################################################
#
# Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# o Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the disclaimer that follows.
#
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# o Neither the name of Digital Creations nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS IS*
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
'''BoboPOS-defined exceptions
$Id: POSException.py,v 1.1 1998/11/11 02:00:55 jim Exp $'''
__version__='$Revision: 1.1 $'[11:-2]
class POSError(Exception):
"""Persistent object system error
"""
class TransactionError(POSError):
"""An error occured due to normal transaction processing
"""
class ConflictError(TransactionError):
"""Two transactions tried to modify the same object at once
This transaction should be resubmitted.
"""
class VersionError(POSError):
"""An error in handling versions occurred
"""
class VersionCommitError(VersionError):
"""An invalid combination of versions was used in a version commit
"""
class VersionLockError(VersionError, TransactionError):
"""An attempt was made to modify an object that has
been modified in an unsaved version"""
class UndoError(POSError):
"""An attempt was made to undo an undoable transaction.
"""
class StorageError(POSError):
pass
class StorageTransactionError(StorageError):
"""An operation was invoked for an invalid transaction or state
"""
class StorageSystemError(StorageError):
"""Panic! Internal storage error!
"""
...@@ -45,149 +45,114 @@ ...@@ -45,149 +45,114 @@
# (540) 371-6909 # (540) 371-6909
# #
############################################################################## ##############################################################################
__doc__='''Python implementation of a persistent base types '''Python implementation of a persistent base types
$Id: Persistence.py,v 1.16 1998/10/23 21:40:15 jim Exp $''' $Id: Persistence.py,v 1.17 1998/11/11 02:00:56 jim Exp $'''
__version__='$Revision: 1.16 $'[11:-2] __version__='$Revision: 1.17 $'[11:-2]
try: _marker=[]
from cPersistence import Persistent class Persistent:
except: """\
class Persistent: Persistent object support mix-in class
"""\
Persistent object support mix-in class When a persistent object is loaded from a database, the object's
data is not immediately loaded. Loading of the objects data is
When a persistent object is loaded from a database, the object's defered until an attempt is made to access an attribute of the
data is not immediately loaded. Loading of the objects data is object.
defered until an attempt is made to access an attribute of the
object. The object also tries to keep track of whether it has changed. It
is easy for this to be done incorrectly. For this reason, methods
The object also tries to keep track of whether it has changed. It of subclasses that change state other than by setting attributes
is easy for this to be done incorrectly. For this reason, methods should: 'self.__changed__(1)' to flag instances as changed.
of subclasses that change state other than by setting attributes
should: 'self.__changed__(1)' to flag instances as changed. You must not override the object's '__getattr__' and '__setattr__'
methods. If you override the objects '__getstate__' method, then
You must not override the object's '__getattr__' and '__setattr__' you must be careful not to include any attributes with names
methods. If you override the objects '__getstate__' method, then starting with '_p_' or '_v_' in the state.
you must be careful not to include any attributes with names
starting with '_p_' or '_v_' in the state. """
_p_oid=None # A Persistent object-id, unique within a jar
""" _p_changed=0 # The object state: None=ghost, 0=normal, 1=changed
_p_oid=None # A Persistent object-id, unique within a jar _p_jar=None # The last jar that this object was stored in.
_p_changed=0 # The object state: None=ghost, 0=normal, 1=changed
_p_jar=None # The last jar that this object was stored in. def _p_deactivate(self):
d=self.__dict__
def _p___init__(self,oid,jar): oid=d['_p_oid']
"""Post creation initialization jar=d['_p_jar']
d.clear()
This is *only* used if we have __getinitargs__! d['_p_oid']=oid
""" d['_p_jar']=jar
d=self.__dict__ d['_p_changed']=None
if d:
newstate={} def __getattr__(self,key):
for key in d.keys(): 'Get an item'
if key[:3] != '_p_': if self._p_changed is None and key[:3] != '_p_':
newstate[key]=d[key] self._p_jar.setstate(self)
del d[key] if self.__dict__.has_key(key): return self.__dict__[key]
if newstate: d['_p_newstate']=newstate
raise AttributeError, key
d['_p_oid']=oid
d['_p_jar']=jar def __setattr__(self,key,value):
d['_p_changed']=None ' '
changed=self._p_changed
def _p_deactivate(self,copy=None): if changed:
if copy is None: newstate=None self.__dict__[key]=value
else: newstate=copy.__dict__ return
d=self.__dict__
oid=self._p_oid k=key[:3]
jar=self._p_jar if k=='_p_' or k=='_v_':
d.clear() if key=='_p_changed':
if newstate: d['_p_newstate']=newstate if changed == value: return
d['_p_oid']=oid if value:
d['_p_jar']=jar if changed: return
d['_p_changed']=None try:
if self._p_jar and self._p_oid:
_p___reinit=_p_deactivate # Back. Comp. get_transaction().register(self)
def __getattr__(self,key):
'Get an item'
if self._p_changed is None and key[:3] != '_p_':
self._p_jar.setstate(self)
if self.__dict__.has_key(key): return self.__dict__[key]
raise AttributeError, key
def __setattr__(self,key,value):
' '
changed=self._p_changed
if changed:
self.__dict__[key]=value
return
k=key[:3]
if k=='_p_' or k=='_v_':
self.__dict__[key]=value
return
jar=self._p_jar
if jar is None:
self.__dict__[key]=value
return
d=self.__dict__
if changed is None:
d['_p_changed']=1
jar.setstate(self)
d[key]=value
try:
get_transaction().register(self)
d['_p_changed']=1
except: pass
def __changed__(self,v=-1):
old=self._p_changed
if v != -1:
if v and not old and self._p_jar is not None:
try: get_transaction().register(self)
except: pass except: pass
self._p_changed = not not v elif value is None:
if self._p_jar and self._p_oid:
return old return self._p_deactivate()
return
def __getstate__(self): value=not not value
self.__dict__[key]=value
# First, update my state, if necessary: return
if self._p_changed is None: self._p_jar.setstate(self)
jar=self._p_jar
state={} if jar is None:
d=self.__dict__ self.__dict__[key]=value
for k,v in d.items(): return
if k[:3] != '_p_' and k[:3] != '_v_': state[k]=v
return state d=self.__dict__
if changed is None:
def __setstate__(self,state): d['_p_changed']=1
d=self.__dict__ jar.setstate(self)
for k,v in state.items(): d[k]=v
return state d[key]=value
try:
def __save__(self): get_transaction().register(self)
'''\ d['_p_changed']=1
Update the object in a persistent database. except: pass
'''
jar=self._p_jar def __changed__(self,v=_marker):
if jar and self._p_changed: jar.store(self) if v is _marker: return not not self._p_changed
self._p_changed = not not v
def __repr__(self):
' ' def __getstate__(self):
return '<%s instance at %s>' % (self.__class__.__name__,
hex(id(self))) # First, update my state, if necessary:
if self._p_changed is None: self._p_jar.setstate(self)
def __inform_commit__(self,T,start_time):
jar=self._p_jar state={}
if jar and self._p_changed: jar.store(self,T) d=self.__dict__
for k,v in d.items():
def __inform_abort__(self,T,start_time): if k[:3] != '_p_' and k[:3] != '_v_': state[k]=v
try: self._p_jar.abort(self,start_time) return state
except: pass
def __setstate__(self,state):
self.__dict__.update(state)
def __repr__(self):
' '
return '<%s instance at %s>' % (self.__class__.__name__,
hex(id(self)))
...@@ -48,12 +48,12 @@ ...@@ -48,12 +48,12 @@
__doc__='''Python implementation of persistent base types __doc__='''Python implementation of persistent base types
$Id: PersistentMapping.py,v 1.2 1998/10/23 21:40:59 jim Exp $''' $Id: PersistentMapping.py,v 1.3 1998/11/11 02:00:56 jim Exp $'''
__version__='$Revision: 1.2 $'[11:-2] __version__='$Revision: 1.3 $'[11:-2]
import Persistence import Persistence
class PersistentMapping(Persistence.Persistent): class PM(Persistence.Persistent):
"""A persistent wrapper for mapping objects. """A persistent wrapper for mapping objects.
This class allows wrapping of mapping objects so that This class allows wrapping of mapping objects so that
...@@ -65,22 +65,36 @@ class PersistentMapping(Persistence.Persistent): ...@@ -65,22 +65,36 @@ class PersistentMapping(Persistence.Persistent):
if container is None: container={} if container is None: container={}
self._container=container self._container=container
def __delitem__(self, key):
del self._container[key]
try: del self._v_keys
except: pass
self.__changed__(1)
def __getitem__(self, key): def __getitem__(self, key):
return self._container[key] return self._container[key]
def __len__(self): return len(self._container)
def __setitem__(self, key, v): def __setitem__(self, key, v):
self._container[key]=v self._container[key]=v
try: del self._v_keys try: del self._v_keys
except: pass except: pass
self.__changed__(1) self.__changed__(1)
def __delitem__(self, key): def clear(self):
del self._container[key] self._container.clear()
try: del self._v_keys self._p_changed=1
except: pass if hasattr(self,'_v_keys'): del self._v_keys
self.__changed__(1)
def __len__(self): return len(self._container) def copy(self): return self.__class__(self._container.copy())
def get(self, key, default): return self._container.get(key, default)
def has_key(self,key): return self._container.has_key(key)
def items(self):
return map(lambda k, d=self: (k,d[k]), self.keys())
def keys(self): def keys(self):
try: return self._v_keys try: return self._v_keys
...@@ -91,14 +105,12 @@ class PersistentMapping(Persistence.Persistent): ...@@ -91,14 +105,12 @@ class PersistentMapping(Persistence.Persistent):
keys.sort() keys.sort()
return keys return keys
def clear(self): def update(self, b):
self._container={} a=self._container
if hasattr(self,'_v_keys'): del self._v_keys for k, v in b.items(): a[k] = v
self._p_changed=1
def values(self): def values(self):
return map(lambda k, d=self: d[k], self.keys()) return map(lambda k, d=self: d[k], self.keys())
def items(self): PersistentMapping=PM
return map(lambda k, d=self: (k,d[k]), self.keys())
def has_key(self,key): return self._container.has_key(key)
...@@ -47,8 +47,8 @@ ...@@ -47,8 +47,8 @@
############################################################################## ##############################################################################
__doc__='''PickleJar Object Cache __doc__='''PickleJar Object Cache
$Id: PickleCache.py,v 1.4 1998/10/23 21:41:24 jim Exp $''' $Id: PickleCache.py,v 1.5 1998/11/11 02:00:56 jim Exp $'''
__version__='$Revision: 1.4 $'[11:-2] __version__='$Revision: 1.5 $'[11:-2]
from sys import getrefcount from sys import getrefcount
...@@ -61,12 +61,14 @@ class PickleCache: ...@@ -61,12 +61,14 @@ class PickleCache:
for a in 'keys', 'items', 'values', 'has_key': for a in 'keys', 'items', 'values', 'has_key':
setattr(self,a,getattr(self.data,a)) setattr(self,a,getattr(self.data,a))
def __getitem__(self, key): def __getitem__(self, key):
cache=self.data v=self.data[key]
v=cache[key] self.incrgc()
return v
def incrgc(self):
# Do cache GC # Do cache GC
cache=self.data
n=min(len(cache)/self.cache_size,10) n=min(len(cache)/self.cache_size,10)
if n: if n:
l=self.cache_location l=self.cache_location
...@@ -82,11 +84,13 @@ class PickleCache: ...@@ -82,11 +84,13 @@ class PickleCache:
del cache[id] del cache[id]
self.cache_location=l self.cache_location=l
return v def __setitem__(self, key, v):
self.data[key]=v
def __setitem__(self, key, v): self.data[key]=v self.incrgc()
def __delitem__(self, key): del self.data[key] def __delitem__(self, key):
del self.data[key]
self.incrgc()
def __len__(self): return len(self.data) def __len__(self): return len(self.data)
......
*shared* *shared*
cPersistence cPersistence.c -I../ExtensionClass -I../python cPersistence cPersistence.c -I../ExtensionClass -I../python
cPickleCache cPickleCache.c -I../ExtensionClass -I../python cPickleCache cPickleCache.c -I../ExtensionClass -I../python
#Record Record.c -I../ExtensionClass cPickleJar ./cPickleJar.c -I../ExtensionClass
iTree ./iTree.c -I../ExtensionClass
intSet ./intSet.c -I/projects/_/ExtensionClass -I/projects/_/cPersistence -I/projects/_/python
BTree ./BTree.c -I/projects/_/ExtensionClass -I/projects/_/cPersistence -I/projects/_/python
IIBTree ./IIBTree.c -I/projects/_/ExtensionClass -I/projects/_/cPersistence -I/projects/_/python
IOBTree ./IOBTree.c -I/projects/_/ExtensionClass -I/projects/_/cPersistence -I/projects/_/python
OIBTree ./OIBTree.c -I/projects/_/ExtensionClass -I/projects/_/cPersistence -I/projects/_/python
#install CacheManager.py
This diff is collapsed.
##############################################################################
#
# Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# o Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the disclaimer that follows.
#
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# o Neither the name of Digital Creations nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS IS*
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
from DB import DB
from Persistence import Persistent
from POSException import *
##############################################################################
#
# Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# o Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the disclaimer that follows.
#
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# o Neither the name of Digital Creations nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS IS*
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
"""Thread abstraction module
With this, we can run with or wothout threads.
$Id: bpthread.py,v 1.1 1998/11/11 02:00:56 jim Exp $"""
try:
from thread import *
except:
class allocate_lock:
def acquire(self, *args): return args and 1 or None
def release(self): pass
start_new_thread=apply
"""Install C-based replacements for BoboPOS components.
"""
import cPickleCache, cPersistence
import BoboPOS3, BoboPOS3.Persistence, BoboPOS3.Connection
BoboPOS3.Persistence.Persistent=cPersistence.Persistent
BoboPOS3.Persistent=cPersistence.Persistent
BoboPOS3.Connection.PickleCache=cPickleCache.PickleCache
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
static char intSet_module_documentation[] = static char intSet_module_documentation[] =
"" ""
"\n$Id: intSet.c,v 1.9 1998/03/24 15:17:34 jim Exp $" "\n$Id: intSet.c,v 1.10 1998/11/11 02:00:56 jim Exp $"
; ;
#include <limits.h> #include <limits.h>
...@@ -225,8 +225,6 @@ intSet___setstate__(intSet *self, PyObject *args) ...@@ -225,8 +225,6 @@ intSet___setstate__(intSet *self, PyObject *args)
char *c; char *c;
INTSET_DATA_TYPE k; INTSET_DATA_TYPE k;
PER_PREVENT_DEACTIVATION(self);
UNLESS(PyArg_ParseTuple(args,"O",&data)) return PER_RETURN(self, NULL); UNLESS(PyArg_ParseTuple(args,"O",&data)) return PER_RETURN(self, NULL);
UNLESS(c=PyString_AsString(data)) return PER_RETURN(self, NULL); UNLESS(c=PyString_AsString(data)) return PER_RETURN(self, NULL);
...@@ -271,7 +269,7 @@ intSet_set_operation(intSet *self, PyObject *other, ...@@ -271,7 +269,7 @@ intSet_set_operation(intSet *self, PyObject *other,
o=INTSET(other); o=INTSET(other);
PER_USE_OR_RETURN(self, NULL); PER_USE_OR_RETURN(self, NULL);
PER_USE_OR_RETURN(other, NULL); PER_USE_OR_RETURN((intSet*)other, NULL);
od=o->data; od=o->data;
...@@ -537,7 +535,7 @@ void ...@@ -537,7 +535,7 @@ void
initintSet() initintSet()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.9 $"; char *rev="$Revision: 1.10 $";
UNLESS(ExtensionClassImported) return; UNLESS(ExtensionClassImported) return;
...@@ -575,6 +573,9 @@ initintSet() ...@@ -575,6 +573,9 @@ initintSet()
Revision Log: Revision Log:
$Log: intSet.c,v $ $Log: intSet.c,v $
Revision 1.10 1998/11/11 02:00:56 jim
alpha1
Revision 1.9 1998/03/24 15:17:34 jim Revision 1.9 1998/03/24 15:17:34 jim
*** empty log message *** *** empty log message ***
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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