Parent

Included Modules

Class/Module Index [+]

Quicksearch

RR::SyncHelper

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

Attributes

table_sync[RW]

The current TableSync instance

Public Class Methods

new(table_sync) click to toggle source

Creates a new SyncHelper for the given TableSync instance.

# 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) click to toggle source

Delegates to Committers::BufferedCommitter#delete_record

# 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() click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# File lib/rubyrep/sync_helper.rb, line 112
def finalize(success = true)
  @committer.finalize(success) if @committer
end
insert_record(database, table, values) click to toggle source

Delegates to Committers::BufferedCommitter#insert_record

# File lib/rubyrep/sync_helper.rb, line 41
def insert_record(database, table, values)
  committer.insert_record(database, tables[database], values)
end
left_table() click to toggle source

Name of the left table

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

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

# 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|
      %("#{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() click to toggle source

Name of the right table

# File lib/rubyrep/sync_helper.rb, line 20
def right_table; table_sync.right_table; end
session() click to toggle source

The active Session

# File lib/rubyrep/sync_helper.rb, line 14
def session; table_sync.session; end
sync_options() click to toggle source

Sync options for the current table sync

# File lib/rubyrep/sync_helper.rb, line 38
def sync_options; @sync_options ||= table_sync.sync_options; end
tables() click to toggle source

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

# 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) click to toggle source

Delegates to Committers::BufferedCommitter#update_record

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.