Class: DbMeta::Oracle::Connection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/db_meta/oracle/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#database_instanceObject

Returns the value of attribute database_instance.



8
9
10
# File 'lib/db_meta/oracle/connection.rb', line 8

def database_instance
  @database_instance
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/db_meta/oracle/connection.rb', line 8

def password
  @password
end

#poolObject (readonly)

Returns the value of attribute pool.



9
10
11
# File 'lib/db_meta/oracle/connection.rb', line 9

def pool
  @pool
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/db_meta/oracle/connection.rb', line 8

def username
  @username
end

#workerObject (readonly)

Returns the value of attribute worker.



10
11
12
# File 'lib/db_meta/oracle/connection.rb', line 10

def worker
  @worker
end

Instance Method Details

#disconnectObject



30
31
32
33
34
35
# File 'lib/db_meta/oracle/connection.rb', line 30

def disconnect
  return unless @pool
  @pool.destroy
  Log.info("Logged off from #{@username}@#{@database_instance}")
  @pool = nil
end

#getObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/db_meta/oracle/connection.rb', line 19

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

  # create and return logical connection. It creates physical connection as needed.
  ::OCI8.new(@username, @password, @pool)
end

#set(username, password, database_instance, worker) ⇒ Object



12
13
14
15
16
17
# File 'lib/db_meta/oracle/connection.rb', line 12

def set(username, password, database_instance, worker)
  @username = username
  @password = password
  @database_instance = database_instance
  @worker = worker
end