require 'flydata/source/generate_source_dump' require 'flydata/preference/data_entry_preference' require 'flydata/source_oracle/oracle_component' require 'flydata/source_oracle/query_based_sync/diff_query_generator' require 'flydata/source_oracle/table_meta' require 'flydata-core/oracle/source_pos' require 'flydata-core/oracle/oracle_client' require 'flydata-core/oracle/query_helper' require 'msgpack' module Flydata module SourceOracle class GenerateSourceDump < Source::GenerateSourceDump include OracleComponent def run_compatibility_check(dump_dir, backup_dir) %w(host username database).each do |k| if de_prefs[k].to_s.empty? raise "'#{k}' is required. Set the value in the conf file " + "-> #{Flydata::Preference::DataEntryPreference.conf_path(de)}" end end end def confirmation_items items = { "host" => de_prefs['host'], "port" => de_prefs['port'], "username" => de_prefs['username'], "database" => de_prefs['database'], "schema" => de_prefs['schema'], } items end DUMP_SIZE_QUERY = < column_name, "format_type" => columndef_hash["data_type"]} end source_table_hash = { "table_name" => tabledef.table_name, "columns" => columns } io.write(source_table_hash.to_msgpack) end def dump_table_chunk(table, schema, source_pos, num_rows, tabledef, pk_columns, last_pks, io, cli) query = Flydata::SourceOracle::QueryBasedSync::DiffQueryGenerator.new( table, schema, columns: tabledef.columns, to_scn: source_pos.scn, pk_columns: pk_columns, last_pks: last_pks, limit: num_rows).build_query column_names = tabledef.columns.inject([]) do |ary, h| ary << h[:column] end res = cli.query(query) count = 0 last_row = nil while (row = res.fetch_hash) count += 1 last_row = row dump_row(row, column_names, io) end last_pks = last_row ? pk_columns.collect{|col| last_row[col]} : nil [count, last_pks] end def dump_row(row, columns, io) data = columns.collect{|col| row[col] }.to_msgpack io.write(data) end end end end