Module: OracleToMysql::ApiInstanceMethods

Defined in:
lib/oracle_to_mysql/api_instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#otm_all_target_tablesObject

returns an array of all target tables by reflecting the table retention options



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/oracle_to_mysql/api_instance_methods.rb', line 82

def otm_all_target_tables
  return_this = [self.otm_target_table]
  if self.otm_retain_options[:n] == 0
    return_this
  else
    (1..self.otm_retain_options[:n]).to_enum.each do |x|
      return_this << self.otm_retained_target_table(x)
    end
    return_this
  end
end

#otm_all_temp_filesObject

Returns all temp files that all commands in the current strategy can create



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

def otm_all_temp_files
  return_this = []
  self.otm_execute_command_names.each do |command_name|
    command = OracleToMysql.get_and_bind_command(command_name, self)
    return_this += command.temp_file_symbols.map {|sym| self.otm_get_file_name_for(sym)}
  end
  return_this.uniq
end

#otm_config_hashObject

For interaction with the configuration file that contains the mysql or oracle stuff override otm_config_file if you have yer config somewhere crazy



48
49
50
51
52
53
# File 'lib/oracle_to_mysql/api_instance_methods.rb', line 48

def otm_config_hash
  if @otm_confile_file_hash.nil?
    @otm_confile_file_hash = YAML.load(File.read(self.otm_config_file))
  end
  @otm_confile_file_hash      
end

#otm_executeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/oracle_to_mysql/api_instance_methods.rb', line 3

def otm_execute
  self.otm_output("[started at #{self.otm_timestamp}]")
  self.otm_started("#otm_execute (in #{self.otm_strategy.to_s} mode, retain_n = #{self.otm_retain_options[:n]}")
  self.otm_execute_command_names.each do |command_name|
    command = OracleToMysql.get_and_bind_command(command_name, self)
    begin
      command.execute
    rescue OracleToMysql::CommandError => e
      puts "TODO: SHOULD EMAIL SOMEONE OR SOMETHING, THE BUILD FAILED"
      raise e           
    rescue Exception => e
      puts "TODO: CUSTOM EXCEPTION HANDLING FOR A PARTICULAR COMMAND MIGHT HAPPEN HERE..."
      raise e
    end        
  end
  self.otm_finished("#otm_execute")
  final_time_elapsed = self.otm_time_elapsed_since_otm_timestamp
  finished_at = self.otm_timestamp + final_time_elapsed
  
  self.otm_output("[finished at #{finished_at}]")
  self.otm_output("[completed in #{final_time_elapsed} seconds]")
  self.otm_reset_timestamp
  return true
end

#otm_get_file_name_for(sym) ⇒ Object

This is used extensively by commands to read and write the the specific files that are shared accross commands, it is a bit protected-ish though (aka prolly don’t want to override this)



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oracle_to_mysql/api_instance_methods.rb', line 31

def otm_get_file_name_for(sym)
  f = self.generate_tmp_file_name(sym)
  case sym
  when :mysql_commands    
    "#{f}.sql"
  when :oracle_commands
    "#{f}.sql"   # sqlplus is such a jackass, the file name must end in .sql for it to work, fyi
  when :oracle_output
    "#{f}.txt"
  else
    raise "Invalid file_name #{sym}"
  end
end

#otm_reset_timestampObject

You need to do this to invoke .otm_execute twice on the same inst, or it will clobber



65
66
67
# File 'lib/oracle_to_mysql/api_instance_methods.rb', line 65

def otm_reset_timestamp
  @otm_timestamp = nil # reset it so all temp files have a new identifier, if otm_execute'd is executed again
end

#otm_timestampObject

all tables and file name are versioned against the seconds of this Time obj



57
58
59
60
61
62
# File 'lib/oracle_to_mysql/api_instance_methods.rb', line 57

def otm_timestamp
  if @otm_timestamp.nil?
    @otm_timestamp = Time.now
  end
  @otm_timestamp
end