Class: JunglePath::DBAccess::Import::DBDir

Inherits:
Object
  • Object
show all
Defined in:
lib/jungle_path/db_access/import/db_dir.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger = nil) ⇒ DBDir

Returns a new instance of DBDir.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 18

def initialize(config, logger=nil)
  @logger = logger
  @config = config
  @path = config.import_file_path
  @log_path = config.import_log_path
  Dir.mkdir(path) unless Dir.exist?(path)
  clear_import_files
  @select = JunglePath::DBAccess::Import::Select.new @config, @logger
  @insert = JunglePath::DBAccess::Import::Insert.new @config, @logger
  @delete = JunglePath::DBAccess::Import::Delete.new @config, @logger
  @schema = JunglePath::DBAccess::Import::Schema.new @config, @logger
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 10

def config
  @config
end

#deleteObject (readonly)

Returns the value of attribute delete.



15
16
17
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 15

def delete
  @delete
end

#insertObject (readonly)

Returns the value of attribute insert.



14
15
16
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 14

def insert
  @insert
end

#log_pathObject (readonly)

Returns the value of attribute log_path.



12
13
14
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 12

def log_path
  @log_path
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 11

def path
  @path
end

#schemaObject (readonly)

Returns the value of attribute schema.



16
17
18
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 16

def schema
  @schema
end

#selectObject (readonly)

Returns the value of attribute select.



13
14
15
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 13

def select
  @select
end

Instance Method Details

#clear_import_filesObject



44
45
46
47
48
49
50
51
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 44

def clear_import_files
  if Dir.exist?(path)
    data_files = Dir.glob(File.join(path, "*.dat"))
    data_files.each do |file_name|
      File.delete file_name
    end
  end
end

#reset_sequence_for_table(table_name) ⇒ Object



31
32
33
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 31

def reset_sequence_for_table(table_name)
  @insert.db.reset_sequence_for_table(table_name)
end

#transactionObject



35
36
37
38
39
40
41
42
# File 'lib/jungle_path/db_access/import/db_dir.rb', line 35

def transaction
  begin_transaction
  yield
  commit_transaction
rescue
  rollback_transaction
  raise
end