Class: Flydata::SourceOracle::GenerateSourceDump

Inherits:
Flydata::Source::GenerateSourceDump show all
Includes:
OracleComponent
Defined in:
lib/flydata/source_oracle/generate_source_dump.rb

Constant Summary collapse

DUMP_SIZE_QUERY =
<<EOS
SELECT
  sum(bytes) as total_size
FROM
(SELECT segment_name table_name, owner, bytes
FROM dba_segments
WHERE segment_type IN ('TABLE','TABLE PARTITION','TABLE SUBPARTITION')
UNION ALL
SELECT i.table_name, i.owner, s.bytes
FROM dba_indexes i, dba_segments s
WHERE s.segment_name = i.index_name
AND s.owner = i.owner
AND s.segment_type IN ('INDEX','INDEX PARTITION','INDEX SUBPARTITION')
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.segment_name
AND s.owner = l.owner
AND s.segment_type IN ('LOBSEGMENT','LOB PARTITION')
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.index_name
AND s.owner = l.owner
AND s.segment_type = 'LOBINDEX')
WHERE owner = %{schema} and table_name in (%{tables})
EOS

Instance Attribute Summary

Attributes inherited from Flydata::Source::GenerateSourceDump

#dp

Instance Method Summary collapse

Methods included from OracleComponent

#de_prefs

Methods inherited from Flydata::Source::GenerateSourceDump

inherited, #initialize

Methods inherited from Flydata::Source::Component

#initialize

Constructor Details

This class inherits a constructor from Flydata::Source::GenerateSourceDump

Instance Method Details

#confirmation_itemsObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flydata/source_oracle/generate_source_dump.rb', line 26

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(tables, file_path = nil, &src_pos_callback) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/flydata/source_oracle/generate_source_dump.rb', line 82

def dump(tables, file_path = nil, &src_pos_callback)
  io = nil
  if file_path
    io = File.open(file_path, "w")
  else
    raise "dump via pipe has not been implemented yet"
  end

  table_meta = Flydata::SourceOracle::TableMeta.new(de_prefs, tables)
  cli = FlydataCore::Oracle::OracleClient.new(de_prefs)
  table_meta.reload(cli)

  tables_missing_meta = tables.select{|t| tm = table_meta[t]; tm.nil? || tm.empty?}
  unless tables_missing_meta.empty?
    raise "Tables are not available.  Check if the following table(s) exist and are visible: #{tables_missing_meta.join(",")}"
  end

  context = source.sync_generate_table_ddl(dp, nil)
  source_pos = get_source_pos(table_meta.current_scn, &src_pos_callback)

  options = de_prefs.merge(table_meta: table_meta)
  missing_tables = context.each_source_tabledef(tables, options) do |tabledef, error|
    dump_table(tabledef, source_pos, io, cli) if tabledef
  end

  nil
ensure
  cli.close if cli
  io.close if io
end

#dump_size(tables) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/flydata/source_oracle/generate_source_dump.rb', line 66

def dump_size(tables)
  cli = FlydataCore::Oracle::OracleClient.new(de_prefs)

  query = DUMP_SIZE_QUERY % {
    schema: FlydataCore::Oracle::QueryHelper.schema_as_value(de_prefs['schema'],
                                                             de_prefs['username']),
    tables: FlydataCore::Oracle::QueryHelper.tables_as_value(tables)
  }

  cursor = cli.query(query)
  cursor.fetch_hash['TOTAL_SIZE'].to_i
ensure
  cursor.close rescue nil if cursor
  cli.close if cli
end

#run_compatibility_check(dump_dir, backup_dir) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/flydata/source_oracle/generate_source_dump.rb', line 17

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