Module: ActiveRecord::ConnectionAdapters::PostgreSQLAdapterPatches

Defined in:
lib/transaction_isolation_level/adapter_patches.rb

Instance Method Summary collapse

Instance Method Details

#begin_db_transactionObject



67
68
69
# File 'lib/transaction_isolation_level/adapter_patches.rb', line 67

def begin_db_transaction
  execute "BEGIN TRANSACTION #{transaction_isolation_level_sql(@transaction_isolation_level)}"
end

#configure_connectionObject



90
91
92
93
94
95
96
97
98
# File 'lib/transaction_isolation_level/adapter_patches.rb', line 90

def configure_connection
  super
  if @config[:transaction_isolation_level]
    @default_transaction_isolation_level = @config[:transaction_isolation_level].to_sym
    execute "SET SESSION CHARACTERISTICS AS TRANSACTION #{transaction_isolation_level_sql default_transaction_isolation_level}"
  else
    @default_transaction_isolation_level = transaction_isolation_level_from_sql(select_value("SELECT current_setting('default_transaction_isolation')"))
  end
end

#type_mapObject

the postgresql adapter calls configure_connection part way through its #initialize. after that point, it sets a type map, which needs to be the postgresql-specific type that #initialize would instantiate, not the default created by #type_map in the abstract adapter code. so we override that default to be the same as #initialize will make.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/transaction_isolation_level/adapter_patches.rb', line 76

def type_map
  return @type_map if instance_variable_defined?(:@type_map)
  @type_map =
    if PostgreSQLAdapter::OID.const_defined?(:TypeMap)
      # 5.0 and below
      PostgreSQLAdapter::OID::TypeMap.new
    else
      # 5.1 and above
      Type::HashLookupTypeMap.new
    end
  initialize_type_map(type_map)
  @type_map
end