Skip to content

Commit 648b769

Browse files
committed
Minimal fixes to be able to run postgres tests
1 parent 7c85e93 commit 648b769

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

lib/arjdbc/abstract/connection_management.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ def disconnect!
3636
# end
3737
# end
3838

39+
private
40+
3941
# DIFFERENCE: we delve into jdbc shared code and this does self.class.new_client.
4042
def connect
41-
@raw_connection = jdbc_connection_class(@config[:adapter_spec]).new(@config, self)
42-
@raw_connection.configure_connection
43+
@raw_connection = jdbc_connection_class.new(@connection_parameters, self)
44+
rescue ConnectionNotEstablished => ex
45+
raise ex.set_pool(@pool)
4346
end
4447

4548
def reconnect

lib/arjdbc/abstract/core.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22

33
module ArJdbc
44
module Abstract
5-
65
# This is minimum amount of code needed from base JDBC Adapter class to make common adapters
76
# work. This replaces using jdbc/adapter as a base class for all adapters.
87
module Core
9-
10-
attr_reader :config
11-
12-
def initialize(config)
13-
@config = config
8+
def initialize(...)
9+
super
1410

1511
if self.class.equal? ActiveRecord::ConnectionAdapters::JdbcAdapter
1612
spec = @config.key?(:adapter_spec) ? @config[:adapter_spec] :
1713
( @config[:adapter_spec] = adapter_spec(@config) ) # due resolving visitor
1814
extend spec if spec
1915
end
20-
21-
super(config) # AbstractAdapter
2216
end
2317

2418
# Retrieve the raw `java.sql.Connection` object.

lib/arjdbc/postgresql/adapter.rb

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def adapter_name
5252
def redshift?
5353
# SELECT version() :
5454
# PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.647
55-
if ( redshift = config[:redshift] ).nil?
56-
redshift = !! (@connection.database_product || '').index('Redshift')
55+
if (redshift = @config[:redshift]).nil?
56+
redshift = !! (valid_raw_connection.database_product || '').index('Redshift')
5757
end
5858
redshift
5959
end
@@ -73,8 +73,8 @@ def configure_connection
7373
# see http://jdbc.postgresql.org/documentation/91/connect.html
7474
# self.set_client_encoding(encoding)
7575
#end
76-
self.client_min_messages = config[:min_messages] || 'warning'
77-
self.schema_search_path = config[:schema_search_path] || config[:schema_order]
76+
self.client_min_messages = @config[:min_messages] || 'warning'
77+
self.schema_search_path = @config[:schema_search_path] || @config[:schema_order]
7878

7979
# Use standard-conforming strings if available so we don't have to do the E'...' dance.
8080
set_standard_conforming_strings
@@ -93,14 +93,17 @@ def configure_connection
9393

9494
# SET statements from :variables config hash
9595
# http://www.postgresql.org/docs/8.3/static/sql-set.html
96-
(config[:variables] || {}).map do |k, v|
96+
(@config[:variables] || {}).map do |k, v|
9797
if v == ':default' || v == :default
9898
# Sets the value to the global or compile default
9999
execute("SET SESSION #{k} TO DEFAULT", 'SCHEMA')
100100
elsif ! v.nil?
101101
execute("SET SESSION #{k} TO #{quote(v)}", 'SCHEMA')
102102
end
103103
end
104+
105+
@type_map = Type::HashLookupTypeMap.new
106+
initialize_type_map
104107
end
105108

106109
# @private
@@ -370,7 +373,7 @@ def use_insert_returning?
370373

371374
def get_database_version # :nodoc:
372375
begin
373-
version = @connection.database_product
376+
version = valid_raw_connection.database_product
374377
if match = version.match(/([\d\.]*\d).*?/)
375378
version = match[1].split('.').map(&:to_i)
376379
# PostgreSQL version representation does not have more than 4 digits
@@ -761,16 +764,17 @@ class PostgreSQLAdapter < AbstractAdapter
761764
# AR expects OID to be available on the adapter
762765
OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
763766

764-
def initialize(connection, logger = nil, connection_parameters = nil, config = {})
767+
def initialize(...)
768+
super
769+
770+
conn_params = @config.compact
771+
772+
@connection_parameters = conn_params
773+
765774
# @local_tz is initialized as nil to avoid warnings when connect tries to use it
766775
@local_tz = nil
767776
@max_identifier_length = nil
768777

769-
super(connection, logger, config) # configure_connection happens in super
770-
771-
@type_map = Type::HashLookupTypeMap.new
772-
initialize_type_map
773-
774778
@use_insert_returning = @config.key?(:insert_returning) ?
775779
self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true
776780
end
@@ -793,7 +797,7 @@ def self.database_exists?(config)
793797
public :sql_for_insert
794798
alias :postgresql_version :database_version
795799

796-
def jdbc_connection_class(spec)
800+
def jdbc_connection_class
797801
::ArJdbc::PostgreSQL.jdbc_connection_class
798802
end
799803

@@ -829,8 +833,10 @@ def exec_no_cache(sql, name, binds, async: false)
829833

830834
type_casted_binds = type_casted_binds(binds)
831835
log(sql, name, binds, type_casted_binds, async: async) do
832-
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
833-
@connection.exec_params(sql, type_casted_binds)
836+
with_raw_connection do |conn|
837+
result = conn.exec_params(sql, type_casted_binds)
838+
verified!
839+
result
834840
end
835841
end
836842
end

0 commit comments

Comments
 (0)