Created
February 21, 2010 10:38
-
-
Save benhoskings/310253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
def atomic &block | |
self.class.transaction { | |
lock! | |
yield | |
} | |
end | |
end | |
end | |
class Sequence < ActiveRecord::Base | |
# so instead of this, | |
def nextval | |
Sequence.transaction { | |
lock! | |
returning self.value += 1 do | |
save! | |
end | |
} | |
end | |
# we can do this | |
def nextval | |
atomic { | |
returning self.value += 1 do | |
save! | |
end | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment