Class: DBFactoryClass

Inherits:
Object
  • Object
show all
Defined in:
lib/db_factory/db_factory.rb

Instance Method Summary collapse

Constructor Details

#initializeDBFactoryClass

Returns a new instance of DBFactoryClass.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/db_factory/db_factory.rb', line 14

def initialize()
  l_erb  = ERB.new(File.read("#{ROOT}/config.yml"))
  @cfg = YAML.load(l_erb.result(binding).to_s)

  @log = Logger.new("#{@cfg['LOG']['path']}/#{@cfg['LOG']['filename']}")
  @log.info  "================ Initializing DBFactory ================"
  @log.debug "[ DBFactory::initialize(...) ]"

  @log.datetime_format = @cfg['LOG']['date format']
  @log.level = @cfg['LOG']['level']

  return self
end

Instance Method Details

#check_postconditions(stage = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/db_factory/db_factory.rb', line 81

def check_postconditions(stage = nil)
  @log.debug "[ DBFactory::check_postconditions(...) ]"
  l_result = true
  raise "Use stage name (must contain string 'stage-[stage name]'" unless stage.nil? || stage.include?('stage')
#    l_stage = "stage-#{stage}" unless stage == nil
  l_diff_file = @cfg['DIFF']['filename_tpl'].gsub('#CASE#',@case)
  File.delete(l_diff_file) unless not File.exist?(l_diff_file)
  @definition[@case]['postconditions']['tables'].each { |t|
    if stage.nil? || t.values[0].include?(stage)
      l_result_tmp = check_postconditions_for_table(t, stage)
      l_result = l_result_tmp unless l_result == false
    end
  }

  if l_result
    @log.info("> DBFactory::evaluate(...) ... PASS")
  else
    @log.warn("> DBFactory::evaluate(...) ... FAIL")
  end

  return l_result
end

#flashbackObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/db_factory/db_factory.rb', line 104

def flashback()
  @log.debug "[ DBFactory::flashback(...) ]"
  l_result = true
  @definition[@case]['flashback']['tables'].each { |t|
      table_owner = t.split('.')[0].upcase
      table_name = t.split('.')[1].upcase
      @log.debug " > table_owner = <#{table_owner}>"
      @log.debug " > table_name  = <#{table_name}>"
      @log.debug " > scn        = <#{@scn}>"
      l_result = plsql.flashback_table(table_owner, table_name, @scn) unless l_result == false
      @log.debug "...DONE"
  }
  @scn = nil

  return l_result
end

#load(definition_file) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/db_factory/db_factory.rb', line 28

def load(definition_file)
  @log.debug "[ DBFactory::load(...) ]"
  @log.debug " > definition_file = <#{definition_file}>"

  begin
    @log.debug "Reading constants ..."
    constants  = YAML.load_file(definition_file)['CONSTANTS'].reduce(Hash.new, :merge)
  rescue Exception => e
    @log.error "[ DBFactory::load(...) ] ERROR: <#{e.to_s}>"
    @log.error "Error occurred during load of definition file <#{definition_file}>"
    raise "Check defintion file <#{definition_file}>: #{e.to_s}"
  end

  @log.debug "Injecting constants ..."
  l_erb      = ERB.new(File.read(definition_file).strip.gsub(/^\s*#.*/,'').gsub(/\n^\s*$/,''))

  @log.debug "Parsing defintion file ..."
  @definition = YAML.load(l_erb.result(binding).to_s)
  @case = 'COMMON'

#    puts @cfg['GENERAL']['supported_file_format_versions'].to_s
#    puts @definition['FORMAT VERSION']
#    puts @definition.inspect
  raise "Unsupported version of YAML file. Supported file versions: #{@cfg['GENERAL']['supported format'].to_s}" unless @cfg['GENERAL']['supported
format'].include?(@definition['%FORMAT'])
end

#setup(casename = 'COMMON') ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/db_factory/db_factory.rb', line 55

def setup(casename = 'COMMON')
  @log.debug "[ DBFactory::setup(...) ]"
  @log.debug " > casename = <#{casename}>"

  if casename != 'COMMON'
    setup()
  else
    @scn = plsql.select("select current_scn from v$database")[0][:current_scn]
    @log.info("CURRENT SCN from DB = <#{@scn}>")
  end

  @case = casename

  if @definition[@case].include?('cleanup')
    @definition[@case]['cleanup']['tables'].each { |t|
      cleanup_table(t)
    }
  end

#    puts @definition[@case] unless casename == 'COMMON'
  @definition[@case]['setup']['tables'].each { |t|
    prepare_table(t)
  }

end