[Xotcl] Persistence in XOTcl (was Re: pb in src/package distribution configure)

uwe.zdun at uni-essen.de uwe.zdun at uni-essen.de
Wed Nov 22 12:03:02 CET 2000


>>>>> "CL" == Catherine Letondal <letondal at pasteur.fr> writes:
>> > 3) What is GDBM required for? Is it a general purpose persistence package that
>> > I could use for my own needs? How can I use it within XOtcl?
>> > 
>> 
>> gdbm is a nice persistence store, which allows you to make any
>> XOTcl object persistent (by specifying, which vars are persistent). There
>> is no documentation yet, but you can see in the counter examples in
>> apps/actiweb-apps how it works. the necessary packages are in the
>> packages/store dir. at the moment we are relying on gdbm, but plan to use
>> also several other persistent stores soon

CL> The problem is that gdbm il old (according to colleagues) and does does not install
CL> easily on my workstation - so I guess there will be problems on other platforms?
CL> Actually I had pbs with their ./libtool script for installing files and nobody could help!

We are aware of these problems. But Gdbm is in most Linux
Distributions. For Windows we provide a pre-compiled DLL. The
other platforms (like Solaris) sometimes require some hand-crafting.

There are several other persistent store (and databases), which we
possibly will support soon behind one common object interface (like
Berkley DB, MetaKit, etc.)


CL> Persistence interests me *a lot*, since the environment I'm currently programming is a
CL> programming environment, where 'programming exploration' is allowed by adding procs to 
CL> objects during the normal use session. Several types of customization - like graphic
CL> attributes, bindings configuration - have also to be saved of course. 

CL> The idea is also to have the already existing objects and their user interface (widget) to be 
CL> automatically displayed when the application is restarted. 
CL> Saving will be done by default, I mean without the user being required to ask for it.

CL> All this is realted to what you call 'programmable interfaces' in the paper 'Design and 
CL> Implementation Constructs for the Devlopment of Flexible, Component-Oriented Software 
CL> Architectures' - except that it is the so-called 'end-user programming'.

CL> What's the main idea to save an object? I have seen the persistent keyword in the
CL> counter examples, but how do you say: save this object, save this object's proc, etc...?

There are basically two things to do in order to make an object
persistent: 

1. you have to set up a Persistence Manager. That is an object wrapper
   for the database/persistent store instance. E.g. with Gdbm it
   represents a GDBM file 

2. you have to say which variables of which objects should be made
   persistent. This is done by calling the method "persistent" ...


"persistent" is an instproc of the class Persistent, which you can
find in store/Persistence.xotcl. This class (or one of its subclasses)
has to be made per-object mixin (or per-class mixin or superclass) of
the instance that should be made persistent.

The subclasses of the Class Persistent are the ones you actually
use. They determine the persistence strategy. Actually we have two
persistence strategies at the moment: Eager and Lazy. The Eager
strategy stores everything when it is written, the Lazy strategy
stores the vars when the xotclsh terminates.

This may sound more complicated than it actually is. Here is a simple
example:


####################################
# load the persistence component
package require Persistence

# Two example objects
Object o
# set two variables to default values
o set x 1
o set y 1

Object p
# set two variables to default values
p set x 1
p set y 1

####################################
# now we make these vars persistent
####################################


# 1. we need the PersistenceMgr (for gdbm we have to specify a file
# name). If we want to get rid of the current setting and start again
# we default values, we have to delete this file
PersistenceMgr pmgr -persistenceDir . -persistenceFile example-db

# 2. we have to make the objects persistent. We register the
# persistence strategy as per-object mixin on the two objects
#
# one uses the lazy, one the eager strategy

o mixin Persistent=Eager
p mixin Persistent=Lazy

# 3. tell the objects, which PersistenceMgr to use

o persistenceMgr pmgr
p persistenceMgr pmgr

# 4. make the vars persistent

o persistent {x y}
p persistent {x y}

#####################################

# now the vars are loaded from the persistence store
#
# we incr them to demonstrate the persistency; and print the results

o incr x 2
o append y 1
p incr x 3
p append y 2

puts "Values:"
puts "  o->x: [o set x]"
puts "  o->y: [o set y]"
puts "  p->x: [p set x]"
puts "  p->y: [p set y]"

# now run the program several times to see the results 

####################################



I will include this example in the store dir of the XOTcl
distribution.

Note, for XOTcl WebObjects, Agents, etc. several of the tasks
demonstrated above are performed automatically ... therefore, the
Counter examples look even much more simple. The WebObjects
automatically associates with the PersistenceMgr of the place.

Therefore a simple:
  [self] persistent varXXX
makes the variable varXXX persistent eagerly.

CL> BTW, I have already develop small things, like a spreadsheet (using a mixin class
CL> to implement the dependencies between cells - see 
CL> http://www.pasteur.fr/~letondal/tmp/mvc-depend.html) implemented thanks to tktable.

great! we have an applications web site on the XOTcl homepage and
encourage everyone to put up a web site for their XOTcl apps. If you
have something to reference please inform us. 


Regards,

Uwe

-- 
Uwe Zdun
Specification of Software Systems, University of Essen
Phone: +49 201 81 00 332, Fax: +49 201 81 00 398
zdun at xotcl.org, uwe.zdun at uni-essen.de




More information about the Xotcl mailing list