Class: DbMeta::Oracle::Connection
- Inherits:
-
Object
- Object
- DbMeta::Oracle::Connection
- Includes:
- Singleton
- Defined in:
- lib/db_meta/oracle/connection.rb
Constant Summary collapse
- THREAD_KEY =
:db_meta_oracle_connection
Instance Attribute Summary collapse
-
#database_instance ⇒ Object
Returns the value of attribute database_instance.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#username ⇒ Object
Returns the value of attribute username.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #disconnect ⇒ Object
- #get ⇒ Object
- #release_thread_connection ⇒ Object
- #set(username, password, database_instance, worker) ⇒ Object
Instance Attribute Details
#database_instance ⇒ Object
Returns the value of attribute database_instance.
10 11 12 |
# File 'lib/db_meta/oracle/connection.rb', line 10 def database_instance @database_instance end |
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/db_meta/oracle/connection.rb', line 10 def password @password end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
11 12 13 |
# File 'lib/db_meta/oracle/connection.rb', line 11 def pool @pool end |
#username ⇒ Object
Returns the value of attribute username.
10 11 12 |
# File 'lib/db_meta/oracle/connection.rb', line 10 def username @username end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
12 13 14 |
# File 'lib/db_meta/oracle/connection.rb', line 12 def worker @worker end |
Instance Method Details
#disconnect ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/db_meta/oracle/connection.rb', line 42 def disconnect release_thread_connection return unless @pool @pool.destroy Log.info("Logged off from #{@username}@#{@database_instance}") @pool = nil end |
#get ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/db_meta/oracle/connection.rb', line 21 def get unless @pool # create connection pool @pool = ::OCI8::ConnectionPool.new(1, @worker, 1, @username, @password, @database_instance) Log.info("Connected to #{@username}@#{@database_instance}") end # one logical connection per thread - reused across all fetches in that thread Thread.current[THREAD_KEY] ||= ::OCI8.new(@username, @password, @pool) end |
#release_thread_connection ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/db_meta/oracle/connection.rb', line 32 def release_thread_connection connection = Thread.current[THREAD_KEY] return unless connection connection.logoff rescue # connection may already be closed ensure Thread.current[THREAD_KEY] = nil end |
#set(username, password, database_instance, worker) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/db_meta/oracle/connection.rb', line 14 def set(username, password, database_instance, worker) @username = username @password = password @database_instance = database_instance @worker = worker end |