class DataMgr::DB

Attributes

clients[RW]
config[RW]

Public Class Methods

new() click to toggle source
# File lib/DataMgr/DB/db.rb, line 22
def initialize
  @clients={}
end

Public Instance Methods

close(_id) click to toggle source
# File lib/DataMgr/DB/db.rb, line 26
def close(_id)
  disconnect(_id)
end
connect(_id) click to toggle source
# File lib/DataMgr/DB/db.rb, line 40
def connect(_id)
  rc=false
  begin
    conn=get(_id)

    if !conn.nil?

      raise DBConnectionError

      #@clients[_id] = TinyTds::Client.new username: conn['user'],
      #                             password: conn['password'],
      #                             host: conn['host'],
      #                             port: conn['port']
      #rc=true if @clients[_id].active?
    else
      puts __FILE__ + (__LINE__).to_s + " WARN: client #{_id} is not defined."
    end

  rescue DBConnectionError => ex
    raise ex

  rescue => ex
    ;
  end

  rc
end
disconnect(_id) click to toggle source
# File lib/DataMgr/DB/db.rb, line 30
def disconnect(_id)
  rc=false
  if @clients.has_key?(_id)
    @clients[_id].close
    rc=true
  end
  rc
end
get(_id) click to toggle source
# File lib/DataMgr/DB/db.rb, line 69
def get(_id)
  @config.each do |_c|
    puts __FILE__ + (__LINE__).to_s + " get => #{_c}"
    if _c.has_key?(_id)
      return _c[_id]
    end
  end

  nil
end
load(_config) click to toggle source
# File lib/DataMgr/DB/db.rb, line 81
def load(_config)
  rc=false
  begin
    @config=YAML.load_stream File.read(_config)
    rc=true
  rescue => ex
    puts __FILE__ + (__LINE__).to_s + " #{ex.class}: Invalid file: #{_config} - abort processing."
    puts ex.backtrace
  end
  rc
end