Skip to content

Commit

Permalink
Rename the raw connection ivar to @raw_connection
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Feb 25, 2022
1 parent c26f3ec commit 7fb630d
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module DatabaseStatements
def execute(sql, name = nil, async: false)
sql = transform_query(sql)

log(sql, name, async: async) { @connection.exec(sql) }
log(sql, name, async: async) { @raw_connection.exec(sql) }
end

def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
Expand All @@ -25,10 +25,10 @@ def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
cached = false
with_retry do
if without_prepared_statement?(binds)
cursor = @connection.prepare(sql)
cursor = @raw_connection.prepare(sql)
else
unless @statements.key? sql
@statements[sql] = @connection.prepare(sql)
@statements[sql] = @raw_connection.prepare(sql)
end

cursor = @statements[sql]
Expand Down Expand Up @@ -101,10 +101,10 @@ def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
returning_id_col = returning_id_index = nil
with_retry do
if without_prepared_statement?(binds)
cursor = @connection.prepare(sql)
cursor = @raw_connection.prepare(sql)
else
unless @statements.key?(sql)
@statements[sql] = @connection.prepare(sql)
@statements[sql] = @raw_connection.prepare(sql)
end

cursor = @statements[sql]
Expand Down Expand Up @@ -141,12 +141,12 @@ def exec_update(sql, name = nil, binds = [])
with_retry do
cached = false
if without_prepared_statement?(binds)
cursor = @connection.prepare(sql)
cursor = @raw_connection.prepare(sql)
else
if @statements.key?(sql)
cursor = @statements[sql]
else
cursor = @statements[sql] = @connection.prepare(sql)
cursor = @statements[sql] = @raw_connection.prepare(sql)
end

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

def begin_db_transaction # :nodoc:
@connection.autocommit = false
@raw_connection.autocommit = false
end

def transaction_isolation_levels
Expand All @@ -183,15 +183,15 @@ def begin_isolated_db_transaction(isolation)
end

def commit_db_transaction # :nodoc:
@connection.commit
@raw_connection.commit
ensure
@connection.autocommit = true
@raw_connection.autocommit = true
end

def exec_rollback_db_transaction # :nodoc:
@connection.rollback
@raw_connection.rollback
ensure
@connection.autocommit = true
@raw_connection.autocommit = true
end

def create_savepoint(name = current_savepoint_name) # :nodoc:
Expand Down Expand Up @@ -265,14 +265,14 @@ def write_lobs(table_name, klass, attributes, columns) # :nodoc:
raise ActiveRecord::RecordNotFound, "statement #{sql} returned no rows"
end
lob = lob_record[col.name]
@connection.write_lob(lob, value.to_s, col.type == :binary)
@raw_connection.write_lob(lob, value.to_s, col.type == :binary)
end
end
end

private
def with_retry
@connection.with_retry do
@raw_connection.with_retry do
yield
rescue
@statements.clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def database_version

class Cursor
def initialize(connection, raw_statement)
@connection = connection
@raw_connection = connection
@raw_statement = raw_statement
end

Expand Down Expand Up @@ -384,7 +384,7 @@ def fetch(options = {})
row_values = []
column_types.each_with_index do |column_type, i|
row_values <<
@connection.get_ruby_value_from_result_set(@raw_result_set, i + 1, column_type, get_lob_value)
@raw_connection.get_ruby_value_from_result_set(@raw_result_set, i + 1, column_type, get_lob_value)
end
row_values
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module JDBCQuoting
def type_cast(value)
case value
when ActiveModel::Type::Binary::Data
blob = Java::OracleSql::BLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::BLOB::DURATION_SESSION)
blob = Java::OracleSql::BLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::BLOB::DURATION_SESSION)
blob.setBytes(1, value.to_s.to_java_bytes)
blob
when Type::OracleEnhanced::Text::Data
clob = Java::OracleSql::CLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
clob = Java::OracleSql::CLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::CLOB::DURATION_SESSION)
clob.setString(1, value.to_s)
clob
when Type::OracleEnhanced::NationalCharacterText::Data
clob = Java::OracleSql::NCLOB.createTemporary(@connection.raw_connection, false, Java::OracleSql::NCLOB::DURATION_SESSION)
clob = Java::OracleSql::NCLOB.createTemporary(@raw_connection.raw_connection, false, Java::OracleSql::NCLOB::DURATION_SESSION)
clob.setString(1, value.to_s)
clob
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def raw_oci_connection
# ActiveRecord Oracle enhanced adapter puts OCI8EnhancedAutoRecover wrapper around OCI8
# in this case we need to pass original OCI8 connection
else
@raw_connection.instance_variable_get(:@connection)
@raw_connection.instance_variable_get(:@raw_connection)
end
end

Expand Down Expand Up @@ -107,7 +107,7 @@ def prepare(sql)

class Cursor
def initialize(connection, raw_cursor)
@connection = connection
@raw_connection = connection
@raw_cursor = raw_cursor
end

Expand Down Expand Up @@ -159,7 +159,7 @@ def fetch(options = {})
get_lob_value = options[:get_lob_value]
col_index = 0
row.map do |col|
col_value = @connection.typecast_result_value(col, get_lob_value)
col_value = @raw_connection.typecast_result_value(col, get_lob_value)
col_metadata = @raw_cursor.column_metadata.fetch(col_index)
if !col_metadata.nil?
key = col_metadata.data_type
Expand Down Expand Up @@ -390,15 +390,15 @@ def initialize(config, factory) # :nodoc:
@active = true
@config = config
@factory = factory
@connection = @factory.new_connection @config
super @connection
@raw_connection = @factory.new_connection @config
super @raw_connection
end

# Checks connection, returns true if active. Note that ping actively
# checks the connection, while #active? simply returns the last
# known state.
def ping # :nodoc:
@connection.exec("select 1 from dual") { |r| nil }
@raw_connection.exec("select 1 from dual") { |r| nil }
@active = true
rescue
@active = false
Expand All @@ -409,8 +409,8 @@ def ping # :nodoc:
def reset! # :nodoc:
logoff rescue nil
begin
@connection = @factory.new_connection @config
__setobj__ @connection
@raw_connection = @factory.new_connection @config
__setobj__ @raw_connection
@active = true
rescue
@active = false
Expand Down Expand Up @@ -442,7 +442,7 @@ def with_retry # :nodoc:
end

def exec(sql, *bindvars, &block) # :nodoc:
with_retry { @connection.exec(sql, *bindvars, &block) }
with_retry { @raw_connection.exec(sql, *bindvars, &block) }
end
end
# :startdoc:
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ def type_cast(value)
when ActiveModel::Type::Binary::Data
lob_value = value == "" ? " " : value
bind_type = OCI8::BLOB
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
ora_value.size = 0 if value == ""
ora_value
when Type::OracleEnhanced::Text::Data
lob_value = value.to_s == "" ? " " : value.to_s
bind_type = OCI8::CLOB
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
ora_value.size = 0 if value.to_s == ""
ora_value
when Type::OracleEnhanced::NationalCharacterText::Data
lob_value = value.to_s == "" ? " " : value.to_s
bind_type = OCI8::NCLOB
ora_value = bind_type.new(@connection.raw_oci_connection, lob_value)
ora_value = bind_type.new(@raw_connection.raw_oci_connection, lob_value)
ora_value.size = 0 if value.to_s == ""
ora_value
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def column_spec_for_primary_key(column)

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

def synonyms(stream)
syns = @connection.synonyms
syns = @raw_connection.synonyms
syns.each do |syn|
next if ignored? syn.name
table_name = syn.table_name
Expand All @@ -46,7 +46,7 @@ def synonyms(stream)
end

def _indexes(table, stream)
if (indexes = @connection.indexes(table)).any?
if (indexes = @raw_connection.indexes(table)).any?
add_index_statements = indexes.filter_map do |index|
case index.type
when nil
Expand Down Expand Up @@ -77,7 +77,7 @@ def _indexes(table, stream)
end

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

def table(table, stream)
columns = @connection.columns(table)
columns = @raw_connection.columns(table)
begin
self.table_name = table

tbl = StringIO.new

# first dump primary key column
if @connection.respond_to?(:primary_keys)
pk = @connection.primary_keys(table)
if @raw_connection.respond_to?(:primary_keys)
pk = @raw_connection.primary_keys(table)
pk = pk.first unless pk.size > 1
else
pk = @connection.primary_key(table)
pk = @raw_connection.primary_key(table)
end

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

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

case pk
when String
Expand All @@ -128,7 +128,7 @@ def table(table, stream)
tbl.print ", id: false"
end

table_options = @connection.table_options(table)
table_options = @raw_connection.table_options(table)
if table_options.present?
tbl.print ", #{format_options(table_options)}"
end
Expand All @@ -137,7 +137,7 @@ def table(table, stream)

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

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

def extract_expression_for_virtual_column(column)
column_name = column.name
@connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
@raw_connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ data_default from all_tab_columns
where owner = SYS_CONTEXT('userenv', 'current_schema')
and table_name = :table_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def table_exists?(table_name)
end

def data_source_exists?(table_name)
(_owner, _table_name) = @connection.describe(table_name)
(_owner, _table_name) = @raw_connection.describe(table_name)
true
rescue
false
Expand Down Expand Up @@ -87,7 +87,7 @@ def synonyms
end

def indexes(table_name) # :nodoc:
(_owner, table_name) = @connection.describe(table_name)
(_owner, table_name) = @raw_connection.describe(table_name)
default_tablespace_name = default_tablespace

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

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

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

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

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

0 comments on commit 7fb630d

Please sign in to comment.