Module: OracleToMysql::PrivateInstanceMethods

Defined in:
lib/oracle_to_mysql/private_instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#generate_tmp_file_name(x) ⇒ Object

This generates a temp file suffixed with the specified x it is used



62
63
64
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 62

def generate_tmp_file_name(x)
  File.join(self.tmp_directory,"#{self.otm_target_table}_#{self.otm_timestamp.to_i}_#{x}")
end

#otm_execute_command_namesObject

This reflects on the various strategy, retain, and other options that the client class has specified and generates a linear sequence of command names that will be executed on .otm_execute



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 35

def otm_execute_command_names
  if @otm_execute_command_names.nil?
    case self.otm_strategy
    when :atomic_rename        
      @otm_execute_command_names = [
        :write_sqlplus_commands_to_file,
        :fork_and_execute_sqlplus_commands_file,
        :write_and_execute_mysql_commands_to_bash_file
      ]
    when :accumulative
      @otm_execute_command_names = [
        :write_sqlplus_commands_to_file,
        :fork_and_execute_sqlplus_commands_file,
        :write_and_execute_mysql_commands_to_bash_file_in_replace_mode
      ]
    else
      raise "Invalid otm_strategy=#{@otm_strategy}"
    end
    
    ## All strategies should cleanup after themselves lastly
    @otm_execute_command_names << :delete_temp_files
  end
  @otm_execute_command_names                  
end

#otm_finished(msg) ⇒ Object



17
18
19
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 17

def otm_finished(msg)
  self.otm_output("[finished t=#{self.otm_time_elapsed_since_otm_timestamp}]#{msg}")
end

#otm_output(msg) ⇒ Object

LOGGING FUNCTIONS BEGIN



11
12
13
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 11

def otm_output(msg)
  puts "[#{self.to_s}]#{msg}"
end

#otm_retained_target_table(retain_n) ⇒ Object

Must pass an argument, retain_n is “the number tables old relative to the current table” if n is 1, the retained table is simple <TBL>_old if its greater, there a dynamic “show retained tables for this table”, sort lexically, and return the -nth retain_n (i think) (negative nth) from the list



71
72
73
74
75
76
77
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 71

def otm_retained_target_table(retain_n)
  if retain_n == 1
    "#{self.otm_target_table}#{OTM_RETAIN_KEY}"
  else
    raise "TODO: HAVE NOT DEALT WITH n != 1 retain option"
  end
end

#otm_set_strategy(strategy, options = {}) ⇒ Object



3
4
5
6
7
8
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 3

def otm_set_strategy(strategy,options={})
  raise "Invalid strategy #{strategy}" unless OTM_VALID_STRATEGIES.include?(strategy)
  @otm_strategy = strategy
  # TODO: verify options
  @otm_strategy_options = options
end

#otm_started(msg) ⇒ Object



14
15
16
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 14

def otm_started(msg)      
  self.otm_output("[started t=#{self.otm_time_elapsed_since_otm_timestamp}]#{msg}")
end

#otm_time_elapsed_since_otm_timestampObject

LOGGING FUNCTIONS END



22
23
24
25
26
27
28
29
# File 'lib/oracle_to_mysql/private_instance_methods.rb', line 22

def otm_time_elapsed_since_otm_timestamp
  if @otm_timestamp.nil?
    self.otm_timestamp # calling this first, causes the lazily loaded timestamp to load...
    0
  else
    Time.now - self.otm_timestamp
  end
end