class RR::TriggerModeSwitcher
Switches rubyrep triggers between “exclude rubyrep activity” modes.
Attributes
session[RW]
The active Session
Public Class Methods
new(session)
click to toggle source
# File lib/rubyrep/trigger_mode_switcher.rb, line 21 def initialize(session) self.session = session end
Public Instance Methods
exclude_rr_activity(database, table)
click to toggle source
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
# 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()
click to toggle source
Restores all switched triggers to not exclude rubyrep activity
# 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)
click to toggle source
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
)
# File lib/rubyrep/trigger_mode_switcher.rb, line 29 def switch_trigger_mode(database, table, exclude_rr_activity) options = session.configuration.options 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 => options[:key_sep], :exclude_rr_activity => exclude_rr_activity, } session.send(database).create_or_replace_replication_trigger_function(params) end end
triggers()
click to toggle source
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.
# File lib/rubyrep/trigger_mode_switcher.rb, line 11 def triggers @triggers ||= { :left => Set.new, :right => Set.new } end