Class: DataMapper::Adapters::MysqlAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/data_mapper/adapters/mysql_adapter.rb

Defined Under Namespace

Modules: Coersion, Queries, Quoting

Constant Summary

Constants inherited from AbstractAdapter

AbstractAdapter::SYNTAX, AbstractAdapter::TYPES

Instance Method Summary collapse

Methods inherited from AbstractAdapter

inherited, #transaction

Constructor Details

#initialize(configuration) ⇒ MysqlAdapter

Returns a new instance of MysqlAdapter.



21
22
23
24
# File 'lib/data_mapper/adapters/mysql_adapter.rb', line 21

def initialize(configuration)
  super
  @connections = Support::ConnectionPool.new { Queries::Connection.new(@configuration)  }
end

Instance Method Details

#connection ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/data_mapper/adapters/mysql_adapter.rb', line 26

def connection
  raise ArgumentError.new('MysqlAdapter#connection requires a block-parameter') unless block_given?
  begin
    @connections.hold { |connection| yield connection }
  rescue Mysql::Error => me
    
    @configuration.log.fatal(me)
    
    @connections.available_connections.each do |sock|
      begin
        sock.close
      rescue => se
        @configuration.log.error(se)
      end
    end
    
    @connections.available_connections.clear
    raise me
  end
end