Class RR::SyncHelper

  1. lib/rubyrep/sync_helper.rb
Parent: Object

Provides helper functionality for the table syncers. The methods exposed by this class are intended to provide a stable interface for third party syncers.

Included modules

  1. LogHelper

Attributes

table_sync [RW] The current TableSync instance

Public class methods

new (table_sync)

Creates a new SyncHelper for the given TableSync instance.

[show source]
# File lib/rubyrep/sync_helper.rb, line 117
    def initialize(table_sync)
      self.table_sync = table_sync
    end

Public instance methods

delete_record (database, table, values)
[show source]
# File lib/rubyrep/sync_helper.rb, line 51
    def delete_record(database, table, values)
      committer.delete_record(database, tables[database], values)
    end
ensure_event_log ()

Checks if the event log table already exists and creates it if necessary

[show source]
# File lib/rubyrep/sync_helper.rb, line 66
    def ensure_event_log
      unless @ensured_event_log
        ReplicationInitializer.new(session).ensure_event_log
        @ensured_event_log = true
      end
    end
extract_key (row)

Given a column_name => value hash of a full row, returns a column_name => value hash of the primary key columns.

  • row: the full row

Returns

[show source]
# File lib/rubyrep/sync_helper.rb, line 33
    def extract_key(row)
      row.reject {|column, value| not primary_key_names.include? column }
    end
finalize (success = true)

Asks the committer (if it exists) to finalize any open transactions success should be true if there were no problems, false otherwise.

[show source]
# File lib/rubyrep/sync_helper.rb, line 112
    def finalize(success = true)
      @committer.finalize(success) if @committer
    end
insert_record (database, table, values)
[show source]
# File lib/rubyrep/sync_helper.rb, line 41
    def insert_record(database, table, values)
      committer.insert_record(database, tables[database], values)
    end
left_table ()

Name of the left table

[show source]
# File lib/rubyrep/sync_helper.rb, line 17
    def left_table; table_sync.left_table; end
log_sync_outcome (row, type, outcome, details = nil)

Logs the outcome of a replication into the replication log table.

  • row: a column_name => value hash for at least the primary keys of the record
  • type: string describing the type of the sync
  • outcome: string describing what’s done about the sync
  • details: string with further details regarding the sync
[show source]
# File lib/rubyrep/sync_helper.rb, line 84
    def log_sync_outcome(row, type, outcome, details = nil)
      ensure_event_log
      if primary_key_names.size == 1
        key = row[primary_key_names[0]]
      else
        key_parts = primary_key_names.map do |column_name|
          %Q("#{column_name}"=>#{row[column_name].to_s.inspect})
        end
        key = key_parts.join(', ')
      end
      sync_outcome, sync_details = fit_description_columns(outcome, details)

      session.left.insert_record "#{sync_options[:rep_prefix]}_logged_events", {
        :activity => 'sync',
        :change_table => left_table,
        :diff_type => type.to_s,
        :change_key => key,
        :left_change_type => nil,
        :right_change_type => nil,
        :description => sync_outcome,
        :long_description => sync_details,
        :event_time => Time.now,
        :diff_dump => nil
      }
    end
right_table ()

Name of the right table

[show source]
# File lib/rubyrep/sync_helper.rb, line 20
    def right_table; table_sync.right_table; end
session ()

The active Session

[show source]
# File lib/rubyrep/sync_helper.rb, line 14
    def session; table_sync.session; end
sync_options ()

Sync options for the current table sync

[show source]
# File lib/rubyrep/sync_helper.rb, line 38
    def sync_options; @sync_options ||= table_sync.sync_options; end
tables ()

A hash with :left: name of the table in the left database :right: name of the table in the right database

[show source]
# File lib/rubyrep/sync_helper.rb, line 25
    def tables
      @tables ||= {:left => left_table, :right => right_table}
    end
update_record (database, table, values, old_key = nil)
[show source]
# File lib/rubyrep/sync_helper.rb, line 46
    def update_record(database, table, values, old_key = nil)
      committer.update_record(database, tables[database], values, old_key)
    end