Class: Db2Session::DbClient
- Inherits:
-
Db2Query::DbClient
- Object
- Db2Query::DbClient
- Db2Session::DbClient
- Defined in:
- lib/db2_session/db_client.rb
Instance Method Summary collapse
- #define_authenticated_client(userid, password) ⇒ Object
-
#initialize(config, userid, password) ⇒ DbClient
constructor
A new instance of DbClient.
- #new_client(userid, password) ⇒ Object
- #reconnect! ⇒ Object
Constructor Details
#initialize(config, userid, password) ⇒ DbClient
Returns a new instance of DbClient.
5 6 7 8 9 10 11 |
# File 'lib/db2_session/db_client.rb', line 5 def initialize(config, userid, password) @dsn = config[:dsn] @idle_time_limit = config[:idle] || 5 define_authenticated_client(userid, password) @client = authenticated_client @last_transaction = Time.now end |
Instance Method Details
#define_authenticated_client(userid, password) ⇒ Object
13 14 15 16 17 |
# File 'lib/db2_session/db_client.rb', line 13 def define_authenticated_client(userid, password) singleton_class.define_method(:authenticated_client) do new_client(userid, password) end end |
#new_client(userid, password) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/db2_session/db_client.rb', line 19 def new_client(userid, password) ODBC.connect(dsn, userid, password).tap do |odbc_conn| odbc_conn.use_time = true odbc_conn.use_utc = is_utc? end rescue ::ODBC::Error => e raise Db2Query::ConnectionError.new(e.) end |
#reconnect! ⇒ Object
28 29 30 31 |
# File 'lib/db2_session/db_client.rb', line 28 def reconnect! disconnect! @client = authenticated_client end |