Class: RR::TriggerModeSwitcher
- Inherits:
-
Object
- Object
- RR::TriggerModeSwitcher
- Defined in:
- lib/rubyrep/trigger_mode_switcher.rb
Overview
Switches rubyrep triggers between “exclude rubyrep activity” modes.
Instance Attribute Summary collapse
-
#session ⇒ Object
The active Session.
Instance Method Summary collapse
-
#exclude_rr_activity(database, table) ⇒ Object
Switches the trigger of the named table to “exclude rubyrep activity” mode.
-
#initialize(session) ⇒ TriggerModeSwitcher
constructor
A new instance of TriggerModeSwitcher.
-
#restore_triggers ⇒ Object
Restores all switched triggers to not exclude rubyrep activity.
-
#switch_trigger_mode(database, table, exclude_rr_activity) ⇒ Object
Does the actual switching of the trigger mode.
-
#triggers ⇒ Object
Keeps track of all the triggers.
Constructor Details
#initialize(session) ⇒ TriggerModeSwitcher
Returns a new instance of TriggerModeSwitcher.
21 22 23 |
# File 'lib/rubyrep/trigger_mode_switcher.rb', line 21 def initialize(session) self.session = session end |
Instance Attribute Details
#session ⇒ Object
The active Session
19 20 21 |
# File 'lib/rubyrep/trigger_mode_switcher.rb', line 19 def session @session end |
Instance Method Details
#exclude_rr_activity(database, table) ⇒ Object
Switches the trigger of the named table to “exclude rubyrep activity” mode. Only switches if it didn’t do so already for the table.
-
database
: either :left
or :right
-
table
: name of the table
49 50 51 |
# File 'lib/rubyrep/trigger_mode_switcher.rb', line 49 def exclude_rr_activity(database, table) switch_trigger_mode(database, table, true) if triggers[database].add? table end |
#restore_triggers ⇒ Object
Restores all switched triggers to not exclude rubyrep activity
54 55 56 57 58 59 60 61 |
# File 'lib/rubyrep/trigger_mode_switcher.rb', line 54 def restore_triggers [:left, :right].each do |database| triggers[database].each do |table| switch_trigger_mode database, table, false end triggers[database].clear end end |
#switch_trigger_mode(database, table, exclude_rr_activity) ⇒ Object
Does the actual switching of the trigger mode.
-
database
: either :left
or :right
-
table
: name of the table -
exclude_rr_activity
: the new trigger mode (eithertrue
orfalse
)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubyrep/trigger_mode_switcher.rb', line 29 def switch_trigger_mode(database, table, exclude_rr_activity) = session.configuration. if session.send(database).replication_trigger_exists? "#{options[:rep_prefix]}_#{table}", table params = { :trigger_name => "#{options[:rep_prefix]}_#{table}", :table => table, :keys => session.send(database).primary_key_names(table), :log_table => "#{options[:rep_prefix]}_pending_changes", :activity_table => "#{options[:rep_prefix]}_running_flags", :key_sep => [:key_sep], :exclude_rr_activity => exclude_rr_activity, } session.send(database).create_or_replace_replication_trigger_function(params) end end |
#triggers ⇒ Object
Keeps track of all the triggers. This is a hash with 2 keys: :left
and :right
. Each of these entries is a Set containing table names.
11 12 13 14 15 16 |
# File 'lib/rubyrep/trigger_mode_switcher.rb', line 11 def triggers @triggers ||= { :left => Set.new, :right => Set.new } end |