Skip to content

Commit 5c51e56

Browse files
committed
Rename the raw connection ivar to @raw_connection
Follow up rails/rails#44530.
1 parent c26f3ec commit 5c51e56

File tree

10 files changed

+65
-65
lines changed

10 files changed

+65
-65
lines changed

lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module DatabaseStatements
1212
def execute(sql, name = nil, async: false)
1313
sql = transform_query(sql)
1414

15-
log(sql, name, async: async) { @connection.exec(sql) }
15+
log(sql, name, async: async) { @raw_connection.exec(sql) }
1616
end
1717

1818
def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
@@ -25,10 +25,10 @@ def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
2525
cached = false
2626
with_retry do
2727
if without_prepared_statement?(binds)
28-
cursor = @connection.prepare(sql)
28+
cursor = @raw_connection.prepare(sql)
2929
else
3030
unless @statements.key? sql
31-
@statements[sql] = @connection.prepare(sql)
31+
@statements[sql] = @raw_connection.prepare(sql)
3232
end
3333

3434
cursor = @statements[sql]
@@ -101,10 +101,10 @@ def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
101101
returning_id_col = returning_id_index = nil
102102
with_retry do
103103
if without_prepared_statement?(binds)
104-
cursor = @connection.prepare(sql)
104+
cursor = @raw_connection.prepare(sql)
105105
else
106106
unless @statements.key?(sql)
107-
@statements[sql] = @connection.prepare(sql)
107+
@statements[sql] = @raw_connection.prepare(sql)
108108
end
109109

110110
cursor = @statements[sql]
@@ -141,12 +141,12 @@ def exec_update(sql, name = nil, binds = [])
141141
with_retry do
142142
cached = false
143143
if without_prepared_statement?(binds)
144-
cursor = @connection.prepare(sql)
144+
cursor = @raw_connection.prepare(sql)
145145
else
146146
if @statements.key?(sql)
147147
cursor = @statements[sql]
148148
else
149-
cursor = @statements[sql] = @connection.prepare(sql)
149+
cursor = @statements[sql] = @raw_connection.prepare(sql)
150150
end
151151

152152
cursor.bind_params(type_casted_binds)
@@ -164,7 +164,7 @@ def exec_update(sql, name = nil, binds = [])
164164
alias :exec_delete :exec_update
165165

166166
def begin_db_transaction # :nodoc:
167-
@connection.autocommit = false
167+
@raw_connection.autocommit = false
168168
end
169169

170170
def transaction_isolation_levels
@@ -183,15 +183,15 @@ def begin_isolated_db_transaction(isolation)
183183
end
184184

185185
def commit_db_transaction # :nodoc:
186-
@connection.commit
186+
@raw_connection.commit
187187
ensure
188-
@connection.autocommit = true
188+
@raw_connection.autocommit = true
189189
end
190190

191191
def exec_rollback_db_transaction # :nodoc:
192-
@connection.rollback
192+
@raw_connection.rollback
193193
ensure
194-
@connection.autocommit = true
194+
@raw_connection.autocommit = true
195195
end
196196

197197
def create_savepoint(name = current_savepoint_name) # :nodoc:
@@ -265,14 +265,14 @@ def write_lobs(table_name, klass, attributes, columns) # :nodoc:
265265
raise ActiveRecord::RecordNotFound, "statement #{sql} returned no rows"
266266
end
267267
lob = lob_record[col.name]
268-
@connection.write_lob(lob, value.to_s, col.type == :binary)
268+
@raw_connection.write_lob(lob, value.to_s, col.type == :binary)
269269
end
270270
end
271271
end
272272

273273
private
274274
def with_retry
275-
@connection.with_retry do
275+
@raw_connection.with_retry do
276276
yield
277277
rescue
278278
@statements.clear

lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def database_version
295295

296296
class Cursor
297297
def initialize(connection, raw_statement)
298-
@connection = connection
298+
@raw_connection = connection
299299
@raw_statement = raw_statement
300300
end
301301

@@ -384,7 +384,7 @@ def fetch(options = {})
384384
row_values = []
385385
column_types.each_with_index do |column_type, i|
386386
row_values <<
387-
@connection.get_ruby_value_from_result_set(@raw_result_set, i + 1, column_type, get_lob_value)
387+
@raw_connection.get_ruby_value_from_result_set(@raw_result_set, i + 1, column_type, get_lob_value)
388388
end
389389
row_values
390390
else

lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ module JDBCQuoting
77
def type_cast(value)
88
case value
99
when ActiveModel::Type::Binary::Data
10-
blob = Java::OracleSql::BLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::BLOB::DURATION_SESSION)
10+
blob = Java::OracleSql::BLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::BLOB::DURATION_SESSION)
1111
blob.setBytes(1, value.to_s.to_java_bytes)
1212
blob
1313
when Type::OracleEnhanced::Text::Data
14-
clob = Java::OracleSql::CLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
14+
clob = Java::OracleSql::CLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
1515
clob.setString(1, value.to_s)
1616
clob
1717
when Type::OracleEnhanced::NationalCharacterText::Data
18-
clob = Java::OracleSql::NCLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::NCLOB::DURATION_SESSION)
18+
clob = Java::OracleSql::NCLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::NCLOB::DURATION_SESSION)
1919
clob.setString(1, value.to_s)
2020
clob
2121
else

lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def raw_oci_connection
4141
# ActiveRecord Oracle enhanced adapter puts OCI8EnhancedAutoRecover wrapper around OCI8
4242
# in this case we need to pass original OCI8 connection
4343
else
44-
@raw_connection.instance_variable_get(:@connection)
44+
@raw_connection.instance_variable_get(:@raw_connection)
4545
end
4646
end
4747

@@ -107,7 +107,7 @@ def prepare(sql)
107107

108108
class Cursor
109109
def initialize(connection, raw_cursor)
110-
@connection = connection
110+
@raw_connection = connection
111111
@raw_cursor = raw_cursor
112112
end
113113

@@ -159,7 +159,7 @@ def fetch(options = {})
159159
get_lob_value = options[:get_lob_value]
160160
col_index = 0
161161
row.map do |col|
162-
col_value = @connection.typecast_result_value(col, get_lob_value)
162+
col_value = @raw_connection.typecast_result_value(col, get_lob_value)
163163
col_metadata = @raw_cursor.column_metadata.fetch(col_index)
164164
if !col_metadata.nil?
165165
key = col_metadata.data_type
@@ -390,15 +390,15 @@ def initialize(config, factory) # :nodoc:
390390
@active = true
391391
@config = config
392392
@factory = factory
393-
@connection = @factory.new_connection @config
394-
super @connection
393+
@raw_connection = @factory.new_connection @config
394+
super @raw_connection
395395
end
396396

397397
# Checks connection, returns true if active. Note that ping actively
398398
# checks the connection, while #active? simply returns the last
399399
# known state.
400400
def ping # :nodoc:
401-
@connection.exec("select 1 from dual") { |r| nil }
401+
@raw_connection.exec("select 1 from dual") { |r| nil }
402402
@active = true
403403
rescue
404404
@active = false
@@ -409,8 +409,8 @@ def ping # :nodoc:
409409
def reset! # :nodoc:
410410
logoff rescue nil
411411
begin
412-
@connection = @factory.new_connection @config
413-
__setobj__ @connection
412+
@raw_connection = @factory.new_connection @config
413+
__setobj__ @raw_connection
414414
@active = true
415415
rescue
416416
@active = false
@@ -442,7 +442,7 @@ def with_retry # :nodoc:
442442
end
443443

444444
def exec(sql, *bindvars, &block) # :nodoc:
445-
with_retry { @connection.exec(sql, *bindvars, &block) }
445+
with_retry { @raw_connection.exec(sql, *bindvars, &block) }
446446
end
447447
end
448448
# :startdoc:

lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ def type_cast(value)
99
when ActiveModel::Type::Binary::Data
1010
lob_value = value == "" ? " " : value
1111
bind_type = OCI8::BLOB
12-
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
12+
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
1313
ora_value.size = 0 if value == ""
1414
ora_value
1515
when Type::OracleEnhanced::Text::Data
1616
lob_value = value.to_s == "" ? " " : value.to_s
1717
bind_type = OCI8::CLOB
18-
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
18+
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
1919
ora_value.size = 0 if value.to_s == ""
2020
ora_value
2121
when Type::OracleEnhanced::NationalCharacterText::Data
2222
lob_value = value.to_s == "" ? " " : value.to_s
2323
bind_type = OCI8::NCLOB
24-
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
24+
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
2525
ora_value.size = 0 if value.to_s == ""
2626
ora_value
2727
else

lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def column_spec_for_primary_key(column)
1616

1717
def tables(stream)
1818
# do not include materialized views in schema dump - they should be created separately after schema creation
19-
sorted_tables = (@connection.tables - @connection.materialized_views).sort
19+
sorted_tables = (@raw_connection.tables - @raw_connection.materialized_views).sort
2020
sorted_tables.each do |tbl|
2121
# add table prefix or suffix for schema_migrations
2222
next if ignored? tbl
@@ -34,7 +34,7 @@ def tables(stream)
3434
end
3535

3636
def synonyms(stream)
37-
syns = @connection.synonyms
37+
syns = @raw_connection.synonyms
3838
syns.each do |syn|
3939
next if ignored? syn.name
4040
table_name = syn.table_name
@@ -46,7 +46,7 @@ def synonyms(stream)
4646
end
4747

4848
def _indexes(table, stream)
49-
if (indexes = @connection.indexes(table)).any?
49+
if (indexes = @raw_connection.indexes(table)).any?
5050
add_index_statements = indexes.filter_map do |index|
5151
case index.type
5252
when nil
@@ -77,7 +77,7 @@ def _indexes(table, stream)
7777
end
7878

7979
def indexes_in_create(table, stream)
80-
if (indexes = @connection.indexes(table)).any?
80+
if (indexes = @raw_connection.indexes(table)).any?
8181
index_statements = indexes.map do |index|
8282
" t.index #{index_parts(index).join(', ')}" unless index.type == "CTXSYS.CONTEXT"
8383
end
@@ -92,24 +92,24 @@ def index_parts(index)
9292
end
9393

9494
def table(table, stream)
95-
columns = @connection.columns(table)
95+
columns = @raw_connection.columns(table)
9696
begin
9797
self.table_name = table
9898

9999
tbl = StringIO.new
100100

101101
# first dump primary key column
102-
if @connection.respond_to?(:primary_keys)
103-
pk = @connection.primary_keys(table)
102+
if @raw_connection.respond_to?(:primary_keys)
103+
pk = @raw_connection.primary_keys(table)
104104
pk = pk.first unless pk.size > 1
105105
else
106-
pk = @connection.primary_key(table)
106+
pk = @raw_connection.primary_key(table)
107107
end
108108

109109
tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}"
110110

111111
# addition to make temporary option work
112-
tbl.print ", temporary: true" if @connection.temporary_table?(table)
112+
tbl.print ", temporary: true" if @raw_connection.temporary_table?(table)
113113

114114
case pk
115115
when String
@@ -128,7 +128,7 @@ def table(table, stream)
128128
tbl.print ", id: false"
129129
end
130130

131-
table_options = @connection.table_options(table)
131+
table_options = @raw_connection.table_options(table)
132132
if table_options.present?
133133
tbl.print ", #{format_options(table_options)}"
134134
end
@@ -137,7 +137,7 @@ def table(table, stream)
137137

138138
# then dump all non-primary key columns
139139
columns.each do |column|
140-
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
140+
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @raw_connection.valid_type?(column.type)
141141
next if column.name == pk
142142
type, colspec = column_spec(column)
143143
tbl.print " t.#{type} #{column.name.inspect}"
@@ -166,7 +166,7 @@ def table(table, stream)
166166
def prepare_column_options(column)
167167
spec = super
168168

169-
if @connection.supports_virtual_columns? && column.virtual?
169+
if @raw_connection.supports_virtual_columns? && column.virtual?
170170
spec[:as] = extract_expression_for_virtual_column(column)
171171
spec = { type: schema_type(column).inspect }.merge!(spec) unless column.type == :decimal
172172
end
@@ -180,7 +180,7 @@ def default_primary_key?(column)
180180

181181
def extract_expression_for_virtual_column(column)
182182
column_name = column.name
183-
@connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
183+
@raw_connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
184184
select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ data_default from all_tab_columns
185185
where owner = SYS_CONTEXT('userenv', 'current_schema')
186186
and table_name = :table_name

lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def table_exists?(table_name)
5353
end
5454

5555
def data_source_exists?(table_name)
56-
(_owner, _table_name) = @connection.describe(table_name)
56+
(_owner, _table_name) = @raw_connection.describe(table_name)
5757
true
5858
rescue
5959
false
@@ -87,7 +87,7 @@ def synonyms
8787
end
8888

8989
def indexes(table_name) # :nodoc:
90-
(_owner, table_name) = @connection.describe(table_name)
90+
(_owner, table_name) = @raw_connection.describe(table_name)
9191
default_tablespace_name = default_tablespace
9292

9393
result = select_all(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
@@ -368,7 +368,7 @@ def index_name(table_name, options) # :nodoc:
368368
#
369369
# Will always query database and not index cache.
370370
def index_name_exists?(table_name, index_name)
371-
(_owner, table_name) = @connection.describe(table_name)
371+
(_owner, table_name) = @raw_connection.describe(table_name)
372372
result = select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("index_name", index_name.to_s.upcase)])
373373
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ 1 FROM all_indexes i
374374
WHERE i.owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -511,7 +511,7 @@ def change_column_comment(table_name, column_name, comment_or_changes)
511511

512512
def table_comment(table_name) # :nodoc:
513513
# TODO
514-
(_owner, table_name) = @connection.describe(table_name)
514+
(_owner, table_name) = @raw_connection.describe(table_name)
515515
select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name)])
516516
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_tab_comments
517517
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -527,7 +527,7 @@ def table_options(table_name) # :nodoc:
527527

528528
def column_comment(table_name, column_name) # :nodoc:
529529
# TODO: it does not exist in Abstract adapter
530-
(_owner, table_name) = @connection.describe(table_name)
530+
(_owner, table_name) = @raw_connection.describe(table_name)
531531
select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
532532
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_col_comments
533533
WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -555,7 +555,7 @@ def tablespace(table_name)
555555

556556
# get table foreign keys for schema dump
557557
def foreign_keys(table_name) # :nodoc:
558-
(_owner, desc_table_name) = @connection.describe(table_name)
558+
(_owner, desc_table_name) = @raw_connection.describe(table_name)
559559

560560
fk_info = select_all(<<~SQL.squish, "SCHEMA", [bind_string("desc_table_name", desc_table_name)])
561561
SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ r.table_name to_table

0 commit comments

Comments
 (0)