Class: JDBCHelpers::ConnectionFactory

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

Overview

Creates a discreet JDBC connection and makes it available via connection attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cleanse_statement, #convert_to_string_classes

Constructor Details

#initialize(jdbc_url, db_user, db_pass, logger = nil) ⇒ ConnectionFactory

Returns a new instance of ConnectionFactory

Parameters:

  • jdbc_url (String)
  • db_user (String)
  • db_pass (String)
  • logger (Logger) (defaults to: nil)

    object otherwise will default to new Logger



38
39
40
41
42
43
44
45
46
47
# File 'lib/jdbc_helpers.rb', line 38

def initialize(jdbc_url, db_user, db_pass, logger = nil)
  @logger = logger ? logger : Logger.new(STDOUT)
  @logger.info("connecting to #{jdbc_url} as user #{db_user}...")
  @connection = java.sql.DriverManager.get_connection(
    jdbc_url,
    db_user,
    db_pass
  )
  @logger.info("connection successful!") if @connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection



32
33
34
# File 'lib/jdbc_helpers.rb', line 32

def connection
  @connection
end