DBSourceDBClient

class Client

Binds a connection pool to the specified adapter.

Definitions

def initialize(adapter, **options)

Initialize the client and internal connection pool using the specified adapter.

Signature

parameter adapter Object

The adapter instance.

Implementation

def initialize(adapter, **options)
	@adapter = adapter
	
	@pool = connect(**options)
end

attr :adapter

The adapter used for making connections.

Signature

attribute Object

def close

Close all open connections in the connection pool.

Implementation

def close
	@pool.close
end

def session(**options)

Acquires a connection and sends the specified statement if given.

Signature

yields {|session| ...}

A connected session if a block is given. Implicitly closed.

parameter session Context::Session
returns Context::Session

A connected session if no block is given.

Implementation

def session(**options)
	session = Context::Session.new(@pool, **options)
	
	return session unless block_given?
	
	begin
		session.connect!
		
		yield session
	ensure
		session.close
	end
end

def transaction(**options)

Acquires a connection and starts a transaction.

Signature

yields {|session| ...}

A connected session if a block is given. Implicitly commits, or aborts the connnection if an exception is raised.

parameter session Context::Transaction
returns Context::Transaction

A connected and started transaction if no block is given.

Implementation

def transaction(**options)
	transaction = Context::Transaction.new(@pool, **options)
	
	transaction.begin
	
	return transaction unless block_given?
	
	begin
		yield transaction
		
	rescue
		transaction.abort
		raise
	ensure
		transaction.commit?
	end
end