Esteban A. Maringolo wrote
> I think it is a tricky thing to do "in memory transactions", even
> without thinking about databases.
> You have to define what to keep and where to place the "original"
> values (inst. vars.) of the object.
> 
> As a general purpose solution if you can do that, you end up
> implementing a mini gemstone in Pharo :)
> 
> But what's sure is that you should have a mini object-table of the
> "touched" objects or do "explicit" registration of these objects like
> GLORP allows you to do.
> 
> e.g.
> 
> | p |
> p := Person new.
> System transaction: [:tx |
>   tx register: p.
>   p name: 'Nobody'.
>   p age: 70.
> ].

It seems to me that the fundamental problem with the idea of registering
each object with the transaction (or anything else) is that it requires
white-box knowledge of what every invoked behaviour will do and touch. The
above example is so minimal, it looks easy.

I think if you really want transactional Smalltalk, you need to use one
designed expressly for that purpose.
(And fortunately, there is one.)



> self assert: p name equals: 'Nobody'.
> self assert: p age equals: 70.
> 
> I'm using System here, to make it compatible with GemStone.
> #transaction: could be implemented in terms of #beginTransaction,
> #commitTransaction and internally use #abortTransaction if an
> unhandled Error is signalled.
> 
> Regards!
> 
> Esteban A. Maringolo
> El lun., 30 jul. 2018 a las 10:17, Peter Uhnák (<

> i.uhnak@

> >) escribió:
>>
>> Hi,
>>
>> is there some library or approach how to do transactions in pharo?
>> And I don't mean database transactions, but directly in memory on Pharo
>> objects... e.g.
>>
>> p := Person new.
>>
>> transaction do: [
>>     p name: 'Nobody'.
>>     p age: 70.
>> ] on: Error do: [
>>     transaction rollback.
>> ].
>>
>> self assert: p name equals: 'Nobody'.
>> self assert: p age equals: 70.
>>
>> transaction do: [
>>     p name: 'Somebody'.
>>     p age: 1 / 0.
>> ] on: Error do: [
>>     transaction rollback.
>> ].
>>
>> self assert: p name equals: 'Nobody'.
>> self assert: p age equals: 70.
>>
>> Any pointers appreciated.
>>
>> Thanks,
>> Peter





--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply via email to