Class: Pool
- Inherits:
-
Object
- Object
- Pool
- Defined in:
- lib/spannerlib/pool.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.create_pool(dsn) ⇒ Object
Create a new Pool given a DSN string.
Instance Method Summary collapse
-
#close ⇒ Object
Close this pool and free native resources.
-
#create_connection ⇒ Object
Create a new Connection associated with this Pool.
-
#initialize(id) ⇒ Pool
constructor
A new instance of Pool.
Constructor Details
#initialize(id) ⇒ Pool
Returns a new instance of Pool.
23 24 25 26 |
# File 'lib/spannerlib/pool.rb', line 23 def initialize(id) @id = id @closed = false end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/spannerlib/pool.rb', line 21 def id @id end |
Class Method Details
.create_pool(dsn) ⇒ Object
Create a new Pool given a DSN string. Raises SpannerLibException on failure.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spannerlib/pool.rb', line 29 def self.create_pool(dsn) begin pool_id = SpannerLib.create_pool(dsn) rescue StandardError => e raise SpannerLibException, e. end raise SpannerLibException, "failed to create pool" if pool_id.nil? || pool_id <= 0 Pool.new(pool_id) end |
Instance Method Details
#close ⇒ Object
Close this pool and free native resources.
42 43 44 45 46 47 |
# File 'lib/spannerlib/pool.rb', line 42 def close return if @closed SpannerLib.close_pool(@id) @closed = true end |
#create_connection ⇒ Object
Create a new Connection associated with this Pool.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/spannerlib/pool.rb', line 50 def create_connection raise SpannerLibException, "pool closed" if @closed begin conn_id = SpannerLib.create_connection(@id) rescue StandardError => e raise SpannerLibException, e. end raise SpannerLibException, "failed to create connection" if conn_id.nil? || conn_id <= 0 Connection.new(@id, conn_id) end |