Hi Tim, thanks a lot for the information regarding pcounters as it
seems to be hard to find at the moment. Until now not even Google
would know about them in the context of Maglev, that will probably
change upon the next index of this group which is a good thing. There
are 4 methods concerning pcounters in Maglev::System,
#decrement_pcounter, #increment_pcounter, #pcounter and #set_pcounter
with pretty obvious semantics. I was originally planning to use one
counter per entity (as you would do with sequences in Oracle or other
databases) but given that there are only 128 of those counters I will
probably only use one of them for the whole application. Ultimately
URLs will be a bit longer, but that should not be a big issue.
I am pretty sure pcounters are the better solution than my clumsy
approximation, but it at least satisfied my tests :-)
Concerning nested transactions your code seems to achieve the same
thing I intended without any of the "smell", thanks for the pointer.
In fact I wanted to be able to persistently save my object with
minimal fuss and still be able to rollback my MiniTest::Specs in a
nested transaction. This seems to be achieved perfectly.
I guess I will put my code up on github as an open source example for
Maglev as soon as it can actually produce invoices. There seem to be
fairly little examples at the moment.
On 25 Dez., 18:10, Tim Felgentreff <
timfelgentr...@gmail.com> wrote:
> There's be a better way to achieve what you're trying to do with the global
> counters here.
>
...
> This functionality is available in Smalltalk as "System
> class>>persistentCounterAt:incrementBy:", which corresponds to
> "Maglev::System#increment_pcounter(counter, by=1)". The methods returns the
> new value. There's more documentation in
> maglev/src/kernel/bootstrap/System.rb
>
> Using that mechanism, you're method could shorten to:
>
> def self.next_number
> # 0 < OBJECT_ID_SLOT < 128
> Maglev::System.increment_pcounter(OBJECT_ID_SLOT)
> end
...