[Borges-users] Re: Transactions (Was: Borges Documentation)

Kaspar Schiess eule at space.ch
Fri Mar 19 21:08:04 EST 2004


Hello Eric,

> I need to check these patches against Seaside, to see if the problem is
> in StateRegistry, or elsewhere.  Inline are my dim recollections of how
> this is supposed to work.
So I guess I should give you the details of my error trace: Took me the 
good part of the week; all the classes I had to skip at university.. ;)

Session holds a list of filters like this:
@filters = StateHolder.new []

def add_filter(f)
	@filters.push f
end

def remove_filter(f)
	@filters.delete f
end

The trouble is, the registry does shallow copies for arrays too, so the 
array gets modified globally. For code like this one (annotated with 
filter list and transaction state)

(1) session.isolate do 		# [], not yet created
(2) 	inform('inside')	# [Transaction], active
(3) end 				# [], closed
(4) inform('outside')		# [], closed

But then jumping back into (2) does not restore the filters array 
(shallow copy), and since that array has been modified in place, it will be
(2) 	inform('inside')	#[], closed

The transaction is there, it is closed, but Session does not know about it.

So what I am proposing is that StateRegistry does shallow copies, except 
for classes like Array (in the patch) and Hash (not there) that should 
really be restored to their original contents. The extensions I make to 
Object and Array are to that purpose:
#snapshot_dup 		# make a snapshot duplication (possibly recurse)
#snapshot_shallow?	# only snapshot this class shallow or recurse ?
#snapshot_identical_to? # is a identical to b ? (recursion)
#snapshot_restore_from? # restore from with recursion

So the Registry holds shallow copies WITH THE EXCEPTION of some classes 
that the user probably expects to be restored in depth, like array. If 
you think about it, there is no way currently to store the contents of 
an array, except a lot of ugly hacks...

Hoping to save you the work of getting behind all this yourself..


kaspar - code philosopher

-- stolen off the net --
C Code. C code run. Run, code, run... PLEASE!!!
		-- Barbara Tongue

PS: Of course, we could change the functions to read:
def add_filter(f)
	@filters = @filters + [f]
end

def remove_filter(f)
	@filters = @filters.dup.delete f
end

but that seems rather ugly to me.




More information about the Borges-users mailing list