@@ -35,11 +35,6 @@ module PostgreSQL
3535 # @private
3636 Type = ::ActiveRecord ::Type
3737
38- # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
39- def self . jdbc_connection_class
40- ::ActiveRecord ::ConnectionAdapters ::PostgreSQLJdbcConnection
41- end
42-
4338 # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
4439 def jdbc_column_class ; ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn end
4540
@@ -52,8 +47,8 @@ def adapter_name
5247 def redshift?
5348 # SELECT version() :
5449 # 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' )
50+ if ( redshift = @ config[ :redshift ] ) . nil?
51+ redshift = !! ( valid_raw_connection . database_product || '' ) . index ( 'Redshift' )
5752 end
5853 redshift
5954 end
@@ -73,8 +68,8 @@ def configure_connection
7368 # see http://jdbc.postgresql.org/documentation/91/connect.html
7469 # self.set_client_encoding(encoding)
7570 #end
76- self . client_min_messages = config [ :min_messages ] || 'warning'
77- self . schema_search_path = config [ :schema_search_path ] || config [ :schema_order ]
71+ self . client_min_messages = @ config[ :min_messages ] || 'warning'
72+ self . schema_search_path = @ config[ :schema_search_path ] || @ config[ :schema_order ]
7873
7974 # Use standard-conforming strings if available so we don't have to do the E'...' dance.
8075 set_standard_conforming_strings
@@ -93,14 +88,17 @@ def configure_connection
9388
9489 # SET statements from :variables config hash
9590 # http://www.postgresql.org/docs/8.3/static/sql-set.html
96- ( config [ :variables ] || { } ) . map do |k , v |
91+ ( @ config[ :variables ] || { } ) . map do |k , v |
9792 if v == ':default' || v == :default
9893 # Sets the value to the global or compile default
9994 execute ( "SET SESSION #{ k } TO DEFAULT" , 'SCHEMA' )
10095 elsif ! v . nil?
10196 execute ( "SET SESSION #{ k } TO #{ quote ( v ) } " , 'SCHEMA' )
10297 end
10398 end
99+
100+ @type_map = Type ::HashLookupTypeMap . new
101+ initialize_type_map
104102 end
105103
106104 # @private
@@ -370,7 +368,7 @@ def use_insert_returning?
370368
371369 def get_database_version # :nodoc:
372370 begin
373- version = @connection . database_product
371+ version = valid_raw_connection . database_product
374372 if match = version . match ( /([\d \. ]*\d ).*?/ )
375373 version = match [ 1 ] . split ( '.' ) . map ( &:to_i )
376374 # PostgreSQL version representation does not have more than 4 digits
@@ -426,8 +424,7 @@ def check_version # :nodoc:
426424 end
427425 end
428426
429-
430- def exec_insert ( sql , name = nil , binds = [ ] , pk = nil , sequence_name = nil )
427+ def exec_insert ( sql , name = nil , binds = [ ] , pk = nil , sequence_name = nil , returning : nil ) # :nodoc:
431428 val = super
432429 if !use_insert_returning? && pk
433430 unless sequence_name
@@ -464,11 +461,11 @@ def write_query?(sql) # :nodoc:
464461 # since apparently calling close on the statement object
465462 # doesn't always free the server resources and calling
466463 # 'DISCARD ALL' fails if we are inside a transaction
467- def clear_cache!
468- super
469- # Make sure all query plans are *really* gone
470- @connection . execute 'DEALLOCATE ALL' if active?
471- end
464+ # def clear_cache!
465+ # super
466+ # # Make sure all query plans are *really* gone
467+ # @connection.execute 'DEALLOCATE ALL' if active?
468+ # end
472469
473470 def reset!
474471 clear_cache!
@@ -660,6 +657,8 @@ def translate_exception(exception, message:, sql:, binds:)
660657 ::ActiveRecord ::LockWaitTimeout . new ( message , sql : sql , binds : binds )
661658 when /canceling statement/ # This needs to come after lock timeout because the lock timeout message also contains "canceling statement"
662659 ::ActiveRecord ::QueryCanceled . new ( message , sql : sql , binds : binds )
660+ when /relation "animals" does not exist/i
661+ ::ActiveRecord ::StatementInvalid . new ( message , sql : sql , binds : binds , connection_pool : @pool )
663662 else
664663 super
665664 end
@@ -742,7 +741,7 @@ class PostgreSQLAdapter < AbstractAdapter
742741 include ActiveRecord ::ConnectionAdapters ::PostgreSQL ::SchemaStatements
743742 include ActiveRecord ::ConnectionAdapters ::PostgreSQL ::Quoting
744743
745- include Jdbc ::ConnectionPoolCallbacks
744+ # include Jdbc::ConnectionPoolCallbacks
746745
747746 include ArJdbc ::Abstract ::Core
748747 include ArJdbc ::Abstract ::ConnectionManagement
@@ -761,16 +760,27 @@ class PostgreSQLAdapter < AbstractAdapter
761760 # AR expects OID to be available on the adapter
762761 OID = ActiveRecord ::ConnectionAdapters ::PostgreSQL ::OID
763762
764- def initialize ( connection , logger = nil , connection_parameters = nil , config = { } )
763+ class << self
764+ def jdbc_connection_class
765+ ::ActiveRecord ::ConnectionAdapters ::PostgreSQLJdbcConnection
766+ end
767+
768+ def new_client ( conn_params , adapter_instance )
769+ jdbc_connection_class . new ( conn_params , adapter_instance )
770+ end
771+ end
772+
773+ def initialize ( ...)
774+ super
775+
776+ conn_params = @config . compact
777+
778+ @connection_parameters = conn_params
779+
765780 # @local_tz is initialized as nil to avoid warnings when connect tries to use it
766781 @local_tz = nil
767782 @max_identifier_length = nil
768783
769- super ( connection , logger , config ) # configure_connection happens in super
770-
771- @type_map = Type ::HashLookupTypeMap . new
772- initialize_type_map
773-
774784 @use_insert_returning = @config . key? ( :insert_returning ) ?
775785 self . class . type_cast_config_to_boolean ( @config [ :insert_returning ] ) : true
776786 end
@@ -793,10 +803,6 @@ def self.database_exists?(config)
793803 public :sql_for_insert
794804 alias :postgresql_version :database_version
795805
796- def jdbc_connection_class ( spec )
797- ::ArJdbc ::PostgreSQL . jdbc_connection_class
798- end
799-
800806 private
801807
802808 FEATURE_NOT_SUPPORTED = "0A000" # :nodoc:
@@ -829,8 +835,10 @@ def exec_no_cache(sql, name, binds, async: false)
829835
830836 type_casted_binds = type_casted_binds ( binds )
831837 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 )
838+ with_raw_connection do |conn |
839+ result = conn . exec_params ( sql , type_casted_binds )
840+ verified!
841+ result
834842 end
835843 end
836844 end
0 commit comments