Class: Db2Query::Connection

Inherits:
Object
  • Object
show all
Includes:
DbStatements, Logger
Defined in:
lib/db2_query/db_connection.rb

Defined Under Namespace

Classes: Pool

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DbStatements

#exec_query, #execute, #query, #query_rows, #query_value, #query_values, #raw_query, #reset_id_sequence!

Methods included from Logger

#log, #translate_exception, #translate_exception_class

Constructor Details

#initialize(config) ⇒ Connection

Returns a new instance of Connection.



46
47
48
49
50
51
52
# File 'lib/db2_query/db_connection.rb', line 46

def initialize(config)
  @config = config
  @instrumenter = ActiveSupport::Notifications.instrumenter
  @mutex = Mutex.new
  @connection_pool = nil
  create_connection_pool
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



38
39
40
# File 'lib/db2_query/db_connection.rb', line 38

def config
  @config
end

#connection_poolObject (readonly)

Returns the value of attribute connection_pool.



38
39
40
# File 'lib/db2_query/db_connection.rb', line 38

def connection_pool
  @connection_pool
end

#instrumenterObject (readonly)

Returns the value of attribute instrumenter.



38
39
40
# File 'lib/db2_query/db_connection.rb', line 38

def instrumenter
  @instrumenter
end

#mutexObject (readonly)

Returns the value of attribute mutex.



38
39
40
# File 'lib/db2_query/db_connection.rb', line 38

def mutex
  @mutex
end

Instance Method Details

#create_connection_poolObject



60
61
62
63
64
65
# File 'lib/db2_query/db_connection.rb', line 60

def create_connection_pool
  mutex.synchronize do
    return @connection_pool if @connection_pool
    @connection_pool = Pool.new(pool_config) { DbClient.new(config) }
  end
end

#pool_configObject



56
57
58
# File 'lib/db2_query/db_connection.rb', line 56

def pool_config
  { size: config[:pool], timeout: config[:timeout] }
end