diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-12-27 18:04:35 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-12-27 18:04:35 -0300 |
commit | b339caca2f3c7306c3944c5fc5d8dde17ae2deb8 (patch) | |
tree | a443bebb38ffc34c3642a655c5cc9d20a22ee3d3 /lib/arel/algebra/relations | |
parent | 3ea68bc6bde539f4391cc1b96999e16c25ca0801 (diff) | |
download | rails-b339caca2f3c7306c3944c5fc5d8dde17ae2deb8.tar.gz rails-b339caca2f3c7306c3944c5fc5d8dde17ae2deb8.tar.bz2 rails-b339caca2f3c7306c3944c5fc5d8dde17ae2deb8.zip |
Added lock to Arel, allowing a locking read if required.
Diffstat (limited to 'lib/arel/algebra/relations')
-rw-r--r-- | lib/arel/algebra/relations/operations/lock.rb | 12 | ||||
-rw-r--r-- | lib/arel/algebra/relations/relation.rb | 5 | ||||
-rw-r--r-- | lib/arel/algebra/relations/utilities/compound.rb | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/arel/algebra/relations/operations/lock.rb b/lib/arel/algebra/relations/operations/lock.rb new file mode 100644 index 0000000000..0d6c12e65b --- /dev/null +++ b/lib/arel/algebra/relations/operations/lock.rb @@ -0,0 +1,12 @@ +module Arel + class Lock < Compound + attributes :relation, :locked + deriving :initialize, :== + + def initialize(relation, locked, &block) + @relation = relation + @locked = locked.blank? ? " FOR UPDATE" : locked + end + end +end + diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 2ce3fdcce8..b24e7c24d0 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -51,6 +51,10 @@ module Arel OPERATION end + def lock(locking = nil) + Lock.new(self, locking) + end + def alias Alias.new(self) end @@ -131,6 +135,7 @@ module Arel def taken; nil end def skipped; nil end def sources; [] end + def locked; [] end end include DefaultOperations end diff --git a/lib/arel/algebra/relations/utilities/compound.rb b/lib/arel/algebra/relations/utilities/compound.rb index 06bfce4ac0..9967472d88 100644 --- a/lib/arel/algebra/relations/utilities/compound.rb +++ b/lib/arel/algebra/relations/utilities/compound.rb @@ -2,7 +2,7 @@ module Arel class Compound < Relation attr_reader :relation delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?, - :column_for, :engine, :sources, + :column_for, :engine, :sources, :locked, :to => :relation [:attributes, :wheres, :groupings, :orders].each do |operation_name| |