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.
].

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.uh...@gmail.com>) 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

Reply via email to