Class: Flydata::SourceOracle::QueryBasedSync::DiffQueryGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/flydata/source_oracle/query_based_sync/diff_query_generator.rb

Constant Summary collapse

DEFAULT_LIMIT =
10000
FETCH_RECORDS_SQL =
<<EOS
SELECT %{columns} FROM %{table_name} AS OF SCN %{scn} WHERE %{where_clause} ORDER BY %{order_by_clause}
EOS

Instance Method Summary collapse

Constructor Details

#initialize(table, schema, query_cond = {}) ⇒ DiffQueryGenerator

Returns a new instance of DiffQueryGenerator.



17
18
19
20
21
22
23
24
25
26
# File 'lib/flydata/source_oracle/query_based_sync/diff_query_generator.rb', line 17

def initialize(table, schema, query_cond = {})
  @table = table
  @schema = schema

  @columns = query_cond[:columns] or raise ArgumentError, "columns is required"
  @to_scn = query_cond[:to_scn] or raise ArgumentError, "to_scn is required"
  @pk_columns = query_cond[:pk_columns] or raise ArgumentError, "pk_columns is required"
  @last_pks = query_cond[:last_pks]
  @limit = query_cond[:limit] || DEFAULT_LIMIT
end

Instance Method Details

#build_query(binding_param_enabled = true) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/flydata/source_oracle/query_based_sync/diff_query_generator.rb', line 28

def build_query(binding_param_enabled = true)
  column_names, types = @columns.inject([[],[]]) do |arys, h|
    arys[0] << h[:column]; arys[1] << h[:type].gsub(/\(.+?\)/,''); arys
  end
  columns = column_list(column_names, types)

  query = FETCH_RECORDS_SQL % {
    columns: columns,
    table_name: fq_table_name(@table, @schema),
    scn: @to_scn,
    where_clause: build_where_clause(@pk_columns, @last_pks, @limit),
    order_by_clause: build_order_by_clause(@pk_columns),
  }

end