Class: OracleToMysql::Command::WriteAndExecuteMysqlCommandsToBashFileInReplaceMode

Inherits:
WriteAndExecuteMysqlCommandsToBashFile show all
Defined in:
lib/oracle_to_mysql/command/write_and_execute_mysql_commands_to_bash_file_in_replace_mode.rb

Instance Attribute Summary

Attributes inherited from OracleToMysql::Command

#client_class

Instance Method Summary collapse

Methods inherited from WriteAndExecuteMysqlCommandsToBashFile

#command_line_invocation, #create_actual_target_table_if_it_doesnt_exist, #drop_expired_retained_tables, #execute_internal, #execute_otm_target_sql, #execute_temp_file_modded_otm_target_sql, #perform_atomic_rename_of_tables, #tables_to_retain, #temp_file_symbols, #the_mysql_commands

Methods inherited from OracleToMysql::Command

#error, #execute, #execute_internal, #finished, #info, #output, #started, #temp_file_symbols, #warn

Instance Method Details

#load_data_infileObject

Mostly the same as parent class except:

* the replace key word which will replace existing rows on the target when there are mysql duplicate key errors
  possible todo: support "ignore" instead of "replace" (i have no reason to do this)
* it copied into the otm_target_table directly rather than the temp table


38
39
40
41
42
43
44
45
46
# File 'lib/oracle_to_mysql/command/write_and_execute_mysql_commands_to_bash_file_in_replace_mode.rb', line 38

def load_data_infile
  "-- Rip through the oracle output data and insert into mysql
   load data local infile '#{self.client_class.otm_get_file_name_for(:oracle_output)}' 
   replace
   into table #{self.client_class.otm_target_table}         
   fields terminated by '\\t'
   lines terminated by '\\n'
  "
end

#mysql_command_orderObject

OVERRIDDEN



6
7
8
9
10
11
12
# File 'lib/oracle_to_mysql/command/write_and_execute_mysql_commands_to_bash_file_in_replace_mode.rb', line 6

def mysql_command_order        
  [:execute_otm_target_sql,
   :drop_expired_retained_tables,   # defined in parent
   :retention_policy_create_and_populate_tables,
   :load_data_infile                # overridden in this class
  ]
end

#retention_policy_create_and_populate_tablesObject

MYSQL COMMANDS BEGIN



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/oracle_to_mysql/command/write_and_execute_mysql_commands_to_bash_file_in_replace_mode.rb', line 16

def retention_policy_create_and_populate_tables
  raise "TODO: not implemented yet for retention :n != 1" if self.tables_to_retain != 1
  the_modded_client_class_inst = self.client_class.clone
  the_modded_client_class_inst.instance_eval(<<-EOS, __FILE__,__LINE__)
    def otm_target_table
      "#{self.client_class.otm_retained_target_table(tables_to_retain)}"
    end
  EOS
  
  return_this = ''
  return_this << the_modded_client_class_inst.otm_target_sql
  return_this << ";\n"
  return_this << "-- Insert existing rows into the retention table\n"
  return_this << "INSERT INTO #{the_modded_client_class_inst.otm_target_table} SELECT * FROM #{self.client_class.otm_target_table}\n"
  return_this
end